DeleteController.class.php
3.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<?php
/**
* 【销售活动-后台】删除活动接口
*
* User: WJY
* Date: 2017-11-02
*/
namespace Apicp\Controller\Activity;
use Common\Common\AttachOperation;
use Common\Common\Helper;
use Common\Service\ActivityService;
use Common\Service\CommentService;
use Common\Service\ReplyService;
use Common\Service\RightService;
use Think\Exception;
class DeleteController extends \Apicp\Controller\AbstractController
{
/** @var ActivityService */
protected $activity_s;
/** @var CommentService */
protected $comment_s;
/** @var RightService */
protected $right_s;
/** @var ReplyService */
protected $reply_s;
public function before_action($action = '')
{
if (!parent::before_action($action)) {
return false;
}
// 实例化活动信息表
$this->activity_s = new ActivityService();
// 实例化评论表
$this->comment_s = new CommentService();
// 实例化权限表
$this->right_s = new RightService();
// 实例化回复表
$this->reply_s = new ReplyService();
return true;
}
public function Index_post()
{
$params = I('post.');
// 执行删除操作
$this->delete_activity($params);
$this->_result = [];
return true;
}
/**
* 删除活动信息
*
* @param array $reqData 请求数据
*
* @return bool
*/
protected function delete_activity($reqData)
{
$ids = $reqData['ac_ids'];
if (empty($ids) || !is_array($ids)) {
// 活动ID存在性判断
E('_EMPTY_ACTIVITY_ID');
}
// 组建条件数组
$conds = ['ac_id' => $ids];
// 开启红包的活动无法删除
$arrayList = $this->activity_s->list_by_conds($conds);
foreach ($arrayList as $value) {
// 如开起开开启红包
if ($value['is_red_open'] == ActivityService::RED_OPENED) {
// 获取当前活动状态1:草稿,2:未开始,3:进行中,4:已结束,5:已终止
$status = $this->activity_s->activity_status($value['activity_status'], $value['begin_time'],
$value['end_time']);
// 不能删除的状态
$cant_del_list = [
Helper::STATUS_ING, // 进行中
Helper::STATUS_END, // 已结束
Helper::STATUS_STOP // 已终止
];
if (in_array($status, $cant_del_list)) {
// 进行中,已结束,已终止的活动无法删除
E('_ERR_RED_ACTIVITY_CANT_DELETE');
}
}
}
// 获取评论ID集合
$comment_list = $this->comment_s->list_by_conds($conds);
$comment_ids = array_column($comment_list, 'comment_id');
try {
// 删除开始
$this->activity_s->start_trans();
// 删除活动主题
$this->activity_s->delete($ids);
// 删除权限
$this->right_s->delete_by_conds($conds);
// 删除评论
$this->comment_s->delete_by_conds($conds);
// 删除回复
$this->reply_s->delete_by_conds($conds);
// 提交修改
$this->activity_s->commit();
} catch (Exception $e) {
$this->activity_s->rollback();
E('_ERR_DELETE_FAILED');
}
// 附件删除操作
$attach_serv = new AttachOperation();
$attach_serv->delete_attach(APP_DIR, 'activity', $ids);
$attach_serv->delete_attach(APP_DIR, 'comment', $comment_ids);
return true;
}
}