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.

45 lines
1.1 KiB

  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,$market_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('store_id')->find($goods_id);
  21. return ShoppingCart::query()->updateOrCreate(
  22. [
  23. 'user_id' => $user_id,
  24. 'goods_id' => $goods_id,
  25. 'activity_type' => $activity_type
  26. ],
  27. [
  28. 'market_id' => $market_id,
  29. 'store_id' => $goods->store_id,
  30. 'num' => $num
  31. ]
  32. );
  33. }
  34. public function check()
  35. {
  36. // TODO: Implement check() method.
  37. }
  38. public function undo($params)
  39. {
  40. return true;
  41. }
  42. }