diff --git a/app/Controller/v3/ShopCartUpdateController.php b/app/Controller/v3/ShopCartUpdateController.php index 3955952..67dbca9 100644 --- a/app/Controller/v3/ShopCartUpdateController.php +++ b/app/Controller/v3/ShopCartUpdateController.php @@ -15,7 +15,12 @@ class ShopCartUpdateController extends BaseController protected $shopCarServiceUpdate; public function update() { - $res = $this->shopCarServiceUpdate->do($this->request->all()); + $user_id = $this->request->input('user_id',0); + $market_id = $this->request->input('market_id',''); + $goods_id = $this->request->input('goods_id',0); + $num = $this->request->input('num',''); + $activity_type = $this->request->input('activity_type',1); + $res = $this->shopCarServiceUpdate->do($user_id,$goods_id,$market_id,$num,$activity_type); return $this->success($res); } diff --git a/app/Model/v3/ShoppingCart.php b/app/Model/v3/ShoppingCart.php index 958ecec..926334d 100644 --- a/app/Model/v3/ShoppingCart.php +++ b/app/Model/v3/ShoppingCart.php @@ -11,6 +11,16 @@ class ShoppingCart extends Model protected $table = 'lanzu_shopping_cart'; + protected $fillable = [ + 'id', + 'user_id', + 'goods_id', + 'market_id', + 'store_id', + 'num', + 'activity_type' + ]; + public function goods() { return $this->hasOne(Goods::class, 'id', 'goods_id'); diff --git a/app/Service/v3/Implementations/ShopCartUpdateService.php b/app/Service/v3/Implementations/ShopCartUpdateService.php index 2ed2011..fce914b 100644 --- a/app/Service/v3/Implementations/ShopCartUpdateService.php +++ b/app/Service/v3/Implementations/ShopCartUpdateService.php @@ -5,25 +5,33 @@ namespace App\Service\v3\Implementations; use App\Constants\v3\ErrorCode; use App\Exception\ErrorCodeException; use App\Service\v3\Interfaces\ShopCartUpdateServiceInterface; - +use App\Model\v3\ShoppingCart; +use App\Model\v3\Goods; +use App\Model\v3\GoodsActivity; +use App\Constants\v3\Goods as GoodsConstants; class ShopCartUpdateService implements ShopCartUpdateServiceInterface { - public function do($params) + public function do($user_id,$goods_id,$market_id,$num,$activity_type) { - switch ($params['goods_id']) - { - case 1000: - throw new ErrorCodeException(ErrorCode::GOODS_INVENTORY_ERROR); - break; - case 2000: - throw new ErrorCodeException(ErrorCode::GOODS_RESTRICT_LIMIT); - break; - case 3000: - throw new ErrorCodeException(ErrorCode::GOODS_ACTIVITY_BUY); - break; - default: - return true; - } + //判断是普通商品还是特价商品 + if(isset($params['activity']) && $params['activity'] == GoodsConstants::IS_ACTIVITY){ + $builder = GoodsActivity::query(); + }else{ + $builder = Goods::query(); + } + $goods = $builder->select('store_id')->find($goods_id); + return ShoppingCart::query()->updateOrCreate( + [ + 'user_id' => $user_id, + 'goods_id' => $goods_id, + 'activity_type' => $activity_type + ], + [ + 'market_id' => $market_id, + 'store_id' => $goods->store_id, + 'num' => $num + ] + ); } public function check() diff --git a/app/Service/v3/Interfaces/ShopCartUpdateServiceInterface.php b/app/Service/v3/Interfaces/ShopCartUpdateServiceInterface.php index 0696801..06ead28 100644 --- a/app/Service/v3/Interfaces/ShopCartUpdateServiceInterface.php +++ b/app/Service/v3/Interfaces/ShopCartUpdateServiceInterface.php @@ -4,7 +4,7 @@ namespace App\Service\v3\Interfaces; interface ShopCartUpdateServiceInterface { - public function do($params); + public function do($user_id,$goods_id,$market_id,$num,$activity_type); public function check();