Browse Source

完成个人任务,上传头像,关注三个人

lizhen_gitee 3 years ago
parent
commit
4fd977e4c2

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

@@ -291,7 +291,24 @@ class User extends Api
         if(empty($data)){
             $this->error('没有任何改变');
         }
-        Db::name('user')->where('id',$this->auth->id)->update($data);
+        Db::startTrans();
+        $update_rs = Db::name('user')->where('id',$this->auth->id)->update($data);
+        if($update_rs === false){
+            Db::rollback();
+            $this->error('修改资料失败');
+        }
+
+        //tag任务赠送金币
+        //上传头像加5金币
+        if(isset($data['avatar'])){
+            $task_rs = model('usertask')->oncetask($this->auth->id,'usetask_avatar_gold');
+            if($task_rs['status'] === false){
+                Db::rollback();
+                $this->error($task_rs['msg']);
+            }
+        }
+
+        Db::commit();
         $this->success();
     }
 

+ 18 - 1
application/api/controller/Userfollow.php

@@ -63,11 +63,28 @@ class Userfollow extends Api
 
         $check = Db::name('user_follow')->where($map)->find();
         if($check){
-            $this->success('success');
+            $this->error('已经关注此人');
         }
 
+        Db::startTrans();
         $id = Db::name('user_follow')->insertGetId($map);
+        if(!$id){
+            Db::rollback();
+            $this->error('关注失败');
+        }
+
+        //tag任务赠送金币
+        //关注3人加3金币
+        $follow_count = Db::name('user_follow')->where('uid',$this->auth->id)->count();
+        if($follow_count >= 3){
+            $task_rs = model('usertask')->oncetask($this->auth->id,'usetask_follow_3user');
+            if($task_rs['status'] === false){
+                Db::rollback();
+                $this->error($task_rs['msg']);
+            }
+        }
 
+        Db::commit();
         $this->success('success',$id);
     }
 

+ 60 - 0
application/common/model/Usertask.php

@@ -0,0 +1,60 @@
+<?php
+namespace app\common\model;
+use think\Db;
+/**
+ * 用户任务
+ */
+class Usertask
+{
+    /**
+     * 一次性任务
+     * @return boolen
+     */
+    public function oncetask($uid,$taskkey)
+    {
+        //初始化
+        $return_rs = array(
+            'status'=>false,
+            'msg'=>'',
+            'log_table' => '',
+            'log_id' => '',
+        );
+
+        //检查
+        $map = [
+            'user_id' => $uid,
+            'taskkey' => $taskkey,
+        ];
+        $check = Db::name('user_task_once_log')->where($map)->find();
+
+        //只能执行一次
+        if($check){
+            $return_rs['status'] = true;
+            return $return_rs;
+        }
+
+        //发放
+        $gift_gold = config('site.'.$taskkey.'');
+        if($gift_gold > 0){
+
+            $map['createtime'] = time();
+            $map['remark']     = Db::name('config')->where('name',$taskkey)->value('title');
+
+            $log_id = Db::name('user_task_once_log')->insertGetId($map);
+            if(!$log_id){
+                $return_rs['msg'] = '赠送金币失败';
+                return $return_rs;
+            }
+
+            $gift_rs = model('wallet')->lockChangeAccountRemain($uid,'gold',$gift_gold,61,$map['remark'],'user_task_once_log',$log_id);
+            //返回结构和wallet一样,直接返回
+            return $gift_rs;
+        }else{
+            $return_rs['status'] = true;
+            return $return_rs;
+        }
+
+    }
+
+
+}

+ 6 - 3
application/extra/site.php

@@ -1,9 +1,9 @@
 <?php
 
 return array (
-  'name' => '觅',
+  'name' => '觅TA',
   'beian' => '',
-  'cdnurl' => '',
+  'cdnurl' => 'http://mita.lanmaonet.com',
   'version' => '1.0.1',
   'timezone' => 'Asia/Shanghai',
   'forbiddenip' => '',
@@ -29,6 +29,7 @@ return array (
     'example' => '示例分组',
     'website' => '金钱变量',
     'party' => '语聊变量',
+    'usertask' => '用户任务',
   ),
   'mail_type' => '1',
   'mail_smtp_host' => 'smtp.qq.com',
@@ -43,7 +44,7 @@ return array (
     'category2' => '分类二',
     'custom' => '自定义',
   ),
-  'domain_name' => 'http://mita.com',
+  'domain_name' => 'http://mita.lanmaonet.com',
   'android_update_num' => '1',
   'android_update_version' => '1.0',
   'ios_update_num' => '1',
@@ -56,4 +57,6 @@ return array (
   'user_sign_gift_vipdays' => '4',
   'roomLimit' => '100',
   'gift_plat_scale' => '30',
+  'usetask_avatar_gold' => '5',
+  'usetask_follow_3user' => '3',
 );

+ 2 - 0
application/extra/wallet.php

@@ -22,6 +22,8 @@ return [
 
         51 => '赠送礼物',
         52 => '他人赠送礼物',
+
+        61 => '完成个人任务',
     ],
     'moneyname' => [
         'money'    => '余额',