增加任务看板主题设置

Signed-off-by: vilson <545522390@qq.com>
This commit is contained in:
vilson 2019-06-23 11:12:33 +08:00
parent 3dd962df4a
commit 1f72f7321a
4 changed files with 127 additions and 22 deletions

View File

@ -2,6 +2,7 @@
namespace app\common\Model; namespace app\common\Model;
use PDOStatement;
use think\db\exception\DataNotFoundException; use think\db\exception\DataNotFoundException;
use think\db\exception\ModelNotFoundException; use think\db\exception\ModelNotFoundException;
use think\Exception; use think\Exception;
@ -95,6 +96,68 @@ class ProjectVersion extends CommonModel
return true; return true;
} }
public function addVersionTask($taskCode, $versionCode)
{
$task = Task::where(['code' => $taskCode])->field('id,version_code,name')->find();
if (!$task) {
return error(1, '该任务已被失效');
}
if ($task['version_code']) {
return error(1, '该任务已被关联');
}
$version = ProjectVersion::where(['code' => $versionCode])->find();
if (!$version) {
return error(1, '该版本已被失效');
}
$task->version_code = $versionCode;
$task->features_code = $version['features_code'];
$task->save();
self::updateSchedule($versionCode);
return $task;
}
/**
* 移除发布内容
* @param $taskCode
* @return array|PDOStatement|string|\think\Model|null
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
public function removeVersionTask($taskCode)
{
$task = Task::where(['code' => $taskCode])->field('id,version_code,name')->find();
if (!$task) {
return error(1, '该任务已被失效');
}
$versionCode = $task['version_code'];
if ($versionCode) {
$task->version_code = '';
$task->features_code = '';
$task->save();
ProjectVersion::versionHook(getCurrentMember()['code'], $versionCode, 'removeVersionTask', '', '', $task['name']);
self::updateSchedule($versionCode);
}
return $task;
}
public static function updateSchedule($versionCode)
{
$version = ProjectVersion::where(['code' => $versionCode])->find();
$taskList = Task::where(['version_code' => $versionCode, 'deleted' => 0])->field('id', true)->select();
$doneTotal = 0;
if ($taskList) {
foreach ($taskList as $task) {
if ($task['done']) {
$doneTotal++;
}
}
$schedule = intval($doneTotal / count($taskList) * 100);
$version->schedule = $schedule;
$version->save();
}
}
public function getStatusTextAttr($value, $data) public function getStatusTextAttr($value, $data)
{ {
//状态。0未开始1进行中2延期发布3已发布 //状态。0未开始1进行中2延期发布3已发布

View File

@ -12,6 +12,7 @@ namespace app\project\behavior;
use app\common\Model\CommonModel; use app\common\Model\CommonModel;
use app\common\Model\Member; use app\common\Model\Member;
use app\common\Model\ProjectLog; use app\common\Model\ProjectLog;
use app\common\Model\ProjectVersion;
use app\common\Model\TaskMember; use app\common\Model\TaskMember;
use app\common\Model\TaskStages; use app\common\Model\TaskStages;
use service\MessageService; use service\MessageService;
@ -68,10 +69,16 @@ class Task
case 'done': case 'done':
$icon = 'check'; $icon = 'check';
$remark = '完成了任务 '; $remark = '完成了任务 ';
if ($task['version_code']) {
ProjectVersion::updateSchedule($task['version_code']);
}
break; break;
case 'redo': case 'redo':
$icon = 'border'; $icon = 'border';
$remark = '重做了任务 '; $remark = '重做了任务 ';
if ($task['version_code']) {
ProjectVersion::updateSchedule($task['version_code']);
}
break; break;
case 'createChild': case 'createChild':
$icon = 'bars'; $icon = 'bars';

View File

@ -34,7 +34,7 @@ class Version
*/ */
public function run($data) public function run($data)
{ {
Log::init(['path' => 'log/task']); Log::init(['path' => 'log/version']);
$logData = ['member_code' => $data['memberCode'], 'source_code' => $data['versionCode'], 'remark' => $data['remark'], 'type' => $data['type'], 'content' => $data['content'], 'create_time' => nowTime(), 'code' => createUniqueCode('projectVersionLog')]; $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(); $version = ProjectVersion::where(['code' => $data['versionCode']])->find();
$logData['features_code'] = $version['features_code']; $logData['features_code'] = $version['features_code'];
@ -88,16 +88,16 @@ class Version
$icon = 'delete'; $icon = 'delete';
$remark = '删除了版本 '; $remark = '删除了版本 ';
break; break;
case 'linkFile': case 'addVersionTask':
$count = count($data['data']);
$icon = 'link'; $icon = 'link';
$remark = ' 添加了 2 项发布内容 '; $remark = "添加了 $count 项发布内容 ";
$content = "<a target=\"_blank\" class=\"muted\" href=\"{$data['data']['url']} \">{$data['data']['title']}</a>"; $content = implode('', $data['data']);
break; break;
case 'unlinkFile': case 'removeVersionTask':
$icon = 'disconnect'; $icon = 'disconnect';
$remark = '移除了发布内容'; $remark = '移除了发布内容';
$content = "<a target=\"_blank\" class=\"muted\" href=\"{$data['data']['url']} \">{$data['data']['title']}</a>"; $content = $data['data'];
break; break;
default: default:
$icon = 'plus'; $icon = 'plus';

View File

@ -151,14 +151,15 @@ class ProjectVersion extends BasicApi
$code = Request::post('versionCode'); $code = Request::post('versionCode');
$version = $this->model->where(['code' => $code])->field('id', true)->find(); $version = $this->model->where(['code' => $code])->field('id', true)->find();
if ($version) { if ($version) {
$version['featureName'] = \app\common\Model\ProjectFeatures::where(['code' => $version['features_code']])->find(); $feature = \app\common\Model\ProjectFeatures::where(['code' => $version['features_code']])->find();
$version['featureName'] && $version['featureName'] = $version['featureName']['name']; $feature && $version['featureName'] = $feature['name'];
$version['projectCode'] = $feature['project_code'];
} }
$this->success('', $version); $this->success('', $version);
} }
/** /**
* 关联任务 * 关联任务列表
* @throws DataNotFoundException * @throws DataNotFoundException
* @throws DbException * @throws DbException
* @throws ModelNotFoundException * @throws ModelNotFoundException
@ -166,28 +167,62 @@ class ProjectVersion extends BasicApi
public function _getVersionTask() public function _getVersionTask()
{ {
$code = Request::post('versionCode'); $code = Request::post('versionCode');
$taskList = \app\common\Model\Task::where(['version_code' => $code, 'deleted' => 0])->field('id', true)->select(); $taskList = \app\common\Model\Task::where(['version_code' => $code, 'deleted' => 0])->order('id desc')->field('id', true)->select();
if ($taskList) {
foreach ($taskList as &$task) {
$task['executor'] = Member::where(['code' => $task['assign_to']])->field('name,avatar')->find();
}
}
$this->success('', $taskList); $this->success('', $taskList);
} }
/** /**
* 关联任务
*/
public function addVersionTask()
{
$taskCodeList = Request::post('taskCodeList');
$versionCode = Request::post('versionCode');
$taskCodeList && $taskCodeList = json_decode($taskCodeList);
$successTotal = 0;
$successTaskList = [];
if ($taskCodeList) {
foreach ($taskCodeList as $taskCode) {
$result = $this->model->addVersionTask($taskCode, $versionCode);
if (!isError($result)) {
$successTotal++;
$successTaskList[] = $result['name'];
}
}
}
if ($successTotal) {
\app\common\Model\ProjectVersion::versionHook(getCurrentMember()['code'], $versionCode, 'addVersionTask', '', '', $successTaskList);
}
$this->success('', ['successTotal' => $successTotal]);
}
/**
* 移除发布内容
*/
public function removeVersionTask()
{
$taskCode = Request::post('taskCode');
$result = $this->model->removeVersionTask($taskCode);
if (isError($result)) {
$this->error($result['msg'], $result['errno']);
}
$this->success();
}
/**
* 版本日志
* @throws DataNotFoundException * @throws DataNotFoundException
* @throws DbException * @throws DbException
* @throws ModelNotFoundException * @throws ModelNotFoundException
*/ */
public function _getVersionLog() 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'); $code = Request::post('versionCode');
$showAll = Request::post('all', 0); $showAll = Request::post('all', 0);
$where = []; $where = [];