SlideItemController.php 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. <?php
  2. // +—————————————————————————————————————————————————————————————————————
  3. // | Created by Yunbao
  4. // +—————————————————————————————————————————————————————————————————————
  5. // | Copyright (c) 2013~2022 http://www.yunbaokj.com All rights reserved.
  6. // +—————————————————————————————————————————————————————————————————————
  7. // | Author: https://gitee.com/yunbaokeji
  8. // +—————————————————————————————————————————————————————————————————————
  9. // | Date: 2022-02-17
  10. // +—————————————————————————————————————————————————————————————————————
  11. namespace app\admin\controller;
  12. use think\Db;
  13. use cmf\controller\AdminBaseController;
  14. use app\admin\model\SlideItemModel;
  15. class SlideItemController extends AdminBaseController
  16. {
  17. /**
  18. * 幻灯片页面列表
  19. * @adminMenu(
  20. * 'name' => '幻灯片页面列表',
  21. * 'parent' => 'admin/Slide/index',
  22. * 'display'=> false,
  23. * 'hasView'=> true,
  24. * 'order' => 10000,
  25. * 'icon' => '',
  26. * 'remark' => '幻灯片页面列表',
  27. * 'param' => ''
  28. * )
  29. * @return mixed
  30. * @throws \think\db\exception\DataNotFoundException
  31. * @throws \think\db\exception\ModelNotFoundException
  32. * @throws \think\exception\DbException
  33. */
  34. public function index()
  35. {
  36. $content = hook_one('admin_slide_item_index_view');
  37. if (!empty($content)) {
  38. return $content;
  39. }
  40. $id = $this->request->param('slide_id', 0, 'intval');
  41. $slideId = !empty($id) ? $id : 1;
  42. $result = Db::name('slideItem')->where('slide_id', $slideId)->select();
  43. $this->assign('slide_id', $id);
  44. $this->assign('result', $result);
  45. return $this->fetch();
  46. }
  47. /**
  48. * 幻灯片页面添加
  49. * @adminMenu(
  50. * 'name' => '幻灯片页面添加',
  51. * 'parent' => 'index',
  52. * 'display'=> false,
  53. * 'hasView'=> true,
  54. * 'order' => 10000,
  55. * 'icon' => '',
  56. * 'remark' => '幻灯片页面添加',
  57. * 'param' => ''
  58. * )
  59. */
  60. public function add()
  61. {
  62. $content = hook_one('admin_slide_item_add_view');
  63. if (!empty($content)) {
  64. return $content;
  65. }
  66. $slideId = $this->request->param('slide_id');
  67. $this->assign('slide_id', $slideId);
  68. return $this->fetch();
  69. }
  70. /**
  71. * 幻灯片页面添加提交
  72. * @adminMenu(
  73. * 'name' => '幻灯片页面添加提交',
  74. * 'parent' => 'index',
  75. * 'display'=> false,
  76. * 'hasView'=> false,
  77. * 'order' => 10000,
  78. * 'icon' => '',
  79. * 'remark' => '幻灯片页面添加提交',
  80. * 'param' => ''
  81. * )
  82. */
  83. public function addPost()
  84. {
  85. $data = $this->request->param();
  86. $id=Db::name('slideItem')->insertGetId($data['post']);
  87. $this->resetcache();
  88. $this->resetShopcache();
  89. $this->success("添加成功!", url("slideItem/index", ['slide_id' => $data['post']['slide_id']]));
  90. }
  91. /**
  92. * 幻灯片页面编辑
  93. * @adminMenu(
  94. * 'name' => '幻灯片页面编辑',
  95. * 'parent' => 'index',
  96. * 'display'=> false,
  97. * 'hasView'=> true,
  98. * 'order' => 10000,
  99. * 'icon' => '',
  100. * 'remark' => '幻灯片页面编辑',
  101. * 'param' => ''
  102. * )
  103. */
  104. public function edit()
  105. {
  106. $content = hook_one('admin_slide_item_edit_view');
  107. if (!empty($content)) {
  108. return $content;
  109. }
  110. $id = $this->request->param('id', 0, 'intval');
  111. $result = Db::name('slideItem')->where('id', $id)->find();
  112. $this->assign('result', $result);
  113. $this->assign('slide_id', $result['slide_id']);
  114. return $this->fetch();
  115. }
  116. /**
  117. * 幻灯片页面编辑
  118. * @adminMenu(
  119. * 'name' => '幻灯片页面编辑提交',
  120. * 'parent' => 'index',
  121. * 'display'=> false,
  122. * 'hasView'=> false,
  123. * 'order' => 10000,
  124. * 'icon' => '',
  125. * 'remark' => '幻灯片页面编辑提交',
  126. * 'param' => ''
  127. * )
  128. */
  129. public function editPost()
  130. {
  131. $data = $this->request->param();
  132. $data['post']['image'] = cmf_asset_relative_url($data['post']['image']);
  133. Db::name('slideItem')->update($data['post']);
  134. $this->resetcache();
  135. $this->resetShopcache();
  136. $this->success("保存成功!", url("SlideItem/index", ['slide_id' => $data['post']['slide_id']]));
  137. }
  138. /**
  139. * 幻灯片页面删除
  140. * @adminMenu(
  141. * 'name' => '幻灯片页面删除',
  142. * 'parent' => 'index',
  143. * 'display'=> false,
  144. * 'hasView'=> false,
  145. * 'order' => 10000,
  146. * 'icon' => '',
  147. * 'remark' => '幻灯片页面删除',
  148. * 'param' => ''
  149. * )
  150. */
  151. public function delete()
  152. {
  153. $id = $this->request->param('id', 0, 'intval');
  154. $slideItem = Db::name('slideItem')->find($id);
  155. $result = Db::name('slideItem')->delete($id);
  156. if ($result) {
  157. $this->resetcache();
  158. $this->resetShopcache();
  159. //删除图片。
  160. // if (file_exists("./upload/".$slideItem['image'])){
  161. // }
  162. $this->success("删除成功!", url("SlideItem/index", ["slide_id" => $slideItem['slide_id']]));
  163. } else {
  164. $this->error('删除失败!');
  165. }
  166. }
  167. /**
  168. * 幻灯片页面隐藏
  169. * @adminMenu(
  170. * 'name' => '幻灯片页面隐藏',
  171. * 'parent' => 'index',
  172. * 'display'=> false,
  173. * 'hasView'=> false,
  174. * 'order' => 10000,
  175. * 'icon' => '',
  176. * 'remark' => '幻灯片页面隐藏',
  177. * 'param' => ''
  178. * )
  179. */
  180. public function ban()
  181. {
  182. $id = $this->request->param('id', 0, 'intval');
  183. if ($id) {
  184. $slideItem = Db::name('slideItem')->find($id);
  185. $rst = Db::name('slideItem')->where('id', $id)->update(['status' => 0]);
  186. if ($rst) {
  187. $this->resetcache();
  188. $this->resetShopcache();
  189. $this->success("幻灯片隐藏成功!");
  190. } else {
  191. $this->error('幻灯片隐藏失败!');
  192. }
  193. } else {
  194. $this->error('数据传入失败!');
  195. }
  196. }
  197. /**
  198. * 幻灯片页面显示
  199. * @adminMenu(
  200. * 'name' => '幻灯片页面显示',
  201. * 'parent' => 'index',
  202. * 'display'=> false,
  203. * 'hasView'=> false,
  204. * 'order' => 10000,
  205. * 'icon' => '',
  206. * 'remark' => '幻灯片页面显示',
  207. * 'param' => ''
  208. * )
  209. */
  210. public function cancelBan()
  211. {
  212. $id = $this->request->param('id', 0, 'intval');
  213. if ($id) {
  214. $slideItem = Db::name('slideItem')->find($id);
  215. $result = Db::name('slideItem')->where('id', $id)->update(['status' => 1]);
  216. if ($result) {
  217. $this->resetcache();
  218. $this->resetShopcache();
  219. $this->success("幻灯片启用成功!");
  220. } else {
  221. $this->error('幻灯片启用失败!');
  222. }
  223. } else {
  224. $this->error('数据传入失败!');
  225. }
  226. }
  227. /**
  228. * 幻灯片页面排序
  229. * @adminMenu(
  230. * 'name' => '幻灯片页面排序',
  231. * 'parent' => 'index',
  232. * 'display'=> false,
  233. * 'hasView'=> false,
  234. * 'order' => 10000,
  235. * 'icon' => '',
  236. * 'remark' => '幻灯片页面排序',
  237. * 'param' => ''
  238. * )
  239. */
  240. public function listOrder()
  241. {
  242. $slideItemModel = new SlideItemModel();
  243. parent::listOrders($slideItemModel);
  244. $this->resetcache();
  245. $this->resetShopcache();
  246. $this->success("排序更新成功!");
  247. }
  248. function resetcache(){
  249. $key='getSlide';
  250. $rs=Db::name("slideItem")->field("image as slide_pic,url as slide_url")->where("status='1' and slide_id='2' ")->order("list_order asc")->select()->toArray();
  251. if($rs){
  252. foreach($rs as $k=>$v){
  253. $rs[$k]['slide_pic']=get_upload_path($v['slide_pic']);
  254. }
  255. setcaches($key,$rs);
  256. }else{
  257. delcache($key);
  258. }
  259. return 1;
  260. }
  261. function resetShopcache(){
  262. $key='getShopSlide';
  263. $rs=Db::name("slideItem")->field("image as slide_pic,url as slide_url")->where("status='1' and slide_id='5' ")->order("list_order asc")->select()->toArray();
  264. if($rs){
  265. foreach($rs as $k=>$v){
  266. $rs[$k]['slide_pic']=get_upload_path($v['slide_pic']);
  267. }
  268. setcaches($key,$rs);
  269. }else{
  270. delcache($key);
  271. }
  272. return 1;
  273. }
  274. }