CostProprietor.php 36 KB

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