Cost.php 62 KB

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