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.

58 lines
1.4 KiB

5 years ago
5 years ago
5 years ago
  1. <?php
  2. namespace App\Service\v3\Implementations;
  3. use App\Constants\v3\ErrorCode;
  4. use App\Exception\ErrorCodeException;
  5. use App\Service\v3\Interfaces\ShopCartUpdateServiceInterface;
  6. use App\Model\v3\ShoppingCart;
  7. use App\Model\v3\Goods;
  8. use App\Model\v3\GoodsActivity;
  9. use App\Constants\v3\Goods as GoodsConstants;
  10. class ShopCartUpdateService implements ShopCartUpdateServiceInterface
  11. {
  12. public function do($user_id,$goods_id,$num,$activity_type)
  13. {
  14. //判断是普通商品还是特价商品
  15. if(isset($params['activity']) && $params['activity'] == GoodsConstants::IS_ACTIVITY){
  16. $builder = GoodsActivity::query();
  17. }else{
  18. $builder = Goods::query();
  19. }
  20. $goods = $builder->select('market_id','store_id')->find($goods_id);
  21. if(empty($goods)){
  22. throw new ErrorCodeException(ErrorCode::GOODS_NOT_EXISTS);
  23. }
  24. return ShoppingCart::query()->updateOrCreate(
  25. [
  26. 'user_id' => $user_id,
  27. 'goods_id' => $goods_id,
  28. 'activity_type' => $activity_type
  29. ],
  30. [
  31. 'market_id' => $goods->market_id,
  32. 'store_id' => $goods->store_id,
  33. 'num' => $num
  34. ]
  35. );
  36. }
  37. public function check()
  38. {
  39. // TODO: Implement check() method.
  40. }
  41. public function undo($params)
  42. {
  43. return true;
  44. }
  45. /**
  46. * 清空购物车
  47. * @param $userId
  48. * @param $marketId
  49. */
  50. public function doClear($userId, $marketId)
  51. {
  52. }
  53. }