Gallery.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2021 勾股工作室
  4. * @license https://opensource.org/licenses/Apache-2.0
  5. * @link https://www.gougucms.com
  6. */
  7. declare (strict_types = 1);
  8. namespace app\admin\controller;
  9. use app\admin\BaseController;
  10. use app\admin\model\Gallery as GalleryModel;
  11. use app\admin\validate\GalleryValidate;
  12. use think\exception\ValidateException;
  13. use think\facade\Db;
  14. use think\facade\View;
  15. class Gallery extends BaseController
  16. {
  17. /**
  18. * 构造函数
  19. */
  20. public function __construct()
  21. {
  22. $this->model = new GalleryModel();
  23. $this->uid = get_login_admin('id');
  24. }
  25. /**
  26. * 数据列表
  27. */
  28. public function datalist()
  29. {
  30. if (request()->isAjax()) {
  31. $param = get_params();
  32. $where = [];
  33. if (!empty($param['keywords'])) {
  34. $where[] = ['a.id|a.title|a.desc|c.title', 'like', '%' . $param['keywords'] . '%'];
  35. }
  36. if (!empty($param['cate_id'])) {
  37. $where[] = ['a.cate_id', '=', $param['cate_id']];
  38. }
  39. $where[] = ['a.delete_time', '=', 0];
  40. $list = $this->model->getGalleryList($where, $param);
  41. return table_assign(0, '', $list);
  42. }
  43. else{
  44. return view();
  45. }
  46. }
  47. /**
  48. * 添加
  49. */
  50. public function add()
  51. {
  52. if (request()->isAjax()) {
  53. $param = get_params();
  54. // 检验完整性
  55. try {
  56. validate(GalleryValidate::class)->check($param);
  57. } catch (ValidateException $e) {
  58. // 验证失败 输出错误信息
  59. return to_assign(1, $e->getError());
  60. }
  61. $param['admin_id'] = $this->uid;
  62. $this->model->addGallery($param);
  63. }else{
  64. return view();
  65. }
  66. }
  67. /**
  68. * 编辑
  69. */
  70. public function edit()
  71. {
  72. $param = get_params();
  73. if (request()->isAjax()) {
  74. // 检验完整性
  75. try {
  76. validate(GalleryValidate::class)->check($param);
  77. } catch (ValidateException $e) {
  78. // 验证失败 输出错误信息
  79. return to_assign(1, $e->getError());
  80. }
  81. $this->model->editGallery($param);
  82. }else{
  83. $id = isset($param['id']) ? $param['id'] : 0;
  84. $detail = $this->model->getGalleryById($id);
  85. if (!empty($detail)) {
  86. //关键字
  87. $keywrod_array = Db::name('GalleryKeywords')
  88. ->field('i.aid,i.keywords_id,k.title')
  89. ->alias('i')
  90. ->join('keywords k', 'k.id = i.keywords_id', 'LEFT')
  91. ->order('i.create_time asc')
  92. ->where(array('i.aid' => $id, 'k.status' => 1))
  93. ->select()->toArray();
  94. $detail['keyword_ids'] = implode(",", array_column($keywrod_array, 'keywords_id'));
  95. $detail['keyword_names'] = implode(',', array_column($keywrod_array, 'title'));
  96. $detail['keyword_array'] = $keywrod_array;
  97. //图集
  98. $gallery_array = Db::name('GalleryFile')
  99. ->order('create_time asc')
  100. ->where(array('aid' => $id))
  101. ->select()->toArray();
  102. $detail['gallery_array'] = $gallery_array;
  103. View::assign('detail', $detail);
  104. return view();
  105. }
  106. else{
  107. throw new \think\exception\HttpException(404, '找不到页面');
  108. }
  109. }
  110. }
  111. /**
  112. * 查看信息
  113. */
  114. public function read()
  115. {
  116. $param = get_params();
  117. $id = isset($param['id']) ? $param['id'] : 0;
  118. $detail = $this->model->getGalleryById($id);
  119. if (!empty($detail)) {
  120. //关键字
  121. $keywrod_array = Db::name('GalleryKeywords')
  122. ->field('i.aid,i.keywords_id,k.title')
  123. ->alias('i')
  124. ->join('keywords k', 'k.id = i.keywords_id', 'LEFT')
  125. ->order('i.create_time asc')
  126. ->where(array('i.aid' => $id, 'k.status' => 1))
  127. ->select()->toArray();
  128. $detail['keyword_ids'] = implode(",", array_column($keywrod_array, 'keywords_id'));
  129. $detail['keyword_names'] = implode(',', array_column($keywrod_array, 'title'));
  130. $detail['keyword_array'] = $keywrod_array;
  131. //图集
  132. $gallery_array = Db::name('GalleryFile')
  133. ->order('create_time asc')
  134. ->where(array('aid' => $id))
  135. ->select()->toArray();
  136. $detail['gallery_array'] = $gallery_array;
  137. View::assign('detail', $detail);
  138. return view();
  139. }
  140. else{
  141. throw new \think\exception\HttpException(404, '找不到页面');
  142. }
  143. }
  144. /**
  145. * 删除
  146. */
  147. public function del()
  148. {
  149. $param = get_params();
  150. $param = get_params();
  151. $id = isset($param['id']) ? $param['id'] : 0;
  152. $type = isset($param['type']) ? $param['type'] : 0;
  153. $this->model->delGalleryById($id,$type);
  154. }
  155. }