CostProprietor.php 39 KB

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