Cost.php 59 KB

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