| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- <?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;
- use app\common\service\pay\WorkerWeChatPayService;
- use app\adminapi\logic\master_worker\MasterWorkerLogic;
- use think\facade\Log;
- /**
- * 支付
- * Class PayController
- * @package app\api\controller
- */
- class PayController extends \app\workerapi\controller\BaseApiController
- {
- public array $notNeedLogin = ['notifyMnp','sharePrepay','notifyOa','retentionMoneyOrder','retentionMoneyPrepay'];
- /**
- * @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::workerPay($params['pay_way'], $params['from'], $order, $this->userInfo, $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);
- }
- /**
- * @notes 小程序支付回调
- * @return \Psr\Http\Message\ResponseInterface
- * @throws \EasyWeChat\Kernel\Exceptions\InvalidArgumentException
- * @throws \EasyWeChat\Kernel\Exceptions\RuntimeException
- * @throws \ReflectionException
- * @throws \Throwable
- */
- public function notifyMnp()
- {
- return (new WorkerWeChatPayService(UserTerminalEnum::WECHAT_MMP))->notify();
- }
- /**
- * @notes 工单分享代付
- * @return \think\response\Json
- */
- public function sharePrepay()
- {
- $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::workerSharePay($params['pay_way'], $params['from'], $order, ['openid'=>$params['openid']??''], $redirectUrl);
- if (false === $result) {
- return $this->fail(PaymentLogic::getError(), $params);
- }
- $result['sn'] = $order['sn'];
- return $this->success('', $result);
- }
- public function notifyOa()
- {
- return (new WorkerWeChatPayService(UserTerminalEnum::WECHAT_OA))->notify();
- }
- /**
- * @notes 质保金缴费订单
- * @return \think\response\Json
- */
- public function retentionMoneyOrder()
- {
- $order_id = $this->request->get('order_id');
- $result = MasterWorkerLogic::retentionMoneyOrderDetail($order_id);
- return $this->success('', $result);
- }
- /**
- * @notes 质保金预支付
- * @return \think\response\Json
- */
- public function retentionMoneyPrepay()
- {
- $params = (new PayValidate())->post()->goCheck();
- //订单信息
- $order = PaymentLogic::getPayRetentionMoneyOrderInfo($params);
- if (false === $order) {
- return $this->fail(PaymentLogic::getError(), $params);
- }
- //支付流程
- $redirectUrl = $params['redirect'] ?? '/pages/payment/payment';
- $result = PaymentLogic::workerRetentionMoneyPay(2, $params['from'], $order, ['openid'=>$params['openid']??''], $redirectUrl);
- if (false === $result) {
- return $this->fail(PaymentLogic::getError(), $params);
- }
- $result['sn'] = $order['sn'];
- return $this->success('', $result);
- }
- }
|