Datastat = new Datastat($app); $this->AppropriationModel = new AppropriationModel(); $this->Field = new Field($app); $this->model = new CostProjectModel(); $this->Adminmodel = new Admin(); $this->Auditmodel = new AuditModel(); $this->ContactModel = new ContactModel(); $this->uid = get_login_admin('id'); $this->unit = get_login_admin('unit_name'); $this->user_tpe = Db::name("department")->where("id", $this->unit)->value("type"); // $session_admin = get_config('app.session_admin'); // $request = Request::instance(); // if (!Session::has($session_admin) && $request->url() !== '/mobile/index/login.html') { // redirect('/mobile/index/login.html')->send(); // exit; // } } /** * 财评首页 * 通用 */ public function main() { // halt(session::get('gougu_admin')); if (session::get(get_config('app.session_admin')) == NULL) { $param = get_params(); if ($param == NULL) { redirect('/mobile/index/login.html')->send(); } else { // 微信登录 但session为空 $session_admin = get_config('app.session_admin'); $admin = Db::name('Admin')->where('id', $param['admin'])->find(); Session::set($session_admin, $admin); // null $token = make_token(); set_cache($token, $admin, 7200); $admin['token'] = $token; $this->uid = $param['admin']; $this->unit = Db::name('Admin')->where('id', $this->uid)->value('unit_name'); } } //0->财政局,1->业主,2->公司 if ($this->user_tpe == 0) { $sent_review_amount = Db::name("cost_project")->where([ ["entrust_unit", "=", get_login_admin("unit_name")], ['delete_time', '=', 0], ["project_status", ">", 2], ["project_status", "<>", 9], ])->field("sent_review_amount,sent_review_cost,review_add_reduce_rate,authorize_amount,engineering_type1")->select(); } else if ($this->user_tpe == 2) { $sent_review_amount = Db::name("cost_project")->where([ ["review_unit", "=", $this->unit], ['delete_time', '=', 0], ["project_status", ">", 3] ])->field("sent_review_amount,sent_review_cost,review_add_reduce_rate,authorize_amount,engineering_type1")->select(); } else if ($this->user_tpe == 1) { $sent_review_amount = Db::name("cost_project")->where([ ["sent_review_unit", "=", $this->unit], ['delete_time', '=', 0], ["project_status", ">", 2] ])->field("sent_review_amount,sent_review_cost,review_add_reduce_rate,authorize_amount,engineering_type1")->select(); } //engineering_type1=1是预算,2是结算 $amount = [ //送审总额 'sent_review_amount' => 0, //评审服务费 'sent_review_cost' => 0, //审定总额 'authorize_amount' => 0, //总审减率 'review_add_reduce_rate' => 0 ]; $sent_review_amount_tol = [ "sent_review_amount_type1" => 0, "sent_review_amount_type2" => 0, "authorize_amount_type1" => 0, "authorize_amount_type2" => 0, "review_add_reduce_rate_type1" => 0, "review_add_reduce_rate_type2" => 0 ]; for ($i = 0; $i < count($sent_review_amount); $i++) { $a = $sent_review_amount[$i]; if ($a['engineering_type1'] == 1) { if ((int)$a["sent_review_amount"]) { //预算总额 $sent_review_amount_tol["sent_review_amount_type1"] += $a["sent_review_amount"]; } if ((int)$a["authorize_amount"]) { //审定 $sent_review_amount_tol["authorize_amount_type1"] += $a["authorize_amount"]; } } elseif ($a['engineering_type1'] == 2) { if ((int)$a["sent_review_amount"]) { //结算总额 $sent_review_amount_tol["sent_review_amount_type2"] += $a["sent_review_amount"]; } if ((int)$a["authorize_amount"]) { //审定 $sent_review_amount_tol["authorize_amount_type2"] += $a["authorize_amount"]; } } } //什么率的 $sentReviewAmount = 0; $authorizeAmount = 0; $sent_review_amount_type1 = 0; $authorize_amount_type1 = 0; $sent_review_amount_type2 = 0; $authorize_amount_type2 = 0; for ($i = 0; $i < count($sent_review_amount); $i++) { $a = $sent_review_amount[$i]; if ($a['engineering_type1'] == 1 && (int)$a["authorize_amount"]) { if ((int)$a["sent_review_amount"]) { //预算总额 $sent_review_amount_type1 += $a["sent_review_amount"]; //审定 $authorize_amount_type1 += $a["authorize_amount"]; } } elseif ($a['engineering_type1'] == 2) { if ((int)$a["sent_review_amount"] && (int)$a["authorize_amount"]) { //结算总额 $sent_review_amount_type2 += $a["sent_review_amount"]; //审定 $authorize_amount_type2 += $a["authorize_amount"]; } } if ((int)$a["sent_review_amount"] && (int)$a["authorize_amount"]) { //结算总额 $sentReviewAmount += $a["sent_review_amount"]; //审定 $authorizeAmount += $a["authorize_amount"]; } } if ((int)$sent_review_amount_type1 && (int)$authorize_amount_type1) { //预算核增减率 $sent_review_amount_tol["review_add_reduce_rate_type1"] = sprintf("%.4f", ($authorize_amount_type1 - $sent_review_amount_type1) / $sent_review_amount_type1) * 100; } if ($sent_review_amount_type2 && $authorize_amount_type2) { //结算核增减率 $sent_review_amount_tol["review_add_reduce_rate_type2"] = sprintf("%.4f", ($authorize_amount_type2 - $sent_review_amount_type2) / $sent_review_amount_type2) * 100; } if ((int)$sentReviewAmount && (int)$authorizeAmount) { $amount['review_add_reduce_rate'] = (sprintf("%.4f", ($authorizeAmount - $sentReviewAmount) / $sentReviewAmount)) * 100; } for ($i = 0; $i < count($sent_review_amount); $i++) { $a = $sent_review_amount[$i]; if ((int)$a['sent_review_amount']) { $amount["sent_review_amount"] += $a['sent_review_amount']; } if ((int)$a['sent_review_cost']) { $amount["sent_review_cost"] += $a['sent_review_cost']; } if ((int)$a['authorize_amount']) { $amount["authorize_amount"] += $a['authorize_amount']; } } //评审服务费,上半年服务费用,下半年服务费用 start $currentTime = time(); $year = date('Y', $currentTime); // 计算上半年时间范围 $firstHalfStart = strtotime($year . '-01-01'); $firstHalfEnd = strtotime($year . '-06-30 23:59:59'); // 计算下半年时间范围 $secondHalfStart = strtotime($year . '-07-01'); $secondHalfEnd = strtotime($year . '-12-31 23:59:59'); if ($this->user_tpe == 0) { $first_sent_review_cost = Db::name("cost_project")->where([ ['delete_time', '=', 0], ["project_status", ">", 2], ["project_status", "<>", 9], ["entrust_unit", "=", get_login_admin("unit_name")] ])->whereBetween('create_time', [$firstHalfStart, $firstHalfEnd])->field("sent_review_cost")->select(); if (!$first_sent_review_cost->isEmpty()) { $first_sent_review_cost->toArray(); } else { $first_sent_review_cost = []; } $second_sent_review_cost = Db::name("cost_project")->where([ ['delete_time', '=', 0], ["project_status", ">", 2], ["project_status", "<>", 9], ["entrust_unit", "=", get_login_admin("unit_name")] ])->whereBetween('create_time', [$secondHalfStart, $secondHalfEnd])->field("sent_review_cost")->select(); if (!$second_sent_review_cost->isEmpty()) { $second_sent_review_cost->toArray(); } else { $second_sent_review_cost = []; } } else if ($this->user_tpe == 2) { $first_sent_review_cost = Db::name("cost_project")->where([ ['project_status', '>', 3], ["review_unit", "=", get_login_admin("unit_name")], ["project_status", "<>", 7], ["project_status", "<>", 9] ])-> whereBetween('create_time', [$firstHalfStart, $firstHalfEnd])->field("sent_review_cost")->select(); if (!$first_sent_review_cost->isEmpty()) { $first_sent_review_cost->toArray(); } else { $first_sent_review_cost = []; } $second_sent_review_cost = Db::name("cost_project")->where([ ['project_status', '>', 3], ["review_unit", "=", get_login_admin("unit_name")], ["project_status", "<>", 7], ["project_status", "<>", 9] ])-> whereBetween('create_time', [$secondHalfStart, $secondHalfEnd])->field("sent_review_cost")->select(); if (!$second_sent_review_cost->isEmpty()) { $second_sent_review_cost->toArray(); } else { $second_sent_review_cost = []; } } else if ($this->user_tpe == 1) { $first_sent_review_cost = Db::name("cost_project")->where([ ['project_status', '>', 2], ["sent_review_unit", "=", $this->unit] ])-> whereBetween('create_time', [$firstHalfStart, $firstHalfEnd])->field("sent_review_cost")->select(); if (!$first_sent_review_cost->isEmpty()) { $first_sent_review_cost->toArray(); } else { $first_sent_review_cost = []; } $second_sent_review_cost = Db::name("cost_project")->where([ ['project_status', '>', 2], ["sent_review_unit", "=", $this->unit] ])-> whereBetween('create_time', [$secondHalfStart, $secondHalfEnd])->field("sent_review_cost")->select(); if (!$second_sent_review_cost->isEmpty()) { $second_sent_review_cost->toArray(); } else { $second_sent_review_cost = []; } } $sent_review_cost = [ 'first_sent_review_cost' => 0, 'second_sent_review_cost' => 0 ]; for ($i = 0; $i < count($first_sent_review_cost); $i++) { $a = $first_sent_review_cost[$i]; $sent_review_cost["first_sent_review_cost"] += $a['sent_review_cost']; } for ($i = 0; $i < count($second_sent_review_cost); $i++) { $a = $second_sent_review_cost[$i]; $sent_review_cost["second_sent_review_cost"] += $a['sent_review_cost']; } //评审服务费,上半年服务费用,下半年服务费用 end //项目数量,正在作业,已归档 $num = Db::name("cost_project")->where([ ["entrust_unit", "=", $this->unit], ['delete_time', '=', 0], ["project_status", '>', 2], ])->count(); if ($this->user_tpe == 0) { $where = [ ["entrust_unit", "=", $this->unit], ['delete_time', '=', 0], ["project_status", '>', 2], ]; } else if ($this->user_tpe == 2) { $where = [ ["review_unit", "=", $this->unit], ['delete_time', '=', 0], ["project_status", '>', 2], ]; } else if ($this->user_tpe == 1) { $where = [ ["sent_review_unit", "=", $this->unit], ['delete_time', '=', 0], ["project_status", '>', 2], ]; } $data = Db::name("cost_project")->where($where)->select(); // halt($data); $num_project = [ 'num' => 0, "yu" => 0, "jie" => 0, "zuo" => 0, "gui" => 0, "tui" => 0, ]; foreach ($data as $key => $value) { $num_project["num"] += 1; if ($value["project_status"] < 6 && $value["project_status"] > 3) { $num_project["zuo"] += 1; } if ($value["project_status"] < 8 && $value["project_status"] > 3) { if ($value["engineering_type1"] == 1) { $num_project["yu"] += 1; } if ($value["engineering_type1"] == 2) { $num_project["jie"] += 1; } } if ($value["project_status"] == 8) { $num_project["gui"] += 1; } if ($value["project_status"] == 9) { $num_project["tui"] += 1; } } $sent_review_cost_real = []; foreach ($sent_review_cost as $item => $value) { $sent_review_cost_real[$item] = number_format($value / 10000, 2, ".", ""); } $sent_review_amount_tol_real = []; foreach ($sent_review_amount_tol as $item => $value) { if (!($item == "review_add_reduce_rate_type1" || $item == "review_add_reduce_rate_type2")) { $sent_review_amount_tol_real[$item] = number_format($value / 10000, 2, ".", ""); } else { $sent_review_amount_tol_real[$item] = number_format($value, 2, ".", ""); } } $amount_real = []; foreach ($amount as $item => $value) { if ($item == "review_add_reduce_rate") { $amount_real[$item] = number_format($value, 2, ".", ""); } else { $amount_real[$item] = number_format($value / 10000, 2, ".", ""); } } $red = $this->Auditmodel->where("approver", $this->uid)->where("audit_status", 1)->count(); $red_id = Db::name("new_msg")->where("uid", "=", $this->uid)->select(); $red_kan = 0; foreach ($red_id as $item => $value) { if ($value["detail"] || $value["comment"] || $value["report"] || $value["user"] || $value["contact"]) { $red_kan = 1; } } $unread_id = Db::name("admin")->where("id", $this->uid)->value("unread"); if (empty($unread_id)) { $unread_id = 0; } else { $unread_id = 1; } View::assign("red_kan", $red_kan); View::assign("sent_review_cost", $sent_review_cost_real); View::assign("amount", $amount_real); View::assign("num", $num); View::assign("num_project", $num_project); View::assign("sent_review_amount_tol", $sent_review_amount_tol_real); View::assign("red", $red); View::assign("red_notice", $unread_id); return View(); } /** * 公司首页 */ public function main_company() { $sent_review_amount = Db::name("cost_project")->where([ ["review_unit", "=", get_login_admin("unit_name")], ['delete_time', '=', 0], ['project_status', '>', 3], ])->field("sent_review_amount,sent_review_cost,review_add_reduce_rate,authorize_amount,engineering_type1")->select(); //engineering_type1=1是预算,2是结算 $amount = [ //送审总额 'sent_review_amount' => 0, //评审服务费 'sent_review_cost' => 0, //审定总额 'authorize_amount' => 0, //总审减率 'review_add_reduce_rate' => 0 ]; $sent_review_amount_tol = [ "sent_review_amount_type1" => 0, "sent_review_amount_type2" => 0, "authorize_amount_type1" => 0, "authorize_amount_type2" => 0, "review_add_reduce_rate_type1" => 0, "review_add_reduce_rate_type2" => 0 ]; for ($i = 0; $i < count($sent_review_amount); $i++) { $a = $sent_review_amount[$i]; if ($a['engineering_type1'] == 1) { if ((int)$a["sent_review_amount"] && (int)$a["authorize_amount"]) { //预算总额 $sent_review_amount_tol["sent_review_amount_type1"] += $a["sent_review_amount"]; //审定 $sent_review_amount_tol["authorize_amount_type1"] += $a["authorize_amount"]; } } elseif ($a['engineering_type1'] == 2) { if ((int)$a["sent_review_amount"] && (int)$a["authorize_amount"]) { //结算总额 $sent_review_amount_tol["sent_review_amount_type2"] += $a["sent_review_amount"]; //审定 $sent_review_amount_tol["authorize_amount_type2"] += $a["authorize_amount"]; } } } if ((int)$sent_review_amount_tol["sent_review_amount_type1"] && (int)$sent_review_amount_tol["authorize_amount_type1"]) { //预算核增减率 $sent_review_amount_tol["review_add_reduce_rate_type1"] = (sprintf("%.4f", ($sent_review_amount_tol["authorize_amount_type1"] - $sent_review_amount_tol["sent_review_amount_type1"]) / $sent_review_amount_tol["sent_review_amount_type1"])) * 100; } if ((int)$sent_review_amount_tol["sent_review_amount_type2"] && (int)$sent_review_amount_tol["authorize_amount_type2"]) { //结算核增减率 $sent_review_amount_tol["review_add_reduce_rate_type2"] = (sprintf("%.4f", ($sent_review_amount_tol["authorize_amount_type2"] - $sent_review_amount_tol["sent_review_amount_type2"]) / $sent_review_amount_tol["sent_review_amount_type2"])) * 100; } for ($i = 0; $i < count($sent_review_amount); $i++) { $a = $sent_review_amount[$i]; if ((int)$a['sent_review_amount'] && (int)$a['sent_review_cost'] && (int)$a['authorize_amount']) { $amount["sent_review_amount"] += $a['sent_review_amount']; $amount["sent_review_cost"] += $a['sent_review_cost']; $amount["authorize_amount"] += $a['authorize_amount']; } } if ((int)$amount['sent_review_amount'] && (int)$amount["authorize_amount"]) { $amount['review_add_reduce_rate'] = (sprintf("%.4f", ($amount["authorize_amount"] - $amount["sent_review_amount"]) / $amount["sent_review_amount"])) * 100; } //评审服务费,上半年服务费用,下半年服务费用 start $currentTime = time(); $year = date('Y', $currentTime); // 计算上半年时间范围 $firstHalfStart = strtotime($year . '-01-01'); $firstHalfEnd = strtotime($year . '-06-30 23:59:59'); // 计算下半年时间范围 $secondHalfStart = strtotime($year . '-07-01'); $secondHalfEnd = strtotime($year . '-12-31 23:59:59'); $first_sent_review_cost = Db::name("cost_project")->where([ ['project_status', '>', 2], ["review_unit", "=", get_login_admin("unit_name")] ])-> whereBetween('create_time', [$firstHalfStart, $firstHalfEnd])->field("sent_review_cost")->select()->toArray(); $second_sent_review_cost = Db::name("cost_project")->where([ ['project_status', '>', 2], ["review_unit", "=", get_login_admin("unit_name")] ])-> whereBetween('create_time', [$secondHalfStart, $secondHalfEnd])->field("sent_review_cost")->select()->toArray(); $sent_review_cost = [ 'first_sent_review_cost' => 0, 'second_sent_review_cost' => 0 ]; for ($i = 0; $i < count($first_sent_review_cost); $i++) { $a = $first_sent_review_cost[$i]; $sent_review_cost["first_sent_review_cost"] += $a['sent_review_cost']; } for ($i = 0; $i < count($second_sent_review_cost); $i++) { $a = $second_sent_review_cost[$i]; $sent_review_cost["second_sent_review_cost"] += $a['sent_review_cost']; } //评审服务费,上半年服务费用,下半年服务费用 end //项目数量,正在作业,已归档 $num = Db::name("cost_project")->where([ ["review_unit", "=", get_login_admin("unit_name")], ['delete_time', '=', 0], ["project_status", '>', 3], ])->count(); $where = [ ["review_unit", "=", get_login_admin("unit_name")], ['delete_time', '=', 0], ["project_status", ">", 3] ]; $data = Db::name("cost_project")->where($where)->select(); $num_project = [ 'num' => 0, "yu" => 0, "jie" => 0, "zuo" => 0, "gui" => 0, "tui" => 0, ]; foreach ($data as $key => $value) { $num_project["num"] += 1; if ($value["project_status"] < 6 && $value["project_status"] > 3) { $num_project["zuo"] += 1; } if ($value["engineering_type1"] == 1) { $num_project["yu"] += 1; } if ($value["engineering_type1"] == 2) { $num_project["jie"] += 1; } if ($value["project_status"] == 8) { $num_project["gui"] += 1; } if ($value["project_status"] == 9) { $num_project["tui"] += 1; } } $red_id = Db::name("new_msg")->where("uid", "=", $this->uid)->select(); $red_kan = 0; foreach ($red_id as $item => $value) { if ($value["detail"] || $value["comment"] || $value["report"] || $value["user"] || $value["contact"]) { $red_kan = 1; } } View::assign("red_kan", $red_kan); View::assign("sent_review_cost", $sent_review_cost); View::assign("amount", $amount); View::assign("num", $num); View::assign("num_project", $num_project); View::assign("sent_review_amount_tol", $sent_review_amount_tol); return View(); } /** * cp看板列表 */ public function kan_list() { //根据所登录的账号,查询跟本身有关的项目 //2是公司,0是财政局,1是业主 $param = get_params(); $rows = empty($param['limit']) ? get_config('app . page_size') : $param['limit']; $order = empty($param['order']) ? 'id desc' : $param['order']; if (isset($param["project_start_time"])) { $param["project_start_time"] = $param["project_start_time"] ? strtotime($param["project_start_time"]) : 0; } if (isset($param["project_end_time"])) { $param["project_end_time"] = $param["project_end_time"] ? strtotime($param["project_end_time"]) : 0; } $where3 = [];//搜索条件 if (!empty($param['project_status'])) { $where3[] = ['project_status', '=', $param['project_status']]; } if (!empty($param['province'])) { $where3[] = ['province', '=', $param['province']]; } if (!empty($param['city'])) { $where3[] = ['city', '=', $param['city']]; } if (!empty($param['area'])) { $where3[] = ['area', '=', $param['area']]; } if (!empty($param['project_end_time'])) { $where3[] = ['project_end_time', '<', $param['project_end_time']]; } if (!empty($param['project_start_time'])) { $where3[] = ['project_start_time', '>', $param['project_start_time']]; } if (!empty($param['keyword'])) { $keyword = $param['keyword']; $where3[] = ['project_num|project_name|review_unit', 'like', '%' . $keyword . '%']; } if (!empty($param['review_unit_name'])) { $where3[] = ['review_unit_name', 'like', '%' . $param['review_unit_name'] . '%']; } if (!empty($param['sent_review_unit_name'])) { $where3[] = ['sent_review_unit_name', 'like', '%' . $param['sent_review_unit_name'] . '%']; } if (!empty($param['entrust_unit_name'])) { $where3[] = ['entrust_unit_name', 'like', '%' . $param['entrust_unit_name'] . '%']; } $unit_type = Db::name("department")->where("id", get_login_admin("unit_name"))->value("type"); $inarr = array(); if ($unit_type == 0) { $where[] = ["delete_time", "=", 0]; $where[] = ["project_status", ">", 0]; $where[] = ["entrust_unit", "=", get_login_admin('unit_name')]; $where2[] = ["delete_time", "=", 0]; $where2[] = ["project_status", ">", 0]; $where2[] = ["entrust_unit", "=", get_login_admin('unit_name')]; //项目可见的权限 $field = $this->Field->get_field_rules_new($this->uid); //1全部-可查看可编辑,2全部-可查看,0与我有关 $see_auth = isset($field["see_auth"]) ? $field["see_auth"] : 3; if ($see_auth == 3) { $where[] = ["entrust_maker", "=", $this->uid]; $where2[] = ["entrust_approver", "=", $this->uid]; $where2[] = ["project_status", ">", 1]; } elseif ($see_auth == 0) { $where[] = ["entrust_maker", "=", $this->uid]; $where[] = ["project_status", ">", 0]; $where2[] = ["entrust_approver", "=", $this->uid]; $where2[] = ["project_status", ">", 1]; } $list = $this->model->where($where3) ->where(function ($query) use ($where,$where2) { // 第一组条件(entrust_maker) $query->where(function ($q1) use ($where) { $q1->where($where); }); // 使用 OR 连接第二组条件(entrust_approver) $query->whereOr(function ($q2) use ($where2) { $q2->where($where2); }); }) ->order("create_time desc")->paginate(9999, false, ['query' => $param]) ->each(function ($item) { $red = Db::name("new_msg")->where([["project_id", "=", $item->id], ["uid", "=", $this->uid]])->find(); if ($red) { if ($red["detail"] || $red["comment"] || $red["report"] || $red["user"] || $red["contact"]) { $item->red = 1; } else { $item->red = 0; } } else { $item->red = 0; } if (($item->province && $item->city && $item->area)) { $item->project_region = $item->province . '-' . $item->city . '-' . $item->area; } })->toArray(); } elseif ($unit_type == 2) { $order = empty($param['order']) ? 'project_receive_time desc,id desc' : $param['order']; $where = [ ["delete_time", "=", 0], ["project_status", ">", 3], ["review_unit", "=", get_login_admin("unit_name")] ]; $review_unit = $this->model->where($where)->where($where3)->field('id,review_head,operate_head,operate_team')->select()->toArray(); for ($i = 0; $i < count($review_unit); $i++) { $a = $review_unit[$i]; $ids = $a["review_head"] . ',' . $a["operate_head"] . ',' . $a["operate_team"]; $ids = explode(",", $ids); $c = in_array($this->uid, $ids); if ($c) { $inarr[] = $a["id"]; } } $field = $this->Field->get_field_rules_New($this->uid); $see_auth = isset($field["see_auth"]) ? $field["see_auth"] : 3; $this->see_auth = $see_auth; if ($see_auth == 3) { $list = $this->model ->where($where)->where($where3)->whereIn("id", $inarr) ->order($order)->paginate(9999, false, ['query' => $param]) ->each(function ($item) { $red = Db::name("new_msg")->where([["project_id", "=", $item->id], ["uid", "=", $this->uid]])->find(); if ($red) { if ($red["detail"] || $red["comment"] || $red["report"] || $red["record"] || $red["user"] || $red["contact"]) { $item->red = 1; } else { $item->red = 0; } } else { $item->red = 0; } })->toArray(); } elseif ($see_auth == 0) { $list = $this->model ->where($where)->where($where3)->whereIn("id", $inarr) ->order($order)->paginate(9999, false, ['query' => $param]) ->each(function ($item) { $red = Db::name("new_msg")->where([["project_id", "=", $item->id], ["uid", "=", $this->uid]])->find(); if ($red) { if ($red["detail"] || $red["comment"] || $red["report"] || $red["record"] || $red["user"] || $red["contact"]) { $item->red = 1; } else { $item->red = 0; } } else { $item->red = 0; } })->toArray(); } else { $list = $this->model ->where($where) ->order($order)->where($where3)->paginate(9999, false, ['query' => $param]) ->each(function ($item) { $red = Db::name("new_msg")->where([["project_id", "=", $item->id], ["uid", "=", $this->uid]])->find(); if ($red) { if ($red["detail"] || $red["comment"] || $red["report"] || $red["record"] || $red["user"] || $red["contact"]) { $item->red = 1; } else { $item->red = 0; } } else { $item->red = 0; } })->toArray(); } } elseif ($unit_type == 1) { $field = $this->Field->get_field_rules_New($this->uid); $see_auth = isset($field["see_auth"]) ? $field["see_auth"] : 3; if ($see_auth == 0 || $see_auth == 3) { $where = [ ["delete_time", "=", 0], ["sent_review_unit", "=", get_login_admin("unit_name")], ["sent_review_head", "=", $this->uid] ]; } else { $where = [ ["delete_time", "=", 0], ["sent_review_unit", "=", get_login_admin("unit_name")] ]; } $list = $this->model ->where($where) ->order($order)->where($where3)->paginate(9999, false, ['query' => $param]) ->each(function ($item) { $red = Db::name("new_msg")->where([["project_id", "=", $item->id], ["uid", "=", $this->uid]])->find(); if ($red) { if ($red["detail"] || $red["comment"] || $red["report"] || $red["record"] || $red["user"] || $red["contact"]) { $item->red = 1; } else { $item->red = 0; } } else { $item->red = 0; } })->toArray(); } else { $list["data"] = []; } $data = $list["data"]; $real_list = array_values(array_column($data, NULL, 'id')); $red = $this->Auditmodel->where("approver", $this->uid)->where("audit_status", 1)->count(); $red_id = Db::name("new_msg")->where("uid", "=", $this->uid)->select(); $red_kan = 0; foreach ($red_id as $item => $value) { if ($value["detail"] || $value["comment"] || $value["report"] || $value["user"] || $value["contact"]) { $red_kan = 1; } } // halt($real_list); View::assign("red_kan", $red_kan); View::assign("detail", $real_list); View::assign("red", $red); View::assign("unit_type", $unit_type); return view(); } public function pending_invite() { $param = get_params(); $unit_type = Db::name("department")->where("id", get_login_admin("unit_name"))->value("type"); $where1 = []; //2是公司,0是财政局,1是业主 if ($unit_type == 0) { if (!empty($param['invite_keyword'])) { $keyword = $param['invite_keyword']; $where1[] = ['review_unit_name', 'like', '%' . $keyword . '%']; } $order = empty($param['order']) ? 'id desc' : $param['order']; $Appropriationlist = $this->AppropriationModel->where("entrust_unit", get_login_admin("unit_name")) ->where("status",">",0)->where($where1) ->order( $order)->paginate(9999, false, ['query' => $param]) ->each(function ($item) { $data = Db::name("appropriation_project")->alias("a")->join("cost_project c","a.project_id=c.id","left") ->where("a.uid","not null")->where("a.uid",$item->id) ->where("c.entrust_unit",get_login_admin("unit_name"))->column("c.project_name,c.sent_review_cost"); if (!empty($data)) { $a = 0; $project_name = []; $appropriation_amount = 0; foreach ($data as $key => $value) { $a += 1; $project_name[] = $a . "." . $value["project_name"]; $appropriation_amount += $value["sent_review_cost"]; } $item->a = count($data); $item->appropriation_amount = $appropriation_amount; $item->project_names = $project_name; } }); } else if($unit_type == 2) { $where = [ ["a.approver", "=", $this->uid], ["a.audit_type", ">", 3], ["a.audit_status", "<", 5] ]; $order = empty($param['order']) ? 'id desc' : $param['order']; if (!empty($param['invite_keyword'])) { $keyword = $param['invite_keyword']; $where[] = ['entrust_unit_name', 'like', '%' . $keyword . '%']; } $Appropriationlist = $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($where)->order($order) ->paginate(9999, false, ['query' => $param]) ->where('audit_type','in',[10,11,12]) ->each(function ($item){ switch ($item["audit_type"]) { case 10: $item->else_name = "请款一级审核"; break; case 11: $item->else_name = "请款二级审核"; break; case 12: $item->else_name = "请款三级审核"; break; } }); } $app_red = 0; if($this->user_tpe==0){ $app_where=[ ["status","=",1], ["entrust_unit","=",get_login_admin("unit_name")] ]; if(Db::name("appropriation")->where($app_where)->count()>0){$app_red=1;} }else if($this->user_tpe==2){ //10请款一审,11请款二审,12,请款三审 $app_where=[ ["audit_type",">",9], ["audit_type","<",13], ["audit_status","=",1], ["approver","=",$this->uid] ]; if($this->Auditmodel->where($app_where)->count()>0){$app_red=1;} } //红点 $where = [ ["approver", "=", $this->uid], ["audit_status", "<", 5] ]; $list = $this->Auditmodel->alias("a")->join("cost_project c", "a.project_id=c.id", "left") ->where($where)->field("a.*,c.project_num,c.project_status,c.engineering_type,c.sent_review_amount") ->paginate(9999, false, ['query' => $param]) ->each(function ($item, $key) { $item->approver_name = Db::name("admin")->where("id", $item->approver)->value("nickname"); })->toArray(); $red = 0; foreach ($list["data"] as $item => $value) { if ($value["audit_status"] == 1) { $red = 1; } } $red_id = Db::name("new_msg")->where("uid", "=", $this->uid)->select(); $red_kan = 0; foreach ($red_id as $item => $value) { if ($value["detail"] || $value["comment"] || $value["report"] || $value["user"] || $value["contact"]) { $red_kan = 1; } } View::assign('unit_type', $unit_type); View::assign('list', $Appropriationlist); View::assign("red_kan", $red_kan); View::assign('red', $red); View::assign('app_red', $app_red); return view(); } /** * cp待办列表 */ public function pending() { $param = get_params(); //1项目,2报告,3联系函,4公司一级审核,5公司二级审核,6公司三级审核,7联系函一审,8联系过二审,9联系函三审,10请款一审,11请款二审,12,请款三审,14报告四审,15报告五审 $where = [ ["approver", "=", $this->uid], ["audit_status", "<", 5], ["audit_type", "<>", 10], ["audit_type", "<>", 11], ["audit_type", "<>", 12], ]; if (!empty($param['project_status'])) { $where[] = ['c.project_status', '=', $param['project_status']]; } if (!empty($param['province'])) { $where[] = ['c.province', '=', $param['province']]; } if (!empty($param['city'])) { $where[] = ['c.city', '=', $param['city']]; } if (!empty($param['area'])) { $where[] = ['c.area', '=', $param['area']]; } if (!empty($param['project_end_time'])) { $where[] = ['c.project_end_time', '<', $param['project_end_time']]; } if (!empty($param['project_start_time'])) { $where[] = ['c.project_start_time', '>', $param['project_start_time']]; } if (!empty($param['keyword'])) { $keyword = $param['keyword']; $where[] = ['c.project_num|c.project_name|c.review_unit', 'like', '%' . $keyword . '%']; } if (!empty($param['list_keyword'])) { $keyword = $param['list_keyword']; $where[] = ['c.project_name', 'like', '%' . $keyword . '%']; } $rows = empty($param['limit']) ? get_config('app . page_size') : $param['limit']; $order = empty($param['order']) ? 'id desc' : $param['order']; $app_red = 0; if($this->user_tpe==0){ $app_where=[ ["status","=",1], ["entrust_unit","=",get_login_admin("unit_name")] ]; if(Db::name("appropriation")->where($app_where)->count()>0){$app_red=1;} }else if($this->user_tpe==2){ //10请款一审,11请款二审,12,请款三审 $app_where=[ ["audit_type",">",9], ["audit_type","<",13], ["audit_status","=",1], ["approver","=",$this->uid] ]; if($this->Auditmodel->where($app_where)->count()>0){$app_red=1;} } $list = $this->Auditmodel->alias("a")->join("cost_project c", "a.project_id=c.id", "left")->where($where)->field("a.*,c.project_num,c.project_status,c.engineering_type,c.sent_review_amount") ->order($order)->paginate(9999, false, ['query' => $param]) ->each(function ($item, $key) { $item->approver_name = Db::name("admin")->where("id", $item->approver)->value("nickname"); })->toArray(); $red = 0; foreach ($list["data"] as $item => $value) { if ($value["audit_status"] == 1) { $red = 1; } } $red_id = Db::name("new_msg")->where("uid", "=", $this->uid)->select(); $red_kan = 0; foreach ($red_id as $item => $value) { if ($value["detail"] || $value["comment"] || $value["report"] || $value["user"] || $value["contact"]) { $red_kan = 1; } } $real_list = []; foreach ($list["data"] as $item => $value) { if (in_array($value["audit_type"], [2,4, 5, 6,14,15])) { $a = Db::name("project_report")->where("id", $value["else_id"])->field("title,status")->find(); $value["else_name"] = $a["title"]; $value["else_status"] = $a["status"]; } elseif (in_array($value["audit_type"], [3,7, 8, 9])) { $a = Db::name("contact")->where("id", $value["else_id"])->field("title,status")->find(); $value["else_name"] = $a["title"]; $value["else_status"] = $a["status"]; } //,14报告四审,15报告五审 if (in_array($value["audit_type"], [4, 5, 6,14,15])) { switch ($value["audit_type"]) { case 4: $value["audit_name"] = "报告一审"; break; case 5: $value["audit_name"] = "报告二审"; break; case 6: $value["audit_name"] = "报告三审"; break; case 14: $value["audit_name"] = "报告四审"; break; case 15: $value["audit_name"] = "报告五审"; break; } } elseif (in_array($value["audit_type"], [7, 8, 9])) { switch ($value["audit_type"]) { case 7: $value["audit_name"] = "联系函一审"; break; case 8: $value["audit_name"] = "联系函二审"; break; case 9: $value["audit_name"] = "联系函三审"; break; } } elseif (in_array($value["audit_type"], [10, 11, 12])) { switch ($value["audit_type"]) { case 10: $value["audit_name"] = "请款一审"; break; case 11: $value["audit_name"] = "请款二审"; break; case 12: $value["audit_name"] = "请款三审"; break; } } $real_list[] = $value; } // halt($real_list); View::assign("red_kan", $red_kan); View::assign('app_red', $app_red); View::assign('red', $red); View::assign('list', $real_list); // halt($real_list); return view(); } /** *个人资料 */ public function person() { $person = get_login_admin(); $red = $this->Auditmodel->where("approver", $this->uid)->where("audit_status", 1)->count(); $red_id = Db::name("new_msg")->where("uid", "=", $this->uid)->select(); $red_kan = 0; foreach ($red_id as $item => $value) { if ($value["detail"] || $value["comment"] || $value["report"] || $value["user"] || $value["contact"]) { $red_kan = 1; } } View::assign("red_kan", $red_kan); View::assign('red', $red); View::assign('person', $person); return view(); } /** * cp看板内容 */ public function detail() { $param = get_params(); $id = isset($param['id']) ? $param['id'] : 0; $type = isset($param['type']) ? $param['type'] : 0; $rows = empty($param['limit']) ? get_config('app.page_size') : $param['limit']; $order = empty($param['order']) ? 'a.id desc' : $param['order']; $detail = $this->model->getCostProjectById($id); $comment = Db::name("project_comment")->where("project_id", $id)->order('create_time', 'desc')->select(); $file_array = Db::name('ProjectFile') ->field('mf.id,mf.topic_id,mf.admin_id,f.name,f.filesize,f.filepath,f.fileext,f.create_time,f.admin_id,a.nickname as admin_name') ->alias('mf') ->join('File f', 'mf.file_id = f.id', 'LEFT') ->join('Admin a', 'mf.admin_id = a.id', 'LEFT') ->order('mf.create_time desc') ->where(array('mf.topic_id' => $id, 'mf.module' => 'project')) ->select()->toArray(); $report = Db::name("project_report") ->where([["project_id", "=", $id]]) ->alias("r")->join("admin a", "r.maker_id = a.id") ->field("r.*,a.nickname") ->select(); $contact = $this->ContactModel->where([['project_id', '=', $id]]) ->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(9999, false, ['query' => $param]) ->each(function ($item, $key) { })->toArray(); $contact = $contact['data']; $where = [ ["cp_project_record.delete_time", "=", 0], ["project_id", "=", $id], ["maker_id", "=", get_login_admin('id')] ]; $record = Db::name('project_record')->where($where) ->field('a.*,u.nickname as admin_name') ->alias('a') ->join('Admin u', 'a.maker_id = u.id', "left") ->order($order) ->select(); //2是公司,0是财政局,1是业主 $unit_type = Db::name("department")->where("id", get_login_admin("unit_name"))->value("type"); if ($unit_type == 0) { $person = self::user($id); View::assign('project_five', self::getProjectFive()); } elseif ($unit_type == 2) { $person = self::user($id); View::assign('project_five', self::getProjectFiveCompany()); } else { $person = 0; View::assign('project_five', self::getProjectFiveYezhu()); } $appropriation_uid = Db::name("appropriation_project")->where("project_id", $id)->value("uid"); if (empty($appropriation_uid)) { $appropriation_data = []; $appropriation_file_array = []; } else { $where = [ ["id", "=", $appropriation_uid], ["status", ">", 0] ]; //请款 $appropriation = Db::name("appropriation")->where($where)->find(); if (!empty($appropriation)) { $projects = Db::name("appropriation_project")->alias("a") ->leftJoin("cost_project c", "a.project_id=c.id") ->where("uid", $appropriation["id"])->column("c.project_name,c.sent_review_cost"); $data = []; $appropriation_amount = 0; for ($i = 0; $i < count($projects); $i++) { $v = $projects[$i]; $b = $i + 1; $appropriation_amount += $v["sent_review_cost"]; $data[] = $b . "." . $v["project_name"]; } $appropriation_data = $appropriation; $appropriation_data["appropriation_amount"] = $appropriation_amount; $appropriation_data["project_name"] = $data; $appropriation_file_array = Db::name('ProjectFile') ->field('mf.id,mf.topic_id,mf.admin_id,f.name,f.filesize,f.filepath,f.fileext,f.create_time,f.admin_id,a.nickname as admin_name') ->alias('mf') ->join('File f', 'mf.file_id = f.id', 'LEFT') ->join('Admin a', 'mf.admin_id = a.id', 'LEFT') ->order('mf.create_time desc') ->where(array('mf.topic_id' => $appropriation_uid, 'mf.module' => 'appropriation')) ->select()->toArray(); } else { $appropriation_data = []; $appropriation_file_array = []; } } $project_log = self::project_log($id); $red = Db::name("new_msg")->where([["uid", '=', $this->uid], ["project_id", "=", $id]])->field('detail,comment,report,user,contact')->find(); if (empty($red)) { $red = ["detail" => 0, "comment" => 0, "report" => 0, "user" => 0, "contact" => 0]; } $field = $this->Field->get_field_rules_new($this->uid); $fields = []; foreach ($field as $k=>$v){ if($v==1){ $fields[$k] = true; }else{ $fields[$k] = false; } } if($this->user_tpe==2){ $fields["sent_review_approver_amount"] = false; $fields["construction_approver_amount"] = false; } View::assign('field', $fields); if (!empty($detail)) { View::assign('project_log', $project_log); View::assign('project_id', $id); View::assign('comment', $comment); View::assign('record', $record); View::assign('contact', $contact); View::assign('detail', $detail); View::assign('appropriation', $appropriation_data); View::assign('file_array', $file_array); View::assign('appropriation_file_array', $appropriation_file_array); View::assign('report', $report); View::assign('person', $person); View::assign('red', $red); View::assign('unit_type', $unit_type); return view(); } else { throw new \think\exception\HttpException(404, '找不到页面'); } } /** * cp代办内容 */ public function pdetail() { $param = get_params(); $id = isset($param['id']) ? $param['id'] : 0; $type = isset($param['type']) ? $param['type'] : 0; $rows = empty($param['limit']) ? get_config('app.page_size') : $param['limit']; $order = empty($param['order']) ? 'a.id desc' : $param['order']; $detail = $this->model->getCostProjectById($id); $comment = Db::name("project_comment")->where("project_id", $id)->order('create_time', 'desc')->select(); $file_array = Db::name('ProjectFile') ->field('mf.id,mf.topic_id,mf.admin_id,f.name,f.filesize,f.filepath,f.fileext,f.create_time,f.admin_id,a.nickname as admin_name') ->alias('mf') ->join('File f', 'mf.file_id = f.id', 'LEFT') ->join('Admin a', 'mf.admin_id = a.id', 'LEFT') ->order('mf.create_time desc') ->where(array('mf.topic_id' => $id, 'mf.module' => 'project')) ->select()->toArray(); $report = Db::name("project_report")->where([["project_id", "=", $id], ["r.status", "=", 1]])->alias("r")->join("admin a", "r.maker_id = a.id")->field("r.*,a.nickname")->select(); $contact = $this->ContactModel->where([['project_id', '=', $id]]) ->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(9999, false, ['query' => $param]) ->each(function ($item, $key) { })->toArray(); $contact = $contact['data']; $where = [ ["cp_project_record.delete_time", "=", 0], ["project_id", "=", $id], ["maker_id", "=", get_login_admin('id')] ]; $record = Db::name('project_record')->where($where) ->field('a.*,u.nickname as admin_name') ->alias('a') ->join('Admin u', 'a.maker_id = u.id', "left") ->order($order) ->select(); //2是公司,0是财政局,1是业主 $unit_type = Db::name("department")->where("id", get_login_admin("unit_name"))->value("type"); if ($unit_type == 0) { $person = self::user($id); View::assign('project_five', self::getProjectFive()); } elseif ($unit_type == 2) { $person = self::user($id); View::assign('project_five', self::getProjectFiveCompany()); } else { $person = 0; View::assign('project_five', self::getProjectFiveYezhu()); } $field = $this->Field->get_field_rules_new($this->uid); $fields = []; foreach ($field as $k=>$v){ if($v==1){ $fields[$k] = true; }else{ $fields[$k] = false; } } if($this->user_tpe==2){ $fields["sent_review_approver_amount"] = false; $fields["construction_approver_amount"] = false; } View::assign('field', $fields); $project_log = self::project_log($id); // halt($detail); if (!empty($detail)) { View::assign('project_log', $project_log); View::assign('project_id', $id); View::assign('comment', $comment); View::assign('record', $record); View::assign('contact', $contact); View::assign('detail', $detail); View::assign('file_array', $file_array); View::assign('report', $report); View::assign('person', $person); return view(); } else { echo '