nowTime(), 'code' => createUniqueCode('projectTemplate'), 'member_code' => $memberCode, 'name' => $name, 'description' => $description, 'organization_code' => $orgCode, 'cover' => $cover ?? FileService::getFilePrefix() . 'static/image/default/cover.png' ]; $result = self::create($data); if ($result) { $taskStagesList = TaskStagesTemplate::$defaultTaskStagesNameList; if ($taskStagesList) { foreach ($taskStagesList as $name) { TaskStagesTemplate::createTaskStagesTemplate($data['code'], $name); } } } return $result; } /** * 删除模板 * @param $code * @return bool * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public function deleteTemplate($code) { $template = self::where(['code' => $code])->field('id')->find(); if (!$template) { throw new \Exception('该模板不存在', 1); } $result = self::destroy(['code' => $code]); if (!$result) { throw new \Exception('删除失败', 2); } return TaskStagesTemplate::destroy(['project_template_code' => $code]); } /** * @param File $file * @return array|bool * @throws \think\Exception * @throws \think\exception\PDOException * @throws \Exception */ public function uploadCover(File $file) { return $this->_uploadImg($file); } }