瀏覽代碼

从送礼物摘出来的计划任务,用以给用户升级

lizhen_gitee 1 年之前
父節點
當前提交
84bef35948
共有 2 個文件被更改,包括 64 次插入5 次删除
  1. 3 3
      application/api/controller/Party.php
  2. 61 2
      application/index/controller/Plantask.php

+ 3 - 3
application/api/controller/Party.php

@@ -1627,7 +1627,6 @@ class Party extends Common
         $userCount = count($user_id_arr);
         $userauthid = $this->auth->id;
         $money_to_jewel = config('site.money_to_jewel') ?: 10; //余额兑换钻石
-        $userModel = new \app\common\model\User();
 
         // 不可以赠送给自己
         //if(in_array($userauthid,$user_id_arr)) $this->error("不可以赠送给自己!");
@@ -1815,6 +1814,7 @@ class Party extends Common
                 $data['guildervalue'] = bcmul($guilderRate/100     ,$data["value"],2);
                 $data['guildermoney'] = bcdiv($data['guildervalue'],$money_to_jewel,2);
 
+                $data['task_status'] = 0;
                 $data["createtime"] = time();
                 $res5 = Db::name('gift_user_party')->insertGetId($data);
 
@@ -1898,9 +1898,9 @@ class Party extends Common
 
                     // +exp
                     \app\common\model\TaskLog::tofinish($this->auth->id,"OBHqCX4g",$number);
-
+                    */
                     // +message
-                    \app\common\model\Message::addMessage($user_id,"礼物通知","收到 ".$this->auth->nickname." 赠送的".$giftInfo["name"]." x".$number." 价值 ".$giftValue ." 钻石");*/
+                    \app\common\model\Message::addMessage($user_id,"礼物通知","收到 ".$this->auth->nickname." 赠送的".$giftInfo["name"]." x".$number." 价值 ".$giftValue ." 钻石");
 
                     $allVal = $allVal + $hotValue;
 

+ 61 - 2
application/index/controller/Plantask.php

@@ -8,10 +8,10 @@ use app\common\library\Tlssigapiv2;
 use think\Db;
 class Plantask extends Controller
 {
-    //关于计划任务
+    //关于本文件里的计划任务
     //只有 public 方法,auto_开头的才是计划任务,其他private 方法都是工具方法
 
-
+////////////////////////////////////////下面都是计划任务方法///////////////////////////////////////////////////////////////
     //主动拉取im群组内 聊天记录
     public function auto_imgroup(){
         $im_config = config('tencent_im');
@@ -131,7 +131,66 @@ class Plantask extends Controller
         exit;
     }
 
+    //送礼物(api/party/giveGiftToYou)拆分出来的异步用户升级方法,
+    public function auto_user_level_up(){
+        Db::startTrans();
+        $tasklist = Db::name('gift_user_party')->where('task_status',0)->limit(20)->lock(true)->select();
+        if(empty($tasklist)){
+            Db::rollback();
+            echo 'empty';
+            exit;
+        }
+
+        try {
+            $getempirical_conf = config("site.getempirical");
+            foreach($tasklist as $key => $giftuserparty){
+                echo $giftuserparty['id'].'<br>';
+
+                $giftValue = $giftuserparty['value'];
+                $hotValue  = $giftValue;
+                //用户经验升级
+                $getempirical = $getempirical_conf * $hotValue;
+                // 获取用户贵族信息
+                $noble = \app\common\model\User::getUserNoble($giftuserparty['user_id']);
+                if(isset($noble["noble_on"]) && $noble["noble_on"] == 1) {
+                    $getempirical = $getempirical + $getempirical * ($noble["explain"]/100);
+                }
+
+                // 增加用户经验值
+                $res = \app\common\model\User::addEmpirical($giftuserparty['user_id'],$getempirical);
+                /*if ($res){
+                    $this->auth->level = $res->level;
+                }*/
+
+                //增加被送礼物用户的魅力等级
+                $res_charm = \app\common\model\User::add_charm_level($giftuserparty['user_to_id'],$giftValue);
+
+                // +exp
+                \app\common\model\TaskLog::tofinish($giftuserparty['user_id'],"OBHqCX4g",$giftuserparty['number']);
+
+                // +message
+                //\app\common\model\Message::addMessage($user_id,"礼物通知","收到 ".$this->auth->nickname." 赠送的".$giftInfo["name"]." x".$number." 价值 ".$giftValue ." 钻石");
+
+                //增加送礼用户的财富等级
+                $res_wealth = \app\common\model\User::add_wealth_level($giftuserparty['user_id'],$giftValue);
+
+                Db::name('gift_user_party')->where('id',$giftuserparty['id'])->update(['task_status'=>1]);
+            }
+            Db::commit();
+        } catch (ValidateException $e) {
+            Db::rollback();
+            $this->error($e->getMessage());
+        } catch (PDOException $e) {
+            Db::rollback();
+            $this->error($e->getMessage());
+        } catch (Exception $e) {
+            Db::rollback();
+            $this->error($e->getMessage());
+        }
+
+    }
 
+/////////////////////////////////////////下面都是工具方法////////////////////////////////////////////////
     //下载远程文件 到指定目录
     private function downloadfile($file_url, $path = '', $save_file_name = '')
     {