1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009 |
- <?php
- //declare (strict_types=1);
- namespace app\admin\controller\project;
- use app\admin\BaseController;
- use app\admin\model\Admin;
- use app\admin\model\Department as DepartmentModel;
- use app\admin\model\CostProject as CostProjectModel;
- use app\admin\model\ProjectAudit;
- use app\admin\model\ProjectFile;
- use think\facade\Db;
- use think\facade\View;
- use think\App;
- use app\admin\controller\field\Fieldproprietor;
- class CostProprietor extends BaseController
- {
- private array $field_name = [
- 'project_num' => '项目编号',
- "project_name" => "项目名称",
- "project_start_time" => "项目开始时间",
- "project_end_time" => "项目结束时间",
- "review_unit" => "评审单位",
- "sent_review_unit" => "送审单位",
- "sent_review_head" => "送审单位负责人",
- "sent_review_phone" => "送审单位负责人电话",
- "construction_unit" => "施工单位",
- "construction_head" => "施工单位负责人",
- "construction_phone" => "施工单位负责人电话",
- "sent_review_amount" => "送审金额",
- "engineering_type" => '工程类型',
- ];
- /**
- * 构造函数
- */
- public function __construct(App $app)
- {
- parent::__construct($app);
- $this->Field = new Fieldproprietor($this->app);
- $this->department = new DepartmentModel();
- $this->model = new CostProjectModel();
- $this->filemodel = new ProjectFile();
- $this->uid = get_login_admin('id');
- $this->Adminmodel = new Admin();
- }
- /**
- * 数据列表
- */
- public function datalist()
- {
- 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'];
- 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;
- }
- if (!empty($param['project_status'])) {
- if($param['project_status'] == 100){
- $where[] = ['project_status', '=', 0];
- $where[] = ['proprietor_status', '=', 0];
- }else if($param['project_status'] == 101){
- $where[] = ['project_status', '=', 0];
- $where[] = ['proprietor_status', '=', 1];
- }else if($param['project_status'] == 102){
- $where[] = ['project_status', '=', 0];
- $where[] = ['proprietor_status', '=', 2];
- }else{
- $where[] = ['project_status', '=', $param['project_status']];
- }
- }
- if (!empty($param['proprietor_status'])) {
- $where[] = ['proprietor_status', '=', $param['proprietor_status']];
- }
- if (!empty($param['province'])) {
- $where[] = ['province', '=', $param['province']];
- }
- if (!empty($param['city'])) {
- $where[] = ['city', '=', $param['city']];
- }
- if (!empty($param['area'])) {
- $where[] = ['area', '=', $param['area']];
- }
- if (!empty($param['project_end_time'])) {
- $where[] = ['project_end_time', '<', $param['project_end_time']];
- }
- if (!empty($param['project_start_time'])) {
- $where[] = ['project_start_time', '>', $param['project_start_time']];
- }
- if (!empty($param['review_head_name'])) {
- $where[] = ['review_head_name', 'like', '%' . $param['review_head_name'] . '%'];
- }
- if (!empty($param['review_unit_name'])) {
- $where[] = ['review_unit_name', 'like', '%' . $param['review_unit_name']. '%'];
- }
- if (!empty($param['sent_review_unit_name'])) {
- $where[] = ['sent_review_unit_name', 'like', '%' . $param['sent_review_unit_name']. '%'];
- }
- if (!empty($param['project_name'])) {
- $where[] = ['project_name', 'like', '%' . $param['project_name'] . '%'];
- }
- $where3 =[];
- if (!empty($param['keyword'])) {
- $keyword = $param['keyword'];
- $where3[] = ['project_num|project_name|review_unit', 'like', '%' . $keyword . '%'];
- }
- //项目可见的权限
- $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==0 || $see_auth==3){
- $where[] =["delete_time", "=", 0];
- $where[] =["sent_review_unit", "=", get_login_admin("unit_name")];
- $where[] =["sent_review_head","=",$this->uid];
- }else{
- $where[] =["delete_time", "=", 0];
- $where[] =["sent_review_unit", "=", get_login_admin("unit_name")];
- }
- $this->see_auth = $see_auth;
- $list = $this->model->where($where)->where($where3)->order($order)->paginate($rows, 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;
- }
- if (($item->province && $item->city && $item->area)) {
- $item->project_region = $item->province . '-' . $item->city . '-' . $item->area;
- }
- $item->self_id = $this->see_auth;
- //作业人
- $operate_team_names = null;
- $operate_team_names_ids = explode(",", $item->operate_team);
- for ($i = 0; $i < count($operate_team_names_ids); $i++) {
- $name = Db::name("admin")->where("id", $operate_team_names_ids[$i])->value("nickname");
- if (!($i == 0)) {
- $name = "," . $name;
- }
- $operate_team_names = $operate_team_names . $name;
- }
- $item->operate_team_names = $operate_team_names;
- });
- return table_assign(0, '', $list);
- } else {
- $field = $this->Field->get_field_rules($this->uid);
- // halt($field);
- View::assign('field', $field);
- return view();
- }
- }
- //TODO
- public function list()
- {
- // if (request()->isAjax()) {
- $param = get_params();
- strtotime('-10 days');
- // halt(strtotime('-10 days'));
- $where2 = [
- ["delete_time", "=", 0],
- ["sent_review_head", "=", $this->uid],
- ['project_end_time', '<', strtotime('15 days')],
- ['project_end_time', '>', time()],
- ["sent_review_unit", "=", get_login_admin("unit_name")],
- ["project_status", "<", 7],
- ["project_status", ">", 3]
- ];
- $where3 = [
- ["delete_time", "=", 0],
- ["sent_review_approver", "=", $this->uid],
- ['project_end_time', '<', strtotime('15 days')],
- ['project_end_time', '>', time()],
- ["sent_review_unit", "=", get_login_admin("unit_name")],
- ["project_status", "<", 7],
- ["project_status", ">", 3]
- ];
- $where4 = [
- ["delete_time", "=", 0],
- ["sent_review_second_approver", "=", $this->uid],
- ['project_end_time', '<', strtotime('15 days')],
- ["sent_review_unit", "=", get_login_admin("unit_name")],
- ['project_end_time', '>', time()],
- ["project_status", "<", 7],
- ["project_status", ">", 3]
- ];
- $rows = empty($param['limit']) ? get_config('app . page_size') : $param['limit'];
- $order = empty($param['order']) ? 'id desc' : $param['order'];
- $list = $this->model->whereOr([ $where2,$where3,$where4])
- ->order($order)
- ->paginate($rows, false, ['query' => $param])
- ->each(function ($item) {
- });
- // halt($list);
- return table_assign(0, '', $list);
- // }
- }
- public function list2()
- {
- // if (request()->isAjax()) {
- $param = get_params();
- $where2 = [
- ["delete_time", "=", 0],
- ["sent_review_head", "=", $this->uid],
- ['project_end_time', '<', time()],
- ["sent_review_unit", "=", get_login_admin("unit_name")],
- ["project_status", "<", 7],
- ["project_status", ">", 3]
- ];
- $where3 = [
- ["delete_time", "=", 0],
- ["sent_review_approver", "=", $this->uid],
- ['project_end_time', '<', time()],
- ["sent_review_unit", "=", get_login_admin("unit_name")],
- ["project_status", "<", 7],
- ["project_status", ">", 3]
- ];
- $where4 = [
- ["delete_time", "=", 0],
- ["sent_review_second_approver", "=", $this->uid],
- ['project_end_time', '<', time()],
- ["sent_review_unit", "=", get_login_admin("unit_name")],
- ["project_status", "<", 7],
- ["project_status", ">", 3]
- ];
- $order = empty($param['order']) ? 'id desc' : $param['order'];
- $list = $this->model->whereOr([$where2,$where3,$where4])
- ->order($order)->paginate(99999, false, ['query' => $param])
- ->each(function ($item) {
- });
- // halt($list);
- return table_assign(0, '', $list);
- // }
- }
- /**
- * 业主保存项目
- */
- public function add()
- {
- if (request()->isAjax()) {
- $param = get_params();
- 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;
- }
- //送审项目的人员信息
- $param["sent_review_unit"] = get_login_admin("unit_name");
- $param["sent_review_unit_name"] = Db::name("department")->where("id", get_login_admin("unit_name"))->value("title");
- $param["sent_review_head"] = $this->uid;
- $param["sent_review_head_name"] = get_login_admin("nickname");
- $param["sent_review_phone"] = get_login_admin("mobile");
- $param["proprietor_status"] = 0;//业主创建项目时的状态 0立项,1审核,2待接收,3已接收
- $param["project_status"] = 0;//真实项目状态
- //1:财政局,3:业主,2:公司
- $param["maker_type"] = 3;
- $file_ids = isset($param["file_ids"]) ? $param["file_ids"] : 0;
- unset($param["file_ids"]);
- $file_id = [];
- $insertId = 0;
- try {
- $param['create_time'] = time();
- $insertId = $this->model->strict(false)->field(true)->insertGetId($param);
- if ($file_ids) {
- for ($a = 0; $a < count($file_ids); $a++) {
- $file_id[] = ["id" => $file_ids[$a], "topic_id" => $insertId];
- }
- $this->filemodel->saveAll($file_id);
- }
- add_log('add', $insertId, $param);
- add_project_log("创建项目", $insertId, $param["project_name"]);
- add_user($param["sent_review_head"], $insertId);
- } catch (\Exception $e) {
- return to_assign(1, '操作失败,原因:' . $e->getMessage());
- }
- return to_assign(0, '操作成功', ['aid' => $insertId]);
- } else {
- $unit_name = Db::name('admin')->where('id', $this->uid)->value('unit_name');
- $leader_id = Db::name("department")
- ->where([
- ["delete_time", "=", 0],
- ["pid", "=", 0],
- ["type", "=", 1], //1表示业主
- ["id", "=", $unit_name]
- ])->value('leader_id');
- $admin_group_id=Db::name("admin")->where("id", $leader_id)->value("admin_group_id");
- $where1 = [
- ['status', '>=', 0],
- ["admin_group_id","=", $admin_group_id],
- ["unit_name","=",$unit_name]
- ];
- $person = Db::name("admin")->where($where1)->field(["id", "nickname"])->select()->toArray();
- $where=[
- ["type","=","1"],
- ["unit_name","=", $unit_name ],
- ];
- $entrust_unit= Db::name("department")->where($where)->value("entrust_unit");
- $entrust_unit_name = Db::name("department")->where("unit_name", $entrust_unit)->value("title");
- View::assign("person", $person);
- View::assign("entrust_unit",$entrust_unit);
- View::assign("entrust_unit_name",$entrust_unit_name);
- return view();
- }
- }
- /**
- * 业主建立项目
- */
- public function save()
- {
- if (request()->isAjax()) {
- $param = get_params();
- //送审单位,即创建项目当的人的信息
- $param["sent_review_unit"] = get_login_admin("unit_name");
- $param["sent_review_unit_name"] = Db::name("department")->where("id", get_login_admin("unit_name"))->value("title");
- $param["sent_review_head"] = $this->uid;//登录人
- $param["sent_review_head_name"] = get_login_admin("nickname");
- $param["sent_review_phone"] = get_login_admin("mobile");
- $param["project_status"] = 0;//项目状态
- $param["proprietor_status"] = 1;//业主创建项目时的状态 0立项,1审核,2待接收,3已接收
- //1:财政局,2:公司,3:业主
- $param["maker_type"] = 3;
- if($param["id"]==0){//创建项目
- $file_id = [];
- $file_ids = isset($param["file_ids"]) ? $param["file_ids"] : 0;
- unset($param["file_ids"]);//去除附件
- // try {
- $param['create_time'] = time();
- $param['update_time'] = time();
- $param["creator"] = $this->uid;//创建者的登录的人的id
- //插入创建项目到costProject,并获取自增的id就是project_id
- $insertGetId = $this->model->strict(false)->field(true)->insertGetId($param);
- if ($file_ids) {//有附件上传
- for ($a = 0; $a < count($file_ids); $a++) {
- $file_id[] = ["id" => $file_ids[$a], "topic_id" => $insertGetId];
- }
- $this->filemodel->saveAll($file_id);
- }
- $auditData1 = [
- "project_id" => $insertGetId,
- "project_name" => $param["project_name"],
- "project_type" => "造价项目",
- "audit_name" => "业主项目审核一审",
- "audit_type" => 1,
- //
- "sponsor" => Db::name('admin')->where("id", $this->uid)->value("nickname"),
- "sponsor_id" => $this->uid,
- //业主不选评审
- //"sponsor_unit" => $param["review_unit_name"],
- "approver" => $param["sent_review_approver"],
- "approver_name" => Db::name('admin')->where("id", $param["sent_review_approver"])->value("nickname"),
- "create_time" => time()
- ];
- //插入
- ProjectAudit::create($auditData1);
- if(!empty($param["sent_review_second_approver"])){
- $auditData2 = [
- "project_id" => $insertGetId,
- "project_name" => $param["project_name"],
- "project_type" => "造价项目",
- "audit_name" => "业主项目审核二审",
- "audit_type" => 0,
- "audit_status" =>5,//待启用
- "sponsor" => Db::name('admin')->where("id", $this->uid)->value("nickname"),
- "sponsor_id" => $this->uid,
- "approver" => $param["sent_review_second_approver"],
- "approver_name" => Db::name('admin')->where("id", $param["sent_review_second_approver"])->value("nickname"),
- "create_time" => time()
- ];
- ProjectAudit::create($auditData2);
- }
- add_log('add', $insertGetId, $param);
- add_project_log("创建项目", $insertGetId,$param["project_name"]);
- add_user($param["sent_review_head"], $insertGetId);
- }else{
- //编辑的时候提交
- try {
- $file_ids = isset($param["file_ids"]) ? $param["file_ids"] : 0;
- unset($param["file_ids"]);
- $param['update_time'] = time();
- $this->model->where('id', $param['id'])->strict(false)->field(true)->update($param);
- if ($file_ids) {
- for ($a = 0; $a < count($file_ids); $a++) {
- $file_id[] = ["id" => $file_ids[$a], "topic_id" => $param['id']];
- }
- $this->filemodel->saveAll($file_id);
- }
- $auditData1 = [
- "project_id" => $param["id"],
- "project_name" => $param["project_name"],
- "project_type" => "造价项目",
- "audit_name" => "业主项目审核一审",
- "audit_type" => 1,
- "sponsor" => Db::name('admin')->where("id", $this->uid)->value("nickname"),
- "sponsor_id" => $this->uid,
- // "sponsor_unit" => $param["review_unit_name"],
- "approver" => $param["sent_review_approver"],
- "approver_name" => Db::name('admin')->where("id", $param["sent_review_approver"])->value("nickname"),
- "create_time" => time()
- ];
- //插入
- ProjectAudit::create($auditData1);
- if(!empty($param["sent_review_second_approver"])) {
- $auditData2 = [
- "project_id" => $param["id"],
- "project_name" => $param["project_name"],
- "project_type" => "造价项目",
- "audit_name" => "业主项目审核二审",
- "audit_type" => 0,
- "audit_status" => 5,//待启用
- "sponsor" => Db::name('admin')->where("id", $this->uid)->value("nickname"),
- "sponsor_id" => $this->uid,
- "approver" => $param["sent_review_second_approver"],
- "approver_name" => Db::name('admin')->where("id", $param["sent_review_second_approver"])->value("nickname"),
- "create_time" => time()
- ];
- ProjectAudit::create($auditData2);
- }
- } catch (\Exception $e) {
- return to_assign(1, '操作失败,原因:' . $e->getMessage());
- }
- }
- return to_assign(0, '操作成功');
- } else {
- $person = Db::name("admin")->where("unit_name", get_login_admin("unit_name"))->where("status",">",0)->field(["id", "nickname"])->select()->toArray();
- View::assign("person", $person);
- return view();
- }
- }
- /**
- * 撤回
- */
- public function withdraw()
- {
- if (request()->isAjax()) {
- $param = get_params();
- $status = Db::name("cost_project")->where("id", $param["id"])->field("proprietor_status")->select();
- // halt($status[0]["status"]);
- if ($status[0]["proprietor_status"] < 2) {
- 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;
- }
- $param = array_merge($param, ["proprietor_status" => 0]);
- try {
- $param['update_time'] = time();
- $this->model->where('id', $param['id'])->strict(false)->field(true)->update($param);
- Db::name("ProjectAudit")->where([["project_id", "=", $param["id"]], ["audit_status", "in", [0,1,5]], ["audit_name", "in", ["业主项目审核一审", "业主项目审核二审"]]])->delete();
- add_log('edit', $param['id'], $param);
- add_project_log('撤回', $param['id'], "撤回");
- } catch (\Exception $e) {
- return to_assign(1, '操作失败,原因:' . $e->getMessage());
- }
- return to_assign(0, "操作成功");
- } else {
- return to_assign(0, "已审核,无法撤回");
- }
- }
- }
- public function edit_main(){
- $param = get_params();
- $type = isset($param["type"])??0;
- if(request()->isAjax()&&$type!=2){
- $param = get_params();
- $id = $param["id"] ?? 0;
- 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;
- }
- $param["sent_review_unit"] = get_login_admin("unit_name");
- $param["sent_review_unit_name"] = Db::name("department")->where("id", get_login_admin("unit_name"))->value("title");
- $param["sent_review_head"] = $this->uid;
- $param["sent_review_head_name"] = get_login_admin("nickname");
- $param["sent_review_phone"] = get_login_admin("mobile");
- $param["project_status"] = 0;
- //1:财政局,3:业主,2:公司
- $param["maker_type"] = 3;
- $file_ids = isset($param["file_ids"]) ? $param["file_ids"] : 0;
- unset($param["file_ids"]);
- unset($param["file"]);
- $file_id = [];
- try {
- $param['create_time'] = time();
- $this->model->where("id",$id)->update($param);
- $insertId = $id;
- if ($file_ids) {
- for ($a = 0; $a < count($file_ids); $a++) {
- $file_id[] = ["id" => $file_ids[$a], "topic_id" => $insertId];
- }
- $this->filemodel->saveAll($file_id);
- }
- add_log('add', $insertId, $param);
- add_project_log("编辑项目", $insertId, "编辑项目");
- } catch (\Exception $e) {
- return to_assign(1, '操作失败,原因:' . $e->getMessage());
- }
- return to_assign(0, '操作成功', ['aid' => $insertId]);
- }else{
- $param = get_params();
- $id = $param['id'] ?? 0;
- $detail = $this->model->getCostProjectById($id);
- $unit_name =get_login_admin("unit_name");
- $leader_id = Db::name("department")
- ->where([
- ["delete_time", "=", 0],
- ["pid", "=", 0],
- ["type", "=", 1], //1表示业主
- ["id", "=", $unit_name]
- ])->value('leader_id');
- $admin_group_id=Db::name("admin")->where("id", $leader_id)->value("admin_group_id");
- $where1 = [
- ['status', '>=', 0],
- ["admin_group_id","=", $admin_group_id],
- ["unit_name","=",$unit_name]
- ];
- $person = Db::name("admin")->where($where1)->field(["id", "nickname"])->select()->toArray();
- $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();
- $project_log = self::project_log($id);
- View::assign('project_log', $project_log);
- if ($detail["project_end_time"]!=null){
- $c = $detail['project_end_time'] - time();
- if ($c > 0) {
- $advent_time = floor($c / 86400) . "天";
- } else {
- $c = -$c;
- $advent_time = floor($c / 86400) . "天";
- }
- }else{
- $advent_time=null;
- }
- $comment_type = isset($param["comment_type"])?$param['comment_type'] : 0;
- $comment = Db::name("project_comment")->where("type",$comment_type)
- ->where("project_id", $id)->order('create_time', 'asc')->select();
- $field = $this->Field->get_field_rules_new(get_login_admin('id'));
- $field_edit = $this->Field->get_field_rules_edit_new($this->uid);
- //委托单位
- $unit_name = Db::name('admin')->where('id', $this->uid)->value('unit_name');
- $where=[
- ["type","=","1"],
- ["unit_name","=", $unit_name ],
- ];
- $entrust_unit= Db::name("department")->where($where)->value("entrust_unit");
- $entrust_unit_name = Db::name("department")->where("unit_name", $entrust_unit)->value("title");
- View::assign("entrust_unit",$entrust_unit);
- View::assign("entrust_unit_name",$entrust_unit_name);
- if (!empty($detail)) {
- View::assign('comment', $comment);
- View::assign('field', $field);
- View::assign('advent_time', $advent_time);
- View::assign('field_edit', $field_edit);
- View::assign('project_id', $id);
- View::assign('detail', $detail);
- View::assign("person", $person);
- View::assign("file_array", $file_array);
- View::assign('project_five', self::getProjectFive());
- } else {
- throw new \think\exception\HttpException(404, '找不到页面,请联系管理员');
- }
- return view();
- }
- }
- /**
- * 查看信息
- */
- public function read()
- {
- $param = get_params();
- $id = isset($param['id']) ? $param['id'] : 0;
- // dump($id);
- $detail = $this->model->getCostProjectById($id);
- $comment_type = isset($param["comment_type"])?$param['comment_type'] : 0;
- $comment = Db::name("project_comment")->where("type",$comment_type)
- ->where("project_id", $id)->order('create_time', 'asc')->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();
- // halt($comment);
- $project_log = self::project_log($id);
- View::assign('project_log', $project_log);
- // halt($project_log);
- // 根据用户id 查询其能显示的字段
- $field = $this->Field->get_field_rules_new(get_login_admin('id'));
- // dump($field);
- // halt(self::getProjectFive());
- if (!empty($detail)) {
- View::assign('project_id', $id);
- View::assign('comment', $comment);
- View::assign('field', $field);
- View::assign('detail', $detail);
- View::assign('file_array', $file_array);
- View::assign('report', $report);
- View::assign('project_five', self::getProjectFive());
- return view();
- } else {
- throw new \think\exception\HttpException(404, '找不到页面');
- }
- }
- /**
- * 删除
- * type=0,逻辑删除,默认
- * type=1,物理删除
- */
- public function del()
- {
- $param = get_params();
- $status = Db::name("cost_project")->where("id", $param["id"])->field("proprietor_status")->select();
- if ($status[0]["proprietor_status"] < 1) {//立项中
- $id = isset($param['id']) ? $param['id'] : 0;
- $type = isset($param['type']) ? $param['type'] : 0;
- add_project_log("删除项目", $id, "删除项目");
- $this->model->delCostProjectById($id, $type);
- } else {
- return to_assign(0, "已审核,无法删除");
- }
- }
- //获取客户列表
- public function get_customer()
- {
- $param = get_params();
- $where = array();
- if (!empty($param['keywords'])) {
- $where[] = ['id|title', 'like', '%' . $param['keywords'] . '%'];
- }
- $where = [
- ["delete_time", "=", 0],
- ["pid", "=", 0],
- ["type", "=", 2]
- ];
- $rows = empty($param['limit']) ? get_config('app.page_size') : $param['limit'];
- $list = $this->department->field('id,title,address,leader_id')->order('id asc')->where($where)->paginate($rows, false)
- ->each(function ($item) {
- $item->nickname = Db::name('admin')->where(['id' => $item->leader_id])->value('nickname');
- $item->mobile = Db::name('admin')->where(['id' => $item->leader_id])->value('mobile');
- });
- // halt($list);
- table_assign(0, '', $list);
- }
- //获取客户列表
- public function addConstructionPeople()
- {
- $param = get_params();
- if (request()->isAjax()) {
- $this->model->addConstructionPeople($param);
- } else {
- $project_id = isset($param['project_id']) ? $param['project_id'] : 0;
- //关联项目id
- View::assign('project_id', $project_id);
- return view();
- }
- }
- public function getConstructionPeople()
- {
- $param = get_params();
- if (request()->isAjax()) {
- $data = $this->model->where('id', $param["id"])->find();
- if ($data["construction_unit"] !== null ||
- $data["construction_head"] !== null ||
- $data["construction_email"] !== null ||
- $data["construction_phone"] !== null
- ) {
- return to_assign(0, "已存在!!");
- } else {
- return to_assign(200, "请上传!!");
- }
- }
- }
- public function project_user()
- {
- $param = get_params();
- $ids = $this->model->where("id", $param["project_id"])->field("entrust_maker,review_head,operate_head,operate_team")->find()->toArray();
- $idarr = $ids["operate_team"] . ',' . $ids["operate_head"] . ',' . $ids["review_head"] . ',' . $ids["entrust_maker"];
- $idarr = explode(",", $idarr);
- $rows = empty($param['limit']) ? get_config('app.page_size') : $param['limit'];
- $list = $this->Adminmodel->whereIn("id", $idarr)->field("id,nickname,unit_name,mobile,email")->paginate($rows, false, ['query' => $param])
- // field("a.id,a.nickname,a.unit_name,a.mobile,a.email,d.title,d.type")->join('department d', 'a.unit_name = d.id', 'LEFT')
- ->each(function ($item) {
- //获取单位的邮箱,单位信息页没做
- $item->email = Db::name('department')->where(['id' => $item->unit_name])->value('email');
- $type = Db::name('department')->where(['id' => $item->unit_name])->value('type');
- $item->unit_name = Db::name('department')->where(['id' => $item->unit_name])->value('title');
- // dump($type);
- if ($type == 0) {
- $item->unit_type = "委托单位";
- } elseif ($type == 1) {
- $item->unit_type = "送审单位";
- } elseif ($type == 2) {
- $item->unit_type = "评审机构";
- } else {
- $item->unit_type = "施工单位";
- }
- })->toArray();
- $list = $list["data"];
- for ($i = 0; $i < count($list); $i++) {
- if ($list[$i]['id'] == $ids['entrust_maker']) {
- // dump($list[$i]['id'],$ids['entrust_maker']);
- $list[$i]["type"] = 1;
- } elseif ($list[$i]['id'] == $ids['review_head']) {
- $list[$i]["type"] = 2;
- } elseif ($list[$i]['id'] == $ids['operate_head']) {
- $list[$i]["type"] = 3;
- } elseif (in_array($list[$i]['id'], explode(',', $ids['operate_team']))) {
- $list[$i]["type"] = 4;
- }
- }
- $type = array_column($list, 'type');
- array_multisort($type, SORT_ASC, $list);
- $shigong = $this->model->where('id', $param["project_id"])->find();
- if ($shigong["construction_unit"] !== null ||
- $shigong["construction_head"] !== null ||
- $shigong["construction_email"] !== null ||
- $shigong["construction_phone"] !== null
- ) {
- $shigongdata["id"] = time();
- $shigongdata["nickname"] = $shigong["construction_unit"];
- $shigongdata["unit_name"] = $shigong["construction_head"];
- $shigongdata["email"] = $shigong["construction_email"];
- $shigongdata["mobile"] = $shigong["construction_phone"];
- $shigongdata["unit_type"] = "施工单位";
- array_push($list, $shigongdata);
- }
- $list["data"] = $list;
- return table_assign(0, '', $list);
- }
- public function getProjectFive()
- {
- $where = [
- ['name', '=', '作业日志-业主'],
- ['name', '=', '工作记录-业主'],
- ['name', '=', '项目报告-业主'],
- ['name', '=', '项目人员-业主'],
- ['name', '=', '项目动态-业主'],
- ['name', '=', '项目附件-业主'],
- ['name', '=', '联系函-业主'],
- ];
- $list = Db::name('AdminRule')->whereOr($where)->field('id,name')->select()->toArray();
- $group_id = Db::name('AdminGroupAccess')->where('uid', get_login_admin('id'))->value('group_id');
- $login_rules = Db::name('AdminGroup')->where('id', $group_id)->value('rules');
- $login_rules = explode(',', $login_rules);
- $rules_id = array();
- foreach ($list as $key => $value) {
- if ($value['name'] == "作业日志-业主") {
- if (in_array($value['id'], $login_rules)) {
- $rules_id['project_comments'] = 1;
- } else {
- $rules_id['project_comments'] = 0;
- }
- } else if ($value['name'] == "工作记录-业主") {
- if (in_array($value['id'], $login_rules)) {
- $rules_id['project_record'] = 1;
- } else {
- $rules_id['project_record'] = 0;
- }
- } else if ($value['name'] == "项目报告-业主") {
- if (in_array($value['id'], $login_rules)) {
- $rules_id['project_report'] = 1;
- } else {
- $rules_id['project_report'] = 0;
- }
- } else if ($value['name'] == "项目人员-业主") {
- if (in_array($value['id'], $login_rules)) {
- $rules_id['project_user'] = 1;
- } else {
- $rules_id['project_user'] = 0;
- }
- } else if ($value['name'] == "项目动态-业主") {
- if (in_array($value['id'], $login_rules)) {
- $rules_id['project_log'] = 1;
- } else {
- $rules_id['project_log'] = 0;
- }
- } else if ($value['name'] == "项目附件-业主") {
- if (in_array($value['id'], $login_rules)) {
- $rules_id['project_file'] = 1;
- } else {
- $rules_id['project_file'] = 0;
- }
- } else if ($value['name'] == "联系函-业主") {
- if (in_array($value['id'], $login_rules)) {
- $rules_id['project_contact'] = 1;
- } else {
- $rules_id['project_contact'] = 0;
- }
- }
- }
- return $rules_id;
- }
- public function getemployeelist()
- {
- if (request()->isAjax()) {
- $data = $this->request->param();
- $person = Db::name("admin")->where([["unit_name", "=", $data['id']], ["status", "=", 1]])->field(["id", "nickname", "mobile"])->select();
- return $person;
- }
- }
- public function project_log($project_id)
- {
- // $project_id = 24;
- $login_admin = get_login_admin();
- $where = array();
- if ($login_admin['user_type'] == 2) {
- $where = [
- ['project_status', '>=', 3],
- ['unit_name', '=', $login_admin['unit_name']],
- ];
- } else {
- if ($login_admin['permission'] != 1) {
- $where = [
- ['unit_name', '=', $login_admin['unit_name']],
- ];
- }
- }
- // dump($where);
- $project_log = Db::name('ProjectLog')->where($where)->where('project_id', $project_id)->order('create_time', 'desc')->select()->toArray();
- foreach ($project_log as $key => $value) {
- $project_log[$key]['create_time'] = date("Y-m-d H:i:s", $value['create_time']);
- }
- // dump($project_log);
- // View::assign('project_log', $project_log);
- // return View();
- return $project_log;
- }
- public function ceshi($id)
- {
- View::assign('detailId', $id);
- return view();
- }
- }
|