MessageLogic.php 10.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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]);//
  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 = array('eq', 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, 16, 27, 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, 16, 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. }
  73. $dataCount = db('admin_message')
  74. ->alias('m')
  75. ->join('__ADMIN_USER__ user', 'user.id=m.from_user_id', 'LEFT')
  76. ->where($where)->count();
  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. 'comment_id' => $v['action_id'],
  90. 'type' => ['like', '%' . $v['controller_name' . '%']],
  91. 'user_id' => $v['from_user_id']
  92. ])
  93. ->find();
  94. if (!empty($content)) {
  95. $list[$k]['content'] = $content['content'];
  96. }
  97. } elseif (in_array($v['type'], ['12', '15'])) {
  98. $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();
  99. if ($content['content']) {
  100. $list[$k]['content'] = $content['content'];
  101. }
  102. }
  103. if ($v['type'] == 10) {
  104. $item = db('oa_event_notice')->where('id', $v['action_id'])->find();
  105. if ($item) {
  106. $noticetype = $item['noticetype'];
  107. if($item['noticetype'] == 1){
  108. $advance_time =$v['advance_time'] - ($item['number'] * 60);
  109. }elseif ($item['noticetype'] == 2){
  110. $advance_time =$v['advance_time'] - ($item['number'] * 60 * 60);
  111. }else{
  112. $advance_time = $v['advance_time'] - ($item['number'] * 60 * 60 * 24);
  113. }
  114. $time = time();
  115. if ($time == $advance_time ||$time>$advance_time) {
  116. $type['value']=$item['number'];
  117. $type['type']=$item['noticetype'];
  118. $list[$k]['content']= $type;
  119. $list[$k]['action_id'] = $item['event_id'];
  120. }
  121. }
  122. // p(222);
  123. }
  124. if (in_array($v['type'], ['17', '18', '19', '20', '27'])) {
  125. $error_file_path = db('admin_import_record')->where('id', $v['action_id'])->find();
  126. if($error_file_path['error_data_file_path']==''){
  127. $list[$k]['title'] = '';
  128. }
  129. $list[$k]['error_file_path'] = $error_file_path['error_data_file_path'];
  130. }
  131. }
  132. $data = [];
  133. $data['page']['list'] = $list;
  134. $data['page']['dataCount'] = $dataCount ?: 0;
  135. if ($param['page'] != 1 && ($param['page'] * $param['limit']) >= $dataCount) {
  136. $data['page']['firstPage'] = false;
  137. $data['page']['lastPage'] = true;
  138. } else if ($param['page'] != 1 && (int)($param['page'] * $param['limit']) < $dataCount) {
  139. $data['page']['firstPage'] = false;
  140. $data['page']['lastPage'] = false;
  141. } else if ($param['page'] == 1) {
  142. $data['page']['firstPage'] = true;
  143. $data['page']['lastPage'] = false;
  144. }
  145. return $data;
  146. }
  147. /**
  148. * 修改状态变为已读
  149. * @param $param
  150. * @return array
  151. * @throws \think\Exception
  152. * @throws \think\exception\PDOException
  153. */
  154. public function endMessage($param)
  155. {
  156. $where = [
  157. 'to_user_id' => $param['id'],
  158. 'message_id' => ['IN', (array)$param['message_id']],
  159. 'read_time' => 0,
  160. ];
  161. $list = db('admin_message')
  162. ->where($where)
  163. ->update(['read_time' => time()]);
  164. $data = [];
  165. $data['list'] = $list;
  166. return $data;
  167. }
  168. /**
  169. * 删除
  170. *
  171. * @param $messageId
  172. * @return array|int|string
  173. * @throws \think\Exception
  174. * @throws \think\exception\PDOException
  175. */
  176. public function delete($param)
  177. {
  178. $res = db('admin_message')->where(['message_id' => $param['message_id']])->find();
  179. if ($res['to_user_id'] != $param['user_id']) {
  180. return resultArray(['error' => '没有权限!']);
  181. }
  182. return db('admin_message')->where(['message_id' => $param['message_id']])->update(['is_delete' => 2]);
  183. }
  184. /**
  185. * 批量更新
  186. * @param $param
  187. * @return array
  188. * @throws \think\Exception
  189. * @throws \think\exception\PDOException
  190. */
  191. public function readAllMessage($param)
  192. {
  193. $where = [
  194. 'to_user_id' => $param['user_id'],
  195. 'read_time' => 0
  196. ];
  197. if ($param['label'] == 4) {
  198. $list = db('admin_message')
  199. ->where('type', 9)
  200. ->where($where)
  201. ->update(['read_time' => time()]);
  202. } else {
  203. $where['type'] = $this->label($param['label']);
  204. $list = db('admin_message')
  205. ->where($where)
  206. ->update(['read_time' => time()]);
  207. }
  208. $data = [];
  209. $data['list'] = $list;
  210. return $data;
  211. }
  212. /**
  213. * 批量删除已读
  214. * @param $param
  215. * @return array
  216. * @throws \think\Exception
  217. * @throws \think\exception\PDOException
  218. */
  219. public function clear($param)
  220. {
  221. $where = [];
  222. $where = [
  223. 'to_user_id' => $param['user_id'],
  224. 'is_delete' => 1,
  225. 'read_time' => ['neq', 0],
  226. ];
  227. $where['type'] = $this->label($param['label']);
  228. $list = db('admin_message')
  229. ->where($where)
  230. ->update(['is_delete' => 2]);
  231. $data = [];
  232. $data['list'] = $list;
  233. return $data;
  234. }
  235. public function unreadCount($param)
  236. {
  237. $userId = $param['user_id'];
  238. //types 1表示已读 0表示未读
  239. $where['read_time'] = ['=', 0];
  240. $label = '';
  241. $where['to_user_id'] = ['eq', $userId];
  242. $where['is_delete'] = ['eq', 1];
  243. $where['type'] = $this->label('');
  244. $allCount = db('admin_message')->where($where)->count();
  245. $where['type'] = $this->label(1);
  246. $taskCount = db('admin_message')->where($where)->count();
  247. $where['type'] = $this->label(2);
  248. $logCount = db('admin_message')->where($where)->count();
  249. $where['type'] = $this->label(3);
  250. $jxcCount = db('admin_message')->where($where)->count();
  251. $where['type'] = 9;
  252. $announceCount = db('admin_message')->where($where)->count();
  253. $where['type'] = $this->label(5);
  254. $eventCount = db('admin_message')->where($where)->where('advance_time', '>=', time())->count();
  255. $where['type'] = $this->label(6);
  256. $crmCount = db('admin_message')->where($where)->count();
  257. $data = [];
  258. $data['allCount'] = $allCount ?: 0;
  259. $data['taskCount'] = $taskCount ?: 0;
  260. $data['logCount'] = $logCount ?: 0;
  261. $data['examineCount'] = $jxcCount ?: 0;
  262. $data['announceCount'] = $announceCount ?: 0;
  263. $data['eventCount'] = $eventCount ?: 0;
  264. $data['crmCount'] = $crmCount ?: 0;
  265. return $data;
  266. }
  267. }