Album.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com
  8. * =========================================================
  9. */
  10. namespace app\shopapi\controller;
  11. use app\model\upload\Album as AlbumModel;
  12. /**
  13. * 相册
  14. * Class Album
  15. * @package app\shopapi\controller
  16. */
  17. class Album extends BaseApi
  18. {
  19. public function __construct()
  20. {
  21. //执行父类构造函数
  22. parent::__construct();
  23. $token = $this->checkToken();
  24. if ($token[ 'code' ] < 0) {
  25. echo $this->response($token);
  26. exit;
  27. }
  28. }
  29. /**
  30. * 获取相册分组
  31. * @return false|string
  32. */
  33. public function lists()
  34. {
  35. $album_model = new AlbumModel();
  36. $type = $this->params['type'] ?? 'img';
  37. $album_list = $album_model->getAlbumListTree([ [ 'site_id', "=", $this->site_id ], ['type', '=', $type] ]);
  38. return $this->response($album_list);
  39. }
  40. /**
  41. * 获取图片列表
  42. * @return false|string
  43. */
  44. public function picList()
  45. {
  46. $page = isset($this->params[ 'page' ]) ? $this->params[ 'page' ] : 1;
  47. $limit = isset($this->params[ 'page_size' ]) ? $this->params[ 'page_size' ] : PAGE_LIST_ROWS;
  48. $album_id = isset($this->params[ 'album_id' ]) ? $this->params[ 'album_id' ] : 0;
  49. $album_model = new AlbumModel();
  50. $condition = array (
  51. [ 'site_id', "=", $this->site_id ],
  52. [ 'album_id', "=", $album_id ],
  53. );
  54. if (!empty($pic_name)) {
  55. $condition[] = [ 'pic_name', 'like', '%' . $pic_name . '%' ];
  56. }
  57. $list = $album_model->getAlbumPicPageList($condition, $page, $limit, 'update_time desc','pic_path');
  58. return $this->response($list);
  59. }
  60. /**
  61. * 生成缩略图
  62. */
  63. public function createThumb()
  64. {
  65. ignore_user_abort(true);
  66. $upload_model = new AlbumModel();
  67. $pic_path = isset($this->params[ 'pic_path' ]) ? $this->params[ 'pic_path' ] : '';
  68. $pic_ids = $upload_model->getAlbumPicList([ ['pic_path', 'in', $pic_path], ['site_id', '=', $this->site_id] ], 'pic_id')['data'] ?? [];
  69. $pic_ids = array_column($pic_ids, 'pic_id');
  70. $thumb_batch = $upload_model->createThumbBatch($this->site_id, $pic_ids);
  71. return $this->response($thumb_batch);
  72. }
  73. }