Cost.php 61 KB

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