Jelajahi Sumber

供需分类

moonsflyer 8 bulan lalu
induk
melakukan
54fbe909d0

+ 61 - 4
app/adminapi/controller/agricultural_machinery/SupplyDemandController.php

@@ -15,12 +15,12 @@
 namespace app\adminapi\controller\agricultural_machinery;
 
 use app\adminapi\controller\BaseAdminController;
-use app\adminapi\lists\agricultural_machinery\UserServiceLists;
-use app\adminapi\validate\agricultural_machinery\UserServiceValidate;
 use app\adminapi\logic\agricultural_machinery\UserServiceLogic;
 use app\adminapi\validate\agricultural_machinery\SupplyDemandValidate;
 use app\adminapi\logic\agricultural_machinery\SupplyDemandLogic;
 use app\adminapi\lists\agricultural_machinery\SupplyDemandLists;
+use app\adminapi\lists\agricultural_machinery\SupplyDemandCateLists;
+use app\adminapi\validate\agricultural_machinery\SupplyDemandCateValidate;
 
 /**
  * 供需管理控制器
@@ -53,8 +53,8 @@ class SupplyDemandController extends BaseAdminController
      */
     public function delete()
     {
-        $params = (new UserServiceValidate())->post()->goCheck('delete');
-        UserServiceLogic::delete($params);
+        $params = (new SupplyDemandValidate())->post()->goCheck('delete');
+        SupplyDemandLogic::delete($params);
         return $this->success('删除成功', [], 1, 1);
     }
 
@@ -105,5 +105,62 @@ class SupplyDemandController extends BaseAdminController
         return $this->data($result);
     }
 
+    /*
+     * 供需分类列表
+     * */
+    public function supplyDemandCateLists(){
+        $params = (new SupplyDemandCateValidate())->get()->goCheck('SupplyDemandCate');
+        return $this->dataLists(new SupplyDemandCateLists());
+    }
+    /**
+     * @notes  添加资讯分类
+     * @return \think\response\Json
+     * @author heshihu
+     * @date 2022/2/21 17:31
+     */
+    public function addCate()
+    {
+        $params = (new SupplyDemandCateValidate())->post()->goCheck('add');
+        SupplyDemandLogic::addCate($params);
+        return $this->success('添加成功', [], 1, 1);
+    }
+
+    public function cateDetail()
+    {
+        $params = (new SupplyDemandCateValidate())->goCheck('detail');
+        $result = SupplyDemandLogic::detailCate($params);
+        return $this->data($result);
+    }
+
+    public function editCate()
+    {
+        $params = (new SupplyDemandCateValidate())->post()->goCheck('edit');
+        $result = SupplyDemandLogic::editCate($params);
+        if (true === $result) {
+            return $this->success('编辑成功', [], 1, 1);
+        }
+        return $this->fail(SupplyDemandLogic::getError());
+    }
+    /**
+     * @notes  更改供需状态
+     * @return \think\response\Json
+     * @author heshihu
+     * @date 2022/2/21 10:15
+     */
+    public function updateCateStatus()
+    {
+        $params = (new SupplyDemandCateValidate())->post()->goCheck('status');
+        $result = SupplyDemandLogic::updateCateStatus($params);
+        if (true === $result) {
+            return $this->success('修改成功', [], 1, 1);
+        }
+        return $this->fail(SupplyDemandLogic::getError());
+    }
+    public function deleteCate()
+    {
+        $params = (new SupplyDemandCateValidate())->post()->goCheck('delete');
+        SupplyDemandLogic::deleteCate($params);
+        return $this->success('删除成功', [], 1, 1);
+    }
 
 }

+ 126 - 0
app/adminapi/lists/agricultural_machinery/SupplyDemandCateLists.php

@@ -0,0 +1,126 @@
+<?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\supply_demand\SupplyDemandInfo;
+use app\common\model\supply_demand\SupplyDemandCate;
+
+/**
+ * 供需分类列表
+ * Class ArticleCateLists
+ * @package app\adminapi\lists\article
+ */
+class SupplyDemandCateLists extends BaseAdminDataLists implements ListsSearchInterface, ListsSortInterface
+{
+
+
+    /**
+     * @notes  设置搜索条件
+     * @return array
+     * @author heshihu
+     * @date 2022/2/8 18:39
+     */
+    public function setSearch(): array
+    {
+        return [
+            '%like%' => ['name'],
+            '=' => ['type','pid']
+        ];
+    }
+    /**
+     * @notes 自定查询条件
+     * @return array
+     * @author 段誉
+     * @date 2022/10/25 16:53
+     */
+    public function queryWhere()
+    {
+        $where  = [];
+        if (isset($this->params['status']) && $this->params['status']) {
+            $status =  $this->params['status'];
+            $where[] = ['status', '=',$status];
+        }
+        return $where;
+    }
+    /**
+     * @notes  设置支持排序字段
+     * @return array
+     * @author heshihu
+     * @date 2022/2/9 15:11
+     */
+    public function setSortFields(): array
+    {
+        return [ 'id' => 'id'];
+    }
+
+    /**
+     * @notes  设置默认排序
+     * @return array
+     * @author heshihu
+     * @date 2022/2/9 15:08
+     */
+    public function setDefaultOrder(): array
+    {
+        return ['id' => 'desc'];
+    }
+
+    /**
+     * @notes  获取分类列表
+     * @return array
+     * @author heshihu
+     * @date 2022/2/21 17:11
+     */
+    public function lists(): array
+    {
+
+        $supplyDemandLists = SupplyDemandCate::where($this->searchWhere)
+            ->where($this->queryWhere())
+            ->field('id,name,pid,type,status,sort,create_time')
+            ->limit($this->limitOffset, $this->limitLength)
+            ->order($this->sortOrder)
+            ->append(['status_desc','type_desc'])
+            ->select()
+            ->toArray();
+        $treeList = linear_to_tree($supplyDemandLists, 'children');
+        if(empty($treeList) && !empty($supplyDemandLists))
+        {
+            foreach($supplyDemandLists as &$v){
+                $v['children']=[];
+            }
+            return $supplyDemandLists;
+        }
+        return $treeList;
+
+    }
+
+    /**
+     * @notes  获取数量
+     * @return int
+     * @author heshihu
+     * @date 2022/2/9 15:12
+     */
+    public function count(): int
+    {
+        return SupplyDemandCate::where($this->searchWhere)->where($this->queryWhere())->count();
+    }
+
+    public function extend()
+    {
+        return [];
+    }
+}

+ 69 - 3
app/adminapi/logic/agricultural_machinery/SupplyDemandLogic.php

@@ -18,10 +18,10 @@ use app\common\enum\PayEnum;
 use app\common\enum\YesNoEnum;
 use app\common\logic\BaseLogic;
 use app\common\model\agricultural_machinery\UserService;
-use app\common\model\article\ArticleCate;
 use app\common\model\user\User;
 use app\common\model\agricultural_machinery\ServiceCategory as AgriculturalMachineryServiceCategory;
 use app\common\model\supply_demand\SupplyDemandInfo;
+use app\common\model\supply_demand\SupplyDemandCate;
 use app\common\model\recharge\RechargeOrder;
 use app\common\model\ServiceCharge;
 use think\facade\Db;
@@ -52,9 +52,9 @@ class SupplyDemandLogic extends BaseLogic
      * @author heshihu
      * @date 2022/2/21 17:54
      */
-    public static function detail($params) : array
+    public static function detailCate($params) : array
     {
-        return SupplyDemandInfo::findOrEmpty($params['id'])->toArray();
+        return SupplyDemandCate::findOrEmpty($params['id'])->toArray();
     }
 
     /**
@@ -96,4 +96,70 @@ class SupplyDemandLogic extends BaseLogic
         return $list;
     }
 
+    /**
+     * @notes  添加供应分类
+     * @param array $params
+     * @author heshihu
+     * @date 2022/2/18 10:17
+     */
+    public static function addCate(array $params)
+    {
+        $pid = $params['pid'];
+        $level = 1;
+
+        $pidInfo = SupplyDemandCate::find($pid);
+        if(!empty($pidInfo)){
+            $level = $pidInfo['level'] + 1;
+        }
+
+
+        SupplyDemandCate::create([
+            'name' => $params['name'],
+            'level' => $level,
+            'pid' => $pid,
+            'type' => $params['type'] ?? 1,
+            'status' => $params['status'] ?? 1,
+            'sort' => $params['sort'] ?? 0
+        ]);
+    }
+    public static function editCate(array $params) : bool
+    {
+        try {
+            $pid = $params['pid'];
+            $level = 1;
+
+            $pidInfo = SupplyDemandCate::find($pid);
+            if(!empty($pidInfo)){
+                $level = $pidInfo['level'] + 1;
+            }
+
+            SupplyDemandCate::update([
+                'id' => $params['id'],
+                'name' => $params['name'],
+                'level' => $level,
+                'pid' => $pid,
+                'status' => $params['status'] ?? 1,
+                'sort' => $params['sort'] ?? 0
+            ]);
+
+            return true;
+        } catch (\Exception $e) {
+            self::setError($e->getMessage());
+            return false;
+        }
+    }
+
+    public static function updateCateStatus(array $params)
+    {
+        SupplyDemandCate::update([
+            'id' => $params['id'],
+            'status' => $params['status'],
+        ]);
+        return true;
+    }
+    public static function deleteCate(array $params)
+    {
+        SupplyDemandCate::destroy($params['id']);
+    }
+
 }

+ 160 - 0
app/adminapi/validate/agricultural_machinery/SupplyDemandCateValidate.php

@@ -0,0 +1,160 @@
+<?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\supply_demand\SupplyDemandInfo;
+use app\common\model\supply_demand\SupplyDemandCate;
+use app\common\model\user\User;
+
+/**
+ * 供需分类验证
+ * Class ArticleCateValidate
+ * @package app\adminapi\validate\article
+ */
+class SupplyDemandCateValidate extends BaseValidate
+{
+    protected $rule = [
+        'id' => 'require|checkCateInfo',
+        'name' => 'require|checkName',
+        'status' => 'requireIf:status,0|in:0,1',
+        'type' =>'requireIf:type,1|in:1,2',
+        'pid'=>'require|checkPid',
+    ];
+
+    protected $message = [
+        'id.require' => '供需分类id不能为空',
+        'name.require' => '请输入分类名称',
+        'type.require' => '类型不能为空',
+        'type.in' => '类型值type参数规则错误',
+        'status.require' => '状态必传',
+        'status.in' => '状态参数规则错误',
+        'pid.require' => '请父级分类必传',
+    ];
+
+    /**
+     * @notes  列表
+     * @return ArticleCateValidate
+     * @author heshihu
+     * @date 2022/2/10 15:11
+     */
+    public function scenesupplyDemandCate()
+    {
+        return $this->only(['type']);
+    }
+
+    /**
+     * @notes  添加场景
+     * @return ArticleCateValidate
+     * @author heshihu
+     * @date 2022/2/10 15:11
+     */
+    public function sceneAdd()
+    {
+        return $this->remove(['id'])
+            ->remove('id', 'require|checkCateInfo');
+    }
+
+    /**
+     * @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 sceneEdit()
+    {
+        return $this
+        ->remove('type', 'require');
+    }
+
+    /**
+     * @notes  获取所有农耕分类场景
+     * @return ArticleCateValidate
+     * @author heshihu
+     * @date 2022/2/15 10:05
+     */
+    public function sceneStatus()
+    {
+        return $this->only(['id','status']);
+    }
+
+    /**
+     * @notes  删除场景
+     * @return ArticleCateValidate
+     * @author heshihu
+     * @date 2022/2/21 17:52
+     */
+    public function sceneDelete()
+    {
+        return $this->only(['id'])
+            ->append('id', 'checkCateInfo');
+    }
+
+    /**
+     * @notes  检查指定服务信息是否存在
+     * @param $value
+     * @return bool|string
+     * @author heshihu
+     * @date 2022/2/10 15:10
+     */
+    public function checkName($value){
+        $category = SupplyDemandCate::findOrEmpty($value);
+        if (!$category->isEmpty()) {
+            return '已存在改分类名称';
+        }
+        return true;
+    }
+    public function checkPid($value)
+    {
+        if($value == 0) return true;
+        $category = SupplyDemandCate::findOrEmpty($value);
+        if ($category->isEmpty()) {
+            return '父级分类不存在';
+        }
+        return true;
+    }
+    public function checkUserInfo($value,$data)
+    {
+        $category = User::findOrEmpty($value);
+        if ($category->isEmpty()) {
+            return '用户信息不存在';
+        }
+
+        return true;
+    }
+
+    public function checkCateInfo($value)
+    {
+        $category = SupplyDemandCate::findOrEmpty($value);
+        if ($category->isEmpty()) {
+            return '分类不存在';
+        }
+
+        return true;
+    }
+
+}

+ 1 - 1
app/adminapi/validate/agricultural_machinery/SupplyDemandValidate.php

@@ -86,7 +86,7 @@ class SupplyDemandValidate extends BaseValidate
      */
     public function sceneStatus()
     {
-        return $this->only(['id', 'status']);
+        return $this->only(['id', 'status'])->append('status', 'checkStatus');;
     }
 
     public function sceneEdit()

+ 151 - 0
app/common/model/supply_demand/SupplyDemandCate.php

@@ -0,0 +1,151 @@
+<?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\supply_demand;
+
+use app\common\model\agricultural_machinery\ServiceCategory;
+use app\common\model\BaseModel;
+use app\common\model\asset\AssetArea;
+use app\common\model\recharge\RechargeOrder;
+use app\common\service\FileService;
+use app\common\model\User\User;
+use think\model\concern\SoftDelete;
+
+/**
+ * 供需分类模型
+ * Class ArticleCate
+ * @package app\common\model\article;
+ */
+class SupplyDemandCate extends BaseModel
+{
+    use SoftDelete;
+
+    protected $deleteTime = 'delete_time';
+
+
+    /**
+     * @notes 关联用户
+     * @return \think\model\relation\HasMany
+     * @author 段誉
+     * @date 2022/10/19 16:59
+     */
+    public function user()
+    {
+        return $this->hasOne(User::class, 'id', 'user_id')->field('id,nickname,avatar,account');
+    }
+
+    /**
+     * @notes 状态描述
+     * @param $value
+     * @param $data  状态 0 新增待发布 1审核中 2 审核成功 3审核失败
+     * @return string
+     * @author 段誉
+     * @date 2022/9/15 11:25
+     */
+
+    public function getStatusDescAttr($value,$data){
+        $status = $data['status'];
+        $desc = [
+            0 => '隐藏',
+            1 => '显示',
+        ];
+
+        return $desc[$status] ?? '';
+    }
+    public function getTypeDescAttr($value,$data){
+        $type = $data['type'];
+        $desc = [
+            1 => '供应',
+            2 => '需求',
+        ];
+
+        return $desc[$type] ?? '';
+    }
+
+    /**
+     * @notes 设置图片域名
+     * @param $value
+     * @param $data
+     * @return array|string|string[]|null
+     * @author 段誉
+     * @date 2022/9/28 10:17
+     */
+    public function getContentAttr($value, $data)
+    {
+        return get_file_domain($value);
+    }
+
+
+    /**
+     * @notes 清除图片域名
+     * @param $value
+     * @param $data
+     * @return array|string|string[]
+     * @author 段誉
+     * @date 2022/9/28 10:17
+     */
+    public function setContentAttr($value, $data)
+    {
+        return clear_file_domain($value);
+    }
+
+    /**
+     * @notes 清除图片域名
+     * @param $value
+     * @param $data
+     * @return array|string|string[]
+     * @author 段誉
+     * @date 2022/9/28 10:17
+     */
+    public function setImagesAttr($value)
+    {
+        $imagesArr = explode(',',$value);
+        $imagesStr = '';
+        foreach($imagesArr as $k=>$v){
+            if($k==0){
+                $imagesStr = clear_file_domain($v);
+            }else{
+                $imagesStr .=','. clear_file_domain($v);
+            }
+
+        }
+        return $imagesStr;
+    }
+    /**
+     * @notes 加图片域名
+     * @param $value
+     * @param $data
+     * @return array|string|string[]
+     * @author 段誉
+     * @date 2022/9/28 10:17
+     */
+    public function getImagesAttr($value,$data)
+    {
+
+        $imagesArr = explode(',',$data['images']);
+
+        $imagesStr = '';
+
+        foreach($imagesArr as $k=>$v){
+
+            if($k==0){
+                $imagesStr =  FileService::getFileUrl(trim($v, '/')); //get_file_domain($v);
+            }else{
+                $imagesStr .=','. FileService::getFileUrl(trim($v, '/')); //get_file_domain($v);
+            }
+
+        }
+        return $imagesStr;
+    }
+}