PayController.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. namespace app\workerapi\controller;
  3. use app\api\validate\PayValidate;
  4. use app\common\enum\user\UserTerminalEnum;
  5. use app\common\logic\PaymentLogic;
  6. use app\common\service\pay\AliPayService;
  7. use app\common\service\pay\WeChatPayService;
  8. use app\common\service\pay\WorkerWeChatPayService;
  9. use app\adminapi\logic\master_worker\MasterWorkerLogic;
  10. use think\facade\Log;
  11. /**
  12. * 支付
  13. * Class PayController
  14. * @package app\api\controller
  15. */
  16. class PayController extends \app\workerapi\controller\BaseApiController
  17. {
  18. public array $notNeedLogin = ['notifyMnp','sharePrepay','notifyOa','retentionMoneyOrder','retentionMoneyPrepay'];
  19. /**
  20. * @notes 工程师代支付
  21. * @return \think\response\Json
  22. */
  23. public function prepay()
  24. {
  25. $params = (new PayValidate())->post()->goCheck();
  26. //订单信息
  27. $order = PaymentLogic::getPayOrderInfo($params);
  28. if (false === $order) {
  29. return $this->fail(PaymentLogic::getError(), $params);
  30. }
  31. //支付流程
  32. $redirectUrl = $params['redirect'] ?? '/pages/payment/payment';
  33. $result = PaymentLogic::workerPay($params['pay_way'], $params['from'], $order, $this->userInfo, $redirectUrl);
  34. if (false === $result) {
  35. return $this->fail(PaymentLogic::getError(), $params);
  36. }
  37. $result['sn'] = $order['sn'];
  38. return $this->success('', $result);
  39. }
  40. /**
  41. * @notes 获取支付状态
  42. * @return \think\response\Json
  43. */
  44. public function payStatus()
  45. {
  46. $params = (new PayValidate())->goCheck('status', ['user_id' => $this->userId]);
  47. $result = PaymentLogic::getPayStatus($params);
  48. if ($result === false) {
  49. return $this->fail(PaymentLogic::getError());
  50. }
  51. return $this->data($result);
  52. }
  53. /**
  54. * @notes 小程序支付回调
  55. * @return \Psr\Http\Message\ResponseInterface
  56. * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
  57. * @throws \EasyWeChat\Kernel\Exceptions\RuntimeException
  58. * @throws \ReflectionException
  59. * @throws \Throwable
  60. */
  61. public function notifyMnp()
  62. {
  63. return (new WorkerWeChatPayService(UserTerminalEnum::WECHAT_MMP))->notify();
  64. }
  65. /**
  66. * @notes 工单分享代付
  67. * @return \think\response\Json
  68. */
  69. public function sharePrepay()
  70. {
  71. $params = (new PayValidate())->post()->goCheck();
  72. //订单信息
  73. $order = PaymentLogic::getPayOrderInfo($params);
  74. if (false === $order) {
  75. return $this->fail(PaymentLogic::getError(), $params);
  76. }
  77. //支付流程
  78. $redirectUrl = $params['redirect'] ?? '/pages/payment/payment';
  79. $result = PaymentLogic::workerSharePay($params['pay_way'], $params['from'], $order, ['openid'=>$params['openid']??''], $redirectUrl);
  80. if (false === $result) {
  81. return $this->fail(PaymentLogic::getError(), $params);
  82. }
  83. $result['sn'] = $order['sn'];
  84. return $this->success('', $result);
  85. }
  86. public function notifyOa()
  87. {
  88. return (new WorkerWeChatPayService(UserTerminalEnum::WECHAT_OA))->notify();
  89. }
  90. /**
  91. * @notes 质保金缴费订单
  92. * @return \think\response\Json
  93. */
  94. public function retentionMoneyOrder()
  95. {
  96. $order_id = $this->request->get('order_id');
  97. $result = MasterWorkerLogic::retentionMoneyOrderDetail($order_id);
  98. return $this->success('', $result);
  99. }
  100. /**
  101. * @notes 质保金预支付
  102. * @return \think\response\Json
  103. */
  104. public function retentionMoneyPrepay()
  105. {
  106. $params = (new PayValidate())->post()->goCheck();
  107. //订单信息
  108. $order = PaymentLogic::getPayRetentionMoneyOrderInfo($params);
  109. if (false === $order) {
  110. return $this->fail(PaymentLogic::getError(), $params);
  111. }
  112. //支付流程
  113. $redirectUrl = $params['redirect'] ?? '/pages/payment/payment';
  114. $result = PaymentLogic::workerRetentionMoneyPay(2, $params['from'], $order, ['openid'=>$params['openid']??''], $redirectUrl);
  115. if (false === $result) {
  116. return $this->fail(PaymentLogic::getError(), $params);
  117. }
  118. $result['sn'] = $order['sn'];
  119. return $this->success('', $result);
  120. }
  121. }