心理咨询网
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SlideController.php 6.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. <?php
  2. /**
  3. * @copyright (C)2016-2099 Hnaoyun Inc.
  4. * @author XingMeng
  5. * @email hnxsh@foxmail.com
  6. * @date 2018年3月1日
  7. * 轮播图控制器
  8. */
  9. namespace app\admin\controller\content;
  10. use core\basic\Controller;
  11. use app\admin\model\content\SlideModel;
  12. class SlideController extends Controller
  13. {
  14. private $model;
  15. public function __construct()
  16. {
  17. $this->model = new SlideModel();
  18. }
  19. // 轮播图列表
  20. public function index()
  21. {
  22. if ((! ! $id = get('id', 'int')) && $result = $this->model->getSlide($id)) {
  23. $this->assign('more', true);
  24. $this->assign('slide', $result);
  25. } else {
  26. $this->assign('list', true);
  27. if (! ! ($field = get('field', 'var')) && ! ! ($keyword = get('keyword', 'vars'))) {
  28. $result = $this->model->findSlide($field, $keyword);
  29. } else {
  30. $result = $this->model->getList();
  31. }
  32. $this->assign('gids', $this->model->getGid());
  33. $this->assign('slides', $result);
  34. }
  35. $this->display('content/slide.html');
  36. }
  37. // 轮播图增加
  38. public function add()
  39. {
  40. if ($_POST) {
  41. // 获取数据
  42. $gid = post('gid', 'int');
  43. $pic = post('pic');
  44. $link = post('link');
  45. $title = post('title');
  46. $subtitle = post('subtitle');
  47. $sorting = post('sorting', 'int');
  48. if (! $gid) {
  49. $gid = $this->model->getMaxGid() + 1;
  50. }
  51. if (! $pic) {
  52. alert_back('图片不能为空!');
  53. }
  54. // 构建数据
  55. $data = array(
  56. 'acode' => session('acode'),
  57. 'gid' => $gid,
  58. 'pic' => $pic,
  59. 'link' => $link,
  60. 'title' => $title,
  61. 'subtitle' => $subtitle,
  62. 'sorting' => $sorting,
  63. 'create_user' => session('username'),
  64. 'update_user' => session('username')
  65. );
  66. // 执行添加
  67. if ($this->model->addSlide($data)) {
  68. $this->log('新增轮播图成功!');
  69. if (! ! $backurl = get('backurl')) {
  70. success('新增成功!', base64_decode($backurl));
  71. } else {
  72. success('新增成功!', url('/admin/Slide/index'));
  73. }
  74. } else {
  75. $this->log('新增轮播图失败!');
  76. error('新增失败!', - 1);
  77. }
  78. }
  79. }
  80. // 轮播图删除
  81. public function del()
  82. {
  83. if (! $id = get('id', 'int')) {
  84. error('传递的参数值错误!', - 1);
  85. }
  86. if ($this->model->delSlide($id)) {
  87. $this->log('删除轮播图' . $id . '成功!');
  88. success('删除成功!', - 1);
  89. } else {
  90. $this->log('删除轮播图' . $id . '失败!');
  91. error('删除失败!', - 1);
  92. }
  93. }
  94. // 轮播图修改
  95. public function mod()
  96. {
  97. if (! ! $submit = post('submit')) {
  98. switch ($submit) {
  99. case 'sorting': // 修改列表排序
  100. $listall = post('listall');
  101. if ($listall) {
  102. $sorting = post('sorting');
  103. foreach ($listall as $key => $value) {
  104. if ($sorting[$key] === '' || ! is_numeric($sorting[$key]))
  105. $sorting[$key] = 255;
  106. $this->model->modSlide($value, "sorting=" . $sorting[$key]);
  107. }
  108. $this->log('批量修改轮播图排序成功!');
  109. success('修改成功!', - 1);
  110. } else {
  111. alert_back('排序失败,无任何内容!');
  112. }
  113. break;
  114. }
  115. }
  116. if (! $id = get('id', 'int')) {
  117. error('传递的参数值错误!', - 1);
  118. }
  119. // 单独修改状态
  120. if (($field = get('field', 'var')) && ! is_null($value = get('value', 'var'))) {
  121. if ($this->model->modSlide($id, "$field='$value',update_user='" . session('username') . "'")) {
  122. location(- 1);
  123. } else {
  124. alert_back('修改失败!');
  125. }
  126. }
  127. // 修改操作
  128. if ($_POST) {
  129. // 获取数据
  130. $gid = post('gid', 'int');
  131. $pic = post('pic');
  132. $link = post('link');
  133. $title = post('title');
  134. $subtitle = post('subtitle');
  135. $sorting = post('sorting', 'int');
  136. if (! $gid) {
  137. $gid = $this->model->getMaxGid() + 1;
  138. }
  139. if (! $pic) {
  140. alert_back('图片不能为空!');
  141. }
  142. // 构建数据
  143. $data = array(
  144. 'gid' => $gid,
  145. 'pic' => $pic,
  146. 'link' => $link,
  147. 'title' => $title,
  148. 'subtitle' => $subtitle,
  149. 'sorting' => $sorting,
  150. 'update_user' => session('username')
  151. );
  152. // 执行添加
  153. if ($this->model->modSlide($id, $data)) {
  154. $this->log('修改轮播图' . $id . '成功!');
  155. if (! ! $backurl = get('backurl')) {
  156. success('修改成功!', base64_decode($backurl));
  157. } else {
  158. success('修改成功!', url('/admin/Slide/index'));
  159. }
  160. } else {
  161. location(- 1);
  162. }
  163. } else {
  164. // 调取修改内容
  165. $this->assign('mod', true);
  166. if (! $result = $this->model->getSlide($id)) {
  167. error('编辑的内容已经不存在!', - 1);
  168. }
  169. $this->assign('gids', $this->model->getGid());
  170. $this->assign('slide', $result);
  171. $this->display('content/slide.html');
  172. }
  173. }
  174. }