| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275 |
- <?php namespace Pinterface\Api;
- use Dever;
- use Pinterface\Lib\Core;
- class Main extends Core
- {
- # 首页
- public function home()
- {
- /*
- $data['e'] = false;
- if ($this->place->info['type'] == 1) {
- # 公开
- $data['e'] = true;
- } elseif ($this->place->info['type'] == 2 && $this->place->user) {
- # 注册
- $data['e'] = true;
- } elseif ($this->place->info['type'] > 2 && $this->place->user && $this->place->user['entry_type'] > 2) {
- # 邀请码、购买、密码等等
- $data['e'] = true;
- } else {
- # 需要注册、购买、输入密码等等
- if ($this->place->info['type'] == 2) {
- $data['b'] = [
- 'name' => '注册',
- 'type' => 2,
- ];
- } elseif ($this->place->info['type'] == 3) {
- $data['b'] = [
- 'name' => '邀请码',
- 'type' => 3,
- ];
- } elseif ($this->place->info['type'] == 4) {
- $data['b'] = [
- 'name' => '密码',
- 'type' => 4,
- ];
- } elseif ($this->place->info['type'] == 5) {
- $data['b'] = [
- 'name' => '购买',
- 'type' => 5,
- ];
- }
- }
- */
- $data['n'] = $this->place->info['name'];
- $data['i'] = $this->place->info['info'];
- $data['l'] = $this->place->info['logo'];
- $data['u'] = $this->place->info['update'];
- $data['m'] = $this->place->nav();
- return $data;
- }
- # 获取品牌介绍
- public function getContent()
- {
- $data['content'] = htmlspecialchars_decode($this->place->info['content']);
- return $data;
- }
- # 获取个人中心首页需要的信息
- public function getUserHome()
- {
- # 获取所有身份
- $data['role'] = Dever::db('prole/info')->select(['status' => 1], ['col' => 'id,name,info']);
- $data['role_info'] = [];
- if ($data['role']) {
- foreach ($data['role'] as &$v) {
- if ($v['info'] && !$data['role_info']) {
- $v['subname'] = $v['info'];
- $v['button'] = '立即开通';
- $data['role_info'] = $v;
- }
- $v['level_name'] = '成为' . $v['name'];
- }
- }
- # 获取所有积分
- $data['score'] = Dever::db('pscore/info')->select(['status' => 1], ['col' => 'id,name,0 as num']);
- return $data;
- }
- # 验证码登录或者注册
- public function login_commit(){}
- public function login()
- {
- $mobile = Dever::input('mobile', 'is_numeric', '手机号');
- $pwd = Dever::input('pwd');
- if (!$pwd) {
- $code = Dever::input('code', 'is_numeric', '验证码');
- Dever::load(\Msg\Lib\Template::class)->check('reg_code', $mobile, $code);
- }
- $invite = Dever::input('invite');
- $db = Dever::db('puser/info');
- $user = $db->find(['mobile' => $mobile]);
- if ($user) {
- $action = '登录';
- if ($pwd && Dever::load(\Manage\Lib\Util::class)->hash($pwd, $user['salt']) != $user['password']) {
- Dever::error('登录失败,密码无效');
- }
- # 已注册,登录
- $uid = $user['id'];
- # 记录日志
- Dever::load(\Pscore\Lib\Log::class)->action('登录')->add($uid);
- # 升级初始身份等级
- if ($user['type'] == 1) {
- Dever::load(\Prole\Lib\Info::class)->up($uid, $user['sales_type'], $user['sales_id']);
- }
- } elseif (!$pwd) {
- $action = '注册';
- if ($invite) {
- $parent_uid = Dever::load(\Invite\Lib\Code::class)->getUid($invite);
- if (!$parent_uid) {
- Dever::error('邀请码不存在');
- }
- } else {
- # 如果没有上级,从访问码里找:
- $parent_uid = $this->place->info['parent_uid'];
- /* 这里暂时不做
- if (!$parent_uid && $this->place->info['sales_type'] && $this->place->info['sales_id']) {
- # 如果还没有上级,找销售渠道,销售渠道就是其的上级
- $sales = Dever::load(\Psales\Lib\Info::class)->get($this->place->info['sales_type'] && $this->place->info['sales_id']);
- if ($sales['uid']) {
- $parent_uid = $sales['uid'];
- }
- }*/
- }
- $uid = Dever::load(\Puser\Lib\Info::class)->createUser($mobile, $this->place->info['sales_type'], $this->place->info['sales_id'], $parent_uid);
- } else {
- Dever::error('账户不存在,请切换到验证码登录');
- }
- return $this->result($uid);
- }
- # 静默注册
- public function reg_commit(){}
- public function reg()
- {
- $value = Dever::input('uuid');
- if (!$value) {
- return [];
- }
- $platform = Dever::input('platform', 'is_string', '平台信息', 'weixin');
- $env = Dever::input('env', 'is_numeric', '环境信息', 3);
- if ($env == 5) {
- $value = false;
- # 小程序下获取openid
- $account = Dever::db('api/account')->find(['key' => $platform]);
- if ($account) {
- $param['js_code'] = Dever::input('applet_code', 'is_string', '登录信息');
- $applet = Dever::load(\Api\Lib\Account::class)->run($account, 'applet_login', $param, $env);
- if (isset($applet['openid'])) {
- $value = $applet['openid'];
- }
- }
- }
- if (!$value) {
- return [];
- }
- $data = ['env' => $env, 'platform' => $platform, 'value' => $value];
- $uuid = Dever::db('puser/uuid')->find($data);
- if ($uuid) {
- return $this->result($uuid['uid'], false);
- }
- $id = Dever::db('puser/uuid')->insert($data);
- if ($id) {
- # 生成新用户
- $parent_uid = $this->place->info['parent_uid'];
- $mobile = Dever::load(\Puser\Lib\Info::class)->createMobile();
- $uid = Dever::load(\Puser\Lib\Info::class)->createUser($mobile, $this->place->info['sales_type'], $this->place->info['sales_id'], $parent_uid, '', '', 2);
- if ($uid) {
- Dever::db('puser/uuid')->update($id, ['uid' => $uid]);
- if ($env == 5) {
- $update['uid'] = $uid;
- $update['account_id'] = $account['id'];
- $update['env'] = $env;
- $update['openid'] = $value;
- Dever::db('api/openid')->insert($update);
- }
- }
- return $this->result($uid, false);
- }
- }
- # env = 2 => 'h5',3 => 'jsapi',4 => 'app',5 => '小程序',6 => 'pc',
- public function result($uid, $openid = true)
- {
- $result['t'] = \Dever\Helper\Secure::login($uid);
- if ($openid) {
- # 获取openid
- $platform = Dever::input('platform', 'is_string', '平台信息', 'weixin');
- $env = Dever::input('env', 'is_numeric', '环境信息', 3);
- $result = Dever::load(\Place\Lib\Account::class)->openid(['key' => $platform], $env, $uid, $result);
- if (isset($result['openid'])) {
- unset($result['openid']);
- }
- }
- return $result;
- }
- # 重置密码
- public function reset()
- {
- # 大于8位字符,至少包含:小写字母、大写字母、数字、特殊字符
- //$pwd = Dever::input('pwd', '/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[\W_]).{8,}$/', '密码');
- $mobile = Dever::input('mobile', 'is_numeric', '手机号');
- $pwd = Dever::input('pwd', 'is_string', '密码');
- $code = Dever::input('code', 'is_string', '验证码');
- Dever::load(\Msg\Lib\Template::class)->check('reg_code', $mobile, $code);
- $update = Dever::load(\Manage\Lib\Util::class)->createPwd($pwd);
- Dever::db('puser/info')->update(['mobile' => $mobile], $update);
- }
- # 发送短信验证码
- public function sms()
- {
- $mobile = Dever::input('mobile', 'is_numeric', '手机号');
- $data = Dever::load(\Msg\Lib\Template::class)->send('reg_code', ['mobile' => $mobile], [], 'place');
- return $data;
- }
- # 获取单页信息
- public function page()
- {
- $name = Dever::input('name', 'is_string', '单页名称');
- $info = Dever::db('sector/page')->find(['name' => $name]);
- if ($info) {
- $info['content'] = htmlspecialchars_decode($info['content']);
- }
- return $info;
- }
- # 获取分享信息
- public function share()
- {
- $sales_type = Dever::input('sales_type');
- $sales_id = Dever::input('sales_id');
- $type = Dever::input('type');
- if (!$type) {
- $type = 0;
- }
- if (!$sales_type || !$sales_id) {
- $sales_type = $this->place->info['sales_type'];
- $sales_id = $this->place->info['sales_id'];
- }
- if (!$this->place->uid) {
- $this->place->uid = 0;
- }
- $result = Dever::load(\Place\Lib\Info::class)->share($this->place->info['id'], $sales_type, $sales_id, $this->place->uid, false, $type, false);
- $share['path'] = $result['path'];
- if ($type > 0) {
- # 资源信息
- $source = Dever::db('source/info')->find(['id' => $type]);
- if (!$source['share_pic'] && $source['pic']) {
- $source['pic'] = explode(',', $source['pic']);
- $share['pic'] = $source['pic'][0];
- } else {
- $share['pic'] = $source['share_pic'];
- }
- $share['name'] = $source['share_name'] ?: $source['name'];
- $share['desc'] = $source['share_desc'] ?: $source['info'];
- } else {
- $share['name'] = $this->place->info['share_name'] ?: $this->place->info['name'];
- $share['pic'] = $this->place->info['share_pic'] ?: $this->place->info['logo'];
- $share['desc'] = $this->place->info['share_desc'] ?: $this->place->info['info'];
- }
- $data['share'] = $share;
- return $data;
- }
- }
|