123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333 |
- <?php namespace Puser\Manage\Lib;
- use Dever;
- class User
- {
- # 后台创建用户
- public function createStart($db, $data)
- {
- if (isset($data['import'])) {
- if (!$data['import']) {
- Dever::error('请选择导入文件');
- }
- Dever::load(\Puser\Manage\Lib\Excel::class)->import($data['import']);
- return 'end';
- }
- if (isset($data['mobile']) && $data['mobile']) {
- $data['type'] = 1;
- if (isset($data['id']) && $data['id'] > 0) {
- $info = Dever::db('puser/info')->find(['mobile' => $data['mobile']]);
- if ($info) {
- Dever::error('手机号'.$data['mobile'].'已存在');
- }
- } else {
- $info = Dever::db('puser/info')->find(['mobile' => $data['mobile']]);
- if ($info) {
- Dever::error('手机号'.$data['mobile'].'已存在');
- }
- if (empty($data['name'])) {
- $data['name'] = Dever::load(\Puser\Lib\Info::class)->createName($data['mobile']);
- }
- if (empty($data['avatar'])) {
- $data['avatar'] = Dever::load(\Puser\Lib\Info::class)->createAvatar($data['name']);
- }
- }
- }
- if (isset($data['sales']) && $data['sales']) {
- $data['sales'] = explode(',', $data['sales']);
- $data['sales_type'] = $data['sales'][0];
- $data['sales_id'] = $data['sales'][1];
- unset($data['sales']);
- }
- if (isset($data['parent_uid']) && $data['parent_uid'] > 0) {
- $length = strlen($data['parent_uid']);
- if ($length == 11) {
- $parent = Dever::db('puser/info')->find(['mobile' => $data['parent_uid'], 'status' => 1]);
- } else {
- $parent = Dever::db('puser/info')->find(['id' => $data['parent_uid'], 'status' => 1]);
- }
- if (!$parent) {
- Dever::error('推荐人' . $data['parent_uid'] . '不存在');
- }
- if (isset($data['id']) && $data['id']) {
- if ($data['id'] == $parent['id']) {
- Dever::error('推荐人' . $data['parent_uid'] . '不能是当前用户');
- }
- $info = Dever::db('puser/info')->find($data['id']);
- if ($info['parent_uid'] > 0) {
- Dever::error('当前用户已有推荐人,添加失败');
- }
- $childInfo = Dever::db('invite/relation')->find(['uid' => $data['id'], 'to_uid' => $parent['id']]);
- if ($childInfo) {
- Dever::error('推荐人' . $data['parent_uid'] . '是当前用户的下'.$childInfo['level'].'级,添加失败');
- }
- $parentInfo = Dever::db('invite/relation')->find(['uid' => $parent['id'], 'to_uid' => $data['id']]);
- if ($parentInfo) {
- Dever::error('推荐人' . $data['parent_uid'] . '是当前用户的上'.$parentInfo['level'].'级,添加失败');
- }
- }
- $data['parent_uid'] = $parent['id'];
- }
-
- return $data;
- }
- public function createEnd($db, $data)
- {
- if (isset($data['parent_uid']) && $data['parent_uid'] > 0) {
- Dever::load(\Invite\Lib\Relation::class)->set($data['parent_uid'], $data['id']);
- }
- Dever::load(\Pscore\Lib\Log::class)->action('注册')->add($data['id']);
- # 升级初始身份等级
- Dever::load(\Prole\Lib\Info::class)->up($data['id'], $data['sales_type'] ?? 0, $data['sales_id'] ?? 0);
- }
- # 获取用户名
- public function getName($uid)
- {
- $user = Dever::db('puser/info')->find($uid);
- return $user['name'] . ' | ' . $user['id'];
- }
- # 统一展示用户信息 'uid' => Dever::call('Puser/Manage/Lib/User.getInfo', ['{name}', '{mobile}']),
- public function getListInfo($title = '', $name = '', $mobile = '', $uid = '{uid}')
- {
- return [
- 'name' => $title ?: '用户信息',
- 'type' => 'popover',
- 'location' => 'right',
- 'align' => 'center',
- //'tag' => true,
- 'show' => 'Dever::call("Puser/Manage/Lib/User.getDesc", ["'.$uid.'", "'.$name.'", "'.$mobile.'", "'.$title.'"])',
- ];
- }
- # 统一做用户搜索信息
- public function getListSearch()
- {
- return [
- 'name' => '用户搜索',
- 'type' => 'select_text',
- 'option' => [
- ['id' => 1, 'name' => '用户ID', 'value' => 'uid'],
- ['id' => 2, 'name' => '用户名', 'value' => 'Puser/Manage/Lib/User.getUidByName'],
- ['id' => 3, 'name' => '用户手机号', 'value' => 'Puser/Manage/Lib/User.getUidByMobile'],
- ],
- ];
- }
- # 统一做用户搜索信息
- public function getListSearchParent()
- {
- return [
- 'name' => '推荐人搜索',
- 'type' => 'select_text',
- 'option' => [
- ['id' => 1, 'name' => '推荐人ID', 'value' => 'parent_uid'],
- ['id' => 2, 'name' => '推荐人用户名', 'value' => 'Puser/Manage/Lib/User.getParentUidByName'],
- ['id' => 3, 'name' => '推荐人手机号', 'value' => 'Puser/Manage/Lib/User.getParentUidByMobile'],
- ],
- ];
- }
- # 获取用户的身份列表
- public function getRole($uid)
- {
- $info = Dever::db('prole/info')->select(['status' => 1]);
- return Dever::load(\Manage\Lib\Util::class)->createTip(function(&$name, &$content) use ($uid, $info) {
- $time = time();
- foreach ($info as $v) {
- $user = Dever::db('prole/user')->find(['uid' => $uid, 'info_id' => $v['id'], 'status' => 1]);
- if ($user) {
- if ($user['edate'] < $time) {
- Dever::db('prole/user')->update($v['id'], ['status' => 2]);
- } else {
- $role = Dever::db('prole/info')->find($user['info_id']);
- $level = Dever::db('prole/level')->find($user['level_id']);
- $content[$v['id']] = ['name' => $role['name'], 'content' => $level['name'], 'role_id' => $role['id'], 'level_id' => $level['id']];
- if ($name = '-') {
- $name = $level['name'];
- }
- }
- }
- }
- });
- }
- # 获取用户的积分列表
- public function getScore($uid)
- {
- $info = Dever::db('pscore/info')->select(['status' => 1]);
- return Dever::load(\Manage\Lib\Util::class)->createTip(function(&$name, &$content) use ($uid, $info) {
- foreach ($info as $v) {
- $user = Dever::db('pscore/user')->find(['uid' => $uid, 'info_id' => $v['id'], 'status' => 1]);
- if ($user) {
- $content[$v['id']] = ['name' => $v['name'], 'content' => $user['balance'], 'id' => $v['id']];
- if ($name = '-') {
- $score = Dever::load(\Pscore\Lib\Info::class)->getText($user['balance'], $v);
- $name = $score;
- }
- }
- }
- });
- }
- # 获取团队人数
- public function getGroup($id)
- {
- return Dever::load(\Invite\Lib\Relation::class)->getChildNum($id);
- }
- public function getDesc($uid, $username = '', $mobile = '', $title = '')
- {
- return Dever::load(\Manage\Lib\Util::class)->createTip(function(&$name, &$content) use ($uid, $username, $mobile, $title) {
- $user = Dever::db('puser/info')->find($uid);
- if ($user) {
- if (!$username) {
- $username = $user['name'];
- }
- if ($mobile) {
- $user['mobile'] = $mobile;
- }
- $content = [
- ['name' => '用户ID', 'content' => $user['id']],
- ['name' => '用户名', 'content' => $user['name']],
- ];
- if ($title) {
- $content[] = ['name' => $title, 'content' => $username];
- }
- $content[] = ['name' => '手机号', 'content' => $user['mobile']];
- $name = $username . ' | ' . $user['id'];
- }
- });
- }
- # 获取用户信息
- public function getMobile($mobile)
- {
- return $mobile;
- return \Dever\Helper\Str::hide($mobile);
- }
- # 后台为用户充值钱包
- public function wallet($db, $data)
- {
- if ($data['amount']) {
- Dever::load(\Puser\Lib\Wallet::class)->sync($data['uid']);
- }
- }
- # 后台为用户充值积分
- public function score($db, $data)
- {
- if ($data['amount']) {
- Dever::load(\Puser\Lib\Score::class)->sync($data['uid']);
- }
- }
- # 根据用户名称获取用户
- public function getUidByName($value)
- {
- # 直接查出数据
- //$user = Dever::db('puser/info')->columns(['name' => $value]);
- # 返回sql
- $user = Dever::db('puser/info')->sql(['name' => $value], ['col' => 'id']);
- return ['uid', 'in', $user];
- }
- # 根据用户手机号获取用户
- public function getUidByMobile($value)
- {
- $user = Dever::db('puser/info')->sql(['mobile' => $value], ['col' => 'id']);
- return ['uid', 'in', $user];
- }
- # 根据上级用户名称获取用户
- public function getParentUidByName($value)
- {
- # 返回sql
- $user = Dever::db('puser/info')->sql(['name' => $value], ['col' => 'id']);
- return ['parent_uid', 'in', $user];
- }
- # 根据上级用户手机号获取用户
- public function getParentUidByMobile($value)
- {
- $user = Dever::db('puser/info')->sql(['mobile' => $value], ['col' => 'id']);
- return ['parent_uid', 'in', $user];
- }
- # 根据用户收件姓名获取用户
- public function getUidByAddName($value)
- {
- $user = Dever::db('puser/address')->sql(['name' => $value], ['col' => 'uid']);
- return ['uid', 'in', $user];
- }
- # 根据用户收件手机号获取用户
- public function getUidByAddMobile($value)
- {
- $user = Dever::db('puser/address')->sql(['phone' => $value], ['col' => 'uid']);
- return ['uid', 'in', $user];
- }
- # 获取用户手机号验证规则
- public function getMobileRules()
- {
- return [
- # 规则1
- [
- # 必填
- 'required' => true,
- # 输入后触发
- 'trigger' => 'blur',
- # 提示信息
- 'message' => '请输入手机号',
- ],
- # 规则2
- [
- # 长度
- 'len' => 11,
- # 正则
- 'pattern' => Dever::rule('mobile', ''),
- 'trigger' => 'blur',
- # 提示信息
- 'message' => '手机号错误',
- # 验证类型 date,array,number,boolean,integer,float,url,email,enum,string
- 'type' => 'string',
- ],
- ];
- }
- # 创建用户
- public function createUser($sales_type, $sales_id, $name, $mobile, $uid = false)
- {
- if ($uid) {
- $info = Dever::db('puser/info')->find($uid);
- if ($info) {
- if ($info['mobile'] == $mobile) {
- return false;
- } else {
- $info = Dever::db('puser/info')->find(['mobile' => $mobile, 'id' => ['!=', $info['id']]]);
- if ($info) {
- return $info['id'];
- }
- Dever::db('puser/info')->update($uid, ['mobile' => $mobile]);
- return false;
- }
- }
- }
- # 创建新账号
- $info = Dever::db('puser/info')->find(['mobile' => $mobile]);
- if ($info) {
- return $info['id'];
- } else {
- return Dever::load(\Puser\Lib\Info::class)->createUser($mobile, $sales_type, $sales_id, 0, $name);
- }
- }
- }
|