Common.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. declare(strict_types=1);
  3. namespace app\api\controller;
  4. use think\annotation\route\Post;
  5. use think\annotation\route\Get;
  6. use think\annotation\route\Group;
  7. use app\common\service\upload\PublicUploadService;
  8. class Common extends Api{
  9. protected $noNeedLogin = ['*'];
  10. /**
  11. * 上传文件
  12. * @param File $file 文件流
  13. */
  14. public function upload()
  15. {
  16. $file = $this->request->file('file');
  17. try{
  18. $savename=PublicUploadService::newInstance([
  19. 'config'=>config('site.upload'),
  20. 'user_id'=>$this->auth->id,
  21. 'file'=>$file
  22. ])->save();
  23. }catch (\Exception $e){
  24. $this->error(__('上传文件出错'),[
  25. 'file'=>$e->getFile(),
  26. 'line'=>$e->getLine(),
  27. 'msg'=>$e->getMessage()
  28. ]);
  29. }
  30. $this->success('',$savename);
  31. }
  32. public function area($pid)
  33. {
  34. if(!class_exists('\app\common\model\Area')){
  35. $this->error('请先安装插件-省份城市地区数据');
  36. }
  37. $area=\app\common\model\Area::where('pid',$pid)->field('id,name')->select();
  38. $this->success('',$area);
  39. }
  40. }