xieruidong 2 年之前
父节点
当前提交
43f6ce76cb

+ 8 - 0
application/api/controller/mall/GoodsCart.php

@@ -67,4 +67,12 @@ class GoodsCart extends Api
         $user->cart()->where('id',$data['id'])->delete();
         $this->success();
     }
+
+    /**
+     * 购物车列表
+     *
+     */
+    public function index(){
+        $list=
+    }
 }

+ 1 - 0
application/common/model/Goods.php

@@ -126,6 +126,7 @@ class Goods Extends Model
             $goods->sku()->delete();
             $goods->binds()->delete();
             GoodsBind::where('bind_goods_id',$goods['id'])->delete();
+            GoodsCart::where('goods_id',$goods['id'])->delete();
         });
     }
 }

+ 3 - 0
application/common/model/GoodsCart.php

@@ -9,4 +9,7 @@ use think\Model;
  */
 class GoodsCart Extends Model
 {
+    public function goods(){
+        return $this->belongsTo(Goods::class);
+    }
 }

+ 8 - 0
application/common/model/GoodsSku.php

@@ -28,4 +28,12 @@ class GoodsSku Extends Model
     public function goods(){
         return $this->belongsTo(Goods::class);
     }
+
+
+    protected static function init()
+    {
+        self::afterDelete(function (self $sku){
+            GoodsCart::where('goods_sku_id',$sku['id'])->delete();
+        });
+    }
 }