增加任务标签

Signed-off-by: vilson <545522390@qq.com>
This commit is contained in:
vilson 2019-02-16 12:18:11 +08:00
parent 6b9d34b21c
commit 9a554244cb
9 changed files with 264 additions and 152 deletions

View File

@ -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;
}
/**
* 子任务数
*/

View File

@ -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)
{

View File

@ -0,0 +1,86 @@
<?php
namespace app\common\Model;
/**
* 任务标签
* Class TaskTag
* @package app\common\Model
*/
class TaskTag extends CommonModel
{
protected $append = [];
/**
* 创建标签
* @param $name
* @param $color
* @param $projectCode
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function createTag($name, $color, $projectCode)
{
if (!$name) {
return error(1, '请填写标签名称');
}
$project = Project::where(['code' => $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);
}
}
}

View File

@ -0,0 +1,18 @@
<?php
namespace app\common\Model;
/**
* 任务标签映射
* Class TaskToTag
* @package app\common\Model
*/
class TaskToTag extends CommonModel
{
protected $append = ['tag'];
public function tag()
{
return $this->belongsTo('taskTag', 'tag_code', 'code');
}
}

View File

@ -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

View File

@ -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;
/**
*/

View File

@ -0,0 +1,104 @@
<?php
namespace app\project\controller;
use controller\BasicApi;
use think\facade\Request;
/**
*/
class TaskTag extends BasicApi
{
public function __construct()
{
parent::__construct();
if (!$this->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();
}
}
}

View File

@ -1,125 +0,0 @@
<?php
namespace app\project\controller\project;
use app\common\Model\Member;
use app\common\Model\MemberAccount;
use app\common\Model\Notify;
use app\common\Model\SystemConfig;
use controller\BasicApi;
use service\FileService;
use service\NodeService;
use think\facade\Request;
use think\File;
/**
*/
class Index extends BasicApi
{
public function __construct()
{
parent::__construct();
if (!$this->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('');
}
}

View File

@ -5,7 +5,7 @@ return [
'key' => 'pearProject',
'alg' => 'HS256',
//access_token有效时间
'accessTokenExp' => 3600,
'accessTokenExp' => 3600 * 24 * 7,
//refresh_token有效时间
'refreshTokenExp' => 3600 * 24 * 7,
//签发者 可选