CostProprietor.php 38 KB

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