Browse Source

邀请和签到调整

zhangxiaobin 1 year ago
parent
commit
6250865934

+ 2 - 0
application/api/controller/Usercenter.php

@@ -1141,6 +1141,7 @@ class UserCenter extends Common
             //全部
             $totalNum = $userInviteModel->where($userInviteWhere)->count();
             $inviteMoney = config('site.invite_money');
+            $inviteRule = config('site.invite_rule');
             $result = [
                 'invite_money' => (int)$inviteMoney,
                 'invite_no' => $inviteNo,//邀请码
@@ -1149,6 +1150,7 @@ class UserCenter extends Common
                 'week_now_num' => $weekNowNum,//本周邀请数
                 'last_week_num' => $lastWeekNum,//上周邀请数
                 'total_num' => $totalNum,//总邀请数
+                'invite_rule' => $inviteRule,//规则说明
             ];
             $this->success('获取成功',$result);
         } catch (Exception $e) {

+ 101 - 73
application/api/controller/Usersign.php

@@ -4,6 +4,7 @@ namespace app\api\controller;
 
 use app\common\controller\Api;
 use think\Db;
+use think\Exception;
 
 /**
  * 签到
@@ -49,72 +50,73 @@ class Usersign extends Api
 
     //签到
     public function signin(){
-        $uid = $this->auth->id;
-
-        //记录日志
-        $data = [
-            'uid' => $uid,
-            'times' => 1,
-            'goldnum' => 0,
-            'createtime' => time(),
-        ];
-
-        $yesterday_time = strtotime('yesterday'); //昨天0点时间戳
-        $today_time = $yesterday_time + 86400; //今日0点时间戳
-        //修正当前次数
-        $check = Db::name('user_sign')->where('uid',$uid)->order('id desc')->find();
-        if($check){
-            //今天只能签一次
-            if($check['createtime'] >= $today_time){
-                $this->error('今天已经签过了');
-            }
-            if ($check['createtime'] >= $yesterday_time) {
-                $data['times'] = $check['times'] + 1; //连续签到次数
+        Db::startTrans();
+        try {
+            $uid = $this->auth->id;
+            //记录日志
+            $data = [
+                'uid' => $uid,
+                'type' => 1,
+                'times' => 1,
+                'goldnum' => 0,
+                'createtime' => time(),
+            ];
+
+            $yesterday_time = strtotime('yesterday'); //昨天0点时间戳
+            $today_time = $yesterday_time + 86400; //今日0点时间戳
+            //修正当前次数
+            $check = Db::name('user_sign')->where('uid',$uid)->order('id desc')->find();
+            if($check){
+                //今天只能签一次
+                if($check['createtime'] >= $today_time){
+                    throw new Exception('今天已经签过了');
+                }
+                if ($check['createtime'] >= $yesterday_time) {
+                    $data['times'] = $check['times'] + 1; //连续签到次数
+                }
             }
-        }
-
-        $signin_id = $data['times'] % 7;
-        if ($signin_id == 0) {
-            $signin_id = 7;
-        }
 
-        //匹配对应金币数
-        $list = Db::name('signin')->order('id asc')->column('id,goldnum');
-        $data['goldnum'] = isset($list[$signin_id]) ? $list[$signin_id] : 0 ;
-        Db::startTrans();
-        //记录日志
-        $log_id = Db::name('user_sign')->insertGetId($data);
-        if(!$log_id){
-            Db::rollback();
-            $this->error('签到失败');
-        }
+            /*$signin_id = $data['times'] % 7;
+            if ($signin_id == 0) {
+                $signin_id = 7;
+            }
 
-        //加经验
-        $userWhere['id'] = $uid;
-        $user = model('User')->where($userWhere)->lock(true)->find();
-        $userNewEmpirical = $user['empirical'] + $data['goldnum'];
-        $userUpdate['empirical'] = $userNewEmpirical;
-        // 获取用户当前经验值对应等级
-        $userconfigModel = new \app\common\model\UserLevelConfig();
-        $where = [];
-        $where["empirical"] = ["elt",$userNewEmpirical];
-        $userexplainstart = $userconfigModel->where($where)->order("empirical","desc")->find();
-        if (!empty($userexplainstart)) {
-            if ($userexplainstart['level'] != $user['level']) {
-                $userUpdate['level'] = $userexplainstart['level'];
+            //匹配对应金币数
+            $list = Db::name('signin')->order('id asc')->column('id,goldnum');
+            $data['goldnum'] = isset($list[$signin_id]) ? $list[$signin_id] : 0 ;
+            Db::startTrans();
+            //记录日志
+            $log_id = Db::name('user_sign')->insertGetId($data);
+            if(!$log_id){
+                Db::rollback();
+                $this->error('签到失败');
+            }*/
+
+            //加经验
+            /*$userWhere['id'] = $uid;
+            $user = model('User')->where($userWhere)->lock(true)->find();
+            $userNewEmpirical = $user['empirical'] + $data['goldnum'];
+            $userUpdate['empirical'] = $userNewEmpirical;
+            // 获取用户当前经验值对应等级
+            $userconfigModel = new \app\common\model\UserLevelConfig();
+            $where = [];
+            $where["empirical"] = ["elt",$userNewEmpirical];
+            $userexplainstart = $userconfigModel->where($where)->order("empirical","desc")->find();
+            if (!empty($userexplainstart)) {
+                if ($userexplainstart['level'] != $user['level']) {
+                    $userUpdate['level'] = $userexplainstart['level'];
+                }
             }
-        }
-        $res = $user->update($userUpdate,$userWhere);
-        if($res === false){
-            Db::rollback();
-            $this->error('经验更新失败');
-        }
-        //第七天赠送礼物
-        $gift = [];
-        $sendGift = config('site.sign_gift');
-        if ($data['times'] == 7 && $sendGift == '1') {
+            $res = $user->update($userUpdate,$userWhere);
+            if($res === false){
+                Db::rollback();
+                $this->error('经验更新失败');
+            }*/
+            //第七天赠送礼物
+            $gift = [];
+            $sendGift = config('site.sign_gift');
             $userSignGift = model('UserSignGift')->with(['gift'])->find();
-            if (!empty($userSignGift)) {
+            if ($data['times'] == 7 && $sendGift == '1' && !empty($userSignGift)) {
                 $giftData = isset($userSignGift['gift']) ? $userSignGift['gift'] : [];
                 if (!empty($giftData)) {
                     $gift = [
@@ -122,20 +124,46 @@ class Usersign extends Api
                         'num' => $userSignGift['num'],
                     ];
                 }
+                $giftName = isset($giftData['name']) ? $giftData['name'] : '';
+                $data['goldnum'] = $gift['num'];
+                $data['type'] = 2;
+                $data['remark'] = '签到奖励'.$giftName.$gift['num'];
+            } else {//随机获取钻石
+                $signJewel = config('site.sign_jewel');
+                $signJewelArr = [];
+                if (!empty($signJewel)) {
+                    $signJewelArr = explode('-', $signJewel);
+                }
+                $min = isset($signJewelArr[0]) ? $signJewelArr[0] : 1;
+                $max = isset($signJewelArr[1]) ? $signJewelArr[1] : 1;
+                $gift['num'] = rand($min,$max);
+                $data['goldnum'] = $gift['num'];
+                $data['remark'] = '签到钻石'.$gift['num'];
+                $user = model('User')->find($uid);
+                $userJewel = isset($user['jewel']) ? $user['jewel'] : 0;
+                $rs_wallet = model('wallet')->lockChangeAccountRemain($uid,$gift['num'],'+',$userJewel,$data['remark'],16,'jewel');
+                if (!$rs_wallet['status']) {
+                    throw new Exception($rs_wallet['msg']);
+                }
             }
+            //记录日志
+            $log_id = Db::name('user_sign')->insertGetId($data);
+            if(!$log_id){
+                throw new Exception('签到失败');
+            }
+            //系统消息
+            $msg_id = \app\common\model\Message::addMessage($this->auth->id,'签到奖励','签到成功,获得奖励');
+            $signImg = config('site.sign_img');
+            $result = [
+                'image' => isset($gift['image']) ? $gift['image'] : cdnurl($signImg),
+                'goldnum' => isset($gift['num']) ? $gift['num'] : $data['goldnum'],
+            ];
+            Db::commit();
+            $this->success('签到成功', $result);
+        } catch (Exception $e) {
+            Db::rollback();
+            $this->error($e->getMessage());
         }
-
-        //系统消息
-        $msg_id = \app\common\model\Message::addMessage($this->auth->id,'签到奖励','签到成功,获得奖励');
-
-        Db::commit();
-        $signImg = config('site.sign_img');
-        $signImg = cdnurl($signImg);
-        $result = [
-            'image' => isset($gift['image']) ? $gift['image'] : $signImg,
-            'goldnum' => isset($gift['num']) ? $gift['num'] : $data['goldnum'],
-        ];
-        $this->success('签到成功', $result);
     }
 
     //第七天赠送vip

+ 7 - 1
application/extra/site.php

@@ -26,6 +26,8 @@ return [
         'currency' => '货币比例配置',
         'other' => '其他配置',
         'egg' => '开箱子和大转盘',
+        'sign' => '签到配置',
+        'invite' => '邀请配置',
     ],
     'mail_type' => '1',
     'mail_smtp_host' => 'smtp.qq.com',
@@ -113,5 +115,9 @@ return [
     'exchange_define' => '1',
     'withdraw_define' => '1',
     'sign_img' => '/uploads/20230714/f02676a5491e5a88141ce9a9a8c20a77.png',
-    'un_authentication_max' => '100',
+    'sign_jewel' => '1-10',
+    'invite_rule' => '邀请规则:'."\r\n"
+        .'1、所有用户都可以参加邀请好友活动'."\r\n"
+        .'2、通过自己分享的活动页面地址下载注册成功,'."\r\n"
+        .'即发放注册奖励,若好友充值即奖励1元。',
 ];

+ 1 - 0
application/extra/wallet.php

@@ -21,6 +21,7 @@ return [
         13 => '抽奖箱子和转盘', //减少
         14 => '余额兑换钻石', //增加
         //15已被占用
+        16 => '签到得钻石',//增加
 
         //money
         101 => '获赠礼物', //增加