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.

126 lines
4.4 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. <?php
  2. namespace App\Controller\v3;
  3. use App\Constants\v3\ErrorCode;
  4. use App\Controller\BaseController;
  5. use App\Exception\ErrorCodeException;
  6. use App\Request\v3\OrderOnlineDetailRequest;
  7. use App\Request\v3\OrderOnlineRequest;
  8. use App\Service\v3\Interfaces\CouponRecServiceInterface;
  9. use App\Service\v3\Interfaces\ShopCartServiceInterface;
  10. use Hyperf\Di\Annotation\Inject;
  11. use App\Service\v3\Interfaces\OrderOnlineServiceInterface;
  12. use App\Service\v3\Interfaces\UserBindTelServiceInterface;
  13. use App\Service\v3\Interfaces\AppointmentTimeServiceInterface;
  14. use Psr\Http\Message\ResponseInterface;
  15. use App\Model\v3\UserAddress;
  16. class OrderOnlineController extends BaseController
  17. {
  18. /**
  19. * @Inject
  20. * @var UserBindTelServiceInterface
  21. */
  22. protected $userBindTelService;
  23. /**
  24. * @Inject
  25. * @var CouponRecServiceInterface
  26. */
  27. protected $couponRecService;
  28. /**
  29. * @Inject
  30. * @var AppointmentTimeServiceInterface
  31. */
  32. protected $appointmentTimeService;
  33. /**
  34. * @Inject
  35. * @var OrderOnlineServiceInterface
  36. */
  37. protected $orderOnlineService;
  38. /**
  39. * @Inject
  40. * @var ShopCartServiceInterface
  41. */
  42. protected $shopCartService;
  43. /*
  44. * 如果没有绑手机号去绑定页面
  45. * 收货地址接口
  46. * 返回预约送达时间
  47. * 商品数据接口
  48. * 红包独立接口
  49. * 配送费独立接口 可根据距离动态计算费用
  50. * 增值服务接口
  51. * */
  52. public function review()
  53. {
  54. $params = $this->request->all();
  55. //判断用户有没有绑定手机
  56. // $telExists = $this->userBindTelService->check($params['user_id']);
  57. // if(!$telExists){
  58. // throw new ErrorCodeException(ErrorCode::NOT_BIND_TEL_ERROR);
  59. // }
  60. //获取用户收货地址
  61. $res['address'] = UserAddress::query()->find(15);
  62. //返回预约送达时间 数组
  63. $res['appointment_time'] = $this->appointmentTimeService->do();
  64. //
  65. $res['store_list'] = $this->shopCartService->do();
  66. //获取用户优惠券
  67. $res['coupon']['available'] = $this->couponRecService->allForOrderOlAvailable('181.02',$params['user_id'],'',1,'','');
  68. $res['coupon']['not_available'] = $this->couponRecService->allForOrderOlAvailable('181.02',$params['user_id'],'',1,'','');
  69. //获取配送费
  70. $res['distribution_price'] = '5.0';
  71. //增值服务接口
  72. $res['value_added_service'] = [
  73. 'select' => 1,
  74. 'price' => 3.50
  75. ];
  76. return $this->success($res);
  77. }
  78. /**
  79. * 订单详情
  80. * 1、主订单信息,用户配送信息(地址、姓名、电话、配送时间、配送类型)、基础信息(订单ID、订单编号、下单时间、订单金额、付款时间、支付方式、红包优惠、服务站电话、增值服务费)
  81. * 2、子订单以及订单商品,按商户分组,有商户信息(ID、商户名、商户logo),商品信息(id、名字、封面、规格、tag、原价、售价、库存、总销、月销、是否失效、失效原因)
  82. * @param OrderOnlineDetailRequest $request
  83. * @return ResponseInterface
  84. */
  85. public function detailByUser(OrderOnlineDetailRequest $request)
  86. {
  87. $params = $request->validated();
  88. return $this->success(['detail' => $this->orderOnlineService->detailByUser($params['order_id'], $params['user_id'])]);
  89. }
  90. /**
  91. * 下单并进行支付,返回支付参数
  92. * 1、用户传参,用户地址ID,用于获取用户地址经纬度来计算配送费
  93. * 2、用户传参,购物车IDs,去获取购物车里的商品详情
  94. * 3、预约送达时间
  95. * 4、优惠券IDs
  96. * 5、订单总金额,用于校验比对
  97. * 6、下单成功,请求支付
  98. * @param OrderOnlineRequest $request
  99. * @return ResponseInterface
  100. */
  101. public function add(OrderOnlineRequest $request){
  102. // 下单
  103. $params = $request->validated();
  104. $data = $this->orderOnlineService->do(
  105. $params['market_id'],
  106. $params['user_id'],
  107. $params['user_address_id'],
  108. json_decode($params['store_list']),
  109. $params['total_money'],
  110. $params['delivery_time_note'],
  111. $params['service_money'],
  112. explode(',', $params['coupon_ids']),
  113. $params['plat']
  114. );
  115. return $this->success(['data' => $data]);
  116. }
  117. }