Cost.php 67 KB

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