正在显示
4 个修改的文件
包含
82 行增加
和
4 行删除
| @@ -38,22 +38,55 @@ class TaskController extends BaseController | @@ -38,22 +38,55 @@ class TaskController extends BaseController | ||
| 38 | } | 38 | } |
| 39 | if(!empty($this->param['dep_id'])){ | 39 | if(!empty($this->param['dep_id'])){ |
| 40 | $manage_ids = Manage::where('dept_id', $this->param['dep_id'])->pluck('id')->toArray(); | 40 | $manage_ids = Manage::where('dept_id', $this->param['dep_id'])->pluck('id')->toArray(); |
| 41 | - $map[] = ['id', 'in', TaskOwner::whereIn('manage_id',$manage_ids)->pluck('task_id')->toArray()]; | 41 | + $map[] = ['gto.manage_id', 'in', $manage_ids]; |
| 42 | } | 42 | } |
| 43 | - if(!empty($this->param['created_manage_id']) && !empty($this->param['type'])){ | 43 | + if(!empty($this->param['manage_id']) && !empty($this->param['type'])){ |
| 44 | if($this->param['type'] == 1){ | 44 | if($this->param['type'] == 1){ |
| 45 | - $map[] = ['created_manage_id', $this->param['created_manage_id']]; | 45 | + $map[] = ['created_manage_id', $this->param['manage_id']]; |
| 46 | }else{ | 46 | }else{ |
| 47 | - $map[] = ['id', 'in', TaskOwner::where('manage_id', $this->param['owner_manage_id'])->pluck('task_id')->toArray()]; | 47 | + $map[] = ['gto.manage_id', $this->param['manage_id']]; |
| 48 | } | 48 | } |
| 49 | } | 49 | } |
| 50 | 50 | ||
| 51 | $sort = ['id' => 'desc']; | 51 | $sort = ['id' => 'desc']; |
| 52 | + $data = $logic->getUserlist($map, $sort, ['id', 'project_id', 'workload', 'priority', 'content', 'attachment', 'status', 'end_at', 'created_manage_id']); | ||
| 53 | + | ||
| 54 | + return $this->success($data); | ||
| 55 | + } | ||
| 56 | + | ||
| 57 | + public function items(Request $request, TaskLogic $logic) | ||
| 58 | + { | ||
| 59 | + $request->validate([ | ||
| 60 | + 'own_manage_id'=>'required' | ||
| 61 | + ],[ | ||
| 62 | + 'own_manage_id.required' => '所属人ID不能为空' | ||
| 63 | + ]); | ||
| 64 | + $map[] = ['id', 'in', TaskOwner::where('manage_id', $this->param['own_manage_id'])->pluck('id')->toArray()]; | ||
| 65 | + if(!empty($this->param['search']) && !empty($this->param['search_type'])){ | ||
| 66 | + if($this->param['search_type'] == 'project'){ | ||
| 67 | + $map[] = ['project_id', 'in', Project::where('title', 'like', "%{$this->param['search']}%")->pluck('id')->toarray()]; | ||
| 68 | + }else{ | ||
| 69 | + $map[] = [$this->param['search_type'], 'like', "%{$this->param['search']}%"]; | ||
| 70 | + } | ||
| 71 | + } | ||
| 72 | + if(!empty($this->param['dep_id'])){ | ||
| 73 | + $manage_ids = Manage::where('dept_id', $this->param['dep_id'])->pluck('id')->toArray(); | ||
| 74 | + $map[] = ['id', 'in', TaskOwner::whereIn('manage_id',$manage_ids)->pluck('task_id')->toArray()]; | ||
| 75 | + } | ||
| 76 | + if(!empty($this->param['manage_id']) && !empty($this->param['type'])){ | ||
| 77 | + if($this->param['type'] == 1){ | ||
| 78 | + $map[] = ['created_manage_id', $this->param['manage_id']]; | ||
| 79 | + }else{ | ||
| 80 | + $map[] = ['id', 'in', TaskOwner::where('manage_id', $this->param['manage_id'])->pluck('task_id')->toArray()]; | ||
| 81 | + } | ||
| 82 | + } | ||
| 83 | + $sort = ['id' => 'desc']; | ||
| 52 | $data = $logic->getList($map, $sort, ['id', 'project_id', 'workload', 'priority', 'content', 'attachment', 'status', 'end_at', 'created_manage_id']); | 84 | $data = $logic->getList($map, $sort, ['id', 'project_id', 'workload', 'priority', 'content', 'attachment', 'status', 'end_at', 'created_manage_id']); |
| 53 | 85 | ||
| 54 | return $this->success($data); | 86 | return $this->success($data); |
| 55 | } | 87 | } |
| 56 | 88 | ||
| 89 | + | ||
| 57 | public function info(Request $request, TaskLogic $logic){ | 90 | public function info(Request $request, TaskLogic $logic){ |
| 58 | $request->validate([ | 91 | $request->validate([ |
| 59 | 'id'=>'required' | 92 | 'id'=>'required' |
| @@ -6,9 +6,11 @@ namespace App\Http\Logic\Aside\Task; | @@ -6,9 +6,11 @@ namespace App\Http\Logic\Aside\Task; | ||
| 6 | use App\Helper\Arr; | 6 | use App\Helper\Arr; |
| 7 | use App\Http\Logic\Aside\BaseLogic; | 7 | use App\Http\Logic\Aside\BaseLogic; |
| 8 | use App\Http\Logic\Aside\LoginLogic; | 8 | use App\Http\Logic\Aside\LoginLogic; |
| 9 | +use App\Http\Logic\Aside\Manage\ManageLogic; | ||
| 9 | use App\Models\Task\Task; | 10 | use App\Models\Task\Task; |
| 10 | use App\Models\Task\TaskOwner; | 11 | use App\Models\Task\TaskOwner; |
| 11 | use Illuminate\Support\Facades\DB; | 12 | use Illuminate\Support\Facades\DB; |
| 13 | +use Illuminate\Support\Str; | ||
| 12 | 14 | ||
| 13 | /** | 15 | /** |
| 14 | * Class TaskLogic | 16 | * Class TaskLogic |
| @@ -25,6 +27,39 @@ class TaskLogic extends BaseLogic | @@ -25,6 +27,39 @@ class TaskLogic extends BaseLogic | ||
| 25 | $this->model = new Task(); | 27 | $this->model = new Task(); |
| 26 | } | 28 | } |
| 27 | 29 | ||
| 30 | + | ||
| 31 | + public function getUserlist(array $map = [], array $sort = ['id' => 'desc'], array $columns = ['*'], int $limit = 20){ | ||
| 32 | + $where = array_map(function ($v) { | ||
| 33 | + if(!Str::startsWith($v[0], 'gto.')) { | ||
| 34 | + $v[0] = 'gl_task.' . $v[0]; | ||
| 35 | + } | ||
| 36 | + return $v; | ||
| 37 | + }, $map); | ||
| 38 | + $data = $this->formatQuery($where)->leftJoin('gl_task_owner as gto', 'gl_task.id', '=', 'gto.task_id') | ||
| 39 | + ->select('gto.manage_id', DB::raw('COUNT(*) as count')) | ||
| 40 | + ->groupBy('gto.manage_id') | ||
| 41 | + ->paginate($limit)->toArray(); | ||
| 42 | + $list = []; | ||
| 43 | + $map = array_map(function ($v) { | ||
| 44 | + if(!Str::startsWith($v[0], 'gto.')) { | ||
| 45 | + return $v; | ||
| 46 | + } | ||
| 47 | + return []; | ||
| 48 | + }, $map); | ||
| 49 | + $map = array_filter($map); | ||
| 50 | + foreach ($data['list'] as $v){ | ||
| 51 | + $map[] = ['id', 'in', TaskOwner::where('manage_id', $v['manage_id'])->pluck('task_id')->toArray()]; | ||
| 52 | + $list[] = [ | ||
| 53 | + "manage_id" => $v['manage_id'], | ||
| 54 | + "manage_id_text" => ManageLogic::getCacheName($v['manage_id']), | ||
| 55 | + "count" => $v['count'], | ||
| 56 | + "task_list" => $this->getList($map, $sort, $columns)['list'] ?? [] | ||
| 57 | + ]; | ||
| 58 | + } | ||
| 59 | + return $this->success($list); | ||
| 60 | + } | ||
| 61 | + | ||
| 62 | + | ||
| 28 | public function getInfo($id) | 63 | public function getInfo($id) |
| 29 | { | 64 | { |
| 30 | parent::setWith(['owner', 'follow']); //删除缓存要添加带with的cache_key | 65 | parent::setWith(['owner', 'follow']); //删除缓存要添加带with的cache_key |
| @@ -27,11 +27,17 @@ class Task extends Base | @@ -27,11 +27,17 @@ class Task extends Base | ||
| 27 | } | 27 | } |
| 28 | 28 | ||
| 29 | public function getProjectIdTextAttribute(){ | 29 | public function getProjectIdTextAttribute(){ |
| 30 | + if($this->project_id === null){ | ||
| 31 | + return ''; | ||
| 32 | + } | ||
| 30 | $project = ProjectLogic::instance()->getCacheInfo($this->project_id); | 33 | $project = ProjectLogic::instance()->getCacheInfo($this->project_id); |
| 31 | return $project['title'] ?? ''; | 34 | return $project['title'] ?? ''; |
| 32 | } | 35 | } |
| 33 | 36 | ||
| 34 | public function getStatusTextAttribute(){ | 37 | public function getStatusTextAttribute(){ |
| 38 | + if($this->status === null){ | ||
| 39 | + return ''; | ||
| 40 | + } | ||
| 35 | return self::statusMap()[$this->status] ?? ''; | 41 | return self::statusMap()[$this->status] ?? ''; |
| 36 | } | 42 | } |
| 37 | 43 | ||
| @@ -44,6 +50,9 @@ class Task extends Base | @@ -44,6 +50,9 @@ class Task extends Base | ||
| 44 | } | 50 | } |
| 45 | 51 | ||
| 46 | public function getTimeoutAttribute(){ | 52 | public function getTimeoutAttribute(){ |
| 53 | + if($this->end_at === null){ | ||
| 54 | + return 0; | ||
| 55 | + } | ||
| 47 | if($this->status != self::STATUS_DOWN && strtotime($this->end_at) < time()){ | 56 | if($this->status != self::STATUS_DOWN && strtotime($this->end_at) < time()){ |
| 48 | return floor((time() - strtotime($this->end_at)) / 60); | 57 | return floor((time() - strtotime($this->end_at)) / 60); |
| 49 | } | 58 | } |
| @@ -142,6 +142,7 @@ Route::middleware(['aloginauth'])->group(function () { | @@ -142,6 +142,7 @@ Route::middleware(['aloginauth'])->group(function () { | ||
| 142 | //工单管理 | 142 | //工单管理 |
| 143 | Route::prefix('task')->group(function () { | 143 | Route::prefix('task')->group(function () { |
| 144 | Route::get('/', [Aside\Task\TaskController::class, 'list'])->name('admin.task'); | 144 | Route::get('/', [Aside\Task\TaskController::class, 'list'])->name('admin.task'); |
| 145 | + Route::get('/items', [Aside\Task\TaskController::class, 'items'])->name('admin.task_items'); | ||
| 145 | Route::get('/info', [Aside\Task\TaskController::class, 'info'])->name('admin.task_info'); | 146 | Route::get('/info', [Aside\Task\TaskController::class, 'info'])->name('admin.task_info'); |
| 146 | Route::post('/save', [Aside\Task\TaskController::class, 'save'])->name('admin.task_save'); | 147 | Route::post('/save', [Aside\Task\TaskController::class, 'save'])->name('admin.task_save'); |
| 147 | Route::post('/status', [Aside\Task\TaskController::class, 'status'])->name('admin.task_status'); | 148 | Route::post('/status', [Aside\Task\TaskController::class, 'status'])->name('admin.task_status'); |
-
请 注册 或 登录 后发表评论