ChatLog.php 4.0 KB

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