MessageLogic.php 9.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. <?php
  2. namespace app\admin\logic;
  3. use think\Db;
  4. class MessageLogic
  5. {
  6. private function label($label)
  7. {
  8. $where = '';
  9. switch ($label) {
  10. case '1': //任务
  11. $where = array('in', [1, 2, 3,27]);//
  12. break;
  13. case '2': //日志
  14. $where = array('in', [4, 5]);//27项目导入
  15. break;
  16. case '3': //办公审批
  17. $where = array('in', [6, 7, 8]);
  18. break;
  19. case '4': //公告
  20. $where = 9;
  21. break;
  22. case '5' : //日程
  23. $where = 10;
  24. break;
  25. case '6' : //客户管理
  26. $where = array('in', [11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 28, 29, 30]);
  27. break;
  28. case '4' :
  29. break;
  30. default:
  31. $where = array('in', [1, 2, 3, 4, 5, 6, 7, 8, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]);//17181920
  32. }
  33. return $where;
  34. }
  35. public function getDataList($param)
  36. {
  37. $userId = $param['user_id'];
  38. unset($param['user_id']);
  39. //types 1表示已读 0表示未读
  40. if (isset($param['is_read'])) {
  41. $where['m.read_time'] = 0;
  42. }
  43. $where['m.to_user_id'] = $userId;
  44. $where['m.is_delete'] = ['eq', 1];
  45. $order = [
  46. 'm.send_time' => 'DESC',
  47. ];
  48. $where['m.type'] = $this->label($param['label']);
  49. if ($param['label'] == 4) {
  50. $where['m.type'] = 9;
  51. $list = db('admin_message')
  52. ->alias('m')
  53. ->join('__ADMIN_USER__ user', 'user.id=m.from_user_id', 'LEFT')
  54. ->where($where)
  55. ->field('m.*,user.realname as user_name')
  56. ->page($param['page'], $param['limit'])
  57. ->order($order)
  58. ->select();
  59. $dataCount = db('admin_message')
  60. ->alias('m')
  61. ->join('__ADMIN_USER__ user', 'user.id=m.from_user_id', 'LEFT')
  62. ->where($where)->count();
  63. } else {
  64. $list = db('admin_message')
  65. ->alias('m')
  66. ->join('__ADMIN_USER__ user', 'user.id=m.from_user_id', 'LEFT')
  67. ->where($where)
  68. ->field('m.*,user.realname as user_name')
  69. ->page($param['page'], $param['limit'])
  70. ->order($order)
  71. ->select();
  72. $dataCount = db('admin_message')
  73. ->alias('m')
  74. ->join('__ADMIN_USER__ user', 'user.id=m.from_user_id', 'LEFT')
  75. ->where($where)->count();
  76. }
  77. //1表示已读 0表示未读
  78. foreach ($list as $k => $v) {
  79. if ($v['read_time'] == 0) {
  80. $list[$k]['is_read'] = 0;
  81. } else {
  82. $list[$k]['is_read'] = 1;
  83. }
  84. $list[$k]['create_time'] = date('Y-m-d H:i:s', $v['send_time']);
  85. if ($v['type'] == 4) {
  86. $content = db('admin_comment')
  87. ->where(
  88. ['status' => 1,
  89. 'type_id' => $v['action_id'],
  90. 'type' => ['like', '%' . $v['controller_name' . '%']],
  91. 'user_id' => $v['from_user_id']
  92. ])
  93. ->select();
  94. $list[$k]['content'] = $content[$k]['content'];
  95. } elseif (in_array($v['type'], [7,12, 15,25])) {
  96. $content = db('admin_examine_record')->where(['types_id' => $v['action_id'], 'types' => ['like', '%' . $v['controller_name'] . '%'], 'check_user_id' => $v['from_user_id']])->field('content')->find();
  97. if ($content['content']) {
  98. $list[$k]['content'] = $content['content'];
  99. }
  100. }
  101. if ($v['type'] == 10 && $v['advance_time'] < time()) {
  102. $item = db('oa_event_notice')->where('id', $v['action_id'])->find();
  103. if ($item) {
  104. $type['value'] = $item['number'];
  105. $type['type'] = $item['noticetype'];
  106. $list[$k]['content'] = $type;
  107. $list[$k]['action_id'] = $item['event_id'];
  108. }
  109. } elseif($v['type'] == 10 && $v['advance_time'] > time()) {
  110. unset($list[$k]);
  111. }
  112. $time=time();
  113. if (in_array($v['type'], ['17', '18', '19', '20', '27'])) {
  114. $error_file_path = db('admin_import_record')->where('id', $v['action_id'])->find();
  115. $week = strtotime("+7 day", $error_file_path['create_time']);
  116. if ($time > (int)$week && $error_file_path['error_data_file_path'] != '') {
  117. $list[$k]['valid'] = 0;
  118. } else {
  119. $list[$k]['valid'] = 1;
  120. }
  121. $list[$k]['error_file_path'] = $error_file_path['error_data_file_path'];
  122. }
  123. }
  124. $data = [];
  125. $data['page']['list'] = array_values($list);
  126. $data['page']['dataCount'] = $dataCount ?: 0;
  127. if ($param['page'] != 1 && ($param['page'] * $param['limit']) >= $dataCount) {
  128. $data['page']['firstPage'] = false;
  129. $data['page']['lastPage'] = true;
  130. } else if ($param['page'] != 1 && (int)($param['page'] * $param['limit']) < $dataCount) {
  131. $data['page']['firstPage'] = false;
  132. $data['page']['lastPage'] = false;
  133. } else if ($param['page'] == 1) {
  134. $data['page']['firstPage'] = true;
  135. $data['page']['lastPage'] = false;
  136. }
  137. return $data;
  138. }
  139. /**
  140. * 修改状态变为已读
  141. * @param $param
  142. * @return array
  143. * @throws \think\Exception
  144. * @throws \think\exception\PDOException
  145. */
  146. public function endMessage($param)
  147. {
  148. $where = [
  149. 'to_user_id' => $param['id'],
  150. 'message_id' => ['IN', (array)$param['message_id']],
  151. 'read_time' => 0,
  152. ];
  153. $list = db('admin_message')
  154. ->where($where)
  155. ->update(['read_time' => time()]);
  156. $data = [];
  157. $data['list'] = $list;
  158. return $data;
  159. }
  160. /**
  161. * 删除
  162. *
  163. * @param $messageId
  164. * @return array|int|string
  165. * @throws \think\Exception
  166. * @throws \think\exception\PDOException
  167. */
  168. public function delete($param)
  169. {
  170. $res = db('admin_message')->where(['message_id' => $param['message_id']])->find();
  171. if ($res['to_user_id'] != $param['user_id']) {
  172. return resultArray(['error' => '没有权限!']);
  173. }
  174. return db('admin_message')->where(['message_id' => $param['message_id']])->update(['is_delete' => 2]);
  175. }
  176. /**
  177. * 批量更新
  178. * @param $param
  179. * @return array
  180. * @throws \think\Exception
  181. * @throws \think\exception\PDOException
  182. */
  183. public function readAllMessage($param)
  184. {
  185. $where = [
  186. 'to_user_id' => $param['user_id'],
  187. 'read_time' => 0
  188. ];
  189. if ($param['label'] == 4) {
  190. $list = db('admin_message')
  191. ->where('type', 9)
  192. ->where($where)
  193. ->update(['read_time' => time()]);
  194. } else {
  195. $where['type'] = $this->label($param['label']);
  196. $list = db('admin_message')
  197. ->where($where)
  198. ->update(['read_time' => time()]);
  199. }
  200. $data = [];
  201. $data['list'] = $list;
  202. return $data;
  203. }
  204. /**
  205. * 批量删除已读
  206. * @param $param
  207. * @return array
  208. * @throws \think\Exception
  209. * @throws \think\exception\PDOException
  210. */
  211. public function clear($param)
  212. {
  213. $where = [];
  214. $where = [
  215. 'to_user_id' => $param['user_id'],
  216. 'is_delete' => 1,
  217. 'read_time' => ['neq', 0],
  218. ];
  219. $where['type'] = $this->label($param['label']);
  220. $list = db('admin_message')
  221. ->where($where)
  222. ->update(['is_delete' => 2]);
  223. $data = [];
  224. $data['list'] = $list;
  225. return $data;
  226. }
  227. public function unreadCount($param)
  228. {
  229. $userId = $param['user_id'];
  230. //types 1表示已读 0表示未读
  231. $where['read_time'] = ['=', 0];
  232. $label = '';
  233. $where['to_user_id'] = ['eq', $userId];
  234. $where['is_delete'] = ['eq', 1];
  235. $where['type'] = $this->label('');
  236. $allCount = db('admin_message')->where($where)->count();
  237. $where['type'] = $this->label(1);
  238. $taskCount = db('admin_message')->where($where)->count();
  239. $where['type'] = $this->label(2);
  240. $logCount = db('admin_message')->where($where)->count();
  241. $where['type'] = $this->label(3);
  242. $jxcCount = db('admin_message')->where($where)->count();
  243. $where['type'] = 9;
  244. $announceCount = db('admin_message')->where($where)->count();
  245. $where['type'] = $this->label(5);
  246. $eventCount = db('admin_message')->where($where)->where(['advance_time'=>['<', time()],'advance_time'=>['<>',0]])->count();
  247. $where['type'] = $this->label(6);
  248. $crmCount = db('admin_message')->where($where)->count();
  249. $data = [];
  250. $data['allCount'] = $allCount ?: 0;
  251. $data['taskCount'] = $taskCount ?: 0;
  252. $data['logCount'] = $logCount ?: 0;
  253. $data['examineCount'] = $jxcCount ?: 0;
  254. $data['announceCount'] = $announceCount ?: 0;
  255. $data['eventCount'] = $eventCount ?: 0;
  256. $data['crmCount'] = $crmCount ?: 0;
  257. return $data;
  258. }
  259. }