Переглянути джерело

1. 关闭主题功能
2. 用户列表添加积分账户合计、余额账户合计

lyh 3 роки тому
батько
коміт
0ebb3f5985

+ 3 - 1
.gitignore

@@ -3,4 +3,6 @@
 .env.*.php
 .env.*.php
 .env.php
 .env.php
 .env
 .env
-
+.idea
+vendor
+runtime

+ 98 - 117
app/admin/controller/user/User.php

@@ -1,11 +1,14 @@
 <?php
 <?php
+
 namespace app\admin\controller\user;
 namespace app\admin\controller\user;
 
 
 //use app\admin\model\ActiveLog;
 //use app\admin\model\ActiveLog;
 //use app\admin\model\ActiveSet;
 //use app\admin\model\ActiveSet;
 //use app\admin\model\CoinLog;
 //use app\admin\model\CoinLog;
+use app\admin\logic\UserLogic;
 use app\common\model\MoneyLog;
 use app\common\model\MoneyLog;
 use app\common\model\ScoreLog;
 use app\common\model\ScoreLog;
+
 //use app\admin\model\UpgradeLog;
 //use app\admin\model\UpgradeLog;
 use app\common\model\ScoreLogModel;
 use app\common\model\ScoreLogModel;
 use app\common\model\User as UserModel;
 use app\common\model\User as UserModel;
@@ -25,7 +28,7 @@ use think\facade\Db;
 class User extends AdminController
 class User extends AdminController
 {
 {
 
 
-    public function __construct (App $app)
+    public function __construct(App $app)
     {
     {
         parent::__construct($app);
         parent::__construct($app);
         $this->model = new UserModel();
         $this->model = new UserModel();
@@ -40,7 +43,7 @@ class User extends AdminController
      * @throws \think\db\exception\DbException
      * @throws \think\db\exception\DbException
      * @throws \think\db\exception\ModelNotFoundException
      * @throws \think\db\exception\ModelNotFoundException
      */
      */
-    public function index ()
+    public function index()
     {
     {
         if ($this->request->isAjax()) {
         if ($this->request->isAjax()) {
             if (input('selectFields')) {
             if (input('selectFields')) {
@@ -51,27 +54,9 @@ class User extends AdminController
             if (($pid = $this->request->param('pid')) !== false && $pid)
             if (($pid = $this->request->param('pid')) !== false && $pid)
                 $where[] = ['pid', '=', $this->request->param('pid', '')];
                 $where[] = ['pid', '=', $this->request->param('pid', '')];
 
 
-
-            $count = $this->model
-                ->withJoin('userData', 'INNER')
-                ->where($where)
-                ->where($this->user_map)
-                ->count();
-            $list = $this->model
-                ->withJoin('userData', 'INNER')
-                ->where($where)
-                ->where($this->user_map)
-                ->page($page, $limit)
-                ->order($this->sort)
-                ->select();
-
-            $data = [
-                'code' => 0,
-                'msg' => Db::getLastSql(),
-                'count' => $count,
-                'data' => $list,
-            ];
-            return json($data);
+            $userLogic = new UserLogic();
+            $data      = $userLogic->getList($page, $limit, $where, $this->sort, $this->user_map);
+            return $data;
         }
         }
         return $this->fetch();
         return $this->fetch();
     }
     }
@@ -80,7 +65,7 @@ class User extends AdminController
      * 禁用用户
      * 禁用用户
      * @param $id
      * @param $id
      */
      */
-    public function forbid ($id)
+    public function forbid($id)
     {
     {
         $user = $this->model->findOrEmpty($id);
         $user = $this->model->findOrEmpty($id);
         empty($user) && $this->error('数据不存在');
         empty($user) && $this->error('数据不存在');
@@ -95,7 +80,7 @@ class User extends AdminController
      * 启用用户
      * 启用用户
      * @param $id
      * @param $id
      */
      */
-    public function enable ($id)
+    public function enable($id)
     {
     {
         $user = $this->model->findOrEmpty($id);
         $user = $this->model->findOrEmpty($id);
         empty($user) && $this->error('数据不存在');
         empty($user) && $this->error('数据不存在');
@@ -115,9 +100,9 @@ class User extends AdminController
      * @throws \think\db\exception\DbException
      * @throws \think\db\exception\DbException
      * @throws \think\db\exception\ModelNotFoundException
      * @throws \think\db\exception\ModelNotFoundException
      */
      */
-    public function details (Request $request)
+    public function details(Request $request)
     {
     {
-        $id = $request->param('id');
+        $id   = $request->param('id');
         $info = $this->model
         $info = $this->model
             ->withJoin('userData', 'INNER')
             ->withJoin('userData', 'INNER')
             ->where('id', $id)
             ->where('id', $id)
@@ -130,32 +115,29 @@ class User extends AdminController
     }
     }
 
 
 
 
-
-
-
     /**
     /**
      * 添加用户
      * 添加用户
      * @return mixed
      * @return mixed
      */
      */
-    public function add ()
+    public function add()
     {
     {
         if ($this->request->isAjax()) {
         if ($this->request->isAjax()) {
-            $post = $this->request->post();
+            $post   = $this->request->post();
             $mobile = $this->model->where('mobile', $post['mobile'])->value('id');
             $mobile = $this->model->where('mobile', $post['mobile'])->value('id');
             $mobile && $this->error('该手机号码已被注册');
             $mobile && $this->error('该手机号码已被注册');
             $invite = $this->model->where('code|px_code', $post['code'])->value('id');
             $invite = $this->model->where('code|px_code', $post['code'])->value('id');
             !$invite && $this->error('邀请人不存在');
             !$invite && $this->error('邀请人不存在');
             $this->model->startTrans();
             $this->model->startTrans();
             try {
             try {
-                $insert['mobile'] = $post['mobile'];
-                $insert['reg_ip'] = $this->request->ip();
-                $insert['avatar'] = 'http://images.yxj.hongyun63.com/user/default_avatar.jpg';
-                $insert['code'] = create_invite_code();
-                $insert['px_code'] = create_invite_code();
+                $insert['mobile']    = $post['mobile'];
+                $insert['reg_ip']    = $this->request->ip();
+                $insert['avatar']    = 'http://images.yxj.hongyun63.com/user/default_avatar.jpg';
+                $insert['code']      = create_invite_code();
+                $insert['px_code']   = create_invite_code();
                 $insert['user_type'] = 2;
                 $insert['user_type'] = 2;
-                $rz_money = 1.5 + rand(0, 30) / 100;
+                $rz_money            = 1.5 + rand(0, 30) / 100;
                 $this->model->save($insert);
                 $this->model->save($insert);
-                $uid = $this->model->id;
+                $uid       = $this->model->id;
                 $user_data = new UserData();
                 $user_data = new UserData();
                 $user_data->save(['uid' => $uid, 'rz_money' => $rz_money]); // 保存用户关联信息
                 $user_data->save(['uid' => $uid, 'rz_money' => $rz_money]); // 保存用户关联信息
                 $this->bindRelation($post['code'], $uid); // 绑定关系
                 $this->bindRelation($post['code'], $uid); // 绑定关系
@@ -173,7 +155,7 @@ class User extends AdminController
      * 邀请页面
      * 邀请页面
      * @return mixed
      * @return mixed
      */
      */
-    public function invite ()
+    public function invite()
     {
     {
         $admin = session('admin');
         $admin = session('admin');
         !$admin['user_id'] && $this->error('没有该权限');
         !$admin['user_id'] && $this->error('没有该权限');
@@ -187,7 +169,7 @@ class User extends AdminController
      * 兜底
      * 兜底
      * @return mixed
      * @return mixed
      */
      */
-    public function doudi ()
+    public function doudi()
     {
     {
         return 22;
         return 22;
         if ($this->request->isAjax()) {
         if ($this->request->isAjax()) {
@@ -195,16 +177,16 @@ class User extends AdminController
             $user = $this->model->findOrEmpty(['id' => $post['uid']]);
             $user = $this->model->findOrEmpty(['id' => $post['uid']]);
             empty($user) && $this->error('用户不存在');
             empty($user) && $this->error('用户不存在');
             $post['active'] <= 0 && $this->error('参数错误');
             $post['active'] <= 0 && $this->error('参数错误');
-            $path = trim_string($user['path'] . ',' . $user['id']);
+            $path         = trim_string($user['path'] . ',' . $user['id']);
             $path_explode = explode(',', $path);
             $path_explode = explode(',', $path);
-            $insert = [];
+            $insert       = [];
             foreach ($path_explode as $value) {
             foreach ($path_explode as $value) {
                 $insert[] = [
                 $insert[] = [
-                    'active' => $post['active'],
-                    'uid' => $value,
-                    'ip' => $this->request->ip(),
+                    'active'     => $post['active'],
+                    'uid'        => $value,
+                    'ip'         => $this->request->ip(),
                     'user_admin' => session('?admin.username') ? session('admin.username') : '',
                     'user_admin' => session('?admin.username') ? session('admin.username') : '',
-                    'from_uid' => $post['uid'],
+                    'from_uid'   => $post['uid'],
                     'failure_at' => date('Y-m-d H:i:s', time() + 86400 * 30),
                     'failure_at' => date('Y-m-d H:i:s', time() + 86400 * 30),
                 ];
                 ];
             }
             }
@@ -226,28 +208,28 @@ class User extends AdminController
      * 增加余额
      * 增加余额
      * @return mixed
      * @return mixed
      */
      */
-    public function editmoney ()
+    public function editmoney()
     {
     {
         if ($this->request->isPost()) {
         if ($this->request->isPost()) {
 
 
-            $post = $this->request->post();
-            $user = $this->model->findOrEmpty(['id' => $post['uid']]);
+            $post  = $this->request->post();
+            $user  = $this->model->findOrEmpty(['id' => $post['uid']]);
             $money = $post['money'];
             $money = $post['money'];
-            $type = $post['type'];
+            $type  = $post['type'];
             empty($user) && $this->error('用户不存在');
             empty($user) && $this->error('用户不存在');
 
 
             $this->model->startTrans();
             $this->model->startTrans();
             try {
             try {
-                if ($type == 'more'){
+                if ($type == 'more') {
                     edit_user_money(7, $post['uid'], $money);
                     edit_user_money(7, $post['uid'], $money);
-                }else {
+                } else {
                     edit_user_money(8, $post['uid'], $money);
                     edit_user_money(8, $post['uid'], $money);
                 }
                 }
 
 
                 $this->model->commit();
                 $this->model->commit();
             } catch (\Exception $e) {
             } catch (\Exception $e) {
                 $this->model->rollback();
                 $this->model->rollback();
-                $this->error('失败'.$e->getMessage());
+                $this->error('失败' . $e->getMessage());
             }
             }
             $this->success('成功');
             $this->success('成功');
         }
         }
@@ -259,14 +241,14 @@ class User extends AdminController
      * 等级设置
      * 等级设置
      * @return mixed
      * @return mixed
      */
      */
-    public function levelset ()
+    public function levelset()
     {
     {
 
 
         if ($this->request->isPost()) {
         if ($this->request->isPost()) {
 
 
-            $post = $this->request->post();
+            $post  = $this->request->post();
             $level = $post['level'];
             $level = $post['level'];
-            if ($level > 4){
+            if ($level > 4) {
                 $this->error('最高等级4级');
                 $this->error('最高等级4级');
             }
             }
 
 
@@ -275,16 +257,16 @@ class User extends AdminController
             empty($user) && $this->error('用户不存在');
             empty($user) && $this->error('用户不存在');
 
 
             $level_type = 1;
             $level_type = 1;
-            if ($level > $user['level']){
+            if ($level > $user['level']) {
                 $level_type = 2;
                 $level_type = 2;
             }
             }
             $this->model->startTrans();
             $this->model->startTrans();
             try {
             try {
-                $this->model->where('id', $post['id'])->save(['level'=>$level, 'level_type'=>$level_type]);
+                $this->model->where('id', $post['id'])->save(['level' => $level, 'level_type' => $level_type]);
                 $this->model->commit();
                 $this->model->commit();
             } catch (\Exception $e) {
             } catch (\Exception $e) {
                 $this->model->rollback();
                 $this->model->rollback();
-                $this->error('失败'.$e->getMessage());
+                $this->error('失败' . $e->getMessage());
             }
             }
             $this->success('成功');
             $this->success('成功');
         }
         }
@@ -301,7 +283,7 @@ class User extends AdminController
      * 末尾奖励
      * 末尾奖励
      * @return mixed
      * @return mixed
      */
      */
-    public function moweiscore ()
+    public function moweiscore()
     {
     {
         if ($this->request->isPost()) {
         if ($this->request->isPost()) {
             $post = $this->request->post();
             $post = $this->request->post();
@@ -316,7 +298,7 @@ class User extends AdminController
                 $this->model->commit();
                 $this->model->commit();
             } catch (\Exception $e) {
             } catch (\Exception $e) {
                 $this->model->rollback();
                 $this->model->rollback();
-                $this->error('失败'.$e->getMessage());
+                $this->error('失败' . $e->getMessage());
             }
             }
             $this->success('成功');
             $this->success('成功');
         }
         }
@@ -325,7 +307,6 @@ class User extends AdminController
     }
     }
 
 
 
 
-
     /**
     /**
      * 余额明细
      * 余额明细
      * @param MoneyLog $model
      * @param MoneyLog $model
@@ -334,19 +315,19 @@ class User extends AdminController
      * @throws \think\db\exception\DbException
      * @throws \think\db\exception\DbException
      * @throws \think\db\exception\ModelNotFoundException
      * @throws \think\db\exception\ModelNotFoundException
      */
      */
-    public function moneyLog (UserMoneyModel $model)
+    public function moneyLog(UserMoneyModel $model)
     {
     {
         if ($this->request->isAjax()) {
         if ($this->request->isAjax()) {
             if (input('selectFields')) {
             if (input('selectFields')) {
                 return $this->selectList();
                 return $this->selectList();
             }
             }
             list($page, $limit, $where) = $this->buildTableParames();
             list($page, $limit, $where) = $this->buildTableParames();
-            $where[] = ['uid', '=', $this->request->param('id', '')];
-            $count = $model
+            $where[]   = ['uid', '=', $this->request->param('id', '')];
+            $count     = $model
                 ->where($where)
                 ->where($where)
                 ->count();
                 ->count();
             $type_conf = config('type.money');
             $type_conf = config('type.money');
-            $list = $model
+            $list      = $model
                 ->where($where)
                 ->where($where)
                 ->withAttr('type', function ($value, $data) use ($type_conf) {
                 ->withAttr('type', function ($value, $data) use ($type_conf) {
                     return $type_conf[$value];
                     return $type_conf[$value];
@@ -359,11 +340,11 @@ class User extends AdminController
                 ->page($page, $limit)
                 ->page($page, $limit)
                 ->order($this->sort)
                 ->order($this->sort)
                 ->select();
                 ->select();
-            $data = [
-                'code' => 0,
-                'msg' => '',
+            $data      = [
+                'code'  => 0,
+                'msg'   => '',
                 'count' => $count,
                 'count' => $count,
-                'data' => $list,
+                'data'  => $list,
             ];
             ];
             return json($data);
             return json($data);
         }
         }
@@ -380,19 +361,19 @@ class User extends AdminController
      * @throws \think\db\exception\DbException
      * @throws \think\db\exception\DbException
      * @throws \think\db\exception\ModelNotFoundException
      * @throws \think\db\exception\ModelNotFoundException
      */
      */
-    public function lookpidlevel (Request $request)
+    public function lookpidlevel(Request $request)
     {
     {
         if ($this->request->isAjax()) {
         if ($this->request->isAjax()) {
 
 
 //            if (($pid = $this->request->param('pid')) !== false && $pid)
 //            if (($pid = $this->request->param('pid')) !== false && $pid)
 //                $where[] = ['pid', '=', $this->request->param('pid', '')];
 //                $where[] = ['pid', '=', $this->request->param('pid', '')];
-            $id = $this->request->param('id');
+            $id   = $this->request->param('id');
             $path = Db::name('user')->where('id', $id)->value('path');
             $path = Db::name('user')->where('id', $id)->value('path');
-            $arr = explode(',', $path);
+            $arr  = explode(',', $path);
 
 
-            $ids = $arr;
-            $ids = implode(',',$ids);
-            $order= 'field(id,'.$ids.')';
+            $ids   = $arr;
+            $ids   = implode(',', $ids);
+            $order = 'field(id,' . $ids . ')';
 //            return User::whereIn('id',$ids)->order(Db::raw($order))->select();
 //            return User::whereIn('id',$ids)->order(Db::raw($order))->select();
 
 
             $where = array();
             $where = array();
@@ -403,17 +384,17 @@ class User extends AdminController
                 ->withJoin('userData', 'INNER')
                 ->withJoin('userData', 'INNER')
                 ->where($where)
                 ->where($where)
                 ->count();
                 ->count();
-            $list = $this->model
+            $list  = $this->model
                 ->withJoin('userData', 'INNER')
                 ->withJoin('userData', 'INNER')
                 ->where($where)
                 ->where($where)
                 ->order(Db::raw($order))
                 ->order(Db::raw($order))
                 ->select();
                 ->select();
 
 
             $data = [
             $data = [
-                'code' => 0,
-                'msg' => '成功',
+                'code'  => 0,
+                'msg'   => '成功',
                 'count' => $count,
                 'count' => $count,
-                'data' => $list,
+                'data'  => $list,
             ];
             ];
             return json($data);
             return json($data);
         }
         }
@@ -428,19 +409,19 @@ class User extends AdminController
      * @throws \think\db\exception\DbException
      * @throws \think\db\exception\DbException
      * @throws \think\db\exception\ModelNotFoundException
      * @throws \think\db\exception\ModelNotFoundException
      */
      */
-    public function coinLog (CoinLog $model)
+    public function coinLog(CoinLog $model)
     {
     {
         if ($this->request->isAjax()) {
         if ($this->request->isAjax()) {
             if (input('selectFields')) {
             if (input('selectFields')) {
                 return $this->selectList();
                 return $this->selectList();
             }
             }
             list($page, $limit, $where) = $this->buildTableParames();
             list($page, $limit, $where) = $this->buildTableParames();
-            $where[] = ['uid', '=', $this->request->param('id', '')];
-            $count = $model
+            $where[]   = ['uid', '=', $this->request->param('id', '')];
+            $count     = $model
                 ->where($where)
                 ->where($where)
                 ->count();
                 ->count();
             $type_conf = config('type.coin');
             $type_conf = config('type.coin');
-            $list = $model
+            $list      = $model
                 ->where($where)
                 ->where($where)
                 ->withAttr('type', function ($value, $data) use ($type_conf) {
                 ->withAttr('type', function ($value, $data) use ($type_conf) {
                     return $type_conf[$value];
                     return $type_conf[$value];
@@ -453,11 +434,11 @@ class User extends AdminController
                 ->page($page, $limit)
                 ->page($page, $limit)
                 ->order($this->sort)
                 ->order($this->sort)
                 ->select();
                 ->select();
-            $data = [
-                'code' => 0,
-                'msg' => '',
+            $data      = [
+                'code'  => 0,
+                'msg'   => '',
                 'count' => $count,
                 'count' => $count,
-                'data' => $list,
+                'data'  => $list,
             ];
             ];
             return json($data);
             return json($data);
         }
         }
@@ -472,19 +453,19 @@ class User extends AdminController
      * @throws \think\db\exception\DbException
      * @throws \think\db\exception\DbException
      * @throws \think\db\exception\ModelNotFoundException
      * @throws \think\db\exception\ModelNotFoundException
      */
      */
-    public function scoreLog (ScoreLogModel $model)
+    public function scoreLog(ScoreLogModel $model)
     {
     {
         if ($this->request->isAjax()) {
         if ($this->request->isAjax()) {
             if (input('selectFields')) {
             if (input('selectFields')) {
                 return $this->selectList();
                 return $this->selectList();
             }
             }
             list($page, $limit, $where) = $this->buildTableParames();
             list($page, $limit, $where) = $this->buildTableParames();
-            $where[] = ['uid', '=', $this->request->param('id', '')];
-            $count = $model
+            $where[]   = ['uid', '=', $this->request->param('id', '')];
+            $count     = $model
                 ->where($where)
                 ->where($where)
                 ->count();
                 ->count();
             $type_conf = config('type.score');
             $type_conf = config('type.score');
-            $list = $model
+            $list      = $model
                 ->where($where)
                 ->where($where)
                 ->withAttr('type', function ($value, $data) use ($type_conf) {
                 ->withAttr('type', function ($value, $data) use ($type_conf) {
                     return $type_conf[$value];
                     return $type_conf[$value];
@@ -497,11 +478,11 @@ class User extends AdminController
                 ->page($page, $limit)
                 ->page($page, $limit)
                 ->order($this->sort)
                 ->order($this->sort)
                 ->select();
                 ->select();
-            $data = [
-                'code' => 0,
-                'msg' => '',
+            $data      = [
+                'code'  => 0,
+                'msg'   => '',
                 'count' => $count,
                 'count' => $count,
-                'data' => $list,
+                'data'  => $list,
             ];
             ];
             return json($data);
             return json($data);
         }
         }
@@ -516,19 +497,19 @@ class User extends AdminController
      * @throws \think\db\exception\DbException
      * @throws \think\db\exception\DbException
      * @throws \think\db\exception\ModelNotFoundException
      * @throws \think\db\exception\ModelNotFoundException
      */
      */
-    public function activeLog (ActiveLog $model)
+    public function activeLog(ActiveLog $model)
     {
     {
         if ($this->request->isAjax()) {
         if ($this->request->isAjax()) {
             if (input('selectFields')) {
             if (input('selectFields')) {
                 return $this->selectList();
                 return $this->selectList();
             }
             }
             list($page, $limit, $where) = $this->buildTableParames();
             list($page, $limit, $where) = $this->buildTableParames();
-            $where[] = ['uid', '=', $this->request->param('id', '')];
-            $count = $model
+            $where[]   = ['uid', '=', $this->request->param('id', '')];
+            $count     = $model
                 ->where($where)
                 ->where($where)
                 ->count();
                 ->count();
             $type_conf = config('type.active');
             $type_conf = config('type.active');
-            $list = $model
+            $list      = $model
                 ->where($where)
                 ->where($where)
                 ->withAttr('type', function ($value, $data) use ($type_conf) {
                 ->withAttr('type', function ($value, $data) use ($type_conf) {
                     return $type_conf[$value];
                     return $type_conf[$value];
@@ -541,11 +522,11 @@ class User extends AdminController
                 ->page($page, $limit)
                 ->page($page, $limit)
                 ->order($this->sort)
                 ->order($this->sort)
                 ->select();
                 ->select();
-            $data = [
-                'code' => 0,
-                'msg' => '',
+            $data      = [
+                'code'  => 0,
+                'msg'   => '',
                 'count' => $count,
                 'count' => $count,
-                'data' => $list,
+                'data'  => $list,
             ];
             ];
             return json($data);
             return json($data);
         }
         }
@@ -555,21 +536,21 @@ class User extends AdminController
     /**
     /**
      * @NodeAnotation(title="导出")
      * @NodeAnotation(title="导出")
      */
      */
-    public function export ()
+    public function export()
     {
     {
         list($page, $limit, $where) = $this->buildTableParames();
         list($page, $limit, $where) = $this->buildTableParames();
         $tableName = $this->model->getName();
         $tableName = $this->model->getName();
         $tableName = CommonTool::humpToLine(lcfirst($tableName));
         $tableName = CommonTool::humpToLine(lcfirst($tableName));
-        $prefix = config('database.connections.mysql.prefix');
-        $dbList = Db::query("show full columns from {$prefix}{$tableName}");
-        $header = [];
+        $prefix    = config('database.connections.mysql.prefix');
+        $dbList    = Db::query("show full columns from {$prefix}{$tableName}");
+        $header    = [];
         foreach ($dbList as $vo) {
         foreach ($dbList as $vo) {
             $comment = !empty($vo['Comment']) ? $vo['Comment'] : $vo['Field'];
             $comment = !empty($vo['Comment']) ? $vo['Comment'] : $vo['Field'];
             if (!in_array($vo['Field'], $this->noExportFields)) {
             if (!in_array($vo['Field'], $this->noExportFields)) {
                 $header[] = [$comment, $vo['Field']];
                 $header[] = [$comment, $vo['Field']];
             }
             }
         }
         }
-        $list = $this->model
+        $list     = $this->model
             ->where($where)
             ->where($where)
             ->withJoin('userData', 'INNER')
             ->withJoin('userData', 'INNER')
             ->where($where)
             ->where($where)
@@ -582,7 +563,7 @@ class User extends AdminController
     }
     }
 
 
 
 
-    public function teamincome (Request $request)
+    public function teamincome(Request $request)
     {
     {
         if ($this->request->isAjax()) {
         if ($this->request->isAjax()) {
 
 
@@ -590,14 +571,14 @@ class User extends AdminController
 //                $where[] = ['pid', '=', $this->request->param('pid', '')];
 //                $where[] = ['pid', '=', $this->request->param('pid', '')];
             $id = $this->request->param('id');
             $id = $this->request->param('id');
 //            $path = Db::name('user')->where('id', $id)->value('path');
 //            $path = Db::name('user')->where('id', $id)->value('path');
-            $where = array();
+            $where   = array();
             $where[] = ['team_id', '=', $id];
             $where[] = ['team_id', '=', $id];
             $where[] = ['type', '=', 5];
             $where[] = ['type', '=', 5];
-            $count = Db::name('userteam_log')
+            $count   = Db::name('userteam_log')
 //                ->withJoin('user', 'INNER')
 //                ->withJoin('user', 'INNER')
                 ->where($where)
                 ->where($where)
                 ->count();
                 ->count();
-            $list = Db::name('userteam_log')
+            $list    = Db::name('userteam_log')
 //                ->withJoin('user', 'INNER')
 //                ->withJoin('user', 'INNER')
                 ->where($where)
                 ->where($where)
                 ->order($this->sort)
                 ->order($this->sort)
@@ -605,10 +586,10 @@ class User extends AdminController
 
 
 
 
             $data = [
             $data = [
-                'code' => 0,
-                'msg' => '成功',
+                'code'  => 0,
+                'msg'   => '成功',
                 'count' => $count,
                 'count' => $count,
-                'data' => $list,
+                'data'  => $list,
             ];
             ];
             return json($data);
             return json($data);
         }
         }

+ 92 - 0
app/admin/logic/UserLogic.php

@@ -0,0 +1,92 @@
+<?php
+
+
+namespace app\admin\logic;
+
+
+use app\admin\model\dao\User;
+use app\common\model\User as UserModel;
+use think\facade\Cache;
+use think\facade\Db;
+
+class UserLogic
+{
+    public function getList($page, $limit, $where, $sort, $userMap)
+    {
+        $userDao = new User();
+        $count   = $userDao->getCount($where, $userMap);
+        $list    = $userDao->getPageList($page, $limit, $where, $sort, $userMap);
+
+        foreach ($list as &$item) {
+            //团队会员(包括1、2级和自身)的积分账户合计、余额账户合计
+            // 计算团队成员(包括1、2级和自身)ID
+
+            $teamIds = $this->getTeamMoneyAndScore($item['id']);
+
+            // 积分账户合计
+            $item['score_total'] = $teamIds['score'];
+            // 余额账户合计
+            $item['money_total'] = $teamIds['money'];
+        }
+
+        $data = [
+            'code'  => 0,
+            'msg'   => Db::getLastSql(),
+            'count' => $count,
+            'data'  => $list,
+        ];
+        return json($data);
+    }
+
+    /**
+     * 获取团队
+     * @param $uid
+     */
+    private function getTeamMoneyAndScore($uid)
+    {
+        $cacheKey = 'userLogicTeamIds_' . $uid;
+
+        if (!Cache::has($cacheKey)) {
+
+            // 自身
+            $user = Db::table(User::$table)
+                ->where('id', $uid)
+                ->field(['id', 'score', 'money'])
+                ->find();
+
+            $totalScore = $user['score'];
+            $totalMoney = $user['money'];
+
+
+            // 一级子用户
+            Db::table(User::$table)
+                ->where('pid', $uid)
+                ->field(['id', 'score', 'money'])
+                ->chunk(100, function ($users) use (&$totalScore, &$totalMoney) {
+                    foreach ($users as $user) {
+                        $uids[]     = $user['id'];
+                        $totalScore += $user['score'];
+                        $totalMoney += $user['money'];
+                    }
+
+                    // 二级子用户
+                    Db::table(User::$table)
+                        ->whereIn('pid', $uids)
+                        ->field(['id', 'score', 'money'])
+                        ->chunk(100, function ($users) use (&$totalScore, &$totalMoney) {
+                            foreach ($users as $user) {
+                                $totalScore += $user['score'];
+                                $totalMoney += $user['money'];
+                            }
+                        });
+
+                }, ['score', 'money']);
+
+            Cache::set($cacheKey, ['score' => $totalScore, 'money' => sprintf("%.2f", $totalMoney)], 5 * 60);
+        }
+
+        return Cache::get($cacheKey);
+
+    }
+
+}

+ 18 - 0
app/admin/model/dao/BaseDao.php

@@ -0,0 +1,18 @@
+<?php
+
+
+namespace app\admin\model\dao;
+
+
+use app\admin\traits\Curd;
+
+class BaseDao
+{
+
+    use Curd;
+
+    protected $model;
+
+    protected static $table;
+
+}

+ 57 - 0
app/admin/model/dao/User.php

@@ -0,0 +1,57 @@
+<?php
+
+
+namespace app\admin\model\dao;
+
+
+use app\common\model\UserModel;
+use think\facade\Db;
+
+class User extends BaseDao
+{
+
+    protected $model;
+
+    public static $table = "db_user";
+
+    public function __construct()
+    {
+        $this->model = new UserModel();
+    }
+
+    public static function getUids(array $uids)
+    {
+        return Db::table(self::$table)->whereIn('pid', $uids)->column('id');
+    }
+
+    public static function countScore(array $uids)
+    {
+
+        return Db::table(self::$table)->whereIn('id', $uids)->sum('score');
+    }
+
+    public static function countMoney(array $uids)
+    {
+        return Db::table(self::$table)->whereIn('id', $uids)->sum('money');
+    }
+
+    public function getCount($where, $userMap)
+    {
+        return $this->model
+            ->withJoin('userData', 'INNER')
+            ->where($where)
+            ->where($userMap)
+            ->count();
+    }
+
+    public function getPageList($page, $limit, $where, $sort, $userMap)
+    {
+        return $this->model
+            ->withJoin('userData', 'INNER')
+            ->where($where)
+            ->where($userMap)
+            ->page($page, $limit)
+            ->order($sort)
+            ->select();
+    }
+}

+ 2 - 2
app/admin/view/index/index.html

@@ -58,9 +58,9 @@
                         </dd>
                         </dd>
                     </dl>
                     </dl>
                 </li>
                 </li>
-                <li class="layui-nav-item layuimini-select-bgcolor" lay-unselect>
+                <!--<li class="layui-nav-item layuimini-select-bgcolor" lay-unselect>
                     <a href="javascript:;" data-bgcolor="配色方案"><i class="fa fa-ellipsis-v"></i></a>
                     <a href="javascript:;" data-bgcolor="配色方案"><i class="fa fa-ellipsis-v"></i></a>
-                </li>
+                </li>-->
             </ul>
             </ul>
         </div>
         </div>
     </div>
     </div>

+ 6 - 0
public/static/admin/js/user/user.js

@@ -85,6 +85,8 @@ define(["jquery", "easy-admin"], function ($, ea) {
 
 
                     {field: 'total_team_income', width: 220, title: '团队总充值', search: 'range'},
                     {field: 'total_team_income', width: 220, title: '团队总充值', search: 'range'},
                     {field: 'total_team_withdraw', width: 220, title: '团队总提现', search: 'range'},
                     {field: 'total_team_withdraw', width: 220, title: '团队总提现', search: 'range'},
+                    {field: 'score_total', width: 220, title: '团队会员积分账户合计', search: 'range'},
+                    {field: 'money_total', width: 220, title: '团队会员余额账户合计', search: 'range'},
 
 
 
 
                     {
                     {
@@ -110,6 +112,10 @@ define(["jquery", "easy-admin"], function ($, ea) {
                             if (ea.checkAuth('levelset', init.table_elem)) {
                             if (ea.checkAuth('levelset', init.table_elem)) {
                                 button += '<button class="layui-btn layui-btn-xs layui-btn-normal" data-open="user.user/levelset?id=' + d.id + '" data-title="等级设置">等级设置</button>';
                                 button += '<button class="layui-btn layui-btn-xs layui-btn-normal" data-open="user.user/levelset?id=' + d.id + '" data-title="等级设置">等级设置</button>';
                             }
                             }
+
+                            if (ea.checkAuth('levelset', init.table_elem)) {
+                                button += '<button class="layui-btn layui-btn-xs layui-btn-normal" data-open="user.user/levelset?id=' + d.id + '" data-title="修改手机号码">修改手机号码</button>';
+                            }
                             if (ea.checkAuth('lookpidlevel', init.table_elem)) {
                             if (ea.checkAuth('lookpidlevel', init.table_elem)) {
                                 button += '<button class="layui-btn layui-btn-xs layui-btn-normal" data-open="user.user/lookpidlevel?id=' + d.id + '" data-title="查看上级">上级</button>';
                                 button += '<button class="layui-btn layui-btn-xs layui-btn-normal" data-open="user.user/lookpidlevel?id=' + d.id + '" data-title="查看上级">上级</button>';
                             }
                             }

+ 1 - 1
public/static/plugs/lay-module/layuimini/miniAdmin.js

@@ -36,7 +36,7 @@ define(["jquery", "miniMenu", "miniTheme", "miniTab"], function ($, miniMenu, mi
             options.iniUrl = options.iniUrl || null;
             options.iniUrl = options.iniUrl || null;
             options.clearUrl = options.clearUrl || null;
             options.clearUrl = options.clearUrl || null;
             options.urlHashLocation = options.urlHashLocation || false;
             options.urlHashLocation = options.urlHashLocation || false;
-            options.bgColorDefault = options.bgColorDefault || 0;
+            options.bgColorDefault = options.bgColorDefault || 1;
             options.multiModule = options.multiModule || false;
             options.multiModule = options.multiModule || false;
             options.menuChildOpen = options.menuChildOpen || false;
             options.menuChildOpen = options.menuChildOpen || false;
             options.loadingTime = options.loadingTime || 1;
             options.loadingTime = options.loadingTime || 1;

+ 1 - 1
public/static/plugs/lay-module/layuimini/miniTheme.js

@@ -393,7 +393,7 @@ define(["jquery"], function ($) {
          * @returns {string}
          * @returns {string}
          */
          */
         buildBgColorHtml: function (options) {
         buildBgColorHtml: function (options) {
-            options.bgColorDefault = options.bgColorDefault || 0;
+            options.bgColorDefault = options.bgColorDefault || 1;
             var bgcolorId = parseInt(sessionStorage.getItem('layuiminiBgcolorId'));
             var bgcolorId = parseInt(sessionStorage.getItem('layuiminiBgcolorId'));
             if (isNaN(bgcolorId)) bgcolorId = options.bgColorDefault;
             if (isNaN(bgcolorId)) bgcolorId = options.bgColorDefault;
             var bgColorConfig = miniTheme.config();
             var bgColorConfig = miniTheme.config();