RegiveAllController.class.php
2 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
<?php
/**
* 【销售活动-后台】管理员批量补发领取失败红包接口
*
* author daijun
*/
namespace Apicp\Controller\Red;
use Common\Service\ActivityService;
use Common\Service\PacketrecordService;
class RegiveAllController extends \Apicp\Controller\AbstractController
{
// 每次处理条数
const MAX_LIMIT = 100;
/**
* 接收参数
* ac_id int 必填 活动ID
*
* @return bool
*/
public function Index_post()
{
$ac_id = I('post.ac_id', 0, 'intval');
if (empty($ac_id)) {
// 验证数据
E('_EMPTY_ACTIVITY_ID');
}
// 实例化活动表
$activity_serv = new ActivityService();
// 获取活动信息
$activity = $activity_serv->get($ac_id);
if (empty($activity)) {
// 活动信息不存在
E('_ERR_ACTIVITY_DATA');
}
// 实例化用户红包记录表
$packet_records = new PacketrecordService();
$conds = [
'ac_id' => $ac_id, // 当前活动
'packet_status' => PacketrecordService::PACKET_STATUS_FAIL, // 领取失败
];
$field = 'rid,pid,p_type,ac_id,cid,rand_money,uid,username';
// 查询领取失败的所有红包记录
$record_list = $packet_records->list_by_conds($conds, [0, self::MAX_LIMIT], [], $field);
if (empty($record_list)) {
// 如果记录为空
$this->_result = [
'fail_count' => 0
];
return true;
}
// 循环处理数据
foreach ($record_list as $record) {
// 补发新的红包关联为旧红包的子红包,并推送消息
$packet_records->regive_red($record, $this->_login->user, $activity);
}
// 获取剩余待补发的数量
$fail_count = $packet_records->count_by_conds($conds);
$this->_result = [
'fail_count' => (int)$fail_count
];
return true;
}
}