StartworkModel = new Startwork(); $this->ReturnworkProject = new ReturnworkProject(); $this->StartworkProject = new StartworkProject(); $this->StartworkContent = new StartworkContent(); $this->WorkTicketProject= new WorkTicketProject(); } /** 状态 */ private function getStatus($id) { $arr = ['不符合', '符合', '基本符合']; return $arr[$id]; } /** 首页/列表-一般开工 */ public function index(Request $request) { if ($request->isAjax()) { $param = $request->all(); $limit = $param['limit']; $where = []; if (isset($param['type']) && !empty($param['type'])) { $where['type'] = $param['type']; } if (isset($param['name']) && !empty($param['name'])) { $where['name'] = $param['name']; } if (isset($param['status']) && $param['status'] !== '') { $where['status'] = $param['status']; } if (isset($param['project_id']) && !empty($param['project_id'])) { $where['project_id'] = $param['project_id']; } $list = $this->StartworkModel->getPaginateList($where, ['*'], ['sort' => $param['sort'] ?? 'asc'], [], $limit); foreach ($list['data'] as $key => $item) { $list['data'][$key]['statusname'] = $this->getStatus($item['status']); } $data['list'] = $list; return sparKSuccess(dataReturn(0, 'success', $data)); } return view('productions/startwork/index'); } /** 添加 */ public function store(Request $request) { if ($request->isAjaxPost()) { $param = $request->post(); $param['create_time'] = now(); $res = $this->StartworkModel->insertOne($param); return sparkSuccess(dataReturn(0, '添加成功')); } return sparkSuccess(dataReturn(0, 'error')); } /** 编辑 */ public function update(Request $request) { if ($request->isAjaxPost()) { $param = $request->post(); $param['update_time'] = now(); unset($param['create_time']); $res = $this->StartworkModel->updateById($param, $param['id']); return sparkSuccess(dataReturn(0, '编辑成功')); } return sparkSuccess(dataReturn(0, 'error')); } /** 查询 */ public function show(Request $request) { $id = $request->get('id'); $row = $this->StartworkModel->getInfoById($id); return sparKSuccess(dataReturn(0, 'success', $row)); } /** 删除 */ public function destroy(Request $request) { $id = $request->get('id'); $row = $this->StartworkModel->delById($id); return sparKSuccess(dataReturn(0, '删除成功')); } /** 风险管控>开工条件 */ public function table(Request $request) { if ($request->isPost()) { $param = $request->all(); $contents = $param['contents']; unset($param['contents']); if ($param['type'] == 1) { if ($this->StartworkProject ->where('org_id', '=', $param['org_id']) ->where('type', '=', 1) ->exists()) { return sparKSuccess(dataReturn(1, '该项目已提交开工条件')); } } $orgInfo = getOrgFromLevel4($param['org_id']); $data = $this->StartworkProject->create(array_merge($param, $orgInfo)); foreach ($contents as $index => $content) { if (isset($content['file']) && is_array($content['file'])) { $content['file'] = implode(',', $content['file']); } !isset($content['file']) && $content['file'] = ''; !isset($content['filename']) && $content['filename'] = ''; !isset($content['filetitle']) && $content['filetitle'] = ''; !isset($content['judge']) && $content['judge'] = ''; !isset($content['name']) && $content['name'] = ''; !isset($content['notes']) && $content['notes'] = ''; !isset($content['sort']) && $content['sort'] = ''; !isset($content['status']) && $content['status'] = ''; !isset($content['type']) && $content['type'] = ''; unset($content['id']); unset($content['create_time']); unset($content['update_time']); $content['project_id'] = $data->id; $contents[$index] = $content; } $data->contents()->insert($contents); return sparKSuccess(dataReturn(0, 'success')); } if ($request->isAjax()) { $param = $request->all(); $list = $this->StartworkModel ->where('type', '=', (int)$param['type']) ->orderBy('sort', 'asc') ->get(); return sparKSuccess(dataReturn(0, 'success', $list)); } View::assign([ 'orgList' => asTreeArray((new AdminOrg())->getAllList([['status', '=', 1]]), 'pid'), ]); return view('productions/startwork/table'); } /** 风险管控>统计分析 */ public function statistics(Request $request) { if ($request->isAjax()) { $param = $request->all(); $where = []; $list = []; // 通过session获取当前数据范围公司 $orgInfo = getOrgSelfAndChildrenOrgsById(); $org = end($orgInfo); if ($org['org_type'] === 'type_corporation') { $where[] = ['company_org_id', '=', $org['id']]; } elseif($org['org_type'] === 'type_company') { $where[] = ['project_org_id', '=', $org['id']]; } else { $where[] = ['org_id', '=', $org['id']]; } if (isset($param['type']) && !empty($param['type'])) { if ($param['type'] == 3) { $list = $this->ReturnworkProject ->where($where) ->with(['contents']) ->orderBy('created_at', 'desc') ->paginate(); } elseif ($param['type'] == 4) { $list = $this->WorkTicketProject ->where($where) ->with(['contents']) ->orderBy('created_at', 'desc') ->paginate(); } else { $list = $this->StartworkProject ->select( 'module_productions_startwork_project.*', 'user.nickname as user_name', ) ->where($where) ->where('type', '=', $param['type']) ->orderBy('created_at', 'desc') ->with(['contents']) ->withCount(['contents', 'status0', 'status1', 'status2']) ->join('admin_user as user', 'user.id', '=', 'module_productions_startwork_project.examiner') ->paginate(); } } return sparKSuccess(dataReturn(0, 'success', $list)); } View::assign([ 'orgList' => asTreeArray((new AdminOrg())->getAllList([['status', '=', 1]]), 'pid'), ]); return view('productions/startwork/statistics'); } /** * 管理员列表 * * @param Request $request * @return Response */ public function userList(Request $request): Response { $adminService = new AdminService(); $res = $adminService->getList($request->all()); return sparkSuccess($res); } /** * 删除统计信息 * * @param Request $request * @param $id * @return Response */ public function delete(Request $request, $id) { $row = $this->StartworkProject->find($id); $row->contents()->delete(); $row->delete(); return sparKSuccess(dataReturn(0, '删除成功')); } }