Ver Fonte

供需信息

moonsflyer há 8 meses atrás
pai
commit
ecc26294d1

+ 109 - 0
app/adminapi/controller/agricultural_machinery/SupplyDemandController.php

@@ -0,0 +1,109 @@
+<?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\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;
+
+/**
+ * 供需管理控制器
+ * Class ArticleCateController
+ * @package app\adminapi\controller\article
+ */
+class SupplyDemandController extends BaseAdminController
+{
+
+    /**
+     * @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 getSupplyDemandList()
+    {
+        $params = (new SupplyDemandValidate())->get()->goCheck('supplyDemand');
+        return $this->dataLists(new SupplyDemandLists());
+    }
+
+    /**
+     * @notes  删除服务商
+     * @return \think\response\Json
+     * @author heshihu
+     * @date 2022/2/21 17:52
+     */
+    public function delete()
+    {
+        $params = (new UserServiceValidate())->post()->goCheck('delete');
+        UserServiceLogic::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 SupplyDemandValidate())->goCheck('detail');
+        $result = SupplyDemandLogic::detail($params);
+        return $this->data($result);
+    }
+
+
+    /**
+     * @notes  更改服务商状态
+     * @return \think\response\Json
+     * @author heshihu
+     * @date 2022/2/21 10:15
+     */
+    public function updateStatus()
+    {
+        $params = (new UserServiceValidate())->post()->goCheck('status');
+        $result = UserServiceLogic::updateStatus($params);
+        if (true === $result) {
+            return $this->success('修改成功', [], 1, 1);
+        }
+        return $this->fail(UserServiceLogic::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 getUserList()
+    {
+        $result = UserServiceLogic::getValidUserData();
+        return $this->data($result);
+    }
+
+
+}

+ 118 - 0
app/adminapi/lists/agricultural_machinery/SupplyDemandLists.php

@@ -0,0 +1,118 @@
+<?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\agricultural_machinery\ServiceCategory as AgriculturalMachineryServiceCategory;
+use app\common\model\agricultural_machinery\UserService;
+use app\common\model\supply_demand\SupplyDemandInfo;
+
+/**
+ * 供需列表
+ * Class ArticleCateLists
+ * @package app\adminapi\lists\article
+ */
+class SupplyDemandLists extends BaseAdminDataLists implements ListsSearchInterface, ListsSortInterface
+{
+
+
+    /**
+     * @notes  设置搜索条件
+     * @return array
+     * @author heshihu
+     * @date 2022/2/8 18:39
+     */
+    public function setSearch(): array
+    {
+        return [
+            '%like%' => ['title','mobile'],
+            '=' => ['type']
+        ];
+    }
+    /**
+     * @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 = SupplyDemandInfo::where($this->searchWhere)
+            ->where($this->queryWhere())
+            ->limit($this->limitOffset, $this->limitLength)
+            ->order($this->sortOrder)
+            ->append(['status_desc','type_desc','user'])
+            ->select()
+            ->toArray();
+
+        return $supplyDemandLists;
+    }
+
+    /**
+     * @notes  获取数量
+     * @return int
+     * @author heshihu
+     * @date 2022/2/9 15:12
+     */
+    public function count(): int
+    {
+        return SupplyDemandInfo::where($this->searchWhere)->where($this->queryWhere())->count();
+    }
+
+    public function extend()
+    {
+        return [];
+    }
+}

+ 97 - 0
app/adminapi/logic/agricultural_machinery/SupplyDemandLogic.php

@@ -0,0 +1,97 @@
+<?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\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\recharge\RechargeOrder;
+use app\common\model\ServiceCharge;
+use think\facade\Db;
+
+/**
+ * 供需管理逻辑
+ * Class ArticleCateLogic
+ * @package app\adminapi\logic\article
+ */
+class SupplyDemandLogic extends BaseLogic
+{
+
+    /**
+     * @notes  删除农耕分类
+     * @param array $params
+     * @author heshihu
+     * @date 2022/2/21 17:52
+     */
+    public static function delete(array $params)
+    {
+        UserService::destroy($params['id']);
+    }
+
+    /**
+     * @notes  查看供需详情
+     * @param $params
+     * @return array
+     * @author heshihu
+     * @date 2022/2/21 17:54
+     */
+    public static function detail($params) : array
+    {
+        return SupplyDemandInfo::findOrEmpty($params['id'])->toArray();
+    }
+
+    /**
+     * @notes  更改服务商状态
+     * @param array $params
+     * @return bool
+     * @author heshihu
+     * @date 2022/2/21 18:04
+     */
+    public static function updateStatus(array $params)
+    {
+        UserService::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 getValidUserData()
+    {
+
+        $list =  User::where(['is_disable' => YesNoEnum::NO])
+            ->field('id,sn,nickname')
+            ->order([ 'id' => 'desc'])
+            ->select()
+            ->toArray();
+        return $list;
+    }
+
+}

+ 162 - 0
app/adminapi/validate/agricultural_machinery/SupplyDemandValidate.php

@@ -0,0 +1,162 @@
+<?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\user\User;
+
+/**
+ * 供需管理验证
+ * Class ArticleCateValidate
+ * @package app\adminapi\validate\article
+ */
+class SupplyDemandValidate extends BaseValidate
+{
+    protected $rule = [
+        'id' => 'require|checkUserServiceInfo',
+        'user_id' => 'require|checkUserInfo',
+        'status' => 'requireIf:status,0|in:0,1,2,3',
+        'type' =>'require|in:1,2',
+        'mobile' => 'require|mobile',
+        'images'=>'require',
+    ];
+
+    protected $message = [
+        'id.require' => ' 供需id不能为空',
+        'user_id.require' => '请选择用户',
+        'type.require' => '类型不能为空',
+        'type.in' => '类型值type参数规则错误',
+        'mobile.require' => '联系方式参数缺失',
+        'mobile.mobile' => '请填写正确的手机号',
+        'images.require' => '请输入上传服务图片',
+    ];
+
+    /**
+     * @notes  列表
+     * @return ArticleCateValidate
+     * @author heshihu
+     * @date 2022/2/10 15:11
+     */
+    public function sceneSupplyDemand()
+    {
+        return $this->only(['status']);
+    }
+
+    /**
+     * @notes  添加场景
+     * @return ArticleCateValidate
+     * @author heshihu
+     * @date 2022/2/10 15:11
+     */
+    public function sceneAdd()
+    {
+        return $this->remove(['id'])
+            ->remove('id', 'require|checkUserServiceInfo');
+    }
+
+    /**
+     * @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()
+    {
+        return $this
+        ->remove('type', 'require');
+    }
+
+    /**
+     * @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', 'checkUserServiceInfo');
+    }
+
+    /**
+     * @notes  检查指定服务信息是否存在
+     * @param $value
+     * @return bool|string
+     * @author heshihu
+     * @date 2022/2/10 15:10
+     */
+    public function checkUserServiceInfo($value)
+    {
+        $category = SupplyDemandInfo::findOrEmpty($value);
+        if ($category->isEmpty()) {
+            return '供需信息不存在';
+        }
+        return true;
+    }
+    public function checkUserInfo($value,$data)
+    {
+        $category = User::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;
+    }
+
+}

+ 4 - 4
app/common/model/supply_demand/SupplyDemandInfo.php

@@ -42,7 +42,7 @@ class SupplyDemandInfo extends BaseModel
      */
     public function user()
     {
-        return $this->hasOne(User::class, 'id', 'user_id')->field('id,nickname,avatar');
+        return $this->hasOne(User::class, 'id', 'user_id')->field('id,nickname,avatar,account');
     }
 
     /**
@@ -55,15 +55,15 @@ class SupplyDemandInfo extends BaseModel
      */
 
     public function getStatusDescAttr($value,$data){
-        $type = $data['type'];
+        $status = $data['status'];
         $desc = [
-            0 => '新增待审核',
+            0 => '新增待提交',
             1 => '审核中',
             2 => '审核成功',
             3 => '审核失败',
         ];
 
-        return $desc[$type] ?? '';
+        return $desc[$status] ?? '';
     }
     public function getTypeDescAttr($value,$data){
         $type = $data['type'];