Imlogc2c.php 3.5 KB

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