Browse Source

增加会员相关

15954078560 3 năm trước cách đây
mục cha
commit
9fd669d28c
1 tập tin đã thay đổi với 70 bổ sung31 xóa
  1. 70 31
      application/api/controller/Index.php

+ 70 - 31
application/api/controller/Index.php

@@ -493,21 +493,24 @@ class Index extends Api
         if (!$active_people) {
         if (!$active_people) {
             $this->error('请添加报名人员信息');
             $this->error('请添加报名人员信息');
         }
         }
-        $active_people = json_decode($active_people, true);
-        if (!$active_people) {
+        $active_people_arr = json_decode($active_people, true);
+        if (!$active_people_arr) {
             $this->error('请添加报名人员信息');
             $this->error('请添加报名人员信息');
         }
         }
-        if ($info['currentperson'] + count($active_people) > $info['maxperson']) {
+        if ($info['currentperson'] + count($active_people_arr) > $info['maxperson']) {
             $this->error('活动名额不足');
             $this->error('活动名额不足');
         }
         }
-
+        //会员信息
+        $vip_info = Db::name('vip')->find($this->auth->maxlevel);
+        if (!$vip_info) {
+            $this->error('会员信息缺失,请联系管理员');
+        }
         $_data = [];
         $_data = [];
         $total_amount = 0; //总价格验证
         $total_amount = 0; //总价格验证
         $active_people = Db::name('active_people'); //报名人员表
         $active_people = Db::name('active_people'); //报名人员表
         $active_people_modify = Db::name('active_people_modify'); //报名修改信息表
         $active_people_modify = Db::name('active_people_modify'); //报名修改信息表
-        $vip = Db::name('vip');
         $user_coupon = Db::name('user_coupon');
         $user_coupon = Db::name('user_coupon');
-        foreach ($active_people as &$v) {
+        foreach ($active_people_arr as $k => &$v) {
             $data = [];
             $data = [];
             //判断是否报名过
             //判断是否报名过
             $count = $active_people->where(['active_id' => $id, 'idcard' => $v['idcard']])->count('id');
             $count = $active_people->where(['active_id' => $id, 'idcard' => $v['idcard']])->count('id');
@@ -530,7 +533,12 @@ class Index extends Api
                 break;
                 break;
             }
             }
             //判断用户信息
             //判断用户信息
-            if ($v['is_self']) {
+            if ($v['is_self'] && $k == 0) {
+                //判断用户信息
+                if ($v['name'] != $this->auth->realname || $v['idcard'] != $this->auth->idcard || $v['mobile'] != $this->auth->mobile || $v['emergencycontact'] != $this->auth->emergencycontact || $v['contactmobile'] != $this->auth->contactmobile) {
+                    $this->error('本人信息错误');
+                    break;
+                }
                 //本人判断年龄 价格
                 //本人判断年龄 价格
                 if ($info['maxage'] > 0) {
                 if ($info['maxage'] > 0) {
                     $age = $this->idcardage($this->auth->idcard);
                     $age = $this->idcardage($this->auth->idcard);
@@ -544,6 +552,9 @@ class Index extends Api
                         $this->error('活动暂不支持免费体验');
                         $this->error('活动暂不支持免费体验');
                         break;
                         break;
                     }
                     }
+                    if ($this->auth->freenumber <= 0) {
+                        $this->error('您的免费次数不足');
+                    }
                     if ($v['vipprice'] != 0 || $v['price'] != 0) {
                     if ($v['vipprice'] != 0 || $v['price'] != 0) {
                         $this->error($this->auth->realname . '价格错误');
                         $this->error($this->auth->realname . '价格错误');
                         break;
                         break;
@@ -563,11 +574,6 @@ class Index extends Api
                     $now_day = date('md', time());
                     $now_day = date('md', time());
                     if ($birthday == $now_day) {
                     if ($birthday == $now_day) {
                         //生日折扣
                         //生日折扣
-                        $vip_info = $vip->find($this->auth->maxlevel);
-                        if (!$vip_info) {
-                            $this->error('会员信息缺失,请联系管理员');
-                            break;
-                        }
                         if ($vip_info['birthdiscount'] > 100 || $vip_info['birthdiscount'] < 0) {
                         if ($vip_info['birthdiscount'] > 100 || $vip_info['birthdiscount'] < 0) {
                             $this->error('会员生日折扣错误,请联系管理员');
                             $this->error('会员生日折扣错误,请联系管理员');
                             break;
                             break;
@@ -578,11 +584,6 @@ class Index extends Api
                         $discount = $info['girldiscount'];
                         $discount = $info['girldiscount'];
                     } else {
                     } else {
                         //会员折扣
                         //会员折扣
-                        $vip_info = $vip->find($this->auth->maxlevel);
-                        if (!$vip_info) {
-                            $this->error('会员信息缺失,请联系管理员');
-                            break;
-                        }
                         if ($vip_info['vipdiscount'] > 100 || $vip_info['vipdiscount'] < 0) {
                         if ($vip_info['vipdiscount'] > 100 || $vip_info['vipdiscount'] < 0) {
                             $this->error('会员折扣错误,请联系管理员');
                             $this->error('会员折扣错误,请联系管理员');
                             break;
                             break;
@@ -708,9 +709,18 @@ class Index extends Api
                     $this->error('请输入正确紧急联系人方式');
                     $this->error('请输入正确紧急联系人方式');
                     break;
                     break;
                 }
                 }
-                if ($v['price'] != $info['price']) {
-                    $this->error('小计显示错误');
-                    break;
+                //判断是否符合满几人减免一人费用
+                //会员权限
+                if ($vip_info['manypeople'] > 1 && $k == $vip_info['manypeople'] - 1) {
+                    if ($v['price'] != 0) {
+                        $this->error('小计显示错误');
+                        break;
+                    }
+                } else {
+                    if ($v['price'] != $info['price']) {
+                        $this->error('小计显示错误');
+                        break;
+                    }
                 }
                 }
 
 
                 $data['name'] = $v['name'];
                 $data['name'] = $v['name'];
@@ -718,7 +728,7 @@ class Index extends Api
                 $data['mobile'] = $v['mobile'];
                 $data['mobile'] = $v['mobile'];
                 $data['emergencycontact'] = $v['emergencycontact'];
                 $data['emergencycontact'] = $v['emergencycontact'];
                 $data['contactmobile'] = $v['contactmobile'];
                 $data['contactmobile'] = $v['contactmobile'];
-                $data['vipprice'] = $info['price']; //会员价
+                $data['vipprice'] = $v['price']; //会员价
             }
             }
 
 
             $data['active_id'] = $id;
             $data['active_id'] = $id;
@@ -750,7 +760,7 @@ class Index extends Api
         $order_data['user_id'] = $this->auth->id;
         $order_data['user_id'] = $this->auth->id;
         $order_data['paytype'] = $paytype;
         $order_data['paytype'] = $paytype;
         $order_data['price'] = $total_amount;
         $order_data['price'] = $total_amount;
-        $order_data['number'] = count($active_people);
+        $order_data['number'] = count($active_people_arr);
         $order_data['status'] = $paytype == 1 ? 0 : 1;
         $order_data['status'] = $paytype == 1 ? 0 : 1;
         $order_data['createtime'] = time();
         $order_data['createtime'] = time();
 
 
@@ -777,6 +787,15 @@ class Index extends Api
                 $this->error('网络延迟,请稍后再试');
                 $this->error('网络延迟,请稍后再试');
             }
             }
         }
         }
+        //扣除免费次数
+        if ($info['is_free'] == 1 && $active_people_arr[0]['is_self'] == 1 && $active_people_arr[0]['is_free'] == 1) {
+            $freenumber = $this->auth->freenumber - 1;
+            $user_rs = Db::name('user')->where(['id' => $this->auth->id, 'freenumber' => $this->auth->freenumber])->setField('freenumber', $freenumber);
+            if (!$user_rs) {
+                Db::rollback();
+                $this->error('网络延迟,请稍后再试');
+            }
+        }
         //扣款 支付方式:0=余额,1=微信
         //扣款 支付方式:0=余额,1=微信
         if ($paytype == 0) {
         if ($paytype == 0) {
             $res = create_log(-$total_amount, '支付活动订单', $this->auth->id, 2);
             $res = create_log(-$total_amount, '支付活动订单', $this->auth->id, 2);
@@ -1049,6 +1068,9 @@ class Index extends Api
         if ($info['status'] != 1) {
         if ($info['status'] != 1) {
             $this->error('体验会员已下架');
             $this->error('体验会员已下架');
         }
         }
+        if ($info['price'] <= 0) {
+            $this->error('会员价格异常');
+        }
         //体验会员等级必须大于成长值会员
         //体验会员等级必须大于成长值会员
         if ($id <= $this->auth->maxlevel) {
         if ($id <= $this->auth->maxlevel) {
             $this->error('请开通更高等级体验会员');
             $this->error('请开通更高等级体验会员');
@@ -1074,22 +1096,39 @@ class Index extends Api
         //开启事务
         //开启事务
         Db::startTrans();
         Db::startTrans();
 
 
-        //添加领取记录
-        $rs = Db::name('user_coupon')->insertGetId($data);
+        //添加开通记录
+        $rs = Db::name('vip_log')->insertGetId($data);
         if (!$rs) {
         if (!$rs) {
             Db::rollback();
             Db::rollback();
-            $this->error('领取失败');
+            $this->error('开通失败');
         }
         }
-
-        $rt = Db::name('user_coupon')->where(['user_id' => $this->auth->id, 'coupon_id' => $id])->count('id');
-        if ($rt != 1) {
+        //扣除余额
+        $result = create_log(-$info['price'], '开通会员', $this->auth->id, 4);
+        if ($result != 1) {
             Db::rollback();
             Db::rollback();
-            $this->error('领取失败');
+            $this->error('资金异常,请联系管理员');
+        }
+        //成长值会员信息
+        $growth_vip_info = Db::name('vip')->find($this->auth->growthlevel);
+        //修改用户表信息
+        $user_data['experiencelevel'] = $id;
+        $user_data['experiencetime'] = $data['endtime'];
+        $user_data['maxlevel'] = $id;
+        $freenumber = $this->auth->freenumber + $info['free'] - $growth_vip_info['free'];
+        $user_data['freenumber'] = $freenumber > 0 ? $freenumber : 0;
+
+        $rt = Db::name('user')->where([
+                'user_id' => $this->auth->id,
+                'experiencelevel' => $this->auth->experiencelevel,
+                'maxlevel' => $this->auth->maxlevel,
+                'freenumber' => $this->auth->freenumber])->setField($user_data);
+        if (!$rt) {
+            Db::rollback();
+            $this->error('开通失败');
         }
         }
 
 
         Db::commit();
         Db::commit();
-        $this->success('领取成功');
-
+        $this->success('开通成功');
     }
     }
 
 
 }
 }