| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- <?php
- // +----------------------------------------------------------------------
- // | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
- // +----------------------------------------------------------------------
- // | 版权所有 2017~2021 LARAVEL研发中心
- // +----------------------------------------------------------------------
- // | 官方网站: http://www.laravel.cn
- // +----------------------------------------------------------------------
- // | Author: laravel开发员 <laravel.qq.com>
- // +----------------------------------------------------------------------
- namespace App\Services;
- use App\Models\ChatMessageModel;
- use App\Models\ConfigModel;
- /**
- * 聊天-服务类
- * Class ChatMessageService
- * @package App\Services
- */
- class ChatMessageService extends BaseService
- {
- // 静态对象
- protected static $instance = null;
- /**
- * 构造函数
- * ChatMessageService constructor.
- */
- public function __construct()
- {
- $this->model = new ChatMessageModel();
- }
- /**
- * 静态入口
- * @return static|null
- */
- public static function make(){
- if(!self::$instance){
- self::$instance = (new static());
- }
- return self::$instance;
- }
- /**
- * 绑定用户
- * @param $fd
- * @param $data
- * @return bool
- */
- public function bind($fd, $data)
- {
- $userId = isset($data['from_uid'])? intval($data['from_uid']) : 0;
- if($userId<=0){
- $this->error = '1013';
- return false;
- }
- RedisService::set("chats:bind:{$userId}", ['fd'=> $fd, 'user_id'=> $userId], 86400);
- return true;
- }
- /**
- * 添加或编辑
- * @return array
- */
- public function saveData($data)
- {
- $data = [
- 'type'=> isset($data['type'])? $data['type'] : 1,
- 'message_type'=> isset($data['message_type'])? $data['message_type'] : 1,
- 'from_uid'=> isset($data['from_uid'])? $data['from_uid'] : 1,
- 'to_uid'=> isset($data['to_uid'])? $data['to_uid'] : 1,
- 'order_no'=> isset($data['order_no'])? $data['order_no'] : '',
- 'chat_key'=> getChatKey($data['from_uid'],$data['to_uid']),
- 'message'=> isset($data['message'])? $data['message'] : '',
- 'create_time'=> time(),
- 'update_time'=> time(),
- 'is_read'=> 2,
- 'status'=> 1,
- 'mark'=> 1,
- ];
- return parent::edit($data); // TODO: Change the autogenerated stub
- }
- /**
- * 推送保存消息,如订单消息
- * @param $data 消息数据
- * @return int|number
- */
- public function pushMessage($data)
- {
- return $this->model->edit($data);
- }
- }
|