<?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; } }