Index.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <?php
  2. namespace app\index\controller;
  3. use app\enterprise\model\{File,Group,User};
  4. use think\facade\View;
  5. use app\manage\model\Config;
  6. class Index
  7. {
  8. public function index()
  9. {
  10. if (!file_exists(PACKAGE_PATH . "install.lock")) {
  11. return redirect(url('index/install/index'));
  12. }
  13. return redirect("/index.html");
  14. }
  15. public function view()
  16. {
  17. $url=request()->param('src');
  18. $suffix=explode('.',$url);
  19. $ext=$suffix[count($suffix)-1];
  20. return View::fetch('',[
  21. 'url' => $url,
  22. 'ext'=>$ext,
  23. 'name'=>"预览文件"
  24. ]);
  25. }
  26. // 头像生成
  27. public function avatar()
  28. {
  29. circleAvatar(input('str'), input('s') ?: 80, input('uid'));die;
  30. }
  31. // 文件下载
  32. public function download()
  33. {
  34. if (strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') !== false) {
  35. throw new \think\Exception('请使用浏览器下载!',400);
  36. }
  37. $param = request()->param();
  38. $file_id = $param['file_id'] ?? 0;
  39. if (!$file_id) {
  40. throw new \think\Exception('参数错误', 502);
  41. }
  42. try {
  43. $file_id = decryptIds($file_id);
  44. } catch (\Exception $e) {
  45. throw new \think\Exception($e->getMessage(), 400);
  46. }
  47. $file = File::find($file_id);
  48. if (!$file) {
  49. throw new \think\Exception('该文件不存在!',404);
  50. }
  51. $file = $file->toArray();
  52. // 兼容本地文件下载
  53. $fileUrl=getDiskUrl();
  54. if($fileUrl==request()->domain()){
  55. $url=rtrim(public_path(),'/').$file['src'];
  56. }else{
  57. $url= getFileUrl($file['src']);
  58. }
  59. return \utils\File::download($url, $file['name'] . '.' . $file['ext'], $file['size'], $file['ext']);
  60. }
  61. // 扫码获取信息
  62. public function scanQr(){
  63. $param=request()->param();
  64. $action=$param['action'] ?? '';
  65. $token=$param['token'] ?? '';
  66. $realToken=$param['realToken'] ?? '';
  67. if(request()->isPost() && $action && $token && $realToken){
  68. $actions=[
  69. 'g'=>'group',
  70. 'u'=>'user',
  71. ];
  72. $a=$actions[$action] ?? '';
  73. if(!$a){
  74. return warning('二维码已失效');
  75. }
  76. return $this->$a($param);
  77. }else{
  78. return $this->index();
  79. }
  80. }
  81. protected function group($param)
  82. {
  83. $token=authcode(urldecode($param['realToken']),"DECODE", 'qr');
  84. if(!$token){
  85. return warning('二维码已失效');
  86. }
  87. $groupInfo=explode('-',$token);
  88. $uid=$groupInfo[0];
  89. $group_id=$groupInfo[1];
  90. $group=Group::find($group_id);
  91. if($group){
  92. $group=$group->toArray();
  93. $group['avatar']=avatarUrl($group['avatar'],$group['name'],$group_id,120);
  94. $group['invite_id']=$uid;
  95. $group['id']='group-'.$group_id;
  96. $group['action']='groupInfo';
  97. return success('',$group);
  98. }else{
  99. return warning('二维码已失效');
  100. }
  101. }
  102. protected function user($param)
  103. {
  104. $id=decryptIds($param['token']);
  105. if(!$id){
  106. return warning('二维码已失效');
  107. }
  108. $user=User::where(['user_id'=>$id])->field(User::$defaultField)->find();
  109. if($user){
  110. $user=$user->toArray();
  111. $user['avatar']=avatarUrl($user['avatar'],$user['realname'],$user['user_id'],120);
  112. $user['id']=$user['user_id'];
  113. $user['action']='userInfo';
  114. return success('',$user);
  115. }else{
  116. return warning('二维码已失效');
  117. }
  118. }
  119. // app下载页
  120. public function downApp(){
  121. $config=Config::where('name','sysInfo')->value('value');
  122. $andriod=getAppDowmUrl('andriod');
  123. $winUrl=getAppDowmUrl('windows');
  124. $macUrl=getAppDowmUrl('mac');
  125. $client=[
  126. 'andriod_appid'=>env('app.andriod_appid',''),
  127. 'andriod_webclip'=>env('app.andriod_webclip','') ? : $andriod,
  128. 'ios_appid'=>env('app.ios_appid',''),
  129. 'ios_webclip'=>env('app.ios_webclip',''),
  130. 'win_webclip'=>env('app.win_webclip','') ? : $winUrl,
  131. 'mac_webclip'=>env('app.mac_webclip','') ? : $macUrl
  132. ];
  133. $noUrl=false;
  134. if(!$client['andriod_appid'] && !$client['andriod_webclip'] && !$client['ios_appid'] && !$client['ios_webclip']){
  135. $noUrl=true;
  136. }
  137. View::assign('noUrl',$noUrl);
  138. View::assign('client',$client);
  139. View::assign('config',$config);
  140. return View::fetch();
  141. }
  142. // 下载APP
  143. public function downloadApp(){
  144. $platform=request()->param('platform','windows');
  145. $config=config('version.'.$platform);
  146. $name=config('version.app_name');
  147. if($platform=='andriod'){
  148. $packageName=$name."_Setup_".$config['version'].".apk";
  149. }elseif($platform=='mac'){
  150. $packageName=$name."_Setup_".$config['version'].".dmg";
  151. }else{
  152. $packageName=$name."_Setup_".$config['version'].".exe";
  153. }
  154. $file=PACKAGE_PATH . $packageName;
  155. if(is_file($file)){
  156. return \utils\File::download($file, $packageName);
  157. }else{
  158. return warning('文件不存在');
  159. }
  160. }
  161. }