AddController.class.php
3.12 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
/**
* 【手机端】07-发布照片接口
* Created by PhpStorm.
* @author:wanghuan
* @date:2017-08-31
*/
namespace Api\Controller\Pic;
use Common\Common\AttachOperation;
use Common\Service\PlanService;
use Common\Service\PlanPicService;
use Common\Service\RightUsersService;
class AddController extends \Api\Controller\AbstractController
{
/** @var PlanService */
protected $plan_s;
/** @var PlanPicService */
protected $pic_s;
/** @var RightUsersService */
protected $right_users_s;
public function before_action($action = '')
{
if (!parent::before_action($action)) {
return false;
}
// 实例化培训计划service
$this->plan_s = new PlanService();
// 实例化照片service
$this->pic_s = new PlanPicService();
// 实例化员工名单service
$this->right_users_s = new RightUsersService();
return true;
}
/**
* 发布照片
*/
public function Index_post()
{
// 培训id
$ed_id = I('post.ed_id', 0, 'intval');
// 培训id为空
if (!$ed_id) {
E('_EMPTY_ED_ID');
}
// 培训详情
$this->get_education($ed_id);
// 适用范围查询条件
$right_cond = [
'ru_uid' => $this->uid,
'ed_id' => $ed_id
];
// 查询当前员工适用范围数据
$user_right = $this->right_users_s->get_by_conds($right_cond);
// 当前员工不在适用范围
if (empty($user_right)) {
E('_ERR_ED_NO_RIGHT');
}
// 照片墙id
$plan_id = I('post.plan_id', 0, 'intval');
// 照片墙id为空
if (!$plan_id) {
E('_EMPTY_PIC_PLAN_ID');
}
// 照片墙信息
$plan = $this->plan_s->get($plan_id);
if (!$plan) {
E('_ERR_PIC_PLAN_EXIST');
}
// 照片描述
$pic_name = I('post.pic_name');
// 照片描述为空
if (!$pic_name) {
E('_EMPTY_PIC_NAME');
}
// 照片附件id
$pic_at_id = I('post.pic_at_id');
// 照片附件id为空
if (!$pic_at_id) {
E('_EMPTY_PIC_AT_ID');
}
// 待新增数据
$data = [
'pic_name' => $pic_name,
'pic_at_id' => $pic_at_id,
'pic_uid' => $this->uid,
'plan_id' => $plan_id,
'ed_id' => $ed_id
];
// 查询照片数据
$pic = $this->pic_s->get_by_conds($data);
// 已发布过名称相同照片提示:已发布过相同描述的照片(避免连击导致多次插入)
if (!empty($pic)) {
E('_ERR_PIC_EXIST');
}
// 新增
$result = $this->pic_s->insert($data);
// 新增失败
if (!$result) {
E('_EMPTY_ADD_PIC_FAIL');
}
$attach_serv = new AttachOperation();
$attach_serv->insert_attach(
APP_DIR,
'plan',
$plan_id,
['attach_ids' => [$pic_at_id]]
);
return true;
}
}