DeleteController.class.php
4.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
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
<?php
/**
* 【后台】 删除培训接口
* DeleteController.class.php
* User: yingcai
* Date: 2017/8/29
* Time: 下午6:15
*/
namespace Apicp\Controller\Education;
use Common\Common\AttachOperation;
use Common\Service\CommentOptionsService;
use Common\Service\EducationService;
use Common\Service\PlanPicService;
use Common\Service\PlanService;
use Common\Service\RightService;
use Common\Service\RightUsersService;
use Common\Service\SignService;
class DeleteController extends \Apicp\Controller\AbstractController
{
/** @var EducationService 实例化权限表对象 */
protected $education_service;
/** @var RightService 实例化权限表对象 */
protected $right_service;
/** @var RightUsersService 班级人员表对象 */
protected $right_user_service;
/** @var PlanService 培训计划表对象 */
protected $plan_service;
/** @var CommentOptionsService 培训评价选项表对象 */
protected $com_opt_service;
/** @var SignService 签到表对象 */
protected $sign_service;
/** @var PlanPicService 照片表对象 */
protected $plan_pic_service;
public function before_action($action = '')
{
if (!parent::before_action($action)) {
return false;
}
$this->education_service = new EducationService();
$this->right_service = new RightService();
$this->right_user_service = new RightUsersService();
$this->plan_service = new PlanService();
$this->com_opt_service = new CommentOptionsService();
$this->sign_service = new SignService();
$this->plan_pic_service = new PlanPicService();
return true;
}
public function Index_post()
{
$ed_ids = I('post.ed_ids');
// 培训ID不能为空
if (empty($ed_ids) || !is_array($ed_ids)) {
E('_EMPTY_ED_ID');
}
try {
$this->education_service->start_trans();
// 获取所有培训
$education_list = $this->education_service->list_by_pks($ed_ids);
// 删除培训
$this->education_service->delete($ed_ids);
// 删除培训权限
$this->right_service->delete_by_conds(['ed_id' => $ed_ids]);
// 删除班级人员
$this->right_user_service->delete_by_conds(['ed_id' => $ed_ids]);
// 删除培训评价项
$this->com_opt_service->delete_by_conds(['ed_id' => $ed_ids]);
// 删除签到
$this->sign_service->delete_by_conds(['ed_id' => $ed_ids]);
// 获取被删除培训关联的照片墙计划ID
$conds = [
'ed_id' => $ed_ids,
'plan_type' => PlanService::PLAN_TYPE_PHOTO
];
$page_option = null;
$order_option = [];
$fields = 'plan_id';
$plans = $this->plan_service->list_by_conds($conds, $page_option, $order_option, $fields);
$plan_ids = array_column($plans, 'plan_id');
// 删除照片
$this->plan_pic_service->delete_by_conds(['plan_id' => $plan_ids]);
// 删除培训计划
$this->plan_service->delete_by_conds(['ed_id' => $ed_ids]);
$this->education_service->commit();
} catch (\Exception $e) {
$this->education_service->rollback();
E('_ERR_DELETE_EDUCATION_FAILED');
return false;
}
// 删除首页推荐feed流
foreach ($education_list as $education) {
if ($education['ed_is_recommend']) {
$url = rpcUrl('/Public/Rpc/Recommender/ArticleDelete');
$params = [
'app' => 'train',
'dataCategoryId' => '',
'dataId' => $education['ed_id'],
];
\Com\Rpc::phprpc($url)->invoke('Index', $params);
}
}
/**
* 删除附件操作
*/
$attach_serv = new AttachOperation();
// 删除培训主表附件
$attach_serv->delete_attach(APP_DIR, 'education', $ed_ids);
// 删除照片墙附件
$attach_serv->delete_attach(APP_DIR, 'plan', $plan_ids);
return true;
}
}