CostProprietor.php 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924
  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. $c = $detail['project_end_time'] - time();
  470. $project_log = self::project_log($id);
  471. View::assign('project_log', $project_log);
  472. if ($c > 0) {
  473. $advent_time = floor($c / 86400) . "天";
  474. } else {
  475. $c = -$c;
  476. $advent_time = floor($c / 86400) . "天";
  477. }
  478. $comment_type = isset($param["comment_type"])?$param['comment_type'] : 0;
  479. $comment = Db::name("project_comment")->where("type",$comment_type)
  480. ->where("project_id", $id)->order('create_time', 'asc')->select();
  481. $field = $this->Field->get_field_rules_new(get_login_admin('id'));
  482. $field_edit = $this->Field->get_field_rules_edit_new($this->uid);
  483. //dump($detail);
  484. if (!empty($detail)) {
  485. View::assign('comment', $comment);
  486. View::assign('field', $field);
  487. View::assign('advent_time', $advent_time);
  488. View::assign('field_edit', $field_edit);
  489. View::assign('project_id', $id);
  490. View::assign('detail', $detail);
  491. View::assign("person", $person);
  492. View::assign("file_array", $file_array);
  493. View::assign('project_five', self::getProjectFive());
  494. } else {
  495. throw new \think\exception\HttpException(404, '找不到页面,请联系管理员');
  496. }
  497. return view();
  498. }
  499. }
  500. /**
  501. * 查看信息
  502. */
  503. public function read()
  504. {
  505. $param = get_params();
  506. $id = isset($param['id']) ? $param['id'] : 0;
  507. // dump($id);
  508. $detail = $this->model->getCostProjectById($id);
  509. $comment_type = isset($param["comment_type"])?$param['comment_type'] : 0;
  510. $comment = Db::name("project_comment")->where("type",$comment_type)
  511. ->where("project_id", $id)->order('create_time', 'asc')->select();
  512. $file_array = Db::name('ProjectFile')
  513. ->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')
  514. ->alias('mf')
  515. ->join('File f', 'mf.file_id = f.id', 'LEFT')
  516. ->join('Admin a', 'mf.admin_id = a.id', 'LEFT')
  517. ->order('mf.create_time desc')
  518. ->where(array('mf.topic_id' => $id, 'mf.module' => 'project'))
  519. ->select()->toArray();
  520. $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();
  521. // halt($comment);
  522. $project_log = self::project_log($id);
  523. View::assign('project_log', $project_log);
  524. // halt($project_log);
  525. // 根据用户id 查询其能显示的字段
  526. $field = $this->Field->get_field_rules_new(get_login_admin('id'));
  527. // dump($field);
  528. // halt(self::getProjectFive());
  529. if (!empty($detail)) {
  530. View::assign('project_id', $id);
  531. View::assign('comment', $comment);
  532. View::assign('field', $field);
  533. View::assign('detail', $detail);
  534. View::assign('file_array', $file_array);
  535. View::assign('report', $report);
  536. View::assign('project_five', self::getProjectFive());
  537. return view();
  538. } else {
  539. throw new \think\exception\HttpException(404, '找不到页面');
  540. }
  541. }
  542. /**
  543. * 删除
  544. * type=0,逻辑删除,默认
  545. * type=1,物理删除
  546. */
  547. public function del()
  548. {
  549. $param = get_params();
  550. $status = Db::name("cost_project")->where("id", $param["id"])->field("proprietor_status")->select();
  551. if ($status[0]["proprietor_status"] < 1) {//立项中
  552. $id = isset($param['id']) ? $param['id'] : 0;
  553. $type = isset($param['type']) ? $param['type'] : 0;
  554. add_project_log("删除项目", $id, "删除项目");
  555. $this->model->delCostProjectById($id, $type);
  556. } else {
  557. return to_assign(0, "已审核,无法删除");
  558. }
  559. }
  560. //获取客户列表
  561. public function get_customer()
  562. {
  563. $param = get_params();
  564. $where = array();
  565. if (!empty($param['keywords'])) {
  566. $where[] = ['id|title', 'like', '%' . $param['keywords'] . '%'];
  567. }
  568. $where = [
  569. ["delete_time", "=", 0],
  570. ["pid", "=", 0],
  571. ["type", "=", 2]
  572. ];
  573. $rows = empty($param['limit']) ? get_config('app.page_size') : $param['limit'];
  574. $list = $this->department->field('id,title,address,leader_id')->order('id asc')->where($where)->paginate($rows, false)
  575. ->each(function ($item) {
  576. $item->nickname = Db::name('admin')->where(['id' => $item->leader_id])->value('nickname');
  577. $item->mobile = Db::name('admin')->where(['id' => $item->leader_id])->value('mobile');
  578. });
  579. // halt($list);
  580. table_assign(0, '', $list);
  581. }
  582. //获取客户列表
  583. public function addConstructionPeople()
  584. {
  585. $param = get_params();
  586. if (request()->isAjax()) {
  587. $this->model->addConstructionPeople($param);
  588. } else {
  589. $project_id = isset($param['project_id']) ? $param['project_id'] : 0;
  590. //关联项目id
  591. View::assign('project_id', $project_id);
  592. return view();
  593. }
  594. }
  595. public function getConstructionPeople()
  596. {
  597. $param = get_params();
  598. if (request()->isAjax()) {
  599. $data = $this->model->where('id', $param["id"])->find();
  600. if ($data["construction_unit"] !== null ||
  601. $data["construction_head"] !== null ||
  602. $data["construction_email"] !== null ||
  603. $data["construction_phone"] !== null
  604. ) {
  605. return to_assign(0, "已存在!!");
  606. } else {
  607. return to_assign(200, "请上传!!");
  608. }
  609. }
  610. }
  611. public function project_user()
  612. {
  613. $param = get_params();
  614. $ids = $this->model->where("id", $param["project_id"])->field("entrust_maker,review_head,operate_head,operate_team")->find()->toArray();
  615. $idarr = $ids["operate_team"] . ',' . $ids["operate_head"] . ',' . $ids["review_head"] . ',' . $ids["entrust_maker"];
  616. $idarr = explode(",", $idarr);
  617. $rows = empty($param['limit']) ? get_config('app.page_size') : $param['limit'];
  618. $list = $this->Adminmodel->whereIn("id", $idarr)->field("id,nickname,unit_name,mobile,email")->paginate($rows, false, ['query' => $param])
  619. // 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')
  620. ->each(function ($item) {
  621. //获取单位的邮箱,单位信息页没做
  622. $item->email = Db::name('department')->where(['id' => $item->unit_name])->value('email');
  623. $type = Db::name('department')->where(['id' => $item->unit_name])->value('type');
  624. $item->unit_name = Db::name('department')->where(['id' => $item->unit_name])->value('title');
  625. // dump($type);
  626. if ($type == 0) {
  627. $item->unit_type = "委托单位";
  628. } elseif ($type == 1) {
  629. $item->unit_type = "送审单位";
  630. } elseif ($type == 2) {
  631. $item->unit_type = "评审机构";
  632. } else {
  633. $item->unit_type = "施工单位";
  634. }
  635. })->toArray();
  636. $list = $list["data"];
  637. for ($i = 0; $i < count($list); $i++) {
  638. if ($list[$i]['id'] == $ids['entrust_maker']) {
  639. // dump($list[$i]['id'],$ids['entrust_maker']);
  640. $list[$i]["type"] = 1;
  641. } elseif ($list[$i]['id'] == $ids['review_head']) {
  642. $list[$i]["type"] = 2;
  643. } elseif ($list[$i]['id'] == $ids['operate_head']) {
  644. $list[$i]["type"] = 3;
  645. } elseif (in_array($list[$i]['id'], explode(',', $ids['operate_team']))) {
  646. $list[$i]["type"] = 4;
  647. }
  648. }
  649. $type = array_column($list, 'type');
  650. array_multisort($type, SORT_ASC, $list);
  651. $shigong = $this->model->where('id', $param["project_id"])->find();
  652. if ($shigong["construction_unit"] !== null ||
  653. $shigong["construction_head"] !== null ||
  654. $shigong["construction_email"] !== null ||
  655. $shigong["construction_phone"] !== null
  656. ) {
  657. $shigongdata["id"] = time();
  658. $shigongdata["nickname"] = $shigong["construction_unit"];
  659. $shigongdata["unit_name"] = $shigong["construction_head"];
  660. $shigongdata["email"] = $shigong["construction_email"];
  661. $shigongdata["mobile"] = $shigong["construction_phone"];
  662. $shigongdata["unit_type"] = "施工单位";
  663. array_push($list, $shigongdata);
  664. }
  665. $list["data"] = $list;
  666. return table_assign(0, '', $list);
  667. }
  668. public function getProjectFive()
  669. {
  670. $where = [
  671. ['name', '=', '作业日志-业主'],
  672. ['name', '=', '工作记录-业主'],
  673. ['name', '=', '项目报告-业主'],
  674. ['name', '=', '项目人员-业主'],
  675. ['name', '=', '项目动态-业主'],
  676. ['name', '=', '项目附件-业主'],
  677. ['name', '=', '联系函-业主'],
  678. ];
  679. $list = Db::name('AdminRule')->whereOr($where)->field('id,name')->select()->toArray();
  680. $group_id = Db::name('AdminGroupAccess')->where('uid', get_login_admin('id'))->value('group_id');
  681. $login_rules = Db::name('AdminGroup')->where('id', $group_id)->value('rules');
  682. $login_rules = explode(',', $login_rules);
  683. $rules_id = array();
  684. foreach ($list as $key => $value) {
  685. if ($value['name'] == "作业日志-业主") {
  686. if (in_array($value['id'], $login_rules)) {
  687. $rules_id['project_comments'] = 1;
  688. } else {
  689. $rules_id['project_comments'] = 0;
  690. }
  691. } else if ($value['name'] == "工作记录-业主") {
  692. if (in_array($value['id'], $login_rules)) {
  693. $rules_id['project_record'] = 1;
  694. } else {
  695. $rules_id['project_record'] = 0;
  696. }
  697. } else if ($value['name'] == "项目报告-业主") {
  698. if (in_array($value['id'], $login_rules)) {
  699. $rules_id['project_report'] = 1;
  700. } else {
  701. $rules_id['project_report'] = 0;
  702. }
  703. } else if ($value['name'] == "项目人员-业主") {
  704. if (in_array($value['id'], $login_rules)) {
  705. $rules_id['project_user'] = 1;
  706. } else {
  707. $rules_id['project_user'] = 0;
  708. }
  709. } else if ($value['name'] == "项目动态-业主") {
  710. if (in_array($value['id'], $login_rules)) {
  711. $rules_id['project_log'] = 1;
  712. } else {
  713. $rules_id['project_log'] = 0;
  714. }
  715. } else if ($value['name'] == "项目附件-业主") {
  716. if (in_array($value['id'], $login_rules)) {
  717. $rules_id['project_file'] = 1;
  718. } else {
  719. $rules_id['project_file'] = 0;
  720. }
  721. } else if ($value['name'] == "联系函-业主") {
  722. if (in_array($value['id'], $login_rules)) {
  723. $rules_id['project_contact'] = 1;
  724. } else {
  725. $rules_id['project_contact'] = 0;
  726. }
  727. }
  728. }
  729. return $rules_id;
  730. }
  731. public function getemployeelist()
  732. {
  733. if (request()->isAjax()) {
  734. $data = $this->request->param();
  735. $person = Db::name("admin")->where([["unit_name", "=", $data['id']], ["status", "=", 1]])->field(["id", "nickname", "mobile"])->select();
  736. return $person;
  737. }
  738. }
  739. public function project_log($project_id)
  740. {
  741. // $project_id = 24;
  742. $login_admin = get_login_admin();
  743. $where = array();
  744. if ($login_admin['user_type'] == 2) {
  745. $where = [
  746. ['project_status', '>=', 3],
  747. ['unit_name', '=', $login_admin['unit_name']],
  748. ];
  749. } else {
  750. if ($login_admin['permission'] != 1) {
  751. $where = [
  752. ['unit_name', '=', $login_admin['unit_name']],
  753. ];
  754. }
  755. }
  756. // dump($where);
  757. $project_log = Db::name('ProjectLog')->where($where)->where('project_id', $project_id)->order('create_time', 'desc')->select()->toArray();
  758. foreach ($project_log as $key => $value) {
  759. $project_log[$key]['create_time'] = date("Y-m-d H:i:s", $value['create_time']);
  760. }
  761. // dump($project_log);
  762. // View::assign('project_log', $project_log);
  763. // return View();
  764. return $project_log;
  765. }
  766. }