ChatMessageService.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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;
  12. use App\Models\ChatMessageModel;
  13. use App\Models\ConfigModel;
  14. /**
  15. * 聊天-服务类
  16. * Class ChatMessageService
  17. * @package App\Services
  18. */
  19. class ChatMessageService extends BaseService
  20. {
  21. // 静态对象
  22. protected static $instance = null;
  23. /**
  24. * 构造函数
  25. * ChatMessageService constructor.
  26. */
  27. public function __construct()
  28. {
  29. $this->model = new ChatMessageModel();
  30. }
  31. /**
  32. * 静态入口
  33. * @return static|null
  34. */
  35. public static function make(){
  36. if(!self::$instance){
  37. self::$instance = (new static());
  38. }
  39. return self::$instance;
  40. }
  41. /**
  42. * 聊天对话窗口唯一KEY
  43. * @param $fromUid
  44. * @param $toUid
  45. * @return string
  46. */
  47. public function getChatKey($fromUid, $toUid)
  48. {
  49. $chatKeys = [$fromUid, $toUid];
  50. asort($chatKeys);
  51. return implode('', $chatKeys);
  52. }
  53. /**
  54. * 推送保存消息,如订单消息
  55. * @param $data 消息数据
  56. * @return int|number
  57. */
  58. public function pushMessage($data)
  59. {
  60. return $this->model->edit($data);
  61. }
  62. }