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.

167 lines
5.8 KiB

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\CouponServiceInterface;
  9. use Hyperf\Di\Annotation\Inject;
  10. use App\Service\v3\Interfaces\OrderOnlineServiceInterface;
  11. use App\Service\v3\Interfaces\UserBindTelServiceInterface;
  12. use App\Service\v3\Interfaces\AppointmentTimeServiceInterface;
  13. use Psr\Http\Message\ResponseInterface;
  14. class OrderOnlineController extends BaseController
  15. {
  16. /**
  17. * @Inject
  18. * @var UserBindTelServiceInterface
  19. */
  20. protected $userBindTelService;
  21. /**
  22. * @Inject
  23. * @var CouponServiceInterface
  24. */
  25. protected $couponService;
  26. /**
  27. * @Inject
  28. * @var AppointmentTimeServiceInterface
  29. */
  30. protected $appointmentTimeService;
  31. /**
  32. * @Inject
  33. * @var OrderOnlineServiceInterface
  34. */
  35. protected $orderOnlineService;
  36. /*
  37. * 如果没有绑手机号去绑定页面
  38. * 收货地址接口
  39. * 返回预约送达时间
  40. * 商品数据接口
  41. * 红包独立接口
  42. * 配送费独立接口 可根据距离动态计算费用
  43. * 增值服务接口
  44. * */
  45. public function review()
  46. {
  47. $params = $this->request->all();
  48. //判断用户有没有绑定手机
  49. // $telExists = $this->userBindTelService->check($params['user_id']);
  50. // if(!$telExists){
  51. // throw new ErrorCodeException(ErrorCode::NOT_BIND_TEL_ERROR);
  52. // }
  53. //获取用户收货地址
  54. $res['address'] = [
  55. 'address' => '南宁市良庆区五象海尔·青啤联合广场',
  56. 'area' => 'A栋八单元' ,
  57. 'lat' => '22.759950637817383',
  58. 'lng' => '108.3835678100586',
  59. 'sex' => '1',
  60. 'tel' => '15677717734',
  61. 'user_name' => '李小龙',
  62. 'user_id' => '214'
  63. ];
  64. //返回预约送达时间 数组
  65. $res['appointment_time'] = $this->appointmentTimeService->do();
  66. //
  67. $res['store_list'] = [
  68. [
  69. 'store_nmae' => '五金杂货铺',
  70. 'price' => '100.00',
  71. 'note' => '多放辣椒',
  72. 'store_id' => 66,
  73. 'goods_list' =>
  74. [
  75. [
  76. 'id' => 3971,
  77. 'goods_id' => 1301,
  78. 'name' => '半边手撕鸡',
  79. 'num' => 4,
  80. 'price' => '90.00',
  81. 'total' => '360.00'
  82. ]
  83. ]
  84. ],
  85. [
  86. 'store_nmae' => '回味手撕鸡J009',
  87. 'note' => '手撕鸡加辣',
  88. 'store_price' => '720.00',
  89. 'store_id' => 123,
  90. 'goods_list' =>
  91. [
  92. [
  93. 'id' => 3971,
  94. 'goods_id' => 1301,
  95. 'name' => '半边手撕鸡',
  96. 'num' => 4,
  97. 'price' => '90.00',
  98. 'total' => '360.00'
  99. ],
  100. [
  101. 'id' => 3971,
  102. 'goods_id' => 1301,
  103. 'name' => '半边手撕鸡',
  104. 'num' => 4,
  105. 'price' => '90.00',
  106. 'total' => '360.00'
  107. ]
  108. ]
  109. ],
  110. ];
  111. //获取用户优惠券
  112. $res['coupon'] = $this->couponService->getUserAvailableCoupons('',$params['user_id'],'',2,'','');
  113. //获取配送费
  114. $res['distribution'] = '5.0';
  115. //增值服务接口
  116. $res['value_added_service'] = [
  117. 'select' => 1,
  118. 'price' => 3.50
  119. ];
  120. return $this->success($res);
  121. }
  122. /**
  123. * 订单详情
  124. * 1、主订单信息,用户配送信息(地址、姓名、电话、配送时间、配送类型)、基础信息(订单ID、订单编号、下单时间、订单金额、付款时间、支付方式、红包优惠、服务站电话、增值服务费)
  125. * 2、子订单以及订单商品,按商户分组,有商户信息(ID、商户名、商户logo),商品信息(id、名字、封面、规格、tag、原价、售价、库存、总销、月销、是否失效、失效原因)
  126. * @param OrderOnlineDetailRequest $request
  127. * @return ResponseInterface
  128. */
  129. public function detailByUser(OrderOnlineDetailRequest $request)
  130. {
  131. $params = $request->validated();
  132. return $this->success(['detail' => $this->orderOnlineService->detailByUser($params['order_id'], $params['user_id'])]);
  133. }
  134. /**
  135. * 下单并进行支付,返回支付参数
  136. * 1、用户传参,用户地址ID,用于获取用户地址经纬度来计算配送费
  137. * 2、用户传参,购物车IDs,去获取购物车里的商品详情
  138. * 3、预约送达时间
  139. * 4、优惠券IDs
  140. * 5、订单总金额,用于校验比对
  141. * 6、下单成功,请求支付
  142. * @param OrderOnlineRequest $request
  143. * @return ResponseInterface
  144. */
  145. public function add(OrderOnlineRequest $request){
  146. // 下单
  147. $params = $request->validated();
  148. $data = $this->orderOnlineService->do(
  149. $params['market_id'],
  150. $params['user_id'],
  151. $params['user_address_id'],
  152. explode(',', $params['cart_ids']),
  153. $params['total_money'],
  154. $params['delivery_time_note'],
  155. explode(',', $params['coupon_ids'])
  156. );
  157. return $this->success(['data' => $data]);
  158. }
  159. }