Album.php 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com
  8. * =========================================================
  9. */
  10. namespace app\shop\controller;
  11. use app\model\system\Site;
  12. use app\model\upload\Album as AlbumModel;
  13. use app\model\web\Config as ConfigModel;
  14. use app\model\web\DiyView as DiyViewModel;
  15. /**
  16. * 相册
  17. * @package app\shop\controller
  18. */
  19. class Album extends BaseShop
  20. {
  21. public function __construct()
  22. {
  23. $this->app_module = input('app_module', SHOP_MODULE);
  24. if ($this->app_module == 'store') {
  25. $this->initConstructInfo(); // 加载构造函数重要信息
  26. } else {
  27. parent::__construct();
  28. }
  29. }
  30. /**
  31. * 图像
  32. */
  33. public function lists()
  34. {
  35. header("Expires:-1");
  36. header("Cache-Control:no_cache");
  37. header("Pragma:no-cache");
  38. $type = input('type', 'img');
  39. $album_model = new AlbumModel();
  40. if (request()->isAjax()) {
  41. $page = input('page', 1);
  42. $limit = input('limit', PAGE_LIST_ROWS);
  43. $album_id = input('album_id', '');
  44. $pic_name = input("pic_name", "");
  45. $order = input("order", "update_time desc");
  46. $condition = array (
  47. [ 'site_id', "=", $this->site_id ],
  48. [ 'album_id', "in", $album_id ],
  49. );
  50. if (!empty($pic_name)) {
  51. $condition[] = [ 'pic_name', 'like', '%' . $pic_name . '%' ];
  52. }
  53. $list = $album_model->getAlbumPicPageList($condition, $page, $limit, $order);
  54. return $list;
  55. } else {
  56. $album_list = $album_model->getAlbumList([ [ 'site_id', "=", $this->site_id ], [ 'type', '=', $type ] ]);
  57. $album_list_tree = $album_model->getAlbumListTree([ [ 'site_id', "=", $this->site_id ], [ 'type', '=', $type ] ]);
  58. $this->assign("album_list", $album_list[ 'data' ]);
  59. $this->assign("album_list_tree", $album_list_tree[ 'data' ]);
  60. $this->assign('type_list', $album_model->getType());
  61. $this->assign('type', $type);
  62. return $this->fetch('album/lists');
  63. }
  64. }
  65. /**
  66. * 获取相册分组
  67. */
  68. function getAlbumList()
  69. {
  70. if (request()->isAjax()) {
  71. $album_model = new AlbumModel();
  72. $type = input('type', 'img');
  73. $album_list = $album_model->getAlbumListTree([ [ 'site_id', "=", $this->site_id ], [ 'type', '=', $type ] ]);
  74. return $album_list;
  75. }
  76. }
  77. /**
  78. * 添加分组
  79. */
  80. public function addAlbum()
  81. {
  82. if (request()->isAjax()) {
  83. $album_name = input('album_name', '');
  84. $pid = input('pid', '0');
  85. $type = input('type', '0');
  86. $data = array (
  87. 'site_id' => $this->site_id,
  88. 'album_name' => $album_name,
  89. 'pid' => $pid,
  90. 'type' => $type,
  91. 'level' => empty($pid) ? 1 : 2
  92. );
  93. $album_model = new AlbumModel();
  94. $res = $album_model->addAlbum($data);
  95. return $res;
  96. }
  97. }
  98. /**
  99. * 修改分组
  100. */
  101. public function editAlbum()
  102. {
  103. if (request()->isAjax()) {
  104. $album_name = input('album_name');
  105. $album_id = input('album_id');
  106. $data = array (
  107. 'album_name' => $album_name
  108. );
  109. $condition = array (
  110. [ 'site_id', "=", $this->site_id ],
  111. [ 'album_id', "=", $album_id ]
  112. );
  113. $album_model = new AlbumModel();
  114. $res = $album_model->editAlbum($data, $condition);
  115. return $res;
  116. }
  117. }
  118. /**
  119. * 删除分组
  120. */
  121. public function deleteAlbum()
  122. {
  123. if (request()->isAjax()) {
  124. $album_id = input('album_id');
  125. $album_model = new AlbumModel();
  126. $condition = array (
  127. [ "album_id", "=", $album_id ],
  128. [ "site_id", "=", $this->site_id ]
  129. );
  130. $res = $album_model->deleteAlbum($condition);
  131. return $res;
  132. }
  133. }
  134. /**
  135. * 分组详情
  136. */
  137. public function albumInfo()
  138. {
  139. if (request()->isAjax()) {
  140. $album_id = input('album_id');
  141. $album_model = new AlbumModel();
  142. $condition = array (
  143. [ "album_id", "=", $album_id ],
  144. [ "site_id", "=", $this->site_id ]
  145. );
  146. $res = $album_model->getAlbumInfo($condition);
  147. return $res;
  148. }
  149. }
  150. /**
  151. * 修改文件名
  152. */
  153. public function modifyPicName()
  154. {
  155. if (request()->isAjax()) {
  156. $pic_id = input('pic_id', 0);
  157. $pic_name = input('pic_name', '');
  158. $album_id = input('album_id', 0);
  159. $album_model = new AlbumModel();
  160. $condition = array (
  161. [ "pic_id", "=", $pic_id ],
  162. [ "site_id", "=", $this->site_id ],
  163. [ 'album_id', '=', $album_id ]
  164. );
  165. $data = array (
  166. "pic_name" => $pic_name
  167. );
  168. $res = $album_model->editAlbumPic($data, $condition);
  169. return $res;
  170. }
  171. }
  172. /**
  173. * 修改图片分组
  174. */
  175. public function modifyFileAlbum()
  176. {
  177. if (request()->isAjax()) {
  178. $pic_id = input('pic_id', 0);//图片id
  179. $album_id = input('album_id', 0);//相册id
  180. $album_model = new AlbumModel();
  181. $condition = array (
  182. [ "pic_id", "in", $pic_id ],
  183. [ "site_id", "=", $this->site_id ]
  184. );
  185. $res = $album_model->modifyAlbumPicAlbum($album_id, $condition);
  186. return $res;
  187. }
  188. }
  189. /**
  190. * 删除图片
  191. */
  192. public function deleteFile()
  193. {
  194. if (request()->isAjax()) {
  195. $pic_id = input('pic_id', 0);//图片id
  196. $album_id = input('album_id', 0);
  197. $album_model = new AlbumModel();
  198. $condition = array (
  199. [ "pic_id", "in", $pic_id ],
  200. [ "site_id", "=", $this->site_id ],
  201. [ 'album_id', '=', $album_id ]
  202. );
  203. $res = $album_model->deleteAlbumPic($condition);
  204. return $res;
  205. }
  206. }
  207. /**
  208. * 相册管理界面
  209. * @return mixed
  210. */
  211. public function album()
  212. {
  213. $album_model = new AlbumModel();
  214. $type = input('type', 'img');
  215. $display_type = input('display_type', 'img');
  216. $is_thumb = input('is_thumb', 0);
  217. if (request()->isAjax()) {
  218. $page_index = input('page', 1);
  219. $list_rows = input('limit', PAGE_LIST_ROWS);
  220. $album_id = input('album_id', '');
  221. $pic_name = input("pic_name", "");
  222. $condition = array (
  223. [ 'site_id', "=", $this->site_id ],
  224. [ 'album_id', "in", $album_id ],
  225. );
  226. if (!empty($pic_name)) {
  227. $condition[] = [ 'pic_name', 'like', '%' . $pic_name . '%' ];
  228. }
  229. $list = $album_model->getAlbumPicPageList($condition, $page_index, $list_rows, 'update_time desc');
  230. return $list;
  231. } else {
  232. $album_list = $album_model->getAlbumList([ [ 'site_id', "=", $this->site_id ] ]);
  233. $this->assign("album_list", $album_list[ 'data' ]);
  234. $album_tree_list = $album_model->getAlbumListTree([ [ 'site_id', "=", $this->site_id ], [ 'type', '=', $type ] ]);
  235. $this->assign("album_tree_list", $album_tree_list[ 'data' ]);
  236. $this->assign('type_list', $album_model->getType());
  237. $this->assign('type', $type);
  238. $this->assign('display_type', $display_type);
  239. $this->assign('is_thumb', $is_thumb);
  240. return $this->fetch('album/album');
  241. }
  242. }
  243. /**
  244. * 生成缩略图
  245. */
  246. public function createThumb()
  247. {
  248. ignore_user_abort(true);
  249. if (request()->isAjax()) {
  250. $upload_model = new AlbumModel();
  251. $pic_ids = input('pic_ids', '');
  252. $thumb_batch = $upload_model->createThumbBatch($this->site_id, $pic_ids);
  253. return $thumb_batch;
  254. }
  255. }
  256. /**
  257. * 刷新相册数量
  258. */
  259. public function refreshAlbumNum()
  260. {
  261. ignore_user_abort(true);
  262. $upload_model = new AlbumModel();
  263. $upload_model->refreshAlbumNum($this->site_id);
  264. }
  265. }