Files.php 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. namespace app\enterprise\controller;
  3. use app\BaseController;
  4. use app\enterprise\model\{File,User,Message};
  5. use think\facade\View;
  6. class Files extends BaseController
  7. {
  8. // 文件列表
  9. public function index()
  10. {
  11. $param = $this->request->param();
  12. $is_all = $param['is_all'] ?? 0;
  13. $map = [];
  14. $data=[];
  15. // 如果是查询全部,就查询file表,否则查询message表
  16. if ($is_all) {
  17. if ($param['cate'] ?? 0) {
  18. $map[] = ['cate', '=', $param['cate']];
  19. }
  20. $model = new File();
  21. if ($param['keywords'] ?? '') {
  22. $model = $model->where('name', 'like', '%' . $param['keywords'] . '%');
  23. }
  24. $list = $this->paginate($model->where($map)->order('file_id desc'));
  25. if ($list) {
  26. $data = $list->toArray()['data'];
  27. $userList = User::matchUser($data, true, 'user_id', 120);
  28. foreach ($data as $k => $v) {
  29. $url=getFileUrl($v['src']);
  30. $data[$k]['src'] =$url;
  31. $data[$k]['preview'] = previewUrl($url);
  32. $data[$k]['extUrl'] = getExtUrl($v['src']);
  33. $data[$k]['name'] = $v['name'].'.'.$v['ext'];
  34. $data[$k]['msg_type'] = getFileType($v['ext'],true);
  35. $data[$k]['user_id_info'] = $userList[$v['user_id']] ?? [];
  36. $data[$k]['download'] = request()->domain().'/filedown/'.encryptIds($v['file_id']);
  37. }
  38. }
  39. } else {
  40. $map = [
  41. ['file_id', '>', 0],
  42. ['type', '<>', 'voice'],
  43. ['is_group', '=', 0],
  44. ['is_undo', '=', 0],
  45. ];
  46. if ($param['cate'] ?? 0) {
  47. $map[] = ['file_cate', '=', $param['cate']];
  48. }
  49. $user_id = $this->uid;
  50. $model = new Message();
  51. if ($param['keywords'] ?? '') {
  52. $map[] = ['file_name', 'like', '%' . $param['keywords'] . '%'];
  53. }
  54. $role = $param['role'] ?? 0;
  55. $where=[];
  56. if($role==1){
  57. $map[] = ['from_user', '=', $user_id];
  58. }elseif($role==2){
  59. $map[] = ['to_user', '=', $user_id];
  60. }else{
  61. $where='(from_user='.$user_id.' or to_user='.$user_id.')';
  62. }
  63. $list = $this->paginate($model->where($map)->where($where)->order('create_time desc'));
  64. if ($list) {
  65. $data = $list->toArray()['data'];
  66. $userList = User::matchUser($data, true, 'from_user', 120);
  67. foreach ($data as $k => $v) {
  68. $content=str_encipher($v['content'],false);
  69. $url=getFileUrl($content);
  70. $data[$k]['src'] = $url;
  71. $data[$k]['preview'] = previewUrl($url);
  72. $data[$k]['extUrl'] = getExtUrl($content);
  73. $data[$k]['cate'] = $v['file_cate'];
  74. $data[$k]['name'] = $v['file_name'];
  75. $data[$k]['size'] = $v['file_size'];
  76. $data[$k]['msg_type'] = $v['type'];
  77. $ext=explode('.',$content);
  78. $data[$k]['ext'] = end($ext);
  79. $data[$k]['user_id_info'] = $userList[$v['from_user']] ?? [];
  80. $data[$k]['download'] = request()->domain().'/filedown/'.encryptIds($v['file_id']);
  81. }
  82. }
  83. }
  84. return success('', $data, $list->total(), $list->currentPage());
  85. }
  86. }