ChatMessageModel.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. namespace app\common\model;
  3. use app\api\services\UserServices;
  4. use app\common\model\TimeModel;
  5. //use app\model\RedPoolModel;
  6. //use app\model\RedStorePoolModel;
  7. use app\common\model\UserDataModel;
  8. use http\Params;
  9. use services\CacheServices;
  10. use think\Exception;
  11. use think\facade\Db;
  12. use think\Model;
  13. class ChatMessageModel extends Model
  14. {
  15. protected $name = "chat_message";
  16. public function chatSendMessage($uid, $para){
  17. $user_info = Db::name('user')->where('id', $uid)->find();
  18. $type = $para['type'];
  19. if (!in_array($type, [1,2])){
  20. sr_throw('类型错误');
  21. }
  22. // if ($type == 2){
  23. //
  24. // }
  25. if ($user_info['user_type'] != 99){
  26. sr_throw('错误');
  27. }
  28. $content = $para['content'];
  29. if (empty($content)){
  30. sr_throw('消息不能为空');
  31. }
  32. if ($type == 1){
  33. $content = removeEmojiChar($content);
  34. if (empty(str_replace(' ','', $content))){
  35. sr_throw('消息不能为空');
  36. }
  37. if (empty($content)){
  38. sr_throw('暂不支持发送表情');
  39. }
  40. }
  41. self::insert([
  42. 'uid'=>$uid,
  43. 'type'=>$type,
  44. 'content'=>($type==1?$content:(getWebUrl().'/'.$para['content'])),
  45. 'create_time'=>sr_getcurtime(time()),
  46. 'avatar'=>getWebUrl().'/'.$user_info['avatar'],
  47. 'nick_name'=>$user_info['nickname']
  48. ]);
  49. }
  50. public function chatGetNewMessage($uid, $para){
  51. // 查询封禁的id
  52. $deny_list = Db::name('chat_message')->where('status', 1)->select()->toArray();
  53. $deny_ids = '';
  54. foreach ($deny_list as $key=>$val){
  55. $deny_ids = $deny_ids.(empty($deny_ids)?'':'|').$val['id'];
  56. }
  57. $last_id = 0;
  58. if (isset($para['last_id']) && $para['last_id'] > 0){
  59. $last_id = $para['last_id'];
  60. }else{
  61. $last_id = 0;
  62. }
  63. // $last_id = (isset($para['last_id'])?$para['last_id']:0);
  64. // if (!isset($last_id) || empty($last_id)){
  65. // $list = self::where('status', 0)->page(1, 10)->order('id desc')->select()->toArray();
  66. // return ['msg_list'=>$list,'deny_ids'=>$deny_ids];
  67. // }
  68. //
  69. // if ($last_id > 0){
  70. $list = self::where('status', 0)->where('id', '>', $last_id)->page(1, 10)->order('id desc')->select()->toArray();
  71. return ['msg_list'=>$list,'deny_ids'=>$deny_ids];
  72. // }
  73. return ['msg_list'=>[],'deny_ids'=>$deny_ids];
  74. }
  75. public function chatGetOldMessage($uid, $para){
  76. $last_id = $para['last_id'];
  77. if (!isset($last_id) || empty($last_id)){
  78. $list = self::where('status', 0)->page(1, 10)->order('id desc')->select()->toArray();
  79. return $list;
  80. }
  81. if ($last_id > 0){
  82. $list = self::where('status', 0)->where('id', '<', $last_id)->page(1, 10)->order('id desc')->select()->toArray();
  83. return $list;
  84. }
  85. return [];
  86. }
  87. }