Imlogc2c.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. namespace app\admin\controller;
  3. use app\common\controller\Backend;
  4. use think\Db;
  5. /**
  6. *
  7. *
  8. * @icon fa fa-circle-o
  9. */
  10. class Imlogc2c extends Backend
  11. {
  12. /**
  13. * Imlogc2c模型对象
  14. * @var \app\admin\model\Imlogc2c
  15. */
  16. protected $model = null;
  17. public function _initialize()
  18. {
  19. parent::_initialize();
  20. $this->model = new \app\admin\model\Imlogc2c;
  21. }
  22. public function import()
  23. {
  24. parent::import();
  25. }
  26. /**
  27. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  28. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  29. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  30. */
  31. /**
  32. * 查看
  33. */
  34. public function index()
  35. {
  36. //当前是否为关联查询
  37. $this->relationSearch = true;
  38. //设置过滤方法
  39. $this->request->filter(['strip_tags', 'trim']);
  40. if ($this->request->isAjax()) {
  41. //如果发送的来源是Selectpage,则转发到Selectpage
  42. if ($this->request->request('keyField')) {
  43. return $this->selectpage();
  44. }
  45. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  46. $list = $this->model
  47. ->with(['fromuser','touser'])
  48. ->where($where)
  49. ->order($sort, $order)
  50. ->paginate($limit);
  51. foreach ($list as $row) {
  52. $row->getRelation('fromuser')->visible(['nickname']);
  53. $row->getRelation('touser')->visible(['nickname']);
  54. }
  55. $list2 = collection($list->items())->toArray();
  56. $type_arr = $this->type_arr();
  57. foreach($list2 as $key => &$val){
  58. $val['MsgType'] = isset($type_arr[$val['MsgType']]) ? $type_arr[$val['MsgType']] : '其他';
  59. }
  60. $result = array("total" => $list->total(), "rows" => $list2);
  61. return json($result);
  62. }
  63. return $this->view->fetch();
  64. }
  65. private function type_arr(){
  66. $type_arr = [
  67. 'TIMTextElem' => '文本',
  68. 'TIMImageElem' => '图片',
  69. 'TIMSoundElem' => '声音',
  70. 'TIMVideoFileElem' => '视频',
  71. ];
  72. return $type_arr;
  73. }
  74. /**
  75. * 消息体
  76. */
  77. public function showbody(){
  78. $id = input('id',0);
  79. $info = Db::name('imlog_c2c')->where('id',$id)->find();
  80. $type_arr = $this->type_arr();
  81. $info['typetext'] = isset($type_arr[$info['MsgType']]) ? $type_arr[$info['MsgType']] : '其他';
  82. if($info['MsgType'] == 'TIMTextElem'){
  83. $info['MsgInfo'] = $info['MsgInfo'];
  84. }
  85. if($info['MsgType'] == 'TIMImageElem'){
  86. $info['MsgInfo'] = '<img width="800" height="800" src="'.$info['MsgInfo'].'">';
  87. }
  88. if($info['MsgType'] == 'TIMSoundElem'){
  89. $info['MsgInfo'] = '<audio controls><source src="'.$info['MsgInfo'].'"></audio>';
  90. }
  91. if($info['MsgType'] == 'TIMVideoFileElem'){
  92. $info['MsgInfo'] = '<video width="800" height="800" controls preload src="'.$info['MsgInfo'].'"></video>';
  93. }
  94. $this->assign('info',$info);
  95. return $this->view->fetch();
  96. }
  97. }