Cost.php 65 KB

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