Cost.php 66 KB

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