Просмотр исходного кода

优化后台管理用户模块代码

lyh 3 лет назад
Родитель
Сommit
be71e153dd

+ 76 - 191
app/admin/controller/user/User.php

@@ -2,26 +2,14 @@
 
 namespace app\admin\controller\user;
 
-//use app\admin\model\ActiveLog;
-//use app\admin\model\ActiveSet;
-//use app\admin\model\CoinLog;
 use app\admin\logic\MoneyLogLogic;
 use app\admin\logic\ScoreLogLogic;
 use app\admin\logic\UserLogic;
-use app\common\model\MoneyLog;
-use app\common\model\ScoreLog;
-
-//use app\admin\model\UpgradeLog;
-use app\common\model\ScoreLogModel;
 use app\common\model\User as UserModel;
-use app\common\model\UserData;
 use app\admin\traits\Curd;
-use app\common\constants\AdminConstant;
 use app\common\controller\AdminController;
 use app\common\model\UserMoneyModel;
-use app\common\model\UserteamLogModel;
 use app\Request;
-use app\validate\admin\mall\shopOrder\EditStatus;
 use app\validate\admin\user\user\ModifyMoney;
 use app\validate\admin\user\user\ModifyScore;
 use app\validate\admin\user\user\ModifyPid;
@@ -30,7 +18,9 @@ use EasyAdmin\tool\CommonTool;
 use jianyan\excel\Excel;
 use think\App;
 use think\exception\ValidateException;
+use think\facade\Cache;
 use think\facade\Db;
+use app\admin\model\dao\User as UserDao;
 
 
 class User extends AdminController
@@ -59,6 +49,8 @@ class User extends AdminController
             }
             list($page, $limit, $where) = $this->buildTableParames();
 
+            Cache::set("USER_EXPORT", ['page' => $page, 'limit' => $limit, 'where' => $where]);
+
             if (($pid = $this->request->param('pid')) !== false && $pid)
                 $where[] = ['pid', '=', $this->request->param('pid', '')];
 
@@ -75,13 +67,11 @@ class User extends AdminController
      */
     public function forbid($id)
     {
-        $user = $this->model->findOrEmpty($id);
-        empty($user) && $this->error('数据不存在');
-        $user['status'] == 0 && $this->error('该用户已被禁用');
-        if ($this->model->where('id', $id)->save(['status' => 0]))
-            $this->success('禁用成功');
-        else
-            $this->error('禁用失败');
+        list($result, $msg) = UserLogic::forbid($id);
+        if ($result !== true) {
+            $this->error($msg);
+        }
+        $this->success($msg);
     }
 
     /**
@@ -90,44 +80,33 @@ class User extends AdminController
      */
     public function enable($id)
     {
-        $user = $this->model->findOrEmpty($id);
-        empty($user) && $this->error('数据不存在');
-        $user['status'] == 1 && $this->error('该用户已启用');
-        if ($this->model->where('id', $id)->save(['status' => 1]))
-            $this->success('启用成功');
-        else
-            $this->error('启用失败');
+        list($result, $msg) = UserLogic::enable($id);
+        if ($result !== true) {
+            $this->error($msg);
+        }
+        $this->success($msg);
+
     }
 
     /**
      * 会员详情
      * @param Request $request
-     * @param UpgradeLog $upgradeLog
      * @return mixed
-     * @throws \think\db\exception\DataNotFoundException
-     * @throws \think\db\exception\DbException
-     * @throws \think\db\exception\ModelNotFoundException
      */
     public function details(Request $request)
     {
         $id   = $request->param('id');
-        $info = $this->model
-            ->withJoin('userData', 'INNER')
-            ->where('id', $id)
-            ->find()
-            ->toArray();
-//        $upgrade_log = $upgradeLog->where('uid', $id)->order('create_at', 'desc')->select();
-//        $this->assign('upgrade_log', $upgrade_log);
+        $info = UserLogic::getUserDetail($id);
         $this->assign('info', $info);
         return $this->fetch();
     }
 
 
     /**
-     * 添加用户
+     * 添加用户(功能不存在)
      * @return mixed
      */
-    public function add()
+    /*public function add()
     {
         if ($this->request->isAjax()) {
             $post   = $this->request->post();
@@ -157,7 +136,7 @@ class User extends AdminController
             $this->success('添加成功');
         }
         return $this->fetch();
-    }
+    }*/
 
     /**
      * 邀请页面
@@ -167,7 +146,8 @@ class User extends AdminController
     {
         $admin = session('admin');
         !$admin['user_id'] && $this->error('没有该权限');
-        $user = $this->model->findOrEmpty(['id' => $admin['user_id']]);
+        $user = UserDao::getUserOrEmptyById($admin['user_id']);
+
         empty($user) && $this->error('用户信息不存在');
         $this->assign('user_id', encode($admin['user_id']));
         return $this->fetch();
@@ -213,10 +193,10 @@ class User extends AdminController
     }
 
     /**
-     * 增加余额
+     * 增加余额(功能已屏蔽)
      * @return mixed
      */
-    public function editmoney()
+    /*public function editmoney()
     {
         if ($this->request->isPost()) {
 
@@ -243,10 +223,10 @@ class User extends AdminController
         }
 
         return $this->fetch();
-    }
+    }*/
 
     /**
-     * 增加余额
+     * 修改手机号码
      * @return mixed
      */
     public function phoneset()
@@ -261,20 +241,15 @@ class User extends AdminController
                 $this->error($e->getMessage());
             }
 
-
-            $user  = $this->model->findOrEmpty(['id' => $post['id']]);
-            $phone = $post['phone'];
-            empty($user) && $this->error('用户不存在');
-
             $userLogic = new UserLogic();
-            $result    = $userLogic->modifyPhone($post['id'], $phone);
+            $result    = $userLogic->modifyPhone($post['id'], $post['phone']);
             if ($result !== true) {
                 $this->error($result);
             }
 
             $this->success('成功');
         }
-        $user = $this->model->findOrEmpty(['id' => $this->request['id']]);
+        $user = UserDao::getUserOrEmptyById($this->request['id']);
         $this->assign('info', $user);
         return $this->fetch('phoneset');
     }
@@ -288,29 +263,21 @@ class User extends AdminController
         if ($this->request->isPost()) {
 
             $post = $this->request->post();
-
             try {
-
                 validate(ModifyPid::class)->check($post);
             } catch (ValidateException $e) {
                 $this->error($e->getMessage());
             }
 
-
-            $pid  = $post['pid'];
-            $uid  = $post['id'];
-            $user = $this->model->findOrEmpty(['id' => $uid]);
-            empty($user) && $this->error('用户不存在');
-
             $userLogic = new UserLogic();
-            $result    = $userLogic->modifypid($uid, $pid);
+            $result    = $userLogic->modifypid($post['id'], $post['pid']);
             if ($result !== true) {
                 $this->error($result);
             }
 
             $this->success('成功');
         }
-        $user = $this->model->findOrEmpty(['id' => $this->request['id']]);
+        $user = UserDao::getUserOrEmptyById($this->request['id']);
         $this->assign('info', $user);
 
         return $this->fetch();
@@ -325,44 +292,26 @@ class User extends AdminController
 
         if ($this->request->isPost()) {
 
-            $post  = $this->request->post();
-            $level = $post['level'];
-            if ($level > 4) {
-                $this->error('最高等级4级');
-            }
-
-
-            $user = $this->model->findOrEmpty(['id' => $post['id']]);
-            empty($user) && $this->error('用户不存在');
+            $post = $this->request->post();
 
-            $level_type = 1;
-            if ($level > $user['level']) {
-                $level_type = 2;
-            }
-            $this->model->startTrans();
-            try {
-                $this->model->where('id', $post['id'])->save(['level' => $level, 'level_type' => $level_type]);
-                $this->model->commit();
-            } catch (\Exception $e) {
-                $this->model->rollback();
-                $this->error('失败' . $e->getMessage());
+            $result = UserLogic::levelset($post);
+            if ($result !== true) {
+                $this->error($result);
             }
             $this->success('成功');
         }
 
-
-        $user = $this->model->findOrEmpty(['id' => $this->request['id']]);
-//        $user_info = Db::name('user', $id)->find();
+        $user = UserDao::getUserOrEmptyById($this->request['id']);
         $this->assign('info', $user);
 
         return $this->fetch();
     }
 
     /**
-     * 末尾奖励
+     * 末尾奖励(功能已注释)
      * @return mixed
      */
-    public function moweiscore()
+    /*public function moweiscore()
     {
         if ($this->request->isPost()) {
             $post = $this->request->post();
@@ -383,43 +332,27 @@ class User extends AdminController
         }
 
         return $this->fetch();
-    }
+    }*/
 
 
     /**
      * 余额明细
-     * @param MoneyLog $model
+     * @param UserMoneyModel $model
      * @return mixed|\think\response\Json
      * @throws \think\db\exception\DataNotFoundException
      * @throws \think\db\exception\DbException
      * @throws \think\db\exception\ModelNotFoundException
      */
-    public function moneyLog(UserMoneyModel $model)
+    public function moneyLog()
     {
         if ($this->request->isAjax()) {
             if (input('selectFields')) {
                 return $this->selectList();
             }
             list($page, $limit, $where) = $this->buildTableParames();
-            $where[]   = ['uid', '=', $this->request->param('id', '')];
-            $count     = $model
-                ->where($where)
-                ->count();
-            $type_conf = config('type.money');
-            $list      = $model
-                ->where($where)
-                ->withAttr('type', function ($value, $data) use ($type_conf) {
-                    return $type_conf[$value];
-                })
-                ->withAttr('money', function ($value, $data) {
-                    if ($data['state'] == 2)
-                        $value = '-' . $value;
-                    return $value;
-                })
-                ->page($page, $limit)
-                ->order($this->sort)
-                ->select();
-            $data      = [
+            $where[] = ['uid', '=', $this->request->param('id', '')];
+            list($count, $list) = MoneyLogLogic::getMoneyLog($page, $limit, $where, $this->sort);
+            $data = [
                 'code'  => 0,
                 'msg'   => '',
                 'count' => $count,
@@ -433,41 +366,15 @@ class User extends AdminController
 
     /**
      * 查看上级
-     * @param Request $request
-     * @param UpgradeLog $upgradeLog
-     * @return mixed
-     * @throws \think\db\exception\DataNotFoundException
-     * @throws \think\db\exception\DbException
-     * @throws \think\db\exception\ModelNotFoundException
+     * @return mixed|\think\response\Json
      */
-    public function lookpidlevel(Request $request)
+    public function lookpidlevel()
     {
         if ($this->request->isAjax()) {
 
-//            if (($pid = $this->request->param('pid')) !== false && $pid)
-//                $where[] = ['pid', '=', $this->request->param('pid', '')];
-            $id   = $this->request->param('id');
-            $path = Db::name('user')->where('id', $id)->value('path');
-            $arr  = explode(',', $path);
-
-            $ids   = $arr;
-            $ids   = implode(',', $ids);
-            $order = 'field(id,' . $ids . ')';
-//            return User::whereIn('id',$ids)->order(Db::raw($order))->select();
-
-            $where = array();
+            $id = $this->request->param('id');
 
-            $where[] = ['uid', 'in', $arr];
-            sr_log($where);
-            $count = $this->model
-                ->withJoin('userData', 'INNER')
-                ->where($where)
-                ->count();
-            $list  = $this->model
-                ->withJoin('userData', 'INNER')
-                ->where($where)
-                ->order(Db::raw($order))
-                ->select();
+            list($count, $list) = UserLogic::lookpidlevel($id);
 
             $data = [
                 'code'  => 0,
@@ -481,14 +388,14 @@ class User extends AdminController
     }
 
     /**
-     * 元宝明细
+     * 元宝明细(功能已失效)
      * @param CoinLog $model
      * @return mixed|\think\response\Json
      * @throws \think\db\exception\DataNotFoundException
      * @throws \think\db\exception\DbException
      * @throws \think\db\exception\ModelNotFoundException
      */
-    public function coinLog(CoinLog $model)
+    /*public function coinLog(CoinLog $model)
     {
         if ($this->request->isAjax()) {
             if (input('selectFields')) {
@@ -522,42 +429,24 @@ class User extends AdminController
             return json($data);
         }
         return $this->fetch();
-    }
+    }*/
 
     /**
      * 积分明细
-     * @param ScoreLog $model
      * @return mixed|\think\response\Json
-     * @throws \think\db\exception\DataNotFoundException
-     * @throws \think\db\exception\DbException
-     * @throws \think\db\exception\ModelNotFoundException
      */
-    public function scoreLog(ScoreLogModel $model)
+    public function scoreLog()
     {
         if ($this->request->isAjax()) {
             if (input('selectFields')) {
                 return $this->selectList();
             }
             list($page, $limit, $where) = $this->buildTableParames();
-            $where[]   = ['uid', '=', $this->request->param('id', '')];
-            $count     = $model
-                ->where($where)
-                ->count();
-            $type_conf = config('type.score');
-            $list      = $model
-                ->where($where)
-                ->withAttr('type', function ($value, $data) use ($type_conf) {
-                    return $type_conf[$value];
-                })
-                ->withAttr('score', function ($value, $data) {
-                    if ($data['state'] == 2)
-                        $value = '-' . $value;
-                    return $value;
-                })
-                ->page($page, $limit)
-                ->order($this->sort)
-                ->select();
-            $data      = [
+            $where[] = ['uid', '=', $this->request->param('id', '')];
+
+            list($count, $list) = ScoreLogLogic::scoreLog($page, $limit, $where, $this->sort);
+
+            $data = [
                 'code'  => 0,
                 'msg'   => '',
                 'count' => $count,
@@ -569,14 +458,14 @@ class User extends AdminController
     }
 
     /**
-     * 积分明细
+     * 活跃明细(功能已失效)
      * @param ActiveLog $model
      * @return mixed|\think\response\Json
      * @throws \think\db\exception\DataNotFoundException
      * @throws \think\db\exception\DbException
      * @throws \think\db\exception\ModelNotFoundException
      */
-    public function activeLog(ActiveLog $model)
+    /*public function activeLog(ActiveLogModel $model)
     {
         if ($this->request->isAjax()) {
             if (input('selectFields')) {
@@ -610,7 +499,7 @@ class User extends AdminController
             return json($data);
         }
         return $this->fetch();
-    }
+    }*/
 
     /**
      * @NodeAnotation(title="导出")
@@ -618,31 +507,27 @@ class User extends AdminController
     public function export()
     {
         list($page, $limit, $where) = $this->buildTableParames();
-        $tableName = $this->model->getName();
-        $tableName = CommonTool::humpToLine(lcfirst($tableName));
-        $prefix    = config('database.connections.mysql.prefix');
-        $dbList    = Db::query("show full columns from {$prefix}{$tableName}");
-        $header    = [];
-        foreach ($dbList as $vo) {
-            $comment = !empty($vo['Comment']) ? $vo['Comment'] : $vo['Field'];
-            if (!in_array($vo['Field'], $this->noExportFields)) {
-                $header[] = [$comment, $vo['Field']];
-            }
+
+        if (empty($where)) {
+            $search = Cache::get("USER_EXPORT");
+            $page   = $search['page'];
+            $limit  = $search['limit'];
+            $where  = $search['where'];
         }
-        $list     = $this->model
-            ->where($where)
-            ->withJoin('userData', 'INNER')
-            ->where($where)
-            ->limit(100000)
-            ->order('id', 'desc')
-            ->select()
-            ->toArray();
+
+        $header = getExportHeader($this->model->getName(), $this->noExportFields);
+
+        $list     = UserLogic::getExportList($where, $page, $limit);
         $fileName = time();
         return Excel::exportData($list, $header, $fileName, 'xlsx');
     }
 
 
-    public function teamincome(Request $request)
+    /**
+     * 团队充值(已失效)
+     * @return mixed
+     */
+    /*public function teamincome(Request $request)
     {
         if ($this->request->isAjax()) {
 
@@ -673,7 +558,7 @@ class User extends AdminController
             return json($data);
         }
         return $this->fetch();
-    }
+    }*/
 
     /*
     * 修改积分
@@ -699,7 +584,7 @@ class User extends AdminController
 
             $this->success('成功');
         }
-        $user              = $this->model->findOrEmpty(['id' => $this->request['id']]);
+        $user              = UserDao::getUserOrEmptyById($this->request['id']);
         $user['type_map']  = ScoreLogLogic::getTypeMap();
         $user['state_map'] = ScoreLogLogic::getStateMap();
         $this->assign('info', $user);
@@ -731,7 +616,7 @@ class User extends AdminController
 
             $this->success('成功');
         }
-        $user              = $this->model->findOrEmpty(['id' => $this->request['id']]);
+        $user              = UserDao::getUserOrEmptyById($this->request['id']);
         $user['type_map']  = MoneyLogLogic::getTypeMap();
         $user['state_map'] = MoneyLogLogic::getStateMap();
         $this->assign('info', $user);

+ 26 - 0
app/admin/logic/MoneyLogLogic.php

@@ -8,6 +8,7 @@ use app\admin\model\dao\MoneyLog;
 use app\admin\model\dao\ScoreLog;
 use app\admin\model\dao\ShopOrder;
 use app\admin\model\dao\User;
+use app\common\model\UserMoneyModel;
 use think\facade\Cache;
 use think\facade\Db;
 
@@ -50,4 +51,29 @@ class MoneyLogLogic
     {
         return self::$typeMap;
     }
+
+    public static function getMoneyLog($page, $limit, $where, $sort)
+    {
+        $model = new UserMoneyModel();
+        $count = $model
+            ->where($where)
+            ->count();
+
+        $type_conf = config('type.money');
+
+        $list = $model
+            ->where($where)
+            ->withAttr('type', function ($value, $data) use ($type_conf) {
+                return $type_conf[$value];
+            })
+            ->withAttr('money', function ($value, $data) {
+                if ($data['state'] == 2)
+                    $value = '-' . $value;
+                return $value;
+            })
+            ->page($page, $limit)
+            ->order($sort)
+            ->select();
+        return [$count, $list];
+    }
 }

+ 25 - 0
app/admin/logic/ScoreLogLogic.php

@@ -8,6 +8,7 @@ use app\admin\model\dao\MoneyLog;
 use app\admin\model\dao\ScoreLog;
 use app\admin\model\dao\ShopOrder;
 use app\admin\model\dao\User;
+use app\common\model\ScoreLogModel;
 use think\facade\Cache;
 use think\facade\Db;
 
@@ -48,4 +49,28 @@ class ScoreLogLogic
         return self::$typeMap;
     }
 
+    public static function scoreLog(mixed $page, mixed $limit, mixed $where, array $sort)
+    {
+        $model     = new ScoreLogModel();
+        $count     = $model
+            ->where($where)
+            ->count();
+        $type_conf = config('type.score');
+        $list      = $model
+            ->where($where)
+            ->withAttr('type', function ($value, $data) use ($type_conf) {
+                return $type_conf[$value];
+            })
+            ->withAttr('score', function ($value, $data) {
+                if ($data['state'] == 2)
+                    $value = '-' . $value;
+                return $value;
+            })
+            ->page($page, $limit)
+            ->order($sort)
+            ->select();
+
+        return [$count, $list];
+    }
+
 }

+ 106 - 13
app/admin/logic/UserLogic.php

@@ -8,11 +8,108 @@ use app\admin\model\dao\MoneyLog;
 use app\admin\model\dao\ScoreLog;
 use app\admin\model\dao\User;
 use app\common\model\UserModel;
+use app\common\model\UserMoneyModel;
 use think\facade\Cache;
 use think\facade\Db;
 
 class UserLogic
 {
+    public static function forbid($id)
+    {
+        $user = User::getUserOrEmptyById($id);
+        if (empty($user)) return [false, '数据不存在'];
+
+        if ($user['status'] == 0) return [false, '该用户已被禁用'];
+
+        $result = User::updateStatus($id, 0);
+
+        return $result ? [true, '禁用成功'] : [false, '禁用失败'];
+    }
+
+    public static function enable($id)
+    {
+        $user = User::getUserOrEmptyById($id);
+        if (empty($user)) return [false, '数据不存在'];
+
+        if ($user['status'] == 1) return [false, '该用户已启用'];
+
+        $result = User::updateStatus($id, 1);
+
+        return $result ? [true, '禁用成功'] : [false, '禁用失败'];
+    }
+
+    public static function getUserDetail($id)
+    {
+        $user = new User();
+        return $user->getUserDetail($id);
+    }
+
+    public static function levelset($post)
+    {
+        $level = $post['level'];
+        if ($level > 4) {
+            return '最高等级4级';
+        }
+
+        $user = User::getUserOrEmptyById($post['id']);
+        if (empty($user)) return '用户不存在';
+
+        $level_type = 1;
+        if ($level > $user['level']) {
+            $level_type = 2;
+        }
+        Db::startTrans();
+        try {
+            $userData = ['level' => $level, 'level_type' => $level_type];
+            User::update($post['id'], $userData);
+            Db::commit();
+        } catch (\Exception $e) {
+            Db::rollback();
+            return '失败' . $e->getMessage();
+        }
+        return true;
+    }
+
+    public static function lookpidlevel($id)
+    {
+        $path = Db::name('user')->where('id', $id)->value('path');
+        $arr  = explode(',', $path);
+
+        $ids   = $arr;
+        $ids   = implode(',', $ids);
+        $order = 'field(id,' . $ids . ')';
+
+        $where = array();
+
+        $where[] = ['uid', 'in', $arr];
+        sr_log($where);
+
+        $user  = new UserModel();
+        $count = $user
+            ->withJoin('userData', 'INNER')
+            ->where($where)
+            ->count();
+
+        $list = $user
+            ->withJoin('userData', 'INNER')
+            ->where($where)
+            ->order(Db::raw($order))
+            ->select();
+        return [$count, $list];
+    }
+
+    public static function getExportList($where, $page, $limit)
+    {
+        return (new UserModel())
+            ->where($where)
+            ->withJoin('userData', 'INNER')
+            ->where($where)
+            ->page($page, $limit)
+            ->order('id', 'desc')
+            ->select()
+            ->toArray();
+    }
+
     public function getList($page, $limit, $where, $sort, $userMap)
     {
         $where[] = ['status', '<>', 3];
@@ -42,7 +139,7 @@ class UserLogic
     }
 
     /**
-     * 获取团队
+     * 获取团队自身,一级、二级自己的余额/积分
      * @param $uid
      */
     private function getTeamMoneyAndScore($uid)
@@ -101,22 +198,17 @@ class UserLogic
     {
         // 判断手机号码是否使用过
         $user = User::getUserById($uid);
-        if ($user['mobile'] == $phone) {
-            return "请输入新的手机号码";
-        }
+        if (empty($user)) return '用户不存在';
 
-        $user = User::getUserByMobile($phone);
+        if ($user['mobile'] == $phone) return "请输入新的手机号码";
 
-        if ($user) {
-            return "该手机号码已注册";
-        }
+        if (User::getUserByMobile($phone)) return "该手机号码已注册";
 
         // 修改用户信息
         try {
             $result = User::ModifyMobile($uid, $phone);
-            if (!$result) {
-                return "更新手机号码失败,请稍后重试";
-            }
+            if (!$result) return "更新手机号码失败,请稍后重试";
+
         } catch (\Exception $e) {
             return '失败' . $e->getMessage();
         }
@@ -132,9 +224,10 @@ class UserLogic
      */
     public function modifypid($uid, $pid)
     {
-        // 查询pid是否存在用户path中
         $user = User::getUserById($uid);
+        if (empty($user)) return '用户不存在';
 
+        // 查询pid是否存在用户path中
         if ($uid == $pid) {
             return "不能修改自己为上级";
         }
@@ -318,7 +411,7 @@ class UserLogic
         if (empty($user)) {
             return "用户不存在";
         }
-        if (User::updateState($id, 3) !== 1) {
+        if (User::updateStatus($id, 3) !== 1) {
             return false;
         }
         return true;

+ 29 - 7
app/admin/model/dao/User.php

@@ -44,7 +44,7 @@ class User extends BaseDao
             ->update([
                 'mobile'      => $phone,
                 'user_name'   => $phone,
-                'update_time' => date('Y-m-d H:i:s')
+                'update_time' => sr_getcurtime(time())
             ]);
     }
 
@@ -55,7 +55,7 @@ class User extends BaseDao
             ->update([
                 'pid'         => $pid,
                 'path'        => $newPathPrefix,
-                'update_time' => date('Y-m-d H:i:s')
+                'update_time' => sr_getcurtime(time())
             ]);
     }
 
@@ -65,7 +65,7 @@ class User extends BaseDao
             ->where(['id' => $id])
             ->update([
                 'path'        => $newPath,
-                'update_time' => date('Y-m-d H:i:s')
+                'update_time' => sr_getcurtime(time())
             ]);
     }
 
@@ -76,7 +76,7 @@ class User extends BaseDao
             ->where(['id' => $id])
             ->update([
                 'money'       => $money,
-                'update_time' => date('Y-m-d H:i:s')
+                'update_time' => sr_getcurtime(time())
             ]);
     }
 
@@ -86,20 +86,42 @@ class User extends BaseDao
             ->where(['id' => $id])
             ->update([
                 'score'       => $score,
-                'update_time' => date('Y-m-d H:i:s')
+                'update_time' => sr_getcurtime(time())
             ]);
     }
 
-    public static function updateState($id, int $status)
+    public static function updateStatus($id, int $status)
     {
         return Db::table(self::$table)
             ->where(['id' => $id])
             ->update([
                 'status'      => $status,
-                'update_time' => date('Y-m-d H:i:s')
+                'update_time' => sr_getcurtime(time())
             ]);
     }
 
+    public static function getUserOrEmptyById($id)
+    {
+        return (new UserModel())->findOrEmpty($id);
+    }
+
+    public static function update($id, $userData)
+    {
+        $userData['update_time'] = sr_getcurtime(time());
+        return Db::table(self::$table)
+            ->where(['id' => $id])
+            ->update($userData);
+    }
+
+    public function getUserDetail($id)
+    {
+        return $this->model
+            ->withJoin('userData', 'INNER')
+            ->where('id', $id)
+            ->find()
+            ->toArray();
+    }
+
     public function getCount($where, $userMap)
     {
         return $this->model

+ 3 - 11
app/admin/traits/Curd.php

@@ -118,17 +118,9 @@ trait Curd
     public function export()
     {
         list($page, $limit, $where) = $this->buildTableParames();
-        $tableName = $this->model->getName();
-        $tableName = CommonTool::humpToLine(lcfirst($tableName));
-        $prefix = config('database.connections.mysql.prefix');
-        $dbList = Db::query("show full columns from {$prefix}{$tableName}");
-        $header = [];
-        foreach ($dbList as $vo) {
-            $comment = !empty($vo['Comment']) ? $vo['Comment'] : $vo['Field'];
-            if (!in_array($vo['Field'], $this->noExportFields)) {
-                $header[] = [$comment, $vo['Field']];
-            }
-        }
+
+        $header = getExportHeader($modelName);
+
         $list = $this->model
             ->where($where)
             ->limit(100000)

+ 1 - 1
app/admin/view/user/user/details.html

@@ -24,7 +24,7 @@
                     <span class="layui-btn layui-btn-xs layui-btn-success">正常</span>
                     {/case}
                     {/switch}</td></p>
-                    <p class="layui-text" style="margin-bottom: 10px;"><th class="layui-font-16">个人活跃:</th><td>{$info.active_me} <button class="layui-btn layui-btn-xs layui-btn-normal" data-open="user.user/activeLog?id={$info.id}" data-title="查看活跃点明细">查看明细</button></td></p>
+                    <p class="layui-text" style="margin-bottom: 10px;"><th class="layui-font-16">个人活跃:</th><td>{$info.active_me} <button class="layui-btn layui-btn-xs layui-btn-normal" disabled data-open="user.user/activeLog?id={$info.id}" data-title="查看活跃点明细">查看明细</button></td></p>
                     <p class="layui-text" style="margin-bottom: 10px;"><th class="layui-font-16">总活跃:</th><td>{$info.total_active}</td></p>
                     </div>
             </div>

+ 20 - 0
app/common.php

@@ -2,6 +2,7 @@
 // 应用公共文件
 
 use app\common\service\AuthService;
+use EasyAdmin\tool\CommonTool;
 use Rsa\RsaClient;
 use services\CacheServices;
 use think\facade\Cache;
@@ -2442,6 +2443,25 @@ if (!function_exists('createdRechargeOrderSn')) {
 
 }
 
+if (!function_exists('getExportHeader')) {
+    function getExportHeader ($name,$noExportFields)
+    {
+        $tableName = $name;
+        $tableName = CommonTool::humpToLine(lcfirst($tableName));
+        $prefix = config('database.connections.mysql.prefix');
+        $dbList = Db::query("show full columns from {$prefix}{$tableName}");
+        $header = [];
+        foreach ($dbList as $vo) {
+            $comment = !empty($vo['Comment']) ? $vo['Comment'] : $vo['Field'];
+            if (!in_array($vo['Field'], $noExportFields)) {
+                $header[] = [$comment, $vo['Field']];
+            }
+        }
+        return $header;
+    }
+
+}
+
 
 /**
  * RSA数据加密解密