diff --git a/application/common/Model/ProjectFeatures.php b/application/common/Model/ProjectFeatures.php new file mode 100644 index 0000000..6202097 --- /dev/null +++ b/application/common/Model/ProjectFeatures.php @@ -0,0 +1,72 @@ + $projectCode, 'deleted' => 0])->field('id')->find(); + if (!$project) { + return error(3, '该项目已失效'); + } + $features = self::where(['name' => $name, 'project_code' => $projectCode])->find(); + if ($features) { + return error(2, '该版本库已名称存在'); + } + $data = [ + 'create_time' => nowTime(), + 'code' => createUniqueCode('ProjectFeatures'), + 'project_code' => $projectCode, + 'description' => $description, + 'organization_code' => $organizationCode, + 'name' => trim($name), + ]; + $result = self::create($data)->toArray(); + return $result; + } + + /** + * 删除版本库 + * @param $featuresCode + * @return array|bool + * @throws Exception + * @throws PDOException + */ + public function deleteProjectFeatures($featuresCode) + { + if (!$featuresCode) { + return error(1, '请选择一个版本库'); + } + self::where(['code' => $featuresCode])->delete(); + Task::update(['features_code' => '', 'version_code' => ''], ['features_code' => $featuresCode]); + return true; + } +} diff --git a/application/common/Model/ProjectVersion.php b/application/common/Model/ProjectVersion.php new file mode 100644 index 0000000..561bd92 --- /dev/null +++ b/application/common/Model/ProjectVersion.php @@ -0,0 +1,111 @@ + $featuresCode])->field('id')->find(); + if (!$projectFeatures) { + return error(3, '该版本库已失效'); + } + $version = self::where(['name' => $name, 'features_code' => $featuresCode])->find(); + if ($version) { + return error(2, '该版本已名称存在'); + } + $data = [ + 'create_time' => nowTime(), + 'code' => createUniqueCode('ProjectVersion'), + 'features_code' => $featuresCode, + 'start_time' => $startTime, + 'plan_publish_time' => $planPublishTime, + 'description' => $description, + 'organization_code' => $organizationCode, + 'name' => trim($name), + ]; + $result = self::create($data)->toArray(); + return $result; + } + + /** + * 删除版本 + * @param $featuresCode + * @return array|bool + * @throws Exception + * @throws PDOException + */ + public function deleteProjectVersion($versionCode) + { + if (!$versionCode) { + return error(1, '请选择一个版本'); + } + self::where(['code' => $versionCode])->delete(); + Task::update(['features_code' => '', 'version_code' => ''], ['version_code' => $versionCode]); + return true; + } + + public function changeStatus($versionCode, $status, $publishTime = '') + { + if (!$versionCode) { + return error(1, '请选择一个版本'); + } + $updateData = ['status' => $status]; + if ($status == 3) { + $updateData['publish_time'] = $publishTime; + } + self::update($updateData, ['code' => $versionCode]); + return true; + } + + public function getStatusTextAttr($value, $data) + { + //状态。0:未开始,1:进行中,2:延期发布,3:已发布 + if (!isset($data['status'])) { + return '-'; + } + switch ($data['status']) { + case 0: + return '未开始'; + case 1: + return '进行中'; + case 2: + return '延期发布'; + case 3: + return '已发布'; + + } + + } +} diff --git a/application/common/Model/ProjectVersionLog.php b/application/common/Model/ProjectVersionLog.php new file mode 100644 index 0000000..27c408f --- /dev/null +++ b/application/common/Model/ProjectVersionLog.php @@ -0,0 +1,8 @@ +model) { + $this->model = new \app\common\Model\ProjectFeatures(); + } + } + + /** + * 显示资源版本库 + * @return void + * @throws DataNotFoundException + * @throws ModelNotFoundException + * @throws DbException + */ + public function index() + { + $where = []; + $code = Request::post('projectCode'); + if (!$code) { + $this->error("请选择一个项目"); + } + $where[] = ['project_code', '=', $code]; +// $list = $this->model->_list($where, 'sort asc,id asc'); + $list = $this->model->where($where)->order('id desc')->select()->toArray(); + $this->success('', $list); + } + + /** + * 新增 + * @param Request $request + * @return void + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException + */ + public function save(Request $request) + { + $data = $request::only('name,projectCode,description'); + if (!$request::post('name')) { + $this->error("请填写版本库名称"); + } + $result = $this->model->createData($data['name'], $data['description'], $data['projectCode'], getCurrentOrganizationCode()); + if (!isError($result)) { + $this->success('添加成功', $result); + } + $this->error($result['msg']); + } + + /** + * 保存 + * @param Request $request + * @return void + * @throws DataNotFoundException + * @throws ModelNotFoundException + * @throws DbException + */ + public function edit(Request $request) + { + $data = $request::only('name,description,featuresCode'); + if (!$request::post('name')) { + $this->error("请填写版本库名称"); + } + if (!$data['featuresCode']) { + $this->error("请选择一个版本库"); + } + $features = $this->model->where(['code' => $data['featuresCode']])->field('id,project_code')->find(); + if (!$features) { + $this->error("该版本库已失效"); + } + $has = $this->model->where(['name' => $data['name'], 'project_code' => $features['project_code']])->field('id')->find(); + if ($has && $has['id'] != $features['id']) { + $this->error("该版本库名称已存在"); + } + $result = $this->model->_edit(['name' => $data['name'], 'description' => $data['description']], ['code' => $data['featuresCode']]); + if ($result) { + $this->success(''); + } + $this->error("操作失败,请稍候再试!"); + } + + /** + * 删除版本库 + * @return void + * @throws Exception + * @throws PDOException + */ + public function delete() + { + $code = Request::post('featuresCode'); + if (!$code) { + $this->error("请选择一个版本库"); + } + $result = $this->model->deleteProjectFeatures($code); + if (isError($result)) { + $this->error($result['msg'], $result['errno']); + } + $this->success(); + } +} diff --git a/application/project/controller/ProjectVersion.php b/application/project/controller/ProjectVersion.php new file mode 100644 index 0000000..f46279a --- /dev/null +++ b/application/project/controller/ProjectVersion.php @@ -0,0 +1,173 @@ +model) { + $this->model = new \app\common\Model\ProjectVersion(); + } + } + + /** + * 显示资源版本 + * @return void + * @throws DataNotFoundException + * @throws ModelNotFoundException + * @throws DbException + */ + public function index() + { + $where = []; + $code = Request::post('projectFeaturesCode'); + if (!$code) { + $this->error("请选择一个版本库"); + } + $where[] = ['features_code', '=', $code]; + $list = $this->model->where($where)->order('id asc')->select()->toArray(); + $this->success('', $list); + } + + /** + * 新增 + * @param Request $request + * @return void + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException + */ + public function save(Request $request) + { + $data = $request::only('featuresCode,name,description,projectCode,startTime,planPublishTime'); + if (!$request::post('name')) { + $this->error("请填写版本名称"); + } + $result = $this->model->createData($data['featuresCode'], $data['name'], $data['description'], getCurrentOrganizationCode(), $data['startTime'], $data['planPublishTime']); + if (!isError($result)) { + $this->success('添加成功', $result); + } + $this->error($result['msg']); + } + + /** + * 保存 + * @param Request $request + * @return void + * @throws DataNotFoundException + * @throws ModelNotFoundException + * @throws DbException + */ + public function edit(Request $request) + { + $data = $request::only('name,description,start_time,plan_publish_time'); + $versionCode = $request::param('versionCode'); + if (isset($data['name']) && !$data['name']) { + $this->error("请填写版本名称"); + } + if (!$versionCode) { + $this->error("请选择一个版本"); + } + $version = $this->model->where(['code' => $versionCode])->field('id,features_code')->find(); + if (!$version) { + $this->error("该版本已失效"); + } + if (isset($data['name'])) { + $has = $this->model->where(['name' => $data['name'], 'features_code' => $version['features_code']])->field('id')->find(); + if ($has && $has['id'] != $version['id']) { + $this->error("该版本名称已存在"); + } + } + $result = $this->model->_edit($data, ['code' => $versionCode]); + if ($result) { + $this->success(''); + } + $this->error("操作失败,请稍候再试!"); + } + + /** + * 更改状态 + */ + public function changeStatus() + { + $code = Request::post('versionCode'); + $status = Request::post('status', ''); + $publishTime = Request::post('publishTime', ''); + $result = $this->model->changeStatus($code, $status, $publishTime); + if (isError($result)) { + $this->error($result['msg'], $result['errno']); + } + $this->success(); + } + + /** + * 详情 + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException + */ + public function read() + { + $code = Request::post('versionCode'); + $version = $this->model->where(['code' => $code])->field('id', true)->find(); + if ($version) { + $version['featureName'] = \app\common\Model\ProjectFeatures::where(['code' => $version['features_code']])->find(); + $version['featureName'] && $version['featureName'] = $version['featureName']['name']; + } + $this->success('', $version); + } + + public function _getVersionTask() + { + $code = Request::post('versionCode'); + $taskList = \app\common\Model\Task::where(['version_code' => $code, 'deleted' => 0])->field('id', true)->select(); + $this->success('', $taskList); + } + + public function _getVersionLog() + { + $code = Request::post('versionCode'); + $logList = ProjectVersionLog::where(['source_code' => $code])->field('id', true)->select(); + if ($logList) { + foreach ($logList as &$item) { + $member = Member::where(['code' => $item['member_code']])->field('id,name,avatar,code')->find(); + !$member && $member = []; + $item['member'] = $member; + } + } + $this->success('', $logList); + } + + /** + * 删除版本 + * @return void + * @throws Exception + * @throws PDOException + */ + public function delete() + { + $code = Request::post('versionCode'); + if (!$code) { + $this->error("请选择一个版本"); + } + $result = $this->model->deleteProjectVersion($code); + if (isError($result)) { + $this->error($result['msg'], $result['errno']); + } + $this->success(); + } +}