$value) { $tmp = Db::name('task')->where('work_id', '<>', 0)->whereLike('owner_user_id', '%,' . $value . ',%')->column('task_id'); $taskArray = array_merge($tmp, $taskArray); } if (!empty($taskArray)) $userWhere['task_id'] = ['in', $taskArray]; } # 项目 if (!empty($workIds)) $workWhere['work_id'] = ['in', $workIds]; # 标签 if (!empty($labelIds) && is_array($labelIds)) { foreach ($labelIds AS $key => $value) { $labelWhere .= '(lable_id like "%,'.$value.',%") OR '; } if (!empty($labelWhere)) $labelWhere = '(' . rtrim($labelWhere, 'OR ') . ')'; } $data = Db::name('task') ->where('work_id', '<>', 0) ->where($searchWhere) ->where($dateWhere) ->where($userWhere) ->where($workWhere) ->where($labelWhere) ->order($orderField, $orderSort) ->select(); foreach ($data AS $key => $value) { $data[$key]['filecount'] = Db::name('work_task_file')->where('task_id', $value['task_id'])->count(); $data[$key]['relationCount'] = $this->getRelationCount($value['task_id']); $data[$key]['lableList'] = Db::name('work_task_lable')->field(['lable_id', 'name', 'color'])->whereIn('lable_id', trim($value['lable_id'], ','))->select(); $data[$key]['subdonecount'] = Db::name('task')->where(['pid' => $value['task_id'], 'status' => 5])->count(); $data[$key]['subcount'] = Db::name('task')->where(['pid' => $value['task_id'], 'status' => ['neq', 5]])->count(); $data[$key]['start_time'] = !empty($value['start_time']) ? date('Y-m-d', $value['start_time']) : null; $data[$key]['stop_time'] = !empty($value['stop_time']) ? date('Y-m-d', $value['stop_time']) : null; $data[$key]['create_time'] = !empty($value['create_time']) ? date('Y-m-d H:i:s', $value['create_time']) : null; $data[$key]['update_time'] = !empty($value['update_time']) ? date('Y-m-d H:i:s', $value['update_time']) : null; } return $data; } private function getRelationCount($task_id) { $relationInfo = Db::name('TaskRelation')->where(['task_id' => $task_id])->find(); $count = 0; if ($relationInfo) { $count1 = count(stringToArray($relationInfo['customer_ids'])); $count2 = count(stringToArray($relationInfo['contacts_ids'])); $count3 = count(stringToArray($relationInfo['business_ids'])); $count4 = count(stringToArray($relationInfo['contract_ids'])); $count = $count1 + $count2 + $count3 + $count4; } return $count; } }