瀏覽代碼

优化订单系统删除购物车中的广告位

15313670163 2 月之前
父節點
當前提交
8ab974e493
共有 1 個文件被更改,包括 6 次插入1 次删除
  1. 6 1
      app/JsonRpc/OrderService.php

+ 6 - 1
app/JsonRpc/OrderService.php

@@ -852,7 +852,12 @@ class OrderService implements OrderServiceInterface
         if (empty($shop)) {
             return Result::error("不存在此条记录!(参数错误)"); 
         }else{
-            $result = ShoppingCart::where('shopping_id', $shop['shopping_id'])->where('user_id',$data['user_id'])->where('pid',$data['pid'])->delete();
+            $count = ShoppingCart::where('shopping_id', $data['shopping_id'])->where('user_id',$data['user_id'])->count();
+            if($count == 1){
+                $result = ShoppingCart::where('shopping_id', $data['shopping_id'])->where('user_id',$data['user_id'])->update(['pid' => null, 'website_id' => null]);; 
+            }else{
+                $result = ShoppingCart::where('shopping_id', $shop['shopping_id'])->where('user_id',$data['user_id'])->where('pid',$data['pid'])->delete();
+            } 
         }
         if(empty($result)){
             return Result::error("删除失败");