CostProprietor.php 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009
  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\ProjectFile;
  10. use think\facade\Db;
  11. use think\facade\View;
  12. use think\App;
  13. use app\admin\controller\field\Fieldproprietor;
  14. class CostProprietor extends BaseController
  15. {
  16. private array $field_name = [
  17. 'project_num' => '项目编号',
  18. "project_name" => "项目名称",
  19. "project_start_time" => "项目开始时间",
  20. "project_end_time" => "项目结束时间",
  21. "review_unit" => "评审单位",
  22. "sent_review_unit" => "送审单位",
  23. "sent_review_head" => "送审单位负责人",
  24. "sent_review_phone" => "送审单位负责人电话",
  25. "construction_unit" => "施工单位",
  26. "construction_head" => "施工单位负责人",
  27. "construction_phone" => "施工单位负责人电话",
  28. "sent_review_amount" => "送审金额",
  29. "engineering_type" => '工程类型',
  30. ];
  31. /**
  32. * 构造函数
  33. */
  34. public function __construct(App $app)
  35. {
  36. parent::__construct($app);
  37. $this->Field = new Fieldproprietor($this->app);
  38. $this->department = new DepartmentModel();
  39. $this->model = new CostProjectModel();
  40. $this->filemodel = new ProjectFile();
  41. $this->uid = get_login_admin('id');
  42. $this->Adminmodel = new Admin();
  43. }
  44. /**
  45. * 数据列表
  46. */
  47. public function datalist()
  48. {
  49. if (request()->isAjax()) {
  50. $param = get_params();
  51. $rows = empty($param['limit']) ? get_config('app . page_size') : $param['limit'];
  52. $order = empty($param['order']) ? 'id desc' : $param['order'];
  53. if (isset($param["project_start_time"])) {
  54. $param["project_start_time"] = $param["project_start_time"] ? strtotime($param["project_start_time"]) : 0;
  55. }
  56. if (isset($param["project_end_time"])) {
  57. $param["project_end_time"] = $param["project_end_time"] ? strtotime($param["project_end_time"]) : 0;
  58. }
  59. if (!empty($param['project_status'])) {
  60. if($param['project_status'] == 100){
  61. $where[] = ['project_status', '=', 0];
  62. $where[] = ['proprietor_status', '=', 0];
  63. }else if($param['project_status'] == 101){
  64. $where[] = ['project_status', '=', 0];
  65. $where[] = ['proprietor_status', '=', 1];
  66. }else if($param['project_status'] == 102){
  67. $where[] = ['project_status', '=', 0];
  68. $where[] = ['proprietor_status', '=', 2];
  69. }else{
  70. $where[] = ['project_status', '=', $param['project_status']];
  71. }
  72. }
  73. if (!empty($param['proprietor_status'])) {
  74. $where[] = ['proprietor_status', '=', $param['proprietor_status']];
  75. }
  76. if (!empty($param['province'])) {
  77. $where[] = ['province', '=', $param['province']];
  78. }
  79. if (!empty($param['city'])) {
  80. $where[] = ['city', '=', $param['city']];
  81. }
  82. if (!empty($param['area'])) {
  83. $where[] = ['area', '=', $param['area']];
  84. }
  85. if (!empty($param['project_end_time'])) {
  86. $where[] = ['project_end_time', '<', $param['project_end_time']];
  87. }
  88. if (!empty($param['project_start_time'])) {
  89. $where[] = ['project_start_time', '>', $param['project_start_time']];
  90. }
  91. if (!empty($param['review_head_name'])) {
  92. $where[] = ['review_head_name', 'like', '%' . $param['review_head_name'] . '%'];
  93. }
  94. if (!empty($param['review_unit_name'])) {
  95. $where[] = ['review_unit_name', 'like', '%' . $param['review_unit_name']. '%'];
  96. }
  97. if (!empty($param['sent_review_unit_name'])) {
  98. $where[] = ['sent_review_unit_name', 'like', '%' . $param['sent_review_unit_name']. '%'];
  99. }
  100. if (!empty($param['project_name'])) {
  101. $where[] = ['project_name', 'like', '%' . $param['project_name'] . '%'];
  102. }
  103. $where3 =[];
  104. if (!empty($param['keyword'])) {
  105. $keyword = $param['keyword'];
  106. $where3[] = ['project_num|project_name|review_unit', 'like', '%' . $keyword . '%'];
  107. }
  108. //项目可见的权限
  109. $field = $this->Field->get_field_rules_new($this->uid);
  110. //1全部-可查看可编辑,2全部-可查看,0与我有关
  111. $see_auth = isset($field["see_auth"]) ? $field["see_auth"] : 3;
  112. if($see_auth==0 || $see_auth==3){
  113. $where[] =["delete_time", "=", 0];
  114. $where[] =["sent_review_unit", "=", get_login_admin("unit_name")];
  115. $where[] =["sent_review_head","=",$this->uid];
  116. }else{
  117. $where[] =["delete_time", "=", 0];
  118. $where[] =["sent_review_unit", "=", get_login_admin("unit_name")];
  119. }
  120. $this->see_auth = $see_auth;
  121. $list = $this->model->where($where)->where($where3)->order($order)->paginate($rows, false, ['query' => $param])
  122. ->each(function ($item) {
  123. //小红点
  124. $red = Db::name("new_msg")->where([["project_id", "=", $item->id], ["uid", "=", $this->uid]])->find();
  125. if ($red) {
  126. if ($red["detail"] || $red["comment"] || $red["report"] || $red["user"] || $red["contact"]) {
  127. $item->red = 1;
  128. }
  129. } else {
  130. $item->red = 0;
  131. }
  132. if (($item->province && $item->city && $item->area)) {
  133. $item->project_region = $item->province . '-' . $item->city . '-' . $item->area;
  134. }
  135. $item->self_id = $this->see_auth;
  136. //作业人
  137. $operate_team_names = null;
  138. $operate_team_names_ids = explode(",", $item->operate_team);
  139. for ($i = 0; $i < count($operate_team_names_ids); $i++) {
  140. $name = Db::name("admin")->where("id", $operate_team_names_ids[$i])->value("nickname");
  141. if (!($i == 0)) {
  142. $name = "," . $name;
  143. }
  144. $operate_team_names = $operate_team_names . $name;
  145. }
  146. $item->operate_team_names = $operate_team_names;
  147. });
  148. return table_assign(0, '', $list);
  149. } else {
  150. $field = $this->Field->get_field_rules($this->uid);
  151. // halt($field);
  152. View::assign('field', $field);
  153. return view();
  154. }
  155. }
  156. //TODO
  157. public function list()
  158. {
  159. // if (request()->isAjax()) {
  160. $param = get_params();
  161. strtotime('-10 days');
  162. // halt(strtotime('-10 days'));
  163. $where2 = [
  164. ["delete_time", "=", 0],
  165. ["sent_review_head", "=", $this->uid],
  166. ['project_end_time', '<', strtotime('15 days')],
  167. ['project_end_time', '>', time()],
  168. ["sent_review_unit", "=", get_login_admin("unit_name")],
  169. ["project_status", "<", 7],
  170. ["project_status", ">", 3]
  171. ];
  172. $where3 = [
  173. ["delete_time", "=", 0],
  174. ["sent_review_approver", "=", $this->uid],
  175. ['project_end_time', '<', strtotime('15 days')],
  176. ['project_end_time', '>', time()],
  177. ["sent_review_unit", "=", get_login_admin("unit_name")],
  178. ["project_status", "<", 7],
  179. ["project_status", ">", 3]
  180. ];
  181. $where4 = [
  182. ["delete_time", "=", 0],
  183. ["sent_review_second_approver", "=", $this->uid],
  184. ['project_end_time', '<', strtotime('15 days')],
  185. ["sent_review_unit", "=", get_login_admin("unit_name")],
  186. ['project_end_time', '>', time()],
  187. ["project_status", "<", 7],
  188. ["project_status", ">", 3]
  189. ];
  190. $rows = empty($param['limit']) ? get_config('app . page_size') : $param['limit'];
  191. $order = empty($param['order']) ? 'id desc' : $param['order'];
  192. $list = $this->model->whereOr([ $where2,$where3,$where4])
  193. ->order($order)
  194. ->paginate($rows, false, ['query' => $param])
  195. ->each(function ($item) {
  196. });
  197. // halt($list);
  198. return table_assign(0, '', $list);
  199. // }
  200. }
  201. public function list2()
  202. {
  203. // if (request()->isAjax()) {
  204. $param = get_params();
  205. $where2 = [
  206. ["delete_time", "=", 0],
  207. ["sent_review_head", "=", $this->uid],
  208. ['project_end_time', '<', time()],
  209. ["sent_review_unit", "=", get_login_admin("unit_name")],
  210. ["project_status", "<", 7],
  211. ["project_status", ">", 3]
  212. ];
  213. $where3 = [
  214. ["delete_time", "=", 0],
  215. ["sent_review_approver", "=", $this->uid],
  216. ['project_end_time', '<', time()],
  217. ["sent_review_unit", "=", get_login_admin("unit_name")],
  218. ["project_status", "<", 7],
  219. ["project_status", ">", 3]
  220. ];
  221. $where4 = [
  222. ["delete_time", "=", 0],
  223. ["sent_review_second_approver", "=", $this->uid],
  224. ['project_end_time', '<', time()],
  225. ["sent_review_unit", "=", get_login_admin("unit_name")],
  226. ["project_status", "<", 7],
  227. ["project_status", ">", 3]
  228. ];
  229. $order = empty($param['order']) ? 'id desc' : $param['order'];
  230. $list = $this->model->whereOr([$where2,$where3,$where4])
  231. ->order($order)->paginate(99999, false, ['query' => $param])
  232. ->each(function ($item) {
  233. });
  234. // halt($list);
  235. return table_assign(0, '', $list);
  236. // }
  237. }
  238. /**
  239. * 业主保存项目
  240. */
  241. public function add()
  242. {
  243. if (request()->isAjax()) {
  244. $param = get_params();
  245. if (isset($param["project_start_time"])) {
  246. $param["project_start_time"] = $param["project_start_time"] ? strtotime($param["project_start_time"]) : 0;
  247. }
  248. if (isset($param["project_end_time"])) {
  249. $param["project_end_time"] = $param["project_end_time"] ? strtotime($param["project_end_time"]) : 0;
  250. }
  251. //送审项目的人员信息
  252. $param["sent_review_unit"] = get_login_admin("unit_name");
  253. $param["sent_review_unit_name"] = Db::name("department")->where("id", get_login_admin("unit_name"))->value("title");
  254. $param["sent_review_head"] = $this->uid;
  255. $param["sent_review_head_name"] = get_login_admin("nickname");
  256. $param["sent_review_phone"] = get_login_admin("mobile");
  257. $param["proprietor_status"] = 0;//业主创建项目时的状态 0立项,1审核,2待接收,3已接收
  258. $param["project_status"] = 0;//真实项目状态
  259. //1:财政局,3:业主,2:公司
  260. $param["maker_type"] = 3;
  261. $file_ids = isset($param["file_ids"]) ? $param["file_ids"] : 0;
  262. unset($param["file_ids"]);
  263. $file_id = [];
  264. $insertId = 0;
  265. try {
  266. $param['create_time'] = time();
  267. $insertId = $this->model->strict(false)->field(true)->insertGetId($param);
  268. if ($file_ids) {
  269. for ($a = 0; $a < count($file_ids); $a++) {
  270. $file_id[] = ["id" => $file_ids[$a], "topic_id" => $insertId];
  271. }
  272. $this->filemodel->saveAll($file_id);
  273. }
  274. add_log('add', $insertId, $param);
  275. add_project_log("创建项目", $insertId, $param["project_name"]);
  276. add_user($param["sent_review_head"], $insertId);
  277. } catch (\Exception $e) {
  278. return to_assign(1, '操作失败,原因:' . $e->getMessage());
  279. }
  280. return to_assign(0, '操作成功', ['aid' => $insertId]);
  281. } else {
  282. $unit_name = Db::name('admin')->where('id', $this->uid)->value('unit_name');
  283. $leader_id = Db::name("department")
  284. ->where([
  285. ["delete_time", "=", 0],
  286. ["pid", "=", 0],
  287. ["type", "=", 1], //1表示业主
  288. ["id", "=", $unit_name]
  289. ])->value('leader_id');
  290. $admin_group_id=Db::name("admin")->where("id", $leader_id)->value("admin_group_id");
  291. $where1 = [
  292. ['status', '>=', 0],
  293. ["admin_group_id","=", $admin_group_id],
  294. ["unit_name","=",$unit_name]
  295. ];
  296. $person = Db::name("admin")->where($where1)->field(["id", "nickname"])->select()->toArray();
  297. $where=[
  298. ["type","=","1"],
  299. ["unit_name","=", $unit_name ],
  300. ];
  301. $entrust_unit= Db::name("department")->where($where)->value("entrust_unit");
  302. $entrust_unit_name = Db::name("department")->where("unit_name", $entrust_unit)->value("title");
  303. View::assign("person", $person);
  304. View::assign("entrust_unit",$entrust_unit);
  305. View::assign("entrust_unit_name",$entrust_unit_name);
  306. return view();
  307. }
  308. }
  309. /**
  310. * 业主建立项目
  311. */
  312. public function save()
  313. {
  314. if (request()->isAjax()) {
  315. $param = get_params();
  316. //送审单位,即创建项目当的人的信息
  317. $param["sent_review_unit"] = get_login_admin("unit_name");
  318. $param["sent_review_unit_name"] = Db::name("department")->where("id", get_login_admin("unit_name"))->value("title");
  319. $param["sent_review_head"] = $this->uid;//登录人
  320. $param["sent_review_head_name"] = get_login_admin("nickname");
  321. $param["sent_review_phone"] = get_login_admin("mobile");
  322. $param["project_status"] = 0;//项目状态
  323. $param["proprietor_status"] = 1;//业主创建项目时的状态 0立项,1审核,2待接收,3已接收
  324. //1:财政局,2:公司,3:业主
  325. $param["maker_type"] = 3;
  326. if($param["id"]==0){//创建项目
  327. $file_id = [];
  328. $file_ids = isset($param["file_ids"]) ? $param["file_ids"] : 0;
  329. unset($param["file_ids"]);//去除附件
  330. // try {
  331. $param['create_time'] = time();
  332. $param['update_time'] = time();
  333. $param["creator"] = $this->uid;//创建者的登录的人的id
  334. //插入创建项目到costProject,并获取自增的id就是project_id
  335. $insertGetId = $this->model->strict(false)->field(true)->insertGetId($param);
  336. if ($file_ids) {//有附件上传
  337. for ($a = 0; $a < count($file_ids); $a++) {
  338. $file_id[] = ["id" => $file_ids[$a], "topic_id" => $insertGetId];
  339. }
  340. $this->filemodel->saveAll($file_id);
  341. }
  342. $auditData1 = [
  343. "project_id" => $insertGetId,
  344. "project_name" => $param["project_name"],
  345. "project_type" => "造价项目",
  346. "audit_name" => "业主项目审核一审",
  347. "audit_type" => 1,
  348. //
  349. "sponsor" => Db::name('admin')->where("id", $this->uid)->value("nickname"),
  350. "sponsor_id" => $this->uid,
  351. //业主不选评审
  352. //"sponsor_unit" => $param["review_unit_name"],
  353. "approver" => $param["sent_review_approver"],
  354. "approver_name" => Db::name('admin')->where("id", $param["sent_review_approver"])->value("nickname"),
  355. "create_time" => time()
  356. ];
  357. //插入
  358. ProjectAudit::create($auditData1);
  359. if(!empty($param["sent_review_second_approver"])){
  360. $auditData2 = [
  361. "project_id" => $insertGetId,
  362. "project_name" => $param["project_name"],
  363. "project_type" => "造价项目",
  364. "audit_name" => "业主项目审核二审",
  365. "audit_type" => 0,
  366. "audit_status" =>5,//待启用
  367. "sponsor" => Db::name('admin')->where("id", $this->uid)->value("nickname"),
  368. "sponsor_id" => $this->uid,
  369. "approver" => $param["sent_review_second_approver"],
  370. "approver_name" => Db::name('admin')->where("id", $param["sent_review_second_approver"])->value("nickname"),
  371. "create_time" => time()
  372. ];
  373. ProjectAudit::create($auditData2);
  374. }
  375. add_log('add', $insertGetId, $param);
  376. add_project_log("创建项目", $insertGetId,$param["project_name"]);
  377. add_user($param["sent_review_head"], $insertGetId);
  378. }else{
  379. //编辑的时候提交
  380. try {
  381. $file_ids = isset($param["file_ids"]) ? $param["file_ids"] : 0;
  382. unset($param["file_ids"]);
  383. $param['update_time'] = time();
  384. $this->model->where('id', $param['id'])->strict(false)->field(true)->update($param);
  385. if ($file_ids) {
  386. for ($a = 0; $a < count($file_ids); $a++) {
  387. $file_id[] = ["id" => $file_ids[$a], "topic_id" => $param['id']];
  388. }
  389. $this->filemodel->saveAll($file_id);
  390. }
  391. $auditData1 = [
  392. "project_id" => $param["id"],
  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["sent_review_approver"],
  401. "approver_name" => Db::name('admin')->where("id", $param["sent_review_approver"])->value("nickname"),
  402. "create_time" => time()
  403. ];
  404. //插入
  405. ProjectAudit::create($auditData1);
  406. if(!empty($param["sent_review_second_approver"])) {
  407. $auditData2 = [
  408. "project_id" => $param["id"],
  409. "project_name" => $param["project_name"],
  410. "project_type" => "造价项目",
  411. "audit_name" => "业主项目审核二审",
  412. "audit_type" => 0,
  413. "audit_status" => 5,//待启用
  414. "sponsor" => Db::name('admin')->where("id", $this->uid)->value("nickname"),
  415. "sponsor_id" => $this->uid,
  416. "approver" => $param["sent_review_second_approver"],
  417. "approver_name" => Db::name('admin')->where("id", $param["sent_review_second_approver"])->value("nickname"),
  418. "create_time" => time()
  419. ];
  420. ProjectAudit::create($auditData2);
  421. }
  422. } catch (\Exception $e) {
  423. return to_assign(1, '操作失败,原因:' . $e->getMessage());
  424. }
  425. }
  426. return to_assign(0, '操作成功');
  427. } else {
  428. $person = Db::name("admin")->where("unit_name", get_login_admin("unit_name"))->where("status",">",0)->field(["id", "nickname"])->select()->toArray();
  429. View::assign("person", $person);
  430. return view();
  431. }
  432. }
  433. /**
  434. * 撤回
  435. */
  436. public function withdraw()
  437. {
  438. if (request()->isAjax()) {
  439. $param = get_params();
  440. $status = Db::name("cost_project")->where("id", $param["id"])->field("proprietor_status")->select();
  441. // halt($status[0]["status"]);
  442. if ($status[0]["proprietor_status"] < 2) {
  443. if (isset($param["project_start_time"])) {
  444. $param["project_start_time"] = $param["project_start_time"] ? strtotime($param["project_start_time"]) : 0;
  445. }
  446. if (isset($param["project_end_time"])) {
  447. $param["project_end_time"] = $param["project_end_time"] ? strtotime($param["project_end_time"]) : 0;
  448. }
  449. $param = array_merge($param, ["proprietor_status" => 0]);
  450. try {
  451. $param['update_time'] = time();
  452. $this->model->where('id', $param['id'])->strict(false)->field(true)->update($param);
  453. Db::name("ProjectAudit")->where([["project_id", "=", $param["id"]], ["audit_status", "in", [0,1,5]], ["audit_name", "in", ["业主项目审核一审", "业主项目审核二审"]]])->delete();
  454. add_log('edit', $param['id'], $param);
  455. add_project_log('撤回', $param['id'], "撤回");
  456. } catch (\Exception $e) {
  457. return to_assign(1, '操作失败,原因:' . $e->getMessage());
  458. }
  459. return to_assign(0, "操作成功");
  460. } else {
  461. return to_assign(0, "已审核,无法撤回");
  462. }
  463. }
  464. }
  465. public function edit_main(){
  466. $param = get_params();
  467. $type = isset($param["type"])??0;
  468. if(request()->isAjax()&&$type!=2){
  469. $param = get_params();
  470. $id = $param["id"] ?? 0;
  471. if (isset($param["project_start_time"])) {
  472. $param["project_start_time"] = $param["project_start_time"] ? strtotime($param["project_start_time"]) : 0;
  473. }
  474. if (isset($param["project_end_time"])) {
  475. $param["project_end_time"] = $param["project_end_time"] ? strtotime($param["project_end_time"]) : 0;
  476. }
  477. $param["sent_review_unit"] = get_login_admin("unit_name");
  478. $param["sent_review_unit_name"] = Db::name("department")->where("id", get_login_admin("unit_name"))->value("title");
  479. $param["sent_review_head"] = $this->uid;
  480. $param["sent_review_head_name"] = get_login_admin("nickname");
  481. $param["sent_review_phone"] = get_login_admin("mobile");
  482. $param["project_status"] = 0;
  483. //1:财政局,3:业主,2:公司
  484. $param["maker_type"] = 3;
  485. $file_ids = isset($param["file_ids"]) ? $param["file_ids"] : 0;
  486. unset($param["file_ids"]);
  487. unset($param["file"]);
  488. $file_id = [];
  489. try {
  490. $param['create_time'] = time();
  491. $this->model->where("id",$id)->update($param);
  492. $insertId = $id;
  493. if ($file_ids) {
  494. for ($a = 0; $a < count($file_ids); $a++) {
  495. $file_id[] = ["id" => $file_ids[$a], "topic_id" => $insertId];
  496. }
  497. $this->filemodel->saveAll($file_id);
  498. }
  499. add_log('add', $insertId, $param);
  500. add_project_log("编辑项目", $insertId, "编辑项目");
  501. } catch (\Exception $e) {
  502. return to_assign(1, '操作失败,原因:' . $e->getMessage());
  503. }
  504. return to_assign(0, '操作成功', ['aid' => $insertId]);
  505. }else{
  506. $param = get_params();
  507. $id = $param['id'] ?? 0;
  508. $detail = $this->model->getCostProjectById($id);
  509. $unit_name =get_login_admin("unit_name");
  510. $leader_id = Db::name("department")
  511. ->where([
  512. ["delete_time", "=", 0],
  513. ["pid", "=", 0],
  514. ["type", "=", 1], //1表示业主
  515. ["id", "=", $unit_name]
  516. ])->value('leader_id');
  517. $admin_group_id=Db::name("admin")->where("id", $leader_id)->value("admin_group_id");
  518. $where1 = [
  519. ['status', '>=', 0],
  520. ["admin_group_id","=", $admin_group_id],
  521. ["unit_name","=",$unit_name]
  522. ];
  523. $person = Db::name("admin")->where($where1)->field(["id", "nickname"])->select()->toArray();
  524. $file_array = Db::name('ProjectFile')
  525. ->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')
  526. ->alias('mf')
  527. ->join('File f', 'mf.file_id = f.id', 'LEFT')
  528. ->join('Admin a', 'mf.admin_id = a.id', 'LEFT')
  529. ->order('mf.create_time desc')
  530. ->where(array('mf.topic_id' => $id, 'mf.module' => 'project'))
  531. ->select()->toArray();
  532. $project_log = self::project_log($id);
  533. View::assign('project_log', $project_log);
  534. if ($detail["project_end_time"]!=null){
  535. $c = $detail['project_end_time'] - time();
  536. if ($c > 0) {
  537. $advent_time = floor($c / 86400) . "天";
  538. } else {
  539. $c = -$c;
  540. $advent_time = floor($c / 86400) . "天";
  541. }
  542. }else{
  543. $advent_time=null;
  544. }
  545. $comment_type = isset($param["comment_type"])?$param['comment_type'] : 0;
  546. $comment = Db::name("project_comment")->where("type",$comment_type)
  547. ->where("project_id", $id)->order('create_time', 'asc')->select();
  548. $field = $this->Field->get_field_rules_new(get_login_admin('id'));
  549. $field_edit = $this->Field->get_field_rules_edit_new($this->uid);
  550. //委托单位
  551. $unit_name = Db::name('admin')->where('id', $this->uid)->value('unit_name');
  552. $where=[
  553. ["type","=","1"],
  554. ["unit_name","=", $unit_name ],
  555. ];
  556. $entrust_unit= Db::name("department")->where($where)->value("entrust_unit");
  557. $entrust_unit_name = Db::name("department")->where("unit_name", $entrust_unit)->value("title");
  558. View::assign("entrust_unit",$entrust_unit);
  559. View::assign("entrust_unit_name",$entrust_unit_name);
  560. if (!empty($detail)) {
  561. View::assign('comment', $comment);
  562. View::assign('field', $field);
  563. View::assign('advent_time', $advent_time);
  564. View::assign('field_edit', $field_edit);
  565. View::assign('project_id', $id);
  566. View::assign('detail', $detail);
  567. View::assign("person", $person);
  568. View::assign("file_array", $file_array);
  569. View::assign('project_five', self::getProjectFive());
  570. } else {
  571. throw new \think\exception\HttpException(404, '找不到页面,请联系管理员');
  572. }
  573. return view();
  574. }
  575. }
  576. /**
  577. * 查看信息
  578. */
  579. public function read()
  580. {
  581. $param = get_params();
  582. $id = isset($param['id']) ? $param['id'] : 0;
  583. // dump($id);
  584. $detail = $this->model->getCostProjectById($id);
  585. $comment_type = isset($param["comment_type"])?$param['comment_type'] : 0;
  586. $comment = Db::name("project_comment")->where("type",$comment_type)
  587. ->where("project_id", $id)->order('create_time', 'asc')->select();
  588. $file_array = Db::name('ProjectFile')
  589. ->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')
  590. ->alias('mf')
  591. ->join('File f', 'mf.file_id = f.id', 'LEFT')
  592. ->join('Admin a', 'mf.admin_id = a.id', 'LEFT')
  593. ->order('mf.create_time desc')
  594. ->where(array('mf.topic_id' => $id, 'mf.module' => 'project'))
  595. ->select()->toArray();
  596. $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();
  597. // halt($comment);
  598. $project_log = self::project_log($id);
  599. View::assign('project_log', $project_log);
  600. // halt($project_log);
  601. // 根据用户id 查询其能显示的字段
  602. $field = $this->Field->get_field_rules_new(get_login_admin('id'));
  603. // dump($field);
  604. // halt(self::getProjectFive());
  605. if (!empty($detail)) {
  606. View::assign('project_id', $id);
  607. View::assign('comment', $comment);
  608. View::assign('field', $field);
  609. View::assign('detail', $detail);
  610. View::assign('file_array', $file_array);
  611. View::assign('report', $report);
  612. View::assign('project_five', self::getProjectFive());
  613. return view();
  614. } else {
  615. throw new \think\exception\HttpException(404, '找不到页面');
  616. }
  617. }
  618. /**
  619. * 删除
  620. * type=0,逻辑删除,默认
  621. * type=1,物理删除
  622. */
  623. public function del()
  624. {
  625. $param = get_params();
  626. $status = Db::name("cost_project")->where("id", $param["id"])->field("proprietor_status")->select();
  627. if ($status[0]["proprietor_status"] < 1) {//立项中
  628. $id = isset($param['id']) ? $param['id'] : 0;
  629. $type = isset($param['type']) ? $param['type'] : 0;
  630. add_project_log("删除项目", $id, "删除项目");
  631. $this->model->delCostProjectById($id, $type);
  632. } else {
  633. return to_assign(0, "已审核,无法删除");
  634. }
  635. }
  636. //获取客户列表
  637. public function get_customer()
  638. {
  639. $param = get_params();
  640. $where = array();
  641. if (!empty($param['keywords'])) {
  642. $where[] = ['id|title', 'like', '%' . $param['keywords'] . '%'];
  643. }
  644. $where = [
  645. ["delete_time", "=", 0],
  646. ["pid", "=", 0],
  647. ["type", "=", 2]
  648. ];
  649. $rows = empty($param['limit']) ? get_config('app.page_size') : $param['limit'];
  650. $list = $this->department->field('id,title,address,leader_id')->order('id asc')->where($where)->paginate($rows, false)
  651. ->each(function ($item) {
  652. $item->nickname = Db::name('admin')->where(['id' => $item->leader_id])->value('nickname');
  653. $item->mobile = Db::name('admin')->where(['id' => $item->leader_id])->value('mobile');
  654. });
  655. // halt($list);
  656. table_assign(0, '', $list);
  657. }
  658. //获取客户列表
  659. public function addConstructionPeople()
  660. {
  661. $param = get_params();
  662. if (request()->isAjax()) {
  663. $this->model->addConstructionPeople($param);
  664. } else {
  665. $project_id = isset($param['project_id']) ? $param['project_id'] : 0;
  666. //关联项目id
  667. View::assign('project_id', $project_id);
  668. return view();
  669. }
  670. }
  671. public function getConstructionPeople()
  672. {
  673. $param = get_params();
  674. if (request()->isAjax()) {
  675. $data = $this->model->where('id', $param["id"])->find();
  676. if ($data["construction_unit"] !== null ||
  677. $data["construction_head"] !== null ||
  678. $data["construction_email"] !== null ||
  679. $data["construction_phone"] !== null
  680. ) {
  681. return to_assign(0, "已存在!!");
  682. } else {
  683. return to_assign(200, "请上传!!");
  684. }
  685. }
  686. }
  687. public function project_user()
  688. {
  689. $param = get_params();
  690. $ids = $this->model->where("id", $param["project_id"])->field("entrust_maker,review_head,operate_head,operate_team")->find()->toArray();
  691. $idarr = $ids["operate_team"] . ',' . $ids["operate_head"] . ',' . $ids["review_head"] . ',' . $ids["entrust_maker"];
  692. $idarr = explode(",", $idarr);
  693. $rows = empty($param['limit']) ? get_config('app.page_size') : $param['limit'];
  694. $list = $this->Adminmodel->whereIn("id", $idarr)->field("id,nickname,unit_name,mobile,email")->paginate($rows, false, ['query' => $param])
  695. // 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')
  696. ->each(function ($item) {
  697. //获取单位的邮箱,单位信息页没做
  698. $item->email = Db::name('department')->where(['id' => $item->unit_name])->value('email');
  699. $type = Db::name('department')->where(['id' => $item->unit_name])->value('type');
  700. $item->unit_name = Db::name('department')->where(['id' => $item->unit_name])->value('title');
  701. // dump($type);
  702. if ($type == 0) {
  703. $item->unit_type = "委托单位";
  704. } elseif ($type == 1) {
  705. $item->unit_type = "送审单位";
  706. } elseif ($type == 2) {
  707. $item->unit_type = "评审机构";
  708. } else {
  709. $item->unit_type = "施工单位";
  710. }
  711. })->toArray();
  712. $list = $list["data"];
  713. for ($i = 0; $i < count($list); $i++) {
  714. if ($list[$i]['id'] == $ids['entrust_maker']) {
  715. // dump($list[$i]['id'],$ids['entrust_maker']);
  716. $list[$i]["type"] = 1;
  717. } elseif ($list[$i]['id'] == $ids['review_head']) {
  718. $list[$i]["type"] = 2;
  719. } elseif ($list[$i]['id'] == $ids['operate_head']) {
  720. $list[$i]["type"] = 3;
  721. } elseif (in_array($list[$i]['id'], explode(',', $ids['operate_team']))) {
  722. $list[$i]["type"] = 4;
  723. }
  724. }
  725. $type = array_column($list, 'type');
  726. array_multisort($type, SORT_ASC, $list);
  727. $shigong = $this->model->where('id', $param["project_id"])->find();
  728. if ($shigong["construction_unit"] !== null ||
  729. $shigong["construction_head"] !== null ||
  730. $shigong["construction_email"] !== null ||
  731. $shigong["construction_phone"] !== null
  732. ) {
  733. $shigongdata["id"] = time();
  734. $shigongdata["nickname"] = $shigong["construction_unit"];
  735. $shigongdata["unit_name"] = $shigong["construction_head"];
  736. $shigongdata["email"] = $shigong["construction_email"];
  737. $shigongdata["mobile"] = $shigong["construction_phone"];
  738. $shigongdata["unit_type"] = "施工单位";
  739. array_push($list, $shigongdata);
  740. }
  741. $list["data"] = $list;
  742. return table_assign(0, '', $list);
  743. }
  744. public function getProjectFive()
  745. {
  746. $where = [
  747. ['name', '=', '作业日志-业主'],
  748. ['name', '=', '工作记录-业主'],
  749. ['name', '=', '项目报告-业主'],
  750. ['name', '=', '项目人员-业主'],
  751. ['name', '=', '项目动态-业主'],
  752. ['name', '=', '项目附件-业主'],
  753. ['name', '=', '联系函-业主'],
  754. ];
  755. $list = Db::name('AdminRule')->whereOr($where)->field('id,name')->select()->toArray();
  756. $group_id = Db::name('AdminGroupAccess')->where('uid', get_login_admin('id'))->value('group_id');
  757. $login_rules = Db::name('AdminGroup')->where('id', $group_id)->value('rules');
  758. $login_rules = explode(',', $login_rules);
  759. $rules_id = array();
  760. foreach ($list as $key => $value) {
  761. if ($value['name'] == "作业日志-业主") {
  762. if (in_array($value['id'], $login_rules)) {
  763. $rules_id['project_comments'] = 1;
  764. } else {
  765. $rules_id['project_comments'] = 0;
  766. }
  767. } else if ($value['name'] == "工作记录-业主") {
  768. if (in_array($value['id'], $login_rules)) {
  769. $rules_id['project_record'] = 1;
  770. } else {
  771. $rules_id['project_record'] = 0;
  772. }
  773. } else if ($value['name'] == "项目报告-业主") {
  774. if (in_array($value['id'], $login_rules)) {
  775. $rules_id['project_report'] = 1;
  776. } else {
  777. $rules_id['project_report'] = 0;
  778. }
  779. } else if ($value['name'] == "项目人员-业主") {
  780. if (in_array($value['id'], $login_rules)) {
  781. $rules_id['project_user'] = 1;
  782. } else {
  783. $rules_id['project_user'] = 0;
  784. }
  785. } else if ($value['name'] == "项目动态-业主") {
  786. if (in_array($value['id'], $login_rules)) {
  787. $rules_id['project_log'] = 1;
  788. } else {
  789. $rules_id['project_log'] = 0;
  790. }
  791. } else if ($value['name'] == "项目附件-业主") {
  792. if (in_array($value['id'], $login_rules)) {
  793. $rules_id['project_file'] = 1;
  794. } else {
  795. $rules_id['project_file'] = 0;
  796. }
  797. } else if ($value['name'] == "联系函-业主") {
  798. if (in_array($value['id'], $login_rules)) {
  799. $rules_id['project_contact'] = 1;
  800. } else {
  801. $rules_id['project_contact'] = 0;
  802. }
  803. }
  804. }
  805. return $rules_id;
  806. }
  807. public function getemployeelist()
  808. {
  809. if (request()->isAjax()) {
  810. $data = $this->request->param();
  811. $person = Db::name("admin")->where([["unit_name", "=", $data['id']], ["status", "=", 1]])->field(["id", "nickname", "mobile"])->select();
  812. return $person;
  813. }
  814. }
  815. public function project_log($project_id)
  816. {
  817. // $project_id = 24;
  818. $login_admin = get_login_admin();
  819. $where = array();
  820. if ($login_admin['user_type'] == 2) {
  821. $where = [
  822. ['project_status', '>=', 3],
  823. ['unit_name', '=', $login_admin['unit_name']],
  824. ];
  825. } else {
  826. if ($login_admin['permission'] != 1) {
  827. $where = [
  828. ['unit_name', '=', $login_admin['unit_name']],
  829. ];
  830. }
  831. }
  832. // dump($where);
  833. $project_log = Db::name('ProjectLog')->where($where)->where('project_id', $project_id)->order('create_time', 'desc')->select()->toArray();
  834. foreach ($project_log as $key => $value) {
  835. $project_log[$key]['create_time'] = date("Y-m-d H:i:s", $value['create_time']);
  836. }
  837. // dump($project_log);
  838. // View::assign('project_log', $project_log);
  839. // return View();
  840. return $project_log;
  841. }
  842. public function ceshi($id)
  843. {
  844. View::assign('detailId', $id);
  845. return view();
  846. }
  847. }