增加版本管理
Signed-off-by: vilson <545522390@qq.com>
This commit is contained in:
parent
488cc3c24e
commit
3dd962df4a
@ -7,6 +7,7 @@ use think\db\exception\ModelNotFoundException;
|
||||
use think\Exception;
|
||||
use think\exception\DbException;
|
||||
use think\exception\PDOException;
|
||||
use think\facade\Hook;
|
||||
|
||||
/**
|
||||
* 版本
|
||||
@ -71,6 +72,7 @@ class ProjectVersion extends CommonModel
|
||||
if (!$versionCode) {
|
||||
return error(1, '请选择一个版本');
|
||||
}
|
||||
ProjectVersion::versionHook(getCurrentMember()['code'], $versionCode, 'delete');
|
||||
self::where(['code' => $versionCode])->delete();
|
||||
Task::update(['features_code' => '', 'version_code' => ''], ['version_code' => $versionCode]);
|
||||
return true;
|
||||
@ -79,13 +81,17 @@ class ProjectVersion extends CommonModel
|
||||
public function changeStatus($versionCode, $status, $publishTime = '')
|
||||
{
|
||||
if (!$versionCode) {
|
||||
|
||||
return error(1, '请选择一个版本');
|
||||
}
|
||||
$updateData = ['status' => $status];
|
||||
$logType = 'status';
|
||||
if ($status == 3) {
|
||||
$updateData['publish_time'] = $publishTime;
|
||||
$logType = 'publish';
|
||||
}
|
||||
self::update($updateData, ['code' => $versionCode]);
|
||||
ProjectVersion::versionHook(getCurrentMember()['code'], $versionCode, $logType);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -106,6 +112,23 @@ class ProjectVersion extends CommonModel
|
||||
return '已发布';
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 版本变动钩子
|
||||
* @param $memberCode
|
||||
* @param $versionCode
|
||||
* @param string $type
|
||||
* @param string $remark
|
||||
* @param string $content
|
||||
* @param array $data
|
||||
* @param string $tag
|
||||
*/
|
||||
public static function versionHook($memberCode, $versionCode, $type = 'create', $remark = '', $content = '', $data = [], $tag = 'version')
|
||||
{
|
||||
$data = ['memberCode' => $memberCode, 'versionCode' => $versionCode, 'remark' => $remark, 'type' => $type, 'content' => $content, 'data' => $data, 'tag' => $tag];
|
||||
Hook::listen($tag, $data);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ class Project
|
||||
public function run($data)
|
||||
{
|
||||
Log::init(['path' => 'log/project']);
|
||||
$logData = ['member_code' => $data['memberCode'], 'source_code' => $data['sourceCode'], 'remark' => $data['remark'], 'type' => $data['type'], 'content' => $data['content'], 'is_comment' => $data['isComment'], 'to_member_code' => $data['toMemberCode'], 'create_time' => nowTime(), 'code' => createUniqueCode('collection'), 'action_type' => 'project'];
|
||||
$logData = ['member_code' => $data['memberCode'], 'source_code' => $data['sourceCode'], 'remark' => $data['remark'], 'type' => $data['type'], 'content' => $data['content'], 'is_comment' => $data['isComment'], 'to_member_code' => $data['toMemberCode'], 'create_time' => nowTime(), 'code' => createUniqueCode('projectLog'), 'action_type' => 'project'];
|
||||
$project = \app\common\Model\Project::where(['code' => $data['sourceCode']])->find();
|
||||
$logData['project_code'] = $project['code'];
|
||||
$toMember = [];
|
||||
|
@ -29,7 +29,7 @@ class Task
|
||||
public function run($data)
|
||||
{
|
||||
Log::init(['path' => 'log/task']);
|
||||
$logData = ['member_code' => $data['memberCode'], 'source_code' => $data['taskCode'], 'remark' => $data['remark'], 'type' => $data['type'], 'content' => $data['content'], 'is_comment' => $data['isComment'], 'to_member_code' => $data['toMemberCode'], 'create_time' => nowTime(), 'code' => createUniqueCode('collection'), 'action_type' => 'task'];
|
||||
$logData = ['member_code' => $data['memberCode'], 'source_code' => $data['taskCode'], 'remark' => $data['remark'], 'type' => $data['type'], 'content' => $data['content'], 'is_comment' => $data['isComment'], 'to_member_code' => $data['toMemberCode'], 'create_time' => nowTime(), 'code' => createUniqueCode('projectLog'), 'action_type' => 'task'];
|
||||
$task = \app\common\Model\Task::where(['code' => $data['taskCode']])->find();
|
||||
$logData['project_code'] = $task['project_code'];
|
||||
$toMember = [];
|
||||
|
116
application/project/behavior/Version.php
Normal file
116
application/project/behavior/Version.php
Normal file
@ -0,0 +1,116 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* SystemUser: vilson
|
||||
* Date: 2018/7/10
|
||||
* Time: 12:38
|
||||
*/
|
||||
|
||||
namespace app\project\behavior;
|
||||
|
||||
|
||||
use app\common\Model\CommonModel;
|
||||
use app\common\Model\Member;
|
||||
use app\common\Model\Notify;
|
||||
use app\common\Model\ProjectLog;
|
||||
use app\common\Model\ProjectVersion;
|
||||
use app\common\Model\ProjectVersionLog;
|
||||
use app\common\Model\TaskMember;
|
||||
use app\common\Model\TaskStages;
|
||||
use service\MessageService;
|
||||
use think\db\exception\DataNotFoundException;
|
||||
use think\db\exception\ModelNotFoundException;
|
||||
use think\exception\DbException;
|
||||
use think\facade\Log;
|
||||
|
||||
class Version
|
||||
{
|
||||
/**
|
||||
* 版本操作钩子
|
||||
* @param $data
|
||||
* @throws DataNotFoundException
|
||||
* @throws ModelNotFoundException
|
||||
* @throws DbException
|
||||
*/
|
||||
public function run($data)
|
||||
{
|
||||
Log::init(['path' => 'log/task']);
|
||||
$logData = ['member_code' => $data['memberCode'], 'source_code' => $data['versionCode'], 'remark' => $data['remark'], 'type' => $data['type'], 'content' => $data['content'], 'create_time' => nowTime(), 'code' => createUniqueCode('projectVersionLog')];
|
||||
$version = ProjectVersion::where(['code' => $data['versionCode']])->find();
|
||||
$logData['features_code'] = $version['features_code'];
|
||||
$remark = '';
|
||||
$content = '';
|
||||
switch ($data['type']) {
|
||||
case 'create':
|
||||
$icon = 'plus';
|
||||
$remark = '创建了版本 ';
|
||||
$content = $version['name'];
|
||||
break;
|
||||
case 'status':
|
||||
$icon = 'check-square';
|
||||
$remark = '更新了状态为 ' . $version['statusText'];
|
||||
break;
|
||||
case 'publish':
|
||||
$icon = 'check-square';
|
||||
$remark = '完成版本时间为 ' . date('m月d日 H:i', strtotime($version['publish_time']));
|
||||
break;
|
||||
case 'name':
|
||||
$icon = 'edit';
|
||||
$remark = '更新了版本名 ';
|
||||
$content = $version['name'];
|
||||
break;
|
||||
case 'content':
|
||||
$icon = 'file-text';
|
||||
$remark = '更新了备注 ';
|
||||
$content = $version['description'];
|
||||
break;
|
||||
case 'clearContent':
|
||||
$icon = 'file-text';
|
||||
$remark = '清空了备注 ';
|
||||
break;
|
||||
case 'setStartTime':
|
||||
$icon = 'calendar';
|
||||
$remark = '更新开始时间为 ' . date('m月d日 H:i', strtotime($version['start_time']));
|
||||
break;
|
||||
case 'clearStartTime':
|
||||
$icon = 'calendar';
|
||||
$remark = '清除了开始时间 ';
|
||||
break;
|
||||
case 'setPlanPublishTime':
|
||||
$icon = 'calendar';
|
||||
$remark = '更新计划发布时间为 ' . date('m月d日 H:i', strtotime($version['plan_publish_time']));
|
||||
break;
|
||||
case 'clearPlanPublishTime':
|
||||
$icon = 'calendar';
|
||||
$remark = '清除了计划发布时间 ';
|
||||
break;
|
||||
case 'delete':
|
||||
$icon = 'delete';
|
||||
$remark = '删除了版本 ';
|
||||
break;
|
||||
case 'linkFile':
|
||||
$icon = 'link';
|
||||
$remark = ' 添加了 2 项发布内容 ';
|
||||
$content = "<a target=\"_blank\" class=\"muted\" href=\"{$data['data']['url']} \">{$data['data']['title']}</a>";
|
||||
|
||||
break;
|
||||
case 'unlinkFile':
|
||||
$icon = 'disconnect';
|
||||
$remark = '移除了发布内容';
|
||||
$content = "<a target=\"_blank\" class=\"muted\" href=\"{$data['data']['url']} \">{$data['data']['title']}</a>";
|
||||
break;
|
||||
default:
|
||||
$icon = 'plus';
|
||||
$remark = ' 创建了版本 ';
|
||||
break;
|
||||
}
|
||||
$logData['icon'] = $icon;
|
||||
if (!$data['remark']) {
|
||||
$logData['remark'] = $remark;
|
||||
}
|
||||
if (!$data['content']) {
|
||||
$logData['content'] = $content;
|
||||
}
|
||||
ProjectVersionLog::create($logData);
|
||||
}
|
||||
}
|
@ -3,6 +3,7 @@
|
||||
namespace app\project\controller;
|
||||
|
||||
use app\common\Model\Member;
|
||||
use app\common\Model\ProjectLog;
|
||||
use app\common\Model\ProjectVersionLog;
|
||||
use controller\BasicApi;
|
||||
use think\db\exception\DataNotFoundException;
|
||||
@ -59,6 +60,7 @@ class ProjectVersion extends BasicApi
|
||||
}
|
||||
$result = $this->model->createData($data['featuresCode'], $data['name'], $data['description'], getCurrentOrganizationCode(), $data['startTime'], $data['planPublishTime']);
|
||||
if (!isError($result)) {
|
||||
\app\common\Model\ProjectVersion::versionHook(getCurrentMember()['code'], $result['code'], 'create');
|
||||
$this->success('添加成功', $result);
|
||||
}
|
||||
$this->error($result['msg']);
|
||||
@ -94,6 +96,30 @@ class ProjectVersion extends BasicApi
|
||||
}
|
||||
$result = $this->model->_edit($data, ['code' => $versionCode]);
|
||||
if ($result) {
|
||||
$member = getCurrentMember();
|
||||
$type = 'name';
|
||||
if (isset($data['name'])) {
|
||||
$type = 'name';
|
||||
}
|
||||
if (isset($data['description'])) {
|
||||
$type = 'content';
|
||||
if (!$data['description']) {
|
||||
$type = 'clearContent';
|
||||
}
|
||||
}
|
||||
if (isset($data['start_time'])) {
|
||||
$type = 'setStartTime';
|
||||
if (!$data['start_time']) {
|
||||
$type = 'clearStartTime';
|
||||
}
|
||||
}
|
||||
if (isset($data['plan_publish_time'])) {
|
||||
$type = 'setPlanPublishTime';
|
||||
if (!$data['plan_publish_time']) {
|
||||
$type = 'clearPlanPublishTime';
|
||||
}
|
||||
}
|
||||
\app\common\Model\ProjectVersion::versionHook($member['code'], $versionCode, $type);
|
||||
$this->success('');
|
||||
}
|
||||
$this->error("操作失败,请稍候再试!");
|
||||
@ -131,6 +157,12 @@ class ProjectVersion extends BasicApi
|
||||
$this->success('', $version);
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联任务
|
||||
* @throws DataNotFoundException
|
||||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
*/
|
||||
public function _getVersionTask()
|
||||
{
|
||||
$code = Request::post('versionCode');
|
||||
@ -138,18 +170,47 @@ class ProjectVersion extends BasicApi
|
||||
$this->success('', $taskList);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws DataNotFoundException
|
||||
* @throws DbException
|
||||
* @throws ModelNotFoundException
|
||||
*/
|
||||
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);
|
||||
|
||||
$code = Request::post('versionCode');
|
||||
$logList = ProjectVersionLog::where(['source_code' => $code])->field('id', true)->select();
|
||||
if ($logList) {
|
||||
foreach ($logList as &$item) {
|
||||
$showAll = Request::post('all', 0);
|
||||
$where = [];
|
||||
$where[] = ['source_code', '=', $code];
|
||||
$projectVersionModel = new ProjectVersionLog();
|
||||
if ($showAll) {
|
||||
$list = [];
|
||||
$list['list'] = $projectVersionModel->where($where)->order('id asc')->select()->toArray();
|
||||
$list['total'] = count($list['list']);
|
||||
} else {
|
||||
$list = $projectVersionModel->_list($where, 'id desc');
|
||||
if ($list['list']) {
|
||||
$list['list'] = array_reverse($list['list']);
|
||||
}
|
||||
}
|
||||
if ($list['list']) {
|
||||
foreach ($list['list'] as &$item) {
|
||||
$member = Member::where(['code' => $item['member_code']])->field('id,name,avatar,code')->find();
|
||||
!$member && $member = [];
|
||||
$item['member'] = $member;
|
||||
}
|
||||
}
|
||||
$this->success('', $logList);
|
||||
$this->success('', $list);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -6,4 +6,7 @@ return [
|
||||
'project' => [
|
||||
'app\\project\\behavior\\Project'
|
||||
],
|
||||
'version' => [
|
||||
'app\\project\\behavior\\Version'
|
||||
],
|
||||
];
|
||||
|
Loading…
x
Reference in New Issue
Block a user