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.

89 lines
2.6 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\Model\v3\OrderMain;
  7. use App\Request\v3\OrderOfflineRequest;
  8. use App\Request\v3\OrderOnlineRequest;
  9. use App\Service\v3\Interfaces\OrderOfflineServiceInterface;
  10. use App\Service\v3\Interfaces\StoreServiceInterface;
  11. use Hyperf\Validation\ValidationException;
  12. use Hyperf\Di\Annotation\Inject;
  13. use Psr\Http\Message\ResponseInterface;
  14. class OrderOfflineController extends BaseController
  15. {
  16. /**
  17. * @Inject
  18. * @var StoreServiceInterface
  19. */
  20. protected $storeService;
  21. /**
  22. * @Inject
  23. * @var OrderOfflineServiceInterface
  24. */
  25. protected $orderOfflineService;
  26. /**
  27. * 当面付的页面详情
  28. * 1、上传store_id,获取商户相关信息
  29. * 2、返回商户相关信息即可
  30. */
  31. public function review()
  32. {
  33. $validator = $this->validationFactory->make(
  34. $this->request->all(),
  35. ['store_id' => 'required|nonempty'],
  36. ['*.*' => '商户ID参数异常']
  37. );
  38. if ($validator->fails()) {
  39. throw new ValidationException($validator);
  40. }
  41. $params = $validator->validated();
  42. $store = $this->storeService->detail($params['store_id']);
  43. return $this->success(['store' => $store, 'digit_length' => 7]);
  44. }
  45. /**
  46. * 当面付下单支付
  47. * 1、用户id、去商户id下支付、支付的金额
  48. * 2、下单同时支付,下发支付参数
  49. * @param OrderOfflineRequest $request
  50. * @return ResponseInterface
  51. */
  52. public function add(OrderOfflineRequest $request)
  53. {
  54. $params = $request->validated();
  55. $data = $this->orderOfflineService->do(
  56. $params['store_id'],
  57. $params['user_id'],
  58. $params['money'],
  59. $params['plat']
  60. );
  61. return $this->success(['data' => $data]);
  62. }
  63. /**
  64. * 当面付完成页
  65. */
  66. public function completePage()
  67. {
  68. $globalOrderId = $this->request->input('global_order_id', 0);
  69. $userId = $this->request->input('user_id', 0);
  70. $orderMain = OrderMain::query()
  71. ->with('orders.store')
  72. ->where(['global_order_id' => $globalOrderId, 'user_id' => $userId])
  73. ->first();
  74. if (empty($orderMain)) {
  75. throw new ErrorCodeException(ErrorCode::ORDER_NOT_AVAILABLE, '', ['message' => '当面付订单完成页', 'data' => ['global_order_id' => $globalOrderId,'user_id' => $userId]]);
  76. }
  77. return $this->success(['order_main' => $orderMain]);
  78. }
  79. }