Publics.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use app\common\model\Config;
  5. use think\facade\Validate;
  6. use think\Request;
  7. use app\common\model\Category;
  8. use app\common\model\SearchHistory;
  9. use OSS\OssClient;
  10. use app\common\model\User;
  11. use OSS\Core\OssException;
  12. use app\common\model\Order;
  13. /**
  14. * @title 公共类
  15. * @controller Publics
  16. */
  17. class Publics extends Api
  18. {
  19. /**
  20. * @title 上传图片
  21. * @desc 上传图片
  22. * @url /api/Publics/uploadLocality
  23. * @method POST
  24. * @tag 基础
  25. *
  26. * @param name:file type:file require:1 desc:上传
  27. * @return name:data@url type:string desc:图片地址
  28. **/
  29. public function uploadLocality(){
  30. $file = request()->file('file');
  31. $dir = dirname(realpath(dirname($_SERVER['SCRIPT_FILENAME']))) . '/public/upload';
  32. if(!file_exists($dir)){
  33. //检查是否有该文件夹,如果没有就创建,并给予最高权限
  34. mkdir($dir, 0700,true);
  35. }
  36. $ossClient = new OssClient(self::getOneValues('storage_oss_keyid'), self::getOneValues('storage_oss_secret'), self::getOneValues('storage_oss_endpoint'));
  37. $info = $file->move($dir);
  38. $newName = $info->getSaveName();
  39. $storage_type = self::getOneValues('storage_type');
  40. if ($storage_type == 'oss'){
  41. $file_path = dirname($_SERVER['SCRIPT_FILENAME']) . "/upload/".$newName;
  42. $result = $ossClient->uploadFile(self::getOneValues('storage_oss_bucket'), $newName, $file_path);
  43. $data['url'] = $result['info']['url'];
  44. unlink($file_path);
  45. }elseif ($storage_type=='local'){
  46. //压缩图片
  47. //image_png_size_add(ROOT_PATH . 'public' . DS . 'uploads/images/'.$newName,ROOT_PATH . 'public' . DS . 'uploads/images/'.$newName);
  48. $data['url'] = 'http://'.$_SERVER['SERVER_NAME']."/upload/{$newName}";
  49. }
  50. $this->success('上传成功',$data);
  51. }
  52. /**
  53. * @title 获取系统配置
  54. * @desc 获取系统配置
  55. * @url /api/Publics/config_info
  56. * @method POST
  57. * @tag 基础
  58. *
  59. * @return name:designclassifi type:string desc:设计分类
  60. * @return name:skillslabel type:string desc:技能标签
  61. * @return name:goodtype type:string desc:擅长类型
  62. * @return name:goodstyle type:string desc:擅长风格
  63. * @return name:service_start_time type:string desc:服务时间开始
  64. * @return name:service_end_time type:string desc:服务时间结束
  65. * @return name:user_instructions type:string desc:用户须知
  66. * @return name:rules_platform type:string desc:平台规则
  67. **/
  68. public function config_info(){
  69. $array['designclassifi'] = explode(',',Config::get_values('designclassifi'));
  70. $array['skillslabel'] = explode(',',Config::get_values('skillslabel'));
  71. $array['goodtype'] = explode(',',Config::get_values('goodtype'));
  72. $array['goodstyle'] = explode(',',Config::get_values('goodstyle'));
  73. $array['service_start_time'] = Config::get_values('service_start_time');
  74. $array['service_end_time'] = Config::get_values('service_end_time');
  75. $array['user_instructions'] = Config::get_values('user_instructions');
  76. $array['rules_platform'] = Config::get_values('rules_platform');
  77. $this->success('成功',$array);
  78. }
  79. }