|
@@ -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("成功!");
|
|
|
|
|
|
}
|