Browse Source

充值回调调整

zhangxiaobin 1 year ago
parent
commit
7c150469ad
2 changed files with 31 additions and 2 deletions
  1. 2 1
      .gitignore
  2. 29 1
      application/api/controller/Pay.php

+ 2 - 1
.gitignore

@@ -6,4 +6,5 @@
 /runtime/*
 /public/uploads/*
 .env.sample
-.env
+.env
+/paylog/*

+ 29 - 1
application/api/controller/Pay.php

@@ -291,8 +291,36 @@ class Pay extends Api
             return false;
         }
         //赠送优惠券
+        $rg = 'recharge_gift';
+        $c = 'coupons';
+        $field = $rg.'.*,'.$c.'.name,'.$c.'.info,'.$c.'.days';
         $rechargeGiftWhere['config_id'] = $orderInfo['table_id'];
-        //$rechargeGift = Db::name('')->where($rechargeGiftWhere)->select();
+        $rechargeGiftWhere[$c.'.status'] = 1;
+        $rechargeGift = Db::name($rg)->alias($rg)->field($field)
+            ->join($c,$c.'.id = '.$rg.'.coupon_id','LEFT')->where($rechargeGiftWhere)->select();
+        if (!empty($rechargeGift)) {
+            $time = time();
+            foreach ($rechargeGift as $key => $value) {
+                $endtime = $time + 86400 * $value['days'];
+                $userCouponsData[] = [
+                    'user_id' => $orderInfo['user_id'],
+                    'company_id' => $orderInfo['company_id'],
+                    'coupons_id' => $value['coupon_id'],
+                    'coupon_name' => $value['name'],
+                    'coupon_info' => $value['info'],
+                    'createtime' => $time,
+                    'endtime' => $endtime,
+                    'number' => $value['number'],
+                    'remain' => $value['number'],
+                    'payorder_id' => $orderInfo['id'],
+                    'getfrom' => '充值赠送',
+                ];
+            }
+            $userCouponsRes = Db::name('user_coupons')->insertAll($userCouponsData);
+            if (!$userCouponsRes) {
+                throw new Exception('赠送优惠失败');
+            }
+        }
         $userWalletWhere['user_id'] = $orderInfo['user_id'];
         $userWalletWhere['company_id'] = $orderInfo['company_id'];
         $userWalletData = Db::name('user_wallet')->where($userWalletWhere)->find();