Quellcode durchsuchen

修改注册 检查会员等级

15954078560 vor 2 Jahren
Ursprung
Commit
108fe8cdad
2 geänderte Dateien mit 15 neuen und 6 gelöschten Zeilen
  1. 10 2
      application/api/controller/User.php
  2. 5 4
      application/common/controller/Api.php

+ 10 - 2
application/api/controller/User.php

@@ -1257,6 +1257,7 @@ class User extends Api
                 'type' => $register_coupon['type'],
                 'money' => $register_coupon['money'],
                 'minmoney' => $register_coupon['minmoney'],
+                'purpose' => $register_coupon['purpose'],
                 'starttime' => time(),
                 'endtime' => time() + $register_coupon['effectiveday'] * 86400,
                 'createtime' => time()
@@ -1270,8 +1271,14 @@ class User extends Api
         }
         //查询是否需要给上级发放优惠券
         if ($invite_info) {
-            $invite_count = Db::name('user')->where(['pre_user_id' => $invite_info['id']])->count();
-            if ($invite_count > 0 && $invite_count % 10 == 0) {
+            //查询上一次获得推广优惠券时间
+            $last_coupon = Db::name('user_coupon')->where(['user_id' => $invite_info['id'], 'purpose' => 2])->order('id', 'desc')->find();
+            $last_coupon_time = $last_coupon ? $last_coupon['createtime'] : 0;
+            //获取后台配置推广获得优惠券指定人数
+            $invitepersonnum = (int)config('site.invitepersonnum');
+            //查询最新推广任务
+            $invite_count = Db::name('user')->where(['pre_user_id' => $invite_info['id'], 'createtime' => ['gt', $last_coupon_time]])->count();
+            if ($invite_count >= $invitepersonnum && $invitepersonnum > 0) {
                 //每邀请10人发放一次优惠券
                 //查询推广优惠券
                 $invite_coupon = Db::name('coupon')->where(['purpose' => 2, 'status' => 1])->order('weigh desc, id desc')->find();
@@ -1284,6 +1291,7 @@ class User extends Api
                         'type' => $invite_coupon['type'],
                         'money' => $invite_coupon['money'],
                         'minmoney' => $invite_coupon['minmoney'],
+                        'purpose' => $invite_coupon['purpose'],
                         'starttime' => time(),
                         'endtime' => time() + $invite_coupon['effectiveday'] * 86400,
                         'createtime' => time()

+ 5 - 4
application/common/controller/Api.php

@@ -196,16 +196,17 @@ class Api
             $growthvalue = Db::name('user')->where(['id' => $this->auth->id])->value('growthvalue');
             $vip_info = Db::name('vip')->where(['growthvalue' => ['elt', $growthvalue]])->order('id', 'desc')->find();
             $user_data = [];
-            if ($vip_info['id'] > $this->auth->growthlevel) {
+            if ($vip_info['id'] != $this->auth->growthlevel) {
                 $user_data['growthlevel'] = $vip_info['id'];
                 //当前会员信息
-                $last_vip_info = Db::name('vip')->find($vip_info['id']);
-                $user_data['freenumber'] = $this->auth->freenumber + $vip_info['free'] - $last_vip_info['free'];
+                $last_vip_info = Db::name('vip')->find($this->auth->growthlevel);
+                $freenumber = $this->auth->freenumber + $vip_info['free'] - $last_vip_info['free'];
+                $user_data['freenumber'] = $freenumber > 0 ? $freenumber : 0;//免费次数
             }
             //检查体验会员
             if ($this->auth->experiencetime < time()) {
                 //体验会员到期
-                if ($vip_info['id'] > $this->auth->growthlevel) { //成长值会员等级更新
+                if ($vip_info['id'] != $this->auth->growthlevel) { //成长值会员等级更新
                     $user_data['maxlevel'] = $vip_info['id'];
                 } elseif ($this->auth->maxlevel != $this->auth->growthlevel) {
                     $user_data['maxlevel'] = $this->auth->growthlevel;