Cost.php 71 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657
  1. <?php
  2. //declare (strict_types=1);
  3. namespace app\admin\controller\project;
  4. use app\admin\BaseController;
  5. use app\admin\model\Admin;
  6. use app\admin\model\Department as DepartmentModel;
  7. use app\admin\model\CostProject as CostProjectModel;
  8. use app\admin\model\ProjectAudit;
  9. use app\admin\model\ProjectMsg;
  10. use app\admin\model\ProjectFile;
  11. use app\admin\validate\project\CostProjectValidate;
  12. use app\wechat\controller\Officialaccount;
  13. use think\db\Where;
  14. use think\exception\ValidateException;
  15. use think\facade\Db;
  16. use think\facade\View;
  17. use think\App;
  18. use app\admin\controller\field\Field;
  19. use app\admin\controller\Pushmessage;
  20. class Cost extends BaseController
  21. {
  22. private array $field_name = [
  23. 'project_num' => '项目编号',
  24. "project_name" => "项目名称",
  25. "project_start_time" => "项目开始时间",
  26. "project_end_time" => "项目结束时间",
  27. "review_unit" => "评审单位",
  28. "sent_review_unit" => "送审单位",
  29. "sent_review_head" => "送审单位负责人",
  30. "sent_review_phone" => "送审单位负责人电话",
  31. "construction_unit" => "施工单位",
  32. "construction_head" => "施工单位负责人",
  33. "construction_phone" => "施工单位负责人电话",
  34. "sent_review_amount" => "送审金额",
  35. "engineering_type" => '工程类型',
  36. ];
  37. /**
  38. * 构造函数
  39. */
  40. public function __construct(App $app)
  41. {
  42. parent::__construct($app);
  43. $this->Field = new Field($this->app);
  44. $this->department = new DepartmentModel();
  45. $this->model = new CostProjectModel();
  46. $this->ProjectAuditModel = new ProjectAudit ();
  47. $this->ProjectMsg = new ProjectMsg();
  48. $this->filemodel = new ProjectFile();
  49. $this->uid = get_login_admin('id');
  50. $this->Adminmodel = new Admin();
  51. $this->time = time();
  52. $this->Officialaccount = new Officialaccount();
  53. $this->Pushmessage = new Pushmessage();
  54. }
  55. /**
  56. * 数据列表
  57. */
  58. public function datalist()
  59. {
  60. if (request()->isAjax()) {
  61. $param = get_params();
  62. $rows = empty($param['limit']) ? get_config('app . page_size') : $param['limit'];
  63. $order = empty($param['order']) ? 'id desc' : $param['order'];
  64. if (isset($param["project_start_time"])) {
  65. $param["project_start_time"] = $param["project_start_time"] ? strtotime($param["project_start_time"]) : 0;
  66. }
  67. if (isset($param["project_end_time"])) {
  68. $param["project_end_time"] = $param["project_end_time"] ? strtotime($param["project_end_time"]) : 0;
  69. }
  70. //项目可见的权限
  71. $field = $this->Field->get_field_rules_new($this->uid);//获取当前登录的id
  72. //1全部-可查看可编辑,2全部-可查看,0与我有关
  73. $see_auth = isset($field["see_auth"]) ? $field["see_auth"] : 3;//等于3
  74. $where[] = ["delete_time", "=", 0];
  75. $where[] = ["project_status", ">", 0];
  76. $where2[] = ["delete_time", "=", 0];
  77. $where2[] = ["project_status", ">", 0];
  78. if ($see_auth == 3||$see_auth == 0) {
  79. $where[] = ["entrust_maker", "=", $this->uid];
  80. $where2[] = ["entrust_approver", "=", $this->uid];
  81. $where2[] = ["project_status", ">", 1];//大于立项
  82. }
  83. $where3 =[];
  84. if (!empty($param['project_status'])) {
  85. $where3[] = ['project_status', '=', $param['project_status']];
  86. }
  87. if (!empty($param['province'])) {
  88. $where3[] = ['province', '=', $param['province']];
  89. }
  90. if (!empty($param['city'])) {
  91. $where3[] = ['city', '=', $param['city']];
  92. }
  93. if (!empty($param['area'])) {
  94. $where3[] = ['area', '=', $param['area']];
  95. }
  96. if (!empty($param['project_end_time'])) {
  97. $where3[] = ['project_end_time', '<', $param['project_end_time']];
  98. }
  99. if (!empty($param['project_start_time'])) {
  100. $where3[] = ['project_start_time', '>', $param['project_start_time']];
  101. }
  102. if (!empty($param['keyword'])) {
  103. $keyword = $param['keyword'];
  104. $where3[] = ['project_num|project_name|review_unit', 'like', '%' . $keyword . '%'];
  105. }
  106. if (!empty($param['review_head_name'])) {
  107. $where3[] = ['review_head_name', 'like', '%' . $param['review_head_name'] . '%'];
  108. }
  109. if (!empty($param['review_unit_name'])) {
  110. $where3[] = ['review_unit_name', 'like', '%' . $param['review_unit_name']. '%'];
  111. }
  112. if (!empty($param['sent_review_unit_name'])) {
  113. $where3[] = ['sent_review_unit_name', 'like', '%' . $param['sent_review_unit_name']. '%'];
  114. }
  115. $where3[] = ["entrust_unit", "=", get_login_admin('unit_name')];
  116. $this->see_auth = $see_auth;
  117. $list = $this->model
  118. ->where($where3)->where(function ($query) use ($where,$where2) {
  119. // 第一组条件(entrust_maker)
  120. $query->where(function ($q1) use ($where) {
  121. $q1->where($where);
  122. });
  123. // 使用 OR 连接第二组条件(entrust_approver)
  124. $query->whereOr(function ($q2) use ($where2) {
  125. $q2->where($where2);
  126. });
  127. })
  128. ->order($order)->paginate($rows, false, ['query' => $param])
  129. ->each(function ($item) {
  130. $red = Db::name("new_msg")->where([["project_id", "=", $item->id], ["uid", "=", $this->uid]])->find();
  131. if ($red) {
  132. if ($red["detail"] || $red["comment"] || $red["report"] || $red["user"] || $red["contact"]) {
  133. $item->red = 1;
  134. }
  135. } else {
  136. $item->red = 0;
  137. }
  138. if (($item->province && $item->city && $item->area)) {
  139. $item->project_region = $item->province . '-' . $item->city . '-' . $item->area;
  140. }
  141. $item->creator = Db::name("admin")->where("id",$item->creator)->value("nickname");
  142. $item->self_id = $this->see_auth;
  143. //作业人
  144. $operate_team_names = null;
  145. $operate_team_names_ids = explode(",", $item->operate_team);
  146. for ($i = 0; $i < count($operate_team_names_ids); $i++) {
  147. $name = Db::name("admin")->where("id", $operate_team_names_ids[$i])->value("nickname");
  148. if (!($i == 0)) {
  149. $name = "," . $name;
  150. }
  151. $operate_team_names = $operate_team_names . $name;
  152. }
  153. $item->operate_team_names = $operate_team_names;
  154. });
  155. return table_assign(0, '', $list);
  156. } else {
  157. $field = $this->Field->get_field_rules_new($this->uid);
  158. $fields = [];
  159. foreach ($field as $k=>$v){
  160. if($v!=1){
  161. $fields[$k] = true;
  162. }else{
  163. $fields[$k] = false;
  164. }
  165. }
  166. View::assign('field', $fields);
  167. return view();
  168. }
  169. }
  170. /**
  171. * 数据列表
  172. */
  173. public function followProject()
  174. {
  175. if (request()->isAjax()) {
  176. $param = get_params();
  177. $rows = empty($param['limit']) ? get_config('app . page_size') : $param['limit'];
  178. $order = empty($param['order']) ? 'id desc' : $param['order'];
  179. $openid = get_login_admin('openid');
  180. $follow_project_id = Db::name('follow_project')->where('openid',$openid)->find();
  181. // halt($openid,$follow_project_id);
  182. if (isset($param["project_start_time"])) {
  183. $param["project_start_time"] = $param["project_start_time"] ? strtotime($param["project_start_time"]) : 0;
  184. }
  185. if (isset($param["project_end_time"])) {
  186. $param["project_end_time"] = $param["project_end_time"] ? strtotime($param["project_end_time"]) : 0;
  187. }
  188. $where[] = ["delete_time", "=", 0];
  189. $where[] = ["project_status", ">", 0];
  190. $where2[] = ["delete_time", "=", 0];
  191. $where2[] = ["project_status", ">", 0];
  192. $where3 =[];
  193. if (!empty($param['project_status'])) {
  194. $where3[] = ['project_status', '=', $param['project_status']];
  195. }
  196. if (!empty($param['province'])) {
  197. $where3[] = ['province', '=', $param['province']];
  198. }
  199. if (!empty($param['city'])) {
  200. $where3[] = ['city', '=', $param['city']];
  201. }
  202. if (!empty($param['area'])) {
  203. $where3[] = ['area', '=', $param['area']];
  204. }
  205. if (!empty($param['project_end_time'])) {
  206. $where3[] = ['project_end_time', '<', $param['project_end_time']];
  207. }
  208. if (!empty($param['project_start_time'])) {
  209. $where3[] = ['project_start_time', '>', $param['project_start_time']];
  210. }
  211. if (!empty($param['keyword'])) {
  212. $keyword = $param['keyword'];
  213. $where3[] = ['project_num|project_name|review_unit', 'like', '%' . $keyword . '%'];
  214. }
  215. if (!empty($param['review_head_name'])) {
  216. $where3[] = ['review_head_name', 'like', '%' . $param['review_head_name'] . '%'];
  217. }
  218. if (!empty($param['review_unit_name'])) {
  219. $where3[] = ['review_unit_name', 'like', '%' . $param['review_unit_name']. '%'];
  220. }
  221. if (!empty($param['sent_review_unit_name'])) {
  222. $where3[] = ['sent_review_unit_name', 'like', '%' . $param['sent_review_unit_name']. '%'];
  223. }
  224. $list = $this->model
  225. ->where('id','in',$follow_project_id)
  226. ->where($where3)->where(function ($query) use ($where,$where2) {
  227. // 第一组条件(entrust_maker)
  228. $query->where(function ($q1) use ($where) {
  229. $q1->where($where);
  230. });
  231. // 使用 OR 连接第二组条件(entrust_approver)
  232. $query->whereOr(function ($q2) use ($where2) {
  233. $q2->where($where2);
  234. });
  235. })
  236. ->order($order)->paginate($rows, false, ['query' => $param])
  237. ->each(function ($item) {
  238. if (($item->province && $item->city && $item->area)) {
  239. $item->project_region = $item->province . '-' . $item->city . '-' . $item->area;
  240. }
  241. $item->creator = Db::name("admin")->where("id",$item->creator)->value("nickname");
  242. //作业人
  243. $operate_team_names = null;
  244. $operate_team_names_ids = explode(",", $item->operate_team);
  245. for ($i = 0; $i < count($operate_team_names_ids); $i++) {
  246. $name = Db::name("admin")->where("id", $operate_team_names_ids[$i])->value("nickname");
  247. if (!($i == 0)) {
  248. $name = "," . $name;
  249. }
  250. $operate_team_names = $operate_team_names . $name;
  251. }
  252. $item->operate_team_names = $operate_team_names;
  253. });
  254. return table_assign(0, '', $list);
  255. }else {
  256. return view();
  257. }
  258. }
  259. /**
  260. * 临期
  261. */
  262. public function list()
  263. {
  264. // if (request()->isAjax()) {
  265. $param = get_params();
  266. $field = $this->Field->get_field_rules_new($this->uid);
  267. $see_auth = isset($field["see_auth"]) ? $field["see_auth"] : 3;
  268. $where = array();
  269. $where3 = array();
  270. if ($see_auth == 3 || $see_auth == 0) {
  271. $where = [
  272. ["entrust_maker", "=", $this->uid],
  273. ];
  274. $where3 = [
  275. ["entrust_approver", "=", $this->uid],
  276. ["project_status", ">", 1]
  277. ];
  278. }
  279. $where1 = [
  280. ["delete_time", "=", 0],
  281. ['project_end_time', '<', strtotime('15 days')],
  282. ['project_end_time', '>', time()],
  283. ["project_status", "<", 7],
  284. ["entrust_unit","=",get_login_admin("unit_name")]
  285. ];
  286. $where1 = array_merge($where, $where1);
  287. $where2 = array_merge($where1, $where3);
  288. $rows = empty($param['limit']) ? get_config('app . page_size') : $param['limit'];
  289. $order = empty($param['order']) ? 'id desc' : $param['order'];
  290. $list = $this->model->whereOr([$where1, $where2])
  291. ->order($order)
  292. ->paginate(9999, false, ['query' => $param])
  293. ->each(function ($item) {
  294. });
  295. return table_assign(0, '', $list);
  296. // }
  297. }
  298. /**
  299. * 逾期
  300. */
  301. public function list2()
  302. {
  303. $param = get_params();
  304. $field = $this->Field->get_field_rules_new($this->uid);
  305. $see_auth = isset($field["see_auth"]) ? $field["see_auth"] : 3;
  306. $where = array();
  307. $where3 = array();
  308. if ($see_auth == 3 || $see_auth == 0) {
  309. $where = [
  310. ["entrust_maker", "=", $this->uid],
  311. ];
  312. $where3 = [
  313. ["entrust_approver", "=", $this->uid],
  314. ["project_status", ">", 1]
  315. ];
  316. }
  317. $where2 = [
  318. ["delete_time", "=", 0],
  319. ['project_end_time', '<', time()],
  320. ["project_status", "<", 7],
  321. ["entrust_unit","=",get_login_admin("unit_name")]
  322. ];
  323. $where1 = array_merge($where, $where2);
  324. $where2 = array_merge($where2, $where3);
  325. $rows = empty($param['limit']) ? get_config('app . page_size') : $param['limit'];
  326. $order = empty($param['order']) ? 'id desc' : $param['order'];
  327. $list = $this->model->whereOr([$where1, $where2])
  328. ->order($order)->paginate(9999, false, ['query' => $param]);
  329. return table_assign(0, '', $list);
  330. // }
  331. }
  332. /**
  333. * 添加/保存
  334. */
  335. public function add()
  336. {
  337. if (request()->isAjax()) {
  338. $param = get_params();
  339. // halt($param);
  340. // 检验完整性
  341. try {
  342. validate(CostProjectValidate::class)->check($param);
  343. } catch (ValidateException $e) {
  344. // 验证失败 输出错误信息
  345. return to_assign(1, $e->getError());
  346. }
  347. if (isset($param["project_start_time"])) {
  348. $param["project_start_time"] = $param["project_start_time"] ? strtotime($param["project_start_time"]) : 0;
  349. }
  350. if (isset($param["project_end_time"])) {
  351. $param["project_end_time"] = $param["project_end_time"] ? strtotime($param["project_end_time"]) : 0;
  352. }
  353. $param["entrust_unit"] = get_login_admin("unit_name");
  354. $param["entrust_unit_name"] = Db::name("department")->where("id", get_login_admin("unit_name"))->value("title");
  355. $param["entrust_maker"] = $this->uid;
  356. $param["entrust_maker_name"] = get_login_admin("nickname");
  357. $param["entrust_phone"] = get_login_admin("mobile");
  358. if(($param["entrust_second_approver"])&&!empty($param["entrust_second_approver"])){
  359. $param["entrust_second_approver_name"] = get_admin($param["entrust_second_approver"])["nickname"];
  360. }
  361. $param["entrust_approver_name"] = get_admin($param["entrust_approver"])["nickname"];
  362. //送审
  363. // if(isset($param["sent_review_unit"]) && $param["sent_review_unit"] !== ""){
  364. // $sent_review_unit = Db::name("department")->where("id",$param["sent_review_unit"])->find();
  365. // $sent_review_head = Db::name("admin")->where("id",$sent_review_unit['leader_id'])->find();
  366. // $param["sent_review_head_name"] = $sent_review_head["nickname"];
  367. // $param["sent_review_phone"] = $sent_review_head["mobile"];
  368. // }
  369. $param["project_status"] = 1;
  370. $param["maker_type"] = 1;
  371. $param["creator"] = $this->uid;
  372. $file_ids = isset($param["file_ids"]) ? $param["file_ids"] : 0;
  373. unset($param["file_ids"]);
  374. $file_id = [];
  375. $insertId = 0;
  376. try {
  377. $param['create_time'] = time();
  378. //插入数据到并且返回数据id值
  379. $insertId = $this->model->strict(false)->field(true)->insertGetId($param);
  380. if ($file_ids) {
  381. for ($a = 0; $a < count($file_ids); $a++) {
  382. $file_id[] = ["id" => $file_ids[$a], "topic_id" => $insertId];
  383. }
  384. $this->filemodel->saveAll($file_id);
  385. }
  386. add_log('add', $insertId, $param);
  387. add_project_log("创建项目", $insertId, "创建项目");
  388. add_user($param["entrust_maker"], $insertId);
  389. add_user($param["entrust_approver"], $insertId);
  390. add_user($param["entrust_second_approver"], $insertId);
  391. } catch (\Exception $e) {
  392. return to_assign(1, '操作失败,原因:' . $e->getMessage());
  393. }
  394. return to_assign(0, '操作成功', ['aid' => $insertId]);
  395. //有日志了
  396. } else {
  397. //拿到自身的所属于单位和职位,查询和自身单位一样的账号,
  398. $unit_name = Db::name('admin')->where('id', $this->uid)->value('unit_name');
  399. $leader_id = Db::name("department")
  400. ->where([
  401. ["delete_time", "=", 0],
  402. ["pid", "=", 0],
  403. ["type", "=", 1], //1表示业主
  404. ["entrust_unit", "=", $unit_name]
  405. ])->value('leader_id');
  406. $proprietor_unit_name = Db::name("department")
  407. ->where([
  408. ["delete_time", "=", 0],
  409. ["pid", "=", 0],
  410. ["type", "=", 1], //1表示业主
  411. ["entrust_unit", "=", $unit_name]
  412. ])->column('unit_name');
  413. $admin_group_id=Db::name("admin")->where("id", $leader_id)->value("admin_group_id");
  414. $where = [
  415. ['status', '>=', 0],
  416. ["admin_group_id","=", $admin_group_id],
  417. ["unit_name","in",$proprietor_unit_name]
  418. ];
  419. $proprietor =Db::name("admin")->where($where)->field(["id","nickname"])->select()->toArray();
  420. $person = Db::name("admin")->where("unit_name", $unit_name)->where("status",">",0)->field(["id", "nickname"])->select()->toArray();
  421. $person = array_values($person);//返回数组所有值,索引从0
  422. $proprietor = array_values($proprietor);
  423. View::assign("person", $person);
  424. View::assign("proprietor", $proprietor);
  425. return view();
  426. }
  427. }
  428. public function getemployeelist()
  429. {
  430. if (request()->isAjax()) {
  431. $data = $this->request->param();
  432. $person = Db::name("admin")->where([["unit_name", "=", $data['id']], ["status", "=", 1]])->field(["id", "nickname", "mobile"])->select();
  433. return $person;
  434. }
  435. }
  436. /**
  437. * 提交审批
  438. */
  439. public function save()
  440. {
  441. if (request()->isAjax()) {
  442. $param = get_params();
  443. $handle = $this->Pushmessage->handleParam($param);//将财务,公司的信息与他分开
  444. $param = $handle['param'];//是项目的信息
  445. // 检验完整性
  446. try {
  447. validate(CostProjectValidate::class)->check($param);
  448. } catch (ValidateException $e) {
  449. // 验证失败 输出错误信息
  450. return to_assign(1, $e->getError());
  451. }
  452. if (isset($param["project_start_time"])) {
  453. $param["project_start_time"] = $param["project_start_time"] ? strtotime($param["project_start_time"]) : 0;
  454. }
  455. if (isset($param["project_end_time"])) {
  456. $param["project_end_time"] = $param["project_end_time"] ? strtotime($param["project_end_time"]) : 0;
  457. }
  458. $param["entrust_unit"] = get_login_admin("unit_name");
  459. $param["entrust_unit_name"] = Db::name("department")->where("id", get_login_admin("unit_name"))->value("title");
  460. $param["entrust_maker"] = $this->uid;
  461. $param["entrust_maker_name"] = get_login_admin("nickname");
  462. $param["entrust_phone"] = get_login_admin("mobile");
  463. //获取审批人员的名称,get_admin获取管理人员信息
  464. $param["entrust_approver_name"] = get_admin($param["entrust_approver"])["nickname"];
  465. if(isset($param["entrust_second_approver"])&&!empty($param["entrust_second_approver"])){
  466. $param["entrust_second_approver_name"] = get_admin($param["entrust_second_approver"])["nickname"];
  467. }
  468. //送审
  469. // if(isset($param["sent_review_unit"]) && $param["sent_review_unit"] !== ""){
  470. // $sent_review_unit = Db::name("department")->where("id",$param["sent_review_unit"])->find();
  471. // $sent_review_head = Db::name("admin")->where("id",$sent_review_unit['leader_id'])->find();
  472. // $param["sent_review_head_name"] = $sent_review_head["nickname"];
  473. // $param["sent_review_phone"] = $sent_review_head["mobile"];
  474. // }
  475. //提交后状态改变为2,待审批中
  476. $param["project_status"] = 2;
  477. $param["maker_type"] = 1;//财政
  478. //id=0代表项目创建
  479. if ($param["id"] == 0) {
  480. $file_id = [];
  481. $file_ids = isset($param["file_ids"]) ? $param["file_ids"] : 0;
  482. unset($param["file_ids"]);//去除附件
  483. // try {
  484. $param['create_time'] = time();
  485. $param['update_time'] = time();
  486. $param["creator"] = $this->uid;//登录的人的id
  487. //插入创建项目到costProject,并获取自增的id就是project_id
  488. $insertGetId = $this->model->where('id', $param['id'])->strict(false)->field(true)->insertGetId($param);
  489. if ($file_ids) {//有附件上传
  490. for ($a = 0; $a < count($file_ids); $a++) {
  491. $file_id[] = ["id" => $file_ids[$a], "topic_id" => $insertGetId];
  492. }
  493. $this->filemodel->saveAll($file_id);
  494. }
  495. //插入审批数据库记录,project_status=2,审批中
  496. $auditData1 = [
  497. "project_id" => $insertGetId,
  498. "project_name" => $param["project_name"],
  499. "project_type" => "造价项目",
  500. "audit_name" => "项目分配审核一审",
  501. "audit_type" => 1,
  502. "sponsor" => Db::name('admin')->where("id", $this->uid)->value("nickname"),
  503. "sponsor_id" => $this->uid,
  504. "sponsor_unit" => $param["review_unit_name"],
  505. "approver" => $param["entrust_approver"],
  506. "approver_name" => Db::name('admin')->where("id", $param["entrust_approver"])->value("nickname"),
  507. "create_time" => time()
  508. ];
  509. //插入
  510. ProjectAudit::create($auditData1);
  511. $MsgData1 = [
  512. "uid" => $auditData1["approver"],
  513. "project_id" => $insertGetId,
  514. "content" => get_login_admin("nickname") . "向您发起了一个" . $auditData1["audit_name"],
  515. "create_time" => time()
  516. ];
  517. $MsgGetId = $this->ProjectMsg->insertGetId($MsgData1);
  518. $unread = Db::name("admin")->where("id", $auditData1["approver"])->value("unread");
  519. if (!empty($unread)) {
  520. $unread = $unread . "," . $MsgGetId;
  521. } else {
  522. $unread = $MsgGetId;
  523. }
  524. Db::name("admin")->where("id", $auditData1["approver"])->update(["unread" => $unread]);
  525. if(empty($handle['financial'])){
  526. $handle['financial'] = (array)$param['entrust_approver'];
  527. }else{
  528. $handle['financial'] = array_merge($handle['financial'], $param['entrust_approver']);
  529. }
  530. if(empty($handle['proprietor'])){
  531. if(isset($param['sent_review_head']) && $param['sent_review_head'] != ""){
  532. $handle['proprietor'] = (array)$param['sent_review_head'];
  533. }else{
  534. $handle['proprietor'] = (array)0;
  535. }
  536. }else{
  537. if(isset($param['sent_review_head']) && $param['sent_review_head'] != ""){
  538. $handle['proprietor'] = array_merge($handle['financial'], $param['sent_review_head']);
  539. }else{
  540. $handle['proprietor'] = (array)0;
  541. }
  542. }
  543. // 发送消息,/项目id/发给的财务人员/公司人员都是int整数
  544. $this->Pushmessage->pushMessage($insertGetId, $handle['financial'], $handle['company'],$handle["proprietor"]);
  545. if(!empty($param["entrust_second_approver"])){
  546. $auditData2 = [
  547. "project_id" => $insertGetId,
  548. "project_name" => $param["project_name"],
  549. "project_type" => "造价项目",
  550. "audit_name" => "项目分配审核二审",
  551. "audit_type" => 0,
  552. "audit_status" =>5,//待启用
  553. "sponsor" => Db::name('admin')->where("id", $this->uid)->value("nickname"),
  554. "sponsor_id" => $this->uid,
  555. "sponsor_unit" => $param["review_unit_name"],
  556. "approver" => $param["entrust_second_approver"],
  557. "approver_name" => Db::name('admin')->where("id", $param["entrust_second_approver"])->value("nickname"),
  558. "create_time" => time()
  559. ];
  560. ProjectAudit::create($auditData2);
  561. $MsgData2 = [
  562. "uid" =>$auditData2["approver"],//显示的文本,传来的id
  563. "project_id" => $insertGetId,
  564. "content" => get_login_admin("nickname") . "向您发起了一个" . $auditData2["audit_name"],
  565. "create_time" => time()
  566. ];
  567. $MsgData3 = [
  568. "uid" =>$auditData2["approver"],//显示的文本,传来的id
  569. "project_id" => $insertGetId,
  570. "content" => "您有一个新的待审批项目等待处理。" ."项目名称:".$auditData2["project_name"]." 申请人:".get_login_admin("nickname"),
  571. "create_time" => time()
  572. ];
  573. // 插入第一条数据($MsgData2)
  574. $MsgGetId2 = $this->ProjectMsg->insertGetId($MsgData2);
  575. $unread1 = Db::name("admin")->where("id", $auditData2["approver"])->value("unread");
  576. if (!empty($unread1)) {
  577. $unread1 = $unread1. ",". $MsgGetId2;
  578. } else {
  579. $unread1 = $MsgGetId2;
  580. }
  581. Db::name("admin")->where("id", $auditData2["approver"])->update(["unread" => $unread1]);
  582. //插入第二条
  583. $MsgGetId3 = $this->ProjectMsg->insertGetId($MsgData3);
  584. $unread2 = Db::name("admin")->where("id", $auditData2["approver"])->value("unread");
  585. if (!empty($unread2)) {
  586. $unread2 = $unread2. ",". $MsgGetId3 ;
  587. } else {
  588. $unread2 = $MsgGetId3;
  589. }
  590. Db::name("admin")->where("id", $auditData2["approver"])->update(["unread" => $unread2]);
  591. // if(empty($handle['financial'])){
  592. // $handle['financial'] = (array)$param['entrust_second_approver'];
  593. // }else{
  594. // $handle['financial'] = array_merge($handle['financial'], $param['entrust_second_approver']);
  595. // }
  596. // // 发送消息,/项目id/发给的财务人员/公司人员都是int整数
  597. // $this->Pushmessage->pushMessage($insertGetId, $handle['financial'], $handle['company']);
  598. }
  599. add_log('edit', $insertGetId, $param);
  600. add_project_log("创建项目", $insertGetId, $param["project_name"]);
  601. $secondApproverName =!empty($param["entrust_second_approver"])? "第二审核:".$auditData2["approver_name"] : "";
  602. add_project_log("提交立项审批", $insertGetId, "提交立项审批, 审批人有:第一审核:". $auditData1["approver_name"]. " ". $secondApproverName);
  603. add_user($param["entrust_maker"], $insertGetId);
  604. add_user($param["entrust_approver"], $insertGetId);
  605. //新增
  606. }
  607. else {
  608. //编辑时
  609. try {
  610. $file_ids = isset($param["file_ids"]) ? $param["file_ids"] : 0;
  611. unset($param["file_ids"]);
  612. $param['update_time'] = time();
  613. $this->model->where('id', $param['id'])->strict(false)->field(true)->update($param);
  614. if ($file_ids) {
  615. for ($a = 0; $a < count($file_ids); $a++) {
  616. $file_id[] = ["id" => $file_ids[$a], "topic_id" => $param['id']];
  617. }
  618. $this->filemodel->saveAll($file_id);
  619. }
  620. //审批记录,project_status=2,审批中,编辑时传过来的id就是已经创建好了的project_id
  621. $auditData1 = [
  622. "project_id" => $param['id'],
  623. "project_name" => $param["project_name"],
  624. "project_type" => "造价项目",
  625. "audit_name" => "项目分配审核一审",
  626. "audit_type" => 1,
  627. "sponsor" => Db::name('admin')->where("id", $this->uid)->value("nickname"),
  628. "sponsor_id" => $this->uid,
  629. "sponsor_unit" => $param["review_unit_name"],
  630. "approver" => $param["entrust_approver"],
  631. "approver_name" => Db::name('admin')->where("id", $param["entrust_approver"])->value("nickname"),
  632. "create_time" => time()
  633. ];
  634. ProjectAudit::create($auditData1);
  635. //审批记录消息
  636. $MsgData1 = [
  637. "uid" => $auditData1["approver"],
  638. "project_id" => $param['id'],
  639. "content" => get_login_admin("nickname") . "向您发起了一个" . $auditData1["audit_name"],
  640. "create_time" => time()
  641. ];
  642. $MsgGetId = $this->ProjectMsg->insertGetId($MsgData1);
  643. $unread = Db::name("admin")->where("id", $auditData1["approver"])->value("unread");
  644. if (!empty($unread)) {
  645. $unread = $unread . "," . $MsgGetId;
  646. } else {
  647. $unread = $MsgGetId;
  648. }
  649. Db::name("admin")->where("id", $auditData1["approver"])->update(["unread" => $unread]);
  650. add_project_log("提交立项审批", $param['id'], "提交立项审批");
  651. add_user($param["entrust_approver"], $param['id']);
  652. if(empty($handle['financial'])){
  653. $handle['financial'] = (array)$param['entrust_approver'];
  654. }else{
  655. $handle['financial'] = array_merge($handle['financial'], $param['entrust_approver']);
  656. }
  657. $this->Pushmessage->pushMessage($param['id'], $handle['financial'], $handle['company']);
  658. //二
  659. if(!empty($param["entrust_second_approver"])){
  660. $auditData2 = [
  661. "project_id" => $param['id'],
  662. "project_name" => $param["project_name"],
  663. "project_type" => "造价项目",
  664. "audit_name" => "项目分配审核二审",
  665. "audit_type" => 0,
  666. "audit_status" =>5,//待启用
  667. "sponsor" => Db::name('admin')->where("id", $this->uid)->value("nickname"),
  668. "sponsor_id" => $this->uid,
  669. "sponsor_unit" => $param["review_unit_name"],
  670. "approver" => $param["entrust_second_approver"],
  671. "approver_name" => Db::name('admin')->where("id", $param["entrust_second_approver"])->value("nickname"),
  672. "create_time" => time()
  673. ];
  674. ProjectAudit::create($auditData2);
  675. $MsgData2 = [
  676. "uid" =>$auditData2["approver"],//显示的文本,传来的id
  677. "project_id" => $param['id'],
  678. "content" => get_login_admin("nickname") . "向您发起了一个" . $auditData2["audit_name"],
  679. "create_time" => time()
  680. ];
  681. $MsgGetId = $this->ProjectMsg->insertGetId($MsgData2);
  682. $unread = Db::name("admin")->where("id", $auditData2["approver"])->value("unread");
  683. if (!empty($unread)) {
  684. $unread = $unread . "," . $MsgGetId;
  685. } else {
  686. $unread = $MsgGetId;
  687. }
  688. Db::name("admin")->where("id", $auditData2["approver"])->update(["unread" => $unread]);
  689. add_user($param["entrust_second_approver"], $param['id']);
  690. $MsgData3 = [
  691. "uid" =>$auditData2["approver"],//显示的文本,传来的id
  692. "project_id" => $param["id"],
  693. "content" => "您有一个新的待审批项目等待处理。" ."项目名称:".$auditData2["project_name"]." 申请人:".get_login_admin("nickname"),
  694. "create_time" => time()
  695. ];
  696. //插入第二条
  697. $MsgGetId3 = $this->ProjectMsg->insertGetId($MsgData3);
  698. $unread2 = Db::name("admin")->where("id", $auditData2["approver"])->value("unread");
  699. if (!empty($unread2)) {
  700. $unread2 = $unread2. ",". $MsgGetId3 ;
  701. } else {
  702. $unread2 = $MsgGetId3;
  703. }
  704. Db::name("admin")->where("id", $auditData2["approver"])->update(["unread" => $unread2]);
  705. //发送消息给第二个人有问题//你有一个审批待处理
  706. // if(empty($handle['financial'])){
  707. // $handle['financial'] = (array)$param['entrust_second_approver'];
  708. // }else{
  709. // $handle['financial'] = array_merge($handle['financial'], $param['entrust_second_approver']);
  710. // }
  711. // $this->Pushmessage->pushMessage($param['id'], $handle['financial'],$handle["company"]);
  712. }
  713. } catch (\Exception $e) {
  714. return to_assign(1, '操作失败,原因:' . $e->getMessage());
  715. }
  716. }
  717. return to_assign(0, "操作成功");
  718. }
  719. }
  720. /**
  721. * 撤回
  722. */
  723. public function withdraw()
  724. {
  725. if (request()->isAjax()) {
  726. $param = get_params();
  727. $status = Db::name("cost_project")->where("id", $param["id"])->field("project_status")->select();
  728. // halt($status[0]["status"]);
  729. if ($status[0]["project_status"] < 3) {
  730. if (isset($param["project_start_time"])) {
  731. $param["project_start_time"] = $param["project_start_time"] ? strtotime($param["project_start_time"]) : 0;
  732. }
  733. if (isset($param["project_end_time"])) {
  734. $param["project_end_time"] = $param["project_end_time"] ? strtotime($param["project_end_time"]) : 0;
  735. }
  736. $param = array_merge($param, ["project_status" => 1]);
  737. try {
  738. $param['update_time'] = time();
  739. $this->model->where('id', $param['id'])->strict(false)->field(true)->update($param);
  740. Db::name("ProjectAudit")->where([["project_id", "=", $param["id"]], ["audit_status", "in", [0,1,5]], ["audit_name", "in", ["项目分配审核一审", "项目分配审核二审"]]])->delete();
  741. add_log('edit', $param['id'], $param);
  742. add_project_log('撤回', $param['id'], "撤回");
  743. } catch (\Exception $e) {
  744. return to_assign(1, '操作失败,原因:' . $e->getMessage());
  745. }
  746. return to_assign(0, "操作成功");
  747. } else {
  748. return to_assign(0, "已审核,无法撤回");
  749. }
  750. }
  751. }
  752. /**
  753. * 编辑|保存
  754. */
  755. public function edit()
  756. {
  757. $param = get_params();
  758. // halt($param);
  759. $type = isset($param['type']) ? $param['type'] : 0;
  760. if (request()->isAjax()) {
  761. $id = isset($param['id']) ? $param['id'] : 0;
  762. $detail = $this->model->getCostProjectById($id);
  763. if ($type == 2) {
  764. $review_unit_name = Db::name('department')->where(['id' => $detail["review_unit"]])->value('title');
  765. $unit_name = Db::name('admin')->where('id', $this->uid)->value('unit_name');
  766. $person = Db::name("admin")->where([["unit_name", "=", $unit_name], ["status", "=", 1]])->field(["id", "nickname"])->select()->toArray();
  767. $leader_id = Db::name("department")
  768. ->where([
  769. ["delete_time", "=", 0],
  770. ["pid", "=", 0],
  771. ["type", "=", 1], //1表示业主
  772. ["entrust_unit", "=", $unit_name]
  773. ])->value('leader_id');
  774. $proprietor_unit_name = Db::name("department")
  775. ->where([
  776. ["delete_time", "=", 0],
  777. ["pid", "=", 0],
  778. ["type", "=", 1], //1表示业主
  779. ["entrust_unit", "=", $unit_name]
  780. ])->column('unit_name');
  781. $admin_group_id=Db::name("admin")->where("id", $leader_id)->value("admin_group_id");
  782. $where = [
  783. ['status', '>=', 0],
  784. ["admin_group_id","=", $admin_group_id],
  785. ["unit_name","in",$proprietor_unit_name]
  786. ];
  787. $proprietor =Db::name("admin")->where($where)->field(["id","nickname"])->select()->toArray();
  788. $review_person = Db::name("admin")->where([["unit_name", "=", $detail["review_unit"]], ["status", "=", 1]])->field(["id", "nickname"])->select();
  789. $review_name = Db::name("admin")->where("id", $detail['review_head'])->field(["id", "nickname"])->find();
  790. $audit = Db::name("project_audit")->where([["project_id", "=", $id], ["sponsor_id", "=", $this->uid]])->order('create_time', 'desc')->select();
  791. $file_array = Db::name('ProjectFile')
  792. ->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')
  793. ->alias('mf')
  794. ->join('File f', 'mf.file_id = f.id', 'LEFT')
  795. ->join('Admin a', 'mf.admin_id = a.id', 'LEFT')
  796. ->order('mf.create_time desc')
  797. ->where(array('mf.topic_id' => $id, 'mf.module' => 'project'))
  798. ->select()->toArray();
  799. $comment_type = isset($param["comment_type"])?$param['comment_type'] : 0;
  800. $comment = Db::name("project_comment")->where("type",$comment_type)
  801. ->where("project_id", $id)->order('create_time', 'asc')->select();
  802. $project_log = self::project_log($id);
  803. View::assign('project_log', $project_log);
  804. $field = $this->Field->get_field_rules_new($this->uid);
  805. $field_edit = $this->Field->get_field_rules_edit_new($this->uid);
  806. if ($detail["project_end_time"]!=null){
  807. $c = $detail['project_end_time'] - time();
  808. if ($c > 0) {
  809. $advent_time = floor($c / 86400) . "天";
  810. } else {
  811. $c = -$c;
  812. $advent_time = floor($c / 86400) . "天";
  813. }
  814. }else{
  815. $advent_time = null;
  816. }
  817. if (!empty($detail)) {
  818. View::assign('advent_time', $advent_time);
  819. View::assign('comment', $comment);
  820. View::assign('project_id', $id);
  821. View::assign("audit", $audit);
  822. View::assign("review_name", $review_name);
  823. View::assign("review_person", $review_person);
  824. View::assign("person", $person);
  825. View::assign("proprietor", $proprietor);
  826. View::assign('detail', $detail);
  827. View::assign('review_unit_name', $review_unit_name);
  828. View::assign('field', $field);
  829. // dump($field_edit);
  830. View::assign('field_edit', $field_edit);
  831. View::assign('file_array', $file_array);
  832. View::assign('project_five', self::getProjectFive());
  833. return view();
  834. } else {
  835. throw new \think\exception\HttpException(404, '找不到页面');
  836. }
  837. }
  838. if (isset($param["project_start_time"])) {
  839. $param["project_start_time"] = $param["project_start_time"] ? strtotime($param["project_start_time"]) : 0;
  840. }
  841. if (isset($param["project_end_time"])) {
  842. $param["project_end_time"] = $param["project_end_time"] ? strtotime($param["project_end_time"]) : 0;
  843. }
  844. //二审
  845. if(($param["entrust_second_approver"])&&!empty($param["entrust_second_approver"])){
  846. $param["entrust_second_approver_name"] = get_admin($param["entrust_second_approver"])["nickname"];
  847. }
  848. //财评送审
  849. if(isset($detail["sent_review_head"]) && $detail.proprietor_status==0){
  850. $param["sent_review_head_name"] = get_admin($param["sent_review_head"])["nickname"];
  851. $param["sent_review_unit"]=get_admin($param["sent_review_head"])["unit_name"];
  852. $param["sent_review_unit_name"]=Db::name("department")->where("id",$param["sent_review_unit"])->value("title");
  853. $param["sent_review_phone"] = get_admin($param["sent_review_head"])["mobile"];//电话
  854. }
  855. //业主创建送审
  856. if(isset($detail["sent_review_head"])&&$detail.proprietor_status==3){
  857. $param["sent_review_head_name"] = get_admin($detail["sent_review_head"])["nickname"];
  858. $param["sent_review_unit"]=get_admin($detail["sent_review_head"])["unit_name"];
  859. $param["sent_review_unit_name"]=Db::name("department")->where("id",$detail["sent_review_unit"])->value("title");
  860. $param["sent_review_phone"] = get_admin($detail["sent_review_head"])["mobile"];//电话
  861. }
  862. $field_name = array_keys($this->field_name);
  863. $ab = $this->model->where("id", $param["id"])->field($field_name)->find()->toArray();
  864. $ab["project_start_time"] = date('Y-m-d', $ab["project_start_time"]);
  865. $ab["project_end_time"] = date('Y-m-d', $ab["project_end_time"]);
  866. $c = array_intersect_key($param, $ab);
  867. if (isset($c["project_start_time"])) {
  868. $c["project_start_time"] = date('Y-m-d', $c["project_start_time"]);
  869. }
  870. if (isset($c["project_end_time"])) {
  871. $c["project_end_time"] = date('Y-m-d', $c["project_end_time"]);
  872. }
  873. $maker_name = get_login_admin("nickname");
  874. $content = '';
  875. foreach ($c as $key => $value) {
  876. if ($c[$key] !== $ab[$key]) {
  877. $value = !empty($value) ? $value : "无";
  878. $content = $content . $this->field_name[$key] . "从" . $ab[$key] . "修改为" . $value . ",";
  879. }
  880. }
  881. $content = rtrim($content, ",");
  882. if (empty($content)) {
  883. $content = "无修改";
  884. }
  885. add_project_log('编辑', $param["id"], $content, 1);
  886. $this->model->editCostProject($param);
  887. } else {//提交前
  888. $id = isset($param['id']) ? $param['id'] : 0;
  889. $detail = $this->model->getCostProjectById($id);
  890. $review_unit_name = Db::name('department')->where(['id' => $detail["review_unit"]])->value('title');
  891. $unit_name = get_login_admin("unit_name");
  892. $person = Db::name("admin")->where([["unit_name", "=", $unit_name], ["status", "=", 1]])->field(["id", "nickname"])->select()->toArray();
  893. $review_person = Db::name("admin")->where([["unit_name", "=", $detail["review_unit"]], ["status", "=", 1]])->field(["id", "nickname"])->select();
  894. $review_name = Db::name("admin")->where("id", $detail['review_head'])->field(["id", "nickname"])->find();
  895. $audit = Db::name("project_audit")->where([["project_id", "=", $id], ["sponsor_id", "=", $this->uid]])->order('create_time', 'desc')->select();
  896. $file_array = Db::name('ProjectFile')
  897. ->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')
  898. ->alias('mf')
  899. ->join('File f', 'mf.file_id = f.id', 'LEFT')
  900. ->join('Admin a', 'mf.admin_id = a.id', 'LEFT')
  901. ->order('mf.create_time desc')
  902. ->where(array('mf.topic_id' => $id, 'mf.module' => 'project'))
  903. ->select()->toArray();
  904. $comment_type = isset($param["comment_type"])?$param['comment_type'] : 0;
  905. $comment = Db::name("project_comment")->where("type",$comment_type)
  906. ->where("project_id", $id)->order('create_time', 'asc')->select();
  907. $project_log = self::project_log($id);
  908. View::assign('project_log', $project_log);
  909. $field = $this->Field->get_field_rules_new($this->uid);
  910. $field_edit = $this->Field->get_field_rules_edit_new($this->uid);
  911. //小红点消息
  912. $red = Db::name("new_msg")->where([["uid", '=', $this->uid], ["project_id", "=", $id]])->field('detail,comment,report,user,contact')->find();
  913. if (empty($red)) {
  914. $red = ["detail" => 0, "comment" => 0, "report" => 0, "user" => 0, "contact" => 0];
  915. }
  916. // dump($red);
  917. if ($detail['project_end_time']!=null){
  918. $c = $detail['project_end_time'] - time();
  919. if ($c > 0) {
  920. $advent_time = floor($c / 86400) . "天";
  921. } else {
  922. $c = -$c;
  923. $advent_time = floor($c / 86400) . "天";
  924. }
  925. }else{
  926. $advent_time = null;
  927. }
  928. $detail["project_end_time"] !=null?$detail["project_end_time"]:null;
  929. $detail["project_start_time"] !=null?$detail["project_start_time"]:null;
  930. //送审业主
  931. $leader_id = Db::name("department")
  932. ->where([
  933. ["delete_time", "=", 0],
  934. ["pid", "=", 0],
  935. ["type", "=", 1], //1表示业主
  936. ["entrust_unit", "=", $unit_name]
  937. ])->value('leader_id');
  938. $proprietor_unit_name = Db::name("department")
  939. ->where([
  940. ["delete_time", "=", 0],
  941. ["pid", "=", 0],
  942. ["type", "=", 1], //1表示业主
  943. ["entrust_unit", "=", $unit_name]
  944. ])->column('unit_name');
  945. // dump( $proprietor_unit_name);
  946. $admin_group_id=Db::name("admin")->where("id", $leader_id)->value("admin_group_id");
  947. $where = [
  948. ['status', '>=', 0],
  949. ["admin_group_id","=", $admin_group_id],
  950. ["unit_name","in",$proprietor_unit_name]
  951. ];
  952. $proprietor =Db::name("admin")->where($where)->field(["id","nickname"])->select()->toArray();
  953. $proprietor = array_values($proprietor);
  954. View::assign("proprietor", $proprietor);
  955. //
  956. if (!empty($detail)) {
  957. View::assign('advent_time', $advent_time);
  958. View::assign('comment', $comment);
  959. View::assign('project_id', $id);
  960. View::assign('red', $red);
  961. View::assign("audit", $audit);
  962. View::assign("review_name", $review_name);
  963. View::assign("review_person", $review_person);
  964. View::assign("person", $person);
  965. View::assign('detail', $detail);
  966. View::assign('review_unit_name', $review_unit_name);
  967. View::assign('field', $field);
  968. // dump($field_edit);
  969. View::assign('field_edit', $field_edit);
  970. View::assign('file_array', $file_array);
  971. View::assign('project_five', self::getProjectFive());
  972. return view();
  973. } else {
  974. throw new \think\exception\HttpException(404, '找不到页面');
  975. }
  976. }
  977. }
  978. public function get_file(){
  979. $param = get_params();
  980. $id = isset($param['id']) ? $param['id'] : 0;
  981. $file_array = Db::name('ProjectFile')
  982. ->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')
  983. ->alias('mf')
  984. ->join('File f', 'mf.file_id = f.id', 'LEFT')
  985. ->join('Admin a', 'mf.admin_id = a.id', 'LEFT')
  986. ->order('mf.create_time desc')
  987. ->where(array('mf.topic_id' => $id, 'mf.module' => 'project'))
  988. ->paginate(9999, false, ['query' => $param]);
  989. return table_assign(0, '', $file_array);
  990. }
  991. public function project_log($project_id)
  992. {
  993. // $project_id = 24;
  994. $login_admin = get_admin(get_login_admin('id'));
  995. $where = array();
  996. if ($login_admin['user_type'] == 2) {
  997. $where = [
  998. ['project_status', '>=', 3],
  999. ['unit_name', '=', $login_admin['unit_name']],
  1000. ];
  1001. } else {
  1002. if ($login_admin['permission'] != 1) {
  1003. $where = [
  1004. ['unit_name', '=', $login_admin['unit_name']],
  1005. ];
  1006. }
  1007. }
  1008. // dump($where);
  1009. $project_log = Db::name('ProjectLog')->where($where)
  1010. ->where('project_id', $project_id)
  1011. ->order('create_time', 'desc')
  1012. ->select()->toArray();
  1013. foreach ($project_log as $key => $value) {
  1014. $project_log[$key]['create_time'] = date("Y-m-d H:i:s", $value['create_time']);
  1015. if($login_admin['user_type'] != 0){
  1016. if(str($project_log[$key]['content'], '送审单位承担审核费')){
  1017. unset($project_log[$key]);
  1018. }
  1019. if(str($project_log[$key]['content'], '施工单位负责核减超5%评审费部分')){
  1020. unset($project_log[$key]);
  1021. }
  1022. }
  1023. }
  1024. $project_log = array_values($project_log);
  1025. // dump($project_log);
  1026. // View::assign('project_log', $project_log);
  1027. // return View();
  1028. return $project_log;
  1029. }
  1030. /**
  1031. * 查看信息
  1032. */
  1033. public function read()
  1034. {
  1035. $param = get_params();
  1036. $id = isset($param['id']) ? $param['id'] : 0;
  1037. // dump($id);
  1038. $detail = $this->model->getCostProjectById($id);
  1039. $comment_type = isset($param["comment_type"])?$param['comment_type'] : 0;
  1040. $comment = Db::name("project_comment")->where("type",$comment_type)
  1041. ->where("project_id", $id)->order('create_time', 'asc')->select();
  1042. $file_array = Db::name('ProjectFile')
  1043. ->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')
  1044. ->alias('mf')
  1045. ->join('File f', 'mf.file_id = f.id', 'LEFT')
  1046. ->join('Admin a', 'mf.admin_id = a.id', 'LEFT')
  1047. ->order('mf.create_time desc')
  1048. ->where(array('mf.topic_id' => $id, 'mf.module' => 'project'))
  1049. ->select()->toArray();
  1050. $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();
  1051. $uid = Db::name("relation")->where("uuid",$id)->column("uid");
  1052. $contract = Db::name("contract")->whereIn("id",$uid)
  1053. ->where("subject_id",get_login_admin("unit_name"))->column("id,name,type,sign_time,sign_name");
  1054. //小红点消息
  1055. $red = Db::name("new_msg")->where([["uid", '=', $this->uid], ["project_id", "=", $id]])->field('detail,comment,report,user,contact')->find();
  1056. if (empty($red)) {
  1057. $red = ["detail" => 0, "comment" => 0, "report" => 0, "user" => 0, "contact" => 0];
  1058. }
  1059. //剩余时间
  1060. $c = $detail['project_end_time'] - time();
  1061. if ($c > 0) {
  1062. $advent_time = floor($c / 86400) . "天";
  1063. } else {
  1064. $c = -$c;
  1065. $advent_time = floor($c / 86400) . "天";
  1066. }
  1067. $project_log = self::project_log($id);
  1068. View::assign('project_log', $project_log);
  1069. // halt($project_log);
  1070. // 根据用户id 查询其能显示的字段
  1071. $field = $this->Field->get_field_rules_new(get_login_admin('id'));
  1072. // dump($field);
  1073. if (!empty($detail)) {
  1074. View::assign('advent_time', $advent_time);
  1075. View::assign('project_id', $id);
  1076. View::assign('comment', $comment);
  1077. View::assign('field', $field);
  1078. View::assign('detail', $detail);
  1079. View::assign('file_array', $file_array);
  1080. View::assign('report', $report);
  1081. View::assign('contract', $contract);
  1082. View::assign('red', $red);
  1083. View::assign('project_five', self::getProjectFive());
  1084. // dump(self::getProjectFive());
  1085. return view();
  1086. } else {
  1087. throw new \think\exception\HttpException(404, '找不到页面');
  1088. }
  1089. }
  1090. /**
  1091. * 删除
  1092. * type=0,逻辑删除,默认
  1093. * type=1,物理删除
  1094. */
  1095. public function del()
  1096. {
  1097. $param = get_params();
  1098. $status = Db::name("cost_project")->where("id", $param["id"])->field("project_status")->select();
  1099. if ($status[0]["project_status"] < 3) {
  1100. $id = isset($param['id']) ? $param['id'] : 0;
  1101. $type = isset($param['type']) ? $param['type'] : 0;
  1102. add_project_log("删除项目", $id, "删除项目");
  1103. $this->model->delCostProjectById($id, $type);
  1104. } else {
  1105. return to_assign(0, "已审核,无法删除");
  1106. }
  1107. }
  1108. //获取客户列表
  1109. public function get_customer()
  1110. {
  1111. $param = get_params();
  1112. $where = array();
  1113. if (!empty($param['keywords'])) {
  1114. $where[] = ['id|title', 'like', '%' . $param['keywords'] . '%'];
  1115. }
  1116. $where = [
  1117. ["delete_time", "=", 0],
  1118. ["pid", "=", 0],
  1119. ["type", "=", 2]
  1120. ];
  1121. $rows = empty($param['limit']) ? get_config('app.page_size') : $param['limit'];
  1122. $list = $this->department->field('id,title,address,leader_id')->order('id asc')->where($where)->paginate($rows, false)
  1123. ->each(function ($item) {
  1124. $item->nickname = Db::name('admin')->where(['id' => $item->leader_id])->value('nickname');
  1125. $item->mobile = Db::name('admin')->where(['id' => $item->leader_id])->value('mobile');
  1126. });
  1127. table_assign(0, '', $list);
  1128. }
  1129. //获取客户列表
  1130. public function addConstructionPeople()
  1131. {
  1132. if (request()->isAjax()) {
  1133. $param = get_params();
  1134. if ($param['type'] == '1') {
  1135. $data = $this->model->where('id', $param['data']['id'])->find();
  1136. if ($data["construction_unit"] !== null ||
  1137. $data["construction_head"] !== null ||
  1138. $data["construction_email"] !== null ||
  1139. $data["construction_phone"] !== null
  1140. ) {
  1141. return to_assign(0, "已存在!!");
  1142. } else {
  1143. return to_assign(200, "请上传!!");
  1144. }
  1145. } else {
  1146. $this->model->addConstructionPeople($param['data']);
  1147. }
  1148. add_project_log('添加施工单位人员', $param['data']['id'], '添加施工单位人员');
  1149. } else {
  1150. $param = get_params();
  1151. $project_id = isset($param['project_id']) ? $param['project_id'] : 0;
  1152. //关联项目id
  1153. View::assign('project_id', $project_id);
  1154. return view();
  1155. }
  1156. }
  1157. //获取业主列表
  1158. public function get_proprietor_list()
  1159. {
  1160. $param = get_params();
  1161. $where = array();
  1162. if (!empty($param['keywords'])) {
  1163. $where[] = ['id|title', 'like', '%' . $param['keywords'] . '%'];
  1164. }
  1165. $where = [
  1166. ["delete_time", "=", 0],
  1167. ["pid", "=", 0],
  1168. ["type", "=", 1],
  1169. ["entrust_unit", "=", get_admin($this->uid)['unit_name']]
  1170. ];
  1171. $rows = empty($param['limit']) ? get_config('app.page_size') : $param['limit'];
  1172. $list = $this->department->field('id,title,address,leader_id')->order('id asc')->where($where)->paginate($rows, false)
  1173. ->each(function ($item) {
  1174. $item->nickname = Db::name('admin')->where(['id' => $item->leader_id])->value('nickname');
  1175. $item->mobile = Db::name('admin')->where(['id' => $item->leader_id])->value('mobile');
  1176. });
  1177. // halt($list);
  1178. table_assign(0, '', $list);
  1179. }
  1180. public function add_sent_review_unit()
  1181. {
  1182. if (request()->isAjax()) {
  1183. $param = get_params();
  1184. if ($param['type'] == '1') {
  1185. $data = $this->model->where('id', $param['data']['id'])->find();
  1186. if ($data["sent_review_unit_name"] !== null ||
  1187. $data["sent_review_head_name"] !== null ||
  1188. $data["sent_review_head_email"] !== null ||
  1189. $data["sent_review_phone"] !== null
  1190. ) {
  1191. return to_assign(0, "已存在,请移除后再添加");
  1192. } else {
  1193. return to_assign(200, "请上传!!");
  1194. }
  1195. } else {
  1196. add_project_log('移除送审单位成员', $param['data']['id'], $param['data']["sent_review_head_name"], 5);
  1197. $this->model->addConstructionPeople($param['data']);
  1198. }
  1199. add_project_log('新增送审单位成员', $param['data']['id'], '新增送审单位成员');
  1200. } else {
  1201. $param = get_params();
  1202. $project_id = isset($param['project_id']) ? $param['project_id'] : 0;
  1203. //关联项目id
  1204. View::assign('project_id', $project_id);
  1205. return view();
  1206. }
  1207. }
  1208. //添加送审单位
  1209. // public function add_sent_review_unit()
  1210. // {
  1211. // if (request()->isAjax()) {
  1212. // $param = get_params();
  1213. // $id = isset($param["id"]) ? $param["id"] : 0;
  1214. // $project_id = isset($param["project_id"]) ? $param["project_id"] : 0;
  1215. // $a = $this->model->where("id", $project_id)->value("sent_review_head");
  1216. // if ($a) {
  1217. // return to_assign(1, '已有负责人,请移除后再添加');
  1218. // }
  1219. // $selfData = get_admin($id);
  1220. // $data = [
  1221. // "id" => $project_id,
  1222. // "sent_review_head" => $id,
  1223. // "sent_review_head_name" => $selfData["nickname"],
  1224. // "sent_review_unit" => $selfData["unit_name"],
  1225. // "sent_review_unit_name" => Db::name("department")->where("id", $selfData["unit_name"])->value("title"),
  1226. // "sent_review_phone" => $selfData["mobile"]
  1227. // ];
  1228. // try {
  1229. // $this->model->update($data);
  1230. // } catch (\Exception $e) {
  1231. // return to_assign(1, '操作失败,原因:' . $e->getMessage());
  1232. // }
  1233. // add_project_log('添加送审单位成员', $project_id, $selfData["nickname"], 5);
  1234. // return to_assign(0, "操作成功");
  1235. // }
  1236. // }
  1237. //移除送审单位成员
  1238. public function remove_sent_review()
  1239. {
  1240. $p = get_params();
  1241. $project_id = isset($p["project_id"]) ? $p["project_id"] : 0;
  1242. $data = [
  1243. "sent_review_unit" => null,
  1244. "sent_review_unit_name" => null,
  1245. "sent_review_head_name" => null,
  1246. "sent_review_head" => null,
  1247. "sent_review_phone" => null,
  1248. "sent_review_head_email" => null,
  1249. ];
  1250. $this->model->where("id", $project_id)->update($data);
  1251. remove_user($p["id"]);
  1252. add_project_log('移除送审单位成员', $project_id, $p["nickname"], 5);
  1253. return to_assign(0, "操作成功");
  1254. }
  1255. public function project_user()
  1256. {
  1257. $param = get_params();//9.13加了一个送审人的 //委托创建人,评审负责人/操作team/
  1258. $ids = $this->model->where("id", $param["project_id"])->field("entrust_maker,review_head,operate_head,operate_team")->find()->toArray();
  1259. $idarr = $ids["operate_team"] . ',' . $ids["operate_head"] . ',' . $ids["review_head"] . ',' . $ids["entrust_maker"];
  1260. $idarr = explode(",", $idarr);
  1261. $rows = empty($param['limit']) ? get_config('app.page_size') : $param['limit'];
  1262. $list = $this->Adminmodel->whereIn("id", $idarr)->field("id,nickname,unit_name,mobile,email")->paginate($rows, false, ['query' => $param])
  1263. // 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')
  1264. ->each(function ($item) {
  1265. //获取单位的邮箱,单位信息页没做
  1266. $item->email = Db::name('department')->where(['id' => $item->unit_name])->value('email');
  1267. $type = Db::name('department')->where(['id' => $item->unit_name])->value('type');
  1268. $item->unit_name = Db::name('department')->where(['id' => $item->unit_name])->value('title');
  1269. // dump($type);
  1270. if ($type == 0) {
  1271. $item->unit_type = "委托单位";
  1272. } elseif ($type == 1) {
  1273. $item->unit_type = "送审单位";
  1274. } elseif ($type == 2) {
  1275. $item->unit_type = "评审机构";
  1276. } else {
  1277. $item->unit_type = "施工单位";
  1278. }
  1279. })->toArray();
  1280. $list = $list["data"];
  1281. $time_id = time();
  1282. $shigong = $this->model->where('id', $param["project_id"])->find();
  1283. if ($shigong["construction_unit"] !== null ||
  1284. $shigong["construction_head"] !== null ||
  1285. $shigong["construction_email"] !== null ||
  1286. $shigong["construction_phone"] !== null
  1287. ) {
  1288. $shigongdata["id"] = $time_id;
  1289. $shigongdata["nickname"] = $shigong["construction_unit"];
  1290. $shigongdata["unit_name"] = $shigong["construction_head"];
  1291. $shigongdata["email"] = $shigong["construction_email"];
  1292. $shigongdata["mobile"] = $shigong["construction_phone"];
  1293. $shigongdata["unit_type"] = "施工单位";
  1294. array_push($list, $shigongdata);
  1295. }
  1296. $time_id_sent = time()-200;
  1297. if ($shigong["sent_review_unit"] !== null ||
  1298. $shigong["sent_review_head"] !== null ||
  1299. $shigong["sent_review_phone"] !== null ||
  1300. $shigong["sent_review_head_email"] !== null
  1301. ) {
  1302. $sent_review_data["id"] = $time_id_sent;
  1303. $sent_review_data["nickname"] = $shigong["sent_review_head_name"];
  1304. $sent_review_data["unit_name"] = $shigong["sent_review_unit_name"];
  1305. $sent_review_data["email"] = $shigong["sent_review_head_email"];
  1306. $sent_review_data["mobile"] = $shigong["sent_review_phone"];
  1307. $sent_review_data["unit_type"] = "送审单位";
  1308. array_push($list, $sent_review_data);
  1309. }
  1310. if (empty($ids['operate_team'])) {
  1311. $operate_team[] = '0';
  1312. } else {
  1313. $operate_team = explode(',', $ids['operate_team']);
  1314. }
  1315. for ($i = 0; $i < count($list); $i++) {
  1316. if ($list[$i]['id'] == $ids['entrust_maker']) {
  1317. // dump($list[$i]['id'],$ids['entrust_maker']);
  1318. $list[$i]["type"] = 1;
  1319. } elseif ($list[$i]['id'] == $ids['review_head']) {
  1320. $list[$i]["type"] = 2;
  1321. } elseif ($list[$i]['id'] == $ids['operate_head']) {
  1322. $list[$i]["type"] = 3;
  1323. } elseif (in_array($list[$i]['id'], $operate_team)) {
  1324. $list[$i]["type"] = 4;
  1325. } elseif ($list[$i]['id'] == $time_id) {
  1326. $list[$i]["type"] = 5;
  1327. } elseif ($list[$i]['id'] !== time() - 1000) {
  1328. $list[$i]["type"] = 6;
  1329. }
  1330. }
  1331. $type = array_column($list, 'type');
  1332. array_multisort($type, SORT_ASC, $list);
  1333. $lists["total"] = count($list);
  1334. $lists["data"] = $list;
  1335. return table_assign(0, '', $lists);
  1336. }
  1337. public function remove_construction_user()
  1338. {
  1339. $p = get_params();
  1340. $data = [
  1341. "construction_unit" => null,
  1342. "construction_head" => null,
  1343. "construction_email" => null,
  1344. "construction_phone" => null
  1345. ];
  1346. $this->model->where("id", $p["project_id"])->update($data);
  1347. add_project_log('删除施工方人员', $p["project_id"], '删除施工方人员');
  1348. return to_assign(0, "操作成功");
  1349. }
  1350. public function getProjectFive()
  1351. {
  1352. $where = [
  1353. ['name', '=', '作业日志-财政局'],
  1354. ['name', '=', '工作记录-财政局'],
  1355. ['name', '=', '项目报告-财政局'],
  1356. ['name', '=', '项目人员-财政局'],
  1357. ['name', '=', '项目动态-财政局'],
  1358. ['name', '=', '项目附件-财政局'],
  1359. ['name', '=', '联系函-财政局'],
  1360. ];
  1361. //where0r满足任意一个name值都可以
  1362. $list = Db::name('AdminRule')->whereOr($where)->field('id,name')->select()->toArray();
  1363. $group_id = Db::name('AdminGroupAccess')->where('uid', get_login_admin('id'))->value('group_id');
  1364. $login_rules = Db::name('AdminGroup')->where('id', $group_id)->value('rules');
  1365. $login_rules = explode(',', $login_rules);
  1366. $rules_id = array();
  1367. //in_array()用于在数组中搜索指定的值,指定值/搜索数组
  1368. foreach ($list as $key => $value) {
  1369. if ($value['name'] == "作业日志-财政局") {
  1370. if (in_array($value['id'], $login_rules)) {
  1371. $rules_id['project_comments'] = 1;
  1372. } else {
  1373. $rules_id['project_comments'] = 0;
  1374. }
  1375. } else if ($value['name'] == "工作记录-财政局") {
  1376. if (in_array($value['id'], $login_rules)) {
  1377. $rules_id['project_record'] = 1;
  1378. } else {
  1379. $rules_id['project_record'] = 0;
  1380. }
  1381. } else if ($value['name'] == "项目报告-财政局") {
  1382. if (in_array($value['id'], $login_rules)) {
  1383. $rules_id['project_report'] = 1;
  1384. } else {
  1385. $rules_id['project_report'] = 0;
  1386. }
  1387. } else if ($value['name'] == "项目人员-财政局") {
  1388. if (in_array($value['id'], $login_rules)) {
  1389. $rules_id['project_user'] = 1;
  1390. } else {
  1391. $rules_id['project_user'] = 0;
  1392. }
  1393. } else if ($value['name'] == "项目动态-财政局") {
  1394. if (in_array($value['id'], $login_rules)) {
  1395. $rules_id['project_log'] = 1;
  1396. } else {
  1397. $rules_id['project_log'] = 0;
  1398. }
  1399. } else if ($value['name'] == "项目附件-财政局") {
  1400. if (in_array($value['id'], $login_rules)) {
  1401. $rules_id['project_file'] = 1;
  1402. } else {
  1403. $rules_id['project_file'] = 0;
  1404. }
  1405. } else if ($value['name'] == "联系函-财政局") {
  1406. if (in_array($value['id'], $login_rules)) {
  1407. $rules_id['project_contact'] = 1;
  1408. } else {
  1409. $rules_id['project_contact'] = 0;
  1410. }
  1411. }
  1412. }
  1413. return $rules_id;
  1414. }
  1415. public function ceshi($id)
  1416. {
  1417. View::assign('detailId', $id);
  1418. return view();
  1419. }
  1420. }