From 2f8975fdb280f0cfdab81ebb09c43362f93a9a27 Mon Sep 17 00:00:00 2001
From: vilson <545522390@qq.com>
Date: Fri, 12 Jul 2019 11:15:04 +0800
Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=89=B9=E9=87=8F=E5=AF=BC?=
=?UTF-8?q?=E5=85=A5=E4=BB=BB=E5=8A=A1?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: vilson <545522390@qq.com>
---
application/common/Model/Task.php | 252 +++++++++++++++++-------
application/project/controller/Task.php | 126 +++++++-----
extend/service/DateService.php | 42 +++-
3 files changed, 286 insertions(+), 134 deletions(-)
diff --git a/application/common/Model/Task.php b/application/common/Model/Task.php
index bedeb71..1652f81 100644
--- a/application/common/Model/Task.php
+++ b/application/common/Model/Task.php
@@ -2,8 +2,10 @@
namespace app\common\Model;
+use Exception;
use function GuzzleHttp\Promise\task;
use service\DateService;
+use service\RandomService;
use think\Db;
use think\db\exception\DataNotFoundException;
use think\db\exception\ModelNotFoundException;
@@ -22,11 +24,11 @@ class Task extends CommonModel
public function read($code)
{
if (!$code) {
- throw new \Exception('请选择任务', 1);
+ throw new Exception('请选择任务', 1);
}
$task = self::where(['code' => $code])->field('id', true)->find();
if (!$task) {
- throw new \Exception('该任务已失效', 404);
+ throw new Exception('该任务已失效', 404);
}
$project = Project::where(['code' => $task['project_code']])->field('name,open_begin_time')->find();
$stage = TaskStages::where(['code' => $task['stage_code']])->field('name')->find();
@@ -58,7 +60,7 @@ class Task extends CommonModel
/**
* @param $projectCode
* @param $deleted
- * @throws \think\exception\DbException
+ * @throws DbException
*/
public function listForProject($projectCode, $deleted)
{
@@ -86,11 +88,11 @@ class Task extends CommonModel
{
if (!$code) {
- throw new \Exception('请选择任务', 1);
+ throw new Exception('请选择任务', 1);
}
$task = self::where(['code' => $code, 'deleted' => 0])->field('id', true)->find();
if (!$task) {
- throw new \Exception('该任务在回收站中无法编辑', 1);
+ throw new Exception('该任务在回收站中无法编辑', 1);
}
if (isset($data['description']) && $data['description'] == '
') {
$data['description'] = "";
@@ -130,11 +132,11 @@ class Task extends CommonModel
public function taskSources($code)
{
if (!$code) {
- throw new \Exception('请选择任务', 1);
+ throw new Exception('请选择任务', 1);
}
$task = self::where(['code' => $code])->field('id', true)->find();
if (!$task) {
- throw new \Exception('该任务不存在', 2);
+ throw new Exception('该任务不存在', 2);
}
$sources = SourceLink::where(['link_code' => $code, 'link_type' => 'task'])->field('id', true)->order('id desc')->select()->toArray();
if ($sources) {
@@ -150,18 +152,18 @@ class Task extends CommonModel
* @param bool $like
* @return bool
* @throws \think\Exception
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
+ * @throws DataNotFoundException
+ * @throws ModelNotFoundException
+ * @throws DbException
*/
public function like($code, $like = true)
{
if (!$code) {
- throw new \Exception('请选择任务', 1);
+ throw new Exception('请选择任务', 1);
}
$task = self::where(['code' => $code, 'deleted' => 0])->field('id', true)->find();
if (!$task) {
- throw new \Exception('该任务在回收站中不能点赞', 1);
+ throw new Exception('该任务在回收站中不能点赞', 1);
}
if ($like) {
$result = self::where(['code' => $code])->setInc('like');
@@ -178,18 +180,18 @@ class Task extends CommonModel
* @param bool $star
* @return bool
* @throws \think\Exception
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
+ * @throws DataNotFoundException
+ * @throws ModelNotFoundException
+ * @throws DbException
*/
public function star($code, $star = true)
{
if (!$code) {
- throw new \Exception('请选择任务', 1);
+ throw new Exception('请选择任务', 1);
}
$task = self::where(['code' => $code, 'deleted' => 0])->field('id', true)->find();
if (!$task) {
- throw new \Exception('该任务在回收站中不能收藏', 1);
+ throw new Exception('该任务在回收站中不能收藏', 1);
}
if ($star) {
$result = self::where(['code' => $code])->setInc('star');
@@ -209,40 +211,43 @@ class Task extends CommonModel
* @param $memberCode
* @param string $assignTo
* @param string $parentCode
+ * @param string $pri
+ * @param string $description
+ * @param array $tagCodes
* @return Task
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
+ * @throws DataNotFoundException
+ * @throws DbException
+ * @throws ModelNotFoundException
*/
- public function createTask($stageCode, $projectCode, $name, $memberCode, $assignTo = '', $parentCode = '')
+ public function createTask($stageCode, $projectCode, $name, $memberCode, $assignTo = '', $parentCode = '', $pri = '', $description = '', $tagCodes = [], $beginTime = '', $endTime = '')
{
if (!$name) {
- throw new \Exception('请填写任务标题', 1);
+ return error(1, '请填写任务标题');
}
$stage = TaskStages::where(['code' => $stageCode])->field('id')->find();
if (!$stage) {
- throw new \Exception('该任务列表无效', 2);
+ return error(2, '该任务列表无效');
}
$project = Project::where(['code' => $projectCode, 'deleted' => 0])->field('id,open_task_private')->find();
if (!$project) {
- throw new \Exception('该项目已失效', 3);
+ return error(3, '该项目已失效');
}
if ($parentCode) {
$parentTask = self::where(['code' => $parentCode])->find();
if (!$parentTask) {
- throw new \Exception('父任务无效', 5);
+ return error(5, '父任务无效');
}
if ($parentTask['deleted']) {
- throw new \Exception('父任务在回收站中无法编辑', 6);
+ return error(6, '父任务在回收站中无法编辑');
}
if ($parentTask['done']) {
- throw new \Exception('父任务已完成,无法添加新的子任务', 7);
+ return error(7, '父任务已完成,无法添加新的子任务');
}
}
if ($assignTo) {
$assignMember = Member::where(['code' => $assignTo])->field('id')->find();
if (!$assignMember) {
- throw new \Exception('任务执行人有误', 4);
+ return error(4, '任务执行人有误');
}
}
@@ -272,6 +277,10 @@ class Task extends CommonModel
'pcode' => $parentCode,
'path' => $path,
'stage_code' => $stageCode,
+ 'pri' => $pri,
+ 'description' => $description,
+ 'begin_time' => $beginTime,
+ 'end_time' => $endTime,
'private' => $project['open_task_private'] ? 1 : 0,
'name' => trim($taskTitle),
];
@@ -294,13 +303,19 @@ class Task extends CommonModel
if (!$assignTo || !$isExecutor) {
TaskMember::inviteMember($memberCode, $data['code'], 0, 1);
}
+ if ($tagCodes) {
+ foreach ($tagCodes as $tagCode) {
+ TaskTag::setTag($tagCode, $data['code']);
+ }
+ }
}
+
//todo 添加任务动态
Db::commit();
- } catch (\Exception $e) {
+ } catch (Exception $e) {
Db::rollback();
- throw new \Exception($e->getMessage());
+ return error(9, $e->getMessage());
}
return $this->read($result['code']);
}
@@ -308,20 +323,20 @@ class Task extends CommonModel
public function taskDone($taskCode, $done)
{
if (!$taskCode) {
- throw new \Exception('请选择任务', 1);
+ throw new Exception('请选择任务', 1);
}
$task = self::where(['code' => $taskCode])->find();
if (!$task) {
- throw new \Exception('任务已失效', 2);
+ throw new Exception('任务已失效', 2);
}
if ($task['deleted']) {
- throw new \Exception('任务在回收站中无法进行编辑', 3);
+ throw new Exception('任务在回收站中无法进行编辑', 3);
}
if ($task['pcode'] && $task['parentDone']) {
- throw new \Exception('父任务已完成,无法重做子任务', 4);
+ throw new Exception('父任务已完成,无法重做子任务', 4);
}
if ($task['hasUnDone']) {
- throw new \Exception('子任务尚未全部完成,无法完成父任务', 5);
+ throw new Exception('子任务尚未全部完成,无法完成父任务', 5);
}
Db::startTrans();
@@ -329,9 +344,9 @@ class Task extends CommonModel
$result = self::update(['done' => $done], ['code' => $taskCode]);
//todo 添加任务动态,编辑权限检测
Db::commit();
- } catch (\Exception $e) {
+ } catch (Exception $e) {
Db::rollback();
- throw new \Exception($e->getMessage());
+ throw new Exception($e->getMessage());
}
$member = getCurrentMember();
$done ? $type = 'done' : $type = 'redo';
@@ -348,30 +363,30 @@ class Task extends CommonModel
* @param $taskCode
* @param $executorCode
* @return TaskMember|bool
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
+ * @throws DataNotFoundException
+ * @throws ModelNotFoundException
+ * @throws DbException
*/
public function assignTask($taskCode, $executorCode)
{
if (!$taskCode) {
- throw new \Exception('请选择任务', 1);
+ throw new Exception('请选择任务', 1);
}
$task = self::where(['code' => $taskCode])->find();
if (!$task) {
- throw new \Exception('任务已失效', 2);
+ throw new Exception('任务已失效', 2);
}
if ($task['deleted']) {
- throw new \Exception('任务在回收站中无法进行指派', 3);
+ throw new Exception('任务在回收站中无法进行指派', 3);
}
Db::startTrans();
try {
$result = TaskMember::inviteMember($executorCode, $taskCode, 1);
//todo 添加任务动态,编辑权限检测
Db::commit();
- } catch (\Exception $e) {
+ } catch (Exception $e) {
Db::rollback();
- throw new \Exception($e->getMessage());
+ throw new Exception($e->getMessage());
}
return $result;
}
@@ -383,7 +398,7 @@ class Task extends CommonModel
foreach ($taskCodes as $taskCode) {
$this->assignTask($taskCode, $executorCode);
}
- } catch (\Exception $e) {
+ } catch (Exception $e) {
return error(201, $e->getMessage());
}
}
@@ -394,18 +409,18 @@ class Task extends CommonModel
* @param $taskCode
* @param $comment
* @return ProjectLog
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
+ * @throws DataNotFoundException
+ * @throws ModelNotFoundException
+ * @throws DbException
*/
public function createComment($taskCode, $comment)
{
if (!$taskCode) {
- throw new \Exception('请选择任务', 1);
+ throw new Exception('请选择任务', 1);
}
$task = self::where(['code' => $taskCode])->find();
if (!$task) {
- throw new \Exception('任务已失效', 2);
+ throw new Exception('任务已失效', 2);
}
$data = [
'member_code' => getCurrentMember()['code'],
@@ -471,19 +486,114 @@ class Task extends CommonModel
return ['list' => $list, 'total' => $total];
}
+
+ /**
+ * 导入成员
+ * @param \think\File $file
+ * @return bool
+ * @throws Exception
+ */
+ public function uploadFile(\think\File $file, $projectCode, $memberCode)
+ {
+ try {
+ $data = importExcel($file->getInfo()['tmp_name']);
+ } catch (Exception $e) {
+ return error('201', $e->getMessage());
+ }
+ $count = 0;
+ if ($data) {
+ foreach ($data as $key => $item) {
+ if ($key > 2) {
+ $name = trim($item['A']);
+ $pTaskName = trim($item['B']);
+ $taskStageName = trim($item['C']);
+ $executorName = trim($item['D']);
+ $beginTime = trim($item['E']);
+ $endTime = trim($item['F']);
+ $description = trim($item['G']);
+ $priName = trim($item['H']);
+ $tagNameList = trim($item['I']);
+
+ if (!$name || !$taskStageName) {
+ continue;
+ }
+ $taskStage = TaskStages::where(['name' => $taskStageName, 'project_code' => $projectCode])->field('code')->find();
+ if (!$taskStage) {
+ continue;
+ }
+ $taskStageCode = $taskStage['code'];
+
+ switch ($priName) {
+ case '紧急':
+ $pri = 1;
+ break;
+ case '非常紧急':
+ $pri = 2;
+ break;
+ default:
+ $pri = 0;
+ }
+
+ $tagCodes = [];
+ if ($tagNameList) {
+ $tagNameList = explode(';', $tagNameList);
+ foreach ($tagNameList as $tagName) {
+ $tag = TaskTag::where(['name' => $tagName, 'project_code' => $projectCode])->field('code')->find();
+ if ($tag) {
+ $tagCodes[] = $tag['code'];
+ }
+ }
+ }
+
+ if ($pTaskName) {
+ if (!isset($parentCode) || !$parentCode) {
+ $pTask = self::where(['name' => $pTaskName, 'project_code' => $projectCode])->field('code')->order('id desc')->find();
+ if ($pTask) {
+ $parentCode = $pTask['code'];
+ } else {
+ $parentCode = '';
+ }
+ }
+ } else {
+ $parentCode = '';
+ }
+
+ $executorCode = '';
+ if ($executorName) {
+ $prefix = config('database.prefix');
+ $sql = "select m.code as code from {$prefix}project_member as pm join {$prefix}member as m on pm.member_code = m.code where m.name = '{$executorName}'";
+ $executor = Db::query($sql);
+ if ($executor) {
+ $executorCode = $executor[0]['code'];
+ }
+ }
+
+ $beginTime = DateService::checkDateIsValid($beginTime) ? $beginTime : '';
+ $endTime = DateService::checkDateIsValid($endTime) ? $endTime : '';
+ $task = $this->createTask($taskStageCode, $projectCode, $name, $memberCode, $executorCode, $parentCode, $pri, $description, $tagCodes, $beginTime, $endTime);
+ if ($task) {
+ $count++;
+ }
+ }
+
+ }
+ }
+ return $count;
+ }
+
/**
* 批量放入回收站
* @param $stageCode
* @return Task
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
+ * @throws DataNotFoundException
+ * @throws ModelNotFoundException
+ * @throws DbException
*/
public function recycleBatch($stageCode)
{
$stage = TaskStages::where(['code' => $stageCode])->find();
if (!$stage) {
- throw new \Exception('任务列表不存在', 1);
+ throw new Exception('任务列表不存在', 1);
}
$where = ['stage_code' => $stageCode, 'deleted' => 0];
$taskCodes = self::where($where)->column('code');
@@ -501,18 +611,18 @@ class Task extends CommonModel
* 放入回收站
* @param $code
* @return Project
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
+ * @throws DataNotFoundException
+ * @throws ModelNotFoundException
+ * @throws DbException
*/
public function recycle($code)
{
$info = self::where(['code' => $code])->find();
if (!$info) {
- throw new \Exception('任务不存在', 1);
+ throw new Exception('任务不存在', 1);
}
if ($info['deleted']) {
- throw new \Exception('任务已在回收站', 2);
+ throw new Exception('任务已在回收站', 2);
}
$result = self::update(['deleted' => 1, 'deleted_time' => nowTime()], ['code' => $code]);
self::taskHook(getCurrentMember()['code'], $code, 'recycle');
@@ -523,18 +633,18 @@ class Task extends CommonModel
* 恢复任务
* @param $code
* @return Project
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
+ * @throws DataNotFoundException
+ * @throws ModelNotFoundException
+ * @throws DbException
*/
public function recovery($code)
{
$info = self::where(['code' => $code])->find();
if (!$info) {
- throw new \Exception('任务不存在', 1);
+ throw new Exception('任务不存在', 1);
}
if (!$info['deleted']) {
- throw new \Exception('任务已恢复', 2);
+ throw new Exception('任务已恢复', 2);
}
$result = self::update(['deleted' => 0], ['code' => $code]);
self::taskHook(getCurrentMember()['code'], $code, 'recovery');
@@ -546,7 +656,7 @@ class Task extends CommonModel
//权限判断
$info = self::where(['code' => $code])->find();
if (!$info) {
- throw new \Exception('任务不存在', 1);
+ throw new Exception('任务不存在', 1);
}
Db::startTrans();
try {
@@ -556,9 +666,9 @@ class Task extends CommonModel
TaskLike::where(['task_code' => $code])->delete();
ProjectLog::where(['source_code' => $code, 'action_type' => 'task'])->delete();
Db::commit();
- } catch (\Exception $e) {
+ } catch (Exception $e) {
Db::rollback();
- throw new \Exception($e->getMessage());
+ throw new Exception($e->getMessage());
}
return true;
}
@@ -653,9 +763,9 @@ class Task extends CommonModel
* @param $value
* @param $data
* @return bool
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
+ * @throws DataNotFoundException
+ * @throws ModelNotFoundException
+ * @throws DbException
*/
public function getCanReadAttr($value, $data)
{
diff --git a/application/project/controller/Task.php b/application/project/controller/Task.php
index c2cf7e2..5deba29 100644
--- a/application/project/controller/Task.php
+++ b/application/project/controller/Task.php
@@ -8,6 +8,10 @@ use app\common\Model\ProjectLog;
use app\common\Model\TaskTag;
use app\common\Model\TaskToTag;
use controller\BasicApi;
+use Exception;
+use think\db\exception\DataNotFoundException;
+use think\db\exception\ModelNotFoundException;
+use think\exception\DbException;
use think\facade\Request;
/**
@@ -25,7 +29,7 @@ class Task extends BasicApi
/**
* 显示资源列表
* @return void
- * @throws \think\exception\DbException
+ * @throws DbException
*/
public function index()
{
@@ -66,9 +70,9 @@ class Task extends BasicApi
/**
* 获取自己的任务
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
+ * @throws DataNotFoundException
+ * @throws ModelNotFoundException
+ * @throws DbException
*/
public function selfList()
{
@@ -99,7 +103,7 @@ class Task extends BasicApi
$code = Request::post('taskCode');
try {
$list = $this->model->taskSources($code);
- } catch (\Exception $e) {
+ } catch (Exception $e) {
$this->error($e->getMessage());
}
$this->success('', $list);
@@ -131,7 +135,7 @@ class Task extends BasicApi
$data = $request::only('taskCode');
try {
$result = $this->model->read($data['taskCode']);
- } catch (\Exception $e) {
+ } catch (Exception $e) {
$this->error($e->getMessage(), $e->getCode());
}
if ($result) {
@@ -141,8 +145,6 @@ class Task extends BasicApi
/**
* 新增
- * @param Request $request
- * @return void
*/
public function save(Request $request)
{
@@ -156,27 +158,23 @@ class Task extends BasicApi
if (!$request::post('name')) {
$this->error("请填写任务标题");
}
- try {
- $member = getCurrentMember();
- if ($data['pcode']) {
- $parentTask = $this->model->where(['code' => $data['pcode']])->find();
- if (!$parentTask) {
- throw new \Exception('父任务无效', 5);
- }
- if ($parentTask['deleted']) {
- throw new \Exception('父任务在回收站中无法编辑', 6);
- }
- $data['project_code'] = $parentTask['project_code'];
- $data['stage_code'] = $parentTask['stage_code'];
+ $member = getCurrentMember();
+ if ($data['pcode']) {
+ $parentTask = $this->model->where(['code' => $data['pcode']])->find();
+ if (!$parentTask) {
+ $this->error('父任务无效', 5);
}
- $result = $this->model->createTask($data['stage_code'], $data['project_code'], $data['name'], $member['code'], $data['assign_to'], $data['pcode']);
- } catch (\Exception $e) {
- $this->error($e->getMessage(), $e->getCode());;
+ if ($parentTask['deleted']) {
+ $this->error('父任务在回收站中无法编辑', 6);
+ }
+ $data['project_code'] = $parentTask['project_code'];
+ $data['stage_code'] = $parentTask['stage_code'];
}
- if ($result) {
+ $result = $this->model->createTask($data['stage_code'], $data['project_code'], $data['name'], $member['code'], $data['assign_to'], $data['pcode']);
+ if (!isError($result)) {
$this->success('', $result);
}
- $this->error("操作失败,请稍候再试!");
+ $this->error($result['msg']);
}
/**
@@ -191,7 +189,7 @@ class Task extends BasicApi
}
try {
$result = $this->model->taskDone($data['taskCode'], $data['done']);
- } catch (\Exception $e) {
+ } catch (Exception $e) {
$this->error($e->getMessage(), $e->getCode());;
}
if ($result) {
@@ -212,7 +210,7 @@ class Task extends BasicApi
}
try {
$result = $this->model->assignTask($data['taskCode'], $data['executorCode']);
- } catch (\Exception $e) {
+ } catch (Exception $e) {
$this->error($e->getMessage(), $e->getCode());;
}
if ($result) {
@@ -252,7 +250,7 @@ class Task extends BasicApi
}
try {
$this->model->sort($data['stageCode'], explode(',', $data['codes']));
- } catch (\Exception $e) {
+ } catch (Exception $e) {
$this->error($e->getMessage(), $e->getCode());;
}
$this->success();
@@ -270,7 +268,7 @@ class Task extends BasicApi
}
try {
$result = $this->model->createComment($data['taskCode'], $data['comment']);
- } catch (\Exception $e) {
+ } catch (Exception $e) {
$this->error($e->getMessage(), $e->getCode());;
}
if ($result) {
@@ -283,9 +281,9 @@ class Task extends BasicApi
* 保存
* @param Request $request
* @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
+ * @throws DataNotFoundException
+ * @throws ModelNotFoundException
+ * @throws DbException
*/
public function edit(Request $request)
{
@@ -300,7 +298,7 @@ class Task extends BasicApi
}
try {
$result = $this->model->edit($code, $data);
- } catch (\Exception $e) {
+ } catch (Exception $e) {
$this->error($e->getMessage(), $e->getCode());;
}
@@ -313,7 +311,7 @@ class Task extends BasicApi
/**
* 设置隐私模式
* @param Request $request
- * @throws \Exception
+ * @throws Exception
*/
public function setPrivate(Request $request)
{
@@ -333,9 +331,9 @@ class Task extends BasicApi
* 点赞
* @param Request $request
* @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
+ * @throws DataNotFoundException
+ * @throws ModelNotFoundException
+ * @throws DbException
*/
public function like(Request $request)
{
@@ -350,7 +348,7 @@ class Task extends BasicApi
}
try {
$result = $this->model->like($code, $data['like']);
- } catch (\Exception $e) {
+ } catch (Exception $e) {
$this->error($e->getMessage(), $e->getCode());;
}
@@ -363,9 +361,9 @@ class Task extends BasicApi
/**
* 任务标签列表
* @param Request $request
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
+ * @throws DataNotFoundException
+ * @throws ModelNotFoundException
+ * @throws DbException
*/
public function taskToTags(Request $request)
{
@@ -377,9 +375,9 @@ class Task extends BasicApi
/**
* 设置标签
* @param Request $request
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
+ * @throws DataNotFoundException
+ * @throws ModelNotFoundException
+ * @throws DbException
*/
public function setTag(Request $request)
{
@@ -399,9 +397,9 @@ class Task extends BasicApi
* 收藏
* @param Request $request
* @return void
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
+ * @throws DataNotFoundException
+ * @throws ModelNotFoundException
+ * @throws DbException
*/
public function star(Request $request)
{
@@ -416,7 +414,7 @@ class Task extends BasicApi
}
try {
$result = $this->model->star($code, $data['star']);
- } catch (\Exception $e) {
+ } catch (Exception $e) {
$this->error($e->getMessage(), $e->getCode());;
}
@@ -427,7 +425,7 @@ class Task extends BasicApi
}
/**
- * @throws \think\exception\DbException
+ * @throws DbException
*/
public function taskLog()
{
@@ -465,6 +463,28 @@ class Task extends BasicApi
$this->success('', $list);
}
+
+ /**
+ * 下载导入任务模板
+ */
+ public function _downloadTemplate()
+ {
+ return download(env('root_path') . 'data/template/importTask.xlsx', '批量导入任务模板.xlsx');
+ }
+
+ /**
+ * 上传文件
+ */
+ public function uploadFile()
+ {
+ $projectCode = Request::param('projectCode');
+ $count = $this->model->uploadFile(Request::file('file'), $projectCode,getCurrentMember()['code']);
+ if (isError($count)) {
+ $this->error($count['msg']);
+ }
+ $this->success('', $count);
+ }
+
/**
* 批量放入回收站
*/
@@ -472,7 +492,7 @@ class Task extends BasicApi
{
try {
$this->model->recycleBatch(Request::post('stageCode'));
- } catch (\Exception $e) {
+ } catch (Exception $e) {
$this->error($e->getMessage(), $e->getCode());;
}
$this->success('');
@@ -485,7 +505,7 @@ class Task extends BasicApi
{
try {
$this->model->recycle(Request::post('taskCode'));
- } catch (\Exception $e) {
+ } catch (Exception $e) {
$this->error($e->getMessage(), $e->getCode());;
}
$this->success('');
@@ -498,7 +518,7 @@ class Task extends BasicApi
{
try {
$this->model->recovery(Request::post('taskCode'));
- } catch (\Exception $e) {
+ } catch (Exception $e) {
$this->error($e->getMessage(), $e->getCode());;
}
$this->success('');
@@ -511,7 +531,7 @@ class Task extends BasicApi
{
try {
$this->model->del(Request::post('taskCode'));
- } catch (\Exception $e) {
+ } catch (Exception $e) {
$this->error($e->getMessage(), $e->getCode());;
}
$this->success('');
diff --git a/extend/service/DateService.php b/extend/service/DateService.php
index 9eac23d..e859458 100644
--- a/extend/service/DateService.php
+++ b/extend/service/DateService.php
@@ -23,9 +23,9 @@ class DateService
* [!!] A list of time zones that PHP supports can be found at
* .
*
- * @param string $remote timezone that to find the offset of
- * @param string $local timezone used as the baseline
- * @param mixed $now UNIX timestamp or date string
+ * @param string $remote timezone that to find the offset of
+ * @param string $local timezone used as the baseline
+ * @param mixed $now UNIX timestamp or date string
* @return integer
*/
public static function offset($remote, $local = NULL, $now = NULL)
@@ -55,9 +55,9 @@ class DateService
* $span = self::span(60, 182, 'minutes,seconds'); // array('minutes' => 2, 'seconds' => 2)
* $span = self::span(60, 182, 'minutes'); // 2
*
- * @param int $remote timestamp to find the span of
- * @param int $local timestamp to use as the baseline
- * @param string $output formatting string
+ * @param int $remote timestamp to find the span of
+ * @param int $local timestamp to use as the baseline
+ * @param string $output formatting string
* @return string when only a single output is requested
* @return array associative list of all outputs requested
* @from https://github.com/kohana/ohanzee-helpers/blob/master/src/Date.php
@@ -115,8 +115,8 @@ class DateService
/**
* 格式化 UNIX 时间戳为人易读的字符串
*
- * @param int Unix 时间戳
- * @param mixed $local 本地时间
+ * @param int Unix 时间戳
+ * @param mixed $local 本地时间
*
* @return string 格式化的日期字符串
*/
@@ -200,8 +200,8 @@ class DateService
/**
* 获取指定日期段内每一天的日期
- * @param string $startDate 开始日期
- * @param string $endDate 结束日期
+ * @param string $startDate 开始日期
+ * @param string $endDate 结束日期
* @return array
*/
public static function getDateFromRange($startDate, $endDate)
@@ -241,5 +241,27 @@ class DateService
return $mondays;
}
+ /**
+ * 校验日期格式是否正确
+ *
+ * @param string $date 日期
+ * @param string $formats 需要检验的格式数组
+ * @return boolean
+ */
+ public static function checkDateIsValid($date, $formats = array("Y-m-d H:i", "Y-m-d H:i:s"))
+ {
+ $unixTime = strtotime($date);
+ if (!$unixTime) { //strtotime转换不对,日期格式显然不对。
+ return false;
+ }
+ //校验日期的有效性,只要满足其中一个格式就OK
+ foreach ($formats as $format) {
+ if (date($format, $unixTime) == $date) {
+ return true;
+ }
+ }
+
+ return false;
+ }
}