Browse Source

伴声个人任务本地化

lizhen_gitee 3 years ago
parent
commit
e844ea68c9
2 changed files with 38 additions and 25 deletions
  1. 27 20
      application/api/controller/Task.php
  2. 11 5
      application/common/model/TaskLog.php

+ 27 - 20
application/api/controller/Task.php

@@ -24,33 +24,33 @@ class Task extends Api
      * 获取任务列表
      */
     public function getTaskList() {
-        $type_id = $this->request->request("type_id"); // 任务类型:1=新手任务,2=每日任务,3=成长任务
-        $plat = $this->request->request("plat",1); // 平台:1=安卓,2=ios,3=小程序
-        $page = $this->request->request('page',1); // 分页
-        $pageNum = $this->request->request('pageNum',10); // 分页
-        // 分页搜索构建
-        $pageStart = ($page-1)*$pageNum;
-        $urlArr = ["1"=>"android_url","2"=>"ios_url","3"=>"mini_url"];
+        $type_id = $this->request->request("type_id",1); // 任务类型:1=实时任务,2=每日任务
+        $plat = $this->request->request("plat",1); // 平台:1=安卓,2=ios
+
+        $urlArr = ["1"=>"android_url","2"=>"ios_url"];
         $jump_url = $urlArr[$plat];
 
         if($type_id == 2) {
 
-            // 获取基本信息
+            // 获取所有基础任务
             $where = [];
-            $type_id && $where["type_id"] = $type_id;
+            $where["type_id"] = 2;
             $where["is_show"] = 1;
+
             $taskList = $this->taskModel
-                ->field("id,type_id,image,name,exp,number,".$jump_url." as jump_url")
+                ->field("id,type_id,image,name,exp,number,".$jump_url." as jump_url,url_type")
                 ->where($where)
-                ->limit($pageStart,$pageNum)
+                ->autopage()
                 ->select();
 
             $today = strtotime(date("Y-m-d 00:00:00"));
 
+            //今日开始的任务
             $where = [];
             $where["user_id"] = $this->auth->id;
             $where["createtime"] = ["gt",$today];
             $finishInfo = \app\common\model\TaskLog::where($where)->select();
+
             $finishIds = [];
             if($finishInfo) foreach($finishInfo as $k => $v) {
                 $finishIds[$v["task_id"]] = $v;
@@ -79,13 +79,13 @@ class Task extends Api
         } else {
             // 获取基本信息
             $where = [];
-            $type_id && $where["a.type_id"] = $type_id;
+            $where["a.type_id"] = 1;
             $where["a.is_show"] = 1;
             $taskList = $this->taskModel->alias("a")
                 ->field("a.id,a.type_id,a.image,a.name,a.exp,a.number,a.".$jump_url." as jump_url,a.url_type,l.pace,l.is_reward,l.is_finish,l.finish_number")
-                ->join("hx_task_log l", "l.task_id = a.id and l.user_id = ".$this->auth->id, "left")
+                ->join("task_log l", "l.task_id = a.id and l.user_id = ".$this->auth->id, "left")
                 ->where($where)
-                ->limit($pageStart,$pageNum)
+                ->autopage()
                 ->order("is_finish","asc")
                 ->select();
 
@@ -123,7 +123,9 @@ class Task extends Api
         $where["user_id"] = $this->auth->id;
         $where["task_id"] = $task_id;
         $where["is_finish"] = 1;
-        $taskInfo["type_id"] == 2 && $where["finish_date"] = date("Ymd");
+        if($taskInfo["type_id"] == 2){
+            $where["finish_date"] = date("Ymd");
+        }
         $tasklogInfo = $this->tasklogModel->where($where)->find();
         if(!$tasklogInfo) {
             $this->error("任务还未完成哦!");
@@ -134,10 +136,15 @@ class Task extends Api
         Db::startTrans();
         try{
             // 增加用户经验值
-            $res1 = \app\common\model\User::addEmpirical($this->auth->id,$taskInfo["exp"]);
+            //$res1 = \app\common\model\User::addEmpirical($this->auth->id,$taskInfo["exp"]);
+            $res1 = model('wallet')->lockChangeAccountRemain($this->auth->id,'gold',$taskInfo["exp"],61,$taskInfo['name'],'task_log',$tasklogInfo);
+            if($res1['status'] === false){
+                Db::rollback();
+                $this->error($res1['msg']);
+            }
             // 更新奖励领取状态
             $res2 = $this->tasklogModel->update(["is_reward"=>1],["task_id"=>$task_id,"user_id"=>$this->auth->id]);
-            if($res1 && $res2) {
+            if($res1['status'] === true && $res2) {
                 Db::commit();
                 $this->success("领取成功!");
             } else {
@@ -159,12 +166,12 @@ class Task extends Api
      * 完成任务
      */
     public function finishTask() {
-        $code = $this->request->request("code"); // 任务编码
+        $task_id = $this->request->request("task_id"); // 任务编码
         $number = $this->request->request("number",1); // 完成次数
-        if (!$code) {
+        if (!$task_id) {
             $this->error(__('Invalid parameters'));
         }
-        \app\common\model\TaskLog::tofinish($this->auth->id,$code,$number);
+        \app\common\model\TaskLog::tofinish($this->auth->id,$task_id,$number);
         $this->success("成功!");
 
     }

+ 11 - 5
application/common/model/TaskLog.php

@@ -14,20 +14,21 @@ class TaskLog extends Model
     protected $autoWriteTimestamp = 'int';
     // 定义时间戳字段名
     protected $createTime = 'createtime';
-//    protected $updateTime = 'updatetime';
+    protected $updateTime = 'updatetime';
 
     /**
      * 增加任务完成进度
      */
-    public static function tofinish($user_id,$task_no,$number) {
-        if(!$user_id || !$task_no || !$number) {
+    public static function tofinish($user_id,$task_id,$number) {
+        if(!$user_id || !$task_id || !$number) {
             return false;
         }
         // 查询任务明细
         $taskModel = new \app\common\model\Task();
         $tasklogModel = new \app\common\model\TaskLog();
+
         $where = [];
-        $where["task_no"] = $task_no;
+        $where["id"] = $task_id;
         $where["is_show"] = 1;
         $taskInfo = $taskModel->where($where)->find();
         if(!$taskInfo) {
@@ -37,13 +38,18 @@ class TaskLog extends Model
         $where = [];
         $where["user_id"] = $user_id;
         $where["task_id"] = $taskInfo["id"];
-        $taskInfo["type_id"] == 2 && $where["finish_date"] = date("Ymd");
+
+        if($taskInfo["type_id"] == 2){
+            $where["finish_date"] = date("Ymd");
+        };
+
         $tasklogInfo = $tasklogModel->where($where)->find();
         if($tasklogInfo) {
             if($tasklogInfo["finish_number"] >= $taskInfo["number"] || $tasklogInfo["is_finish"] == 1) {
                 if($tasklogInfo["finish_number"] >= $taskInfo["number"]) {
                     $tasklogInfo->is_finish = 1;
                     $tasklogInfo->save();
+                    return false;
                 } else {
                     return false;
                 }