ContentListController.class.php
2.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
/**
* Created by PhpStorm.
* User: liyifei2012it
* Date: 17/7/26
* Time: 14:08
*/
namespace Api\Controller\Customtask;
use Com\PackageValidate;
use Common\Common\Constant;
use Common\Common\TaskHelper;
use Common\Service\CustomtaskContentService;
use Common\Service\UserContentService;
class ContentListController extends \Api\Controller\AbstractController
{
/**
* ContentList
* @author tangxingguo
* @desc 常规任务内容列表
* @param Int customtask_id 常规任务ID
* @return array
array(
'customtask_id' => 1, // 任务ID
'list' => array(
array(
'app' => 'news', // 应用(news=新闻;course=课程;exam=考试;activity=活动;questionnaire=调研)
'title' => '完不成别吃饭', // 标题
'content_status' => 1, // 内容完成状态(1=未完成;2=已完成;)
'link' => 'http://dsc.vchangyi.com', // 任务链接
),
),
);
*/
public function Index_post()
{
// 验证规则
$rules = [
'customtask_id' => 'require|integer',
];
// 验证数据
$validate = new PackageValidate($rules, [], array_keys($rules));
$customtask_id = $validate->postData['customtask_id'];
// 检查任务内容状态
$contentServ = new CustomtaskContentService();
$contents = $contentServ->list_by_conds(['customtask_id' => $customtask_id]);
if (empty($contents)) {
E('_ERR_CUSTOMTASK_NOT_FOUND');
}
// 任务内容详情
$userContentServ = new UserContentService();
$contentList = $userContentServ->list_by_conds(['customtask_id' => $customtask_id, 'uid' => $this->uid]);
if (!empty($contentList)) {
$contentList = array_combine_by_key($contentList, 'customtask_content_id');
}
$list = [];
foreach ($contents as $k => $v) {
$status = isset($contentList[$v['customtask_content_id']]) ? $contentList[$v['customtask_content_id']]['content_status'] : Constant::USER_CONTENT_STATUS_INCOMPLETE;
$params = [
'app_data_id' => $v['app_data_id'],
'customtask_id' => $customtask_id,
];
$list[] = [
'app' => $v['app'],
'title' => $v['title'],
'content_status' => $status,
'link' => oaUrl('Frontend/Index/TaskCenter/Index', $params, '', ucwords($v['app'])),
];
}
$this->_result = [
'customtask_id' => $customtask_id,
'list' => $list,
];
}
}