From 9a554244cbc509c3a870b8c179c49b5a51f6f5b6 Mon Sep 17 00:00:00 2001 From: vilson <545522390@qq.com> Date: Sat, 16 Feb 2019 12:18:11 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BB=BB=E5=8A=A1=E6=A0=87?= =?UTF-8?q?=E7=AD=BE?= 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 | 13 +- application/common/Model/TaskLike.php | 2 + application/common/Model/TaskTag.php | 86 ++++++++++++ application/common/Model/TaskToTag.php | 18 +++ application/project/controller/Task.php | 53 ++++++-- application/project/controller/TaskStages.php | 13 -- application/project/controller/TaskTag.php | 104 +++++++++++++++ .../project/controller/project/Index.php | 125 ------------------ config/jwt.php | 2 +- 9 files changed, 264 insertions(+), 152 deletions(-) create mode 100644 application/common/Model/TaskTag.php create mode 100644 application/common/Model/TaskToTag.php create mode 100644 application/project/controller/TaskTag.php delete mode 100644 application/project/controller/project/Index.php diff --git a/application/common/Model/Task.php b/application/common/Model/Task.php index 3db3b40..3a40e7c 100644 --- a/application/common/Model/Task.php +++ b/application/common/Model/Task.php @@ -17,7 +17,7 @@ use think\facade\Hook; */ class Task extends CommonModel { - protected $append = ['priText', 'liked', 'stared', 'childCount', 'hasUnDone', 'parentDone', 'hasComment', 'hasSource', 'canRead']; + protected $append = ['priText', 'liked', 'stared', 'tags', 'childCount', 'hasUnDone', 'parentDone', 'hasComment', 'hasSource', 'canRead']; public function read($code) { @@ -556,6 +556,17 @@ class Task extends CommonModel return $status[$data['pri']]; } + /** + * 标签 + */ + public function getTagsAttr($value, $data) + { + $tags = []; + if (isset($data['code'])) { + $tags = TaskToTag::where(['task_code' => $data['code']])->field('id', true)->order('id asc')->select()->toArray(); + } + return $tags; + } /** * 子任务数 */ diff --git a/application/common/Model/TaskLike.php b/application/common/Model/TaskLike.php index 34ca30b..8ce1667 100644 --- a/application/common/Model/TaskLike.php +++ b/application/common/Model/TaskLike.php @@ -16,9 +16,11 @@ class TaskLike extends CommonModel * @param $memberCode * @param $like * @return TaskLike|bool + * @throws \think\Exception * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException + * @throws \think\exception\PDOException */ public static function likeTask($code, $memberCode, $like) { diff --git a/application/common/Model/TaskTag.php b/application/common/Model/TaskTag.php new file mode 100644 index 0000000..4da259e --- /dev/null +++ b/application/common/Model/TaskTag.php @@ -0,0 +1,86 @@ + $projectCode, 'deleted' => 0])->field('id')->find(); + if (!$project) { + return error(3, '该项目已失效'); + } + $tag = self::where(['name' => $name, 'project_code' => $projectCode])->find(); + if ($tag) { + return error(2, '该标签已存在'); + } + $data = [ + 'create_time' => nowTime(), + 'code' => createUniqueCode('taskTag'), + 'project_code' => $projectCode, + 'color' => $color, + 'name' => trim($name), + ]; + $result = self::create($data)->toArray(); + return $result; + } + + /** + * 删除标签 + * @param $tagCode + * @return array|bool + * @throws \think\Exception + * @throws \think\exception\PDOException + */ + public function deleteTag($tagCode) + { + if (!$tagCode) { + return error(1, '请选择一个标签'); + } + self::where(['code' => $tagCode])->delete(); + TaskToTag::where(['tag_code' => $tagCode])->delete(); + return true; + } + + /** + * 设置标签 + * @param $tagCode + * @param $taskCode + * @return TaskToTag|bool + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\ModelNotFoundException + * @throws \think\exception\DbException + */ + public static function setTag($tagCode, $taskCode) + { + $data = ['tag_code' => $tagCode, 'task_code' => $taskCode]; + $taskToTag = TaskToTag::where($data)->find(); + if ($taskToTag) { + return $taskToTag->delete($data); + } else { + $data['create_time'] = nowTime(); + $data['code'] = createUniqueCode('taskToTag'); + return TaskToTag::create($data); + } + } +} diff --git a/application/common/Model/TaskToTag.php b/application/common/Model/TaskToTag.php new file mode 100644 index 0000000..4684190 --- /dev/null +++ b/application/common/Model/TaskToTag.php @@ -0,0 +1,18 @@ +belongsTo('taskTag', 'tag_code', 'code'); + } +} diff --git a/application/project/controller/Task.php b/application/project/controller/Task.php index d8ba322..af03481 100644 --- a/application/project/controller/Task.php +++ b/application/project/controller/Task.php @@ -3,21 +3,11 @@ namespace app\project\controller; use app\common\Model\Member; -use app\common\Model\MemberAccount; -use app\common\Model\Notify; -use app\common\Model\ProjectCollection; use app\common\Model\ProjectLog; -use app\common\Model\ProjectMember; -use app\common\Model\SystemConfig; +use app\common\Model\TaskTag; +use app\common\Model\TaskToTag; use controller\BasicApi; -use OSS\Core\OssException; -use service\FileService; -use service\NodeService; -use service\RandomService; -use think\Exception; -use think\exception\PDOException; use think\facade\Request; -use think\File; /** */ @@ -247,6 +237,10 @@ class Task extends BasicApi $this->success(); } + /** + * 发表评论 + * @param Request $request + */ public function createComment(Request $request) { $data = $request::only('taskCode,comment'); @@ -345,6 +339,41 @@ class Task extends BasicApi $this->error("操作失败,请稍候再试!"); } + /** + * 任务标签列表 + * @param Request $request + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\ModelNotFoundException + * @throws \think\exception\DbException + */ + public function taskToTags(Request $request) + { + $taskCode = $request::param('taskCode'); + $tags = TaskToTag::where(['task_code' => $taskCode])->field('id', true)->select()->toArray(); + $this->success('', $tags); + } + + /** + * 设置标签 + * @param Request $request + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\ModelNotFoundException + * @throws \think\exception\DbException + */ + public function setTag(Request $request) + { + $tagCode = $request::param('tagCode'); + $taskCode = $request::param('taskCode'); + if (!$taskCode) { + $this->error("请选择一个任务"); + } + if (!$tagCode) { + $this->error("请选择一个标签"); + } + TaskTag::setTag($tagCode, $taskCode); + $this->success(); + } + /** * 收藏 * @param Request $request diff --git a/application/project/controller/TaskStages.php b/application/project/controller/TaskStages.php index 18d5454..52b4309 100644 --- a/application/project/controller/TaskStages.php +++ b/application/project/controller/TaskStages.php @@ -2,21 +2,8 @@ namespace app\project\controller; -use app\common\Model\Member; -use app\common\Model\MemberAccount; -use app\common\Model\Notify; -use app\common\Model\ProjectCollection; -use app\common\Model\ProjectMember; -use app\common\Model\SystemConfig; use controller\BasicApi; -use OSS\Core\OssException; -use service\FileService; -use service\NodeService; -use service\RandomService; -use think\Exception; -use think\exception\PDOException; use think\facade\Request; -use think\File; /** */ diff --git a/application/project/controller/TaskTag.php b/application/project/controller/TaskTag.php new file mode 100644 index 0000000..2e077d9 --- /dev/null +++ b/application/project/controller/TaskTag.php @@ -0,0 +1,104 @@ +model) { + $this->model = new \app\common\Model\TaskTag(); + } + } + + /** + * 显示资源标签 + * @return void + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\ModelNotFoundException + * @throws \think\exception\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('name asc')->select()->toArray(); + $this->success('', $list); + } + + /** + * 新增 + * @param Request $request + * @return void + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\ModelNotFoundException + * @throws \think\exception\DbException + */ + public function save(Request $request) + { + $data = $request::only('name,projectCode,color'); + if (!$request::post('name')) { + $this->error("请填写标签名称"); + } + $result = $this->model->createTag($data['name'], $data['color'], $data['projectCode']); + if (!isError($result)) { + $this->success('添加成功', $result); + } + $this->error($result['msg']); + } + + /** + * 保存 + * @param Request $request + * @return void + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\ModelNotFoundException + * @throws \think\exception\DbException + */ + public function edit(Request $request) + { + $data = $request::only('name,tagCode,color'); + if (!$request::post('name')) { + $this->error("请填写标签名称"); + } + if (!$data['tagCode']) { + $this->error("请选择一个标签"); + } + $tag = $this->model->where(['code' => $data['tagCode']])->field('id')->find(); + if (!$tag) { + $this->error("该标签已失效"); + } + $result = $this->model->_edit(['name' => $data['name'], 'color' => $data['color']], ['code' => $data['tagCode']]); + if ($result) { + $this->success(''); + } + $this->error("操作失败,请稍候再试!"); + } + + /** + * 删除标签 + * @return void + */ + public function delete() + { + $code = Request::post('tagCode'); + if (!$code) { + $this->error("请选择一个标签"); + } + $result = $this->model->deleteTag($code); + if (!isError($result)) { + $this->success(); + } + } +} diff --git a/application/project/controller/project/Index.php b/application/project/controller/project/Index.php deleted file mode 100644 index 7fdd724..0000000 --- a/application/project/controller/project/Index.php +++ /dev/null @@ -1,125 +0,0 @@ -model) { - $this->model = new \app\common\Model\Project(); - } - } - - /** - * 显示资源列表 - * - * @return void - * @throws \think\exception\DbException - */ - public function index() - { - $where = []; - $params = Request::post(); - foreach (['name'] as $key) { - (isset($params[$key]) && $params[$key] !== '') && $where[] = [$key, 'like', "%{$params[$key]}%"]; - } - foreach (['state'] as $key) { - (isset($params[$key]) && $params[$key] !== '') && $where[] = [$key, '=', $params['state']]; - } - if (isset($params['date']) && $params['date'] !== '') { - list($start, $end) = explode('~', $params['date']); - $where[] = ['regdate', 'between', ["{$start} 00:00:00", "{$end} 23:59:59"]]; - } - $list = $this->model->_list($where); - $result = ['list' => $list]; - $this->success('', $result); - - - } - - /** - * 新增 - * - * @param Request $request - * @return void - */ - public function save(Request $request) - { - $data = $request::only('name,address,lng,lat,phone,type_id,open_time,close_time,areas'); - - list($data['province'], $data['city'], $data['area']) = json_decode($data['areas']); - unset($data['areas']); - - $data['landlord_id'] = $this->session['landlord_id']; - $data['status'] = 0; - if (empty($data['landlord_id'])) { - $this->success('', ''); - } - $result = $this->model->_add($data); - if ($result) { - $this->success('', $result); - } - $this->error("操作失败,请稍候再试!"); - } - - /** - * 获取信息 - * - * @param Request $request - * @return void - * @throws \think\Exception\DbException - */ - public function read(Request $request) - { - $this->success('', $this->model->get($request::post('id'))); - } - - /** - * 保存 - * - * @param Request $request - * @return void - */ - public function edit(Request $request) - { - $data = $request::only('id,name,address,lng,lat,phone,type_id,open_time,close_time,areas'); - - list($data['province'], $data['city'], $data['area']) = json_decode($data['areas']); - unset($data['areas']); - - //编辑后重新审核 - $data['status'] = 0; - $result = $this->model->_edit($data); - if ($result) { - $this->success(''); - } - $this->error("操作失败,请稍候再试!"); - } - - /** - * 删除指定资源 - * - * @param int $id - * @return \think\Response - */ - public function delete($id = 0) - { - $this->model->destroy(Request::post('id')); - $this->success(''); - } - -} diff --git a/config/jwt.php b/config/jwt.php index d805ee8..1c00344 100644 --- a/config/jwt.php +++ b/config/jwt.php @@ -5,7 +5,7 @@ return [ 'key' => 'pearProject', 'alg' => 'HS256', //access_token有效时间 - 'accessTokenExp' => 3600, + 'accessTokenExp' => 3600 * 24 * 7, //refresh_token有效时间 'refreshTokenExp' => 3600 * 24 * 7, //签发者 可选