PayController.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 think\facade\Log;
  10. /**
  11. * 支付
  12. * Class PayController
  13. * @package app\api\controller
  14. */
  15. class PayController extends \app\workerapi\controller\BaseApiController
  16. {
  17. public array $notNeedLogin = ['notifyMnp'];
  18. /**
  19. * @notes 工程师代支付
  20. * @return \think\response\Json
  21. */
  22. public function prepay()
  23. {
  24. $params = (new PayValidate())->post()->goCheck();
  25. //订单信息
  26. $order = PaymentLogic::getPayOrderInfo($params);
  27. if (false === $order) {
  28. return $this->fail(PaymentLogic::getError(), $params);
  29. }
  30. //支付流程
  31. $redirectUrl = $params['redirect'] ?? '/pages/payment/payment';
  32. $result = PaymentLogic::workerPay($params['pay_way'], $params['from'], $order, $this->userInfo, $redirectUrl);
  33. if (false === $result) {
  34. return $this->fail(PaymentLogic::getError(), $params);
  35. }
  36. $result['sn'] = $order['sn'];
  37. return $this->success('', $result);
  38. }
  39. /**
  40. * @notes 获取支付状态
  41. * @return \think\response\Json
  42. */
  43. public function payStatus()
  44. {
  45. $params = (new PayValidate())->goCheck('status', ['user_id' => $this->userId]);
  46. $result = PaymentLogic::getPayStatus($params);
  47. if ($result === false) {
  48. return $this->fail(PaymentLogic::getError());
  49. }
  50. return $this->data($result);
  51. }
  52. /**
  53. * @notes 小程序支付回调
  54. * @return \Psr\Http\Message\ResponseInterface
  55. * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
  56. * @throws \EasyWeChat\Kernel\Exceptions\RuntimeException
  57. * @throws \ReflectionException
  58. * @throws \Throwable
  59. */
  60. public function notifyMnp()
  61. {
  62. return (new WorkerWeChatPayService(UserTerminalEnum::WECHAT_MMP))->notify();
  63. }
  64. }