lizhen_gitee 3 years ago
parent
commit
ebe4b07d15

+ 118 - 0
application/api/controller/Usersign.php

@@ -0,0 +1,118 @@
+<?php
+
+namespace app\api\controller;
+
+use app\common\controller\Api;
+use think\Db;
+
+/**
+ * 签到
+ */
+class Usersign extends Api
+{
+    protected $noNeedLogin = ['config'];
+    protected $noNeedRight = ['*'];
+
+    /**
+     * 配置
+     */
+    public function config()
+    {
+        $list = Db::name('signin')->order('id asc')->select();
+        $this->success('success',$list);
+    }
+
+    //签到
+    public function signin(){
+        $uid = $this->auth->id;
+
+        //记录日志
+        $data = [
+            'uid' => $uid,
+            'times' => 1,
+            'goldnum' => 0,
+            'createtime' => time(),
+        ];
+
+        //修正当前次数
+        $check = Db::name('user_sign')->where('uid',$uid)->order('id desc')->find();
+        if($check){
+            $data['times'] = $check['times'] + 1;
+
+            //今天只能签一次
+            if($check['createtime'] > strtotime(date('Y-m-d'))){
+                //$this->error('今天已经签过了');
+            }
+        }
+
+        if($data['times'] > 7){
+            $data['times'] = 1;
+        }
+
+        //匹配对应金币数
+        $list = Db::name('signin')->order('id asc')->column('id,goldnum');
+        $data['goldnum'] = isset($list[$data['times']]) ? $list[$data['times']] : 0 ;
+
+        Db::startTrans();
+        //记录日志
+        $log_id = Db::name('user_sign')->insertGetId($data);
+        if(!$log_id){
+            Db::rollback();
+            $this->error('签到失败');
+        }
+
+        //加钱
+        $rs = model('wallet')->lockChangeAccountRemain($this->auth->id,'gold',$data['goldnum'],41,'','user_sign',$log_id);
+        if($rs['status'] === false){
+            Db::rollback();
+            $this->error($rs['msg']);
+        }
+
+        //第七天赠送vip
+        $vip_rs = false;
+        $user_sign_gift_vipdays = intval(config('site.user_sign_gift_vipdays'));
+        if($data['times'] == 7 && $user_sign_gift_vipdays > 0){
+
+            $vip_rs = $this->gift_vip($user_sign_gift_vipdays);
+        }
+
+        Db::commit();
+        $remark = '获得金币'.$data['goldnum'];
+        if($vip_rs){
+            $remark .= ',vip'.$user_sign_gift_vipdays.'天';
+        }
+        $this->success('签到成功',$remark);
+    }
+
+    //第七天赠送vip
+    //找出最近七天的次数
+    private function gift_vip($user_sign_gift_vipdays){
+        $start = strtotime(date('Y-m-d')) - 518400;
+        $map = [
+            'uid' => $this->auth->id,
+            'createtime' => ['gt',$start],
+        ];
+        $count = Db::name('user_sign')->where($map)->count();
+
+        if($count >= 7){
+            //赠送vip三天
+            $add_time = 86400 * $user_sign_gift_vipdays;
+
+            //有vip的续费,没有的从现在开始
+            $vip_endtime = model('wallet')->getWallet($this->auth->id,'vip_endtime');
+            if($vip_endtime <= time()){
+                $new_vip_endtime = time() + $add_time;
+            }else{
+                $new_vip_endtime = $vip_endtime + $add_time;
+            }
+            $rs = Db::name('user_wallet')->where('user_id',$this->auth->id)->update(['vip_endtime'=>$new_vip_endtime]);
+
+            if($rs === false){
+                Db::rollback();
+                $this->error('签到失败赠送vip失败');
+            }
+            return true;
+        }
+        return false;
+    }
+}

+ 2 - 2
application/common/model/Recharge.php

@@ -66,7 +66,7 @@ class Recharge
             }
 
             //先充值
-            $user_info = Db::name('wallet')->where('user_id',$args['user_id'])->lock(true)->find();
+            $user_info = Db::name('user_wallet')->where('user_id',$args['user_id'])->lock(true)->find();
             if($user_info['vip_endtime'] < time()){
                 //过期了
                 $vip_endtime = time() + (intval($args['days']) * 86400);
@@ -74,7 +74,7 @@ class Recharge
                 //追加vip
                 $vip_endtime = $user_info['vip_endtime'] + (intval($args['days']) * 86400);
             }
-            $result = Db::name('wallet')->where('user_id',$args['user_id'])->update(['vip_endtime'=>$vip_endtime]);
+            $result = Db::name('user_wallet')->where('user_id',$args['user_id'])->update(['vip_endtime'=>$vip_endtime]);
             if($result === false)
             {
                 Db::rollback();

+ 1 - 0
application/extra/site.php

@@ -52,4 +52,5 @@ return array (
   'audio_min_price' => '13',
   'typing_min_price' => '6',
   'vip_price_discount' => '95',
+  'user_sign_gift_vipdays' => '4',
 );

+ 1 - 0
application/extra/wallet.php

@@ -17,6 +17,7 @@ return [
         23 => '直播收益',
 
         31 => '购买装扮消费',
+        41 => '签到赠送金币',
     ],
     'moneyname' => [
         'money'    => '余额',