Cost.php 71 KB

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