123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173 |
- <?php
- namespace app\index\controller;
- use app\enterprise\model\{File,Group,User};
- use think\facade\View;
- use app\manage\model\Config;
- class Index
- {
- public function index()
- {
- if (!file_exists(PACKAGE_PATH . "install.lock")) {
- return redirect(url('index/install/index'));
- }
- return redirect("/index.html");
- }
- public function view()
- {
- $url=request()->param('src');
- $suffix=explode('.',$url);
- $ext=$suffix[count($suffix)-1];
- return View::fetch('',[
- 'url' => $url,
- 'ext'=>$ext,
- 'name'=>"预览文件"
- ]);
- }
- // 头像生成
- public function avatar()
- {
- circleAvatar(input('str'), input('s') ?: 80, input('uid'));die;
- }
- // 文件下载
- public function download()
- {
-
- if (strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') !== false) {
- throw new \think\Exception('请使用浏览器下载!',400);
- }
- $param = request()->param();
- $file_id = $param['file_id'] ?? 0;
- if (!$file_id) {
- throw new \think\Exception('参数错误', 502);
- }
- try {
- $file_id = decryptIds($file_id);
- } catch (\Exception $e) {
- throw new \think\Exception($e->getMessage(), 400);
- }
- $file = File::find($file_id);
- if (!$file) {
- throw new \think\Exception('该文件不存在!',404);
- }
- $file = $file->toArray();
- // 兼容本地文件下载
- $fileUrl=getDiskUrl();
- if($fileUrl==request()->domain()){
- $url=rtrim(public_path(),'/').$file['src'];
- }else{
- $url= getFileUrl($file['src']);
- }
- return \utils\File::download($url, $file['name'] . '.' . $file['ext'], $file['size'], $file['ext']);
- }
- // 扫码获取信息
- public function scanQr(){
- $param=request()->param();
- $action=$param['action'] ?? '';
- $token=$param['token'] ?? '';
- $realToken=$param['realToken'] ?? '';
- if(request()->isPost() && $action && $token && $realToken){
- $actions=[
- 'g'=>'group',
- 'u'=>'user',
- ];
- $a=$actions[$action] ?? '';
- if(!$a){
- return warning('二维码已失效');
- }
- return $this->$a($param);
- }else{
- return $this->index();
- }
- }
- protected function group($param)
- {
- $token=authcode(urldecode($param['realToken']),"DECODE", 'qr');
- if(!$token){
- return warning('二维码已失效');
- }
- $groupInfo=explode('-',$token);
- $uid=$groupInfo[0];
- $group_id=$groupInfo[1];
- $group=Group::find($group_id);
- if($group){
- $group=$group->toArray();
- $group['avatar']=avatarUrl($group['avatar'],$group['name'],$group_id,120);
- $group['invite_id']=$uid;
- $group['id']='group-'.$group_id;
- $group['action']='groupInfo';
- return success('',$group);
- }else{
- return warning('二维码已失效');
- }
- }
- protected function user($param)
- {
- $id=decryptIds($param['token']);
- if(!$id){
- return warning('二维码已失效');
- }
- $user=User::where(['user_id'=>$id])->field(User::$defaultField)->find();
- if($user){
- $user=$user->toArray();
- $user['avatar']=avatarUrl($user['avatar'],$user['realname'],$user['user_id'],120);
- $user['id']=$user['user_id'];
- $user['action']='userInfo';
- return success('',$user);
- }else{
- return warning('二维码已失效');
- }
- }
- // app下载页
- public function downApp(){
- $config=Config::where('name','sysInfo')->value('value');
- $andriod=getAppDowmUrl('andriod');
- $winUrl=getAppDowmUrl('windows');
- $macUrl=getAppDowmUrl('mac');
- $client=[
- 'andriod_appid'=>env('app.andriod_appid',''),
- 'andriod_webclip'=>env('app.andriod_webclip','') ? : $andriod,
- 'ios_appid'=>env('app.ios_appid',''),
- 'ios_webclip'=>env('app.ios_webclip',''),
- 'win_webclip'=>env('app.win_webclip','') ? : $winUrl,
- 'mac_webclip'=>env('app.mac_webclip','') ? : $macUrl
- ];
- $noUrl=false;
- if(!$client['andriod_appid'] && !$client['andriod_webclip'] && !$client['ios_appid'] && !$client['ios_webclip']){
- $noUrl=true;
- }
- View::assign('noUrl',$noUrl);
- View::assign('client',$client);
- View::assign('config',$config);
- return View::fetch();
- }
- // 下载APP
- public function downloadApp(){
- $platform=request()->param('platform','windows');
- $config=config('version.'.$platform);
- $name=config('version.app_name');
- if($platform=='andriod'){
- $packageName=$name."_Setup_".$config['version'].".apk";
- }elseif($platform=='mac'){
- $packageName=$name."_Setup_".$config['version'].".dmg";
- }else{
- $packageName=$name."_Setup_".$config['version'].".exe";
- }
- $file=PACKAGE_PATH . $packageName;
- if(is_file($file)){
- return \utils\File::download($file, $packageName);
- }else{
- return warning('文件不存在');
- }
- }
- }
|