Upload.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 上海牛之云网络科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com
  8. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用。
  9. * 任何企业和个人不允许对程序代码以任何形式任何目的再发布。
  10. * =========================================================
  11. */
  12. namespace addon\store\shopapi\controller;
  13. use app\model\upload\Upload as UploadModel;
  14. /**
  15. * Class Upload
  16. * @package addon\shop\siteapi\controller
  17. */
  18. class Upload extends BaseStoreApi
  19. {
  20. /**
  21. * 上传(不存入相册)
  22. * @return false|string
  23. */
  24. public function image()
  25. {
  26. $site_id = $this->site_id;
  27. $upload_model = new UploadModel($site_id, $this->app_module);
  28. $thumb_type = isset($this->params[ 'thumb' ]) ? $this->params[ 'thumb' ] : '';
  29. $name = isset($this->params[ 'name' ]) ? $this->params[ 'name' ] : '';
  30. $watermark = isset($this->params[ 'watermark' ]) ? $this->params[ 'watermark' ] : 0;// 是否需生成水印
  31. $cloud = isset($this->params[ 'cloud' ]) ? $this->params[ 'cloud' ] : 1;// 是否需上传到云存储
  32. $width = isset($this->params[ 'width' ]) ? $this->params[ 'width' ] : 0;// 限制宽度
  33. $height = isset($this->params[ 'height' ]) ? $this->params[ 'height' ] : 0;// 限制高度
  34. $from = isset($this->params[ 'from' ]) ? $this->params[ 'from' ] : '';// 位置
  35. $param = array (
  36. "thumb_type" => "",
  37. "name" => "file",
  38. "watermark" => $watermark,
  39. "cloud" => $cloud,
  40. 'width' => $width,
  41. 'height' => $height,
  42. 'from' => $from
  43. );
  44. $result = $upload_model->setPath("common/images/" . date("Ymd") . '/')->image($param);
  45. return $this->response($result);
  46. }
  47. /**
  48. * 上传 存入相册
  49. * @return \multitype
  50. */
  51. public function album()
  52. {
  53. $upload_model = new UploadModel($this->site_id);
  54. $album_id = isset($this->params[ 'album_id' ]) ? $this->params[ 'album_id' ] : 0;
  55. $name = isset($this->params[ 'name' ]) ? $this->params[ 'name' ] : '';
  56. $param = array (
  57. "thumb_type" => [ "BIG", "MID", "SMALL" ],
  58. "name" => "file",
  59. "album_id" => $album_id
  60. );
  61. $result = $upload_model->setPath("common/images/" . date("Ymd") . '/')->imageToAlbum($param);
  62. return $this->response($result);
  63. }
  64. /**
  65. * 视频上传
  66. * @return \multitype
  67. */
  68. public function video()
  69. {
  70. $upload_model = new UploadModel($this->site_id);
  71. $name = isset($this->params[ 'name' ]) ? $this->params[ 'name' ] : '';
  72. $param = array (
  73. "name" => "file"
  74. );
  75. $result = $upload_model->setPath("common/video/" . date("Ymd") . '/')->video($param);
  76. return $this->response($this->success($result));
  77. }
  78. /**
  79. * 上传(不存入相册)
  80. * @return \app\model\upload\Ambigous|\multitype
  81. */
  82. public function upload()
  83. {
  84. $upload_model = new UploadModel();
  85. $name = isset($this->params[ 'name' ]) ? $this->params[ 'name' ] : '';
  86. $thumb_type = isset($this->params[ 'thumb' ]) ? $this->params[ 'thumb' ] : '';
  87. $param = array (
  88. "thumb_type" => "",
  89. "name" => "file"
  90. );
  91. $result = $upload_model->setPath("common/images/" . date("Ymd") . '/')->image($param);
  92. return $this->response($this->success($result));
  93. }
  94. /**
  95. * 校验文件
  96. */
  97. public function checkfile()
  98. {
  99. $upload_model = new UploadModel();
  100. $result = $upload_model->domainCheckFile([ "name" => "file" ]);
  101. return $this->response($result);
  102. }
  103. /**
  104. * 上传文件
  105. */
  106. public function file()
  107. {
  108. $upload_model = new UploadModel($this->site_id);
  109. $param = array (
  110. "name" => "file",
  111. 'extend_type' => [ 'xlsx', 'pdf' ]
  112. );
  113. $result = $upload_model->setPath("common/file/" . date("Ymd") . '/')->file($param);
  114. return $this->response($this->success($result));
  115. }
  116. /**
  117. * 删除文件
  118. */
  119. public function deleteFile()
  120. {
  121. if (request()->isAjax()) {
  122. $path = isset($this->params[ 'path' ]) ? $this->params[ 'path' ] : '';
  123. $res = false;
  124. if (!empty($path)) {
  125. $res = delFile($path);
  126. }
  127. return $this->response($this->success($res));
  128. }
  129. }
  130. /**
  131. * 上传微信支付证书
  132. */
  133. public function uploadWechatCert()
  134. {
  135. $upload_model = new UploadModel();
  136. $site_id = $this->site_id;
  137. $name = isset($this->params[ 'name' ]) ? $this->params[ 'name' ] : '';
  138. $extend_type = [ 'pem' ];
  139. $param = array (
  140. "name" => "file",
  141. "extend_type" => $extend_type
  142. );
  143. $site_id = $site_id > 0 ? $site_id : 0;
  144. $result = $upload_model->setPath("common/wechat/cert/" . $site_id . "/")->file($param);
  145. return $this->response($this->success($result));
  146. }
  147. /**
  148. * 退款退货凭证上传
  149. */
  150. public function refundMessageImg()
  151. {
  152. $upload_model = new UploadModel($this->site_id);
  153. $param = array (
  154. "thumb_type" => "",
  155. "name" => "file",
  156. "watermark" => 0,
  157. "cloud" => 1
  158. );
  159. $result = $upload_model->setPath("refund/refund_message/" . date("Ymd") . '/')->image($param);
  160. return $this->response($result);
  161. }
  162. }