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.

63 lines
1.6 KiB

5 years ago
5 years ago
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. $goodsType = '';
  15. //判断是普通商品还是特价商品
  16. if(isset($params['activity']) && $params['activity'] == GoodsConstants::IS_ACTIVITY){
  17. $builder = GoodsActivity::query();
  18. $goodsType = GoodsActivity::class;
  19. }else{
  20. $builder = Goods::query();
  21. $goodsType = Goods::class;
  22. }
  23. $goods = $builder->select('market_id','store_id')->find($goods_id);
  24. if(empty($goods)){
  25. throw new ErrorCodeException(ErrorCode::GOODS_NOT_EXISTS);
  26. }
  27. return ShoppingCart::query()->updateOrCreate(
  28. [
  29. 'user_id' => $user_id,
  30. 'goods_id' => $goods_id,
  31. 'activity_type' => $activity_type
  32. ],
  33. [
  34. 'market_id' => $goods->market_id,
  35. 'store_id' => $goods->store_id,
  36. 'num' => $num,
  37. 'goods_type' => $goodsType
  38. ]
  39. );
  40. }
  41. public function check()
  42. {
  43. // TODO: Implement check() method.
  44. }
  45. public function undo($shopcartIds)
  46. {
  47. $shopcartIdsArr = explode(',',$shopcartIds);
  48. return ShoppingCart::destroy($shopcartIdsArr);
  49. }
  50. /**
  51. * 清空购物车
  52. * @param $userId
  53. * @param $marketId
  54. */
  55. public function doClear($userId, $marketId)
  56. {
  57. }
  58. }