Browse Source

完善注册

15954078560 2 years ago
parent
commit
5cf1c6989f
2 changed files with 158 additions and 9 deletions
  1. 156 7
      application/api/controller/Index.php
  2. 2 2
      application/api/controller/User.php

+ 156 - 7
application/api/controller/Index.php

@@ -435,16 +435,16 @@ class Index extends Api
         }
         //检查自己信息是否完善
         if (!$this->auth->realname) {
-            $this->error('请在个人资料中完善真实姓名', '', 5);
+            $this->success('请在个人资料中完善真实姓名', ['code' => 3]);
         }
         if (!$this->auth->idcard) {
-            $this->error('请在个人资料中完善身份证号', '', 5);
+            $this->success('请在个人资料中完善身份证号', ['code' => 3]);
         }
         if (!$this->auth->emergencycontact) {
-            $this->error('请在个人资料中完善紧急联系人', '', 5);
+            $this->success('请在个人资料中完善紧急联系人', ['code' => 3]);
         }
         if (!$this->auth->contactmobile) {
-            $this->error('请在个人资料中完善紧急联系方式', '', 5);
+            $this->success('请在个人资料中完善紧急联系方式', ['code' => 3]);
         }
 
         $this->success('检查通过');
@@ -454,7 +454,7 @@ class Index extends Api
     public function signupactive() {
         //检查自己信息是否完善
         if (!$this->auth->realname || !$this->auth->idcard || !$this->auth->emergencycontact || !$this->auth->contactmobile) {
-            $this->error('请在个人资料中完善资料', '', 5);
+            $this->success('请在个人资料中完善资料', ['code' => 3]);
         }
 
         $id = input('id', 0, 'intval'); //活动id
@@ -740,7 +740,7 @@ class Index extends Api
         }
         if ($paytype == 0) { //余额支付
             if ($this->auth->money < $total_amount) {
-                $this->error('余额不足,请先去充值');
+                $this->success('您的余额不足,请先去充值', ['code' => 2]);
             }
         }
 
@@ -935,12 +935,161 @@ class Index extends Api
             $this->error('留言最多500字');
         }
 
+        $data['user_id'] = $this->auth->id;
+        $data['type'] = $type;
+        $data['number'] = $number;
+        $data['traveltime'] = $traveltime;
+        $data['traveday'] = $traveday;
+        $data['activetype'] = $activetype;
+        $data['car'] = $car;
+        $data['leader'] = $leader;
+        $data['travedirection'] = $travedirection;
+        $data['freerange'] = $freerange;
+        $data['remark'] = $remark;
+        $data['createtime'] = time();
 
+        $rs = Db::name('personal_order')->insertGetId($data);
+        if (!$rs) {
+            $this->error('提交失败');
+        }
 
-        
+        $this->success('提交成功');
     }
 
+    //查询轮播图优惠券列表
+    public function bannercoupon() {
+        $list = Db::name('coupon')->field('id, title, desc, type, money')
+            ->where(['purpose' => 4, 'status' => 1])->page($this->page, $this->pagenum)->order('weigh desc, id desc')->select();
 
+        $user_coupon = Db::name('user_coupon');
+        foreach ($list as &$v) {
+            $v['is_receive'] = $user_coupon->where(['user_id' => $this->auth->id, 'coupon_id' => $v['id']])->count('id');
+        }
+
+        $this->success('查询轮播图优惠券列表', $list);
+    }
 
+    //领取轮播图优惠券
+    public function receivebannercoupon() {
+        $id = input('id', 0, 'intval'); //优惠券id
+
+        if (!$id) {
+            $this->error('参数缺失');
+        }
+
+        $info = Db::name('coupon')->where(['id' => $id, 'purpose' => 4])->find();
+        if (!$info) {
+            $this->error('优惠券不存在');
+        }
+        if ($info['status'] != 1) {
+            $this->error('优惠券已下架');
+        }
+
+        //查询是否已领取
+        $count = Db::name('user_coupon')->where(['user_id' => $this->auth->id, 'coupon_id' => $id])->count('id');
+        if ($count) {
+            $this->error('您已经领取过了');
+        }
+
+        $data['user_id'] = $this->auth->id;
+        $data['coupon_id'] = $id;
+        $data['title'] = $info['title'];
+        $data['desc'] = $info['desc'];
+        $data['type'] = $info['type'];
+        $data['money'] = $info['money'];
+        $data['minmoney'] = $info['minmoney'];
+        $data['purpose'] = $info['purpose'];
+        $data['starttime'] = time();
+        $data['endtime'] = time() + $info['effectiveday'] * 86400;
+        $data['createtime'] = time();
+
+        //开启事务
+        Db::startTrans();
+
+        //添加领取记录
+        $rs = Db::name('user_coupon')->insertGetId($data);
+        if (!$rs) {
+            Db::rollback();
+            $this->error('领取失败');
+        }
+
+        $rt = Db::name('user_coupon')->where(['user_id' => $this->auth->id, 'coupon_id' => $id])->count('id');
+        if ($rt != 1) {
+            Db::rollback();
+            $this->error('领取失败');
+        }
+
+        Db::commit();
+        $this->success('领取成功');
+    }
+    
+    //体验会员列表
+    public function experiencevip() {
+        $list = Db::name('vip')->where(['id' => ['gt', $this->auth->maxlevel], 'status' => 1])->select();
+
+        $this->success('体验会员列表', $list);
+    }
+
+    //购买体验会员
+    public function buyexperiencevip() {
+        //检查是否已经开通体验会员
+        if ($this->auth->experiencetime >= time()) {
+            $this->error('您已开通体验会员,不能重复开通');
+        }
+
+        $id = input('id', 0, 'intval');
+        if (!$id) {
+            $this->error('参数缺失');
+        }
+
+        $info = Db::name('vip')->where(['id' => $id])->find();
+        if (!$info) {
+            $this->error('会员不存在');
+        }
+        if ($info['status'] != 1) {
+            $this->error('体验会员已下架');
+        }
+        //体验会员等级必须大于成长值会员
+        if ($id <= $this->auth->maxlevel) {
+            $this->error('请开通更高等级体验会员');
+        }
+        //判断余额
+        if ($this->auth->money < $info['price']) {
+            $this->success('您的余额不足,请先去充值', ['code' => 2]);
+        }
+
+        $data['user_id'] = $this->auth->id;
+        $data['vip_id'] = $id;
+        $data['title'] = $info['title'];
+        $data['level'] = $info['level'];
+        $data['growthvalue'] = $info['growthvalue'];
+        $data['free'] = $info['free'];
+        $data['price'] = $info['price'];
+        $data['endtime'] = time() + $info['day'] * 86400;
+        $data['vipdiscount'] = $info['vipdiscount'];
+        $data['birthdiscount'] = $info['birthdiscount'];
+        $data['manypeople'] = $info['manypeople'];
+        $data['createtime'] = time();
+
+        //开启事务
+        Db::startTrans();
+
+        //添加领取记录
+        $rs = Db::name('user_coupon')->insertGetId($data);
+        if (!$rs) {
+            Db::rollback();
+            $this->error('领取失败');
+        }
+
+        $rt = Db::name('user_coupon')->where(['user_id' => $this->auth->id, 'coupon_id' => $id])->count('id');
+        if ($rt != 1) {
+            Db::rollback();
+            $this->error('领取失败');
+        }
+
+        Db::commit();
+        $this->success('领取成功');
+
+    }
 
 }

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

@@ -1147,7 +1147,7 @@ class User extends Api
 
         $user = \app\common\model\User::getByOpenid($openid);
         if (!$user) {
-            $this->error('用户尚未注册', [], 5);
+            $this->success('用户尚未注册', ['code' => 5]);
         }
         if ($user['status'] != 1) {
             $this->error(__('Account is locked'));
@@ -1228,7 +1228,7 @@ class User extends Api
             'birthday' => $birthday,
             'openid' => $openid,
             'invite_no' => $this->myinvite(),
-            'pre_user_id' => $invite_info['id'],
+            'pre_user_id' => $invite_info ? $invite_info['id'] : 0,
             'invite_time' => $time,
         ];