Browse Source

最新ios充值优化

lizhen_gitee 1 year ago
parent
commit
4af49a47db
1 changed files with 35 additions and 7 deletions
  1. 35 7
      application/api/controller/Payios.php

+ 35 - 7
application/api/controller/Payios.php

@@ -162,7 +162,7 @@ class Payios extends Api
         $check_order = Db::name('user_vipxufei_task')->where($check_map)->field('id')->find();
         if($check_order){
             filePut($prefix.'续费早已完成');
-            $this->success('充值已完成');
+            $this->success('充值已完成');
         }
 
 
@@ -204,19 +204,47 @@ class Payios extends Api
         //原始id换给别人用了
         $order_info_bundle_id = $order_info['bundle_id'];
         $order_info_user_id   = $order_info['user_id'];
+        //在app里,不能连续购买同一个续费规格(bunder_id),可以升级或降级另一个续费规格。也可以在苹果商店直接修改规格(不产生新订单)。
         if($only_trans['product_id'] != $order_info['bundle_id'] || $order_info['user_id'] != $this->auth->id){
 
             $pay_order_map = [
-                'user_id' => $this->auth->id,
-                'bundle_id' => $only_trans['product_id'],
+                'user_id'   => ($order_info['user_id']   != $this->auth->id)           ? $this->auth->id           : $order_info['user_id'],
+                'bundle_id' => ($order_info['bundle_id'] != $only_trans['product_id']) ? $only_trans['product_id'] : $order_info['bundle_id'],
                 'order_status' => 0,
                 'table_name' => 'vip_recharge',
             ];
             $pay_order = Db::name('pay_order')->where($pay_order_map)->order('id desc')->lock(true)->find();
             if(!$pay_order){
-                Db::rollback();
+                /*Db::rollback();
                 filePut($prefix.'未找到匹配的交易,新订单找不到');
-                $this->error('未找到匹配的新订单');
+                $this->error('未找到匹配的新订单');*/
+
+                //创建订单
+                $recharge_config = Db::name('payvip_config_ios')->where('id',$pay_order_map['bundle_id'])->find();
+                $new_order = [
+                   'user_id' => $pay_order_map['user_id'],
+                   'out_trade_no'=> createUniqueNo('NV',$pay_order_map['user_id']), // 数据库订单号加密
+                   'order_amount'=> $recharge_config['money'],
+                   'createtime'=> time(),
+
+                   'pay_type'=> 'ios',
+                   'platform'=> 'app',
+                   'order_status'=> 0,
+                   'table_name'=> 'vip_recharge',
+                   'table_id'=> 0,
+                   'args'=> json_encode(['days'=>$recharge_config['days']]),
+                   'bundle_id'=> $recharge_config['bundle_id'],
+                   'is_lianxu'=> $recharge_config['is_lianxu'],
+                ];
+                $new_orderid = Db::name('pay_order')->insertGetId($new_order);
+                if(!$new_orderid){
+                    Db::rollback();
+                    filePut($prefix.'未找到匹配的交易,创建新订单失败');
+                    $this->error('创建新订单失败');
+                }
+                $pay_order = $new_order;
+                $pay_order['id'] = $new_orderid;
+
             }
             // 修改订单状态
             $update_order = [
@@ -243,13 +271,13 @@ class Payios extends Api
         }
 
         //验证时间,不得小于最新的一条预定信息
-        if($order_info_user_id == $this->auth->id){
+//        if($order_info_user_id == $this->auth->id){
             if($only_trans['purchase_date_ms'] <= $order_info['purchase_date_ms'] || $only_trans['expires_date_ms'] <= $order_info['expires_date_ms']){
                 Db::rollback();
                 filePut($prefix.'时间对不上,返回成功,finish掉');
                 $this->success(1);
             }
-        }
+//        }
 
         //逻辑开始
         //先充值