UpdateUnreadController.class.php
1.69 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
<?php
/**
* Created by PhpStorm.
* User: liyifei2012it
* Date: 17/4/11
* Time: 19:12
*/
namespace Apicp\Controller\News;
use Com\PackageValidate;
use Common\Common\Constant;
use Common\Common\NewsHelper;
use Common\Service\ArticleService;
class UpdateUnreadController extends \Apicp\Controller\AbstractController
{
/**
* UpdateUnread
* @author zhonglei
* @desc 更新未读总数
* @param Array article_ids:true 新闻ID数组
* @return mixed
*/
public function Index_post()
{
// 验证规则
$rules = [
'article_ids' => 'require|array',
];
// 验证数据
$validate = new PackageValidate($rules, [], array_keys($rules));
$postData = $validate->postData;
$article_ids = $postData['article_ids'];
$artServ = new ArticleService();
$list = $artServ->list_by_conds([
'article_id' => $article_ids,
'update_time < ?' => MILLI_TIME - Constant::NEWS_UNREAD_TIME,
]);
if (empty($list)) {
return true;
}
$newsHelper = &NewsHelper::instance();
foreach ($list as $article) {
list(, $uids_read, $uids_unread) = $newsHelper->getReadData($article['article_id']);
$unread_total = count($uids_unread);
$read_total = count($uids_read);
if ($article['unread_total'] != $unread_total || $article['read_total'] != $read_total) {
$artServ->update($article['article_id'], [
'unread_total' => $unread_total,
'read_total' => $read_total,
'update_time' => MILLI_TIME,
]);
}
}
}
}