123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659 |
- <?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\ProjectMsg;
- use app\admin\model\ProjectFile;
- use app\admin\validate\project\CostProjectValidate;
- use app\wechat\controller\Officialaccount;
- use think\db\Where;
- use think\exception\ValidateException;
- use think\facade\Db;
- use think\facade\View;
- use think\App;
- use app\admin\controller\field\Field;
- use app\admin\controller\Pushmessage;
- class Cost 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 Field($this->app);
- $this->department = new DepartmentModel();
- $this->model = new CostProjectModel();
- $this->ProjectAuditModel = new ProjectAudit ();
- $this->ProjectMsg = new ProjectMsg();
- $this->filemodel = new ProjectFile();
- $this->uid = get_login_admin('id');
- $this->Adminmodel = new Admin();
- $this->time = time();
- $this->Officialaccount = new Officialaccount();
- $this->Pushmessage = new Pushmessage();
- }
- /**
- * 数据列表
- */
- 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;
- }
- //项目可见的权限
- $field = $this->Field->get_field_rules_new($this->uid);//获取当前登录的id
- //1全部-可查看可编辑,2全部-可查看,0与我有关
- $see_auth = isset($field["see_auth"]) ? $field["see_auth"] : 3;//等于3
- $where[] = ["delete_time", "=", 0];
- $where[] = ["project_status", ">", 0];
- $where2[] = ["delete_time", "=", 0];
- $where2[] = ["project_status", ">", 0];
- if ($see_auth == 3||$see_auth == 0) {
- $where[] = ["entrust_maker", "=", $this->uid];
- $where2[] = ["entrust_approver", "=", $this->uid];
- $where2[] = ["project_status", ">", 1];//大于立项
- }
- $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_head_name'])) {
- $where3[] = ['review_head_name', 'like', '%' . $param['review_head_name'] . '%'];
- }
- 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']. '%'];
- }
- $where3[] = ["entrust_unit", "=", get_login_admin('unit_name')];
- $this->see_auth = $see_auth;
- $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($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->creator = Db::name("admin")->where("id",$item->creator)->value("nickname");
- $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_new($this->uid);
- $fields = [];
- foreach ($field as $k=>$v){
- if($v!=1){
- $fields[$k] = true;
- }else{
- $fields[$k] = false;
- }
- }
- View::assign('field', $fields);
- return view();
- }
- }
- /**
- * 数据列表
- */
- public function followProject()
- {
- 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'];
- $openid = get_login_admin('openid');
- $follow_project_id = Db::name('follow_project')->where('openid',$openid)->find();
- // halt($openid,$follow_project_id);
- 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;
- }
- $where[] = ["delete_time", "=", 0];
- $where[] = ["project_status", ">", 0];
- $where2[] = ["delete_time", "=", 0];
- $where2[] = ["project_status", ">", 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_head_name'])) {
- $where3[] = ['review_head_name', 'like', '%' . $param['review_head_name'] . '%'];
- }
- 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']. '%'];
- }
- $list = $this->model
- ->where('id','in',$follow_project_id)
- ->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($order)->paginate($rows, false, ['query' => $param])
- ->each(function ($item) {
- if (($item->province && $item->city && $item->area)) {
- $item->project_region = $item->province . '-' . $item->city . '-' . $item->area;
- }
- $item->creator = Db::name("admin")->where("id",$item->creator)->value("nickname");
- //作业人
- $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 {
- return view();
- }
- }
- /**
- * 临期
- */
- public function list()
- {
- // if (request()->isAjax()) {
- $param = get_params();
- $field = $this->Field->get_field_rules_new($this->uid);
- $see_auth = isset($field["see_auth"]) ? $field["see_auth"] : 3;
- $where = array();
- $where3 = array();
- if ($see_auth == 3 || $see_auth == 0) {
- $where = [
- ["entrust_maker", "=", $this->uid],
- ];
- $where3 = [
- ["entrust_approver", "=", $this->uid],
- ["project_status", ">", 1]
- ];
- }
- $where1 = [
- ["delete_time", "=", 0],
- ['project_end_time', '<', strtotime('15 days')],
- ['project_end_time', '>', time()],
- ["project_status", "<", 7],
- ["entrust_unit","=",get_login_admin("unit_name")]
- ];
- $where1 = array_merge($where, $where1);
- $where2 = array_merge($where1, $where3);
- $rows = empty($param['limit']) ? get_config('app . page_size') : $param['limit'];
- $order = empty($param['order']) ? 'id desc' : $param['order'];
- $list = $this->model->whereOr([$where1, $where2])
- ->order($order)
- ->paginate(9999, false, ['query' => $param])
- ->each(function ($item) {
- });
- return table_assign(0, '', $list);
- // }
- }
- /**
- * 逾期
- */
- public function list2()
- {
- $param = get_params();
- $field = $this->Field->get_field_rules_new($this->uid);
- $see_auth = isset($field["see_auth"]) ? $field["see_auth"] : 3;
- $where = array();
- $where3 = array();
- if ($see_auth == 3 || $see_auth == 0) {
- $where = [
- ["entrust_maker", "=", $this->uid],
- ];
- $where3 = [
- ["entrust_approver", "=", $this->uid],
- ["project_status", ">", 1]
- ];
- }
- $where2 = [
- ["delete_time", "=", 0],
- ['project_end_time', '<', time()],
- ["project_status", "<", 7],
- ["entrust_unit","=",get_login_admin("unit_name")]
- ];
- $where1 = array_merge($where, $where2);
- $where2 = array_merge($where2, $where3);
- $rows = empty($param['limit']) ? get_config('app . page_size') : $param['limit'];
- $order = empty($param['order']) ? 'id desc' : $param['order'];
- $list = $this->model->whereOr([$where1, $where2])
- ->order($order)->paginate(9999, false, ['query' => $param]);
- return table_assign(0, '', $list);
- // }
- }
- /**
- * 添加/保存
- */
- public function add()
- {
- if (request()->isAjax()) {
- $param = get_params();
- // halt($param);
- // 检验完整性
- try {
- validate(CostProjectValidate::class)->check($param);
- } catch (ValidateException $e) {
- // 验证失败 输出错误信息
- return to_assign(1, $e->getError());
- }
- 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["entrust_unit"] = get_login_admin("unit_name");
- $param["entrust_unit_name"] = Db::name("department")->where("id", get_login_admin("unit_name"))->value("title");
- $param["entrust_maker"] = $this->uid;
- $param["entrust_maker_name"] = get_login_admin("nickname");
- $param["entrust_phone"] = get_login_admin("mobile");
- if(($param["entrust_second_approver"])&&!empty($param["entrust_second_approver"])){
- $param["entrust_second_approver_name"] = get_admin($param["entrust_second_approver"])["nickname"];
- }
- $param["entrust_approver_name"] = get_admin($param["entrust_approver"])["nickname"];
- //送审
- // if(isset($param["sent_review_unit"]) && $param["sent_review_unit"] !== ""){
- // $sent_review_unit = Db::name("department")->where("id",$param["sent_review_unit"])->find();
- // $sent_review_head = Db::name("admin")->where("id",$sent_review_unit['leader_id'])->find();
- // $param["sent_review_head_name"] = $sent_review_head["nickname"];
- // $param["sent_review_phone"] = $sent_review_head["mobile"];
- // }
- $param["project_status"] = 1;
- $param["maker_type"] = 1;
- $param["creator"] = $this->uid;
- $file_ids = isset($param["file_ids"]) ? $param["file_ids"] : 0;
- unset($param["file_ids"]);
- $file_id = [];
- $insertId = 0;
- try {
- $param['create_time'] = time();
- //插入数据到并且返回数据id值
- $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, "创建项目");
- add_user($param["entrust_maker"], $insertId);
- add_user($param["entrust_approver"], $insertId);
- add_user($param["entrust_second_approver"], $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表示业主
- ["entrust_unit", "=", $unit_name]
- ])->value('leader_id');
- $proprietor_unit_name = Db::name("department")
- ->where([
- ["delete_time", "=", 0],
- ["pid", "=", 0],
- ["type", "=", 1], //1表示业主
- ["entrust_unit", "=", $unit_name]
- ])->column('unit_name');
- $admin_group_id=Db::name("admin")->where("id", $leader_id)->value("admin_group_id");
- $where = [
- ['status', '>=', 0],
- ["admin_group_id","=", $admin_group_id],
- ["unit_name","in",$proprietor_unit_name]
- ];
- $proprietor =Db::name("admin")->where($where)->field(["id","nickname"])->select()->toArray();
- $person = Db::name("admin")->where("unit_name", $unit_name)->where("status",">",0)->field(["id", "nickname"])->select()->toArray();
- $person = array_values($person);//返回数组所有值,索引从0
- $proprietor = array_values($proprietor);
- View::assign("person", $person);
- View::assign("proprietor", $proprietor);
- return view();
- }
- }
- 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 save()
- {
- if (request()->isAjax()) {
- $param = get_params();
- $handle = $this->Pushmessage->handleParam($param);//将财务,公司的信息与他分开
- $param = $handle['param'];//是项目的信息
- // 检验完整性
- try {
- validate(CostProjectValidate::class)->check($param);
- } catch (ValidateException $e) {
- // 验证失败 输出错误信息
- return to_assign(1, $e->getError());
- }
- 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["entrust_unit"] = get_login_admin("unit_name");
- $param["entrust_unit_name"] = Db::name("department")->where("id", get_login_admin("unit_name"))->value("title");
- $param["entrust_maker"] = $this->uid;
- $param["entrust_maker_name"] = get_login_admin("nickname");
- $param["entrust_phone"] = get_login_admin("mobile");
- //获取审批人员的名称,get_admin获取管理人员信息
- $param["entrust_approver_name"] = get_admin($param["entrust_approver"])["nickname"];
- if(isset($param["entrust_second_approver"])&&!empty($param["entrust_second_approver"])){
- $param["entrust_second_approver_name"] = get_admin($param["entrust_second_approver"])["nickname"];
- }
- //送审
- // if(isset($param["sent_review_unit"]) && $param["sent_review_unit"] !== ""){
- // $sent_review_unit = Db::name("department")->where("id",$param["sent_review_unit"])->find();
- // $sent_review_head = Db::name("admin")->where("id",$sent_review_unit['leader_id'])->find();
- // $param["sent_review_head_name"] = $sent_review_head["nickname"];
- // $param["sent_review_phone"] = $sent_review_head["mobile"];
- // }
- //提交后状态改变为2,待审批中
- $param["project_status"] = 2;
- $param["maker_type"] = 1;//财政
- //id=0代表项目创建
- 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->where('id', $param['id'])->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);
- }
- //插入审批数据库记录,project_status=2,审批中
- $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["entrust_approver"],
- "approver_name" => Db::name('admin')->where("id", $param["entrust_approver"])->value("nickname"),
- "create_time" => time()
- ];
- //插入
- ProjectAudit::create($auditData1);
- $MsgData1 = [
- "uid" => $auditData1["approver"],
- "project_id" => $insertGetId,
- "content" => get_login_admin("nickname") . "向您发起了一个" . $auditData1["audit_name"],
- "create_time" => time()
- ];
- $MsgGetId = $this->ProjectMsg->insertGetId($MsgData1);
- $unread = Db::name("admin")->where("id", $auditData1["approver"])->value("unread");
- if (!empty($unread)) {
- $unread = $unread . "," . $MsgGetId;
- } else {
- $unread = $MsgGetId;
- }
- Db::name("admin")->where("id", $auditData1["approver"])->update(["unread" => $unread]);
- if(empty($handle['financial'])){
- $handle['financial'] = (array)$param['entrust_approver'];
- }else{
- $handle['financial'] = array_merge($handle['financial'], $param['entrust_approver']);
- }
- if(empty($handle['proprietor'])){
- if(isset($param['sent_review_head']) && $param['sent_review_head'] != ""){
- $handle['proprietor'] = (array)$param['sent_review_head'];
- }else{
- $handle['proprietor'] = (array)0;
- }
- }else{
- if(isset($param['sent_review_head']) && $param['sent_review_head'] != ""){
- $handle['proprietor'] = array_merge($handle['financial'], $param['sent_review_head']);
- }else{
- $handle['proprietor'] = (array)0;
- }
- }
- // 发送消息,/项目id/发给的财务人员/公司人员都是int整数
- $this->Pushmessage->pushMessage($insertGetId, $handle['financial'], $handle['company'],$handle["proprietor"]);
- if(!empty($param["entrust_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,
- "sponsor_unit" => $param["review_unit_name"],
- "approver" => $param["entrust_second_approver"],
- "approver_name" => Db::name('admin')->where("id", $param["entrust_second_approver"])->value("nickname"),
- "create_time" => time()
- ];
- ProjectAudit::create($auditData2);
- $MsgData2 = [
- "uid" =>$auditData2["approver"],//显示的文本,传来的id
- "project_id" => $insertGetId,
- "content" => get_login_admin("nickname") . "向您发起了一个" . $auditData2["audit_name"],
- "create_time" => time()
- ];
- $MsgData3 = [
- "uid" =>$auditData2["approver"],//显示的文本,传来的id
- "project_id" => $insertGetId,
- "content" => "您有一个新的待审批项目等待处理。" ."项目名称:".$auditData2["project_name"]." 申请人:".get_login_admin("nickname"),
- "create_time" => time()
- ];
- // 插入第一条数据($MsgData2)
- $MsgGetId2 = $this->ProjectMsg->insertGetId($MsgData2);
- $unread1 = Db::name("admin")->where("id", $auditData2["approver"])->value("unread");
- if (!empty($unread1)) {
- $unread1 = $unread1. ",". $MsgGetId2;
- } else {
- $unread1 = $MsgGetId2;
- }
- Db::name("admin")->where("id", $auditData2["approver"])->update(["unread" => $unread1]);
- //插入第二条
- $MsgGetId3 = $this->ProjectMsg->insertGetId($MsgData3);
- $unread2 = Db::name("admin")->where("id", $auditData2["approver"])->value("unread");
- if (!empty($unread2)) {
- $unread2 = $unread2. ",". $MsgGetId3 ;
- } else {
- $unread2 = $MsgGetId3;
- }
- Db::name("admin")->where("id", $auditData2["approver"])->update(["unread" => $unread2]);
- // if(empty($handle['financial'])){
- // $handle['financial'] = (array)$param['entrust_second_approver'];
- // }else{
- // $handle['financial'] = array_merge($handle['financial'], $param['entrust_second_approver']);
- // }
- // // 发送消息,/项目id/发给的财务人员/公司人员都是int整数
- // $this->Pushmessage->pushMessage($insertGetId, $handle['financial'], $handle['company']);
- }
- add_log('edit', $insertGetId, $param);
- add_project_log("创建项目", $insertGetId, $param["project_name"]);
- $secondApproverName =!empty($param["entrust_second_approver"])? "第二审核:".$auditData2["approver_name"] : "";
- add_project_log("提交立项审批", $insertGetId, "提交立项审批, 审批人有:第一审核:". $auditData1["approver_name"]. " ". $secondApproverName);
- add_user($param["entrust_maker"], $insertGetId);
- add_user($param["entrust_approver"], $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);
- }
- //审批记录,project_status=2,审批中,编辑时传过来的id就是已经创建好了的project_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["entrust_approver"],
- "approver_name" => Db::name('admin')->where("id", $param["entrust_approver"])->value("nickname"),
- "create_time" => time()
- ];
- ProjectAudit::create($auditData1);
- //审批记录消息
- $MsgData1 = [
- "uid" => $auditData1["approver"],
- "project_id" => $param['id'],
- "content" => get_login_admin("nickname") . "向您发起了一个" . $auditData1["audit_name"],
- "create_time" => time()
- ];
- $MsgGetId = $this->ProjectMsg->insertGetId($MsgData1);
- $unread = Db::name("admin")->where("id", $auditData1["approver"])->value("unread");
- if (!empty($unread)) {
- $unread = $unread . "," . $MsgGetId;
- } else {
- $unread = $MsgGetId;
- }
- Db::name("admin")->where("id", $auditData1["approver"])->update(["unread" => $unread]);
- add_project_log("提交立项审批", $param['id'], "提交立项审批");
- add_user($param["entrust_approver"], $param['id']);
- if(empty($handle['financial'])){
- $handle['financial'] = (array)$param['entrust_approver'];
- }else{
- $handle['financial'] = array_merge($handle['financial'], $param['entrust_approver']);
- }
- $this->Pushmessage->pushMessage($param['id'], $handle['financial'], $handle['company']);
- //二
- if(!empty($param["entrust_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,
- "sponsor_unit" => $param["review_unit_name"],
- "approver" => $param["entrust_second_approver"],
- "approver_name" => Db::name('admin')->where("id", $param["entrust_second_approver"])->value("nickname"),
- "create_time" => time()
- ];
- ProjectAudit::create($auditData2);
- $MsgData2 = [
- "uid" =>$auditData2["approver"],//显示的文本,传来的id
- "project_id" => $param['id'],
- "content" => get_login_admin("nickname") . "向您发起了一个" . $auditData2["audit_name"],
- "create_time" => time()
- ];
- $MsgGetId = $this->ProjectMsg->insertGetId($MsgData2);
- $unread = Db::name("admin")->where("id", $auditData2["approver"])->value("unread");
- if (!empty($unread)) {
- $unread = $unread . "," . $MsgGetId;
- } else {
- $unread = $MsgGetId;
- }
- Db::name("admin")->where("id", $auditData2["approver"])->update(["unread" => $unread]);
- add_user($param["entrust_second_approver"], $param['id']);
- $MsgData3 = [
- "uid" =>$auditData2["approver"],//显示的文本,传来的id
- "project_id" => $param["id"],
- "content" => "您有一个新的待审批项目等待处理。" ."项目名称:".$auditData2["project_name"]." 申请人:".get_login_admin("nickname"),
- "create_time" => time()
- ];
- //插入第二条
- $MsgGetId3 = $this->ProjectMsg->insertGetId($MsgData3);
- $unread2 = Db::name("admin")->where("id", $auditData2["approver"])->value("unread");
- if (!empty($unread2)) {
- $unread2 = $unread2. ",". $MsgGetId3 ;
- } else {
- $unread2 = $MsgGetId3;
- }
- Db::name("admin")->where("id", $auditData2["approver"])->update(["unread" => $unread2]);
- //发送消息给第二个人有问题//你有一个审批待处理
- // if(empty($handle['financial'])){
- // $handle['financial'] = (array)$param['entrust_second_approver'];
- // }else{
- // $handle['financial'] = array_merge($handle['financial'], $param['entrust_second_approver']);
- // }
- // $this->Pushmessage->pushMessage($param['id'], $handle['financial'],$handle["company"]);
- }
- } catch (\Exception $e) {
- return to_assign(1, '操作失败,原因:' . $e->getMessage());
- }
- }
- return to_assign(0, "操作成功");
- }
- }
- /**
- * 撤回
- */
- public function withdraw()
- {
- if (request()->isAjax()) {
- $param = get_params();
- $status = Db::name("cost_project")->where("id", $param["id"])->field("project_status")->select();
- // halt($status[0]["status"]);
- if ($status[0]["project_status"] < 3) {
- 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, ["project_status" => 1]);
- 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()
- {
- $param = get_params();
- // halt($param);
- $type = isset($param['type']) ? $param['type'] : 0;
- if (request()->isAjax()) {
- $id = isset($param['id']) ? $param['id'] : 0;
- $detail = $this->model->getCostProjectById($id);
- if ($type == 2) {
- $review_unit_name = Db::name('department')->where(['id' => $detail["review_unit"]])->value('title');
- $unit_name = Db::name('admin')->where('id', $this->uid)->value('unit_name');
- $person = Db::name("admin")->where([["unit_name", "=", $unit_name], ["status", "=", 1]])->field(["id", "nickname"])->select()->toArray();
- $leader_id = Db::name("department")
- ->where([
- ["delete_time", "=", 0],
- ["pid", "=", 0],
- ["type", "=", 1], //1表示业主
- ["entrust_unit", "=", $unit_name]
- ])->value('leader_id');
- $proprietor_unit_name = Db::name("department")
- ->where([
- ["delete_time", "=", 0],
- ["pid", "=", 0],
- ["type", "=", 1], //1表示业主
- ["entrust_unit", "=", $unit_name]
- ])->column('unit_name');
- $admin_group_id=Db::name("admin")->where("id", $leader_id)->value("admin_group_id");
- $where = [
- ['status', '>=', 0],
- ["admin_group_id","=", $admin_group_id],
- ["unit_name","in",$proprietor_unit_name]
- ];
- $proprietor =Db::name("admin")->where($where)->field(["id","nickname"])->select()->toArray();
- $review_person = Db::name("admin")->where([["unit_name", "=", $detail["review_unit"]], ["status", "=", 1]])->field(["id", "nickname"])->select();
- $review_name = Db::name("admin")->where("id", $detail['review_head'])->field(["id", "nickname"])->find();
- $audit = Db::name("project_audit")->where([["project_id", "=", $id], ["sponsor_id", "=", $this->uid]])->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();
- $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();
- $project_log = self::project_log($id);
- View::assign('project_log', $project_log);
- $field = $this->Field->get_field_rules_new($this->uid);
- $field_edit = $this->Field->get_field_rules_edit_new($this->uid);
- 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;
- }
- if (!empty($detail)) {
- View::assign('advent_time', $advent_time);
- View::assign('comment', $comment);
- View::assign('project_id', $id);
- View::assign("audit", $audit);
- View::assign("review_name", $review_name);
- View::assign("review_person", $review_person);
- View::assign("person", $person);
- View::assign("proprietor", $proprietor);
- View::assign('detail', $detail);
- View::assign('review_unit_name', $review_unit_name);
- View::assign('field', $field);
- // dump($field_edit);
- View::assign('field_edit', $field_edit);
- View::assign('file_array', $file_array);
- View::assign('project_five', self::getProjectFive());
- return view();
- } else {
- throw new \think\exception\HttpException(404, '找不到页面');
- }
- }
- 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(($param["entrust_second_approver"])&&!empty($param["entrust_second_approver"])){
- $param["entrust_second_approver_name"] = get_admin($param["entrust_second_approver"])["nickname"];
- }
- //财评送审
- if(isset($detail["sent_review_head"]) && $detail.proprietor_status==0){
- $param["sent_review_head_name"] = get_admin($param["sent_review_head"])["nickname"];
- $param["sent_review_unit"]=get_admin($param["sent_review_head"])["unit_name"];
- $param["sent_review_unit_name"]=Db::name("department")->where("id",$param["sent_review_unit"])->value("title");
- $param["sent_review_phone"] = get_admin($param["sent_review_head"])["mobile"];//电话
- }
- //业主创建送审
- if(isset($detail["sent_review_head"])&&$detail.proprietor_status==3){
- $param["sent_review_head_name"] = get_admin($detail["sent_review_head"])["nickname"];
- $param["sent_review_unit"]=get_admin($detail["sent_review_head"])["unit_name"];
- $param["sent_review_unit_name"]=Db::name("department")->where("id",$detail["sent_review_unit"])->value("title");
- $param["sent_review_phone"] = get_admin($detail["sent_review_head"])["mobile"];//电话
- }
- $field_name = array_keys($this->field_name);
- $ab = $this->model->where("id", $param["id"])->field($field_name)->find()->toArray();
- $ab["project_start_time"] = date('Y-m-d', $ab["project_start_time"]);
- $ab["project_end_time"] = date('Y-m-d', $ab["project_end_time"]);
- $c = array_intersect_key($param, $ab);
- if (isset($c["project_start_time"])) {
- $c["project_start_time"] = date('Y-m-d', $c["project_start_time"]);
- }
- if (isset($c["project_end_time"])) {
- $c["project_end_time"] = date('Y-m-d', $c["project_end_time"]);
- }
- $maker_name = get_login_admin("nickname");
- $content = '';
- foreach ($c as $key => $value) {
- if ($c[$key] !== $ab[$key]) {
- $value = !empty($value) ? $value : "无";
- $content = $content . $this->field_name[$key] . "从" . $ab[$key] . "修改为" . $value . ",";
- }
- }
- $content = rtrim($content, ",");
- if (empty($content)) {
- $content = "无修改";
- }
- add_project_log('编辑', $param["id"], $content, 1);
- $this->model->editCostProject($param);
- } else {//提交前
- $id = isset($param['id']) ? $param['id'] : 0;
- $detail = $this->model->getCostProjectById($id);
- $review_unit_name = Db::name('department')->where(['id' => $detail["review_unit"]])->value('title');
- $unit_name = get_login_admin("unit_name");
- $person = Db::name("admin")->where([["unit_name", "=", $unit_name], ["status", "=", 1]])->field(["id", "nickname"])->select()->toArray();
- $review_person = Db::name("admin")->where([["unit_name", "=", $detail["review_unit"]], ["status", "=", 1]])->field(["id", "nickname"])->select();
- $review_name = Db::name("admin")->where("id", $detail['review_head'])->field(["id", "nickname"])->find();
- $audit = Db::name("project_audit")->where([["project_id", "=", $id], ["sponsor_id", "=", $this->uid]])->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();
- $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();
- $project_log = self::project_log($id);
- View::assign('project_log', $project_log);
- $field = $this->Field->get_field_rules_new($this->uid);
- $field_edit = $this->Field->get_field_rules_edit_new($this->uid);
- //小红点消息
- $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];
- }
- // dump($red);
- 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;
- }
- $detail["project_end_time"] !=null?$detail["project_end_time"]:null;
- $detail["project_start_time"] !=null?$detail["project_start_time"]:null;
- //送审业主
- $leader_id = Db::name("department")
- ->where([
- ["delete_time", "=", 0],
- ["pid", "=", 0],
- ["type", "=", 1], //1表示业主
- ["entrust_unit", "=", $unit_name]
- ])->value('leader_id');
- $proprietor_unit_name = Db::name("department")
- ->where([
- ["delete_time", "=", 0],
- ["pid", "=", 0],
- ["type", "=", 1], //1表示业主
- ["entrust_unit", "=", $unit_name]
- ])->column('unit_name');
- // dump( $proprietor_unit_name);
- $admin_group_id=Db::name("admin")->where("id", $leader_id)->value("admin_group_id");
- $where = [
- ['status', '>=', 0],
- ["admin_group_id","=", $admin_group_id],
- ["unit_name","in",$proprietor_unit_name]
- ];
- $proprietor =Db::name("admin")->where($where)->field(["id","nickname"])->select()->toArray();
- $proprietor = array_values($proprietor);
- View::assign("proprietor", $proprietor);
- //
- if (!empty($detail)) {
- View::assign('advent_time', $advent_time);
- View::assign('comment', $comment);
- View::assign('project_id', $id);
- View::assign('red', $red);
- View::assign("audit", $audit);
- View::assign("review_name", $review_name);
- View::assign("review_person", $review_person);
- View::assign("person", $person);
- View::assign('detail', $detail);
- View::assign('review_unit_name', $review_unit_name);
- View::assign('field', $field);
- // dump($field_edit);
- View::assign('field_edit', $field_edit);
- View::assign('file_array', $file_array);
- View::assign('project_five', self::getProjectFive());
- return view();
- } else {
- throw new \think\exception\HttpException(404, '找不到页面');
- }
- }
- }
- public function get_file(){
- $param = get_params();
- $id = isset($param['id']) ? $param['id'] : 0;
- $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,mf.remark')
- ->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'))
- ->paginate(9999, false, ['query' => $param]);
- return table_assign(0, '', $file_array);
- }
- public function project_log($project_id)
- {
- // $project_id = 24;
- $login_admin = get_admin(get_login_admin('id'));
- $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']);
- if($login_admin['user_type'] != 0){
- if(str($project_log[$key]['content'], '送审单位承担审核费')){
- unset($project_log[$key]);
- }
- if(str($project_log[$key]['content'], '施工单位负责核减超5%评审费部分')){
- unset($project_log[$key]);
- }
- }
- }
- $project_log = array_values($project_log);
- // dump($project_log);
- // View::assign('project_log', $project_log);
- // return View();
- return $project_log;
- }
- /**
- * 查看信息
- */
- 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();
- $uid = Db::name("relation")->where("uuid",$id)->column("uid");
- $contract = Db::name("contract")->whereIn("id",$uid)
- ->where("subject_id",get_login_admin("unit_name"))->column("id,name,type,sign_time,sign_name");
- //小红点消息
- $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];
- }
- //剩余时间
- $c = $detail['project_end_time'] - time();
- if ($c > 0) {
- $advent_time = floor($c / 86400) . "天";
- } else {
- $c = -$c;
- $advent_time = floor($c / 86400) . "天";
- }
- $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);
- if (!empty($detail)) {
- View::assign('advent_time', $advent_time);
- 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('contract', $contract);
- View::assign('red', $red);
- View::assign('project_five', self::getProjectFive());
- // dump(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("project_status")->select();
- if ($status[0]["project_status"] < 3) {
- $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');
- });
- table_assign(0, '', $list);
- }
- //获取客户列表
- public function addConstructionPeople()
- {
- if (request()->isAjax()) {
- $param = get_params();
- if ($param['type'] == '1') {
- $data = $this->model->where('id', $param['data']['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, "请上传!!");
- }
- } else {
- $this->model->addConstructionPeople($param['data']);
- }
- add_project_log('添加施工单位人员', $param['data']['id'], '添加施工单位人员');
- } else {
- $param = get_params();
- $project_id = isset($param['project_id']) ? $param['project_id'] : 0;
- //关联项目id
- View::assign('project_id', $project_id);
- return view();
- }
- }
- //获取业主列表
- public function get_proprietor_list()
- {
- $param = get_params();
- $where = array();
- if (!empty($param['keywords'])) {
- $where[] = ['id|title', 'like', '%' . $param['keywords'] . '%'];
- }
- $where = [
- ["delete_time", "=", 0],
- ["pid", "=", 0],
- ["type", "=", 1],
- ["entrust_unit", "=", get_admin($this->uid)['unit_name']]
- ];
- $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 add_sent_review_unit()
- {
- if (request()->isAjax()) {
- $param = get_params();
- if ($param['type'] == '1') {
- $data = $this->model->where('id', $param['data']['id'])->find();
- if ($data["sent_review_unit_name"] !== null ||
- $data["sent_review_head_name"] !== null ||
- $data["sent_review_head_email"] !== null ||
- $data["sent_review_phone"] !== null
- ) {
- return to_assign(0, "已存在,请移除后再添加");
- } else {
- return to_assign(200, "请上传!!");
- }
- } else {
- add_project_log('移除送审单位成员', $param['data']['id'], $param['data']["sent_review_head_name"], 5);
- $this->model->addConstructionPeople($param['data']);
- }
- add_project_log('新增送审单位成员', $param['data']['id'], '新增送审单位成员');
- } else {
- $param = get_params();
- $project_id = isset($param['project_id']) ? $param['project_id'] : 0;
- //关联项目id
- View::assign('project_id', $project_id);
- return view();
- }
- }
- //添加送审单位
- // public function add_sent_review_unit()
- // {
- // if (request()->isAjax()) {
- // $param = get_params();
- // $id = isset($param["id"]) ? $param["id"] : 0;
- // $project_id = isset($param["project_id"]) ? $param["project_id"] : 0;
- // $a = $this->model->where("id", $project_id)->value("sent_review_head");
- // if ($a) {
- // return to_assign(1, '已有负责人,请移除后再添加');
- // }
- // $selfData = get_admin($id);
- // $data = [
- // "id" => $project_id,
- // "sent_review_head" => $id,
- // "sent_review_head_name" => $selfData["nickname"],
- // "sent_review_unit" => $selfData["unit_name"],
- // "sent_review_unit_name" => Db::name("department")->where("id", $selfData["unit_name"])->value("title"),
- // "sent_review_phone" => $selfData["mobile"]
- // ];
- // try {
- // $this->model->update($data);
- // } catch (\Exception $e) {
- // return to_assign(1, '操作失败,原因:' . $e->getMessage());
- // }
- // add_project_log('添加送审单位成员', $project_id, $selfData["nickname"], 5);
- // return to_assign(0, "操作成功");
- // }
- // }
- //移除送审单位成员
- public function remove_sent_review()
- {
- $p = get_params();
- $project_id = isset($p["project_id"]) ? $p["project_id"] : 0;
- $data = [
- "sent_review_unit" => null,
- "sent_review_unit_name" => null,
- "sent_review_head_name" => null,
- "sent_review_head" => null,
- "sent_review_phone" => null,
- "sent_review_head_email" => null,
- ];
- $this->model->where("id", $project_id)->update($data);
- remove_user($p["id"]);
- add_project_log('移除送审单位成员', $project_id, $p["nickname"], 5);
- return to_assign(0, "操作成功");
- }
- public function project_user()
- {
- $param = get_params();//9.13加了一个送审人的 //委托创建人,评审负责人/操作team/
- $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"];
- $time_id = time();
- $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_id;
- $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);
- }
- $time_id_sent = time()-200;
- if ($shigong["sent_review_unit"] !== null ||
- $shigong["sent_review_head"] !== null ||
- $shigong["sent_review_phone"] !== null ||
- $shigong["sent_review_head_email"] !== null
- ) {
- $sent_review_data["id"] = $time_id_sent;
- $sent_review_data["nickname"] = $shigong["sent_review_head_name"];
- $sent_review_data["unit_name"] = $shigong["sent_review_unit_name"];
- $sent_review_data["email"] = $shigong["sent_review_head_email"];
- $sent_review_data["mobile"] = $shigong["sent_review_phone"];
- $sent_review_data["unit_type"] = "送审单位";
- array_push($list, $sent_review_data);
- }
- if (empty($ids['operate_team'])) {
- $operate_team[] = '0';
- } else {
- $operate_team = explode(',', $ids['operate_team']);
- }
- 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'], $operate_team)) {
- $list[$i]["type"] = 4;
- } elseif ($list[$i]['id'] == $time_id) {
- $list[$i]["type"] = 5;
- } elseif ($list[$i]['id'] !== time() - 1000) {
- $list[$i]["type"] = 6;
- }
- }
- $type = array_column($list, 'type');
- array_multisort($type, SORT_ASC, $list);
- $lists["total"] = count($list);
- $lists["data"] = $list;
- return table_assign(0, '', $lists);
- }
- public function remove_construction_user()
- {
- $p = get_params();
- $data = [
- "construction_unit" => null,
- "construction_head" => null,
- "construction_email" => null,
- "construction_phone" => null
- ];
- $this->model->where("id", $p["project_id"])->update($data);
- add_project_log('删除施工方人员', $p["project_id"], '删除施工方人员');
- return to_assign(0, "操作成功");
- }
- public function getProjectFive()
- {
- $where = [
- ['name', '=', '作业日志-财政局'],
- ['name', '=', '工作记录-财政局'],
- ['name', '=', '项目报告-财政局'],
- ['name', '=', '项目人员-财政局'],
- ['name', '=', '项目动态-财政局'],
- ['name', '=', '项目附件-财政局'],
- ['name', '=', '联系函-财政局'],
-
- ];
- //where0r满足任意一个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();
- //in_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 ceshi($id)
- {
- View::assign('detailId', $id);
- return view();
- }
- }
|