Cost.php 59 KB

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