소스 검색

农耕分类代码

moonsflyer 9 달 전
부모
커밋
b908b9f24d

+ 137 - 0
app/adminapi/controller/agricultural_machinery/AgriculturalMachineryCategoryController.php

@@ -0,0 +1,137 @@
+<?php
+// +----------------------------------------------------------------------
+// | likeadmin快速开发前后端分离管理后台(PHP版)
+// +----------------------------------------------------------------------
+// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
+// | 开源版本可自由商用,可去除界面版权logo
+// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
+// | github下载:https://github.com/likeshop-github/likeadmin
+// | 访问官网:https://www.likeadmin.cn
+// | likeadmin团队 版权所有 拥有最终解释权
+// +----------------------------------------------------------------------
+// | author: likeadminTeam
+// +----------------------------------------------------------------------
+
+namespace app\adminapi\controller\agricultural_machinery;
+
+use app\adminapi\controller\BaseAdminController;
+use app\adminapi\lists\article\ArticleCateLists;
+use app\adminapi\lists\agricultural_machinery\AgriculturalMachineryCategoryLists;
+use app\adminapi\logic\agricultural_machinery\AgriculturalMachineryServiceCategoryLogic;
+use app\adminapi\validate\agricultural_machinery\AgriculturalMachineryServiceCategoryValidate;
+use app\adminapi\logic\article\ArticleCateLogic;
+use app\adminapi\validate\article\ArticleCateValidate;
+
+/**
+ * 农机服务分类管理控制器
+ * Class ArticleCateController
+ * @package app\adminapi\controller\article
+ */
+class AgriculturalMachineryCategoryController extends BaseAdminController
+{
+    
+    /**
+     * @notes  查看农耕分类列表
+     * @return \think\response\Json
+     * @author heshihu
+     * @date 2022/2/21 17:11
+     */
+    public function lists()
+    {
+        return $this->dataLists(new AgriculturalMachineryCategoryLists());
+    }
+
+
+    /**
+     * @notes  添加资讯分类
+     * @return \think\response\Json
+     * @author heshihu
+     * @date 2022/2/21 17:31
+     */
+    public function add()
+    {
+        $params = (new AgriculturalMachineryServiceCategoryValidate())->post()->goCheck('add');
+        AgriculturalMachineryServiceCategoryLogic::add($params);
+        return $this->success('添加成功', [], 1, 1);
+    }
+
+
+    /**
+     * @notes  编辑农耕分类
+     * @return \think\response\Json
+     * @author heshihu
+     * @date 2022/2/21 17:49
+     */
+    public function edit()
+    {
+        $params = (new AgriculturalMachineryServiceCategoryValidate())->post()->goCheck('edit');
+        $result = AgriculturalMachineryServiceCategoryLogic::edit($params);
+        if (true === $result) {
+            return $this->success('编辑成功', [], 1, 1);
+        }
+        return $this->fail(AgriculturalMachineryServiceCategoryLogic::getError());
+    }
+
+
+    /**
+     * @notes  删除农耕分类
+     * @return \think\response\Json
+     * @author heshihu
+     * @date 2022/2/21 17:52
+     */
+    public function delete()
+    {
+        $params = (new AgriculturalMachineryServiceCategoryValidate())->post()->goCheck('delete');
+        AgriculturalMachineryServiceCategoryLogic::delete($params);
+        return $this->success('删除成功', [], 1, 1);
+    }
+
+
+    /**
+     * @notes  农耕分类详情
+     * @return \think\response\Json
+     * @author heshihu
+     * @date 2022/2/21 17:54
+     */
+    public function detail()
+    {
+        $params = (new AgriculturalMachineryServiceCategoryValidate())->goCheck('detail');
+        $result = AgriculturalMachineryServiceCategoryLogic::detail($params);
+        return $this->data($result);
+    }
+
+
+    /**
+     * @notes  更改农耕分类状态
+     * @return \think\response\Json
+     * @author heshihu
+     * @date 2022/2/21 10:15
+     */
+    public function updateStatus()
+    {
+        $params = (new AgriculturalMachineryServiceCategoryValidate())->post()->goCheck('status');
+        $result = AgriculturalMachineryServiceCategoryLogic::updateStatus($params);
+        if (true === $result) {
+            return $this->success('修改成功', [], 1, 1);
+        }
+        return $this->fail(AgriculturalMachineryServiceCategoryLogic::getError());
+    }
+
+
+    /**
+     * @notes 获取农耕分类
+     * @return \think\response\Json
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @author 段誉
+     * @date 2022/10/13 10:54
+     */
+    public function getValidCate()
+    {
+        $result = AgriculturalMachineryServiceCategoryLogic::getValidCateData();
+        return $this->data($result);
+    }
+
+
+}

+ 98 - 0
app/adminapi/lists/agricultural_machinery/AgriculturalMachineryCategoryLists.php

@@ -0,0 +1,98 @@
+<?php
+// +----------------------------------------------------------------------
+// | likeadmin快速开发前后端分离管理后台(PHP版)
+// +----------------------------------------------------------------------
+// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
+// | 开源版本可自由商用,可去除界面版权logo
+// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
+// | github下载:https://github.com/likeshop-github/likeadmin
+// | 访问官网:https://www.likeadmin.cn
+// | likeadmin团队 版权所有 拥有最终解释权
+// +----------------------------------------------------------------------
+// | author: likeadminTeam
+// +----------------------------------------------------------------------
+
+namespace app\adminapi\lists\agricultural_machinery;
+
+use app\adminapi\lists\BaseAdminDataLists;
+use app\common\lists\ListsSearchInterface;
+use app\common\lists\ListsSortInterface;
+use app\common\model\article\ArticleCate;
+use app\common\model\agricultural_machinery\AgriculturalMachineryServiceCategory;
+
+/**
+ * 资讯分类列表
+ * Class ArticleCateLists
+ * @package app\adminapi\lists\article
+ */
+class AgriculturalMachineryCategoryLists extends BaseAdminDataLists implements ListsSearchInterface, ListsSortInterface
+{
+
+
+    /**
+     * @notes  设置搜索条件
+     * @return array
+     * @author heshihu
+     * @date 2022/2/8 18:39
+     */
+    public function setSearch(): array
+    {
+        return [];
+    }
+
+    /**
+     * @notes  设置支持排序字段
+     * @return array
+     * @author heshihu
+     * @date 2022/2/9 15:11
+     */
+    public function setSortFields(): array
+    {
+        return ['create_time' => 'create_time', 'id' => 'id'];
+    }
+
+    /**
+     * @notes  设置默认排序
+     * @return array
+     * @author heshihu
+     * @date 2022/2/9 15:08
+     */
+    public function setDefaultOrder(): array
+    {
+        return ['sort' => 'desc','id' => 'desc'];
+    }
+
+    /**
+     * @notes  获取管理列表
+     * @return array
+     * @author heshihu
+     * @date 2022/2/21 17:11
+     */
+    public function lists(): array
+    {
+        $ServerCateLists = AgriculturalMachineryServiceCategory::where($this->searchWhere)
+            ->limit($this->limitOffset, $this->limitLength)
+            ->order($this->sortOrder)
+            ->append(['aricultural_machinery_count','status_desc'])
+            ->select()
+            ->toArray();
+
+        return $ServerCateLists;
+    }
+
+    /**
+     * @notes  获取数量
+     * @return int
+     * @author heshihu
+     * @date 2022/2/9 15:12
+     */
+    public function count(): int
+    {
+        return AgriculturalMachineryServiceCategory::where($this->searchWhere)->count();
+    }
+
+    public function extend()
+    {
+        return [];
+    }
+}

+ 129 - 0
app/adminapi/logic/agricultural_machinery/AgriculturalMachineryServiceCategoryLogic.php

@@ -0,0 +1,129 @@
+<?php
+// +----------------------------------------------------------------------
+// | likeadmin快速开发前后端分离管理后台(PHP版)
+// +----------------------------------------------------------------------
+// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
+// | 开源版本可自由商用,可去除界面版权logo
+// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
+// | github下载:https://github.com/likeshop-github/likeadmin
+// | 访问官网:https://www.likeadmin.cn
+// | likeadmin团队 版权所有 拥有最终解释权
+// +----------------------------------------------------------------------
+// | author: likeadminTeam
+// +----------------------------------------------------------------------
+
+namespace app\adminapi\logic\agricultural_machinery;
+
+use app\common\enum\YesNoEnum;
+use app\common\logic\BaseLogic;
+use app\common\model\article\ArticleCate;
+use app\common\model\agricultural_machinery\AgriculturalMachineryServiceCategory;
+
+/**
+ * 农耕分类管理逻辑
+ * Class ArticleCateLogic
+ * @package app\adminapi\logic\article
+ */
+class AgriculturalMachineryServiceCategoryLogic extends BaseLogic
+{
+
+
+    /**
+     * @notes  添加农耕分类
+     * @param array $params
+     * @author heshihu
+     * @date 2022/2/18 10:17
+     */
+    public static function add(array $params)
+    {
+        AgriculturalMachineryServiceCategory::create([
+            'name' => $params['name'],
+            'status' => $params['status'] ?? 1,
+            'sort' => $params['sort'] ?? 0
+        ]);
+    }
+
+
+    /**
+     * @notes  编辑农耕分类
+     * @param array $params
+     * @return bool
+     * @author heshihu
+     * @date 2022/2/21 17:50
+     */
+    public static function edit(array $params) : bool
+    {
+        try {
+            AgriculturalMachineryServiceCategory::update([
+                'id' => $params['id'],
+                'name' => $params['name'],
+                'status' => $params['status'] ?? 1,
+                'sort' => $params['sort'] ?? 0
+            ]);
+            return true;
+        } catch (\Exception $e) {
+            self::setError($e->getMessage());
+            return false;
+        }
+    }
+
+
+    /**
+     * @notes  删除农耕分类
+     * @param array $params
+     * @author heshihu
+     * @date 2022/2/21 17:52
+     */
+    public static function delete(array $params)
+    {
+        AgriculturalMachineryServiceCategory::destroy($params['id']);
+    }
+
+    /**
+     * @notes  查看农耕分类详情
+     * @param $params
+     * @return array
+     * @author heshihu
+     * @date 2022/2/21 17:54
+     */
+    public static function detail($params) : array
+    {
+        return AgriculturalMachineryServiceCategory::findOrEmpty($params['id'])->toArray();
+    }
+
+    /**
+     * @notes  更改农耕分类状态
+     * @param array $params
+     * @return bool
+     * @author heshihu
+     * @date 2022/2/21 18:04
+     */
+    public static function updateStatus(array $params)
+    {
+        AgriculturalMachineryServiceCategory::update([
+            'id' => $params['id'],
+            'status' => $params['status']
+        ]);
+        return true;
+    }
+
+
+    /**
+     * @notes 有效农耕分类数据
+     * @return array
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @author 段誉
+     * @date 2022/10/13 10:53
+     */
+    public static function getValidCateData()
+    {
+        return AgriculturalMachineryServiceCategory::where(['status' => YesNoEnum::YES])
+            ->field('id,name')
+            ->order(['sort' => 'desc', 'id' => 'desc'])
+            ->select()
+            ->toArray();
+    }
+
+}

+ 137 - 0
app/adminapi/validate/agricultural_machinery/AgriculturalMachineryServiceCategoryValidate.php

@@ -0,0 +1,137 @@
+<?php
+// +----------------------------------------------------------------------
+// | likeadmin快速开发前后端分离管理后台(PHP版)
+// +----------------------------------------------------------------------
+// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
+// | 开源版本可自由商用,可去除界面版权logo
+// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
+// | github下载:https://github.com/likeshop-github/likeadmin
+// | 访问官网:https://www.likeadmin.cn
+// | likeadmin团队 版权所有 拥有最终解释权
+// +----------------------------------------------------------------------
+// | author: likeadminTeam
+// +----------------------------------------------------------------------
+
+namespace app\adminapi\validate\agricultural_machinery;
+
+use app\common\validate\BaseValidate;
+use app\common\model\article\ArticleCate;
+use app\common\model\agricultural_machinery\AgriculturalMachineryServiceCategory;
+use app\common\model\article\Article;
+
+/**
+ * 农耕分类管理验证
+ * Class ArticleCateValidate
+ * @package app\adminapi\validate\article
+ */
+class AgriculturalMachineryServiceCategoryValidate extends BaseValidate
+{
+    protected $rule = [
+        'id' => 'require|checkMachineryCate',
+        'name' => 'require|length:1,60',
+        'status' => 'require|in:0,1',
+        'sort' => 'egt:0',
+    ];
+
+    protected $message = [
+        'id.require' => ' 农耕分类id不能为空',
+        'name.require' => '农耕分类名称不能为空',
+        'name.length' => '农耕分类长度须在1-60位字符',
+        'sort.egt' => '排序值不正确',
+    ];
+
+    /**
+     * @notes  添加场景
+     * @return ArticleCateValidate
+     * @author heshihu
+     * @date 2022/2/10 15:11
+     */
+    public function sceneAdd()
+    {
+        return $this->remove(['id'])
+            ->remove('id', 'require|checkMachineryCate');
+    }
+
+    /**
+     * @notes  详情场景
+     * @return ArticleCateValidate
+     * @author heshihu
+     * @date 2022/2/21 17:55
+     */
+    public function sceneDetail()
+    {
+        return $this->only(['id']);
+    }
+
+    /**
+     * @notes  更改状态场景
+     * @return ArticleCateValidate
+     * @author heshihu
+     * @date 2022/2/21 18:02
+     */
+    public function sceneStatus()
+    {
+        return $this->only(['id', 'status']);
+    }
+
+    public function sceneEdit()
+    {
+    }
+
+    /**
+     * @notes  获取所有农耕分类场景
+     * @return ArticleCateValidate
+     * @author heshihu
+     * @date 2022/2/15 10:05
+     */
+    public function sceneSelect()
+    {
+//        return $this->only(['type']);
+    }
+
+
+    /**
+     * @notes  删除场景
+     * @return ArticleCateValidate
+     * @author heshihu
+     * @date 2022/2/21 17:52
+     */
+    public function sceneDelete()
+    {
+        return $this->only(['id'])
+            ->append('id', 'checkDeleteArticleCate');
+    }
+
+    /**
+     * @notes  检查指定农耕分类是否存在
+     * @param $value
+     * @return bool|string
+     * @author heshihu
+     * @date 2022/2/10 15:10
+     */
+    public function checkMachineryCate($value)
+    {
+        $category = AgriculturalMachineryServiceCategory::findOrEmpty($value);
+        if ($category->isEmpty()) {
+            return '农耕分类不存在';
+        }
+        return true;
+    }
+
+    /**
+     * @notes  删除时验证农耕分类是否已使用
+     * @param $value
+     * @return bool|string
+     * @author heshihu
+     * @date 2022/2/22 14:45
+     */
+    public function checkDeleteArticleCate($value)
+    {
+//        $article = Article::where('cid', $value)->findOrEmpty();
+//        if (!$article->isEmpty()) {
+//            return '农耕分类已使用,请先删除绑定该农耕分类的农耕服务';
+//        }
+        return true;
+    }
+
+}

+ 75 - 0
app/common/model/agricultural_machinery/AgriculturalMachineryServiceCategory.php

@@ -0,0 +1,75 @@
+<?php
+// +----------------------------------------------------------------------
+// | likeadmin快速开发前后端分离管理后台(PHP版)
+// +----------------------------------------------------------------------
+// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
+// | 开源版本可自由商用,可去除界面版权logo
+// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
+// | github下载:https://github.com/likeshop-github/likeadmin
+// | 访问官网:https://www.likeadmin.cn
+// | likeadmin团队 版权所有 拥有最终解释权
+// +----------------------------------------------------------------------
+// | author: likeadminTeam
+// +----------------------------------------------------------------------
+
+namespace app\common\model\agricultural_machinery;
+
+use app\common\model\BaseModel;
+use think\model\concern\SoftDelete;
+
+/**
+ * 资讯分类管理模型
+ * Class ArticleCate
+ * @package app\common\model\article;
+ */
+class AgriculturalMachineryServiceCategory extends BaseModel
+{
+    use SoftDelete;
+
+    protected $deleteTime = 'delete_time';
+
+
+    /**
+     * @notes 关联文章
+     * @return \think\model\relation\HasMany
+     * @author 段誉
+     * @date 2022/10/19 16:59
+     */
+    public function article()
+    {
+        return $this->hasMany(Article::class, 'cid', 'id');
+    }
+
+
+    /**
+     * @notes 状态描述
+     * @param $value
+     * @param $data
+     * @return string
+     * @author 段誉
+     * @date 2022/9/15 11:25
+     */
+    public function getStatusDescAttr($value, $data)
+    {
+        return $data['status'] ? '启用' : '停用';
+    }
+
+
+    /**
+     * @notes 文章数量
+     * @param $value
+     * @param $data
+     * @return int
+     * @author 段誉
+     * @date 2022/9/15 11:32
+     */
+    public function getAriculturalMachineryCountAttr($value, $data)
+    {
+        return 10;
+//        return Article::where(['cid' => $data['id']])->count('id');
+    }
+
+
+
+
+}