From 204e7f006d27ba942a805e0de3b6b21225292bc4 Mon Sep 17 00:00:00 2001
From: mkm <727897186@qq.com>
Date: Mon, 17 Jun 2024 17:06:25 +0800
Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E7=94=A8=E6=88=B7?=
 =?UTF-8?q?=E6=A0=87=E7=AD=BE=E5=8A=9F=E8=83=BD?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../user_label/UserLabelController.php        | 95 +++++++++++++++++++
 app/admin/lists/user_label/UserLabelLists.php | 65 +++++++++++++
 app/admin/logic/user_label/UserLabelLogic.php | 94 ++++++++++++++++++
 .../validate/user_label/UserLabelValidate.php | 84 ++++++++++++++++
 app/api/controller/store/StoreController.php  |  2 +-
 app/common/model/user_label/UserLabel.php     | 22 +++++
 6 files changed, 361 insertions(+), 1 deletion(-)
 create mode 100644 app/admin/controller/user_label/UserLabelController.php
 create mode 100644 app/admin/lists/user_label/UserLabelLists.php
 create mode 100644 app/admin/logic/user_label/UserLabelLogic.php
 create mode 100644 app/admin/validate/user_label/UserLabelValidate.php
 create mode 100644 app/common/model/user_label/UserLabel.php

diff --git a/app/admin/controller/user_label/UserLabelController.php b/app/admin/controller/user_label/UserLabelController.php
new file mode 100644
index 000000000..b03673825
--- /dev/null
+++ b/app/admin/controller/user_label/UserLabelController.php
@@ -0,0 +1,95 @@
+<?php
+
+namespace app\admin\controller\user_label;
+
+
+use app\admin\controller\BaseAdminController;
+use app\admin\lists\user_label\UserLabelLists;
+use app\admin\logic\user_label\UserLabelLogic;
+use app\admin\validate\user_label\UserLabelValidate;
+
+
+/**
+ * 用户标签控制器
+ * Class UserLabelController
+ * @package app\admin\controller\user_label
+ */
+class UserLabelController extends BaseAdminController
+{
+
+
+    /**
+     * @notes 获取用户标签列表
+     * @return \think\response\Json
+     * @author admin
+     * @date 2024/06/17 17:02
+     */
+    public function lists()
+    {
+        return $this->dataLists(new UserLabelLists());
+    }
+
+
+    /**
+     * @notes 添加用户标签
+     * @return \think\response\Json
+     * @author admin
+     * @date 2024/06/17 17:02
+     */
+    public function add()
+    {
+        $params = (new UserLabelValidate())->post()->goCheck('add');
+        $result = UserLabelLogic::add($params);
+        if (true === $result) {
+            return $this->success('添加成功', [], 1, 1);
+        }
+        return $this->fail(UserLabelLogic::getError());
+    }
+
+
+    /**
+     * @notes 编辑用户标签
+     * @return \think\response\Json
+     * @author admin
+     * @date 2024/06/17 17:02
+     */
+    public function edit()
+    {
+        $params = (new UserLabelValidate())->post()->goCheck('edit');
+        $result = UserLabelLogic::edit($params);
+        if (true === $result) {
+            return $this->success('编辑成功', [], 1, 1);
+        }
+        return $this->fail(UserLabelLogic::getError());
+    }
+
+
+    /**
+     * @notes 删除用户标签
+     * @return \think\response\Json
+     * @author admin
+     * @date 2024/06/17 17:02
+     */
+    public function delete()
+    {
+        $params = (new UserLabelValidate())->post()->goCheck('delete');
+        UserLabelLogic::delete($params);
+        return $this->success('删除成功', [], 1, 1);
+    }
+
+
+    /**
+     * @notes 获取用户标签详情
+     * @return \think\response\Json
+     * @author admin
+     * @date 2024/06/17 17:02
+     */
+    public function detail()
+    {
+        $params = (new UserLabelValidate())->goCheck('detail');
+        $result = UserLabelLogic::detail($params);
+        return $this->data($result);
+    }
+
+
+}
\ No newline at end of file
diff --git a/app/admin/lists/user_label/UserLabelLists.php b/app/admin/lists/user_label/UserLabelLists.php
new file mode 100644
index 000000000..4e142b649
--- /dev/null
+++ b/app/admin/lists/user_label/UserLabelLists.php
@@ -0,0 +1,65 @@
+<?php
+
+namespace app\admin\lists\user_label;
+
+
+use app\admin\lists\BaseAdminDataLists;
+use app\common\model\user_label\UserLabel;
+use app\common\lists\ListsSearchInterface;
+
+
+/**
+ * 用户标签列表
+ * Class UserLabelLists
+ * @package app\admin\listsuser_label
+ */
+class UserLabelLists extends BaseAdminDataLists implements ListsSearchInterface
+{
+
+
+    /**
+     * @notes 设置搜索条件
+     * @return \string[][]
+     * @author admin
+     * @date 2024/06/17 17:02
+     */
+    public function setSearch(): array
+    {
+        return [
+            '=' => ['label_name'],
+        ];
+    }
+
+
+    /**
+     * @notes 获取用户标签列表
+     * @return array
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @author admin
+     * @date 2024/06/17 17:02
+     */
+    public function lists(): array
+    {
+        return UserLabel::where($this->searchWhere)
+            ->field(['label_id', 'label_name'])
+            ->limit($this->limitOffset, $this->limitLength)
+            ->order(['label_id' => 'desc'])
+            ->select()
+            ->toArray();
+    }
+
+
+    /**
+     * @notes 获取用户标签数量
+     * @return int
+     * @author admin
+     * @date 2024/06/17 17:02
+     */
+    public function count(): int
+    {
+        return UserLabel::where($this->searchWhere)->count();
+    }
+
+}
\ No newline at end of file
diff --git a/app/admin/logic/user_label/UserLabelLogic.php b/app/admin/logic/user_label/UserLabelLogic.php
new file mode 100644
index 000000000..d8a766b7c
--- /dev/null
+++ b/app/admin/logic/user_label/UserLabelLogic.php
@@ -0,0 +1,94 @@
+<?php
+
+namespace app\admin\logic\user_label;
+
+
+use app\common\model\user_label\UserLabel;
+use app\common\logic\BaseLogic;
+use think\facade\Db;
+
+
+/**
+ * 用户标签逻辑
+ * Class UserLabelLogic
+ * @package app\admin\logic\user_label
+ */
+class UserLabelLogic extends BaseLogic
+{
+
+
+    /**
+     * @notes 添加用户标签
+     * @param array $params
+     * @return bool
+     * @author admin
+     * @date 2024/06/17 17:02
+     */
+    public static function add(array $params): bool
+    {
+        Db::startTrans();
+        try {
+            UserLabel::create([
+                'label_name' => $params['label_name']
+            ]);
+
+            Db::commit();
+            return true;
+        } catch (\Exception $e) {
+            Db::rollback();
+            self::setError($e->getMessage());
+            return false;
+        }
+    }
+
+
+    /**
+     * @notes 编辑用户标签
+     * @param array $params
+     * @return bool
+     * @author admin
+     * @date 2024/06/17 17:02
+     */
+    public static function edit(array $params): bool
+    {
+        Db::startTrans();
+        try {
+            UserLabel::where('label_id', $params['label_id'])->update([
+                'label_name' => $params['label_name']
+            ]);
+
+            Db::commit();
+            return true;
+        } catch (\Exception $e) {
+            Db::rollback();
+            self::setError($e->getMessage());
+            return false;
+        }
+    }
+
+
+    /**
+     * @notes 删除用户标签
+     * @param array $params
+     * @return bool
+     * @author admin
+     * @date 2024/06/17 17:02
+     */
+    public static function delete(array $params): bool
+    {
+        return UserLabel::destroy($params['label_id']);
+    }
+
+
+    /**
+     * @notes 获取用户标签详情
+     * @param $params
+     * @return array
+     * @author admin
+     * @date 2024/06/17 17:02
+     */
+    public static function detail($params): array
+    {
+        return UserLabel::findOrEmpty($params['label_id'])->toArray();
+    }
+}
\ No newline at end of file
diff --git a/app/admin/validate/user_label/UserLabelValidate.php b/app/admin/validate/user_label/UserLabelValidate.php
new file mode 100644
index 000000000..2289e5630
--- /dev/null
+++ b/app/admin/validate/user_label/UserLabelValidate.php
@@ -0,0 +1,84 @@
+<?php
+
+namespace app\admin\validate\user_label;
+
+
+use app\common\validate\BaseValidate;
+
+
+/**
+ * 用户标签验证器
+ * Class UserLabelValidate
+ * @package app\admin\validate\user_label
+ */
+class UserLabelValidate extends BaseValidate
+{
+
+     /**
+      * 设置校验规则
+      * @var string[]
+      */
+    protected $rule = [
+        'label_id' => 'require',
+        'label_name' => 'require',
+    ];
+
+
+    /**
+     * 参数描述
+     * @var string[]
+     */
+    protected $field = [
+        'label_id' => 'label_id',
+        'label_name' => '标签名称',
+    ];
+
+
+    /**
+     * @notes 添加场景
+     * @return UserLabelValidate
+     * @author admin
+     * @date 2024/06/17 17:02
+     */
+    public function sceneAdd()
+    {
+        return $this->only(['label_name']);
+    }
+
+
+    /**
+     * @notes 编辑场景
+     * @return UserLabelValidate
+     * @author admin
+     * @date 2024/06/17 17:02
+     */
+    public function sceneEdit()
+    {
+        return $this->only(['label_id','label_name']);
+    }
+
+
+    /**
+     * @notes 删除场景
+     * @return UserLabelValidate
+     * @author admin
+     * @date 2024/06/17 17:02
+     */
+    public function sceneDelete()
+    {
+        return $this->only(['label_id']);
+    }
+
+
+    /**
+     * @notes 详情场景
+     * @return UserLabelValidate
+     * @author admin
+     * @date 2024/06/17 17:02
+     */
+    public function sceneDetail()
+    {
+        return $this->only(['label_id']);
+    }
+
+}
\ No newline at end of file
diff --git a/app/api/controller/store/StoreController.php b/app/api/controller/store/StoreController.php
index 2334ce3aa..20e5a93a9 100644
--- a/app/api/controller/store/StoreController.php
+++ b/app/api/controller/store/StoreController.php
@@ -41,7 +41,7 @@ class StoreController extends BaseApiController
 
         $info = StoreLogic::search($where);
         if ($info) {
-            return $this->success('ok',$info?$info->toArray():[]);
+            return $this->success('ok',$info??[]);
         } else {
             return $this->fail('店铺不存在');
         }
diff --git a/app/common/model/user_label/UserLabel.php b/app/common/model/user_label/UserLabel.php
new file mode 100644
index 000000000..adeb03be2
--- /dev/null
+++ b/app/common/model/user_label/UserLabel.php
@@ -0,0 +1,22 @@
+<?php
+
+namespace app\common\model\user_label;
+
+
+use app\common\model\BaseModel;
+use think\model\concern\SoftDelete;
+
+
+/**
+ * 用户标签模型
+ * Class UserLabel
+ * @package app\common\model\user_label
+ */
+class UserLabel extends BaseModel
+{
+    use SoftDelete;
+    protected $name = 'user_label';
+    protected $deleteTime = 'delete_time';
+
+    
+}
\ No newline at end of file