diff --git a/app/api/controller/TaskController.php b/app/api/controller/TaskController.php index 1a3771be9..1e765c2a7 100644 --- a/app/api/controller/TaskController.php +++ b/app/api/controller/TaskController.php @@ -3,13 +3,17 @@ namespace app\api\controller; use app\common\logic\task\TaskLogic; +use app\common\model\Approve; use app\common\model\Company; use app\common\model\company\CompanyProperty; +use app\common\model\flow\Flow; use app\common\model\informationg\UserInformationg; use app\common\model\task\Task; use app\common\model\task_template\TaskTemplate; use app\common\model\user\User; -use think\facade\Log; +use think\Exception; +use think\facade\Db; + class TaskController extends BaseApiController { @@ -217,14 +221,45 @@ class TaskController extends BaseApiController */ public function cimmit_other_task() { - $parmas = $this->request->param(); //id note annex - $task = TaskLogic::detail($parmas); - if (empty($task)) { - $this->fail('任务不存在'); + try { + $parmas = $this->request->param(); //id note annex + $task = TaskLogic::detail($parmas); + if (empty($task)) { + $this->fail('任务不存在'); + } + $extend = ['other' => ['is_commit' => 1, 'note' => $parmas['note'], 'annex'=>$parmas['annex']]]; + Db::startTrans(); + Task::where(['id' => $parmas['id']])->update(['extend' => json_encode($extend)]); + + // 片区经理 + $areaManagerId = User::where(['id' => $this->userId])->with('company')->value('area_manager'); + + // 创建审批任务 + $approveModel = new Approve(); + $approveModel->type = 1; + $approveModel->flow_id = 1; + $approveModel->name = $task['title']; + $approveModel->type = 1; + $approveModel->admin_id = 0; // 后台发起人id 暂时为0 + $approveModel->user_id = $this->userId; // 前台发起人用户id + $approveModel->task_id = $task['id']; // 前台发起人用户id + $approveModel->check_admin_id = $areaManagerId; // 前审批人ID 片区经理的admin_id + $approveModel->check_status = 1; // 状态 0待审核,1审核中,2审核通过,3审核不通过,4撤销审核 + $approveModel->last_admin_id = $areaManagerId; + $approveModel->other_type = 6; + $approveModel->create_time = time(); + $approveModel->update_time = time(); + $approveModel->save(); + if ($approveModel->id) { + Db::commit(); + } + + return $this->success('ok', []); + } catch (Exception $e) { + Db::rollback(); + return $this->fail($e->getMessage()); } - $extend = ['other' => ['is_commit' => 1, 'note' => $parmas['note'], 'annex'=>$parmas['annex']]]; - Task::where(['id' => $parmas['id']])->update(['extend' => json_encode($extend)]); - return $this->success('ok', []); + } } diff --git a/app/common/model/Approve.php b/app/common/model/Approve.php new file mode 100644 index 000000000..e6dfb4af5 --- /dev/null +++ b/app/common/model/Approve.php @@ -0,0 +1,11 @@ +hasOne(Company::class, 'id', 'company_id')->field(['id','company_name','admin_id','company_type','responsible_area']); + return $this->hasOne(Company::class, 'id', 'company_id')->field(['id','company_name','admin_id','company_type','responsible_area', 'area_manager']); } public function getProvinceNameAttr($value) {