Browse Source

邀请功能,邀请接口,邀请码,邀请奖励,聊天赠送礼物

lizhen_gitee 3 years ago
parent
commit
e13ed671ce

+ 11 - 0
application/admin/controller/Useridconfirm.php

@@ -89,6 +89,7 @@ class Useridconfirm extends Backend
                 'updatetime' => time(),
             ];
             Db::startTrans();
+            $userinfo = Db::name('user')->where('id',$info['user_id'])->lock(true)->find();
             $rs = Db::name('user_idconfirm')->where('id',$id)->update($data);
 
             //修改用户表
@@ -111,6 +112,16 @@ class Useridconfirm extends Backend
                     Db::rollback();
                     $this->error('完成任务赠送奖励失败');
                 }
+
+                //邀请人拿奖励,男性3元
+                $intro_money = $userinfo['gender'] == 1 ? config('site.intro_man_money') : config('site.intro_woman_money');
+                if($userinfo['real_status'] == 1 && !empty($userinfo['intro_uid']) && $intro_money > 0){
+                    $task_rs = model('wallet')->lockChangeAccountRemain($userinfo['intro_uid'],'money',$intro_money,63,$remark='');
+                    if($task_rs['status'] === false){
+                        Db::rollback();
+                        $this->error($task_rs['msg']);
+                    }
+                }
             }
             Db::commit();
 

+ 99 - 0
application/api/controller/Gift.php

@@ -84,4 +84,103 @@ class Gift extends Api
             ->select();
         $this->success("获取成功!", $list);
     }
+
+    public function giveGiftToYou() {
+        // 接口防并发
+        /*if (!$this->apiLimit(1, 1000)) {
+            $this->error(__('Operation frequently'));
+        }*/
+
+        $user_id = input('user_id');// 赠送对象
+        $gift_id = input('gift_id');// 礼物ID
+
+        if (!$user_id || !$gift_id )
+        {
+            $this->error();
+        }
+
+        // 不可以赠送给自己
+        if($this->auth->id == $user_id)
+        {
+            $this->error("不可以赠送给自己");
+        }
+
+        // 获取礼物信息
+        $giftinfo = Db::name('gift')->where('id',$gift_id)->find();
+        if (!$giftinfo)
+        {
+            $this->error("请选择礼物");
+        }
+
+        //被赠送人信息
+        $touserinfo = Db::name('user')->where('id',$user_id)->find();
+        if (!$touserinfo)
+        {
+            $this->error("不存在的用户");
+        }
+
+        // 判断当前用户余额
+        $user_gold = model('wallet')->getWallet($this->auth->id,'gold');
+        if($user_gold < $giftinfo['value'])
+        {
+            $this->error("您的金币余额不足");
+        }
+
+
+        Db::startTrans();
+
+
+        // 添加礼物赠送记录表
+        $data = [
+            'user_id' => $this->auth->id,
+            'user_to_id' => $user_id,
+            'gift_id' => $giftinfo['id'],
+            'gift_name' => $giftinfo['name'],
+            'number' => 1,
+            'price' => $giftinfo['value'],
+            'createtime' => time(),
+        ];
+        $log_id = Db::name('gift_user_typing')->insertGetId($data);
+        if(!$log_id){
+            Db::rollback();
+            $this->error('赠送失败');
+        }
+
+
+        if($giftinfo['value'] > 0){
+
+            // 扣除当前用户余额
+            $wallet_rs = model('wallet')->lockChangeAccountRemain($this->auth->id,'gold',-$giftinfo['value'],53,'赠送礼物:'.$giftinfo["name"],'gift_user_typing',$log_id);
+            if($wallet_rs['status'] === false){
+                Db::rollback();
+                $this->error($wallet_rs['msg']);
+            }
+
+            // 添加赠送用户声币余额
+            $money_to_gold = config('site.money_to_gold');
+            $gift_plat_scale = config('site.gift_plat_scale');
+
+            $giftmoney = bcdiv($giftinfo['value'],$money_to_gold,2);
+
+            $money = bcdiv(bcmul($giftmoney,100 - $gift_plat_scale,2),100,2);
+            $wallet_rs = model('wallet')->lockChangeAccountRemain($user_id,'money',$money,54,'他人赠送礼物:'.$giftinfo["name"],'gift_user_typing',$log_id);
+            if($wallet_rs['status'] === false){
+                Db::rollback();
+                $this->error($wallet_rs['msg']);
+            }
+        }
+
+        Db::commit();
+        $this->success('赠送成功');
+
+    }
+
+
+
+
+
+
+
+
+
 }

+ 34 - 1
application/api/controller/User.php

@@ -153,6 +153,22 @@ class User extends Api
         $this->success(__('success'),$info);
     }
 
+    //用户邀请信息
+    public function userintroinfo(){
+        $intro_num = Db::name('user')->where('intro_uid',$this->auth->id)->count();
+        $money_sum = Db::name('user_money_log')->where(['user_id'=>$this->auth->id,'log_type'=>63])->sum('change_value');
+
+        $user_list = Db::name('user')->field('id,avatar,nickname,createtime')->where('intro_uid',$this->auth->id)->autopage()->select();
+
+        $rs = [
+            'intro_num' => $intro_num,
+            'money_sum' => $money_sum,
+            'user_list' => $user_list,
+        ];
+
+        $this->success('success',$rs);
+    }
+
     //申请真人认证
     public function apply_real_confirm(){
         $avatar = input('avatar', '', 'trim,strip_tags,htmlspecialchars');
@@ -182,6 +198,16 @@ class User extends Api
                 Db::rollback();
                 $this->error('完成任务赠送奖励失败');
             }
+            //邀请人拿奖励,男性3元
+            $intro_money = $this->auth->gender == 1 ? config('site.intro_man_money') : config('site.intro_woman_money');
+            if($this->auth->idcard_status == 1 && !empty($this->auth->intro_uid) && $intro_money > 0){
+                $task_rs = model('wallet')->lockChangeAccountRemain($this->auth->intro_uid,'money',$intro_money,63,$remark='');
+                if($task_rs['status'] === false){
+                    Db::rollback();
+                    $this->error($task_rs['msg']);
+                }
+            }
+
         }
         Db::commit();
         $this->success();
@@ -282,7 +308,7 @@ class User extends Api
      */
     public function profile()
     {
-        $field_array = ['nickname','gender','birthday','height','weight','bio','audio_bio','avatar','photo_images','education_id','hobby_ids','job_id','marital_id','tag_ids','wages_id','hometown_cityid','hide_is_finishinfo'];
+        $field_array = ['nickname','introcode','gender','birthday','height','weight','bio','audio_bio','avatar','photo_images','education_id','hobby_ids','job_id','marital_id','tag_ids','wages_id','hometown_cityid','hide_is_finishinfo'];
 
         $data = [];
         foreach($field_array as $key => $field){
@@ -315,6 +341,13 @@ class User extends Api
         if(isset($data['tag_ids'])){
             $data['tag_ids'] = implode(',',explode(',',$data['tag_ids']));
         }
+        if(isset($data['introcode'])){
+            $intro_user = Db::name('user')->where('introcode',$data['introcode'])->value('id');
+            if(!$intro_user){
+                $this->error('不存在的邀请人');
+            }
+            $data['intro_uid'] = $intro_user;
+        }
         //dump($data);
         if(empty($data)){
             $this->error('没有任何改变');

+ 5 - 0
application/common/library/Auth.php

@@ -31,6 +31,8 @@ class Auth
         'username',
         'nickname',
         'truename',//
+        'introcode',
+        'intro_uid',
 
         'email',
         'mobile',
@@ -213,6 +215,8 @@ class Auth
         $ip = request()->ip();
         $time = time();
 
+        $introcode = User::column("introcode");
+
         $data = [
             //'username' => $username,
             'password' => $password,
@@ -221,6 +225,7 @@ class Auth
             /*'level'    => 1,
             'score'    => 0,
             'avatar'   => '',*/
+            'introcode' => $this->getUinqueNo(8, $introcode),
         ];
         $params = array_merge($data, [
             //'nickname'  => preg_match("/^1[3-9]{1}\d{9}$/",$username) ? substr_replace($username,'****',3,4) : $username,

+ 2 - 3
application/extra/site.php

@@ -29,7 +29,6 @@ return array (
     'example' => '示例分组',
     'website' => '金钱变量',
     'party' => '语聊变量',
-    'usertask' => '用户任务',
   ),
   'mail_type' => '1',
   'mail_smtp_host' => 'smtp.qq.com',
@@ -57,7 +56,7 @@ return array (
   'user_sign_gift_vipdays' => '4',
   'roomLimit' => '100',
   'gift_plat_scale' => '30',
-  'usetask_avatar_gold' => '5',
-  'usetask_follow_3user' => '3',
   'unlock_like_me' => '38',
+  'intro_man_money' => '3',
+  'intro_woman_money' => '4',
 );

+ 6 - 2
application/extra/wallet.php

@@ -20,11 +20,15 @@ return [
         31 => '购买装扮消费',
         41 => '签到赠送金币',
 
-        51 => '赠送礼物',
-        52 => '他人赠送礼物',
+        51 => '语聊间赠送礼物',
+        52 => '语聊间他人赠送礼物',
+
+        53 => '聊天赠送礼物',
+        54 => '聊天他人赠送礼物',
 
         61 => '完成个人任务',
         62 => '解锁喜欢我的人',
+        63 => '邀请注册奖励',
     ],
     'moneyname' => [
         'money'    => '余额',