Преглед на файлове

Merge branch 'dev_wf' of wufeng/fuse into version1.5

wufeng преди 2 години
родител
ревизия
08bc3439f1

+ 17 - 8
app/admin/config/validate_rules.php

@@ -9,6 +9,13 @@ return [
         'keyword|关键字' => 'chsDash|max:100',
         'page|页码' => 'require|number|gt:0',
         'size|每页数量' => 'require|number|elt:100',
+        'status|状态' => 'number|in:' . CommonModel::$status_normal . ',' . CommonModel::$status_disable,
+    ],
+
+    //【启禁用】
+    'status'=>[
+        'id' => 'require|number|gt:0',
+        'status|状态' => 'require|number|in:' . CommonModel::$status_normal . ',' . CommonModel::$status_disable,
     ],
 
     //【登录】
@@ -50,11 +57,6 @@ return [
         'is_show|是否显示' => 'number|in:' . AdminMenuModel::$show . ',' . AdminMenuModel::$hide,
         'weight|权重' => 'number|egt:0',
     ],
-    //启禁用菜单
-    'menuStatus' => [
-        'id' => 'require|number|gt:0',
-        'status|状态' => 'require|number|in:' . CommonModel::$status_normal . ',' . CommonModel::$status_disable,
-    ],
 
     //【视频】
     //添加视频
@@ -74,10 +76,17 @@ return [
         'weight|权重' => 'number|egt:0',
         'remark|备注' => 'max:255',
     ],
-    //视频启禁用
-    'videoChange' => [
+
+
+    //【卡类型】
+    //添加卡类型
+    'cardAdd' => [
+        'title|卡类型' => 'require|max:255'
+    ],
+    //编辑卡类型
+    'cardEdit' => [
         'id' => 'require|number|gt:0',
-        'status|状态' => 'require|number|in:' . CommonModel::$status_normal . ',' . CommonModel::$status_disable,
+        'title|卡类型' => 'require|max:255'
     ],
 
 

+ 77 - 0
app/admin/controller/Card.php

@@ -0,0 +1,77 @@
+<?php
+
+namespace app\admin\controller;
+
+use app\admin\logic\CardLogic;
+use app\BaseController;
+use think\exception\ValidateException;
+use think\facade\Config;
+use think\facade\Validate;
+
+class Card extends BaseController
+{
+
+//获取卡类型列表
+    public function cardList()
+    {
+        $param = $this->request->only(['page' => 1, 'size' => 10, 'status' => '', 'title' => '',], 'post');
+
+        $val = Validate::rule(Config::get('validate_rules.common'));
+
+        if (!$val->check($param)) throw new ValidateException($val->getError());
+
+        return CardLogic::cardList($param);
+    }
+
+//添加卡类型
+    public function cardAdd()
+    {
+        $param = $this->request->only(['title'], 'post');
+
+        $val = Validate::rule(Config::get('validate_rules.cardAdd'));
+
+        if (!$val->check($param)) throw new ValidateException($val->getError());
+
+        return CardLogic::cardAdd($param);
+
+    }
+
+//获取卡类型详情
+    public function cardRead()
+    {
+        $id = $this->request->post('id/d',0);
+        return CardLogic::cardRead($id);
+    }
+
+//编辑卡类型
+    public function cardEdit()
+    {
+        $param = $this->request->only(['id','title'], 'post');
+
+        $val = Validate::rule(Config::get('validate_rules.cardEdit'));
+
+        if (!$val->check($param)) throw new ValidateException($val->getError());
+
+        return CardLogic::cardEdit($param);
+    }
+
+//卡类型启禁用
+    public function cardChange()
+    {
+        $param = $this->request->only(['id','status'], 'post');
+
+        $val = Validate::rule(Config::get('validate_rules.status'));
+
+        if (!$val->check($param)) throw new ValidateException($val->getError());
+
+        return CardLogic::cardChange($param);
+    }
+
+//删除卡类型
+    public function cardDelete()
+    {
+        $id = $this->request->post('id/d',0);
+        return CardLogic::cardDelete($id);
+    }
+
+}

+ 1 - 1
app/admin/controller/Menu.php

@@ -77,7 +77,7 @@ class Menu extends BaseController
     {
         $param = $this->request->only(['id', 'status'], 'post');
 
-        $val = Validate::rule(Config::get('validate_rules.menuStatus'));
+        $val = Validate::rule(Config::get('validate_rules.status'));
 
         if (!$val->check($param)) throw new ValidateException($val->getError());
 

+ 2 - 1
app/admin/controller/Video.php

@@ -75,7 +75,7 @@ class Video extends BaseController
     {
         $param = $this->request->only(['id', 'status',], 'post');
 
-        $val = Validate::rule(Config::get('validate_rules.videoChange'));
+        $val = Validate::rule(Config::get('validate_rules.status'));
 
         if (!$val->check($param)) throw new ValidateException($val->getError());
         return VideoLogic::videoChange($param);
@@ -84,6 +84,7 @@ class Video extends BaseController
     //删除视频
     public function videoDelete()
     {
+        halt($this->request->uid,$this->request->uname,$this->request->roleid);
         $id = $this->request->post('id/d', 0);
         return VideoLogic::videoDelete($id);
     }

+ 20 - 0
app/admin/logic/BaseLogic.php

@@ -0,0 +1,20 @@
+<?php
+
+namespace app\admin\logic;
+
+class BaseLogic
+{
+
+    protected static $uid = 0;//当前操作的用户id
+    protected static $uname = '';//当前操作的用户名
+    protected static $roleid = 0;//当前操作的用户角色id
+
+    //设置用户信息
+    public static function setUserInfo(array $user = [])
+    {
+        self::$uid = $user['uid'];
+        self::$uname = $user['uname'];
+        self::$roleid = $user['roleid'];
+    }
+
+}

+ 124 - 0
app/admin/logic/CardLogic.php

@@ -0,0 +1,124 @@
+<?php
+
+namespace app\admin\logic;
+
+use app\model\CardModel;
+use app\model\CommonModel;
+use think\exception\ValidateException;
+use think\response\Json;
+
+class CardLogic extends BaseLogic
+{
+    //获取卡类型列表
+    public static function cardList(array $data = []): Json
+    {
+        $db = CardModel::where('is_del', CommonModel::$del_normal);
+        if ($data['title'] != '') $db->whereLike('title', '%' . $data['title'] . '%');
+        if ($data['status'] != '') $db->where('status', $data['status']);
+
+        $count = $db->count('id');
+
+        $list = $db->field('id,title,status,creater,addtime')
+            ->page($data['page'], $data['size'])
+            ->order(['id' => 'desc'])
+            ->select()
+            ->toArray();
+
+        return json_show(CommonModel::$success, '获取卡类型列表成功', ['count' => $count, 'list' => $list]);
+
+    }
+
+    //添加卡类型
+    public static function cardAdd(array $data = []): Json
+    {
+        $rs = CardModel::field('id')
+            ->where(['is_del' => CommonModel::$del_normal, 'title' => $data['title']])
+            ->findOrEmpty()
+            ->isEmpty();
+        if (!$rs) throw new ValidateException('卡类型已存在,请勿重复添加');
+
+        $data = array_merge($data, [
+            'status' => CommonModel::$status_normal,
+            'is_del' => CommonModel::$del_normal,
+            'createrid' => self::$uid,
+            'creater' => self::$uname,
+            'updaterid' => self::$uid,
+            'updater' => self::$uname,
+        ]);
+
+        $res = CardModel::create($data)->save();
+
+        return $res ? json_show(CommonModel::$success, '添加卡类型成功') : json_show(CommonModel::$error_param, '添加卡类型失败');
+    }
+
+    //获取卡类型详情
+    public static function cardRead(int $id = 0): Json
+    {
+        $rs = CardModel::field(true)
+            ->where(['id' => $id, 'is_del' => CommonModel::$del_normal])
+            ->findOrEmpty()
+            ->toArray();
+        return json_show(CommonModel::$success, '获取卡类型详情成功', $rs);
+    }
+
+    //编辑卡类型
+    public static function cardEdit(array $data = []): Json
+    {
+        $rs = CardModel::field('id,title')
+            ->where(['id' => $data['id'], 'is_del' => CommonModel::$del_normal])
+            ->findOrEmpty();
+        if ($rs->isEmpty()) throw new ValidateException('该卡类型不存在');
+
+        if ($rs->title != $data['title']) {
+            $temp = CardModel::field('id')
+                ->where(['is_del' => CommonModel::$del_normal, 'title' => $data['title']])
+                ->findOrEmpty()
+                ->isEmpty();
+            if (!$temp) throw new ValidateException('该卡类型已存在');
+        }
+
+        $data = array_merge($data, [
+            'updaterid' => self::$uid,
+            'updater' => self::$uname,
+            'updatetime' => date('Y-m-d H:i:s'),
+        ]);
+
+        $res = CardModel::where(['id' => $data['id'], 'is_del' => CommonModel::$del_normal])
+            ->save($data);
+
+        return $res ? json_show(CommonModel::$success, '编辑卡类型成功') : json_show(CommonModel::$error_param, '编辑卡类型失败');
+
+    }
+
+    //卡类型启禁用
+    public static function cardChange(array $data = []): Json
+    {
+        $where = [
+            ['id', '=', $data['id']],
+            ['is_del', '=', CommonModel::$del_normal],
+            ['status', '<>', $data['status']],
+        ];
+        $rs = CardModel::field('id,status')
+            ->where($where)
+            ->findOrEmpty()
+            ->isEmpty();
+
+        if ($rs) throw new ValidateException('该卡类型不存在或重复操作');
+
+        $res = CardModel::where($where)->save($data);
+
+        return $res ? json_show(CommonModel::$success, '操作成功') : json_show(CommonModel::$error_param, '操作失败');
+    }
+
+    //删除卡类型
+    public static function cardDelete(int $id = 0): Json
+    {
+        $rs = CardModel::where(['id' => $id, 'is_del' => CommonModel::$del_normal])
+            ->save(['is_del' => CommonModel::$del_deleted, 'updatetime' => date('Y-m-d H:i:s')]);
+
+        return $rs ? json_show(CommonModel::$success, '卡类型删除成功') : json_show(CommonModel::$error_param, '卡类型不存在或重复删除');
+
+    }
+
+
+}

+ 2 - 0
app/admin/middleware/apiMiddleware.php

@@ -2,6 +2,7 @@
 
 namespace app\admin\middleware;
 
+use app\admin\logic\BaseLogic;
 use think\Exception;
 use think\exception\ValidateException;
 use think\facade\Cache;
@@ -38,6 +39,7 @@ class apiMiddleware
 
             //获取用户信息
             $user = verifyToken($param['token']);
+            BaseLogic::setUserInfo($user);
             $request->uid = $user['uid'];
             $request->uname = $user['uname'];
             $request->roleid = $user['roleid'];

+ 7 - 0
app/admin/route/app.php

@@ -25,3 +25,10 @@ Route::rule('videoEdit', 'admin/Video/videoEdit');//编辑视频
 Route::rule('videoChange', 'admin/Video/videoChange');//视频启禁用
 Route::rule('videoDelete', 'admin/Video/videoDelete');//删除视频
 
+//【卡类型】
+Route::rule('cardList', 'admin/Card/cardList');//获取卡类型列表
+Route::rule('cardAdd', 'admin/Card/cardAdd');//添加卡类型
+Route::rule('cardRead', 'admin/Card/cardRead');//获取卡类型详情
+Route::rule('cardEdit', 'admin/Card/cardEdit');//编辑卡类型
+Route::rule('cardChange', 'admin/Card/cardChange');//卡类型启禁用
+Route::rule('cardDelete', 'admin/Card/cardDelete');//删除卡类型

+ 12 - 0
app/model/CardModel.php

@@ -0,0 +1,12 @@
+<?php
+
+namespace app\model;
+
+use think\Model;
+
+class CardModel extends Model
+{
+    protected $table = 'fc_card';
+    protected $pk = 'id';
+
+}

+ 0 - 0
public/.htaccess


+ 0 - 0
public/nginx.htaccess


BIN
public/storage/topic/20220908/456_20220908163806.png