Project.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\BaseController;
  4. use app\admin\model\CostProject as CostProjectModel;
  5. use think\facade\Db;
  6. use think\facade\View;
  7. use think\App;
  8. use app\admin\controller\field\Field;
  9. class Project extends BaseController
  10. {
  11. /**
  12. * 构造函数
  13. */
  14. public function __construct(App $app)
  15. {
  16. parent::__construct($app);
  17. $this->model = new CostProjectModel();
  18. $this->uid = get_login_admin('id');
  19. $this->unit = get_login_admin('unit_name');
  20. $this->Field = new Field($this->app);
  21. }
  22. public function index($project_name = '',$sent_review_unit_name = '',$entrust_unit_name = '',$project_status = '')
  23. {
  24. $where[] = ["c.delete_time","=",0];
  25. $where[] = ["c.project_status",">",1];
  26. if (!empty($project_name)) {
  27. $where[] = ['project_name', 'like', '%' . $project_name . '%'];
  28. }
  29. if (!empty($sent_review_unit_name)) {
  30. $where[] = ['sent_review_unit_name', 'like', '%' . $sent_review_unit_name . '%'];
  31. }
  32. if (!empty($entrust_unit_name)) {
  33. $where[] = ['entrust_unit_name', 'like', '%' . $entrust_unit_name . '%'];
  34. }
  35. if (!empty($project_status)) {
  36. $where[] = ['project_status', '=', $project_status];
  37. }
  38. $inarr = array();
  39. $review_unit = $this->model->where("entrust_unit", get_login_admin("unit_name"))->field('id,entrust_maker,entrust_approver')->select()->toArray();
  40. for ($i = 0; $i < count($review_unit); $i++) {
  41. $a = $review_unit[$i];
  42. $ids = $a["entrust_maker"] . ',' . $a["entrust_approver"];
  43. $ids = explode(",", $ids);
  44. $c = in_array($this->uid, $ids);
  45. if ($c) {
  46. $inarr[] = $a["id"];
  47. }
  48. }
  49. $rows = empty($param['limit']) ? get_config('app . page_size') : $param['limit'];
  50. $order = empty($param['order']) ? 'id desc' : $param['order'];
  51. $aa = Db::name('cost_project')->alias("c")->field("c.id,c.project_name,c.project_status,c.engineering_type,c.preparation_amount,c.preparation_amount,c.create_time,d.title as review_unit_name,dd.title as entrust_unit_name,a.nickname as operate_head_name,aa.nickname as review_head_name")->
  52. join("department d", "c.review_unit=d.id", "LEFT")->
  53. join("department dd", "c.entrust_unit=d.id", "LEFT")->
  54. join("admin a", "c.operate_head=a.id", "LEFT")->
  55. join("admin aa", "c.review_head=a.id", "LEFT")->
  56. where($where)->
  57. whereIn("c.id", $inarr)->select()->toArray();
  58. $field = $this->Field->get_field_rules_new($this->uid);
  59. $list = array_values(array_column($aa, NULL, 'id'));
  60. // return json($list);
  61. View::assign("detail", $list);
  62. View::assign('field', $field);
  63. return view();
  64. }
  65. public function index_company($project_name = '',$sent_review_unit_name = '',$entrust_unit_name = '',$project_status = '')
  66. {
  67. $where[] = ["c.delete_time","=",0];
  68. $where[] = ["c.project_status",">",3];
  69. if (!empty($project_name)) {
  70. $where[] = ['project_name', 'like', '%' . $project_name . '%'];
  71. }
  72. if (!empty($sent_review_unit_name)) {
  73. $where[] = ['sent_review_unit_name', 'like', '%' . $sent_review_unit_name . '%'];
  74. }
  75. if (!empty($entrust_unit_name)) {
  76. $where[] = ['entrust_unit_name', 'like', '%' . $entrust_unit_name . '%'];
  77. }
  78. if (!empty($project_status)) {
  79. $where[] = ['project_status', '=', $project_status];
  80. }
  81. //根据所登录的账号,查询跟本身有关的项目
  82. // $this->model->where()->select();
  83. $param = get_params();
  84. $inarr = array();
  85. $review_unit = $this->model->where("review_unit", get_login_admin("unit_name"))->field('id,review_head,operate_head,operate_team')->select()->toArray();
  86. for ($i = 0; $i < count($review_unit); $i++) {
  87. $a = $review_unit[$i];
  88. $ids = $a["review_head"] . ',' . $a["operate_head"] . ',' . $a["operate_team"];
  89. $ids = explode(",", $ids);
  90. $c = in_array($this->uid, $ids);
  91. if ($c) {
  92. $inarr[] = $a["id"];
  93. }
  94. }
  95. $rows = empty($param['limit']) ? get_config('app . page_size') : $param['limit'];
  96. $order = empty($param['order']) ? 'id desc' : $param['order'];
  97. $aa = Db::name('cost_project')->alias("c")->field("c.id,c.project_name,c.project_status,c.engineering_type,c.preparation_amount,c.preparation_amount,c.create_time,d.title as review_unit_name,dd.title as entrust_unit_name,a.nickname as operate_head_name,aa.nickname as review_head_name")->
  98. join("department d", "c.review_unit=d.id", "LEFT")->
  99. join("department dd", "c.entrust_unit=d.id", "LEFT")->
  100. join("admin a", "c.operate_head=a.id", "LEFT")->
  101. join("admin aa", "c.review_head=a.id", "LEFT")->
  102. where($where)->
  103. whereIn("c.id", $inarr)->select()->toArray();
  104. $list = array_values(array_column($aa, NULL, 'id'));
  105. View::assign("detail", $list);
  106. return view();
  107. }
  108. public function kan()
  109. {
  110. $param = get_params();
  111. $id = isset($param['id']) ? $param['id'] : 0;
  112. $comment = Db::name("project_comment")->where("project_id", $id)->order('create_time', 'desc')->select();
  113. $report = Db::name("project_report")->where("project_id", $id)->alias("r")->join("admin a", "r.maker_id = a.id")->field("r.*,a.nickname")->select()->toArray();
  114. $project_log = self::project_log($id);
  115. $rows = empty($param['limit']) ? get_config('app . page_size') : $param['limit'];
  116. $detail = $this->model->getCostProjectById($param['id']);
  117. $file_array = Db::name('ProjectFile')
  118. ->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')
  119. ->alias('mf')
  120. ->join('File f', 'mf.file_id = f.id', 'LEFT')
  121. ->join('Admin a', 'mf.admin_id = a.id', 'LEFT')
  122. ->order('mf.create_time desc')
  123. ->where(array('mf.topic_id' => $id, 'mf.module' => 'project'))
  124. ->select()->toArray();
  125. $field = $this->Field->get_field_rules_new($this->uid);
  126. //剩余时间
  127. $c = $detail['project_end_time']-time();
  128. if($c>0){
  129. $advent_time = floor($c / 86400)."天";
  130. }else{
  131. $c = -$c;
  132. $advent_time = floor($c / 86400)."天";
  133. }
  134. //报告进度
  135. $type_max = -1;
  136. foreach ($report as $key => $val) {
  137. $type_max = max($type_max , $val['type']);
  138. }
  139. // 创建新数组
  140. $report_time = [
  141. 0 => [
  142. "create_time" => 0,
  143. "nickname" => null
  144. ],
  145. 1 => [
  146. "create_time" => 0,
  147. "nickname" => null
  148. ],
  149. 2 => [
  150. "create_time" => 0,
  151. "nickname" => null
  152. ]
  153. ];
  154. // 遍历原始数组
  155. foreach ($report as $item) {
  156. $type = $item["type"];
  157. $create_time = $item["create_time"];
  158. $nickname = $item["nickname"];
  159. // 更新新数组中对应type的create_time和nickname
  160. if ($create_time > $report_time[$type]["create_time"]) {
  161. $report_time[$type]["create_time"] = $create_time;
  162. $report_time[$type]["nickname"] = $nickname;
  163. }
  164. }
  165. View::assign('project_id', $id);
  166. View::assign('comment', $comment);
  167. View::assign('detail', $detail);
  168. View::assign('file_array', $file_array);
  169. View::assign('report', $report);
  170. View::assign('type_max', $type_max+1);
  171. View::assign('report_time', $report_time);
  172. View::assign('project_log', $project_log);
  173. View::assign('advent_time', $advent_time);
  174. View::assign('project_five', self::getProjectFive());
  175. // halt($detail);
  176. return view();
  177. }
  178. public function kan_c()
  179. {
  180. $param = get_params();
  181. $id = isset($param['id']) ? $param['id'] : 0;
  182. //项目日志
  183. $comment = Db::name("project_comment")->where("project_id", $id)->order('create_time', 'desc')->select();
  184. //项目报告
  185. $report = Db::name("project_report")->where("project_id", $id)->alias("r")->join("admin a", "r.maker_id = a.id")->field("r.*,a.nickname")->select()->toArray();
  186. //项目动态
  187. $project_log = self::project_log($id);
  188. $rows = empty($param['limit']) ? get_config('app . page_size') : $param['limit'];
  189. //项目内容
  190. $detail = $this->model->where("id", $id)->paginate($rows, false, ['query' => $param])
  191. ->each(function ($item) {
  192. $item->entrust_unit_name = Db::name('department')->where(['id' => $item->entrust_unit])->value('title');
  193. $item->entrust_maker_name = Db::name('admin')->where(['id' => $item->entrust_maker])->value('nickname');
  194. })->toArray();
  195. $detail = $detail["data"][0];
  196. //附件
  197. $file_array = Db::name('ProjectFile')
  198. ->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')
  199. ->alias('mf')
  200. ->join('File f', 'mf.file_id = f.id', 'LEFT')
  201. ->join('Admin a', 'mf.admin_id = a.id', 'LEFT')
  202. ->order('mf.create_time desc')
  203. ->where(array('mf.topic_id' => $id, 'mf.module' => 'project'))
  204. ->select()->toArray();
  205. //剩余时间
  206. $c = $detail['project_end_time']-time();
  207. if($c>0){
  208. $advent_time = floor($c / 86400)."天";
  209. }else{
  210. $c = -$c;
  211. $advent_time = floor($c / 86400)."天";
  212. }
  213. //报告进度
  214. $type_max = -1;
  215. foreach ($report as $key => $val) {
  216. $type_max = max($type_max , $val['type']);
  217. }
  218. // 创建新数组
  219. $report_time = [
  220. 0 => [
  221. "create_time" => 0,
  222. "nickname" => null
  223. ],
  224. 1 => [
  225. "create_time" => 0,
  226. "nickname" => null
  227. ],
  228. 2 => [
  229. "create_time" => 0,
  230. "nickname" => null
  231. ]
  232. ];
  233. // 遍历原始数组
  234. foreach ($report as $item) {
  235. $type = $item["type"];
  236. $create_time = $item["create_time"];
  237. $nickname = $item["nickname"];
  238. // 更新新数组中对应type的create_time和nickname
  239. if ($create_time > $report_time[$type]["create_time"]) {
  240. $report_time[$type]["create_time"] = $create_time;
  241. $report_time[$type]["nickname"] = $nickname;
  242. }
  243. }
  244. View::assign('project_id', $id);
  245. View::assign('comment', $comment);
  246. View::assign('detail', $detail);
  247. View::assign('file_array', $file_array);
  248. View::assign('report', $report);
  249. View::assign('type_max', $type_max+1);
  250. View::assign('report_time', $report_time);
  251. View::assign('project_log', $project_log);
  252. View::assign('advent_time', $advent_time);
  253. View::assign('project_five', self::getProjectFive_company());
  254. // dump(self::getProjectFive_company());
  255. return view();
  256. }
  257. public function project_log($project_id)
  258. {
  259. // $project_id = 24;
  260. $login_admin = get_admin(get_login_admin('id'));
  261. $where = array();
  262. if ($login_admin['user_type'] == 2) {
  263. $where = [
  264. ['project_status', '>=', 3],
  265. ['unit_name', '=', $login_admin['unit_name']],
  266. ];
  267. } else {
  268. if ($login_admin['permission'] != 1) {
  269. $where = [
  270. ['unit_name', '=', $login_admin['unit_name']],
  271. ];
  272. }
  273. }
  274. // dump($where);
  275. $project_log = Db::name('ProjectLog')->where($where)->where('project_id', $project_id)->order('create_time', 'desc')->select()->toArray();
  276. foreach ($project_log as $key => $value) {
  277. $project_log[$key]['create_time'] = date("Y-m-d H:i:s", $value['create_time']);
  278. }
  279. // dump($project_log);
  280. // View::assign('project_log', $project_log);
  281. // return View();
  282. return $project_log;
  283. }
  284. public function data()
  285. {
  286. $param = get_params();
  287. $inarr = array();
  288. $review_unit = $this->model->where("entrust_unit", get_login_admin("unit_name"))->field('id,entrust_maker,entrust_approver')->select()->toArray();
  289. for ($i = 0; $i < count($review_unit); $i++) {
  290. $a = $review_unit[$i];
  291. $ids = $a["entrust_maker"] . ',' . $a["entrust_approver"];
  292. $ids = explode(",", $ids);
  293. $c = in_array($this->uid, $ids);
  294. if ($c) {
  295. $inarr[] = $a["id"];
  296. }
  297. }
  298. $rows = empty($param['limit']) ? get_config('app . page_size') : $param['limit'];
  299. $order = empty($param['order']) ? 'id desc' : $param['order'];
  300. $list = $this->model->whereIn("id", $inarr)->order($order)->paginate($rows, false, ['query' => $param])
  301. ->each(function ($item) {
  302. $item->review_unit_name = Db::name('department')->where(['id' => $item->review_unit])->value('title');
  303. $item->entrust_unit_name = Db::name('department')->where(['id' => $item->entrust_unit])->value('title');
  304. });
  305. // halt($list);
  306. return $inarr;
  307. //$inarr没去重,应该不要紧
  308. }
  309. public function getProjectFive()
  310. {
  311. $where = [
  312. ['name', '=', '作业日志-财政局'],
  313. ['name', '=', '工作记录-财政局'],
  314. ['name', '=', '项目报告-财政局'],
  315. ['name', '=', '项目人员-财政局'],
  316. ['name', '=', '项目动态-财政局'],
  317. ['name', '=', '项目附件-财政局'],
  318. ['name', '=', '联系函-财政局'],
  319. ];
  320. $list = Db::name('AdminRule')->whereOr($where)->field('id,name')->select()->toArray();
  321. $group_id = Db::name('AdminGroupAccess')->where('uid', get_login_admin('id'))->value('group_id');
  322. $login_rules = Db::name('AdminGroup')->where('id', $group_id)->value('rules');
  323. $login_rules = explode(',', $login_rules);
  324. $rules_id = array();
  325. foreach ($list as $key => $value) {
  326. if ($value['name'] == "作业日志-财政局") {
  327. if (in_array($value['id'], $login_rules)) {
  328. $rules_id['project_comments'] = 1;
  329. } else {
  330. $rules_id['project_comments'] = 0;
  331. }
  332. } else if ($value['name'] == "工作记录-财政局") {
  333. if (in_array($value['id'], $login_rules)) {
  334. $rules_id['project_record'] = 1;
  335. } else {
  336. $rules_id['project_record'] = 0;
  337. }
  338. } else if ($value['name'] == "项目报告-财政局") {
  339. if (in_array($value['id'], $login_rules)) {
  340. $rules_id['project_report'] = 1;
  341. } else {
  342. $rules_id['project_report'] = 0;
  343. }
  344. } else if ($value['name'] == "项目人员-财政局") {
  345. if (in_array($value['id'], $login_rules)) {
  346. $rules_id['project_user'] = 1;
  347. } else {
  348. $rules_id['project_user'] = 0;
  349. }
  350. } else if ($value['name'] == "项目动态-财政局") {
  351. if (in_array($value['id'], $login_rules)) {
  352. $rules_id['project_log'] = 1;
  353. } else {
  354. $rules_id['project_log'] = 0;
  355. }
  356. } else if ($value['name'] == "项目附件-财政局") {
  357. if (in_array($value['id'], $login_rules)) {
  358. $rules_id['project_file'] = 1;
  359. } else {
  360. $rules_id['project_file'] = 0;
  361. }
  362. } else if ($value['name'] == "联系函-财政局") {
  363. if (in_array($value['id'], $login_rules)) {
  364. $rules_id['project_contact'] = 1;
  365. } else {
  366. $rules_id['project_contact'] = 0;
  367. }
  368. }
  369. }
  370. return $rules_id;
  371. }
  372. public function getProjectFive_company()
  373. {
  374. $where = [
  375. ['name', '=', '作业日志-公司'],
  376. ['name', '=', '工作记录-公司'],
  377. ['name', '=', '项目报告-公司'],
  378. ['name', '=', '项目人员-公司'],
  379. ['name', '=', '项目动态-公司'],
  380. ['name', '=', '项目附件-公司'],
  381. ['name', '=', '联系函-公司'],
  382. ];
  383. $list = Db::name('AdminRule')->whereOr($where)->field('id,name')->select()->toArray();
  384. $group_id = Db::name('AdminGroupAccess')->where('uid', get_login_admin('id'))->value('group_id');
  385. $login_rules = Db::name('AdminGroup')->where('id', $group_id)->value('rules');
  386. $login_rules = explode(',', $login_rules);
  387. $rules_id = array();
  388. foreach ($list as $key => $value) {
  389. if ($value['name'] == "作业日志-公司") {
  390. if (in_array($value['id'], $login_rules)) {
  391. $rules_id['project_comments'] = 1;
  392. } else {
  393. $rules_id['project_comments'] = 0;
  394. }
  395. } else if ($value['name'] == "工作记录-公司") {
  396. if (in_array($value['id'], $login_rules)) {
  397. $rules_id['project_record'] = 1;
  398. } else {
  399. $rules_id['project_record'] = 0;
  400. }
  401. } else if ($value['name'] == "项目报告-公司") {
  402. if (in_array($value['id'], $login_rules)) {
  403. $rules_id['project_report'] = 1;
  404. } else {
  405. $rules_id['project_report'] = 0;
  406. }
  407. } else if ($value['name'] == "项目人员-公司") {
  408. if (in_array($value['id'], $login_rules)) {
  409. $rules_id['project_user'] = 1;
  410. } else {
  411. $rules_id['project_user'] = 0;
  412. }
  413. } else if ($value['name'] == "项目动态-公司") {
  414. if (in_array($value['id'], $login_rules)) {
  415. $rules_id['project_log'] = 1;
  416. } else {
  417. $rules_id['project_log'] = 0;
  418. }
  419. } else if ($value['name'] == "项目附件-公司") {
  420. if (in_array($value['id'], $login_rules)) {
  421. $rules_id['project_file'] = 1;
  422. } else {
  423. $rules_id['project_file'] = 0;
  424. }
  425. } else if ($value['name'] == "联系函-公司") {
  426. if (in_array($value['id'], $login_rules)) {
  427. $rules_id['project_contact'] = 1;
  428. } else {
  429. $rules_id['project_contact'] = 0;
  430. }
  431. }
  432. }
  433. return $rules_id;
  434. }
  435. }