EditController.class.php
1.77 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
<?php
/**
* 【后台】编辑分类接口
* EditController.class.php
* @author:daijun
* @date:2017-08-31
*/
namespace Apicp\Controller\Category;
use Common\Service\CategoryService;
use Common\Service\EducationService;
class EditController extends \Apicp\Controller\AbstractController
{
/**
* 编辑分类接口
* @author daijun
*/
public function Index_post()
{
// 获取请求参数
$data = I('post.');
// 实例化分类service
$cate_service = new CategoryService();
// 检查传入参数
$check_res = $cate_service->check_edit_data($data);
if (!$check_res) {
return false;
}
// 组织入库数据
$update_data = [
'ca_name' => $data['ca_name'],
'ca_status' => intval($data['ca_status']),
];
if (!empty($data['ca_desc'])) {
$update_data['ca_desc'] = strval($data['ca_desc']);
}
$education_serv = new EducationService();
try {
// 开启事务
$cate_service->start_trans();
// 更新分类表操作
$cate_service->update($data['ca_id'], $update_data);
// 组装更新条件
$conds = ['ca_id' => $data['ca_id']];
// 组装更新数据
$update_edu_data = ['ca_status' => $data['ca_status']];
// 同步更新培训主表分类状态
$education_serv->update_by_conds($conds, $update_edu_data);
// 提交事务
$cate_service->commit();
} catch (\Think\Exception $e) {
\Think\Log::record($e);
// 事务回滚
$cate_service->rollback();
E('_ERR_EDIT_FAIL');
}
return true;
}
}