123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208 |
- <?php
- namespace app\admin\controller\user;
- use app\common\controller\Backend;
- use think\Db;
- /**
- * 会员管理
- *
- * @icon fa fa-user
- */
- class User extends Backend
- {
- /**
- * User模型对象
- * @var \app\admin\model\User
- */
- protected $model = null;
- public function _initialize()
- {
- parent::_initialize();
- $this->model = new \app\admin\model\User;
- $this->view->assign("statusList", $this->model->getStatusList());
- }
- /**
- * 查看
- */
- public function index()
- {
- //当前是否为关联查询
- $this->relationSearch = true;
- $this->selectpageFields = ['id','nickname'];
- //设置过滤方法
- $this->request->filter(['strip_tags', 'trim']);
- if (false === $this->request->isAjax()) {
- return $this->view->fetch();
- }
- //如果发送的来源是 Selectpage,则转发到 Selectpage
- if ($this->request->request('keyField')) {
- return $this->selectpage();
- }
- list($where, $sort, $order, $offset, $limit) = $this->buildparams();
- $list = $this->model
- ->with(['userwallet'])
- ->where($where)
- ->order($sort, $order)
- ->paginate($limit);
- foreach ($list as $row) {
- $row->getRelation('userwallet')->visible(['score']);
- }
- $result = ['total' => $list->total(), 'rows' => $list->items()];
- return json($result);
- }
- /**
- * 过期账号列表
- */
- public function indexguoqi()
- {
- if (false === $this->request->isAjax()) {
- return $this->view->fetch();
- }
- //用户消费额
- $user_pay = [];
- $order_map = [
- 'status' => 1,
- 'have_paid' => ['gt',0],
- ];
- $user_order = Db::name('unishop_order')->field('user_id,sum(order_price) as sum_order_price')->where($order_map)->group('user_id')->select();
- //dump($user_order);
- foreach($user_order as $order){
- $user_pay[$order['user_id']] = $order['sum_order_price'];
- }
- //dump($user_pay);
- //用户积分额
- $user_score = Db::name('user_wallet')->where('score','gt',0)->column('user_id,score');
- //dump($user_score);
- //找出那个超出2倍的
- $special_user = [];
- foreach($user_score as $user_id => $score){
- $user_pay_money = isset($user_pay[$user_id]) ? $user_pay[$user_id] : 0;
- if($score > $user_pay_money * 2){
- $special_user[] = $user_id;
- }
- }
- //dump($special_user);
- list($where, $sort, $order, $offset, $limit) = $this->buildparams();
- //用户
- $hualuo_tendays_ago = hualuo_tendays_ago();
- //dump($hualuo_tendays_ago);
- //开始列表
- $list = $this->model
- ->where('last_paytime','lt',$hualuo_tendays_ago)
- ->whereor('id','IN',$special_user)
- ->order($sort, $order)
- ->paginate($limit);
- $user_list = collection($list->items())->toArray();
- foreach($user_list as $key => &$val){
- $user_id = $val['id'];
- $val['sum_order_price'] = isset($user_pay[$user_id]) ? $user_pay[$user_id] : 0;
- $val['score'] = isset($user_score[$user_id]) ? $user_score[$user_id] : 0;
- $val['special'] = in_array($user_id,$special_user) ? '是' : '否';
- $val['tendaysago'] = date('Y-m-d H:i:s',$hualuo_tendays_ago);
- }
- //dump($user_list);
- $result = ['total' => $list->total(), 'rows' => $user_list];
- return json($result);
- }
- //获取注册链接,推荐人是此人网体下最后一个人
- public function registerurl(){
- $user_id = input('id');
- $commonuser = new \app\common\model\User();
- $down_user_ids = $commonuser->my_down_all($user_id,[$user_id]);
- $last_uid = $down_user_ids[count($down_user_ids)-1];
- $introcode = Db::name('user')->where('id',$last_uid)->value('introcode');
- $url = config('h5_url').'/#/pages/login/register?introcode='.$introcode;
- $this->assign('registerurl',$url);
- return $this->view->fetch();
- }
- /**
- * 关系转移
- */
- public function zhuanyiintro(){
- if($this->request->isPost()){
- $user_id = input('user_id');
- $new_intro_uid = input('new_intro_uid');
- //验证
- if(empty($user_id)) $this->error("请输入需要转移的用户ID");
- if(empty($new_intro_uid)) $this->error("请输入新的推荐人用户ID");
- $user = Db::name('user')->where('id',$user_id)->find();
- if(empty($user)){
- $this->error('不存在的用户');
- }
- $new_intro = Db::name('user')->where('id',$new_intro_uid)->find();
- if(empty($new_intro)){
- $this->error('不存在的新推荐人');
- }
- if($user_id == $new_intro_uid){
- $this->error('新邀请人不能是被转移用户');
- }
- $commonuser = new \app\common\model\User();
- $down_user_ids = $commonuser->my_down_all($user_id,[$user_id]);
- if(in_array($new_intro_uid,$down_user_ids)){
- $this->error('新的邀请人不能在被转移用户下级网体内,会出现内循环');
- }
- Db::startTrans();
- //我的多个下级,的推荐人,改成新人
- $my_down = Db::name('user')->where('intro_uid',$user['id'])->select();
- if(!empty($my_down)){
- $rs_down = Db::name('user')->where('intro_uid',$user['id'])->update(['intro_uid'=>$new_intro_uid]);
- if($rs_down === false){
- Db::rollback();
- $this->error('操作失败');
- }
- }
- //记录个日志
- $log = [
- 'info' => '用户['.$user['id'].']的关系被转移,其名下直推有['.implode(',',array_column($my_down,'id')).'],都改到['.$new_intro_uid.']名下',
- 'createtime' => time(),
- ];
- $log_id = Db::name('intro_log')->insertGetId($log);
- if(!$log_id){
- Db::rollback();
- $this->error('操作失败');
- }
- //提交
- Db::commit();
- $this->success('转移完成');
- }
- return $this->view->fetch();
- }
- }
|