RemindController.class.php
1.88 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
<?php
/**
* Created by PhpStorm.
* User: liyifei2012it
* Date: 17/4/11
* Time: 18:20
*/
namespace Apicp\Controller\News;
use Com\PackageValidate;
use Common\Common\Constant;
use Common\Common\NewsHelper;
use Common\Service\ClassService;
use Common\Service\ArticleService;
class RemindController extends \Apicp\Controller\AbstractController
{
/**
* Remind
* @author liyifei
* @desc 未读提醒
* @param Int article_id:true 新闻ID
* @param array uids:false 用户UIDS集合格式(array[1,2,3])
* @return array
*/
public function Index_post()
{
$uids = I('post.uids');
// 验证规则
$rules = [
'article_id' => 'require|integer',
];
// 验证数据
$validate = new PackageValidate($rules, [], array_keys($rules));
$postData = $validate->postData;
// 获取新闻详情
$articleServ = new ArticleService();
$article = $articleServ->get($postData['article_id']);
if (empty($article)) {
E('_ERR_ARTICLE_NOT_FOUND');
}
// 草稿和预发布不允许发送提醒
if (in_array($article['news_status'], [Constant::NEWS_STATUS_DRAFT, Constant::NEWS_STATUS_READY_SEND])) {
E('_ERR_ARTICLE_STATUS_FAIL');
}
// 获取顶级分类名称
$classServ = new ClassService();
$class = $classServ->getTopClass($article['class_id']);
$article['class_name'] = $class['class_name'];
// 获取未读人员列表
$newsHelper = &NewsHelper::instance();
list($uids_all, $uids_read, $uids_unread) = $newsHelper->getReadData($postData['article_id']);
// 提醒人员UID
if (!empty($uids)) {
$uids_unread = array_intersect($uids_unread, $uids);
}
// 发送未读提醒
$newsHelper->sendUnreadMsg($uids_unread, $article);
}
}