OrderController.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. namespace app\workerapi\controller\shops;
  3. use app\common\logic\PaymentLogic;
  4. use app\workerapi\controller\BaseApiController;
  5. use app\workerapi\lists\shops\ShopOrderLists;
  6. use app\workerapi\logic\shops\ShopOrderLogic;
  7. use app\workerapi\validate\shops\ShopOrderValidate;
  8. use app\workerapi\validate\shops\ShopPayValidate;
  9. /**
  10. * 商城订单
  11. */
  12. class OrderController extends BaseApiController
  13. {
  14. public function submitOrder()
  15. {
  16. $params = (new ShopOrderValidate())->post()->goCheck('submit', [
  17. 'user_id' => $this->userId,
  18. 'terminal' => $this->userInfo['terminal'],
  19. 'user_info' => $this->userInfo
  20. ]);
  21. $result = ShopOrderLogic::submitOrder($params);
  22. if (false === $result) {
  23. return $this->fail(ShopOrderLogic::getError());
  24. }
  25. return $this->data($result);
  26. }
  27. public function lists()
  28. {
  29. return $this->dataLists(new ShopOrderLists());
  30. }
  31. public function detail()
  32. {
  33. $params = (new ShopOrderValidate())->goCheck('detail',[
  34. 'worker_id' => $this->userId,
  35. ]);
  36. $result = ShopOrderLogic::detail($params);
  37. if (false === $result) {
  38. return $this->fail(ShopOrderLogic::getError());
  39. }
  40. return $this->data($result);
  41. }
  42. /**
  43. * 取消订单
  44. */
  45. public function cancelOrder()
  46. {
  47. $params = (new ShopOrderValidate())->goCheck('detail',[
  48. 'worker_id' => $this->userId,
  49. ]);
  50. $result = ShopOrderLogic::cancelOrder($params);
  51. if (false === $result) {
  52. return $this->fail(ShopOrderLogic::getError());
  53. }
  54. return $this->success('取消成功', [], 1, 1);
  55. }
  56. /**
  57. * @notes 预支付
  58. * @return \think\response\Json
  59. */
  60. public function prepay()
  61. {
  62. $params = (new ShopPayValidate())->post()->goCheck('pay');
  63. //订单信息
  64. $order = PaymentLogic::getPayShopOrderInfo($params);
  65. if (false === $order) {
  66. return $this->fail(PaymentLogic::getError(), $params);
  67. }
  68. //支付流程
  69. $redirectUrl = $params['redirect'] ?? '/pages/payment/payment';
  70. $result = PaymentLogic::shopPay($params['pay_way'], 'shop_goods', $order, $this->userInfo['terminal'], $redirectUrl);
  71. if (false === $result) {
  72. return $this->fail(PaymentLogic::getError(), $params);
  73. }
  74. $result['sn'] = $order['sn'];
  75. return $this->success('', $result);
  76. }
  77. }