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.
59 lines
1.4 KiB
59 lines
1.4 KiB
<?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)
|
|
{
|
|
//判断是普通商品还是特价商品
|
|
if(isset($params['activity']) && $params['activity'] == GoodsConstants::IS_ACTIVITY){
|
|
$builder = GoodsActivity::query();
|
|
}else{
|
|
$builder = Goods::query();
|
|
}
|
|
$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
|
|
]
|
|
);
|
|
}
|
|
|
|
public function check()
|
|
{
|
|
// TODO: Implement check() method.
|
|
}
|
|
|
|
public function undo($params)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* 清空购物车
|
|
* @param $userId
|
|
* @param $marketId
|
|
*/
|
|
public function doClear($userId, $marketId)
|
|
{
|
|
|
|
}
|
|
}
|