whitefang 1 год назад
Родитель
Сommit
96f6a1f1b8

+ 11 - 3
app/api/controller/GoodsController.php

@@ -3,6 +3,7 @@ namespace app\api\controller;
 
 use app\api\lists\GoodsLists;
 use app\api\logic\GoodsLogic;
+use app\api\validate\GoodsValidate;
 
 /**
  * 用户控制器
@@ -24,10 +25,17 @@ class GoodsController extends BaseApiController
         return $this->data($result);
     }
 
-    public function detail()
+    public function categoryDetail()
     {
-        $id = $this->request->get('category_id/d');
-        $result = GoodsLogic::detail($id);
+        $params = (new GoodsValidate())->goCheck('category');
+        $result = GoodsLogic::detail($params['goods_category_id'],'category');
+        return $this->data($result);
+    }
+
+    public function goodsDetail()
+    {
+        $params = (new GoodsValidate())->goCheck('goods');
+        $result = GoodsLogic::detail($params['id'],'goods');
         return $this->data($result);
     }
 }

+ 16 - 6
app/api/logic/GoodsLogic.php

@@ -23,12 +23,22 @@ class GoodsLogic extends BaseLogic
      * @author whitef
      * @date 2022/9/20 17:09
      */
-    public static function detail($goods_category_id){
-        $goods = Goods::where('goods_category_id',$goods_category_id)->visible([
-            'id','goods_image','goods_video',
-            'goods_number','good_unit','base_service_fee',
-            'service_total','service_fee','service_image','fee_schedule','warranty_period'
-        ])->select()->toArray();
+    public static function detail($id,$type){
+        if($type == 'category'){
+            $goods = Goods::where('goods_category_id',$id)->visible([
+                'id','goods_image','goods_video',
+                'goods_number','good_unit','base_service_fee',
+                'service_total','service_fee','service_image','fee_schedule','warranty_period'
+            ])->select()->toArray();
+        }else{
+            $goods_category_id = Goods::where('id',$id)->value('goods_category_id');
+            $goods = Goods::where('goods_category_id',$goods_category_id)->visible([
+                'id','goods_image','goods_video',
+                'goods_number','good_unit','base_service_fee',
+                'service_total','service_fee','service_image','fee_schedule','warranty_period'
+            ])->select()->toArray();
+        }
+
         return $goods;
     }
 

+ 6 - 34
app/api/validate/GoodsValidate.php

@@ -20,6 +20,7 @@ class GoodsValidate extends BaseValidate
     protected $rule = [
         'id' => 'require',
         'goods_category_ids' => 'require',
+        'goods_category_id'=>'require',
         'goods_name' => 'require',
         'goods_number' => 'require',
         'base_service_fee' => 'require',
@@ -37,6 +38,7 @@ class GoodsValidate extends BaseValidate
     protected $field = [
         'id' => 'id',
         'goods_category_ids' => '服务类目',
+        'goods_category_id' => '服务类目',
         'goods_name' => '商品名称',
         'goods_number' => '商品数量',
         'base_service_fee' => '基础服务费',
@@ -46,50 +48,20 @@ class GoodsValidate extends BaseValidate
 
     ];
 
-
-    /**
-     * @notes 添加场景
-     * @return GoodsValidate
-     * @author likeadmin
-     * @date 2024/07/07 18:37
-     */
-    public function sceneAdd()
-    {
-        return $this->only(['goods_category_ids','goods_category_id','goods_name','goods_number','base_service_fee','service_total','service_fee','goods_status']);
-    }
-
-
-    /**
-     * @notes 编辑场景
-     * @return GoodsValidate
-     * @author likeadmin
-     * @date 2024/07/07 18:37
-     */
-    public function sceneEdit()
-    {
-        return $this->only(['id','goods_category_ids','goods_category_id','goods_name','goods_number','base_service_fee','service_total','service_fee','goods_status']);
-    }
-
-
     /**
-     * @notes 删除场景
+     * @notes 详情场景
      * @return GoodsValidate
-     * @author likeadmin
-     * @date 2024/07/07 18:37
      */
-    public function sceneDelete()
+    public function sceneCategory()
     {
-        return $this->only(['id']);
+        return $this->only(['goods_category_id']);
     }
 
-
     /**
      * @notes 详情场景
      * @return GoodsValidate
-     * @author likeadmin
-     * @date 2024/07/07 18:37
      */
-    public function sceneDetail()
+    public function sceneGoods()
     {
         return $this->only(['id']);
     }