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.

131 lines
4.5 KiB

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