|
|
@@ -0,0 +1,54 @@
|
|
|
+<?php
|
|
|
+namespace app\workerapi\controller;
|
|
|
+
|
|
|
+use app\api\validate\PayValidate;
|
|
|
+use app\common\enum\user\UserTerminalEnum;
|
|
|
+use app\common\logic\PaymentLogic;
|
|
|
+use app\common\service\pay\AliPayService;
|
|
|
+use app\common\service\pay\WeChatPayService;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 支付
|
|
|
+ * Class PayController
|
|
|
+ * @package app\api\controller
|
|
|
+ */
|
|
|
+class PayController extends \app\workerapi\controller\BaseApiController
|
|
|
+{
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @notes 工程师代支付
|
|
|
+ * @return \think\response\Json
|
|
|
+ */
|
|
|
+ public function prepay()
|
|
|
+ {
|
|
|
+ $params = (new PayValidate())->post()->goCheck();
|
|
|
+ //订单信息
|
|
|
+ $order = PaymentLogic::getPayOrderInfo($params);
|
|
|
+ if (false === $order) {
|
|
|
+ return $this->fail(PaymentLogic::getError(), $params);
|
|
|
+ }
|
|
|
+ //支付流程
|
|
|
+ $redirectUrl = $params['redirect'] ?? '/pages/payment/payment';
|
|
|
+ $result = PaymentLogic::pay($params['pay_way'], $params['from'], $order, $this->userInfo['terminal'], $redirectUrl);
|
|
|
+ if (false === $result) {
|
|
|
+ return $this->fail(PaymentLogic::getError(), $params);
|
|
|
+ }
|
|
|
+ $result['sn'] = $order['sn'];
|
|
|
+ return $this->success('', $result);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @notes 获取支付状态
|
|
|
+ * @return \think\response\Json
|
|
|
+ */
|
|
|
+ public function payStatus()
|
|
|
+ {
|
|
|
+ $params = (new PayValidate())->goCheck('status', ['user_id' => $this->userId]);
|
|
|
+ $result = PaymentLogic::getPayStatus($params);
|
|
|
+ if ($result === false) {
|
|
|
+ return $this->fail(PaymentLogic::getError());
|
|
|
+ }
|
|
|
+ return $this->data($result);
|
|
|
+ }
|
|
|
+}
|