UploadFile.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. namespace app\controller;
  3. use think\annotation\Route;
  4. use think\annotation\route\Middleware;
  5. use hg\apidoc\annotation as Apidoc;
  6. use app\BaseController;
  7. use think\db\exception\DataNotFoundException;
  8. use think\db\exception\DbException;
  9. use think\db\exception\ModelNotFoundException;
  10. use thans\filesystem\Filesystem;
  11. use think\response\Json;
  12. /**
  13. * @Apidoc\Title("文件上传")
  14. * @Apidoc\Group("文件")
  15. * @Apidoc\Sort (8)
  16. */
  17. class UploadFile extends BaseController
  18. {
  19. protected $middleware = [
  20. 'jwt',
  21. ];
  22. use ResponseJson;
  23. /**
  24. * @Apidoc\Title("企业营业执照上传")
  25. * @Apidoc\Tag("文件")
  26. * @Apidoc\Method ("POST")
  27. * @Apidoc\Author ("ihavoc")
  28. * @Route("enterpriseCardUpload",method="POST")
  29. * @Middleware({})
  30. */
  31. public function enterpriseCardUpload(): Json
  32. {
  33. $file = request()->file('image');
  34. $savename = (new Filesystem(app()))->disk("aliyun")->putFile( 'enterprise', $file, 'uniqid');
  35. return $this->JsonSucess(["filename"=>$savename,"url"=>"https://ahwgh.oss-cn-hangzhou.aliyuncs.com/".$savename]);
  36. }
  37. /**
  38. * @Apidoc\Title("法人、个人身份证上传")
  39. * @Apidoc\Tag("文件")
  40. * @Apidoc\Method ("POST")
  41. * @Apidoc\Author ("ihavoc")
  42. * @Route("personCardUpload",method="POST")
  43. * @Middleware({})
  44. */
  45. public function personCardUpload(): Json
  46. {
  47. $file = request()->file('image');
  48. $savename = (new Filesystem(app()))->disk("aliyun")->putFile( 'person', $file, 'uniqid');
  49. return $this->JsonSucess(["filename"=>$savename,"url"=>"https://ahwgh.oss-cn-hangzhou.aliyuncs.com/".$savename]);
  50. }
  51. /**
  52. * @Apidoc\Title("产品图片上传")
  53. * @Apidoc\Tag("文件")
  54. * @Apidoc\Method ("POST")
  55. * @Apidoc\Author ("ihavoc")
  56. * @Route("productUpload",method="POST")
  57. * @Middleware({})
  58. */
  59. public function productUpload(): Json
  60. {
  61. $file = request()->file('image');
  62. $savename = (new Filesystem(app()))->disk("aliyun")->putFile( 'product', $file, 'uniqid');
  63. return $this->JsonSucess(["filename"=>$savename,"url"=>"https://ahwgh.oss-cn-hangzhou.aliyuncs.com/".$savename]);
  64. }
  65. /**
  66. * @Apidoc\Title("产品认证上传")
  67. * @Apidoc\Tag("文件")
  68. * @Apidoc\Method ("POST")
  69. * @Apidoc\Author ("ihavoc")
  70. * @Route("productCreUpload",method="POST")
  71. * @Middleware({})
  72. */
  73. public function productCreUpload(): Json
  74. {
  75. $file = request()->file('image');
  76. $savename = (new Filesystem(app()))->disk("aliyun")->putFile( 'productCre', $file, 'uniqid');
  77. return $this->JsonSucess(["filename"=>$savename,"url"=>"https://ahwgh.oss-cn-hangzhou.aliyuncs.com/".$savename]);
  78. }
  79. /**
  80. * @Apidoc\Title("巡检照片上传")
  81. * @Apidoc\Tag("文件")
  82. * @Apidoc\Method ("POST")
  83. * @Apidoc\Author ("ihavoc")
  84. * @Route("patrolInspectionUpload",method="POST")
  85. * @Middleware({})
  86. */
  87. public function patrolInspectionUpload(): Json
  88. {
  89. $file = request()->file('image');
  90. $savename = (new Filesystem(app()))->disk("aliyun")->putFile( 'patrolInspection', $file, 'uniqid');
  91. return $this->JsonSucess(["filename"=>$savename,"url"=>"https://ahwgh.oss-cn-hangzhou.aliyuncs.com/".$savename]);
  92. }
  93. /**
  94. * @Apidoc\Title("投入品照片上传")
  95. * @Apidoc\Tag("文件")
  96. * @Apidoc\Method ("POST")
  97. * @Apidoc\Author ("ihavoc")
  98. * @Route("inputUpload",method="POST")
  99. * @Middleware({})
  100. */
  101. public function inputUpload(): Json
  102. {
  103. $file = request()->file('image');
  104. $savename = (new Filesystem(app()))->disk("aliyun")->putFile( 'input', $file, 'uniqid');
  105. return $this->JsonSucess(["filename"=>$savename,"url"=>"https://ahwgh.oss-cn-hangzhou.aliyuncs.com/".$savename]);
  106. }
  107. }