| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- <?php
- namespace app\common\model;
- use app\api\services\UserServices;
- use app\common\model\TimeModel;
- //use app\model\RedPoolModel;
- //use app\model\RedStorePoolModel;
- use app\common\model\UserDataModel;
- use http\Params;
- use services\CacheServices;
- use think\Exception;
- use think\facade\Db;
- use think\Model;
- class ChatMessageModel extends Model
- {
- protected $name = "chat_message";
- public function chatSendMessage($uid, $para){
- $user_info = Db::name('user')->where('id', $uid)->find();
- $type = $para['type'];
- if (!in_array($type, [1,2])){
- sr_throw('类型错误');
- }
- // if ($type == 2){
- //
- // }
- if ($user_info['user_type'] != 99){
- sr_throw('错误');
- }
- $content = $para['content'];
- if (empty($content)){
- sr_throw('消息不能为空');
- }
- if ($type == 1){
- $content = removeEmojiChar($content);
- if (empty(str_replace(' ','', $content))){
- sr_throw('消息不能为空');
- }
- if (empty($content)){
- sr_throw('暂不支持发送表情');
- }
- }
- self::insert([
- 'uid'=>$uid,
- 'type'=>$type,
- 'content'=>($type==1?$content:(getWebUrl().'/'.$para['content'])),
- 'create_time'=>sr_getcurtime(time()),
- 'avatar'=>getWebUrl().'/'.$user_info['avatar'],
- 'nick_name'=>$user_info['nickname']
- ]);
- }
- public function chatGetNewMessage($uid, $para){
- // 查询封禁的id
- $deny_list = Db::name('chat_message')->where('status', 1)->select()->toArray();
- $deny_ids = '';
- foreach ($deny_list as $key=>$val){
- $deny_ids = $deny_ids.(empty($deny_ids)?'':'|').$val['id'];
- }
- $last_id = 0;
- if (isset($para['last_id']) && $para['last_id'] > 0){
- $last_id = $para['last_id'];
- }else{
- $last_id = 0;
- }
- // $last_id = (isset($para['last_id'])?$para['last_id']:0);
- // if (!isset($last_id) || empty($last_id)){
- // $list = self::where('status', 0)->page(1, 10)->order('id desc')->select()->toArray();
- // return ['msg_list'=>$list,'deny_ids'=>$deny_ids];
- // }
- //
- // if ($last_id > 0){
- $list = self::where('status', 0)->where('id', '>', $last_id)->page(1, 10)->order('id desc')->select()->toArray();
- return ['msg_list'=>$list,'deny_ids'=>$deny_ids];
- // }
- return ['msg_list'=>[],'deny_ids'=>$deny_ids];
- }
- public function chatGetOldMessage($uid, $para){
- $last_id = $para['last_id'];
- if (!isset($last_id) || empty($last_id)){
- $list = self::where('status', 0)->page(1, 10)->order('id desc')->select()->toArray();
- return $list;
- }
- if ($last_id > 0){
- $list = self::where('status', 0)->where('id', '<', $last_id)->page(1, 10)->order('id desc')->select()->toArray();
- return $list;
- }
- return [];
- }
- }
|