Approval.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. <?php
  2. namespace app\admin\controller\project;
  3. use app\admin\BaseController;
  4. use app\admin\model\CostProject as CostProjectModel;
  5. use app\admin\model\ProjectAudit;
  6. use app\admin\validate\project\CostProjectValidate;
  7. use think\exception\ValidateException;
  8. use think\facade\Db;
  9. use think\facade\Session;
  10. use think\facade\View;
  11. use think\App;
  12. use app\admin\controller\field\Fieldcompany;
  13. use app\admin\controller\Pushmessage;
  14. class Approval extends BaseController
  15. {
  16. public function __construct(App $app)
  17. {
  18. parent::__construct($app);
  19. $this->Field = new Fieldcompany($this->app);
  20. $this->model = new CostProjectModel();
  21. $this->uid = get_login_admin('id');
  22. $this->Pushmessage = new Pushmessage();
  23. }
  24. public function datalist()
  25. {
  26. if (request()->isAjax()) {
  27. $param = get_params();
  28. $where = [
  29. ["cp_cost_project.delete_time", "=", 0],
  30. ["project_status","=",0],
  31. ["proprietor_status", "=", 2],
  32. ["entrust_unit", "=", get_login_admin('unit_name')],
  33. ];
  34. $rows = empty($param['limit']) ? get_config('app . page_size') : $param['limit'];
  35. $order = empty($param['order']) ? 'id desc' : $param['order'];
  36. $list = $this->model->where($where)
  37. ->order($order)->paginate($rows, false, ['query' => $param])
  38. ->each(function ($item) {
  39. //作业人
  40. $red = Db::name("new_msg")->where([["project_id", "=", $item->id], ["uid", "=", $this->uid]])->find();
  41. if ($red) {
  42. if ($red["detail"] || $red["comment"] || $red["report"] || $red["user"] || $red["contact"]) {
  43. $item->red = 1;
  44. }
  45. } else {
  46. $item->red = 0;
  47. }
  48. if (($item->province && $item->city && $item->area)) {
  49. $item->project_region = $item->province . '-' . $item->city . '-' . $item->area;
  50. }
  51. //作业人
  52. $operate_team_names = null;
  53. $operate_team_names_ids = explode(",", $item->operate_team);
  54. for ($i = 0; $i < count($operate_team_names_ids); $i++) {
  55. $name = Db::name("admin")->where("id", $operate_team_names_ids[$i])->value("nickname");
  56. if (!($i == 0)) {
  57. $name = "," . $name;
  58. }
  59. $operate_team_names = $operate_team_names . $name;
  60. }
  61. $item->operate_team_names = $operate_team_names;
  62. });
  63. return table_assign(0, '', $list);
  64. } else {
  65. return view();
  66. }
  67. }
  68. public function receive(){
  69. if(request()->isAjax()){
  70. $param = get_params();
  71. $id = $param["id"] ?? 0;
  72. $this->model->update(["id"=>$id,"proprietor_status"=>3,"project_status"=>1]);
  73. add_project_log('项目接收', $id, '项目接收');
  74. // $project_id = $this->model->where('id', $id)->value('project_id');
  75. // $sent_review_head = $this->model->where('id', $id)->value('sent_review_head');
  76. // $this->Pushmessage->pushMessage($project_id, [], [], (array)$sent_review_head);
  77. return to_assign(0,"操作成功");
  78. }
  79. }
  80. /**
  81. * 查看信息
  82. */
  83. public function read()
  84. {
  85. $param = get_params();
  86. $id = isset($param['id']) ? $param['id'] : 0;
  87. // dump($id);
  88. $detail = $this->model->getCostProjectById($id);
  89. $comment_type = isset($param["comment_type"])?$param['comment_type'] : 0;
  90. $comment = Db::name("project_comment")->where("type",$comment_type)
  91. ->where("project_id", $id)->order('create_time', 'asc')->select();
  92. $file_array = Db::name('ProjectFile')
  93. ->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')
  94. ->alias('mf')
  95. ->join('File f', 'mf.file_id = f.id', 'LEFT')
  96. ->join('Admin a', 'mf.admin_id = a.id', 'LEFT')
  97. ->order('mf.create_time desc')
  98. ->where(array('mf.topic_id' => $id, 'mf.module' => 'project'))
  99. ->select()->toArray();
  100. $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();
  101. $uid = Db::name("relation")->where("uuid",$id)->column("uid");
  102. $contract = Db::name("contract")->whereIn("id",$uid)
  103. ->where("subject_id",get_login_admin("unit_name"))->column("id,name,type,sign_time,sign_name");
  104. //小红点消息
  105. $red = Db::name("new_msg")->where([["uid", '=', $this->uid], ["project_id", "=", $id]])->field('detail,comment,report,user,contact')->find();
  106. if (empty($red)) {
  107. $red = ["detail" => 0, "comment" => 0, "report" => 0, "user" => 0, "contact" => 0];
  108. }
  109. //剩余时间
  110. $c = $detail['project_end_time'] - time();
  111. if ($c > 0) {
  112. $advent_time = floor($c / 86400) . "天";
  113. } else {
  114. $c = -$c;
  115. $advent_time = floor($c / 86400) . "天";
  116. }
  117. $project_log = self::project_log($id);
  118. View::assign('project_log', $project_log);
  119. // halt($project_log);
  120. // 根据用户id 查询其能显示的字段
  121. $field = $this->Field->get_field_rules_new(get_login_admin('id'));
  122. // dump($field);
  123. if (!empty($detail)) {
  124. View::assign('advent_time', $advent_time);
  125. View::assign('project_id', $id);
  126. View::assign('comment', $comment);
  127. View::assign('field', $field);
  128. View::assign('detail', $detail);
  129. View::assign('file_array', $file_array);
  130. View::assign('report', $report);
  131. View::assign('contract', $contract);
  132. View::assign('red', $red);
  133. View::assign('project_five', self::getProjectFive());
  134. // dump(self::getProjectFive());
  135. return view();
  136. } else {
  137. throw new \think\exception\HttpException(404, '找不到页面');
  138. }
  139. }
  140. public function project_log($project_id)
  141. {
  142. // $project_id = 24;
  143. $login_admin = get_admin(get_login_admin('id'));
  144. $where = array();
  145. if ($login_admin['user_type'] == 2) {
  146. $where = [
  147. ['project_status', '>=', 3],
  148. ['unit_name', '=', $login_admin['unit_name']],
  149. ];
  150. } else {
  151. if ($login_admin['permission'] != 1) {
  152. $where = [
  153. ['unit_name', '=', $login_admin['unit_name']],
  154. ];
  155. }
  156. }
  157. // dump($where);
  158. $project_log = Db::name('ProjectLog')->where($where)->where('project_id', $project_id)->order('create_time', 'desc')->select()->toArray();
  159. foreach ($project_log as $key => $value) {
  160. $project_log[$key]['create_time'] = date("Y-m-d H:i:s", $value['create_time']);
  161. }
  162. // dump($project_log);
  163. // View::assign('project_log', $project_log);
  164. // return View();
  165. return $project_log;
  166. }
  167. public function getProjectFive()
  168. {
  169. $where = [
  170. ['name', '=', '作业日志-业主'],
  171. ['name', '=', '工作记录-业主'],
  172. ['name', '=', '项目报告-业主'],
  173. ['name', '=', '项目人员-业主'],
  174. ['name', '=', '项目动态-业主'],
  175. ['name', '=', '项目附件-业主'],
  176. ['name', '=', '联系函-业主'],
  177. ];
  178. $list = Db::name('AdminRule')->whereOr($where)->field('id,name')->select()->toArray();
  179. $group_id = Db::name('AdminGroupAccess')->where('uid', get_login_admin('id'))->value('group_id');
  180. $login_rules = Db::name('AdminGroup')->where('id', $group_id)->value('rules');
  181. $login_rules = explode(',', $login_rules);
  182. $rules_id = array();
  183. foreach ($list as $key => $value) {
  184. if ($value['name'] == "作业日志-业主") {
  185. if (in_array($value['id'], $login_rules)) {
  186. $rules_id['project_comments'] = 1;
  187. } else {
  188. $rules_id['project_comments'] = 0;
  189. }
  190. } else if ($value['name'] == "工作记录-业主") {
  191. if (in_array($value['id'], $login_rules)) {
  192. $rules_id['project_record'] = 1;
  193. } else {
  194. $rules_id['project_record'] = 0;
  195. }
  196. } else if ($value['name'] == "项目报告-业主") {
  197. if (in_array($value['id'], $login_rules)) {
  198. $rules_id['project_report'] = 1;
  199. } else {
  200. $rules_id['project_report'] = 0;
  201. }
  202. } else if ($value['name'] == "项目人员-业主") {
  203. if (in_array($value['id'], $login_rules)) {
  204. $rules_id['project_user'] = 1;
  205. } else {
  206. $rules_id['project_user'] = 0;
  207. }
  208. } else if ($value['name'] == "项目动态-业主") {
  209. if (in_array($value['id'], $login_rules)) {
  210. $rules_id['project_log'] = 1;
  211. } else {
  212. $rules_id['project_log'] = 0;
  213. }
  214. } else if ($value['name'] == "项目附件-业主") {
  215. if (in_array($value['id'], $login_rules)) {
  216. $rules_id['project_file'] = 1;
  217. } else {
  218. $rules_id['project_file'] = 0;
  219. }
  220. } else if ($value['name'] == "联系函-业主") {
  221. if (in_array($value['id'], $login_rules)) {
  222. $rules_id['project_contact'] = 1;
  223. } else {
  224. $rules_id['project_contact'] = 0;
  225. }
  226. }
  227. }
  228. return $rules_id;
  229. }
  230. }