Field = new Field($this->app); $this->Costmodel = new CostProjectModel(); $this->filemodel = new ProjectFile(); $this->model = new AppropriationModel(); $this->uid = get_login_admin("id"); $this->nickname = get_login_admin("nickname"); } public function datalist() { if (request()->isAjax()) { $param = get_params(); $where = []; if(!empty($param["keywords"])){ $where[] = ["review_unit_name","like","%".$param["keywords"]."%"]; } $rows = empty($param['limit']) ? get_config('app . page_size') : $param['limit']; $order = empty($param['order']) ? 'id desc' : $param['order']; $list = $this->model->where("entrust_unit", get_login_admin("unit_name")) ->where("status",">",0) ->where($where) ->order($order)->paginate($rows, 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; } }); return table_assign(0, '', $list); } else{ // $field = $this->Field->get_field_rules_new($this->uid); // $see_auth = isset($field["see_auth"]) ? $field["see_auth"] : 3; $where[] = ["delete_time", "=", 0]; $where[] = ["entrust_unit", "=", get_login_admin('unit_name')]; $where[] = ["project_status", ">", 2]; $where[] = ["project_status", "<>", 9]; // $where2[] = ["delete_time", "=", 0]; // $where2[] = ["entrust_unit", "=", get_login_admin('unit_name')]; // $where2[] = ["project_status", ">", 2]; // $where2[] = ["project_status", "<>", 8]; // if ($see_auth == 3) { // $where[] = ["entrust_maker", "=", $this->uid]; // $where2[] = ["entrust_approver", "=", $this->uid]; // } elseif ($see_auth == 0) { // $where[] = ["entrust_maker", "=", $this->uid]; // $where2[] = ["entrust_approver", "=", $this->uid]; // // } $list = $this->Costmodel->where($where)->column("sent_review_cost"); $data = Db::name("appropriation")->alias("a")->leftJoin("appropriation_project p","a.id=p.uid")->leftJoin("cost_project c","p.project_id=c.id") ->where("p.uid","not null") ->where("a.status","2") ->where("c.entrust_unit",get_login_admin("unit_name"))->column("c.id"); $appropriation = $this->model->where([["entrust_unit","=", get_login_admin("unit_name")],["status","=",2]])->paginate(10000, false, ['query' => []]); $sent_review_cost = 0.00; $invoicing_amount = 0.00; $appropriation_amount = 0.00; foreach ($list as $item=>$value){ //送审服务费 $sent_review_cost += (float)sprintf("%01.2f", $value); $sent_review_cost = number_format($sent_review_cost, 2, '.', ''); } foreach ($appropriation as $item=>$value){ if($value["invoice_status"]==1){ //开票金额 $invoicing_amount += (float)$value["invoicing_amount"]; $invoicing_amount = number_format($invoicing_amount, 2, '.', ''); } } $invoicing_amount = number_format($invoicing_amount, 2, '.', ''); $list_ids = $this->Costmodel->where($where)->column("id,sent_review_cost"); foreach ($list_ids as $item=>$value){ //已请款 if(in_array($value["id"],$data)){ $appropriation_amount += (float)$value["sent_review_cost"]; $appropriation_amount = number_format($appropriation_amount, 2, '.', ''); } } $appropriation_amount = number_format($appropriation_amount, 2, '.', ''); //未请款 $not_appropriation_amount = number_format($sent_review_cost-$appropriation_amount,2,'.',''); //未开票 $not_invoicing_amount = number_format($sent_review_cost-$invoicing_amount,2,'.',''); View::assign("sent_review_cost",$sent_review_cost); View::assign("appropriation_amount",$appropriation_amount); View::assign("not_appropriation_amount",$not_appropriation_amount); View::assign("invoicing_amount",$invoicing_amount); View::assign("not_invoicing_amount",$not_invoicing_amount); return view(); } } public function datalist_company() { if (request()->isAjax()) { $param = get_params(); $rows = empty($param['limit']) ? get_config('app . page_size') : $param['limit']; $order = empty($param['order']) ? 'id desc' : $param['order']; $where = []; if(!empty($param["keywords"])){ $where[] = ["entrust_unit_name","like","%".$param["keywords"]."%"]; } $list = $this->model->where("review_unit", get_login_admin("unit_name")) ->where($where) ->order($order)->paginate($rows, false, ['query' => $param]) ->each(function ($item) { $item->invoice_detail = Db::name("ProjectFile")->alias("p")->where([["p.topic_id","=",$item->id],["p.module","=","appropriation"]]) ->join("file f","p.file_id=f.id")->value("name"); $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.review_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; } }); return table_assign(0, '', $list); } else { $inarr = array(); $review_unit = $this->Costmodel->where("review_unit", get_login_admin("unit_name"))->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"]; } } $where = [ ["cp_cost_project.delete_time", "=", 0], ["project_status", ">", 3], ["project_status", "<>", 9], ["review_unit","=",get_login_admin("unit_name")] ]; $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->Costmodel->where($where)->whereIn("id", $inarr)->column("sent_review_cost"); $list_ids = $this->Costmodel->where($where)->whereIn("id", $inarr)->column("id,sent_review_cost"); }elseif ($see_auth==0){ $list = $this->Costmodel->where($where)->whereIn("id", $inarr)->column("sent_review_cost"); $list_ids = $this->Costmodel->where($where)->whereIn("id", $inarr)->column("id,sent_review_cost"); }else{ $list = $this->Costmodel->where($where)->column("sent_review_cost"); $list_ids = $this->Costmodel->where($where)->column("id,sent_review_cost"); } $data = Db::name("appropriation")->alias("a")->leftJoin("appropriation_project p","a.id=p.uid")->leftJoin("cost_project c","p.project_id=c.id") ->where("p.uid","not null") ->where("a.status","2") ->where("c.review_unit",get_login_admin("unit_name"))->column("c.id"); $appropriation = $this->model->where("review_unit", get_login_admin("unit_name"))->where("status","=",2)->select(); $sent_review_cost = 0; $invoicing_amount = 0; $appropriation_amount = 0; foreach ($list as $item=>$value){ //送审服务费 $sent_review_cost += (float)$value; $sent_review_cost = number_format($sent_review_cost, 2, '.', ''); } foreach ($appropriation as $item=>$value){ if($value["invoice_status"]==1){ //开票金额 $invoicing_amount += (float)$value["invoicing_amount"]; $invoicing_amount = number_format($invoicing_amount, 2, '.', ''); } } $invoicing_amount = number_format($invoicing_amount, 2, '.', ''); foreach ($list_ids as $item=>$value){ //已请款 if(in_array($value["id"],$data)){ $appropriation_amount += (float)$value["sent_review_cost"]; $appropriation_amount = number_format($appropriation_amount, 2, '.', ''); } } $appropriation_amount = number_format($appropriation_amount, 2, '.', ''); //未请款 $not_appropriation_amount = number_format($sent_review_cost-$appropriation_amount, 2, '.', ''); //未开票 $not_invoicing_amount = number_format($sent_review_cost-$invoicing_amount, 2, '.', ''); View::assign("sent_review_cost",$sent_review_cost); View::assign("appropriation_amount",$appropriation_amount); View::assign("not_appropriation_amount",$not_appropriation_amount); View::assign("invoicing_amount",$invoicing_amount); View::assign("not_invoicing_amount",$not_invoicing_amount); return view(); } } public function add() { if (request()->isAjax()) { $params = get_params(); $params["appropriation_time"] = time(); $params["maker_id"] = $this->uid; $params["maker_name"] = $this->nickname; $params["review_unit"] = get_login_admin("unit_name"); $params["review_unit_name"] = Db::name("department")->where("id", get_login_admin("unit_name"))->value("title"); if(empty($params["id"])){ $insertGetId = $this->model->strict(false)->insertGetId($params); if (empty($params["project_ids"])) { return to_assign(1, "请添加项目"); } else { Db::name("appropriation_project")->whereIn("id", $params["project_ids"])->update(["uid" => $insertGetId]); } }else{ $params["status"] = -1; $this->model->where("id",$params["id"])->strict(false)->update($params); $insertGetId = $params["id"]; if (!empty($params["project_ids"])) { Db::name("appropriation_project")->whereIn("id", $params["project_ids"])->update(["uid" => $insertGetId]); }else { $params["project_ids"] = Db::name("appropriation_project")->where("uid",$insertGetId)->column("id"); } } if (!empty($params["file_ids"])) { $this->filemodel->whereIn("id", $params["file_ids"])->update(["topic_id" => $insertGetId, "module" => "appropriation"]); } $project_names= ''; if(!empty($params["project_ids"])){ $project = Db::name("appropriation_project")->where("uid", $insertGetId)->select(); if (!$project->isEmpty()) { $a = 0; $project_name = ''; foreach ($project as $key => $value) { $a += 1; $project_name .= $a . "." . $value["project_name"] . ","; } $project_names = $project_name; } } if (!empty($params["first"])) { $auditData = [ "project_id" => $insertGetId, "project_name" => $project_names, "project_type" =>"请款审核", "audit_name" => "请款一审", "audit_type" => 10, "sponsor" => get_login_admin("nickname"), "sponsor_id" => $this->uid, "sponsor_unit" => Db::name("department")->where("id", get_login_admin('unit_name'))->value("title"), "approver" => $params["first"], "approver_name" => get_admin($params["first"])["nickname"], "create_time" => time() ]; $auditDataArr[] = $auditData; } else { return to_assign(1, "请选择审批人"); } if (!empty($params["second"])) { $auditData = [ "project_id" => $insertGetId, "project_name" => $project_names, "project_type" =>"请款审核", "audit_name" => "请款二审", "audit_type" => 11, "audit_status"=>5, "sponsor" => get_login_admin("nickname"), "sponsor_id" => $this->uid, "sponsor_unit" => Db::name("department")->where("id", get_login_admin('unit_name'))->value("title"), "approver" => $params["second"], "approver_name" => get_admin($params["second"])["nickname"], "create_time" => time() ]; $auditDataArr[] = $auditData; } if (!empty($params["third"])) { $auditData = [ "project_id" => $insertGetId, "project_name" => $project_names, "project_type" =>"请款审核", "audit_name" => "请款三审", "audit_type" => 12, "audit_status"=>5, "sponsor" => get_login_admin("nickname"), "sponsor_id" => $this->uid, "sponsor_unit" => Db::name("department")->where("id", get_login_admin('unit_name'))->value("title"), "approver" => $params["third"], "approver_name" => get_admin($params["third"])["nickname"], "create_time" => time() ]; $auditDataArr[] = $auditData; } if (!empty($auditDataArr)) { $ProjectAudit = new ProjectAudit(); try { $ProjectAudit->saveAll($auditDataArr); } catch (\Exception $e) { return to_assign(1, '操作失败,原因:' . $e->getMessage()); } } return to_assign(0, "操作成功"); } else { return view(); } } public function save() { if (request()->isAjax()) { $params = get_params(); $params["appropriation_time"] = time(); $params["maker_id"] = $this->uid; $params["maker_name"] = $this->nickname; $params["review_unit"] = get_login_admin("unit_name"); $params["review_unit_name"] = Db::name("department")->where("id", get_login_admin("unit_name"))->value("title"); if(empty($params["id"])){//新建 $params["status"] = 0; $insertGetId = $this->model->strict(false)->insertGetId($params); if (empty($params["project_ids"])) { return to_assign(1, "请添加项目"); } else { Db::name("appropriation_project")->whereIn("id", $params["project_ids"])->update(["uid" => $insertGetId]); } if (!empty($params["file_ids"])) { $this->filemodel->whereIn("id", $params["file_ids"])->update(["topic_id" => $insertGetId, "module" => "appropriation"]); } }else{//编辑保存 $this->model->where("id",$params["id"])->strict(false)->update($params); if (!empty($params["project_ids"])) { Db::name("appropriation_project")->whereIn("id", $params["project_ids"])->update(["uid" => $params["id"]]); } if (!empty($params["file_ids"])) { $this->filemodel->whereIn("id", $params["file_ids"])->update(["topic_id" => $params["id"], "module" => "appropriation"]); } } return to_assign(0, "操作成功"); } else { return view(); } } public function c_edit() { $params = get_params(); if (request()->isAjax()) { $a= time(); $id = isset($params["id"]) ? $params["id"] : $a; if($id==$a){ $datas = array(); $datas["data"] = null; return table_assign(0, "无项目", $datas); } $project = Db::name("appropriation_project")->alias("a")->join("cost_project c",'c.id=a.project_id',"left")->where("a.uid", $id)->field("a.*,c.sent_review_cost")->select(); $data = []; foreach ($project as $item=>$value){ $value["appropriation_amount"] = $value["sent_review_cost"]; $data[] = $value; } $datas["data"] = $data; $datas["total"] = count($data); return table_assign(0, "", $datas); } else { $a= time(); $id = isset($params["id"]) ? $params["id"] : $a; $detail = Db::name("appropriation")->where("id",$id)->find(); $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' => 'appropriation')) ->select()->toArray(); View::assign('id',$id); View::assign('detail',$detail); View::assign('file_array',$file_array); return view(); } } public function edit_company() { $params = get_params(); if (request()->isAjax()) { $a= time(); $id = isset($params["id"]) ? $params["id"] : $a; if($id==$a){ $datas = array(); $datas["data"] = null; return table_assign(0, "无项目", $datas); } $project = Db::name("appropriation_project")->where("uid", $id)->select(); $datas["data"] = $project; $datas["total"] = count($project); return table_assign(0, "", $datas); } else { $a= time(); $id = isset($params["id"]) ? $params["id"] : $a; $detail = Db::name("appropriation")->where("id",$id)->find(); $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' => 'appropriation')) ->select()->toArray(); View::assign('id',$id); View::assign('detail',$detail); View::assign('file_array',$file_array); return view(); } } public function c_read() { $params = get_params(); if (request()->isAjax()) { $a= time(); $id = isset($params["id"]) ? $params["id"] : $a; if($id==$a){ $datas = array(); $datas["data"] = null; return table_assign(0, "无项目", $datas); } $project = Db::name("appropriation_project")->where("uid", $id)->select(); $datas["data"] = $project; $datas["total"] = count($project); return table_assign(0, "", $datas); }else { $a = time(); $id = isset($params["id"]) ? $params["id"] : $a; $detail = Db::name("appropriation")->where("id", $id)->find(); $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' => 'appropriation')) ->select()->toArray(); View::assign('id', $id); View::assign('detail', $detail); View::assign('file_array', $file_array); $audit = Db::name("project_audit")->where("project_id",$id)->select(); // halt($audit); View::assign('audit', $audit); return view(); } } public function read() { $params = get_params(); if (request()->isAjax()) { $a= time(); $id = isset($params["id"]) ? $params["id"] : $a; if($id==$a){ $datas = array(); $datas["data"] = null; return table_assign(0, "无项目", $datas); } $project = Db::name("appropriation_project")->where("uid", $id)->select(); $datas["data"] = $project; $datas["total"] = count($project); return table_assign(0, "", $datas); }else { $a = time(); $id = isset($params["id"]) ? $params["id"] : $a; $detail = Db::name("appropriation")->where("id", $id)->find(); $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' => 'appropriation')) ->select()->toArray(); View::assign('id', $id); View::assign('detail', $detail); View::assign('file_array', $file_array); $audit = Db::name("project_audit")->where("project_id",$id)->select(); // halt($audit); View::assign('audit', $audit); return view(); } } public function cc_edit(){ if (request()->isAjax()) { $params = get_params(); $id = isset($params["id"]) ? $params["id"] : 0; $params["audit_time"] = time(); $params["status"] = 2; $this->model->where("id",$id)->update($params); return to_assign(0,"操作成功"); } } public function disagree(){ if (request()->isAjax()) { $params = get_params(); $id = isset($params["id"]) ? $params["id"] : 0; if(isset($params['reason'])){ $reason = $params['reason']; }else{ $reason = ''; } $this->model->where("id",$id)->update(["status"=>3,"reason"=>$reason]); return to_assign(0,"操作成功"); } } public function add_project() { $params = get_params(); try { $where = [ ["unit_id","=",get_login_admin("unit_name")], ["create_time","<",time()-300], ["uid","=",null] ]; Db::name("appropriation_project")->where($where)->delete(); $params["create_time"] = time(); $params["unit_id"] = get_login_admin("unit_name"); $insertGetId = Db::name("appropriation_project")->strict(false)->insertGetId($params); } catch (DbException $e) { return to_assign(1, '操作失败,原因:' . $e->getMessage()); } return to_assign(0, '操作成功', $insertGetId); } public function del_project() { $params = get_params(); $id = isset($params["id"]) ? $params["id"] : 0; try { Db::name("appropriation_project")->where("id", $id)->delete(); } catch (DbException $e) { return to_assign(1, '操作失败,原因:' . $e->getMessage()); } return to_assign(0, '操作成功'); } public function project_list() { $params = get_params(); $ids = isset($params["id"]) ? $params["id"] : array(); $data = Db::name("appropriation_project")->whereIn("id", $ids)->select(); $datas["data"] = $data; $datas["total"] = count($data); return table_assign(0, "", $datas); } public function project_list_c() { $params = get_params(); $ids = isset($params["id"]) ? $params["id"] : array(); $data = Db::name("appropriation_project")->whereIn("id", $ids)->select(); $datas["data"] = $data; $datas["total"] = count($data); return table_assign(0, "", $datas); } public function edit() { $params = get_params(); $id = isset($params["id"]) ? $params["id"] : 0; $params["refund_time"] = time(); try { Db::name("appropriation_project")->where("id", $id)->update($params); } catch (DbException $e) { return to_assign(1, '操作失败,原因:' . $e->getMessage()); } return to_assign(0, '操作成功'); } public function edit_c() { $params = get_params(); $id = isset($params["id"]) ? $params["id"] : 0; try { Db::name("appropriation_project")->where("id", $id)->update($params); } catch (DbException $e) { return to_assign(1, '操作失败,原因:' . $e->getMessage()); } return to_assign(0, '操作成功'); } }