CostProprietor.php 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947
  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. $unit_name = Db::name('admin')->where('id', $this->uid)->value('unit_name');
  251. $person = Db::name("admin")->where("unit_name", $unit_name)->where("status",">",0)->field(["id", "nickname"])->select()->toArray();
  252. $where=[
  253. ["type","=","1"],
  254. ["unit_name","=", $unit_name ],
  255. ];
  256. $entrust_unit= Db::name("department")->where($where)->value("entrust_unit");
  257. $entrust_unit_name = Db::name("department")->where("unit_name", $entrust_unit)->value("title");
  258. View::assign("person", $person);
  259. View::assign("entrust_unit",$entrust_unit);
  260. View::assign("entrust_unit_name",$entrust_unit_name);
  261. return view();
  262. }
  263. }
  264. /**
  265. * 业主建立项目
  266. */
  267. public function save()
  268. {
  269. if (request()->isAjax()) {
  270. $param = get_params();
  271. //送审单位,即创建项目当的人的信息
  272. $param["sent_review_unit"] = get_login_admin("unit_name");
  273. $param["sent_review_unit_name"] = Db::name("department")->where("id", get_login_admin("unit_name"))->value("title");
  274. $param["sent_review_head"] = $this->uid;//登录人
  275. $param["sent_review_head_name"] = get_login_admin("nickname");
  276. $param["sent_review_head_phone"] = get_login_admin("mobile");
  277. $param["project_status"] = 0;//项目状态
  278. $param["proprietor_status"] = 1;//业主创建项目时的状态 0立项,1审核,2待接收,3已接收
  279. //1:财政局,2:公司,3:业主
  280. $param["maker_type"] = 3;
  281. if($param["id"]==0){//创建项目
  282. $file_id = [];
  283. $file_ids = isset($param["file_ids"]) ? $param["file_ids"] : 0;
  284. unset($param["file_ids"]);//去除附件
  285. // try {
  286. $param['create_time'] = time();
  287. $param['update_time'] = time();
  288. $param["creator"] = $this->uid;//创建者的登录的人的id
  289. //插入创建项目到costProject,并获取自增的id就是project_id
  290. $insertGetId = $this->model->strict(false)->field(true)->insertGetId($param);
  291. if ($file_ids) {//有附件上传
  292. for ($a = 0; $a < count($file_ids); $a++) {
  293. $file_id[] = ["id" => $file_ids[$a], "topic_id" => $insertGetId];
  294. }
  295. $this->filemodel->saveAll($file_id);
  296. }
  297. $auditData1 = [
  298. "project_id" => $insertGetId,
  299. "project_name" => $param["project_name"],
  300. "project_type" => "造价项目",
  301. "audit_name" => "业主项目审核一审",
  302. "audit_type" => 1,
  303. //
  304. "sponsor" => Db::name('admin')->where("id", $this->uid)->value("nickname"),
  305. "sponsor_id" => $this->uid,
  306. //业主不选评审
  307. //"sponsor_unit" => $param["review_unit_name"],
  308. "approver" => $param["sent_review_approver"],
  309. "approver_name" => Db::name('admin')->where("id", $param["sent_review_approver"])->value("nickname"),
  310. "create_time" => time()
  311. ];
  312. //插入
  313. ProjectAudit::create($auditData1);
  314. if(!empty($param["sent_review_second_approver"])){
  315. $auditData2 = [
  316. "project_id" => $insertGetId,
  317. "project_name" => $param["project_name"],
  318. "project_type" => "造价项目",
  319. "audit_name" => "业主项目审核二审",
  320. "audit_type" => 0,
  321. "audit_status" =>5,//待启用
  322. "sponsor" => Db::name('admin')->where("id", $this->uid)->value("nickname"),
  323. "sponsor_id" => $this->uid,
  324. "approver" => $param["sent_review_second_approver"],
  325. "approver_name" => Db::name('admin')->where("id", $param["sent_review_second_approver"])->value("nickname"),
  326. "create_time" => time()
  327. ];
  328. ProjectAudit::create($auditData2);
  329. }
  330. add_log('add', $insertGetId, $param);
  331. add_project_log("创建项目", $insertGetId,$param["project_name"]);
  332. add_user($param["sent_review_head"], $insertGetId);
  333. }else{
  334. //编辑的时候提交
  335. try {
  336. $file_ids = isset($param["file_ids"]) ? $param["file_ids"] : 0;
  337. unset($param["file_ids"]);
  338. $param['update_time'] = time();
  339. $this->model->where('id', $param['id'])->strict(false)->field(true)->update($param);
  340. if ($file_ids) {
  341. for ($a = 0; $a < count($file_ids); $a++) {
  342. $file_id[] = ["id" => $file_ids[$a], "topic_id" => $param['id']];
  343. }
  344. $this->filemodel->saveAll($file_id);
  345. }
  346. $auditData1 = [
  347. "project_id" => $param["id"],
  348. "project_name" => $param["project_name"],
  349. "project_type" => "造价项目",
  350. "audit_name" => "业主项目审核一审",
  351. "audit_type" => 1,
  352. "sponsor" => Db::name('admin')->where("id", $this->uid)->value("nickname"),
  353. "sponsor_id" => $this->uid,
  354. // "sponsor_unit" => $param["review_unit_name"],
  355. "approver" => $param["sent_review_approver"],
  356. "approver_name" => Db::name('admin')->where("id", $param["sent_review_approver"])->value("nickname"),
  357. "create_time" => time()
  358. ];
  359. //插入
  360. ProjectAudit::create($auditData1);
  361. if(!empty($param["sent_review_second_approver"])) {
  362. $auditData2 = [
  363. "project_id" => $param["id"],
  364. "project_name" => $param["project_name"],
  365. "project_type" => "造价项目",
  366. "audit_name" => "业主项目审核二审",
  367. "audit_type" => 0,
  368. "audit_status" => 5,//待启用
  369. "sponsor" => Db::name('admin')->where("id", $this->uid)->value("nickname"),
  370. "sponsor_id" => $this->uid,
  371. "approver" => $param["sent_review_second_approver"],
  372. "approver_name" => Db::name('admin')->where("id", $param["sent_review_second_approver"])->value("nickname"),
  373. "create_time" => time()
  374. ];
  375. ProjectAudit::create($auditData2);
  376. }
  377. } catch (\Exception $e) {
  378. return to_assign(1, '操作失败,原因:' . $e->getMessage());
  379. }
  380. }
  381. return to_assign(0, '操作成功');
  382. } else {
  383. $person = Db::name("admin")->where("unit_name", get_login_admin("unit_name"))->where("status",">",0)->field(["id", "nickname"])->select()->toArray();
  384. View::assign("person", $person);
  385. return view();
  386. }
  387. }
  388. /**
  389. * 撤回
  390. */
  391. public function withdraw()
  392. {
  393. if (request()->isAjax()) {
  394. $param = get_params();
  395. $status = Db::name("cost_project")->where("id", $param["id"])->field("proprietor_status")->select();
  396. // halt($status[0]["status"]);
  397. if ($status[0]["proprietor_status"] < 2) {
  398. if (isset($param["project_start_time"])) {
  399. $param["project_start_time"] = $param["project_start_time"] ? strtotime($param["project_start_time"]) : 0;
  400. }
  401. if (isset($param["project_end_time"])) {
  402. $param["project_end_time"] = $param["project_end_time"] ? strtotime($param["project_end_time"]) : 0;
  403. }
  404. $param = array_merge($param, ["proprietor_status" => 0]);
  405. try {
  406. $param['update_time'] = time();
  407. $this->model->where('id', $param['id'])->strict(false)->field(true)->update($param);
  408. Db::name("ProjectAudit")->where([["project_id", "=", $param["id"]], ["audit_status", "in", [0,1,5]], ["audit_name", "in", ["业主项目审核一审", "业主项目审核二审"]]])->delete();
  409. add_log('edit', $param['id'], $param);
  410. add_project_log('撤回', $param['id'], "撤回");
  411. } catch (\Exception $e) {
  412. return to_assign(1, '操作失败,原因:' . $e->getMessage());
  413. }
  414. return to_assign(0, "操作成功");
  415. } else {
  416. return to_assign(0, "已审核,无法撤回");
  417. }
  418. }
  419. }
  420. public function edit_main(){
  421. $param = get_params();
  422. $type = isset($param["type"])??0;
  423. if(request()->isAjax()&&$type!=2){
  424. $param = get_params();
  425. $id = $param["id"] ?? 0;
  426. if (isset($param["project_start_time"])) {
  427. $param["project_start_time"] = $param["project_start_time"] ? strtotime($param["project_start_time"]) : 0;
  428. }
  429. if (isset($param["project_end_time"])) {
  430. $param["project_end_time"] = $param["project_end_time"] ? strtotime($param["project_end_time"]) : 0;
  431. }
  432. $param["sent_review_unit"] = get_login_admin("unit_name");
  433. $param["sent_review_unit_name"] = Db::name("department")->where("id", get_login_admin("unit_name"))->value("title");
  434. $param["sent_review_head"] = $this->uid;
  435. $param["sent_review_head_name"] = get_login_admin("nickname");
  436. $param["sent_review_phone"] = get_login_admin("mobile");
  437. $param["project_status"] = 0;
  438. //1:财政局,3:业主,2:公司
  439. $param["maker_type"] = 3;
  440. $file_ids = isset($param["file_ids"]) ? $param["file_ids"] : 0;
  441. unset($param["file_ids"]);
  442. unset($param["file"]);
  443. $file_id = [];
  444. try {
  445. $param['create_time'] = time();
  446. $this->model->where("id",$id)->update($param);
  447. $insertId = $id;
  448. if ($file_ids) {
  449. for ($a = 0; $a < count($file_ids); $a++) {
  450. $file_id[] = ["id" => $file_ids[$a], "topic_id" => $insertId];
  451. }
  452. $this->filemodel->saveAll($file_id);
  453. }
  454. add_log('add', $insertId, $param);
  455. add_project_log("编辑项目", $insertId, "编辑项目");
  456. } catch (\Exception $e) {
  457. return to_assign(1, '操作失败,原因:' . $e->getMessage());
  458. }
  459. return to_assign(0, '操作成功', ['aid' => $insertId]);
  460. }else{
  461. $param = get_params();
  462. $id = $param['id'] ?? 0;
  463. $detail = $this->model->getCostProjectById($id);
  464. $person = Db::name("admin")->where("unit_name", get_login_admin("unit_name"))->where("status",">",0)->field(["id", "nickname"])->select()->toArray();
  465. $file_array = Db::name('ProjectFile')
  466. ->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')
  467. ->alias('mf')
  468. ->join('File f', 'mf.file_id = f.id', 'LEFT')
  469. ->join('Admin a', 'mf.admin_id = a.id', 'LEFT')
  470. ->order('mf.create_time desc')
  471. ->where(array('mf.topic_id' => $id, 'mf.module' => 'project'))
  472. ->select()->toArray();
  473. $project_log = self::project_log($id);
  474. View::assign('project_log', $project_log);
  475. if ($detail["project_end_time"]!=null){
  476. $c = $detail['project_end_time'] - time();
  477. if ($c > 0) {
  478. $advent_time = floor($c / 86400) . "天";
  479. } else {
  480. $c = -$c;
  481. $advent_time = floor($c / 86400) . "天";
  482. }
  483. }else{
  484. $advent_time=null;
  485. }
  486. $comment_type = isset($param["comment_type"])?$param['comment_type'] : 0;
  487. $comment = Db::name("project_comment")->where("type",$comment_type)
  488. ->where("project_id", $id)->order('create_time', 'asc')->select();
  489. $field = $this->Field->get_field_rules_new(get_login_admin('id'));
  490. $field_edit = $this->Field->get_field_rules_edit_new($this->uid);
  491. //委托单位
  492. $unit_name = Db::name('admin')->where('id', $this->uid)->value('unit_name');
  493. $where=[
  494. ["type","=","1"],
  495. ["unit_name","=", $unit_name ],
  496. ];
  497. $entrust_unit= Db::name("department")->where($where)->value("entrust_unit");
  498. $entrust_unit_name = Db::name("department")->where("unit_name", $entrust_unit)->value("title");
  499. View::assign("entrust_unit",$entrust_unit);
  500. View::assign("entrust_unit_name",$entrust_unit_name);
  501. if (!empty($detail)) {
  502. View::assign('comment', $comment);
  503. View::assign('field', $field);
  504. View::assign('advent_time', $advent_time);
  505. View::assign('field_edit', $field_edit);
  506. View::assign('project_id', $id);
  507. View::assign('detail', $detail);
  508. View::assign("person", $person);
  509. View::assign("file_array", $file_array);
  510. View::assign('project_five', self::getProjectFive());
  511. } else {
  512. throw new \think\exception\HttpException(404, '找不到页面,请联系管理员');
  513. }
  514. return view();
  515. }
  516. }
  517. /**
  518. * 查看信息
  519. */
  520. public function read()
  521. {
  522. $param = get_params();
  523. $id = isset($param['id']) ? $param['id'] : 0;
  524. // dump($id);
  525. $detail = $this->model->getCostProjectById($id);
  526. $comment_type = isset($param["comment_type"])?$param['comment_type'] : 0;
  527. $comment = Db::name("project_comment")->where("type",$comment_type)
  528. ->where("project_id", $id)->order('create_time', 'asc')->select();
  529. $file_array = Db::name('ProjectFile')
  530. ->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')
  531. ->alias('mf')
  532. ->join('File f', 'mf.file_id = f.id', 'LEFT')
  533. ->join('Admin a', 'mf.admin_id = a.id', 'LEFT')
  534. ->order('mf.create_time desc')
  535. ->where(array('mf.topic_id' => $id, 'mf.module' => 'project'))
  536. ->select()->toArray();
  537. $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();
  538. // halt($comment);
  539. $project_log = self::project_log($id);
  540. View::assign('project_log', $project_log);
  541. // halt($project_log);
  542. // 根据用户id 查询其能显示的字段
  543. $field = $this->Field->get_field_rules_new(get_login_admin('id'));
  544. // dump($field);
  545. // halt(self::getProjectFive());
  546. if (!empty($detail)) {
  547. View::assign('project_id', $id);
  548. View::assign('comment', $comment);
  549. View::assign('field', $field);
  550. View::assign('detail', $detail);
  551. View::assign('file_array', $file_array);
  552. View::assign('report', $report);
  553. View::assign('project_five', self::getProjectFive());
  554. return view();
  555. } else {
  556. throw new \think\exception\HttpException(404, '找不到页面');
  557. }
  558. }
  559. /**
  560. * 删除
  561. * type=0,逻辑删除,默认
  562. * type=1,物理删除
  563. */
  564. public function del()
  565. {
  566. $param = get_params();
  567. $status = Db::name("cost_project")->where("id", $param["id"])->field("proprietor_status")->select();
  568. if ($status[0]["proprietor_status"] < 1) {//立项中
  569. $id = isset($param['id']) ? $param['id'] : 0;
  570. $type = isset($param['type']) ? $param['type'] : 0;
  571. add_project_log("删除项目", $id, "删除项目");
  572. $this->model->delCostProjectById($id, $type);
  573. } else {
  574. return to_assign(0, "已审核,无法删除");
  575. }
  576. }
  577. //获取客户列表
  578. public function get_customer()
  579. {
  580. $param = get_params();
  581. $where = array();
  582. if (!empty($param['keywords'])) {
  583. $where[] = ['id|title', 'like', '%' . $param['keywords'] . '%'];
  584. }
  585. $where = [
  586. ["delete_time", "=", 0],
  587. ["pid", "=", 0],
  588. ["type", "=", 2]
  589. ];
  590. $rows = empty($param['limit']) ? get_config('app.page_size') : $param['limit'];
  591. $list = $this->department->field('id,title,address,leader_id')->order('id asc')->where($where)->paginate($rows, false)
  592. ->each(function ($item) {
  593. $item->nickname = Db::name('admin')->where(['id' => $item->leader_id])->value('nickname');
  594. $item->mobile = Db::name('admin')->where(['id' => $item->leader_id])->value('mobile');
  595. });
  596. // halt($list);
  597. table_assign(0, '', $list);
  598. }
  599. //获取客户列表
  600. public function addConstructionPeople()
  601. {
  602. $param = get_params();
  603. if (request()->isAjax()) {
  604. $this->model->addConstructionPeople($param);
  605. } else {
  606. $project_id = isset($param['project_id']) ? $param['project_id'] : 0;
  607. //关联项目id
  608. View::assign('project_id', $project_id);
  609. return view();
  610. }
  611. }
  612. public function getConstructionPeople()
  613. {
  614. $param = get_params();
  615. if (request()->isAjax()) {
  616. $data = $this->model->where('id', $param["id"])->find();
  617. if ($data["construction_unit"] !== null ||
  618. $data["construction_head"] !== null ||
  619. $data["construction_email"] !== null ||
  620. $data["construction_phone"] !== null
  621. ) {
  622. return to_assign(0, "已存在!!");
  623. } else {
  624. return to_assign(200, "请上传!!");
  625. }
  626. }
  627. }
  628. public function project_user()
  629. {
  630. $param = get_params();
  631. $ids = $this->model->where("id", $param["project_id"])->field("entrust_maker,review_head,operate_head,operate_team")->find()->toArray();
  632. $idarr = $ids["operate_team"] . ',' . $ids["operate_head"] . ',' . $ids["review_head"] . ',' . $ids["entrust_maker"];
  633. $idarr = explode(",", $idarr);
  634. $rows = empty($param['limit']) ? get_config('app.page_size') : $param['limit'];
  635. $list = $this->Adminmodel->whereIn("id", $idarr)->field("id,nickname,unit_name,mobile,email")->paginate($rows, false, ['query' => $param])
  636. // 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')
  637. ->each(function ($item) {
  638. //获取单位的邮箱,单位信息页没做
  639. $item->email = Db::name('department')->where(['id' => $item->unit_name])->value('email');
  640. $type = Db::name('department')->where(['id' => $item->unit_name])->value('type');
  641. $item->unit_name = Db::name('department')->where(['id' => $item->unit_name])->value('title');
  642. // dump($type);
  643. if ($type == 0) {
  644. $item->unit_type = "委托单位";
  645. } elseif ($type == 1) {
  646. $item->unit_type = "送审单位";
  647. } elseif ($type == 2) {
  648. $item->unit_type = "评审机构";
  649. } else {
  650. $item->unit_type = "施工单位";
  651. }
  652. })->toArray();
  653. $list = $list["data"];
  654. for ($i = 0; $i < count($list); $i++) {
  655. if ($list[$i]['id'] == $ids['entrust_maker']) {
  656. // dump($list[$i]['id'],$ids['entrust_maker']);
  657. $list[$i]["type"] = 1;
  658. } elseif ($list[$i]['id'] == $ids['review_head']) {
  659. $list[$i]["type"] = 2;
  660. } elseif ($list[$i]['id'] == $ids['operate_head']) {
  661. $list[$i]["type"] = 3;
  662. } elseif (in_array($list[$i]['id'], explode(',', $ids['operate_team']))) {
  663. $list[$i]["type"] = 4;
  664. }
  665. }
  666. $type = array_column($list, 'type');
  667. array_multisort($type, SORT_ASC, $list);
  668. $shigong = $this->model->where('id', $param["project_id"])->find();
  669. if ($shigong["construction_unit"] !== null ||
  670. $shigong["construction_head"] !== null ||
  671. $shigong["construction_email"] !== null ||
  672. $shigong["construction_phone"] !== null
  673. ) {
  674. $shigongdata["id"] = time();
  675. $shigongdata["nickname"] = $shigong["construction_unit"];
  676. $shigongdata["unit_name"] = $shigong["construction_head"];
  677. $shigongdata["email"] = $shigong["construction_email"];
  678. $shigongdata["mobile"] = $shigong["construction_phone"];
  679. $shigongdata["unit_type"] = "施工单位";
  680. array_push($list, $shigongdata);
  681. }
  682. $list["data"] = $list;
  683. return table_assign(0, '', $list);
  684. }
  685. public function getProjectFive()
  686. {
  687. $where = [
  688. ['name', '=', '作业日志-业主'],
  689. ['name', '=', '工作记录-业主'],
  690. ['name', '=', '项目报告-业主'],
  691. ['name', '=', '项目人员-业主'],
  692. ['name', '=', '项目动态-业主'],
  693. ['name', '=', '项目附件-业主'],
  694. ['name', '=', '联系函-业主'],
  695. ];
  696. $list = Db::name('AdminRule')->whereOr($where)->field('id,name')->select()->toArray();
  697. $group_id = Db::name('AdminGroupAccess')->where('uid', get_login_admin('id'))->value('group_id');
  698. $login_rules = Db::name('AdminGroup')->where('id', $group_id)->value('rules');
  699. $login_rules = explode(',', $login_rules);
  700. $rules_id = array();
  701. foreach ($list as $key => $value) {
  702. if ($value['name'] == "作业日志-业主") {
  703. if (in_array($value['id'], $login_rules)) {
  704. $rules_id['project_comments'] = 1;
  705. } else {
  706. $rules_id['project_comments'] = 0;
  707. }
  708. } else if ($value['name'] == "工作记录-业主") {
  709. if (in_array($value['id'], $login_rules)) {
  710. $rules_id['project_record'] = 1;
  711. } else {
  712. $rules_id['project_record'] = 0;
  713. }
  714. } else if ($value['name'] == "项目报告-业主") {
  715. if (in_array($value['id'], $login_rules)) {
  716. $rules_id['project_report'] = 1;
  717. } else {
  718. $rules_id['project_report'] = 0;
  719. }
  720. } else if ($value['name'] == "项目人员-业主") {
  721. if (in_array($value['id'], $login_rules)) {
  722. $rules_id['project_user'] = 1;
  723. } else {
  724. $rules_id['project_user'] = 0;
  725. }
  726. } else if ($value['name'] == "项目动态-业主") {
  727. if (in_array($value['id'], $login_rules)) {
  728. $rules_id['project_log'] = 1;
  729. } else {
  730. $rules_id['project_log'] = 0;
  731. }
  732. } else if ($value['name'] == "项目附件-业主") {
  733. if (in_array($value['id'], $login_rules)) {
  734. $rules_id['project_file'] = 1;
  735. } else {
  736. $rules_id['project_file'] = 0;
  737. }
  738. } else if ($value['name'] == "联系函-业主") {
  739. if (in_array($value['id'], $login_rules)) {
  740. $rules_id['project_contact'] = 1;
  741. } else {
  742. $rules_id['project_contact'] = 0;
  743. }
  744. }
  745. }
  746. return $rules_id;
  747. }
  748. public function getemployeelist()
  749. {
  750. if (request()->isAjax()) {
  751. $data = $this->request->param();
  752. $person = Db::name("admin")->where([["unit_name", "=", $data['id']], ["status", "=", 1]])->field(["id", "nickname", "mobile"])->select();
  753. return $person;
  754. }
  755. }
  756. public function project_log($project_id)
  757. {
  758. // $project_id = 24;
  759. $login_admin = get_login_admin();
  760. $where = array();
  761. if ($login_admin['user_type'] == 2) {
  762. $where = [
  763. ['project_status', '>=', 3],
  764. ['unit_name', '=', $login_admin['unit_name']],
  765. ];
  766. } else {
  767. if ($login_admin['permission'] != 1) {
  768. $where = [
  769. ['unit_name', '=', $login_admin['unit_name']],
  770. ];
  771. }
  772. }
  773. // dump($where);
  774. $project_log = Db::name('ProjectLog')->where($where)->where('project_id', $project_id)->order('create_time', 'desc')->select()->toArray();
  775. foreach ($project_log as $key => $value) {
  776. $project_log[$key]['create_time'] = date("Y-m-d H:i:s", $value['create_time']);
  777. }
  778. // dump($project_log);
  779. // View::assign('project_log', $project_log);
  780. // return View();
  781. return $project_log;
  782. }
  783. }