ChatMessageService.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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\Common;
  12. use App\Models\AdModel;
  13. use App\Models\ApiModel;
  14. use App\Models\ChatMessageModel;
  15. use App\Services\BaseService;
  16. use App\Services\RedisService;
  17. /**
  18. * 聊天管理-服务类
  19. * Class ChatMessageService
  20. * @package App\Services\Common
  21. */
  22. class ChatMessageService extends BaseService
  23. {
  24. // 静态对象
  25. protected static $instance = null;
  26. /**
  27. * 构造函数
  28. * ChatMessageService constructor.
  29. */
  30. public function __construct()
  31. {
  32. $this->model = new ChatMessageModel();
  33. }
  34. /**
  35. * 静态入口
  36. * @return static|null
  37. */
  38. public static function make()
  39. {
  40. if (!self::$instance) {
  41. self::$instance = (new static());
  42. }
  43. return self::$instance;
  44. }
  45. /**
  46. * 绑定用户
  47. * @param $fd
  48. * @param $data
  49. * @return bool
  50. */
  51. public function bind($fd, $data)
  52. {
  53. $userId = isset($data['from_uid'])? intval($data['from_uid']) : 0;
  54. if($userId<=0){
  55. $this->error = '1013';
  56. return false;
  57. }
  58. RedisService::set("caches:chats:bind:{$userId}", ['fd'=> $fd, 'user_id'=> $userId], 86400);
  59. return true;
  60. }
  61. /**
  62. * 添加或编辑
  63. * @return array
  64. */
  65. public function saveData($fd, $data)
  66. {
  67. return parent::edit($data); // TODO: Change the autogenerated stub
  68. }
  69. }