1
0

PayController.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. /**
  9. * 支付
  10. * Class PayController
  11. * @package app\api\controller
  12. */
  13. class PayController extends \app\workerapi\controller\BaseApiController
  14. {
  15. /**
  16. * @notes 工程师代支付
  17. * @return \think\response\Json
  18. */
  19. public function prepay()
  20. {
  21. $params = (new PayValidate())->post()->goCheck();
  22. //订单信息
  23. $order = PaymentLogic::getPayOrderInfo($params);
  24. if (false === $order) {
  25. return $this->fail(PaymentLogic::getError(), $params);
  26. }
  27. //支付流程
  28. $redirectUrl = $params['redirect'] ?? '/pages/payment/payment';
  29. $result = PaymentLogic::pay($params['pay_way'], $params['from'], $order, $this->userInfo['terminal'], $redirectUrl);
  30. if (false === $result) {
  31. return $this->fail(PaymentLogic::getError(), $params);
  32. }
  33. $result['sn'] = $order['sn'];
  34. return $this->success('', $result);
  35. }
  36. /**
  37. * @notes 获取支付状态
  38. * @return \think\response\Json
  39. */
  40. public function payStatus()
  41. {
  42. $params = (new PayValidate())->goCheck('status', ['user_id' => $this->userId]);
  43. $result = PaymentLogic::getPayStatus($params);
  44. if ($result === false) {
  45. return $this->fail(PaymentLogic::getError());
  46. }
  47. return $this->data($result);
  48. }
  49. }