Explorar el Código

优化系统管理功能

lyh hace 3 años
padre
commit
3535f8f818
Se han modificado 37 ficheros con 871 adiciones y 281 borrados
  1. 12 17
      app/admin/controller/system/Admin.php
  2. 22 46
      app/admin/controller/system/Article.php
  3. 16 40
      app/admin/controller/system/Banner.php
  4. 0 20
      app/admin/controller/system/Config.php
  5. 16 36
      app/admin/controller/system/Faq.php
  6. 2 18
      app/admin/controller/system/Log.php
  7. 10 24
      app/admin/controller/system/Menu.php
  8. 4 4
      app/admin/controller/system/Node.php
  9. 20 43
      app/admin/controller/system/Payconfig.php
  10. 2 11
      app/admin/controller/system/Xzfenhong.php
  11. 35 0
      app/admin/logic/PayConfigLogic.php
  12. 34 0
      app/admin/logic/SystemAdminLogic.php
  13. 55 0
      app/admin/logic/SystemArticleLogic.php
  14. 19 0
      app/admin/logic/SystemAuthLogic.php
  15. 62 0
      app/admin/logic/SystemBannerLogic.php
  16. 19 0
      app/admin/logic/SystemConfigLogic.php
  17. 77 0
      app/admin/logic/SystemFaqLogic.php
  18. 43 0
      app/admin/logic/SystemLogLogic.php
  19. 54 0
      app/admin/logic/SystemMenuLogic.php
  20. 54 0
      app/admin/logic/SystemNodeLogic.php
  21. 10 1
      app/admin/logic/UserLogic.php
  22. 34 0
      app/admin/logic/UserteamLogLogic.php
  23. 2 2
      app/admin/model/dao/BaseDao.php
  24. 17 0
      app/admin/model/dao/PayConfig.php
  25. 17 0
      app/admin/model/dao/SystemAdmin.php
  26. 31 0
      app/admin/model/dao/SystemArticle.php
  27. 14 0
      app/admin/model/dao/SystemArticleType.php
  28. 17 0
      app/admin/model/dao/SystemAuth.php
  29. 17 0
      app/admin/model/dao/SystemBanner.php
  30. 17 0
      app/admin/model/dao/SystemConfig.php
  31. 31 0
      app/admin/model/dao/SystemFaq.php
  32. 17 0
      app/admin/model/dao/SystemLog.php
  33. 17 0
      app/admin/model/dao/SystemMenu.php
  34. 36 0
      app/admin/model/dao/SystemNode.php
  35. 0 18
      app/admin/model/dao/User.php
  36. 17 0
      app/admin/model/dao/UserteamLog.php
  37. 21 1
      app/common/model/SystemFaq.php

+ 12 - 17
app/admin/controller/system/Admin.php

@@ -13,6 +13,7 @@
 namespace app\admin\controller\system;
 
 
+use app\admin\logic\SystemAdminLogic;
 use app\common\model\SystemAdmin;
 use app\admin\service\TriggerService;
 use app\common\constants\AdminConstant;
@@ -53,15 +54,9 @@ class Admin extends AdminController
                 return $this->selectList();
             }
             list($page, $limit, $where) = $this->buildTableParames();
-            $count = $this->model
-                ->where($where)
-                ->count();
-            $list = $this->model
-                ->withoutField('password')
-                ->where($where)
-                ->page($page, $limit)
-                ->order($this->sort)
-                ->select();
+
+            list($count, $list) = SystemAdminLogic::getList($page, $limit, $where, $this->sort);
+
             $data = [
                 'code'  => 0,
                 'msg'   => '',
@@ -79,10 +74,10 @@ class Admin extends AdminController
     public function add()
     {
         if ($this->request->isPost()) {
-            $post = $this->request->post();
-            $authIds = $this->request->post('auth_ids', []);
+            $post             = $this->request->post();
+            $authIds          = $this->request->post('auth_ids', []);
             $post['auth_ids'] = implode(',', array_keys($authIds));
-            $rule = [];
+            $rule             = [];
             $this->validate($post, $rule);
             try {
                 $save = $this->model->save($post);
@@ -103,10 +98,10 @@ class Admin extends AdminController
         $row = $this->model->find($id);
         empty($row) && $this->error('数据不存在');
         if ($this->request->isPost()) {
-            $post = $this->request->post();
-            $authIds = $this->request->post('auth_ids', []);
+            $post             = $this->request->post();
+            $authIds          = $this->request->post('auth_ids', []);
             $post['auth_ids'] = implode(',', array_keys($authIds));
-            $rule = [];
+            $rule             = [];
             $this->validate($post, $rule);
             if (isset($row['password'])) {
                 unset($row['password']);
@@ -165,8 +160,8 @@ class Admin extends AdminController
         $row = $this->model->whereIn('id', $id)->select();
         $row->isEmpty() && $this->error('数据不存在');
         $id == AdminConstant::SUPER_ADMIN_ID && $this->error('超级管理员不允许修改');
-        if (is_array($id)){
-            if (in_array(AdminConstant::SUPER_ADMIN_ID, $id)){
+        if (is_array($id)) {
+            if (in_array(AdminConstant::SUPER_ADMIN_ID, $id)) {
                 $this->error('超级管理员不允许修改');
             }
         }

+ 22 - 46
app/admin/controller/system/Article.php

@@ -2,6 +2,10 @@
 
 namespace app\admin\controller\system;
 
+use app\admin\logic\SystemAdminLogic;
+use app\admin\logic\SystemArticleLogic;
+use app\admin\model\dao\SystemArticle;
+use app\admin\model\dao\SystemArticleType;
 use app\common\controller\AdminController;
 use app\common\model\ArticleTypeModel;
 use app\common\model\CouponPlanModel;
@@ -20,7 +24,7 @@ class Article extends AdminController
 
     use \app\admin\traits\Curd;
 
-    public function __construct (App $app)
+    public function __construct(App $app)
     {
         parent::__construct($app);
 
@@ -28,32 +32,22 @@ class Article extends AdminController
 
     }
 
-    public function index ()
+    public function index()
     {
         if ($this->request->isAjax()) {
             if (input('selectFields')) {
                 return $this->selectList();
             }
             list($page, $limit, $where) = $this->buildTableParames();
-            $count = $this->model
-                ->where($where)
-                ->count();
-//            return 11;
-
-//            return json_decode('[{"price":10, "fee":1},{"price":50, "fee":0.5},{"price":100, "fee":0}]');
-            $list = $this->model
-                ->where($where)
-                ->withAttr('type', function ($val, $data){
-                    return config('type.article')[$val]?config('type.article')[$val]:'未知类型';
-                })
-                ->page($page, $limit)
-                ->order($this->sort)
-                ->select();
+
+            list($count, $list) = SystemArticleLogic::getList($page, $limit, $where, $this->sort);
+
+
             $data = [
-                'code' => 0,
-                'msg' => '',
+                'code'  => 0,
+                'msg'   => '',
                 'count' => $count,
-                'data' => $list,
+                'data'  => $list,
             ];
             return json($data);
         }
@@ -65,7 +59,7 @@ class Article extends AdminController
     /**
      * @NodeAnotation(title="修改")
      */
-    public function edit ($id)
+    public function edit($id)
     {
         $row = $this->model->find($id);
         empty($row) && $this->error('数据不存在');
@@ -93,40 +87,22 @@ class Article extends AdminController
      */
     public function add()
     {
-        if ($this->request->isAjax()){
+        if ($this->request->isAjax()) {
             $row = request()->post();
-//            $row['img_pic'] = __HTTPSAVEIMGADMIN($row['img_pic']);
-            $row['banner_desc'] = htmlspecialchars_decode($row['banner_desc']);
-            $row['create_time'] = sr_getcurtime(time());
-            unset($row['file']);
-            $type_info = Db::name('article_type')->where('id', $row['type'])->find();
-            if ($type_info){
-                $count = $this->model->where('type', $row['type'])->count();
-                if ($count >= $type_info['max_count']){
-                    $this->error('这种类型只能存在'.$type_info['max_count'].'种');
-                }
-            }
-
-            $save = $this->model->insert($row);
-            $save?$this->success('添加成功'):$this->error('添加失败');
-
+            list($save, $msg) = SystemArticleLogic::add($row);
+            $save ? $this->success($msg) : $this->error($msg);
         }
 
         return $this->fetch();
     }
 
 
-     public function articleType()
-     {
-         $model = new ArticleTypeModel();
-         $list = $model
-             ->where('status', 1)
-             ->field('id,name')
-             ->select()
-             ->toArray();
-         $this->success('成功', $list);
+    public function articleType()
+    {
+        $list  = SystemArticle::getIdNameMapByStatus(1);
+        $this->success('成功', $list);
 
-     }
+    }
 
 
 }

+ 16 - 40
app/admin/controller/system/Banner.php

@@ -2,6 +2,7 @@
 
 namespace app\admin\controller\system;
 
+use app\admin\logic\SystemBannerLogic;
 use app\common\controller\AdminController;
 use app\common\model\SystemBannerModel;
 use think\App;
@@ -15,7 +16,7 @@ class Banner extends AdminController
 
     use \app\admin\traits\Curd;
 
-    public function __construct (App $app)
+    public function __construct(App $app)
     {
         parent::__construct($app);
 
@@ -23,32 +24,21 @@ class Banner extends AdminController
 
     }
 
-    public function index ()
+    public function index()
     {
         if ($this->request->isAjax()) {
             if (input('selectFields')) {
                 return $this->selectList();
             }
             list($page, $limit, $where) = $this->buildTableParames();
-            $count = $this->model
-                ->where($where)
-                ->count();
-//            return 11;
-
-//            return json_decode('[{"price":10, "fee":1},{"price":50, "fee":0.5},{"price":100, "fee":0}]');
-            $list = $this->model
-                ->where($where)
-                ->withAttr('img_pic', function ($val, $data){
-                    return __HTTPGETIMGADMIN($val);
-                })
-                ->page($page, $limit)
-                ->order($this->sort)
-                ->select();
+
+            list($count, $list) = SystemBannerLogic::getList($page, $limit, $where, $this->sort);
+
             $data = [
-                'code' => 0,
-                'msg' => '',
+                'code'  => 0,
+                'msg'   => '',
                 'count' => $count,
-                'data' => $list,
+                'data'  => $list,
             ];
             return json($data);
         }
@@ -60,7 +50,7 @@ class Banner extends AdminController
     /**
      * @NodeAnotation(title="修改")
      */
-    public function edit ($id)
+    public function edit($id)
     {
         $row = $this->model->find($id);
         empty($row) && $this->error('数据不存在');
@@ -68,15 +58,8 @@ class Banner extends AdminController
             $post = $this->request->post();
             $rule = [];
             $this->validate($post, $rule);
-            try {
-                $post['banner_desc'] = htmlspecialchars_decode($post['banner_desc']);
-                $post['img_pic'] = __HTTPSAVEIMGADMIN($post['img_pic']);
-                $save = $row->save($post);
-                RedisCache::clear('getAppBanner'.$row['type']);
-            } catch (\Exception $e) {
-                $this->error('保存失败');
-            }
-            $save ? $this->success('保存成功') : $this->error('保存失败');
+            $save = SystemBannerLogic::edit($post);
+            $save === true ? $this->success('保存成功') : $this->error('保存失败');
         }
         $row['img_pic'] = __HTTPGETIMGADMIN($row['img_pic']);
         $this->assign('row', $row);
@@ -88,21 +71,14 @@ class Banner extends AdminController
      */
     public function add()
     {
-        if ($this->request->isAjax()){
-            $row = request()->post();
-            $row['img_pic'] = __HTTPSAVEIMGADMIN($row['img_pic']);
-            $row['banner_desc'] = htmlspecialchars_decode($row['banner_desc']);
-            $row['create_time'] = sr_getcurtime(time());
-            unset($row['file']);
-            $save = $this->model->insert($row);
-            RedisCache::clear('getAppBanner'.$row['type']);
-            $save?$this->success('添加成功'):$this->error('添加失败');
-
+        if ($this->request->isAjax()) {
+            $row  = request()->post();
+            $save = SystemBannerLogic::add($row);
+            $save === true ? $this->success('添加成功') : $this->error('添加失败');
         }
 
         return $this->fetch();
     }
 
 
-
 }

+ 0 - 20
app/admin/controller/system/Config.php

@@ -56,27 +56,7 @@ class Config extends AdminController
         $this->checkPostRequest();
         $post = $this->request->post();
         sr_log(json_encode($post));
-//        if (isset($post['xz_min_money'])){
-//            if ($post['xz_min_money'] > $post['xz_max_money']){
-//                return $this->error('最高级不能小于最低价');
-//            }
-//            if (!($post['xz_cur_money'] < $post['xz_max_money'] && $post['xz_cur_money'] > $post['xz_min_money'])){
-//                return $this->error('当前价必须在区间之间');
-//            }
-//        }
-
-
         try {
-
-//            if (isset($post['xz_cur_money'])){
-//                // 清空所有商品详情缓存
-//                $list = Db::name('shop_goods')->where('goods_type', 5)->field('goods_id,goods_sn')->select()->toArray();
-//                foreach ($list as $key=>$val){
-//                    CacheServices::clearToken(md5('goodsDetail_' . $val['goods_sn']));
-//                }
-//
-//            }
-
             foreach ($post as $key => $val) {
                 $this->model
                     ->where('name', $key)

+ 16 - 36
app/admin/controller/system/Faq.php

@@ -2,6 +2,7 @@
 
 namespace app\admin\controller\system;
 
+use app\admin\logic\SystemFaqLogic;
 use app\common\controller\AdminController;
 use app\common\model\SystemFaq;
 use think\App;
@@ -14,7 +15,7 @@ class Faq extends AdminController
 
     use \app\admin\traits\Curd;
 
-    public function __construct (App $app)
+    public function __construct(App $app)
     {
         parent::__construct($app);
 
@@ -25,36 +26,20 @@ class Faq extends AdminController
     /**
      * @NodeAnotation(title="列表")
      */
-    public function index ()
+    public function index()
     {
         if ($this->request->isAjax()) {
             if (input('selectFields')) {
                 return $this->selectList();
             }
             list($page, $limit, $where) = $this->buildTableParames();
-            $count = $this->model
-                ->where($where)
-                ->count();
-            $list = $this->model
-                ->where($where)
-                ->page($page, $limit)
-                ->order($this->sort)
-                ->select();
-            foreach ($list as &$v) {
-                if ($v->parent_id == 0) {
-                    $v->parent_id = '最上级';
-                } else {
-                    $self = \think\facade\Db::name('system_faq')
-                        ->where(['id' => $v->parent_id])
-                        ->value('title');
-                    $v->parent_id = $self;
-                }
-            }
+
+            list($count, $list) = SystemFaqLogic::getList($page, $limit, $where, $this->sort);
             $data = [
-                'code' => 0,
-                'msg' => '',
+                'code'  => 0,
+                'msg'   => '',
                 'count' => $count,
-                'data' => $list,
+                'data'  => $list,
             ];
             return json($data);
         }
@@ -65,7 +50,7 @@ class Faq extends AdminController
     /**
      * @NodeAnotation(title="修改")
      */
-    public function edit ($id)
+    public function edit($id)
     {
         $row = $this->model->find($id);
         empty($row) && $this->error('数据不存在');
@@ -93,7 +78,7 @@ class Faq extends AdminController
     /**
      * @NodeAnotation(title="添加")
      */
-    public function add ()
+    public function add()
     {
         if ($this->request->isAjax()) {
             $post = $this->request->post();
@@ -121,7 +106,7 @@ class Faq extends AdminController
     /**
      * @NodeAnotation(title="删除")
      */
-    public function delete ($id)
+    public function delete($id)
     {
         $row = $this->model->find($id);
         if ($row->id == 1) {
@@ -144,19 +129,14 @@ class Faq extends AdminController
     /**
      * @NodeAnotation(title="选择上级")
      */
-    public function type ()
+    public function type()
     {
-        $list = \think\facade\Db::name('system_faq')
-            ->field('id,title')
-            ->where(['parent_id' => 0])
-            ->select()
-            ->toArray();
-        array_push($list, ['id' => 0, 'title' => '最上级']);
+        $list = SystemFaqLogic::getTopList();
         $data = [
-            'code' => 1,
-            'msg' => '',
+            'code'  => 1,
+            'msg'   => '',
             'count' => count($list),
-            'data' => $list,
+            'data'  => $list,
         ];
         return json($data);
     }

+ 2 - 18
app/admin/controller/system/Log.php

@@ -3,6 +3,7 @@
 namespace app\admin\controller\system;
 
 
+use app\admin\logic\SystemLogLogic;
 use app\common\model\SystemLog;
 use app\common\controller\AdminController;
 use EasyAdmin\annotation\ControllerAnnotation;
@@ -34,24 +35,7 @@ class Log extends AdminController
             }
             [$page, $limit, $where, $excludeFields] = $this->buildTableParames(['month']);
 
-            $month = (isset($excludeFields['month']) && !empty($excludeFields['month']))
-                ? date('Ym',strtotime($excludeFields['month']))
-                : date('Ym');
-
-            // todo TP6框架有一个BUG,非模型名与表名不对应时(name属性自定义),withJoin生成的sql有问题
-
-            $count = $this->model
-                ->setMonth($month)
-                ->with('admin')
-                ->where($where)
-                ->select();
-            $list = $this->model
-                ->setMonth($month)
-                ->with('admin')
-                ->where($where)
-                ->page($page, $limit)
-                ->order($this->sort)
-                ->select();
+            list($count, $list) = SystemLogLogic::getList($page, $limit, $where, $excludeFields, $this->sort);
 
             $data = [
                 'code'  => 0,

+ 10 - 24
app/admin/controller/system/Menu.php

@@ -12,6 +12,7 @@
 
 namespace app\admin\controller\system;
 
+use app\admin\logic\SystemMenuLogic;
 use app\common\model\SystemMenu;
 use app\common\model\SystemNode;
 use app\admin\service\TriggerService;
@@ -51,8 +52,8 @@ class Menu extends AdminController
             if (input('selectFields')) {
                 return $this->selectList();
             }
-            $count = $this->model->count();
-            $list = $this->model->order($this->sort)->select();
+            list($count, $list) = SystemMenuLogic::getList($this->sort);
+
             $data = [
                 'code'  => 0,
                 'msg'   => '',
@@ -85,17 +86,10 @@ class Menu extends AdminController
                 'icon|菜单图标'  => 'require',
             ];
             $this->validate($post, $rule);
-            try {
-                $save = $this->model->save($post);
-            } catch (\Exception $e) {
-                $this->error('保存失败');
-            }
-            if ($save) {
-                TriggerService::updateMenu();
-                $this->success('保存成功');
-            } else {
-                $this->error('保存失败');
-            }
+
+            $result = SystemMenuLogic::add($post);
+            $result === true ? $this->success('保存成功') : $this->error('保存失败');
+
         }
         $pidMenuList = $this->model->getPidMenuList();
         $this->assign('id', $id);
@@ -118,17 +112,9 @@ class Menu extends AdminController
                 'icon|菜单图标'  => 'require',
             ];
             $this->validate($post, $rule);
-            try {
-                $save = $row->save($post);
-            } catch (\Exception $e) {
-                $this->error('保存失败');
-            }
-            if ($save) {
-                TriggerService::updateMenu();
-                $this->success('保存成功');
-            } else {
-                $this->error('保存失败');
-            }
+
+            $result = SystemMenuLogic::edit($id, $post);
+            $result === true ? $this->success('保存成功') : $this->error('保存失败');
         }
         $pidMenuList = $this->model->getPidMenuList();
         $this->assign([

+ 4 - 4
app/admin/controller/system/Node.php

@@ -13,6 +13,7 @@
 namespace app\admin\controller\system;
 
 
+use app\admin\logic\SystemNodeLogic;
 use app\common\model\SystemNode;
 use app\admin\service\TriggerService;
 use app\common\controller\AdminController;
@@ -46,10 +47,9 @@ class Node extends AdminController
             if (input('selectFields')) {
                 return $this->selectList();
             }
-            $count = $this->model
-                ->count();
-            $list = $this->model
-                ->getNodeTreeList();
+
+            list($count,$list) = SystemNodeLogic::getList();
+
             $data = [
                 'code'  => 0,
                 'msg'   => '',

+ 20 - 43
app/admin/controller/system/Payconfig.php

@@ -2,6 +2,8 @@
 
 namespace app\admin\controller\system;
 
+use app\admin\logic\PayConfigLogic;
+use app\admin\logic\SystemFaqLogic;
 use app\common\controller\AdminController;
 use app\common\model\PayConfigModel;
 use app\common\model\SystemFaq;
@@ -15,7 +17,7 @@ class Payconfig extends AdminController
 
     use \app\admin\traits\Curd;
 
-    public function __construct (App $app)
+    public function __construct(App $app)
     {
         parent::__construct($app);
 
@@ -26,39 +28,18 @@ class Payconfig extends AdminController
     /**
      * @NodeAnotation(title="列表")
      */
-    public function index ()
+    public function index()
     {
         if ($this->request->isAjax()) {
-//            if (input('selectFields')) {
-//                return $this->selectList();
-//            }
             list($page, $limit, $where) = $this->buildTableParames();
-            $count = $this->model
-                ->where($where)
-                ->count();
-            $list = $this->model
-                ->where($where)
-                ->withAttr('channel', function ($val, $data){
-                    return $val==1?'支付宝':'微信';
-                })
-                ->page($page, $limit)
-                ->order($this->sort)
-                ->select();
-//            foreach ($list as &$v) {
-//                if ($v->parent_id == 0) {
-//                    $v->parent_id = '最上级';
-//                } else {
-//                    $self = \think\facade\Db::name('system_faq')
-//                        ->where(['id' => $v->parent_id])
-//                        ->value('title');
-//                    $v->parent_id = $self;
-//                }
-//            }
-            $data = [
-                'code' => 0,
-                'msg' => '',
+
+            list($count, $list) = PayConfigLogic::getList($page, $limit, $where, $this->sort);
+
+            $data  = [
+                'code'  => 0,
+                'msg'   => '',
                 'count' => $count,
-                'data' => $list,
+                'data'  => $list,
             ];
             return json($data);
         }
@@ -69,7 +50,7 @@ class Payconfig extends AdminController
     /**
      * @NodeAnotation(title="修改")
      */
-    public function edit ($id)
+    public function edit($id)
     {
         $row = $this->model->find($id);
         empty($row) && $this->error('数据不存在');
@@ -97,7 +78,7 @@ class Payconfig extends AdminController
     /**
      * @NodeAnotation(title="添加")
      */
-    public function add ()
+    public function add()
     {
         if ($this->request->isAjax()) {
             $post = $this->request->post();
@@ -125,7 +106,7 @@ class Payconfig extends AdminController
     /**
      * @NodeAnotation(title="删除")
      */
-    public function delete ($id)
+    public function delete($id)
     {
         $row = $this->model->find($id);
         if ($row->id == 1) {
@@ -148,19 +129,15 @@ class Payconfig extends AdminController
     /**
      * @NodeAnotation(title="选择上级")
      */
-    public function type ()
+    public function type()
     {
-        $list = \think\facade\Db::name('system_faq')
-            ->field('id,title')
-            ->where(['parent_id' => 0])
-            ->select()
-            ->toArray();
-        array_push($list, ['id' => 0, 'title' => '最上级']);
+        $list = SystemFaqLogic::getTopList();
+
         $data = [
-            'code' => 1,
-            'msg' => '',
+            'code'  => 1,
+            'msg'   => '',
             'count' => count($list),
-            'data' => $list,
+            'data'  => $list,
         ];
         return json($data);
     }

+ 2 - 11
app/admin/controller/system/Xzfenhong.php

@@ -2,6 +2,7 @@
 
 namespace app\admin\controller\system;
 
+use app\admin\logic\UserteamLogLogic;
 use app\common\controller\AdminController;
 use app\common\model\PayConfigModel;
 use app\common\model\SystemFaq;
@@ -31,19 +32,9 @@ class Xzfenhong extends AdminController
     public function index ()
     {
         if ($this->request->isAjax()) {
-//            if (input('selectFields')) {
-//                return $this->selectList();
 //            }
             list($page, $limit, $where) = $this->buildTableParames();
-            $count = $this->model
-                ->where($where)
-                ->count();
-            $list = $this->model
-                ->where($where)
-                ->where('type', 2)
-                ->page($page, $limit)
-                ->order($this->sort)
-                ->select();
+            list($count, $list) = UserteamLogLogic::getList($page, $limit, $where, $this->sort);
 
             $data = [
                 'code' => 0,

+ 35 - 0
app/admin/logic/PayConfigLogic.php

@@ -0,0 +1,35 @@
+<?php
+
+
+namespace app\admin\logic;
+
+
+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\BoxModel;
+use app\common\model\PayConfigModel;
+use app\common\model\UserMoneyModel;
+use think\facade\Cache;
+use think\facade\Db;
+
+class PayConfigLogic
+{
+
+    public static function getList( $page,  $limit,  $where,  $sort)
+    {
+        $count = (new PayConfigModel())
+            ->where($where)
+            ->count();
+        $list  = (new PayConfigModel())
+            ->where($where)
+            ->withAttr('channel', function ($val, $data) {
+                return $val == 1 ? '支付宝' : '微信';
+            })
+            ->page($page, $limit)
+            ->order($sort)
+            ->select();
+        return [$count, $list];
+    }
+}

+ 34 - 0
app/admin/logic/SystemAdminLogic.php

@@ -0,0 +1,34 @@
+<?php
+
+
+namespace app\admin\logic;
+
+
+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\admin\model\SystemAdmin;
+use app\common\model\BoxModel;
+use app\common\model\UserMoneyModel;
+use think\facade\Cache;
+use think\facade\Db;
+
+class SystemAdminLogic
+{
+
+    public static function getList($page, $limit, $where, $sort)
+    {
+        $count = (new SystemAdmin())
+            ->where($where)
+            ->count();
+
+        $list = (new SystemAdmin())
+            ->withoutField('password')
+            ->where($where)
+            ->page($page, $limit)
+            ->order($sort)
+            ->select();
+        return [$count, $list];
+    }
+}

+ 55 - 0
app/admin/logic/SystemArticleLogic.php

@@ -0,0 +1,55 @@
+<?php
+
+
+namespace app\admin\logic;
+
+
+use app\admin\model\dao\MoneyLog;
+use app\admin\model\dao\ScoreLog;
+use app\admin\model\dao\ShopOrder;
+use app\admin\model\dao\SystemArticle;
+use app\admin\model\dao\User;
+use app\common\model\BoxModel;
+use app\common\model\SystemArticleModel;
+use app\common\model\UserMoneyModel;
+use think\facade\Cache;
+use think\facade\Db;
+
+class SystemArticleLogic
+{
+
+    public static function getList($page, $limit, $where, $sort)
+    {
+        $count = (new SystemArticleModel())
+            ->where($where)
+            ->count();
+
+        $list = (new SystemArticleModel())
+            ->where($where)
+            ->withAttr('type', function ($val, $data) {
+                return config('type.article')[$val] ? config('type.article')[$val] : '未知类型';
+            })
+            ->page($page, $limit)
+            ->order($sort)
+            ->select();
+        return [$count, $list];
+    }
+
+    public static function add($row)
+    {
+        $row['banner_desc'] = htmlspecialchars_decode($row['banner_desc']);
+        $row['create_time'] = sr_getcurtime(time());
+        unset($row['file']);
+
+        $type_info = SystemArticle::getById($row['type']);
+        if ($type_info) {
+            $count = SystemArticle::count($row['type']);
+
+            if ($count >= $type_info['max_count']) {
+                return [false, '这种类型只能存在' . $type_info['max_count'] . '种'];
+            }
+        }
+
+        return (new SystemArticleModel())->insert($row);
+    }
+}

+ 19 - 0
app/admin/logic/SystemAuthLogic.php

@@ -0,0 +1,19 @@
+<?php
+
+
+namespace app\admin\logic;
+
+
+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\BoxModel;
+use app\common\model\UserMoneyModel;
+use think\facade\Cache;
+use think\facade\Db;
+
+class SystemAuthLogic
+{
+
+}

+ 62 - 0
app/admin/logic/SystemBannerLogic.php

@@ -0,0 +1,62 @@
+<?php
+
+
+namespace app\admin\logic;
+
+
+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\BoxModel;
+use app\common\model\SystemBannerModel;
+use app\common\model\UserMoneyModel;
+use think\facade\Cache;
+use think\facade\Db;
+use utils\RedisCache;
+
+class SystemBannerLogic
+{
+
+    public static function getList($page, $limit, $where, $sort)
+    {
+        $count = (new SystemBannerModel())
+            ->where($where)
+            ->count();
+
+        $list = (new SystemBannerModel())
+            ->where($where)
+            ->withAttr('img_pic', function ($val, $data) {
+                return __HTTPGETIMGADMIN($val);
+            })
+            ->page($page, $limit)
+            ->order($sort)
+            ->select();
+        return [$count, $list];
+    }
+
+    public static function edit($post)
+    {
+        $row = new SystemBannerModel();
+        try {
+            $post['banner_desc'] = htmlspecialchars_decode($post['banner_desc']);
+            $post['img_pic']     = __HTTPSAVEIMGADMIN($post['img_pic']);
+            $save                = $row->save($post);
+            RedisCache::clear('getAppBanner' . $row['type']);
+            return $save;
+        } catch (\Exception $e) {
+            return '保存失败';
+        }
+    }
+
+    public static function add($data)
+    {
+        $data['img_pic']     = __HTTPSAVEIMGADMIN($data['img_pic']);
+        $data['banner_desc'] = htmlspecialchars_decode($data['banner_desc']);
+        $data['create_time'] = sr_getcurtime(time());
+        unset($data['file']);
+        $save = (new SystemBannerModel())->insert($data);
+        RedisCache::clear('getAppBanner' . $data['type']);
+        return $save;
+    }
+}

+ 19 - 0
app/admin/logic/SystemConfigLogic.php

@@ -0,0 +1,19 @@
+<?php
+
+
+namespace app\admin\logic;
+
+
+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\BoxModel;
+use app\common\model\UserMoneyModel;
+use think\facade\Cache;
+use think\facade\Db;
+
+class SystemConfigLogic
+{
+
+}

+ 77 - 0
app/admin/logic/SystemFaqLogic.php

@@ -0,0 +1,77 @@
+<?php
+
+
+namespace app\admin\logic;
+
+use app\common\model\SystemFaq;
+use app\admin\model\dao\SystemFaq as SystemFaqDao;
+use think\facade\Cache;
+
+class SystemFaqLogic
+{
+
+    private static $CACHE_ID_KEY = "cache:system_faq:id:";
+
+    private static $CACHE_LIST_KEY = "cache:system_faq:list";
+
+
+    public static function getList($page, $limit, $where, $sort)
+    {
+        $count = (new SystemFaq())
+            ->where($where)
+            ->count();
+        $list  = (new SystemFaq())
+            ->where($where)
+            ->page($page, $limit)
+            ->order($sort)
+            ->select();
+        foreach ($list as &$v) {
+            if ($v->parent_id == 0) {
+                $v->parent_id = '最上级';
+            } else {
+                $self         = SystemFaqLogic::getTitleById($v->parent_id);
+                $v->parent_id = $self;
+            }
+        }
+        return [$count, $list];
+    }
+
+    private static function getTitleById($parent_id)
+    {
+        $key = self::$CACHE_ID_KEY . $parent_id;
+        if (Cache::has($key)) {
+            return Cache::get($key);
+        }
+        $name = SystemFaqDao::getTitleById($parent_id);
+        Cache::set($key, $name, 10 * 60);
+        return $name;
+    }
+
+    public static function delTitleCache($parent_id)
+    {
+        $key = self::$CACHE_ID_KEY . $parent_id;
+        Cache::delete($key);
+    }
+
+    public static function getTopList()
+    {
+        $key = self::$CACHE_LIST_KEY;
+        if (Cache::has($key)) {
+            return Cache::get($key);
+        }
+        $list = SystemFaqDao::getTopArrList();
+        array_push($list, ['id' => 0, 'title' => '最上级']);
+
+        Cache::set($key, $list, 10 * 60);
+        return $list;
+    }
+
+
+    public static function delCache()
+    {
+        $key = self::$CACHE_LIST_KEY;
+        Cache::delete($key);
+    }
+
+
+}

+ 43 - 0
app/admin/logic/SystemLogLogic.php

@@ -0,0 +1,43 @@
+<?php
+
+
+namespace app\admin\logic;
+
+
+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\admin\model\SystemLog;
+use app\common\model\BoxModel;
+use app\common\model\UserMoneyModel;
+use think\facade\Cache;
+use think\facade\Db;
+
+class SystemLogLogic
+{
+
+    public static function getList($page, $limit, $where, $excludeFields, $sort)
+    {
+        $month = (isset($excludeFields['month']) && !empty($excludeFields['month']))
+            ? date('Ym', strtotime($excludeFields['month']))
+            : date('Ym');
+
+        // todo TP6框架有一个BUG,非模型名与表名不对应时(name属性自定义),withJoin生成的sql有问题
+
+        $count = (new SystemLog())
+            ->setMonth($month)
+            ->with('admin')
+            ->where($where)
+            ->select();
+        $list  = (new SystemLog())
+            ->setMonth($month)
+            ->with('admin')
+            ->where($where)
+            ->page($page, $limit)
+            ->order($sort)
+            ->select();
+
+        return [$count, $list];
+    }
+}

+ 54 - 0
app/admin/logic/SystemMenuLogic.php

@@ -0,0 +1,54 @@
+<?php
+
+
+namespace app\admin\logic;
+
+
+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\admin\model\SystemMenu;
+use app\admin\service\TriggerService;
+use app\common\model\BoxModel;
+use app\common\model\UserMoneyModel;
+use think\facade\Cache;
+use think\facade\Db;
+
+class SystemMenuLogic
+{
+
+    public static function getList($sort)
+    {
+        $list = (new SystemMenu())->order($sort)->select();
+        return [$list->count(), $list];
+    }
+
+    public static function add($post)
+    {
+        try {
+            $save = (new SystemMenu())->save($post);
+        } catch (\Exception $e) {
+            return '保存失败';
+        }
+        if (!$save) return '保存失败';
+
+        TriggerService::updateMenu();
+
+        return true;
+    }
+
+    public static function edit($id, $post)
+    {
+        try {
+            $save = SystemMenu::where(['id' => $id])->save($post);
+        } catch (\Exception $e) {
+            return '保存失败';
+        }
+        if (!$save) return '保存失败';
+
+        TriggerService::updateMenu();
+
+        return true;
+    }
+}

+ 54 - 0
app/admin/logic/SystemNodeLogic.php

@@ -0,0 +1,54 @@
+<?php
+
+
+namespace app\admin\logic;
+
+
+use app\admin\model\SystemNode;
+use app\admin\service\NodeService;
+use app\admin\service\TriggerService;
+use app\admin\model\dao\SystemNode as SystemNodeDao;
+
+class SystemNodeLogic
+{
+
+    public static function getList()
+    {
+        $list = (new SystemNode())
+            ->getNodeTreeList();
+
+        return [count($list), $list];
+    }
+
+    public static function refreshNode($force)
+    {
+        $nodeList = (new NodeService())->getNodelist();
+        if (empty($nodeList)) return '暂无需要更新的系统节点';
+        $model = new SystemNode();
+        try {
+            if ($force == 1) {
+                $updateNodeList = SystemNodeDao::getNodeByNodeList($nodeList);
+                $formatNodeList = array_format_key($nodeList, 'node');
+                foreach ($updateNodeList as $vo) {
+                    if (isset($formatNodeList[$vo['node']])) {
+                        SystemNodeDao::update($vo['id'], $formatNodeList[$vo['node']]['title'], $formatNodeList[$vo['node']]['is_auth']);
+                    }
+                }
+            }
+            $existNodeList = SystemNodeDao::getNodeAndTitleAndIsAuth();
+            foreach ($nodeList as $key => $vo) {
+                foreach ($existNodeList as $v) {
+                    if ($vo['node'] == $v->node) {
+                        unset($nodeList[$key]);
+                        break;
+                    }
+                }
+            }
+            $model->saveAll($nodeList);
+            TriggerService::updateNode();
+        } catch (\Exception $e) {
+            return '节点更新失败' . $e->getMessage();
+        }
+        return true;
+    }
+}

+ 10 - 1
app/admin/logic/UserLogic.php

@@ -227,7 +227,16 @@ class UserLogic
 
         // 修改用户信息
         try {
-            $result = User::ModifyMobile($uid, $phone);
+            $updateData = [
+                'mobile' => $phone,
+            ];
+
+            // 按照账号原规则,手机号码作为用户名,同时修改新的用户名
+            if ($user['mobile'] == $user['user_name']) {
+                $updateData['user_name'] = $phone;
+            }
+
+            $result = User::update($uid, $updateData);
             if (!$result) return "更新手机号码失败,请稍后重试";
 
         } catch (\Exception $e) {

+ 34 - 0
app/admin/logic/UserteamLogLogic.php

@@ -0,0 +1,34 @@
+<?php
+
+
+namespace app\admin\logic;
+
+
+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\BoxModel;
+use app\common\model\UserFansModel;
+use app\common\model\UserMoneyModel;
+use app\common\model\UserteamLogModel;
+use think\facade\Cache;
+use think\facade\Db;
+
+class UserteamLogLogic
+{
+
+    public static function getList($page, $limit, $where, $sort)
+    {
+        $count = (new UserteamLogModel())
+            ->where($where)
+            ->count();
+        $list  = (new UserteamLogModel())
+            ->where($where)
+            ->where('type', 2)
+            ->page($page, $limit)
+            ->order($sort)
+            ->select();
+        return [$count, $list];
+    }
+}

+ 2 - 2
app/admin/model/dao/BaseDao.php

@@ -22,8 +22,8 @@ class BaseDao
         return Db::table(self::$table)->select()->toArray();
     }
 
-    public static function getById($uid)
+    public static function getById($id)
     {
-        return Db::table(self::$table)->where(['id' => $uid])->find();
+        return Db::table(self::$table)->where(['id' => $id])->find();
     }
 }

+ 17 - 0
app/admin/model/dao/PayConfig.php

@@ -0,0 +1,17 @@
+<?php
+
+
+namespace app\admin\model\dao;
+
+
+use app\common\model\UserModel;
+use think\facade\Db;
+
+class PayConfig extends BaseDao
+{
+    public static $table = "db_pay_config";
+
+    public function __construct()
+    {
+    }
+}

+ 17 - 0
app/admin/model/dao/SystemAdmin.php

@@ -0,0 +1,17 @@
+<?php
+
+
+namespace app\admin\model\dao;
+
+
+use app\common\model\UserModel;
+use think\facade\Db;
+
+class SystemAdmin extends BaseDao
+{
+    public static $table = "db_system_admin";
+
+    public function __construct()
+    {
+    }
+}

+ 31 - 0
app/admin/model/dao/SystemArticle.php

@@ -0,0 +1,31 @@
+<?php
+
+
+namespace app\admin\model\dao;
+
+
+use app\common\model\UserModel;
+use think\facade\Db;
+
+class SystemArticle extends BaseDao
+{
+    public static $table = "db_system_article";
+
+    public function __construct()
+    {
+    }
+
+    public static function count($type)
+    {
+        return $count = Db::table(self::$table)->where('type', $type)->count();
+    }
+
+    public static function getIdNameMapByStatus($int)
+    {
+        return Db::table(self::$table)
+            ->where('status', $int)
+            ->field('id,name')
+            ->select()
+            ->toArray();
+    }
+}

+ 14 - 0
app/admin/model/dao/SystemArticleType.php

@@ -0,0 +1,14 @@
+<?php
+
+
+namespace app\admin\model\dao;
+
+
+class SystemArticleType extends BaseDao
+{
+    public static $table = "db_article_type";
+
+    public function __construct()
+    {
+    }
+}

+ 17 - 0
app/admin/model/dao/SystemAuth.php

@@ -0,0 +1,17 @@
+<?php
+
+
+namespace app\admin\model\dao;
+
+
+use app\common\model\UserModel;
+use think\facade\Db;
+
+class SystemAuth extends BaseDao
+{
+    public static $table = "db_system_auth";
+
+    public function __construct()
+    {
+    }
+}

+ 17 - 0
app/admin/model/dao/SystemBanner.php

@@ -0,0 +1,17 @@
+<?php
+
+
+namespace app\admin\model\dao;
+
+
+use app\common\model\UserModel;
+use think\facade\Db;
+
+class SystemBanner extends BaseDao
+{
+    public static $table = "db_system_banner";
+
+    public function __construct()
+    {
+    }
+}

+ 17 - 0
app/admin/model/dao/SystemConfig.php

@@ -0,0 +1,17 @@
+<?php
+
+
+namespace app\admin\model\dao;
+
+
+use app\common\model\UserModel;
+use think\facade\Db;
+
+class SystemConfig extends BaseDao
+{
+    public static $table = "db_system_config";
+
+    public function __construct()
+    {
+    }
+}

+ 31 - 0
app/admin/model/dao/SystemFaq.php

@@ -0,0 +1,31 @@
+<?php
+
+
+namespace app\admin\model\dao;
+
+
+use app\common\model\UserModel;
+use think\facade\Db;
+
+class SystemFaq extends BaseDao
+{
+    public static $table = "db_system_faq";
+
+    public function __construct()
+    {
+    }
+
+    public static function getTitleById($parent_id)
+    {
+        return Db::table(self::$table)->where(['id' => $parent_id])->value('title');
+    }
+
+    public static function getTopArrList()
+    {
+        return Db::table(self::$table)
+            ->field('id,title')
+            ->where(['parent_id' => 0])
+            ->select()
+            ->toArray();
+    }
+}

+ 17 - 0
app/admin/model/dao/SystemLog.php

@@ -0,0 +1,17 @@
+<?php
+
+
+namespace app\admin\model\dao;
+
+
+use app\common\model\UserModel;
+use think\facade\Db;
+
+class SystemLog extends BaseDao
+{
+    public static $table = "db_system_log_202302_";
+
+    public function __construct()
+    {
+    }
+}

+ 17 - 0
app/admin/model/dao/SystemMenu.php

@@ -0,0 +1,17 @@
+<?php
+
+
+namespace app\admin\model\dao;
+
+
+use app\common\model\UserModel;
+use think\facade\Db;
+
+class SystemMenu extends BaseDao
+{
+    public static $table = "db_system_menu";
+
+    public function __construct()
+    {
+    }
+}

+ 36 - 0
app/admin/model/dao/SystemNode.php

@@ -0,0 +1,36 @@
+<?php
+
+
+namespace app\admin\model\dao;
+
+
+use app\common\model\UserModel;
+use think\facade\Db;
+
+class SystemNode extends BaseDao
+{
+    public static $table = "db_system_node";
+
+    public function __construct()
+    {
+    }
+
+    public static function getNodeByNodeList($nodeList)
+    {
+        return Db::table(self::$table)->whereIn('node', array_column($nodeList, 'node'))->select();
+    }
+
+    public static function update($id, $title, $is_auth)
+    {
+        Db::table(self::$table)->where('id', $id)->update([
+            'update_time' => time(),
+            'title'       => $title,
+            'is_auth'     => $is_auth,
+        ]);
+    }
+
+    public static function getNodeAndTitleAndIsAuth()
+    {
+        return Db::table(self::$table)->field('node,title,type,is_auth')->select();
+    }
+}

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

@@ -30,24 +30,6 @@ class User extends BaseDao
         return Db::table(self::$table)->where('mobile', $mobile)->find();
     }
 
-    /**
-     * 修改手机号码的时候同时修改用户名
-     * @param $uid
-     * @param $phone
-     * @return int
-     * @throws \think\db\exception\DbException
-     */
-    public static function ModifyMobile($uid, $phone)
-    {
-        return Db::table(self::$table)
-            ->where(['id' => $uid])
-            ->update([
-                'mobile'      => $phone,
-                'user_name'   => $phone,
-                'update_time' => sr_getcurtime(time())
-            ]);
-    }
-
     public static function modifyUserPidAndPath($uid, $pid, $newPathPrefix)
     {
         return Db::table(self::$table)

+ 17 - 0
app/admin/model/dao/UserteamLog.php

@@ -0,0 +1,17 @@
+<?php
+
+
+namespace app\admin\model\dao;
+
+
+use app\common\model\UserModel;
+use think\facade\Db;
+
+class UserteamLog extends BaseDao
+{
+    public static $table = "db_userteam_log";
+
+    public function __construct()
+    {
+    }
+}

+ 21 - 1
app/common/model/SystemFaq.php

@@ -6,11 +6,31 @@
 namespace app\common\model;
 
 
-use app\common\model\TimeModel;
+use app\admin\logic\SystemFaqLogic;
+use think\Model;
 
 class SystemFaq extends TimeModel
 {
     protected $name = "system_faq";
 
     protected $deleteTime = false;
+
+
+    public static function onAfterUpdate(Model $model)
+    {
+        SystemFaqLogic::delTitleCache($model->id);
+        SystemFaqLogic::delCache();
+    }
+
+    public static function onAfterInsert(Model $model): void
+    {
+        SystemFaqLogic::delTitleCache($model->id);
+        SystemFaqLogic::delCache();
+    }
+
+    public static function onAfterDelete(Model $model): void
+    {
+        SystemFaqLogic::delTitleCache($model->id);
+        SystemFaqLogic::delCache();
+    }
 }