ChatLog.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. namespace App\Admin\Actions\Chat;
  3. use App\Models\ChatList;
  4. use App\Models\User;
  5. use App\Repositories\ImMessage;
  6. use App\Services\TencentImMessage;
  7. use Dcat\Admin\Grid;
  8. use Dcat\Admin\Grid\LazyRenderable;
  9. class ChatLog extends LazyRenderable
  10. {
  11. public function grid(): Grid
  12. {
  13. $chat_data = ChatList::query()->find($this->payload['id']);
  14. return Grid::make(new ImMessage($chat_data->user_id,$chat_data->to_user_id), function (Grid $grid) {
  15. // $grid->column('user_id', 'ID')->sortable();
  16. $grid->column('From_Account','发消息用户')->display(function ($res){
  17. $user = User::query()->where('tencent_im_user_id',$res)->with("user_info")->first();
  18. $str = "";
  19. $str.="<div style='margin-right:10px;text-align: center;display: flex'>";
  20. $str.='<img data-action="preview-img" src="'.$user->user_info->avatar.'" style="max-width:50px;max-height:50px;cursor:pointer" class="img img-thumbnail">';
  21. $str.='<p style="margin-top: 5px">'.$user->user_info->nickname.'</p>';
  22. $str.="</div>";
  23. return $str;
  24. });
  25. $grid->column('To_Account','接收消息用户')->display(function ($res){
  26. $user = User::query()->where('tencent_im_user_id',$res)->with("user_info")->first();
  27. $str = "";
  28. $str.="<div style='margin-right:10px;text-align: center;display: flex'>";
  29. $str.='<img data-action="preview-img" src="'.$user->user_info->avatar.'" style="max-width:50px;max-height:50px;cursor:pointer" class="img img-thumbnail">';
  30. $str.='<p style="margin-top: 5px">'.$user->user_info->nickname.'</p>';
  31. $str.="</div>";
  32. return $str;
  33. });
  34. $grid->column('MsgTimeStamp','时间')->display(function ($res){
  35. return date("m-d H:i",$res);
  36. });
  37. $grid->column('MsgBody','消息内容')->display(function ($res){
  38. //dd($res);
  39. //$res = json_decode($res,true);
  40. if($res[0]['MsgType']=='TIMTextElem'){
  41. //文本消息
  42. return $res[0]['MsgContent']['Text'];
  43. }elseif ($res[0]['MsgType']=="TIMLocationElem"){
  44. //位置消息
  45. return $res[0]['MsgContent']['Desc'];
  46. }elseif ($res[0]['MsgType']=="TIMFaceElem"){
  47. //表情消息
  48. }elseif ($res[0]['MsgType']=="TIMCustomElem"){
  49. //自定义消息
  50. }elseif ($res[0]['MsgType']=="TIMSoundElem"){
  51. //语音消息
  52. }elseif ($res[0]['MsgType']=="TIMImageElem"){
  53. //图像消息
  54. $imgs = $res[0]['MsgContent']['ImageInfoArray'];
  55. $str = "";
  56. if(count($imgs)>0){
  57. $str.='<img data-action="preview-img" src="'.$imgs[0]['URL'].'" style="max-width:50px;max-height:200px;cursor:pointer" class="img img-thumbnail">';
  58. }
  59. return $str;
  60. }elseif ($res[0]['MsgType']=="TIMFileElem"){
  61. //文件消息
  62. }elseif ($res[0]['MsgType']=="TIMVideoFileElem"){
  63. //视频消息
  64. $str = "<video src='".$res[0]['MsgContent']['VideoUrl']."' style='width:200px;height:200px;margin-right:10px' controls='controls'></video>";
  65. return $str;
  66. }
  67. });
  68. $grid->quickSearch(['user_id', 'nickname']);
  69. $grid->paginate(10);
  70. $grid->disableActions();
  71. $grid->filter(function (Grid\Filter $filter) {
  72. // $filter->like('nickname','昵称')->width(4);
  73. });
  74. });
  75. }
  76. }