Uploadfiy.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | A3Mall
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2020 http://www.a3-mall.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Author: xzncit <158373108@qq.com>
  8. // +----------------------------------------------------------------------
  9. namespace app\admin\controller\common;
  10. use app\admin\controller\Auth;
  11. use think\facade\Request;
  12. use mall\response\Response;
  13. use app\admin\service\common\Uploadfiy as UploadfiyService;
  14. use app\common\models\Attachments as AttachmentsModel;
  15. /**
  16. * 上传控制器类
  17. * Class Uploadfiy
  18. * @package app\admin\controller\common
  19. */
  20. class Uploadfiy extends Auth {
  21. /**
  22. * 上传附件
  23. * @return \think\response\Json
  24. */
  25. public function upload(){
  26. try{
  27. $dataInfo = UploadfiyService::upload(
  28. "file",
  29. Request::param("isthumb","1","intval"),
  30. "public",
  31. ["jpg","png","gif","jpeg","bmp"]
  32. );
  33. $id = AttachmentsModel::create(array_merge($dataInfo,[
  34. "module"=>Request::param("module","","trim,strip_tags"),
  35. "method"=>Request::param("method","","trim,strip_tags"),
  36. "cat_id"=>Request::param("cat_id",0,"intval")
  37. ]))->id;
  38. return Response::returnArray("ok",0,["src"=>'/'.trim($dataInfo["path"],"/"),"id"=>$id]);
  39. }catch (\Exception $ex){
  40. return Response::returnArray($ex->getMessage(),1);
  41. }
  42. }
  43. /**
  44. * 上传证书
  45. * @return \think\response\Json
  46. */
  47. public function file(){
  48. try{
  49. $dataInfo = UploadfiyService::upload(
  50. "file",
  51. false,
  52. "certificate",
  53. ["pem","crt"]
  54. );
  55. $id = AttachmentsModel::create(array_merge($dataInfo,[
  56. "module"=>Request::param("module","","trim,strip_tags"),
  57. "method"=>Request::param("method","","trim,strip_tags"),
  58. "cat_id"=>Request::param("cat_id",0,"intval")
  59. ]))->id;
  60. return Response::returnArray("ok",0,["src"=>'/'.trim($dataInfo["path"],"/"),"id"=>$id]);
  61. }catch (\Exception $ex){
  62. return Response::returnArray($ex->getMessage(),1);
  63. }
  64. }
  65. /**
  66. * 删除附件
  67. * @return \think\response\Json
  68. * @throws \think\db\exception\DataNotFoundException
  69. * @throws \think\db\exception\DbException
  70. * @throws \think\db\exception\ModelNotFoundException
  71. */
  72. public function delete(){
  73. try{
  74. UploadfiyService::delete(Request::post("path","","strip_tags,trim"));
  75. return Response::returnArray("删除成功");
  76. }catch (\Exception $ex){
  77. return Response::returnArray($ex->getMessage(),0);
  78. }
  79. }
  80. }