panda 1 سال پیش
والد
کامیت
25d7f53208
2فایلهای تغییر یافته به همراه105 افزوده شده و 0 حذف شده
  1. 83 0
      application/index/controller/Plantask.php
  2. 22 0
      application/utils/JingXiu/JingXiuPayUtil.php

+ 83 - 0
application/index/controller/Plantask.php

@@ -2,12 +2,95 @@
 
 namespace app\index\controller;
 
+use app\utils\JingXiu\JingXiuPayUtil;
 use think\Controller;
 use think\Db;
 use think\Cache;
 
 class Plantask extends Controller
 {
+    /**
+     * 精秀支付订单支付状态查询
+     * @return string|void
+     */
+    public function pay_queue()
+    {
+        // 处理次数
+        $queue_times = 6;
+        //查询订单信息 十分钟未处理的
+        $order_info = Db::name('pay_order')
+            ->where('queue_status', 1)
+            ->where('status',0)
+            ->where('queue_times','<',$queue_times)
+            ->where('createtime','<',time() - 600)
+            ->order('queue_times','asc')
+            ->find();
+        if (!$order_info){
+            return '无订单';
+        }
+        // 增加处理次数
+        Db::name('pay_order')->where('id',$order_info['id'])->inc('queue_times');
+        // 查询订单是否支付成功
+        $pay = new JingXiuPayUtil();
+        if (!$pay->getOrder($order_info['pay_no'])){
+            $this->error($pay->getMessage());
+        }
+        $params = $pay->getData();
+        if (empty($params['order_status']) || $params['order_status'] != 'SUCCESS' || empty($params['out_trade_no'])) {
+            return '支付信息有误';
+        }
+        // 开始处理业务逻辑
+        $pay_no = $params['out_trade_no'];
+        //查询订单信息
+        $order_info = Db::name('pay_order')->where('pay_no', $pay_no)->find();
+        if (!$order_info) {
+            return '订单信息不存在'.$pay_no;
+        }
+        if ($order_info['status'] == 3){
+            return '订单信息_已删除'.$pay_no;
+        }
+        if ($order_info['status'] == 1 || $order_info['status'] == 2) {
+            return '充值入账更新余额失败_status已更新过'.$pay_no;
+        }
+
+        $extendType = '';
+        //区分vip 还是 冲金币
+        $is_g = stripos($pay_no, 'P');
+        if ($is_g !== false) {
+            $extendType = 'gold';
+        } else {
+            $is_v = stripos($pay_no, 'V');
+            if ($is_v !== false) {
+                $extendType = 'vip';
+            }
+        }
+
+        //status已更新过
+        $result = Db::name('pay_order')->where('pay_no', $pay_no)->where('status',$order_info['status'])->setField(['status' => 2]);
+        if (!$result) {
+            return '充值入账更新余额失败_status更新状态2不成功'.$pay_no;
+        }
+
+        //你可以在此编写订单逻辑
+        $payEvent = Db::name('pay_event')->where('pay_no', $pay_no)->find();
+        $args = json_decode($payEvent['args'] ?? '', true);
+        $rechargeM = new \app\common\model\Recharge();
+        if ($extendType == 'gold') {
+            $payRes = $rechargeM->goldpaysucc($pay_no, $args);
+            $payTypeStr = '充值';
+        } elseif ($extendType == 'vip') {
+            $payRes = $rechargeM->vippaysucc($pay_no, $args);
+            $payTypeStr = 'vip';
+        } else {
+            $payRes = false;
+            $payTypeStr = '未知支付类型';
+        }
+        if (!$payRes) {
+            return '更新失败'.$payTypeStr.$pay_no;
+        }
+
+        return '订单处理成功'.$payTypeStr.$pay_no;
+    }
     //计划任务
     //定时跑用户活跃,改成离线
     public function user_active(){

+ 22 - 0
application/utils/JingXiu/JingXiuPayUtil.php

@@ -47,6 +47,28 @@ class JingXiuPayUtil extends Module
     }
 
     /**
+     * 获取订单信息
+     * @param $out_trade_no
+     * @return mixed
+     * @throws \Exception
+     */
+    public function getOrder($out_trade_no)
+    {
+        $client = new PasspayClient($this->host, $this->mch_id, $this->merchant_private_key, $this->platform_public_key);
+        $param      = [
+            'out_trade_no'   => $out_trade_no,
+        ];
+
+        try {
+            $result   = $client->execute('pay.order/query', $param);
+        } catch (\Exception $e) {
+            return $this->error('获取失败!' . $e->getMessage());
+        }
+        return $this->success('获取成功!', $result);
+    }
+
+    /**
+     * 校验通知签名
      * @param $params
      * @return bool
      */