MessageService.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2017~2021 LARAVEL研发中心
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://www.laravel.cn
  8. // +----------------------------------------------------------------------
  9. // | Author: laravel开发员 <laravel.qq.com>
  10. // +----------------------------------------------------------------------
  11. namespace App\Services\Api;
  12. use App\Models\ImChatModel;
  13. use App\Models\MerchantModel;
  14. use App\Models\MessageModel;
  15. use App\Services\BaseService;
  16. use App\Services\ConfigService;
  17. use App\Services\RedisService;
  18. /**
  19. * 站内消息服务管理-服务类
  20. * @author laravel开发员
  21. * @since 2020/11/11
  22. * Class MessageService
  23. * @package App\Services\Api
  24. */
  25. class MessageService extends BaseService
  26. {
  27. // 静态对象
  28. protected static $instance = null;
  29. /**
  30. * 构造函数
  31. * @author laravel开发员
  32. * @since 2020/11/11
  33. * MessageService constructor.
  34. */
  35. public function __construct()
  36. {
  37. $this->model = new MessageModel();
  38. }
  39. /**
  40. * 静态入口
  41. * @return static|null
  42. */
  43. public static function make()
  44. {
  45. if (!self::$instance) {
  46. self::$instance = (new static());
  47. }
  48. return self::$instance;
  49. }
  50. /**
  51. * 消息列表
  52. * @param $userId
  53. * @param $params
  54. * @param int $pageSize
  55. * @return array
  56. */
  57. public function getDataList($userId, $params, $pageSize = 0)
  58. {
  59. $page = request()->post('page', 1);
  60. $cacheKey = "caches:messages:history_{$page}_" . md5($userId . json_encode($params) . $pageSize);
  61. $datas = RedisService::get($cacheKey);
  62. if ($datas) {
  63. return $datas;
  64. }
  65. $where = ['a.status' => 1, 'a.mark' => 1];
  66. $field = ['a.id', 'a.title', 'a.type', 'a.msg_type', 'a.chat_type', 'a.description', 'a.content', 'a.from_user_name', 'a.from_user_avatar', 'a.from_uid', 'a.to_user_name', 'a.to_user_avatar', 'a.to_uid', 'a.create_time', 'a.is_read', 'a.pages', 'a.status'];
  67. $datas = $this->model->from('message as a')
  68. ->leftJoin('member as b', 'b.id', '=', 'a.from_uid')
  69. ->leftJoin('member as c', 'c.id', '=', 'a.to_uid')
  70. ->where($where)
  71. ->where(function ($query) use ($params, $userId) {
  72. $fromUid = isset($params['from_uid']) ? intval($params['from_uid']) : 0;
  73. if ($fromUid) {
  74. $query->where('a.from_uid', $fromUid);
  75. }
  76. $type = isset($params['type']) ? intval($params['type']) : 0;
  77. if ($type) {
  78. $query->where('a.type', $type);
  79. }
  80. if ($type != 9) {
  81. $query->where('a.to_uid', $userId);
  82. }else {
  83. $query->where(function ($query) use ($userId) {
  84. $query->where(function($query) use($userId){
  85. $query->where(['a.from_uid' => $userId,'a.from_show'=>1]);
  86. })->orWhere(function($query) use($userId){
  87. $query->where(['a.to_uid' => $userId,'a.to_show'=>1]);
  88. });
  89. });
  90. }
  91. $chatType = isset($params['chat_type']) ? intval($params['chat_type']) : 0;
  92. if ($chatType) {
  93. $query->where('a.chat_type', $chatType);
  94. }
  95. $chatKey = isset($params['chat_key']) ? trim($params['chat_key']) : '';
  96. if ($chatKey) {
  97. $query->where('a.chat_key', $chatKey);
  98. }
  99. })->select($field)
  100. ->orderBy('a.create_time', 'desc')
  101. ->orderBy('a.id', 'desc')
  102. ->paginate($pageSize > 0 ? $pageSize : 9999999);
  103. $datas = $datas ? $datas->toArray() : [];
  104. if ($datas) {
  105. $ids = [];
  106. foreach ($datas['data'] as &$item) {
  107. // 已读
  108. if($item['to_uid'] == $userId){
  109. $ids[] = $item['id'];
  110. }
  111. $item['time_text'] = isset($item['create_time']) && $item['create_time'] ? dateForWeek($item['create_time']) : '';
  112. $item['content'] = $item['msg_type'] == 2 ? get_images_preview(json_decode($item['content'], true), '') : $item['content'];
  113. $item['from_user_avatar'] = $item['from_user_avatar'] ? get_image_url($item['from_user_avatar']) : get_image_url('/images/member/logo.png');
  114. $item['to_user_avatar'] = $item['to_user_avatar'] ? get_image_url($item['to_user_avatar']) : get_image_url('/images/member/logo.png');
  115. }
  116. unset($item);
  117. // 更新已读
  118. if ($ids) {
  119. $this->model->whereIn('id', $ids)->update(['is_read' => 1, 'update_time' => time()]);
  120. }
  121. arsort($datas['data'], true);
  122. $datas['data'] = array_reverse($datas['data'], false);
  123. RedisService::set($cacheKey, $datas, rand(3, 5));
  124. }
  125. return [
  126. 'list' => isset($datas['data']) ? $datas['data'] : [],
  127. 'total' => isset($datas['total']) ? $datas['total'] : 0,
  128. 'pageSize' => $pageSize
  129. ];
  130. }
  131. /**
  132. * 获取站内消息窗口列表
  133. * @param $userId
  134. * @return array|mixed
  135. */
  136. public function getGroupList($userId, $cache = false)
  137. {
  138. $cachekey = "caches:message:topList_{$userId}";
  139. $datas = RedisService::get($cachekey);
  140. if ($datas && $cache) {
  141. $datas['cache'] = true;
  142. return $datas;
  143. }
  144. $types = [1, 4, 5];
  145. $setting = MemberSettingService::make()->getSetting($userId);
  146. $pushStatus = false;
  147. if ($setting) {
  148. foreach ($setting as $k => $v) {
  149. if ($v == 1) {
  150. if ($k == 'receive_app') {
  151. $pushStatus = true;
  152. } else if ($k == 'receive_order') {
  153. $types[] = 2;
  154. } else if ($k == 'receive_account') {
  155. $types[] = 3;
  156. }
  157. }
  158. }
  159. asort($types);
  160. } else {
  161. $pushStatus = true;
  162. $types = [1, 2, 3, 4, 5];
  163. }
  164. // 关闭系统APP消息
  165. if (!$pushStatus) {
  166. return ['list' => [], 'total' => 0, 'types' => []];
  167. }
  168. $field = ['title', 'type', 'to_uid', 'description', 'is_read', 'create_time'];
  169. $datas = $this->model->where(['to_uid' => $userId, 'status' => 1, 'mark' => 1])
  170. ->whereIn('type', $types)
  171. ->groupBy('type')
  172. ->orderBy('type', 'asc')
  173. ->orderBy('is_read', 'desc')
  174. ->orderBy('create_time', 'desc')
  175. ->select($field)
  176. ->get();
  177. $datas = $datas ? $datas->toArray() : [];
  178. $total = 0;
  179. if ($datas) {
  180. $titles = [1 => '公告通知', 2 => '订单通知', 3 => '账户通知', 4 => '客服通知', 5 => '互动消息'];
  181. foreach ($datas as &$item) {
  182. $item['title'] = isset($titles[$item['type']]) ? $titles[$item['type']] : '消息通知';
  183. $data = $this->getNewMessage($item['type'], 0, $userId);
  184. $item['description'] = isset($data['description']) && $data['description'] ? $data['description'] : (isset($data['content']) ? mb_substr($data['content'], 0, 56, 'utf-8') . '...' : lang('有新消息'));
  185. $item['create_time'] = isset($data['create_time']) && $data['create_time'] ? $data['create_time'] : '';
  186. $item['time_text'] = isset($item['create_time']) && $item['create_time'] ? dateFormat($item['create_time']) : '';
  187. $item['create_time'] = isset($item['create_time']) ? datetime($item['create_time'], 'Y-m-d H.i.s') : '';
  188. $unread = $this->getUnreadCount($userId, 0, $item['type']);
  189. $item['unread'] = intval($unread);
  190. $total += intval($unread);
  191. }
  192. RedisService::set($cachekey, ['list' => $datas, 'total' => $total, 'types' => $types], rand(2, 3));
  193. }
  194. return ['list' => $datas, 'total' => $total, 'types' => $types];
  195. }
  196. /**
  197. * 聊天分组消息
  198. * @param $userId
  199. * @param $params
  200. * @param int $pageSize
  201. * @return array
  202. */
  203. public function getDataListFromatKey($userId, $params, $pageSize = 0)
  204. {
  205. $page = request()->post('page', 1);
  206. $cacheKey = "caches:m_chat:{$page}_" . md5($userId . json_encode($params) . $pageSize);
  207. $datas = RedisService::get($cacheKey);
  208. $data = isset($datas['data']) ? $datas['data'] : [];
  209. if ($datas && $data) {
  210. return [
  211. 'unread' => isset($datas['unReadCount']) ? $datas['unReadCount'] : 0,
  212. 'total' => isset($datas['total']) ? $datas['total'] : 0,
  213. 'list' => $data,
  214. 'pageSize' => $pageSize,
  215. 'cache' => true,
  216. ];
  217. }
  218. // 不接收则不显示聊天消息
  219. $receiveCustom = MemberSettingService::make()->getSetting($userId, 'receive_custom', 1);
  220. if ($receiveCustom != 1) {
  221. return [
  222. 'unread' => 0,
  223. 'total' => 0,
  224. 'list' => [],
  225. 'pageSize' => $pageSize,
  226. 'close' => true,
  227. ];
  228. }
  229. $where = ['a.type' => 9, 'a.status' => 1, 'a.mark' => 1];
  230. $expire = ConfigService::make()->getConfigByCode('chat_log_expire');
  231. $expire = $expire ? $expire * 86400 : 60 * 86400;
  232. $field = ['a.id', 'a.title', 'a.type', 'a.msg_type','a.to_show', 'a.chat_key', 'a.chat_type', 'a.description', 'a.content', 'a.from_user_name', 'a.from_user_avatar', 'a.from_uid', 'a.to_user_name', 'a.to_user_avatar', 'a.to_uid', 'a.create_time', 'a.is_read', 'a.status'];
  233. $datas = $this->model->from('message as a')
  234. ->where($where)
  235. ->where('a.chat_key', '>', 0)
  236. ->where('a.create_time', '>=', time() - $expire)
  237. ->where(function ($query) use ($params, $userId) {
  238. $chatKey = isset($params['chat_key']) ? trim($params['chat_key']) : '';
  239. if ($chatKey) {
  240. $query->where('a.chat_key', $chatKey);
  241. }
  242. $isRead = isset($params['is_read']) ? intval($params['is_read']) : 0;
  243. if ($isRead) {
  244. $query->where('a.is_read', $isRead);
  245. }
  246. $chatType = isset($params['chat_type']) ? intval($params['chat_type']) : 0;
  247. if ($chatType) {
  248. $query->where('a.chat_type', $chatType);
  249. }
  250. if ($userId) {
  251. $query->where(function ($query) use ($userId) {
  252. $query->where(function($query) use($userId){
  253. $query->where(['a.from_uid' => $userId,'a.from_show'=>1]);
  254. })->orWhere(function($query) use($userId){
  255. $query->where(['a.to_uid' => $userId,'a.to_show'=>1]);
  256. });
  257. });
  258. }
  259. })
  260. ->select($field)
  261. ->groupBy('chat_key')
  262. ->orderBy('a.create_time', 'desc')
  263. ->orderBy('a.id', 'desc')
  264. ->paginate($pageSize > 0 ? $pageSize : 9999999);
  265. $datas = $datas ? $datas->toArray() : [];
  266. $unReadCount = 0;
  267. if ($datas) {
  268. foreach ($datas['data'] as &$item) {
  269. $item['from_user_avatar'] = isset($item['from_user_avatar']) && $item['from_user_avatar'] ? get_image_url($item['from_user_avatar']) : get_image_url('/images/member/logo.png');
  270. $item['to_user_avatar'] = isset($item['to_user_avatar']) && $item['to_user_avatar'] ? get_image_url($item['to_user_avatar']) : get_image_url('/images/member/logo.png');
  271. $data = $this->getNewMessage(0, $item['chat_key']);
  272. $item['description'] = isset($data['description']) && $data['description'] ? $data['description'] : (isset($data['content']) ? mb_substr($data['content'], 0, 30, 'utf-8') : lang('有新消息'));
  273. $item['create_time'] = isset($data['create_time']) && $data['create_time'] ? $data['create_time'] : '';
  274. $item['time_text'] = isset($item['create_time']) && $item['create_time'] ? dateFormat($item['create_time']) : '';
  275. $item['create_time'] = isset($item['create_time']) ? datetime($item['create_time'], 'Y-m-d H.i.s') : '';
  276. $item['unread'] = $this->getUnreadCount($userId, $item['chat_key'], 0);
  277. if ($item['from_uid'] == $userId) {
  278. $item['from_user_name'] = $item['to_user_name'];
  279. $item['from_user_avatar'] = $item['to_user_avatar'];
  280. $item['tuid'] = $item['to_uid'];
  281. } else {
  282. $item['tuid'] = $item['from_uid'];
  283. }
  284. $unReadCount += intval($item['unread']);
  285. }
  286. unset($item);
  287. $datas['unReadCount'] = $unReadCount;
  288. RedisService::set($cacheKey, $datas, rand(3, 5));
  289. }
  290. return [
  291. 'unread' => $unReadCount,
  292. 'total' => isset($datas['total']) ? $datas['total'] : 0,
  293. 'list' => isset($datas['data']) ? $datas['data'] : [],
  294. 'pageSize' => $pageSize,
  295. 'cache' => false,
  296. ];
  297. }
  298. /**
  299. * 获取最新消息
  300. * @param $chatKey
  301. * @return mixed
  302. */
  303. public function getNewMessage($type = 0, $chatKey = 0, $userId = 0)
  304. {
  305. $cacheKey = "caches:messages:new_{$type}_{$chatKey}_{$userId}";
  306. $data = RedisService::get($cacheKey);
  307. if ($data) {
  308. return $data;
  309. }
  310. $where = ['status' => 1, 'mark' => 1];
  311. if ($type) {
  312. $where['type'] = $type;
  313. }
  314. if ($chatKey) {
  315. $where['chat_key'] = $chatKey;
  316. }
  317. if ($userId) {
  318. $where['to_uid'] = $userId;
  319. }
  320. $data = $this->model->where($where)->select('id', 'title', 'description', 'msg_type', 'content', 'create_time')
  321. ->orderBy('create_time', 'desc')
  322. ->orderBy('id', 'desc')
  323. ->first();
  324. $data = $data ? $data->toArray() : [];
  325. if ($data) {
  326. if ($data['msg_type'] == 2) {
  327. $data['description'] = '[图片]';
  328. } else if ($data['msg_type'] == 3) {
  329. $data['description'] = '[视频聊天]';
  330. } else if ($data['msg_type'] == 4) {
  331. $data['description'] = '[直播间分享]';
  332. }
  333. RedisService::set($cacheKey, $data, rand(3, 5));
  334. }
  335. return $data;
  336. }
  337. /**
  338. * 获取未读消息数量
  339. * @param $userId
  340. * @return array|mixed
  341. */
  342. public function getBarCount($userId, $type = 0)
  343. {
  344. $cacheKey = "caches:barCount:{$userId}_{$type}";
  345. $data = RedisService::get($cacheKey);
  346. if ($data) {
  347. return $data;
  348. }
  349. $data = $this->getUnreadCount($userId, 0, $type);
  350. RedisService::set($cacheKey, $data, rand(3, 5));
  351. return $data;
  352. }
  353. /**
  354. * 推送站内消息
  355. * @param $userId 用户ID
  356. * @param $title 标题
  357. * @param $message 消息内容
  358. * @param int $type 类型:1-公告,2-订单,3-账户,4-客服,5-动态
  359. * @return false
  360. */
  361. public function pushMessage($userId, $title, $message, $type = 1, $fromUid = 0)
  362. {
  363. $types = [4, 5];
  364. $pushStatus = false;
  365. $datas = MemberSettingService::make()->getSetting($userId);
  366. if ($datas) {
  367. foreach ($datas as $k => $v) {
  368. if ($v == 1) {
  369. if ($k == 'receive_app') {
  370. $pushStatus = true;
  371. $types[] = 1;
  372. } else if ($k == 'receive_order') {
  373. $types[] = 2;
  374. } else if ($k == 'receive_account') {
  375. $types[] = 3;
  376. }
  377. }
  378. }
  379. } else {
  380. $pushStatus = true;
  381. $types = [1, 2, 3, 4, 5];
  382. }
  383. if ($userId && $pushStatus && in_array($type, $types)) {
  384. $appName = ConfigService::make()->getConfigByCode('app_name', '星链社交');
  385. $log = [
  386. 'from_uid' => $fromUid,
  387. 'to_uid' => $userId,
  388. 'from_user_name' => $appName,
  389. 'chat_type' => 0,
  390. 'msg_type' => 1,
  391. 'type' => $type,
  392. 'title' => $title,
  393. 'description' => $title,
  394. 'content' => $message,
  395. 'chat_key' => "0{$userId}",
  396. 'create_time' => time(),
  397. 'status' => 1,
  398. 'mark' => 1,
  399. ];
  400. return MessageModel::insert($log);
  401. }
  402. return false;
  403. }
  404. /**
  405. * 获取
  406. * @param $userId
  407. * @return array|mixed
  408. */
  409. public function getUnreadCount($userId, $chatKey = 0, $type = 0)
  410. {
  411. $cacheKey = "caches:messages:un_{$userId}_{$chatKey}_{$type}";
  412. $data = RedisService::get($cacheKey);
  413. if (RedisService::exists($cacheKey)) {
  414. return $data;
  415. }
  416. $where = ['to_uid' => $userId,'to_show'=>1, 'status' => 1, 'is_read' => 2, 'mark' => 1];
  417. if ($type > 0) {
  418. $where['type'] = $type;
  419. }
  420. if ($chatKey) {
  421. $where['chat_key'] = $chatKey;
  422. }
  423. $data = $this->model->where($where)->count('id');
  424. RedisService::set($cacheKey, $data, rand(3, 5));
  425. return $data;
  426. }
  427. /**
  428. * 验证发送消息或者内容是否有屏蔽词
  429. * @param $message 消息或内容
  430. * @param $type 是否返回屏蔽后内容:1-是
  431. * @return bool
  432. */
  433. public function filterMessage($message, $type = 1)
  434. {
  435. $filter = ConfigService::make()->getConfigByCode('chat_sensitive');
  436. $filter = !empty($filter) ? explode('、', $filter) : [];
  437. $filter = array_filter($filter);
  438. if ($filter) {
  439. if ($type != 2) {
  440. foreach ($filter as $kw) {
  441. $message = preg_replace("/{$kw}/", '***', $message);
  442. }
  443. } else {
  444. foreach ($filter as $kw) {
  445. if (preg_match("/{$kw}/", $message)) {
  446. return false;
  447. }
  448. }
  449. }
  450. // 手机号、邮箱、网址
  451. if ($type == 1) {
  452. $message = preg_replace("/^(1[3-9][0-9]{9})$/", '***', $message);
  453. $message = preg_replace("/([a-z0-9&\-_.]+@[\w\-_]+([\w\-.]+)?\.[\w\-]+)/is", '***', $message);
  454. $message = str_replace(['https:', 'http:', '.com', '.cn', '.net', '.top', 'www.'], '***', $message);
  455. $message = preg_replace("/([a-zA-Z0-9][a-zA-Z0-9\_]{6,20})/", '***', $message);
  456. $message = preg_replace("/\*{3}\*{1,}/", '***', $message);
  457. }
  458. }
  459. return $type == 3 && $message === '***' ? '' : $message;
  460. }
  461. /**
  462. * 已读
  463. * @param $userId 用户ID
  464. * @param $chatKey 聊天窗口ID
  465. * @return bool
  466. */
  467. public function setRead($userId, $type = 0, $chatKey = '')
  468. {
  469. $where = ['to_uid' => $userId];
  470. if ($type) {
  471. $where['type'] = $type;
  472. }
  473. if ($chatKey) {
  474. $where['chat_key'] = $chatKey;
  475. }
  476. $this->model->where($where)->update(['is_read' => 1, 'update_time' => time()]);
  477. // 清除缓存
  478. RedisService::keyDel("caches:messages:bar*");
  479. RedisService::keyDel("caches:messages:new_*");
  480. RedisService::keyDel("caches:messages:un_*");
  481. RedisService::keyDel("caches:messages:topList_{$userId}");
  482. return true;
  483. }
  484. /**
  485. * 隐藏
  486. * @param $userId
  487. * @param int $expire
  488. * @return mixed
  489. */
  490. public function setHide($userId, $type)
  491. {
  492. $this->model->where(['to_uid' => $userId, 'type' => $type, 'status' => 1, 'mark' => 1])
  493. ->update(['update_time' => time(),'to_show'=>2, 'is_read' => 1, 'status' => 3]);
  494. // 清除缓存
  495. RedisService::keyDel("caches:messages:bar*");
  496. RedisService::keyDel("caches:messages:new_*");
  497. RedisService::keyDel("caches:messages:un_*");
  498. RedisService::keyDel("caches:messages:topList_{$userId}");
  499. return true;
  500. }
  501. /**
  502. * 清除历史
  503. * @param $userId
  504. * @param int $expire
  505. * @return mixed
  506. */
  507. public function clear($userId, $chatKey = 0, $type = 0)
  508. {
  509. $where = ['to_uid' => $userId, 'mark' => 1];
  510. if ($type) {
  511. $where['type'] = $type;
  512. }
  513. if ($chatKey) {
  514. $where['chat_key'] = $chatKey;
  515. }
  516. $this->model->where($where)
  517. ->update(['update_time' => time(), 'mark' => 0]);
  518. // 清除缓存
  519. RedisService::keyDel("caches:messages:bar*");
  520. RedisService::keyDel("caches:messages:new_*");
  521. RedisService::keyDel("caches:messages:un_*");
  522. RedisService::keyDel("caches:messages:topList_{$userId}");
  523. return true;
  524. }
  525. /**
  526. * 清除历史
  527. * @param $userId
  528. * @param int $expire
  529. * @return mixed
  530. */
  531. public function clearAll($userId, $type=0)
  532. {
  533. $expire = ConfigService::make()->getConfigByCode('chat_log_expire');
  534. $expire = $expire > 0 ? $expire : 60;
  535. $this->model->where(['to_uid' => $userId, 'mark' => 0])
  536. ->where('update_time', '<', time() - $expire * 86400)
  537. ->delete();
  538. // 清除缓存
  539. RedisService::keyDel("caches:messages:bar*");
  540. RedisService::keyDel("caches:messages:new_*");
  541. RedisService::keyDel("caches:messages:topList_{$userId}");
  542. // 站内消息发给我的全删
  543. $this->model->whereNotIn('type',[9])->where(function($query) use($userId, $type){
  544. $query->where(['to_uid'=> $userId,'mark'=>1]);
  545. if($type>0){
  546. $query->where('type', $type);
  547. }
  548. })->update(['update_time' => time(), 'mark' => 0]);
  549. if($type==9 || !$type){
  550. // 聊天消息我发的全删
  551. $this->model->where(function($query) use($userId){
  552. $query->where(['type'=>9,'from_uid'=> $userId,'mark'=>1]);
  553. })->update(['update_time' => time(), 'mark' => 0]);
  554. // 聊天消息发给我的,接收方全隐藏
  555. $this->model->where(function($query) use($userId){
  556. $query->where(['type'=>9,'to_uid'=> $userId,'mark'=>1]);
  557. })->update(['update_time' => time(),'is_read'=>1, 'to_show' => 2]);
  558. }
  559. return true;
  560. }
  561. }