聊天,基本
This commit is contained in:
45
extend/chat/model/Business.php
Normal file
45
extend/chat/model/Business.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace extend\chat\model;
|
||||
|
||||
use ba\Random;
|
||||
use support\Redis;
|
||||
|
||||
class Business
|
||||
{
|
||||
// 存消息
|
||||
public static function setRedisMessage($uid, $user_type, $data)
|
||||
{
|
||||
$str_uid = Base::getUid($uid, $user_type);
|
||||
$rand_msg_str = $str_uid . Random::build();
|
||||
$set_str = 'nomsg:message:' . $str_uid;
|
||||
$set_info_str = 'nomsg:message:' . $rand_msg_str;
|
||||
$sent = Redis::get($set_str);
|
||||
if($sent) {
|
||||
$sent = json_decode($sent, true);
|
||||
$sent[count($sent - 1)] = $set_info_str;
|
||||
Redis::set($set_str, json_encode($sent));
|
||||
}else {
|
||||
Redis::set($set_str, json_encode([$set_info_str]));
|
||||
}
|
||||
Redis::set($set_info_str, json_encode($data));
|
||||
}
|
||||
|
||||
// 拉消息
|
||||
public static function getRedisMessage($uid, $user_type)
|
||||
{
|
||||
$str_uid = Base::getUid($uid, $user_type);
|
||||
$set_str = 'nomsg:message:' . $str_uid;
|
||||
$sent = Redis::get($set_str);
|
||||
$data = [];
|
||||
if($sent) {
|
||||
$sent = json_decode($sent, true);
|
||||
foreach ($sent as $k => $v) {
|
||||
$data[] = json_decode(Redis::get($v), true);
|
||||
Redis::del($v);
|
||||
}
|
||||
Redis::del($set_str);
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user