Cost.php 60 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429
  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. if ($detail["project_end_time"]!=null){
  646. $c = $detail['project_end_time'] - time();
  647. if ($c > 0) {
  648. $advent_time = floor($c / 86400) . "天";
  649. } else {
  650. $c = -$c;
  651. $advent_time = floor($c / 86400) . "天";
  652. }
  653. }else{
  654. $advent_time = null;
  655. }
  656. if (!empty($detail)) {
  657. View::assign('advent_time', $advent_time);
  658. View::assign('comment', $comment);
  659. View::assign('project_id', $id);
  660. View::assign("audit", $audit);
  661. View::assign("review_name", $review_name);
  662. View::assign("review_person", $review_person);
  663. View::assign("person", $person);
  664. View::assign('detail', $detail);
  665. View::assign('review_unit_name', $review_unit_name);
  666. View::assign('field', $field);
  667. // dump($field_edit);
  668. View::assign('field_edit', $field_edit);
  669. View::assign('file_array', $file_array);
  670. View::assign('project_five', self::getProjectFive());
  671. return view();
  672. } else {
  673. throw new \think\exception\HttpException(404, '找不到页面');
  674. }
  675. }
  676. if (isset($param["project_start_time"])) {
  677. $param["project_start_time"] = $param["project_start_time"] ? strtotime($param["project_start_time"]) : 0;
  678. }
  679. if (isset($param["project_end_time"])) {
  680. $param["project_end_time"] = $param["project_end_time"] ? strtotime($param["project_end_time"]) : 0;
  681. }
  682. $field_name = array_keys($this->field_name);
  683. $ab = $this->model->where("id", $param["id"])->field($field_name)->find()->toArray();
  684. $ab["project_start_time"] = date('Y-m-d', $ab["project_start_time"]);
  685. $ab["project_end_time"] = date('Y-m-d', $ab["project_end_time"]);
  686. $c = array_intersect_key($param, $ab);
  687. if (isset($c["project_start_time"])) {
  688. $c["project_start_time"] = date('Y-m-d', $c["project_start_time"]);
  689. }
  690. if (isset($c["project_end_time"])) {
  691. $c["project_end_time"] = date('Y-m-d', $c["project_end_time"]);
  692. }
  693. $maker_name = get_login_admin("nickname");
  694. $content = '';
  695. foreach ($c as $key => $value) {
  696. if ($c[$key] !== $ab[$key]) {
  697. $value = !empty($value) ? $value : "无";
  698. $content = $content . $this->field_name[$key] . "从" . $ab[$key] . "修改为" . $value . ",";
  699. }
  700. }
  701. $content = rtrim($content, ",");
  702. if (empty($content)) {
  703. $content = "无修改";
  704. }
  705. add_project_log('编辑', $param["id"], $content, 1);
  706. $this->model->editCostProject($param);
  707. } else {//提交前
  708. $id = isset($param['id']) ? $param['id'] : 0;
  709. $detail = $this->model->getCostProjectById($id);
  710. $review_unit_name = Db::name('department')->where(['id' => $detail["review_unit"]])->value('title');
  711. $unit_name = get_login_admin("unit_name");
  712. $person = Db::name("admin")->where([["unit_name", "=", $unit_name], ["status", "=", 1]])->field(["id", "nickname"])->select()->toArray();
  713. $review_person = Db::name("admin")->where([["unit_name", "=", $detail["review_unit"]], ["status", "=", 1]])->field(["id", "nickname"])->select();
  714. $review_name = Db::name("admin")->where("id", $detail['review_head'])->field(["id", "nickname"])->find();
  715. $audit = Db::name("project_audit")->where([["project_id", "=", $id], ["sponsor_id", "=", $this->uid]])->order('create_time', 'desc')->select();
  716. $file_array = Db::name('ProjectFile')
  717. ->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')
  718. ->alias('mf')
  719. ->join('File f', 'mf.file_id = f.id', 'LEFT')
  720. ->join('Admin a', 'mf.admin_id = a.id', 'LEFT')
  721. ->order('mf.create_time desc')
  722. ->where(array('mf.topic_id' => $id, 'mf.module' => 'project'))
  723. ->select()->toArray();
  724. $comment_type = isset($param["comment_type"])?$param['comment_type'] : 0;
  725. $comment = Db::name("project_comment")->where("type",$comment_type)
  726. ->where("project_id", $id)->order('create_time', 'asc')->select();
  727. $project_log = self::project_log($id);
  728. View::assign('project_log', $project_log);
  729. $field = $this->Field->get_field_rules_new($this->uid);
  730. $field_edit = $this->Field->get_field_rules_edit_new($this->uid);
  731. //小红点消息
  732. $red = Db::name("new_msg")->where([["uid", '=', $this->uid], ["project_id", "=", $id]])->field('detail,comment,report,user,contact')->find();
  733. if (empty($red)) {
  734. $red = ["detail" => 0, "comment" => 0, "report" => 0, "user" => 0, "contact" => 0];
  735. }
  736. // dump($red);
  737. if ($detail['project_end_time']!=null){
  738. $c = $detail['project_end_time'] - time();
  739. if ($c > 0) {
  740. $advent_time = floor($c / 86400) . "天";
  741. } else {
  742. $c = -$c;
  743. $advent_time = floor($c / 86400) . "天";
  744. }
  745. }else{
  746. $advent_time = null;
  747. }
  748. if (!empty($detail)) {
  749. View::assign('advent_time', $advent_time);
  750. View::assign('comment', $comment);
  751. View::assign('project_id', $id);
  752. View::assign('red', $red);
  753. View::assign("audit", $audit);
  754. View::assign("review_name", $review_name);
  755. View::assign("review_person", $review_person);
  756. View::assign("person", $person);
  757. View::assign('detail', $detail);
  758. View::assign('review_unit_name', $review_unit_name);
  759. View::assign('field', $field);
  760. // dump($field_edit);
  761. View::assign('field_edit', $field_edit);
  762. View::assign('file_array', $file_array);
  763. View::assign('project_five', self::getProjectFive());
  764. return view();
  765. } else {
  766. throw new \think\exception\HttpException(404, '找不到页面');
  767. }
  768. }
  769. }
  770. public function get_file(){
  771. $param = get_params();
  772. $id = isset($param['id']) ? $param['id'] : 0;
  773. $file_array = Db::name('ProjectFile')
  774. ->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')
  775. ->alias('mf')
  776. ->join('File f', 'mf.file_id = f.id', 'LEFT')
  777. ->join('Admin a', 'mf.admin_id = a.id', 'LEFT')
  778. ->order('mf.create_time desc')
  779. ->where(array('mf.topic_id' => $id, 'mf.module' => 'project'))
  780. ->paginate(9999, false, ['query' => $param]);
  781. return table_assign(0, '', $file_array);
  782. }
  783. public function project_log($project_id)
  784. {
  785. // $project_id = 24;
  786. $login_admin = get_admin(get_login_admin('id'));
  787. $where = array();
  788. if ($login_admin['user_type'] == 2) {
  789. $where = [
  790. ['project_status', '>=', 3],
  791. ['unit_name', '=', $login_admin['unit_name']],
  792. ];
  793. } else {
  794. if ($login_admin['permission'] != 1) {
  795. $where = [
  796. ['unit_name', '=', $login_admin['unit_name']],
  797. ];
  798. }
  799. }
  800. // dump($where);
  801. $project_log = Db::name('ProjectLog')->where($where)
  802. ->where('project_id', $project_id)
  803. ->order('create_time', 'desc')
  804. ->select()->toArray();
  805. foreach ($project_log as $key => $value) {
  806. $project_log[$key]['create_time'] = date("Y-m-d H:i:s", $value['create_time']);
  807. if($login_admin['user_type'] != 0){
  808. if(str($project_log[$key]['content'], '送审单位承担审核费')){
  809. unset($project_log[$key]);
  810. }
  811. if(str($project_log[$key]['content'], '施工单位负责核减超5%评审费部分')){
  812. unset($project_log[$key]);
  813. }
  814. }
  815. }
  816. $project_log = array_values($project_log);
  817. // dump($project_log);
  818. // View::assign('project_log', $project_log);
  819. // return View();
  820. return $project_log;
  821. }
  822. /**
  823. * 查看信息
  824. */
  825. public function read()
  826. {
  827. $param = get_params();
  828. $id = isset($param['id']) ? $param['id'] : 0;
  829. // dump($id);
  830. $detail = $this->model->getCostProjectById($id);
  831. $comment_type = isset($param["comment_type"])?$param['comment_type'] : 0;
  832. $comment = Db::name("project_comment")->where("type",$comment_type)
  833. ->where("project_id", $id)->order('create_time', 'asc')->select();
  834. $file_array = Db::name('ProjectFile')
  835. ->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')
  836. ->alias('mf')
  837. ->join('File f', 'mf.file_id = f.id', 'LEFT')
  838. ->join('Admin a', 'mf.admin_id = a.id', 'LEFT')
  839. ->order('mf.create_time desc')
  840. ->where(array('mf.topic_id' => $id, 'mf.module' => 'project'))
  841. ->select()->toArray();
  842. $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();
  843. $uid = Db::name("relation")->where("uuid",$id)->column("uid");
  844. $contract = Db::name("contract")->whereIn("id",$uid)
  845. ->where("subject_id",get_login_admin("unit_name"))->column("id,name,type,sign_time,sign_name");
  846. //小红点消息
  847. $red = Db::name("new_msg")->where([["uid", '=', $this->uid], ["project_id", "=", $id]])->field('detail,comment,report,user,contact')->find();
  848. if (empty($red)) {
  849. $red = ["detail" => 0, "comment" => 0, "report" => 0, "user" => 0, "contact" => 0];
  850. }
  851. //剩余时间
  852. $c = $detail['project_end_time'] - time();
  853. if ($c > 0) {
  854. $advent_time = floor($c / 86400) . "天";
  855. } else {
  856. $c = -$c;
  857. $advent_time = floor($c / 86400) . "天";
  858. }
  859. $project_log = self::project_log($id);
  860. View::assign('project_log', $project_log);
  861. // halt($project_log);
  862. // 根据用户id 查询其能显示的字段
  863. $field = $this->Field->get_field_rules_new(get_login_admin('id'));
  864. // dump($field);
  865. if (!empty($detail)) {
  866. View::assign('advent_time', $advent_time);
  867. View::assign('project_id', $id);
  868. View::assign('comment', $comment);
  869. View::assign('field', $field);
  870. View::assign('detail', $detail);
  871. View::assign('file_array', $file_array);
  872. View::assign('report', $report);
  873. View::assign('contract', $contract);
  874. View::assign('red', $red);
  875. View::assign('project_five', self::getProjectFive());
  876. // dump(self::getProjectFive());
  877. return view();
  878. } else {
  879. throw new \think\exception\HttpException(404, '找不到页面');
  880. }
  881. }
  882. /**
  883. * 删除
  884. * type=0,逻辑删除,默认
  885. * type=1,物理删除
  886. */
  887. public function del()
  888. {
  889. $param = get_params();
  890. $status = Db::name("cost_project")->where("id", $param["id"])->field("project_status")->select();
  891. if ($status[0]["project_status"] < 3) {
  892. $id = isset($param['id']) ? $param['id'] : 0;
  893. $type = isset($param['type']) ? $param['type'] : 0;
  894. add_project_log("删除项目", $id, "删除项目");
  895. $this->model->delCostProjectById($id, $type);
  896. } else {
  897. return to_assign(0, "已审核,无法删除");
  898. }
  899. }
  900. //获取客户列表
  901. public function get_customer()
  902. {
  903. $param = get_params();
  904. $where = array();
  905. if (!empty($param['keywords'])) {
  906. $where[] = ['id|title', 'like', '%' . $param['keywords'] . '%'];
  907. }
  908. $where = [
  909. ["delete_time", "=", 0],
  910. ["pid", "=", 0],
  911. ["type", "=", 2]
  912. ];
  913. $rows = empty($param['limit']) ? get_config('app.page_size') : $param['limit'];
  914. $list = $this->department->field('id,title,address,leader_id')->order('id asc')->where($where)->paginate($rows, false)
  915. ->each(function ($item) {
  916. $item->nickname = Db::name('admin')->where(['id' => $item->leader_id])->value('nickname');
  917. $item->mobile = Db::name('admin')->where(['id' => $item->leader_id])->value('mobile');
  918. });
  919. // halt($list);
  920. table_assign(0, '', $list);
  921. }
  922. //获取客户列表
  923. public function addConstructionPeople()
  924. {
  925. if (request()->isAjax()) {
  926. $param = get_params();
  927. if ($param['type'] == '1') {
  928. $data = $this->model->where('id', $param['data']['id'])->find();
  929. if ($data["construction_unit"] !== null ||
  930. $data["construction_head"] !== null ||
  931. $data["construction_email"] !== null ||
  932. $data["construction_phone"] !== null
  933. ) {
  934. return to_assign(0, "已存在!!");
  935. } else {
  936. return to_assign(200, "请上传!!");
  937. }
  938. } else {
  939. $this->model->addConstructionPeople($param['data']);
  940. }
  941. add_project_log('添加施工单位人员', $param['data']['id'], '添加施工单位人员');
  942. } else {
  943. $param = get_params();
  944. $project_id = isset($param['project_id']) ? $param['project_id'] : 0;
  945. //关联项目id
  946. View::assign('project_id', $project_id);
  947. return view();
  948. }
  949. }
  950. public function add_sent_review_unit()
  951. {
  952. if (request()->isAjax()) {
  953. $param = get_params();
  954. if ($param['type'] == '1') {
  955. $data = $this->model->where('id', $param['data']['id'])->find();
  956. if ($data["sent_review_unit_name"] !== null ||
  957. $data["sent_review_head_name"] !== null ||
  958. $data["sent_review_head_email"] !== null ||
  959. $data["sent_review_phone"] !== null
  960. ) {
  961. return to_assign(0, "已存在,请移除后再添加");
  962. } else {
  963. return to_assign(200, "请上传!!");
  964. }
  965. } else {
  966. add_project_log('移除送审单位成员', $param['data']['id'], $param['data']["sent_review_head_name"], 5);
  967. $this->model->addConstructionPeople($param['data']);
  968. }
  969. add_project_log('新增送审单位成员', $param['data']['id'], '新增送审单位成员');
  970. } else {
  971. $param = get_params();
  972. $project_id = isset($param['project_id']) ? $param['project_id'] : 0;
  973. //关联项目id
  974. View::assign('project_id', $project_id);
  975. return view();
  976. }
  977. }
  978. //添加送审单位
  979. // public function add_sent_review_unit()
  980. // {
  981. // if (request()->isAjax()) {
  982. // $param = get_params();
  983. // $id = isset($param["id"]) ? $param["id"] : 0;
  984. // $project_id = isset($param["project_id"]) ? $param["project_id"] : 0;
  985. // $a = $this->model->where("id", $project_id)->value("sent_review_head");
  986. // if ($a) {
  987. // return to_assign(1, '已有负责人,请移除后再添加');
  988. // }
  989. // $selfData = get_admin($id);
  990. // $data = [
  991. // "id" => $project_id,
  992. // "sent_review_head" => $id,
  993. // "sent_review_head_name" => $selfData["nickname"],
  994. // "sent_review_unit" => $selfData["unit_name"],
  995. // "sent_review_unit_name" => Db::name("department")->where("id", $selfData["unit_name"])->value("title"),
  996. // "sent_review_phone" => $selfData["mobile"]
  997. // ];
  998. // try {
  999. // $this->model->update($data);
  1000. // } catch (\Exception $e) {
  1001. // return to_assign(1, '操作失败,原因:' . $e->getMessage());
  1002. // }
  1003. // add_project_log('添加送审单位成员', $project_id, $selfData["nickname"], 5);
  1004. // return to_assign(0, "操作成功");
  1005. // }
  1006. // }
  1007. //移除送审单位成员
  1008. public function remove_sent_review()
  1009. {
  1010. $p = get_params();
  1011. $project_id = isset($p["project_id"]) ? $p["project_id"] : 0;
  1012. $data = [
  1013. "sent_review_unit" => null,
  1014. "sent_review_unit_name" => null,
  1015. "sent_review_head_name" => null,
  1016. "sent_review_head" => null,
  1017. "sent_review_phone" => null,
  1018. "sent_review_head_email" => null,
  1019. ];
  1020. $this->model->where("id", $project_id)->update($data);
  1021. remove_user($p["id"]);
  1022. add_project_log('移除送审单位成员', $project_id, $p["nickname"], 5);
  1023. return to_assign(0, "操作成功");
  1024. }
  1025. public function project_user()
  1026. {
  1027. $param = get_params();
  1028. $ids = $this->model->where("id", $param["project_id"])->field("entrust_maker,review_head,operate_head,operate_team")->find()->toArray();
  1029. $idarr = $ids["operate_team"] . ',' . $ids["operate_head"] . ',' . $ids["review_head"] . ',' . $ids["entrust_maker"];
  1030. $idarr = explode(",", $idarr);
  1031. $rows = empty($param['limit']) ? get_config('app.page_size') : $param['limit'];
  1032. $list = $this->Adminmodel->whereIn("id", $idarr)->field("id,nickname,unit_name,mobile,email")->paginate($rows, false, ['query' => $param])
  1033. // 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')
  1034. ->each(function ($item) {
  1035. //获取单位的邮箱,单位信息页没做
  1036. $item->email = Db::name('department')->where(['id' => $item->unit_name])->value('email');
  1037. $type = Db::name('department')->where(['id' => $item->unit_name])->value('type');
  1038. $item->unit_name = Db::name('department')->where(['id' => $item->unit_name])->value('title');
  1039. // dump($type);
  1040. if ($type == 0) {
  1041. $item->unit_type = "委托单位";
  1042. } elseif ($type == 1) {
  1043. $item->unit_type = "送审单位";
  1044. } elseif ($type == 2) {
  1045. $item->unit_type = "评审机构";
  1046. } else {
  1047. $item->unit_type = "施工单位";
  1048. }
  1049. })->toArray();
  1050. $list = $list["data"];
  1051. $time_id = time();
  1052. $shigong = $this->model->where('id', $param["project_id"])->find();
  1053. if ($shigong["construction_unit"] !== null ||
  1054. $shigong["construction_head"] !== null ||
  1055. $shigong["construction_email"] !== null ||
  1056. $shigong["construction_phone"] !== null
  1057. ) {
  1058. $shigongdata["id"] = $time_id;
  1059. $shigongdata["nickname"] = $shigong["construction_unit"];
  1060. $shigongdata["unit_name"] = $shigong["construction_head"];
  1061. $shigongdata["email"] = $shigong["construction_email"];
  1062. $shigongdata["mobile"] = $shigong["construction_phone"];
  1063. $shigongdata["unit_type"] = "施工单位";
  1064. array_push($list, $shigongdata);
  1065. }
  1066. $time_id_sent = time()-200;
  1067. if ($shigong["sent_review_unit"] !== null ||
  1068. $shigong["sent_review_head"] !== null ||
  1069. $shigong["sent_review_phone"] !== null ||
  1070. $shigong["sent_review_head_email"] !== null
  1071. ) {
  1072. $sent_review_data["id"] = $time_id_sent;
  1073. $sent_review_data["nickname"] = $shigong["sent_review_head_name"];
  1074. $sent_review_data["unit_name"] = $shigong["sent_review_unit_name"];
  1075. $sent_review_data["email"] = $shigong["sent_review_head_email"];
  1076. $sent_review_data["mobile"] = $shigong["sent_review_phone"];
  1077. $sent_review_data["unit_type"] = "送审单位";
  1078. array_push($list, $sent_review_data);
  1079. }
  1080. if (empty($ids['operate_team'])) {
  1081. $operate_team[] = '0';
  1082. } else {
  1083. $operate_team = explode(',', $ids['operate_team']);
  1084. }
  1085. for ($i = 0; $i < count($list); $i++) {
  1086. if ($list[$i]['id'] == $ids['entrust_maker']) {
  1087. // dump($list[$i]['id'],$ids['entrust_maker']);
  1088. $list[$i]["type"] = 1;
  1089. } elseif ($list[$i]['id'] == $ids['review_head']) {
  1090. $list[$i]["type"] = 2;
  1091. } elseif ($list[$i]['id'] == $ids['operate_head']) {
  1092. $list[$i]["type"] = 3;
  1093. } elseif (in_array($list[$i]['id'], $operate_team)) {
  1094. $list[$i]["type"] = 4;
  1095. } elseif ($list[$i]['id'] == $time_id) {
  1096. $list[$i]["type"] = 5;
  1097. } elseif ($list[$i]['id'] !== time() - 1000) {
  1098. $list[$i]["type"] = 6;
  1099. }
  1100. }
  1101. $type = array_column($list, 'type');
  1102. array_multisort($type, SORT_ASC, $list);
  1103. $lists["total"] = count($list);
  1104. $lists["data"] = $list;
  1105. return table_assign(0, '', $lists);
  1106. }
  1107. public function remove_construction_user()
  1108. {
  1109. $p = get_params();
  1110. $data = [
  1111. "construction_unit" => null,
  1112. "construction_head" => null,
  1113. "construction_email" => null,
  1114. "construction_phone" => null
  1115. ];
  1116. $this->model->where("id", $p["project_id"])->update($data);
  1117. add_project_log('删除施工方人员', $p["project_id"], '删除施工方人员');
  1118. return to_assign(0, "操作成功");
  1119. }
  1120. public function getProjectFive()
  1121. {
  1122. $where = [
  1123. ['name', '=', '作业日志-财政局'],
  1124. ['name', '=', '工作记录-财政局'],
  1125. ['name', '=', '项目报告-财政局'],
  1126. ['name', '=', '项目人员-财政局'],
  1127. ['name', '=', '项目动态-财政局'],
  1128. ['name', '=', '项目附件-财政局'],
  1129. ['name', '=', '联系函-财政局'],
  1130. ];
  1131. //where0r满足任意一个name值都可以
  1132. $list = Db::name('AdminRule')->whereOr($where)->field('id,name')->select()->toArray();
  1133. $group_id = Db::name('AdminGroupAccess')->where('uid', get_login_admin('id'))->value('group_id');
  1134. $login_rules = Db::name('AdminGroup')->where('id', $group_id)->value('rules');
  1135. $login_rules = explode(',', $login_rules);
  1136. $rules_id = array();
  1137. //in_array()用于在数组中搜索指定的值,指定值/搜索数组
  1138. foreach ($list as $key => $value) {
  1139. if ($value['name'] == "作业日志-财政局") {
  1140. if (in_array($value['id'], $login_rules)) {
  1141. $rules_id['project_comments'] = 1;
  1142. } else {
  1143. $rules_id['project_comments'] = 0;
  1144. }
  1145. } else if ($value['name'] == "工作记录-财政局") {
  1146. if (in_array($value['id'], $login_rules)) {
  1147. $rules_id['project_record'] = 1;
  1148. } else {
  1149. $rules_id['project_record'] = 0;
  1150. }
  1151. } else if ($value['name'] == "项目报告-财政局") {
  1152. if (in_array($value['id'], $login_rules)) {
  1153. $rules_id['project_report'] = 1;
  1154. } else {
  1155. $rules_id['project_report'] = 0;
  1156. }
  1157. } else if ($value['name'] == "项目人员-财政局") {
  1158. if (in_array($value['id'], $login_rules)) {
  1159. $rules_id['project_user'] = 1;
  1160. } else {
  1161. $rules_id['project_user'] = 0;
  1162. }
  1163. } else if ($value['name'] == "项目动态-财政局") {
  1164. if (in_array($value['id'], $login_rules)) {
  1165. $rules_id['project_log'] = 1;
  1166. } else {
  1167. $rules_id['project_log'] = 0;
  1168. }
  1169. } else if ($value['name'] == "项目附件-财政局") {
  1170. if (in_array($value['id'], $login_rules)) {
  1171. $rules_id['project_file'] = 1;
  1172. } else {
  1173. $rules_id['project_file'] = 0;
  1174. }
  1175. } else if ($value['name'] == "联系函-财政局") {
  1176. if (in_array($value['id'], $login_rules)) {
  1177. $rules_id['project_contact'] = 1;
  1178. } else {
  1179. $rules_id['project_contact'] = 0;
  1180. }
  1181. }
  1182. }
  1183. return $rules_id;
  1184. }
  1185. // public function getIntitutions()//获取当前财评关联的业主列表
  1186. // {
  1187. // // 获取当前登录用户所属单位名称
  1188. // $unit_Name = get_login_admin('unit_name');
  1189. //
  1190. // // 查询满足条件的业主列表
  1191. // $Intitutions = $this->department->where([
  1192. // ["delete_time", "=", 0],
  1193. // ["pid", "=", 0],
  1194. // ["type", "=", 1], //1表示业主
  1195. // //entrust_unit委托的单位
  1196. // ["entrust_unit", "=", $unit_Name] // 确保只获取当前财评所属单位关联的业主
  1197. // ])->field('id,title')->select();
  1198. //
  1199. // return Intitutions;
  1200. //
  1201. // // 在某个业务方法中
  1202. //// $owners = $this->getOwners();
  1203. //// / 对 $owners 数据进行进一步处理,例如传递给视图进行展示等
  1204. //// View::assign('owners', $owners);
  1205. // }
  1206. public function ceshi($id)
  1207. {
  1208. View::assign('detailId', $id);
  1209. return view();
  1210. }
  1211. }