moonsflyer 8 hónapja
szülő
commit
6362f48a40

+ 7 - 0
app/api/controller/SupplyDemandInfoController.php

@@ -94,4 +94,11 @@ class SupplyDemandInfoController extends BaseApiController
         }
         return $this->data($result['data']);
     }
+    //供需分类
+    public function getCateList()
+    {
+        $params = (new SupplyDemandValidate())->get()->goCheck('cate');
+        $result = SupplyDemandLogic::getCateList($params,$this->userId);
+        return $this->data($result);
+    }
 }

+ 2 - 2
app/api/lists/supply_demand/SupplyDemandLists.php

@@ -81,12 +81,12 @@ class SupplyDemandLists extends BaseApiDataLists implements ListsSearchInterface
     {
         $orderRaw = 'id desc';
 
-        $field = 'id,user_id,title,type,mobile,images,address,number,content,status,remark,create_time';
+        $field = 'id,user_id,title,type,cate_id,mobile,images,address,number,content,status,remark,create_time';
         $result = SupplyDemandInfo::field($field)
             ->where($this->queryWhere())
             ->where($this->searchWhere)
             ->orderRaw($orderRaw)
-            ->append(['type_desc','status_desc','images','user'])
+            ->append(['type_desc','cateInfo','status_desc','images','user'])
             ->limit($this->limitOffset, $this->limitLength)
             ->select()->toArray();
 

+ 33 - 1
app/api/logic/SupplyDemandLogic.php

@@ -28,6 +28,7 @@ use app\common\service\{
 };
 use app\common\model\agricultural_machinery\UserService;
 use app\common\model\agricultural_machinery\ServiceCategory;
+use app\common\model\supply_demand\SupplyDemandCate;
 use app\common\model\ServiceCharge;
 use app\common\model\asset\AssetArea;
 use app\common\model\recharge\RechargeOrder;
@@ -56,6 +57,7 @@ class SupplyDemandLogic extends BaseLogic
             SupplyDemandInfo::create([
                 'user_id' => $params['user_id'],
                 'type' => $params['type'] ?? 1,
+                'cate_id' => $params['cate_id'],
                 'title' => $params['title'],
                 'mobile' => $params['mobile'],
                 'content' =>$params['content'],
@@ -85,7 +87,7 @@ class SupplyDemandLogic extends BaseLogic
             $where = [];
             $where[]=['id','=',$params['id']];
 
-            $supplyDemandInfo = SupplyDemandInfo::where($where) ->append(['type_desc','images','user'])->findOrEmpty()->toArray();
+            $supplyDemandInfo = SupplyDemandInfo::where($where) ->append(['type_desc','cateInfo','images','user'])->findOrEmpty()->toArray();
 
             return ['code'=>true,'data'=>$supplyDemandInfo];
         } catch (\Exception $e) {
@@ -420,4 +422,34 @@ class SupplyDemandLogic extends BaseLogic
             'is_new_user' => YesNoEnum::NO
         ]);
     }
+
+    /**
+     * @notes 供应分类列表
+     * @author 段誉
+     * @date 2022/9/16 17:56
+     */
+    public static function getCateList($get)
+    {
+        $where=[];
+        $where[]=['type','=',$get['type']];
+        $where[]=['status','=',1];
+        if(isset($get['name'])){
+            $where[]=['name','like','%'.$get['name'].'%'];
+        }
+        $cate_list = SupplyDemandCate::where($where)->field('id,name,pid')->order('sort desc,id asc')->select()->toArray();
+        if($get['is_tree'] == 1) {
+
+
+            $treeList = linear_to_tree($cate_list, 'children');
+            if (empty($treeList) && !empty($cate_list)) {
+                foreach ($cate_list as &$v) {
+                    $v['children'] = [];
+                }
+                return $cate_list;
+            }
+            return $treeList;
+        }else{
+            return $cate_list;
+        }
+    }
 }

+ 16 - 9
app/api/validate/SupplyDemandValidate.php

@@ -14,17 +14,11 @@
 
 namespace app\api\validate;
 
-use app\common\cache\UserAccountSafeCache;
-use app\common\enum\LoginEnum;
-use app\common\enum\notice\NoticeEnum;
-use app\common\enum\user\UserTerminalEnum;
-use app\common\enum\YesNoEnum;
-use app\common\service\ConfigService;
-use app\common\service\sms\SmsDriver;
+
 use app\common\validate\BaseValidate;
 use app\common\model\user\User;
 use app\common\model\agricultural_machinery\ServiceCategory;
-use app\common\model\asset\AssetArea;
+use app\common\model\supply_demand\SupplyDemandCate;
 use think\facade\Config;
 
 /**
@@ -40,6 +34,7 @@ class SupplyDemandValidate extends BaseValidate
         'title'=>'require|min:1|max:100',
         'mobile' => 'require|mobile',
         'type'  => 'require|in:1,2',
+        'cate_id'=> 'require|checkCate',
         'address'=>'require',
         'images'=>'require',
         'content'=>'require',
@@ -55,14 +50,16 @@ class SupplyDemandValidate extends BaseValidate
         'mobile.require' => '联系方式参数缺失',
         'mobile.mobile' => '请填写正确的手机号',
         'type.require'  => '类型type参数必传',
+        'cate_id.require'  => '供应分类参数必传',
         'address.require'  => '地址信息必传',
         'type.in'    =>'类型type参数规则错误',
         'images.require'                          => '请输入上传图片',
         'number.require'  => '地区信息必传',
     ];
     protected $scene = [
-        'supplyDemandRelease' => ['title','type','images','address','mobile','number'], //
+        'supplyDemandRelease' => ['title','type','images','address','mobile','number','cate_id'], //
         'info' => ['id'], //
+        'cate' => ['type']
     ];
 
     /**
@@ -86,5 +83,15 @@ class SupplyDemandValidate extends BaseValidate
 
         return true;
     }
+    public function checkCate($scene, $rule, $data)
+    {
+
+        $info = SupplyDemandCate::where(['id'=>$data['cate_id'],'type'=>$data['type']])->findOrEmpty();
+        if($info->isEmpty()){
+            return '传入的分类id不存在!';
+        }
 
+
+        return true;
+    }
 }

+ 11 - 1
app/common/model/supply_demand/SupplyDemandInfo.php

@@ -18,6 +18,7 @@ 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\model\supply_demand\SupplyDemandCate;
 use app\common\service\FileService;
 use app\common\model\User\User;
 use think\model\concern\SoftDelete;
@@ -44,7 +45,16 @@ class SupplyDemandInfo extends BaseModel
     {
         return $this->hasOne(User::class, 'id', 'user_id')->field('id,nickname,avatar,account');
     }
-
+    /**
+     * @notes 关联分类
+     * @return \think\model\relation\HasMany
+     * @author 段誉
+     * @date 2022/10/19 16:59
+     */
+    public function cateInfo()
+    {
+        return $this->hasOne(SupplyDemandCate::class, 'id', 'cate_id')->field('id,name');
+    }
     /**
      * @notes 状态描述
      * @param $value