123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- <?php
- namespace app\data\controller\user;
- use app\data\service\UserAdminService;
- use app\data\service\UserUpgradeService;
- use think\admin\Controller;
- class Admin extends Controller
- {
-
- private $table = 'DataUser';
-
- public function index()
- {
- $this->title = '普通用户管理';
- $query = $this->_query($this->table);
-
- $db = $this->_query('DataUser')->equal('vip_code#from_vipcode')->like('phone#from_phone,username|nickname#from_username')->db();
- if ($db->getOptions('where')) $query->whereRaw("pid1 in {$db->field('id')->buildSql()}");
-
- $query->like('phone,username|nickname#username')->equal('status,vip_code');
- $query->order('id desc')->dateBetween('create_at')->page();
- }
-
- protected function _page_filter(array &$data)
- {
- $this->upgrades = UserUpgradeService::instance()->levels();
- UserAdminService::instance()->buildByUid($data, 'pid1', 'from');
- }
-
- public function parent()
- {
- $data = $this->_vali(['pid.default' => '', 'uid.require' => '待操作UID不能为空']);
- if ($data['uid'] === $data['pid']) $this->error('推荐人不能是自己');
- if (empty($data['pid'])) {
- $map = [['id', '<>', $data['uid']], ['deleted', '=', 0]];
- $query = $this->_query($this->table)->where($map)->equal('status,vip_code');
- $query->like('phone,username|nickname#username')->dateBetween('create_at')->order('id desc')->page();
- } else try {
- $user = $this->app->db->name('DataUser')->where(['id' => $data['uid']])->find();
- $parent = $this->app->db->name('DataUser')->where(['id' => $data['pid']])->find();
- if (empty($user)) $this->error('读取用户数据失败!');
- if (empty($parent)) $this->error('读取推荐人数据失败!');
- $this->app->db->transaction(function () use ($data, $user, $parent) {
- if (empty($parent['vip_code'])) $this->error('推荐人无推荐资格');
- if (is_numeric(strpos($parent['path'], "-{$data['uid']}-"))) $this->error('推荐人不能绑下属');
-
- $path = rtrim($parent['path'] ?: '-', '-') . "-{$parent['id']}-";
-
- $newPath = rtrim($path, '-') . "-{$user['id']}-";
- $oldPath = rtrim($user['path'], '-') . "-{$user['id']}-";
- foreach ($this->app->db->name('DataUser')->whereLike('path', "{$oldPath}%")->cursor() as $vo) {
- dump($vo);
- }
- });
- exit;
- $this->success('修改推荐人成功!');
- } catch (\think\exception\HttpResponseException $exception) {
- throw $exception;
- } catch (\Exception $exception) {
- $this->error($exception->getMessage());
- }
- }
-
- public function sync()
- {
- $this->_queue('重新计算用户余额返利', 'xdata:UserAmount');
- }
-
- public function state()
- {
- $this->_save($this->table, $this->_vali([
- 'status.in:0,1' => '状态值范围异常!',
- 'status.require' => '状态值不能为空!',
- ]));
- }
- }
|