all(); if (!empty($result)) { $this->saveClientProjectFlow($result); } $user = auth()->user(); if (empty($user)) { return view('admin/site/not_found', [ 'tips' => 'error', 'siteId' => 0, ]); } $projectFlowMemo = ProjectFlowMemo::query(); if (!empty($type)) { $projectFlowMemo->whereRaw('FIND_IN_SET(?,roles)', [Role::TYPE_CUSTOMER]); } $siteIds = DB::table('user_has_sites')->where('user_id', $user->id)->first(); if (empty($siteIds)) { return view('admin/site/not_found', [ 'tips' => '暂无建站进度', 'siteId' => 0, ]); } $flowList = $projectFlowMemo ->with(['projectFlowMemoRelation']) ->where('site_id', $siteIds->site_id) ->get(); if (empty($flowList->toArray())) { return view('admin/site/not_found', [ 'tips' => '暂无建站进度', 'siteId' => 0, ]); } $flowService = new FlowService(); //各阶段负责人 $flowService->getRoleUser($flowList, User::query()->pluck('nickname', 'id')); //按阶段分组 $flowList = $flowList->groupBy('level')->toArray() ?? []; //统计完成和没完成的阶段 $ids = $flowService->addUp($flowList); $title = $projectFlowMemo ->where('site_id', $siteIds->site_id) ->groupBy('rank', 'level') ->orderBy('level', 'asc') ->pluck('rank', 'level')->toArray() ?? []; foreach ($title as $key => $value) { $title[$key] = $value . ':' . $key . ':' . $ids[$key] ?? ''; } $result = array_combine($title, $flowList); //所有阶段任务数量 $count = ProjectFlowMemo::query()->where('site_id', $siteIds->site_id)->count() ?? 0; //没完成的 $toBeCompletedCount = ProjectFlowMemo::query()->where('site_id', $siteIds->site_id)->where('status', 0)->count() ?? 0; $flowList = ProjectFlowMemo::query() ->where('site_id', $siteIds->site_id) ->orderBy('id', 'asc')->get(); if (!empty($flowList)) { //最后的上线时间 $nodeDate = $flowList[count($flowList) - 1]['node_date']; //延期的时间 if (date('Y-m-d') > $nodeDate) { $diff = strtotime(date('Y-m-d')) - strtotime($nodeDate); $newNodeDate = date('Y-m-d', (strtotime($nodeDate) + $diff)); } } //每个小阶段的起始和结束时间 [$taskLastDateStart, $taskLastDateEnd] = $flowService->getStageDate($result); //这周一周日、下周一下周末 [$monday, $sunday, $nextMonday, $nextSunday] = $flowService->getThisMonDayAndNextMonday(); $thisWeekTaskList = $flowService->getWeekTaskList($siteIds->site_id, $monday, $sunday, 'this'); $nextWeekTaskList = $flowService->getWeekTaskList($siteIds->site_id, $nextMonday, $nextSunday, 'next'); return view('wap.site_flow', [ 'list' => $result, 'count' => $count, 'nodeDate' => $nodeDate ?? '', 'toBeCompletedCount' => $toBeCompletedCount, 'scoreList' => ProjectFlowMemo::SCORE, 'type' => $type, 'taskLastDateStart' => $taskLastDateStart, 'taskLastDateEnd' => $taskLastDateEnd, 'newNodeDate' => $newNodeDate ?? '', 'thisWeekTaskList' => $thisWeekTaskList, 'nextWeekTaskList' => $nextWeekTaskList, 'site' => Site::query()->where('id', $siteIds->site_id)->value('cn_title') ?? '', ]); } public function saveClientProjectFlow($result) { $data = []; foreach ($result as $key => $item) { //拆分表单提交过来的字段 $filed = explode('-', $key); $data[] = [ 'id' => $filed[0], $filed[1] => $item, ]; } foreach ($data as $datum) { ProjectFlowMemo::query()->where('id', $datum['id'])->update(['client_score' => $datum['client_score']]); } } }