From 5bb76088ce6b5026b01126c9776aab0a96808637 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Sat, 5 Aug 2023 16:14:43 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=BB=BB=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/task/TaskController.php | 118 +++++++++++ app/adminapi/lists/task/TaskLists.php | 83 ++++++++ app/adminapi/validate/task/TaskValidate.php | 94 +++++++++ app/api/controller/InformationController.php | 7 +- app/api/controller/TaskController.php | 25 +++ app/common/logic/task/TaskLogic.php | 133 ++++++++++++ app/common/model/task/Task.php | 51 +++++ app/common/model/user/Task.php | 194 ------------------ 8 files changed, 509 insertions(+), 196 deletions(-) create mode 100644 app/adminapi/controller/task/TaskController.php create mode 100644 app/adminapi/lists/task/TaskLists.php create mode 100644 app/adminapi/validate/task/TaskValidate.php create mode 100644 app/api/controller/TaskController.php create mode 100644 app/common/logic/task/TaskLogic.php create mode 100644 app/common/model/task/Task.php delete mode 100644 app/common/model/user/Task.php diff --git a/app/adminapi/controller/task/TaskController.php b/app/adminapi/controller/task/TaskController.php new file mode 100644 index 000000000..54de3571b --- /dev/null +++ b/app/adminapi/controller/task/TaskController.php @@ -0,0 +1,118 @@ +dataLists(new TaskLists()); + } + + + /** + * @notes 添加任务 + * @return \think\response\Json + * @author likeadmin + * @date 2023/08/05 13:39 + */ + public function add() + { + $params = (new TaskValidate())->post()->goCheck('add'); + + + if($params['type']==1){ + $arr=[42,43,44,45];//信息更新 + $params['extend']['informationg']['arr']=$arr; + $params['extend']['informationg']['arr_count']=count($arr); + $params['extend']['informationg']['update']=[]; + $params['extend']['informationg']['update_count']=0; + } + + $result = TaskLogic::add($params); + if (true === $result) { + return $this->success('添加成功', [], 1, 1); + } + return $this->fail(TaskLogic::getError()); + } + + + /** + * @notes 编辑任务 + * @return \think\response\Json + * @author likeadmin + * @date 2023/08/05 13:39 + */ + public function edit() + { + $params = (new TaskValidate())->post()->goCheck('edit'); + $result = TaskLogic::edit($params); + if (true === $result) { + return $this->success('编辑成功', [], 1, 1); + } + return $this->fail(TaskLogic::getError()); + } + + + /** + * @notes 删除任务 + * @return \think\response\Json + * @author likeadmin + * @date 2023/08/05 13:39 + */ + public function delete() + { + $params = (new TaskValidate())->post()->goCheck('delete'); + TaskLogic::delete($params); + return $this->success('删除成功', [], 1, 1); + } + + + /** + * @notes 获取任务详情 + * @return \think\response\Json + * @author likeadmin + * @date 2023/08/05 13:39 + */ + public function detail() + { + $params = (new TaskValidate())->goCheck('detail'); + $result = TaskLogic::detail($params); + return $this->data($result); + } + + +} \ No newline at end of file diff --git a/app/adminapi/lists/task/TaskLists.php b/app/adminapi/lists/task/TaskLists.php new file mode 100644 index 000000000..6e892f3c6 --- /dev/null +++ b/app/adminapi/lists/task/TaskLists.php @@ -0,0 +1,83 @@ + ['title', 'template_id', 'company_id', 'start_time', 'end_time', 'director_uid', 'type', 'status', 'content'], + ]; + } + + + /** + * @notes 获取任务列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author likeadmin + * @date 2023/08/05 13:39 + */ + public function lists(): array + { + if($this->adminInfo['root']==1){ + $where=[]; + }else{ + $where['company_id']=$this->adminInfo['company_id']; + } + return Task::where($this->searchWhere) + ->where($where) + ->field(['id', 'title', 'template_id', 'company_id', 'admin_id', 'start_time', 'end_time', 'director_uid', 'type', 'status', 'content']) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select() + ->toArray(); + } + + + /** + * @notes 获取任务数量 + * @return int + * @author likeadmin + * @date 2023/08/05 13:39 + */ + public function count(): int + { + return Task::where($this->searchWhere)->count(); + } + +} \ No newline at end of file diff --git a/app/adminapi/validate/task/TaskValidate.php b/app/adminapi/validate/task/TaskValidate.php new file mode 100644 index 000000000..9792421db --- /dev/null +++ b/app/adminapi/validate/task/TaskValidate.php @@ -0,0 +1,94 @@ + 'require', + ]; + + + /** + * 参数描述 + * @var string[] + */ + protected $field = [ + 'id' => 'id', + ]; + + + /** + * @notes 添加场景 + * @return TaskValidate + * @author likeadmin + * @date 2023/08/05 13:39 + */ + public function sceneAdd() + { + return $this->remove('id', true); + } + + + /** + * @notes 编辑场景 + * @return TaskValidate + * @author likeadmin + * @date 2023/08/05 13:39 + */ + public function sceneEdit() + { + return $this->only(['id']); + } + + + /** + * @notes 删除场景 + * @return TaskValidate + * @author likeadmin + * @date 2023/08/05 13:39 + */ + public function sceneDelete() + { + return $this->only(['id']); + } + + + /** + * @notes 详情场景 + * @return TaskValidate + * @author likeadmin + * @date 2023/08/05 13:39 + */ + public function sceneDetail() + { + return $this->only(['id']); + } + +} \ No newline at end of file diff --git a/app/api/controller/InformationController.php b/app/api/controller/InformationController.php index 5cef866e8..17faa5c16 100644 --- a/app/api/controller/InformationController.php +++ b/app/api/controller/InformationController.php @@ -13,9 +13,12 @@ class InformationController extends BaseApiController $param = Request()->param(); [$page, $limit] = $this->getPage(); if(isset($param['user_id'])&&$param['user_id']>0){ - $data['create_user_id'] = $param['user_id']; + $data[] = ['create_user_id','=',$param['user_id']]; }else{ - $data['company_id'] = $this->userInfo['company_id']; + $data[] = ['company_id','=',$this->userInfo['company_id']]; + } + if(isset($param['arr']) && count($param['arr'])>0){ + $data[] =['id','in', $param['arr']]; } $res = UserInformationg::list($data,$page,$limit); if ($res != true) { diff --git a/app/api/controller/TaskController.php b/app/api/controller/TaskController.php new file mode 100644 index 000000000..332a6bbb9 --- /dev/null +++ b/app/api/controller/TaskController.php @@ -0,0 +1,25 @@ +param(); + [$page, $limit] = $this->getPage(); + if($this->userInfo['admin_id']!=00){ + $where[]=['company_id','=',$this->userInfo['company_id']]; + }else{ + return $this->fail('你没有权限访问'); + } + $res=Task::where($where) + ->field(['id', 'title', 'template_id','director_uid', 'company_id', 'start_time', 'end_time', 'director_uid', 'type', 'status', 'content','extend']) + ->page($page,25) + ->order(['id' => 'desc']) + ->select() + ->toArray(); + return $this->success('ok', $res); + } +} \ No newline at end of file diff --git a/app/common/logic/task/TaskLogic.php b/app/common/logic/task/TaskLogic.php new file mode 100644 index 000000000..b6f45e184 --- /dev/null +++ b/app/common/logic/task/TaskLogic.php @@ -0,0 +1,133 @@ + $params['title'], + 'template_id' => $params['template_id'], + 'company_id' => $params['company_id'], + // 'admin_id' => $params['admin_id'], + 'start_time' => strtotime($params['start_time']), + 'end_time' =>strtotime($params['end_time']), + 'director_uid' => $params['director_uid'], + 'type' => $params['type'], + 'status' => $params['status'], + 'content' => $params['content'], + 'extend'=>json_encode($params['extend']) + ]); + + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + self::setError($e->getMessage()); + return false; + } + } + + + /** + * @notes 编辑任务 + * @param array $params + * @return bool + * @author likeadmin + * @date 2023/08/05 13:39 + */ + public static function edit(array $params): bool + { + Db::startTrans(); + try { + Task::where('id', $params['id'])->update([ + 'title' => $params['title'], + 'template_id' => $params['template_id'], + 'company_id' => $params['company_id'], + 'admin_id' => $params['admin_id'], + 'start_time' => $params['start_time'], + 'end_time' => $params['end_time'], + 'director_uid' => $params['director_uid'], + 'type' => $params['type'], + 'status' => $params['status'], + 'content' => $params['content'] + ]); + + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + self::setError($e->getMessage()); + return false; + } + } + + + /** + * @notes 删除任务 + * @param array $params + * @return bool + * @author likeadmin + * @date 2023/08/05 13:39 + */ + public static function delete(array $params): bool + { + return Task::destroy($params['id']); + } + + + /** + * @notes 获取任务详情 + * @param $params + * @return array + * @author likeadmin + * @date 2023/08/05 13:39 + */ + public static function detail($params): array + { + $task= Task::findOrEmpty($params['id'])->toArray(); + if($task){ + if(isset($task['extend']['informationg'])){ + $task['extend']['informationg']=UserInformationg::where('id',$task['extend']['informationg'])->field('name,phone,sex,age,update_time') + ->find()->toArray(); + } + } + return $task; + } +} \ No newline at end of file diff --git a/app/common/model/task/Task.php b/app/common/model/task/Task.php new file mode 100644 index 000000000..67c4d2680 --- /dev/null +++ b/app/common/model/task/Task.php @@ -0,0 +1,51 @@ +hasOne(User::class, 'id', 'director_uid')->field(['id', 'nickname', 'avatar']); + } + +} \ No newline at end of file diff --git a/app/common/model/user/Task.php b/app/common/model/user/Task.php deleted file mode 100644 index 2d5b43d29..000000000 --- a/app/common/model/user/Task.php +++ /dev/null @@ -1,194 +0,0 @@ - '未设置', - self::ONE => '一般', - self::TWO => '中', - self::THREE => '高', - self::FOUR => '紧急', - ]; - public static $FlowStatus = [ - self::ZERO => '未设置', - self::ONE => '未开始', - self::TWO => '进行中', - self::THREE => '等待验收', - self::FOUR => '已拒绝', - self::FIVE => '已关闭', - self::SIX => '通过验收', - ]; - - //列表 - function list($param, $type = 0) - { - $where = array(); - $map1 = []; - $map2 = []; - $map3 = []; - $map4 = []; - if (!empty($param['project_id'])) { - $where[] = ['project_id', '=', $param['project_id']]; - } - if (!empty($param['product_id'])) { - $where[] = ['product_id', '=', $param['product_id']]; - } else { - $map1[] = ['admin_id', '=', $param['uid']]; - $map2[] = ['director_uid', '=', $param['uid']]; - $map3[] = ['', 'exp', Db::raw("FIND_IN_SET({$param['uid']},assist_admin_ids)")]; - } - if (!empty($param['type'])) { - $where[] = ['type', '=', $param['type']]; - } - if (!empty($param['flow_status'])) { - $where[] = ['flow_status', '=', $param['flow_status']]; - } - if (!empty($param['priority'])) { - $where[] = ['priority', '=', $param['priority']]; - } - if (!empty($param['cate'])) { - $where[] = ['cate', '=', $param['cate']]; - } - if (!empty($param['director_uid'])) { - $where[] = ['director_uid', 'in', $param['director_uid']]; - } - if (!empty($param['keywords'])) { - $where[] = ['title|content', 'like', '%' . $param['keywords'] . '%']; - } - if (!empty($param['did'])) { - $where[] = ['did', '=', $param['did']]; - } - if (!empty($param['create_time'])) { - $where[] = ['create_time', 'BETWEEN', [strtotime($param['create_time']), strtotime($param['create_time'] . " +1 month -1 day")]]; - } - if (!empty($param['types']) && $param['types'] == 9) { - $where = []; - $where[] = ['end_time', 'BETWEEN', [strtotime(date('Y-m-d'), time()), strtotime(date('Y-m-d'), time()) + 86399]]; - $where[] = ['flow_status', '=', 2]; - - } - if (!empty($param['start_time'])) { - $where[] = ['start_time', '>=', strtotime($param['start_time'])]; - } - if (!empty($param['end_time'])) { - $where[] = ['end_time', '<=', strtotime($param['end_time']) + 86400]; - } - $where[] = ['delete_time', '=', 0]; - if ($type == 1) { - unset($where['project_id']); - $map1 = []; - $map2 = []; - $map3 = []; - $map4 = []; - } - $param['limit'] = !empty($param['day']) ? 999 : $param['limit']; - - $query = Db::name('Task')->where(function ($query) use ($map1, $map2, $map3, $map4) { - $query->where($map1)->whereor($map2)->whereor($map3); - })->where($where); - $count = $query->count(); - $list = $query->withoutField('content,md_content') - ->order('flow_status asc') - ->order('id desc') - ->page($param['page']) - ->limit($param['limit']) - ->select() - ->each(function ($item, $key) { - $item['director_name'] = Db::name('Admin')->where(['id' => $item['director_uid']])->value('name'); - $item['admin_name'] = Db::name('Admin')->where(['id' => $item['admin_id']])->value('name'); - $assist_admin_names = Db::name('Admin')->where([['id', 'in', $item['assist_admin_ids']]])->column('name'); - $item['cate_name'] = Db::name('WorkCate')->where(['id' => $item['cate']])->value('title'); - $item['type_name'] = Db::name('TaskCate')->where(['id' => $item['type']])->value('title'); - $item['did_name'] = Db::name('department')->where(['id' => $item['did']])->value('title'); - if (empty($assist_admin_names)) { - $item['assist_admin_names'] = '-'; - } else { - $item['assist_admin_names'] = implode(',', $assist_admin_names); - } - $item['start_time'] = date('Y-m-d', $item['start_time']); - $item['end_time'] = date('Y-m-d', $item['end_time']); - $item['delay'] = 0; - if ($item['over_time'] > 0 && $item['flow_status'] > 3 && $item['initial_end_time'] < time()) { - $item['delay'] = countDays(date('Y-m-d', $item['initial_end_time']), date('Y-m-d', $item['over_time'])); - } - if ($item['over_time'] == 0 && $item['flow_status'] < 2 && $item['initial_end_time'] < time()) { - $item['delay'] = countDays(date('Y-m-d', time()), $item['initial_end_time']); - } - $item['priority_name'] = self::$Priority[(int)$item['priority']]; - $item['flow_name'] = self::$FlowStatus[(int)$item['flow_status']]; - return $item; - }); - $return = []; - if (!empty($param['day']) && !empty($param['start_time']) && !empty($param['end_time'])) { - foreach ($list as $item) { - if (isset($return[$item['start_time']]) && count($return[$item['start_time']]) > 2) { - continue; - } - $return[$item['start_time']][] = $item; - } - } else { - $return = $list; - } - return [$count, $return]; - } - - //详情 - public function detail($id) - { - $detail = Db::name('Task')->where(['id' => $id])->find(); - if (!empty($detail)) { - $detail['product_name'] = ''; - $detail['project_name'] = ''; - if ($detail['project_id'] > 0) { - $project = Db::name('Project')->where(['id' => $detail['project_id']])->field('product_id,name')->find(); - $detail['product_name'] = Db::name('Product')->where(['id' => $project['product_id']])->value('name'); - $detail['project_name'] = $project['name']; - } - $detail['admin_name'] = Db::name('Admin')->where(['id' => $detail['admin_id']])->value('name'); - $detail['work_hours'] = Db::name('Schedule')->where(['delete_time' => 0, 'tid' => $detail['id']])->sum('labor_time'); - $detail['cate_name'] = Db::name('WorkCate')->where(['id' => $detail['cate']])->value('title'); - $detail['type_name'] = Db::name('TaskCate')->where(['id' => $detail['type']])->value('title'); - $find = Db::name('Admin')->where(['id' => $detail['director_uid']])->field('name,total_working_hours')->find(); - $detail['director_name'] = $find['name'] ?? ''; - $detail['assist_admin_names'] = ''; - if (!empty($detail['assist_admin_ids'])) { - $assist_admin_names = Db::name('Admin')->where('id', 'in', $detail['assist_admin_ids'])->column('name'); - $detail['assist_admin_names'] = implode(',', $assist_admin_names); - } - $detail['priority_name'] = self::$Priority[(int)$detail['priority']]; - $detail['flow_name'] = self::$FlowStatus[(int)$detail['flow_status']]; - $detail['times'] = time_trans($detail['create_time']); - $detail['end_time'] = date('Y-m-d H:i', $detail['end_time']); - $detail['delay'] = 0; - if ($detail['over_time'] > 0 && $detail['flow_status'] > 3 && $detail['initial_end_time'] < time()) { - $detail['delay'] = countDays(date('Y-m-d', $detail['initial_end_time']), date('Y-m-d', $detail['over_time'])); - } - if ($detail['over_time'] == 0 && $detail['flow_status'] < 2 && $detail['initial_end_time'] < time()) { - $detail['delay'] = countDays(date('Y-m-d', time()), $detail['initial_end_time']); - } - } - return $detail; - } -} -