Cost.php 63 KB

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