1
0

PayController.php 2.0 KB

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