Message.php 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\BaseController;
  4. use app\admin\controller\field\Field;
  5. use think\App;
  6. use think\facade\Db;
  7. use think\facade\View;
  8. use app\admin\model\ProjectMsg;
  9. use app\admin\model\CostProject;
  10. use app\admin\model\Admin;
  11. class Message extends BaseController
  12. {
  13. public function __construct(App $app)
  14. {
  15. parent::__construct($app);
  16. $this->model = new ProjectMsg();
  17. $this->Admin = new Admin();
  18. $this->CostProject = new CostProject();
  19. $this->Field = new Field($this->app);
  20. $this->uid = get_login_admin("id");
  21. }
  22. public function index()
  23. {
  24. if (request()->isAjax()) {
  25. $param = get_params();
  26. $unread_id = $this->Admin->where("id",$this->uid)->value("unread");
  27. if(!empty($unread_ids)){
  28. $unread_ids = explode(",",$unread_id);
  29. }
  30. $list = $this->model->whereIn("m.id",$unread_ids)->alias("m")->join("cost_project c","m.project_id=c.id")->field('m.*,c.id as project_id,c.project_name,c.project_status')->order('create_time', 'desc')->select();
  31. $list2['data'] = $list;
  32. $list2["count"] = count($list);
  33. return table_assign(0, '', $list2);
  34. }else{
  35. $param = get_params();
  36. $unread_id = $this->Admin->where("id",$this->uid)->value("unread");
  37. if(empty($unread_id)){
  38. $unread_ids = [];
  39. }else{
  40. $unread_ids = explode(",",$unread_id);
  41. }
  42. $list = Db::name("ProjectMsg")->where("uid",$this->uid)->order('create_time', 'desc')->select();
  43. if (is_object($list)) {
  44. $data = $list->toArray();
  45. }
  46. $real_data = [];
  47. foreach ($data as $item => $v){
  48. if(in_array($v["id"],$unread_ids)){
  49. $v["red"] = 1;
  50. $real_data[] =$v;
  51. }else{
  52. $v["red"] = 0;
  53. $real_data[] =$v;
  54. }
  55. }
  56. View::assign("msg",$real_data);
  57. $this->Admin->where("id",$this->uid)->update(["unread"=>null]);
  58. return view();
  59. }
  60. }
  61. /**
  62. * 已读
  63. */
  64. public function read()
  65. {
  66. $param = get_params();
  67. $unread_id = $this->Admin->where("id", $this->uid)->value("unread");
  68. $unread_ids = explode(",", $unread_id);
  69. $key = array_search($param["id"], $unread_ids);
  70. unset($unread_ids[$key]);
  71. $ids_str = implode(',', $unread_ids);
  72. try {
  73. $this->Admin->where("id", $this->uid)->update(["unread" => $ids_str]);
  74. } catch (\Exception $e) {
  75. return to_assign(1, '操作失败,原因:' . $e->getMessage());
  76. }
  77. $id = isset($param['project_id']) ? $param['project_id'] : 0;
  78. $detail = $this->CostProject->getCostProjectById($id);
  79. $comment = Db::name("project_comment")->where("project_id", $id)->order('create_time', 'desc')->select();
  80. $file_array = Db::name('ProjectFile')
  81. ->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')
  82. ->alias('mf')
  83. ->join('File f', 'mf.file_id = f.id', 'LEFT')
  84. ->join('Admin a', 'mf.admin_id = a.id', 'LEFT')
  85. ->order('mf.create_time desc')
  86. ->where(array('mf.topic_id' => $id, 'mf.module' => 'project'))
  87. ->select()->toArray();
  88. $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();
  89. $project_log = self::project_log($id);
  90. View::assign('project_log', $project_log);
  91. // 根据用户id 查询其能显示的字段
  92. $field = $this->Field->get_field_rules_new(get_login_admin('id'));
  93. if (!empty($detail)) {
  94. View::assign('project_id', $id);
  95. View::assign('comment', $comment);
  96. View::assign('field', $field);
  97. View::assign('detail', $detail);
  98. View::assign('file_array', $file_array);
  99. View::assign('report', $report);
  100. View::assign('project_five', self::getProjectFive());
  101. return view();
  102. }
  103. }
  104. public function read_all(){
  105. try {
  106. $this->Admin->where("id", $this->uid)->update(["unread" => null]);
  107. } catch (\Exception $e) {
  108. return to_assign(1, '操作失败,原因:' . $e->getMessage());
  109. }
  110. return to_assign(0,"操作成功");
  111. }
  112. public function project_log($project_id)
  113. {
  114. // $project_id = 24;
  115. $login_admin = get_admin(get_login_admin('id'));
  116. $where = array();
  117. if ($login_admin['user_type'] == 2) {
  118. $where = [
  119. ['project_status', '>=', 3],
  120. ['unit_name', '=', $login_admin['unit_name']],
  121. ];
  122. } else {
  123. if ($login_admin['permission'] != 1) {
  124. $where = [
  125. ['unit_name', '=', $login_admin['unit_name']],
  126. ];
  127. }
  128. }
  129. // dump($where);
  130. $project_log = Db::name('ProjectLog')->where($where)->where('project_id', $project_id)->order('create_time', 'desc')->select()->toArray();
  131. foreach ($project_log as $key => $value) {
  132. $project_log[$key]['create_time'] = date("Y-m-d H:i:s", $value['create_time']);
  133. }
  134. // dump($project_log);
  135. // View::assign('project_log', $project_log);
  136. // return View();
  137. return $project_log;
  138. }
  139. public function getProjectFive()
  140. {
  141. $where = [
  142. ['name', '=', '作业日志-财政局'],
  143. ['name', '=', '工作记录-财政局'],
  144. ['name', '=', '项目报告-财政局'],
  145. ['name', '=', '项目人员-财政局'],
  146. ['name', '=', '项目动态-财政局'],
  147. ];
  148. $list = Db::name('AdminRule')->whereOr($where)->field('id,name')->select()->toArray();
  149. $group_id = Db::name('AdminGroupAccess')->where('uid', get_login_admin('id'))->value('group_id');
  150. $login_rules = Db::name('AdminGroup')->where('id', $group_id)->value('rules');
  151. $login_rules = explode(',', $login_rules);
  152. $rules_id = array();
  153. foreach ($list as $key => $value) {
  154. if ($value['name'] == "作业日志-财政局") {
  155. if (in_array($value['id'], $login_rules)) {
  156. $rules_id['project_comments'] = 1;
  157. } else {
  158. $rules_id['project_comments'] = 0;
  159. }
  160. } else if ($value['name'] == "工作记录-财政局") {
  161. if (in_array($value['id'], $login_rules)) {
  162. $rules_id['project_record'] = 1;
  163. } else {
  164. $rules_id['project_record'] = 0;
  165. }
  166. } else if ($value['name'] == "项目报告-财政局") {
  167. if (in_array($value['id'], $login_rules)) {
  168. $rules_id['project_report'] = 1;
  169. } else {
  170. $rules_id['project_report'] = 0;
  171. }
  172. } else if ($value['name'] == "项目人员-财政局") {
  173. if (in_array($value['id'], $login_rules)) {
  174. $rules_id['project_user'] = 1;
  175. } else {
  176. $rules_id['project_user'] = 0;
  177. }
  178. } else if ($value['name'] == "项目动态-财政局") {
  179. if (in_array($value['id'], $login_rules)) {
  180. $rules_id['project_log'] = 1;
  181. } else {
  182. $rules_id['project_log'] = 0;
  183. }
  184. }
  185. }
  186. return $rules_id;
  187. }
  188. }