model = new ProjectReport(); $this->CostModel = new CostProject(); $this->uid = get_login_admin('id'); $this->ProjectMsg = new ProjectMsg(); $this->Auditmodel = new AuditModel(); $this->Officialaccount = new Officialaccount(); $this->Pushmessage = new Pushmessage(); } /** * 数据列表-财政局 */ public function datalist() { $param = get_params(); // halt($param); $where = [ ["cp_project_report.delete_time", "=", 0], ["project_id", "=", $param["project_id"]], ["a.status","<",6] ]; $rows = empty($param['limit']) ? get_config('app.page_size') : $param['limit']; $order = empty($param['order']) ? 'a.id desc' : $param['order']; $list = $this->model->where($where) ->field('a.*,f.name,f.filesize,f.filepath,f.fileext,f.admin_id') ->alias('a') ->join('file f', "a.file = f.id", "left") ->order($order) ->paginate($rows, false, ['query' => $param]) ->each(function ($item, $key) { }); return table_assign(0, '', $list); } /** * 数据列表-公司 */ public function datalist_company() { $param = get_params(); $where = [ ["cp_project_report.delete_time", "=", 0], ["project_id", "=", $param["project_id"]] ]; $rows = empty($param['limit']) ? get_config('app.page_size') : $param['limit']; $order = empty($param['order']) ? 'a.id desc' : $param['order']; $list = $this->model->where($where) ->field('a.*,f.name,f.filesize,f.filepath,f.fileext,f.admin_id') ->alias('a') ->join('file f', "a.file = f.id", "left") ->order($order) ->paginate($rows, false, ['query' => $param]) ->each(function ($item, $key) { }); // halt($list); return table_assign(0, '', $list); } /** * 数据列表-公司 */ public function datalist_proprietor() { $param = get_params(); $where = [ ["cp_project_report.delete_time", "=", 0], ["project_id", "=", $param["project_id"]] ]; $rows = empty($param['limit']) ? get_config('app.page_size') : $param['limit']; $order = empty($param['order']) ? 'a.id desc' : $param['order']; $list = $this->model->where($where) ->field('a.*,u.nickname as admin_name,f.name,f.filesize,f.filepath,f.fileext,f.admin_id') ->alias('a') ->join('file f', "a.file = f.id", "left") ->join('Admin u', 'a.maker_id = u.id', "left") ->order($order) ->paginate($rows, false, ['query' => $param]) ->each(function ($item, $key) { }); return table_assign(0, '', $list); } /** * 添加-公司 */ public function add_company() { $param = get_params(); $handle = $this->Pushmessage->handleParam($param); $param = $handle['param']; if (request()->isAjax()) { if (isset($param['table-align'])) { unset($param['table-align']); } if (isset($param['content'])) { $param['md_content'] = ''; } if (isset($param['docContent-html-code'])) { $param['content'] = $param['docContent-html-code']; $param['md_content'] = $param['docContent-markdown-doc']; unset($param['docContent-html-code']); unset($param['docContent-markdown-doc']); } // 创建HTMLPurifier配置对象 $config = HTMLPurifier_Config::createDefault(); $config->set('HTML.DefinitionID', 'html5-definitions'); $config->set('HTML.DefinitionRev', 1); $config->set('HTML.ForbiddenAttributes', ['width', 'height']); //$config->set('HTML.Allowed', 'p,b,a[href],pre[class],code,blockquote,img[src],table,tr,th,td,ul,li,ol,dl,dt,dd'); $config->set('HTML.ForbiddenElements', array('script'), true);//设置拒绝使用的tagname if ($def = $config->maybeGetRawHTMLDefinition()) { $def->addElement('video', 'Block', 'Optional: (source, Flow) | (Flow, source) | Flow', 'Common', [ 'src' => 'URI', 'type' => 'Text', 'poster' => 'URI', 'preload' => 'Enum#auto,metadata,none', 'controls' => 'Bool', ]); $def->addElement('source', 'Block', 'Flow', 'Common', [ 'src' => 'URI', 'type' => 'Text', ]); } // 创建HTMLPurifier对象 $purifier = new HTMLPurifier($config); //防止xss,过滤输入并输出结果 //$param['content'] = '测试'; $param['content'] = $purifier->purify($param['content']); $project_id = isset($param['project_id']) ? $param['project_id'] : 0; $param['status'] = 6; $param['project_id'] = $project_id; $param['maker_id'] = $this->uid; $param['admin_name'] = get_login_admin('nickname'); try { $param['create_time'] = time(); $insertId = $this->model->strict(false)->field(true)->insertGetId($param); $log = $param; unset($log['content']); add_log('add', $insertId, $log); } catch (\Exception $e) { return to_assign(1, '操作失败,原因:' . $e->getMessage()); } $detail = Db::name("cost_project")->where("id", $project_id)->field("project_name,project_status,entrust_maker,entrust_maker_name")->find(); $auditDataArr = []; $auditData = [ "project_id" => $project_id, "project_name" => $detail["project_name"], "project_type" => "造价项目", "audit_name" => "报告一审", "audit_type" => 4, "else_id" => $insertId, "sponsor" => get_login_admin("nickname"), "sponsor_id" => $this->uid, "sponsor_unit" => Db::name("department")->where("id", get_login_admin('unit_name'))->value("title"), "approver" => $param["first"], "approver_name" => get_admin($param["first"])["nickname"], "create_time" => time() ]; //1项目,2报告,3公司一级审核,4公司二级审核,5公司三级审核 if (!empty($param["first"])) { $auditData["audit_name"] = "报告一审"; $auditData["audit_type"] = 4; $auditData["approver"] = $param["first"]; $auditData["approver_name"] = get_admin($param["first"])["nickname"]; $auditDataArr[] = $auditData; if (empty($handle['financial'])) { $handle['company'] = (array)$param["first"]; } else { $handle['company'] = array_merge($param["first"], $handle['financial']); } $this->Pushmessage->pushMessage($project_id, $handle['financial'], $handle['company']); } else { return to_assign(1, "请选择审批人"); } if (!empty($param["second"])) { $auditData["audit_name"] = "报告二审"; $auditData["audit_type"] = 5; $auditData["audit_status"] = 5; $auditData["approver"] = $param["second"]; $auditData["approver_name"] = get_admin($param["second"])["nickname"]; $auditDataArr[] = $auditData; } if (!empty($param["third"])) { $auditData["audit_name"] = "报告三审"; $auditData["audit_type"] = 6; $auditData["audit_status"] = 5; $auditData["approver"] = $param["third"]; $auditData["approver_name"] = get_admin($param["third"])["nickname"]; $auditDataArr[] = $auditData; } if (!empty($param["fourth"])) { $auditData["audit_name"] = "报告四审"; $auditData["audit_type"] = 14; $auditData["audit_status"] = 5; $auditData["approver"] = $param["fourth"]; $auditData["approver_name"] = get_admin($param["fourth"])["nickname"]; $auditDataArr[] = $auditData; } if (!empty($param["fifth"])) { $auditData["audit_name"] = "报告五审"; $auditData["audit_type"] = 15; $auditData["audit_status"] = 5; $auditData["approver"] = $param["fifth"]; $auditData["approver_name"] = get_admin($param["fifth"])["nickname"]; $auditDataArr[] = $auditData; } // halt($auditDataArr); if (!empty($auditDataArr)) { $ProjectAudit = new ProjectAudit(); try { $ProjectAudit->saveAll($auditDataArr); } catch (\Exception $e) { return to_assign(1, '操作失败,原因:' . $e->getMessage()); } } return to_assign(0, '操作成功'); } else { $project_id = isset($param['project_id']) ? $param['project_id'] : 0; $ids = Db::name('CostProject')->where("id", $project_id)->field("entrust_maker,review_head,operate_head,operate_team")->find(); // halt($ids); $idarr = $ids["operate_team"] . ',' . $ids["operate_head"] . ',' . $ids["review_head"]; $idarr = explode(",", $idarr); $people = Db::name("admin")->whereIn('id', $idarr)->field('id,nickname')->select(); //富文本类型 View::assign('editor', get_system_config('other', 'editor')); //关联项目id View::assign('project_id', $project_id); View::assign('people', $people); return view('add'); } } /** * 查看信息-财政局 */ public function view() { $param = get_params(); $id = isset($param['id']) ? $param['id'] : 0; $detail = (new ProjectReport())->detail($id); if (empty($detail)) { if (empty($detail)) { echo '
该文档不存在
'; exit; } } else { $maker_name = Db::name('admin')->where(['id' => $detail["maker_id"]])->value("nickname"); $detail["maker_name"] = $maker_name; $file_array = Db::name('ProjectReport') ->field("r.*,a.nickname as admin_name,f.name,f.filesize,f.filepath,f.fileext,f.admin_id") ->alias('r') ->join('File f', 'r.file = f.id') ->join('Admin a', 'r.maker_id = a.id', 'LEFT') ->order('r.create_time desc') ->where(array('r.id' => $id)) ->select()->toArray(); View::assign('file_array', $file_array); View::assign('detail', $detail); return view(); } } /** * 查看信息-公司 */ public function view_company() { $param = get_params(); $id = isset($param['id']) ? $param['id'] : 0; $detail = (new ProjectReport())->detail($id); if (empty($detail)) { if (empty($detail)) { echo '
该文档不存在
'; exit; } } else { $maker_name = Db::name('admin')->where(['id' => $detail["maker_id"]])->value("nickname"); $detail["maker_name"] = $maker_name; $file_array = Db::name('ProjectReport') ->field("r.*,a.nickname as admin_name,f.name,f.filesize,f.filepath,f.fileext,f.admin_id") ->alias('r') ->join('File f', 'r.file = f.id') ->join('Admin a', 'r.maker_id = a.id', 'LEFT') ->order('r.create_time desc') ->where(array('r.id' => $id)) ->select()->toArray(); View::assign('file_array', $file_array); View::assign('detail', $detail); return view(); } } /** * 查看信息-业主 */ public function view_proprietor() { $param = get_params(); $id = isset($param['id']) ? $param['id'] : 0; $detail = (new ProjectReport())->detail($id); if (empty($detail)) { if (empty($detail)) { echo '
该文档不存在
'; exit; } } else { $maker_name = Db::name('admin')->where(['id' => $detail["maker_id"]])->value("nickname"); $detail["maker_name"] = $maker_name; $file_array = Db::name('ProjectReport') ->field("r.*,a.nickname as admin_name,f.name,f.filesize,f.filepath,f.fileext,f.admin_id") ->alias('r') ->join('File f', 'r.file = f.id') ->join('Admin a', 'r.maker_id = a.id', 'LEFT') ->order('r.create_time desc') ->where(array('r.id' => $id)) ->select()->toArray(); View::assign('file_array', $file_array); View::assign('detail', $detail); return view(); } } /** * 删除-公司 * 跟财评申请删除 */ public function delete_company() { $param = get_params(); $handle = $this->Pushmessage->handleParam($param); $param = $handle['param']; $id = isset($param['id']) ? $param['id'] : 0; $detail = $this->model->where("id", $id)->find(); $approver = Db::name("cost_project")->where("id", $detail["project_id"])->value("entrust_maker"); $details = Db::name("cost_project")->where("id", $detail["project_id"])->field("project_name,project_status,entrust_maker,entrust_maker_name")->find(); $auditData = [ "project_id" => $detail["project_id"], "project_name" => $details["project_name"], "project_type" => "造价项目", "audit_name" => "删除报告申请", "audit_type" => 2, "else_id" => $id, "sponsor" => get_login_admin("nickname"), "sponsor_id" => $this->uid, "sponsor_unit" => Db::name("department")->where("id", get_login_admin('unit_name'))->value("title"), "approver" => $details["entrust_maker"], "approver_name" => $details["entrust_maker_name"], "remark" => $param["remark"], "create_time" => time() ]; ProjectAudit::create($auditData); if (empty($handle['financial'])) { $handle['financial'] = (array)$details["entrust_maker"]; } else { $handle['financial'] = array_merge($details["entrust_maker"], $handle['financial']); } $this->Pushmessage->pushMessage($detail["project_id"], $handle['financial'], $handle['company']); $this->model->where("id", $id)->update(["status" => 3]); add_project_log("发起删除项目报告审批", $detail["project_id"], $detail["title"]); return to_assign(0, "操作成功"); } /** * 财评 * 同意-报告 */ public function agree_report() { $param = get_params(); $handle = $this->Pushmessage->handleParam($param); $param = $handle['param']; $type = isset($param['type']) ? $param['type'] : 0; if (!isset($param["type"])) { $id = isset($param['id']) ? $param['id'] : 0; $this->model->where("id", $id)->update(["status" => 1]); $detail = $this->model->where("id", $id)->find(); $num = $this->model->where([ ["project_id", "=", $detail["project_id"], ["type", ">", $detail["type"]]], ["status", ">", 1], ["status", "<>", 2], ["status", "<", 4] ])->count(); //type,0初审,1对数,2审定 $report_status = $detail["type"] + 1; if ($num == 0) { $data = ['report_time' => time(), "report_status" => $report_status]; } else { $data = ['report_time' => time()]; } try { Db::name("cost_project")->where("id", $detail["project_id"])->update($data); } catch (DbException $e) { return to_assign(1, '操作失败,原因:' . $e->getMessage()); } try { Db::name("project_audit")->where([["else_id", "=", $id]])->update(["audit_status" => 2, "audit_time" => time()]); } catch (DbException $e) { return to_assign(1, '操作失败,原因:' . $e->getMessage()); } $people = $this->model->where('id', $id)->value("maker_id"); if (empty($handle['company'])) { $handle['company'] = (array)$people; } else { $handle['company'] = array_merge($handle['company'], (array)$people); } $this->Pushmessage->pushMessage($detail["project_id"], $handle['financial'], $handle['company']); } else { $param['audit_time'] = time(); $this->Auditmodel->where('id', $param['id'])->strict(false)->field(true)->update(["audit_status" => 2, "audit_time" => time()]); add_log('edit', $param['id'], $param); $id = $param['id']; unset($param["id"]); $detail = ProjectReport::where("id", $param["else_id"])->find(); $num = $this->model->where([ ["project_id", "=", $detail["project_id"], ["type", ">", $detail["type"]]], ["status", ">", 1], ["status", "<>", 2], ["status", "<", 4] ])->count(); //type,0初审,1对数,2审定 $report_status = $detail["type"] + 1; if ($num == 0) { $data = ['report_time' => time(), "report_status" => $report_status]; } else { $data = ['report_time' => time()]; } $type_status = $detail["status"]; if ($type_status == 0) { ProjectReport::where("id", $param["else_id"])->update(["status" => 1, "update_time" => time()]); $this->CostModel->where('id', $param['project_id'])->strict(false)->update($data); } elseif ($type_status == 3) { ProjectReport::where("id", $param["else_id"])->update(["status" => 4, "update_time" => time()]); } $people = $this->Auditmodel->where('id', $id)->value("sponsor_id"); if (empty($handle['company'])) { $handle['company'] = (array)$people; } else { $handle['company'] = array_merge($handle['company'], (array)$people); } $this->Pushmessage->pushMessage($param['project_id'], $handle['financial'], $handle['company']); add_project_log('审批通过', $param['project_id'], "报告审批通过"); } return to_assign(0, "操作成功"); } /** * 财评 * 不同意-报告 */ public function un_report() { $param = get_params(); $handle = $this->Pushmessage->handleParam($param); $param = $handle['param']; if (!isset($param["type"])) { $id = isset($param['id']) ? $param['id'] : 0; $this->model->where("id", $id)->update(["status" => 2]); try { Db::name("project_audit")->where([["else_id", "=", $id]])->update(["audit_status" => 3, "audit_remark" => $param["audit_remark"]]); } catch (DbException $e) { return to_assign(1, '操作失败,原因:' . $e->getMessage()); } $people = $this->model->where('id', $id)->value("maker_id"); if (empty($handle['company'])) { $handle['company'] = (array)$people; } else { $handle['company'] = array_merge($handle['company'], (array)$people); } $project_id = $this->model->where("id", $id)->value("project_id"); $this->Pushmessage->pushMessage($project_id, $handle['financial'], $handle['company']); } else { $param = get_params(); $handle = $this->Pushmessage->handleParam($param); $param = $handle['param']; try { $param['audit_time'] = time(); $this->Auditmodel->where('id', $param["id"])->strict(false)->field(true)->update(["audit_status" => 3, "audit_remark" => $param["audit_remark"], "audit_time" => time()]); $id = $param['id']; unset($param["id"]); $type_status = Db::name("contact")->where("id", $param["else_id"])->value("status"); if ($type_status == 0) { //新建 Db::name("contact")->where("id", $param["else_id"])->update(["status" => 2, "update_time" => time()]); } elseif ($type_status == 3) { //删除 Db::name("contact")->where("id", $param["else_id"])->update(["status" => 5, "update_time" => time()]); } $people = $this->Auditmodel->where('id', $id)->value("sponsor_id"); if (empty($handle['company'])) { $handle['company'] = (array)$people; } else { $handle['company'] = array_merge($handle['company'], (array)$people); } $this->Pushmessage->pushMessage($param['project_id'], $handle['financial'], $handle['company']); } catch (\Exception $e) { return to_assign(1, '操作失败,原因:' . $e->getMessage()); } } return to_assign(0, "操作成功"); } /** * 财评 * 同意-删除 */ public function agree_delete() { $param = get_params(); $handle = $this->Pushmessage->handleParam($param); $param = $handle['param']; if (!isset($param["type"])) { $id = isset($param['id']) ? $param['id'] : 0; $this->model->where("id", $id)->update(["status" => 4]); $detail = $this->model->where("id", $id)->find(); //type,0初审,1对数,2审定 $num = $this->model->where([ ["project_id", "=", $detail["project_id"], ["type", ">=", $detail["type"]]], ["status", ">", 1], ["status", "<>", 2], ["status", "<", 4] ])->count(); //type,0初审,1对数,2审定 $report_status = $detail["type"]; if ($num == 0) { $data = ['report_time' => time(), "report_status" => $report_status]; } else { $data = ['report_time' => time()]; } try { Db::name("cost_project")->where("id", $detail["project_id"])->update($data); } catch (DbException $e) { return to_assign(1, '操作失败,原因:' . $e->getMessage()); } try { Db::name("project_audit")->where([["else_id", "=", $id]])->update(["audit_status" => 2]); } catch (DbException $e) { return to_assign(1, '操作失败,原因:' . $e->getMessage()); } $people = $this->model->where('id', $id)->value("maker_id"); if (empty($handle['company'])) { $handle['company'] = (array)$people; } else { $handle['company'] = array_merge($handle['company'], (array)$people); } $project_id = $this->model->where("id", $id)->value("project_id"); $this->Pushmessage->pushMessage($project_id, $handle['financial'], $handle['company']); } else { $param['audit_time'] = time(); $this->Auditmodel->where('id', $param['id'])->strict(false)->field(true)->update(["audit_status" => 2, "audit_time" => time()]); $id = $param['id']; unset($param["id"]); $detail = ProjectReport::where("id", $param["else_id"])->find(); $num = $this->model->where([ ["project_id", "=", $detail["project_id"], ["type", ">=", $detail["type"]]], ["status", ">", 1], ["status", "<>", 2], ["status", "<", 4] ])->count(); //type,0初审,1对数,2审定 $report_status = $detail["type"]; if ($num == 0) { $data = ['report_time' => time(), "report_status" => $report_status]; } else { $data = ['report_time' => time()]; } $type_status = $detail["status"]; if ($type_status == 0) { ProjectReport::where("id", $param["else_id"])->update(["status" => 1, "update_time" => time()]); $this->CostModel->where('id', $param['project_id'])->strict(false)->update($data); } elseif ($type_status == 3) { ProjectReport::where("id", $param["else_id"])->update(["status" => 4, "update_time" => time()]); Db::name("cost_project")->where("id", $detail["project_id"])->update(["report_status" => $report_status]); } $people = $this->Auditmodel->where('id', $id)->value("sponsor_id"); if (empty($handle['company'])) { $handle['company'] = (array)$people; } else { $handle['company'] = array_merge($handle['company'], (array)$people); } $this->Pushmessage->pushMessage($param['project_id'], $handle['financial'], $handle['company']); add_project_log('审批通过', $param['project_id'], "报告删除审批通过"); } return to_assign(0, "操作成功"); } /** * 财评 * 不同意-删除 */ public function un_delete() { $param = get_params(); $handle = $this->Pushmessage->handleParam($param); $param = $handle['param']; if (!isset($param["type"])) { $id = isset($param['id']) ? $param['id'] : 0; $this->model->where("id", $id)->update(["status" => 5]); try { Db::name("project_audit")->where([["else_id", "=", $id]])->update(["audit_status" => 3, "audit_remark" => $param["audit_remark"]]); } catch (DbException $e) { return to_assign(1, '操作失败,原因:' . $e->getMessage()); } $people = $this->model->where('id', $id)->value("maker_id"); if (empty($handle['company'])) { $handle['company'] = (array)$people; } else { $handle['company'] = array_merge($handle['company'], (array)$people); } $project_id = $this->model->where("id", $id)->value("project_id"); $this->Pushmessage->pushMessage($project_id, $handle['financial'], $handle['company']); } else { $param = get_params(); $handle = $this->Pushmessage->handleParam($param); $param = $handle['param']; try { $param['audit_time'] = time(); $this->Auditmodel->where('id', $param["id"])->strict(false)->field(true)->update(["audit_status" => 3, "audit_remark" => $param["audit_remark"], "audit_time" => time()]); $id = $param['id']; unset($param["id"]); $type_status = Db::name("contact")->where("id", $param["else_id"])->value("status"); if ($type_status == 0) { //新建 Db::name("contact")->where("id", $param["else_id"])->update(["status" => 2, "update_time" => time()]); } elseif ($type_status == 3) { //删除 Db::name("contact")->where("id", $param["else_id"])->update(["status" => 5, "update_time" => time()]); } $people = $this->Auditmodel->where('id', $id)->value("sponsor_id"); if (empty($handle['company'])) { $handle['company'] = (array)$people; } else { $handle['company'] = array_merge($handle['company'], (array)$people); } $this->Pushmessage->pushMessage($param['project_id'], $handle['financial'], $handle['company']); } catch (\Exception $e) { return to_assign(1, '操作失败,原因:' . $e->getMessage()); } } return to_assign(0, "操作成功"); } /** * 报告附件上传 */ public function add_file_company() { $param = get_params(); // $param['create_time'] = time(); $param['maker_id'] = $this->uid; $file_array = Db::name('file') ->field("f.id,f.name,f.filesize,f.filepath,f.fileext,f.admin_id,f.create_time,a.nickname as admin_name") ->alias("f") // ->field("r.*,a.nickname as admin_name,f.name,f.filesize,f.filepath,f.fileext,f.admin_id") ->join('Admin a', 'f.admin_id = a.id', 'LEFT') ->order('f.create_time desc') ->where(array('f.id' => $param["file"])) ->select()->toArray(); // ->find(); View::assign("file_array", $file_array); return json($file_array); } /** * 查看审批进度 */ public function progress() { $param = get_params(); $id = isset($param['id']) ? $param['id'] : 0; $rows = empty($param['limit']) ? get_config('app . page_size') : $param['limit']; $order = empty($param['order']) ? 'id desc' : $param['order']; $list = $this->Auditmodel->alias('a')->join("cost_project c", "a.project_id=c.id", 'left') ->field("a.*,c.project_status,c.sent_review_amount,c.engineering_type,c.review_unit_name")->where('else_id', $id)->order('create_time', "sec") ->select() ->each(function ($item) { switch ($item["audit_type"]) { case 4: $item->else_name = "报告一级审核"; break; case 5: $item->else_name = "报告二级审核"; break; case 6: $item->else_name = "报告三级审核"; break; } }); View::assign('list', $list); return view(); } }