Ver código fonte

批量商品规则

liugc 1 ano atrás
pai
commit
0864e36dcd

+ 9 - 1
app/adminapi/controller/goods/GoodsController.php

@@ -104,5 +104,13 @@ class GoodsController extends BaseAdminController
         return $this->data($result);
     }
 
-
+    public function rulesBatch()
+    {
+        $params = (new GoodsValidate())->post()->goCheck('rules');
+        $result = GoodsLogic::rulesBatch($params);
+        if (true === $result) {
+            return $this->success('批量配置成功', [], 1, 1);
+        }
+        return $this->fail(GoodsLogic::getError());
+    }
 }

+ 34 - 0
app/adminapi/logic/goods/GoodsLogic.php

@@ -176,4 +176,38 @@ class GoodsLogic extends BaseLogic
     {
         return Goods::with('performanceRules')->findOrEmpty($params['id'])->toArray();
     }
+    /**
+     * @notes 批量规则配置
+     * @param $params
+     * @return array
+     */
+    public static function rulesBatch($params): bool
+    {
+        Db::startTrans();
+        try {
+            foreach ($params['ids'] as $id){
+                $rule = null;
+                //更新绩效规则
+                $rule = PerformanceRules::where(['goods_id'=>$id])->findOrEmpty();
+                if(!$rule->isEmpty()){
+                    $rule->type = $params['type'];
+                    $rule->rate = $params['rate'];
+                }else{
+                    $rule = new PerformanceRules();
+                    $rule->goods_id = $id;
+                    $rule->type = $params['type'];
+                    $rule->rate = $params['rate'];
+                }
+                $rule->save();
+            }
+            Db::commit();
+            return true;
+        } catch (\Exception $e) {
+            Db::rollback();
+            self::setError($e->getMessage());
+            return false;
+        }
+    }
+
+
 }

+ 12 - 3
app/adminapi/validate/goods/GoodsValidate.php

@@ -39,7 +39,7 @@ class GoodsValidate extends BaseValidate
         'service_total' => 'require',
         'service_fee' => 'require',
         'goods_status' => 'require',
-
+        'ids' => 'require',
     ];
 
 
@@ -56,7 +56,7 @@ class GoodsValidate extends BaseValidate
         'service_total' => '服务原价',
         'service_fee' => '服务价格',
         'goods_status' => '商品状态',
-
+        'ids' => '批量操作id',
     ];
 
 
@@ -106,5 +106,14 @@ class GoodsValidate extends BaseValidate
     {
         return $this->only(['id']);
     }
-
+    /**
+     * @notes 添加场景
+     * @return GoodsValidate
+     * @author likeadmin
+     * @date 2024/07/07 18:37
+     */
+    public function sceneRules()
+    {
+        return $this->only(['ids','rate','type']);
+    }
 }