|
|
|
@ -4,33 +4,57 @@ namespace App\Service\v3\Implementations; |
|
|
|
|
|
|
|
use App\Constants\v3\ErrorCode; |
|
|
|
use App\Exception\ErrorCodeException; |
|
|
|
use App\Service\v3\Interfaces\GoodsActivityServiceInterface; |
|
|
|
use App\Service\v3\Interfaces\GoodsServiceInterface; |
|
|
|
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; |
|
|
|
use Hyperf\Di\Annotation\Inject; |
|
|
|
class ShopCartUpdateService implements ShopCartUpdateServiceInterface |
|
|
|
{ |
|
|
|
public function do($user_id,$goods_id,$num,$activity_type) |
|
|
|
/** |
|
|
|
* @Inject |
|
|
|
* @var GoodsServiceInterface |
|
|
|
*/ |
|
|
|
protected $goodsService; |
|
|
|
|
|
|
|
/** |
|
|
|
* @Inject |
|
|
|
* @var GoodsActivityServiceInterface |
|
|
|
*/ |
|
|
|
protected $goodsActivityService; |
|
|
|
|
|
|
|
public function do($userId,$goodsId,$num,$activityType) |
|
|
|
{ |
|
|
|
$goodsType = ''; |
|
|
|
//判断是普通商品还是特价商品
|
|
|
|
if($activity_type == GoodsConstants::IS_ACTIVITY){ |
|
|
|
if($activityType == GoodsConstants::IS_ACTIVITY){ |
|
|
|
$builder = GoodsActivity::query(); |
|
|
|
$goodsType = GoodsActivity::class; |
|
|
|
}else{ |
|
|
|
$goodsModel = $builder->find($goodsId); |
|
|
|
$goodsCheck = $this->goodsActivityService->check($goodsModel,$num,$userId); |
|
|
|
}else{ |
|
|
|
$builder = Goods::query(); |
|
|
|
$goodsType = Goods::class; |
|
|
|
$goodsModel = $builder->find($goodsId); |
|
|
|
$goodsCheck = $this->goodsService->check($goodsModel,$num); |
|
|
|
} |
|
|
|
$goods = $builder->select('market_id','store_id')->find($goods_id); |
|
|
|
if(empty($goods)){ |
|
|
|
throw new ErrorCodeException(ErrorCode::GOODS_NOT_EXISTS); |
|
|
|
} |
|
|
|
|
|
|
|
if($goodsCheck !== true) |
|
|
|
{ |
|
|
|
throw new ErrorCodeException($goodsCheck); |
|
|
|
} |
|
|
|
|
|
|
|
return ShoppingCart::query()->updateOrCreate( |
|
|
|
[ |
|
|
|
'user_id' => $user_id, |
|
|
|
'goods_id' => $goods_id, |
|
|
|
'activity_type' => $activity_type |
|
|
|
'user_id' => $userId, |
|
|
|
'goods_id' => $goodsId, |
|
|
|
'activity_type' => $activityType |
|
|
|
], |
|
|
|
[ |
|
|
|
'market_id' => $goods->market_id, |
|
|
|
|