Upload.php 5.7 KB

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