You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
<?php
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($user_id,$goods_id,$num,$activity_type) { $goodsType = ''; //判断是普通商品还是特价商品
if($activity_type == GoodsConstants::IS_ACTIVITY){ $builder = GoodsActivity::query(); $goodsType = GoodsActivity::class; }else{ $builder = Goods::query(); $goodsType = Goods::class; } $goods = $builder->select('market_id','store_id')->find($goods_id); if(empty($goods)){ throw new ErrorCodeException(ErrorCode::GOODS_NOT_EXISTS); } return ShoppingCart::query()->updateOrCreate( [ 'user_id' => $user_id, 'goods_id' => $goods_id, 'activity_type' => $activity_type ], [ 'market_id' => $goods->market_id, 'store_id' => $goods->store_id, 'num' => $num, 'goods_type' => $goodsType ] ); }
public function check() { // TODO: Implement check() method.
}
public function undo($shopcartIds) { $shopcartIdsArr = explode(',',$shopcartIds); return ShoppingCart::destroy($shopcartIdsArr); }
/** * 清空购物车 * @param $userId * @param $marketId */ public function doClear($userId, $marketId) { return ShoppingCart::query()->where([ ['user_id','=',$userId], ['market_id','=',$marketId], ]) ->delete(); }}
|