123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322 |
- <?php
- // +—————————————————————————————————————————————————————————————————————
- // | Created by Yunbao
- // +—————————————————————————————————————————————————————————————————————
- // | Copyright (c) 2013~2022 http://www.yunbaokj.com All rights reserved.
- // +—————————————————————————————————————————————————————————————————————
- // | Author: https://gitee.com/yunbaokeji
- // +—————————————————————————————————————————————————————————————————————
- // | Date: 2022-02-17
- // +—————————————————————————————————————————————————————————————————————
- namespace app\admin\controller;
- use think\Db;
- use cmf\controller\AdminBaseController;
- use app\admin\model\SlideItemModel;
- class SlideItemController extends AdminBaseController
- {
- /**
- * 幻灯片页面列表
- * @adminMenu(
- * 'name' => '幻灯片页面列表',
- * 'parent' => 'admin/Slide/index',
- * 'display'=> false,
- * 'hasView'=> true,
- * 'order' => 10000,
- * 'icon' => '',
- * 'remark' => '幻灯片页面列表',
- * 'param' => ''
- * )
- * @return mixed
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function index()
- {
- $content = hook_one('admin_slide_item_index_view');
- if (!empty($content)) {
- return $content;
- }
- $id = $this->request->param('slide_id', 0, 'intval');
- $slideId = !empty($id) ? $id : 1;
- $result = Db::name('slideItem')->where('slide_id', $slideId)->select();
- $this->assign('slide_id', $id);
- $this->assign('result', $result);
- return $this->fetch();
- }
- /**
- * 幻灯片页面添加
- * @adminMenu(
- * 'name' => '幻灯片页面添加',
- * 'parent' => 'index',
- * 'display'=> false,
- * 'hasView'=> true,
- * 'order' => 10000,
- * 'icon' => '',
- * 'remark' => '幻灯片页面添加',
- * 'param' => ''
- * )
- */
- public function add()
- {
- $content = hook_one('admin_slide_item_add_view');
- if (!empty($content)) {
- return $content;
- }
- $slideId = $this->request->param('slide_id');
- $this->assign('slide_id', $slideId);
- return $this->fetch();
- }
- /**
- * 幻灯片页面添加提交
- * @adminMenu(
- * 'name' => '幻灯片页面添加提交',
- * 'parent' => 'index',
- * 'display'=> false,
- * 'hasView'=> false,
- * 'order' => 10000,
- * 'icon' => '',
- * 'remark' => '幻灯片页面添加提交',
- * 'param' => ''
- * )
- */
- public function addPost()
- {
- $data = $this->request->param();
- $id=Db::name('slideItem')->insertGetId($data['post']);
-
- $this->resetcache();
- $this->resetShopcache();
-
-
-
- $this->success("添加成功!", url("slideItem/index", ['slide_id' => $data['post']['slide_id']]));
- }
- /**
- * 幻灯片页面编辑
- * @adminMenu(
- * 'name' => '幻灯片页面编辑',
- * 'parent' => 'index',
- * 'display'=> false,
- * 'hasView'=> true,
- * 'order' => 10000,
- * 'icon' => '',
- * 'remark' => '幻灯片页面编辑',
- * 'param' => ''
- * )
- */
- public function edit()
- {
- $content = hook_one('admin_slide_item_edit_view');
- if (!empty($content)) {
- return $content;
- }
- $id = $this->request->param('id', 0, 'intval');
- $result = Db::name('slideItem')->where('id', $id)->find();
- $this->assign('result', $result);
- $this->assign('slide_id', $result['slide_id']);
- return $this->fetch();
- }
- /**
- * 幻灯片页面编辑
- * @adminMenu(
- * 'name' => '幻灯片页面编辑提交',
- * 'parent' => 'index',
- * 'display'=> false,
- * 'hasView'=> false,
- * 'order' => 10000,
- * 'icon' => '',
- * 'remark' => '幻灯片页面编辑提交',
- * 'param' => ''
- * )
- */
- public function editPost()
- {
- $data = $this->request->param();
- $data['post']['image'] = cmf_asset_relative_url($data['post']['image']);
- Db::name('slideItem')->update($data['post']);
-
- $this->resetcache();
- $this->resetShopcache();
-
-
- $this->success("保存成功!", url("SlideItem/index", ['slide_id' => $data['post']['slide_id']]));
- }
- /**
- * 幻灯片页面删除
- * @adminMenu(
- * 'name' => '幻灯片页面删除',
- * 'parent' => 'index',
- * 'display'=> false,
- * 'hasView'=> false,
- * 'order' => 10000,
- * 'icon' => '',
- * 'remark' => '幻灯片页面删除',
- * 'param' => ''
- * )
- */
- public function delete()
- {
- $id = $this->request->param('id', 0, 'intval');
- $slideItem = Db::name('slideItem')->find($id);
- $result = Db::name('slideItem')->delete($id);
- if ($result) {
- $this->resetcache();
- $this->resetShopcache();
- //删除图片。
- // if (file_exists("./upload/".$slideItem['image'])){
- // }
-
- $this->success("删除成功!", url("SlideItem/index", ["slide_id" => $slideItem['slide_id']]));
- } else {
- $this->error('删除失败!');
- }
- }
- /**
- * 幻灯片页面隐藏
- * @adminMenu(
- * 'name' => '幻灯片页面隐藏',
- * 'parent' => 'index',
- * 'display'=> false,
- * 'hasView'=> false,
- * 'order' => 10000,
- * 'icon' => '',
- * 'remark' => '幻灯片页面隐藏',
- * 'param' => ''
- * )
- */
- public function ban()
- {
- $id = $this->request->param('id', 0, 'intval');
- if ($id) {
- $slideItem = Db::name('slideItem')->find($id);
- $rst = Db::name('slideItem')->where('id', $id)->update(['status' => 0]);
- if ($rst) {
- $this->resetcache();
- $this->resetShopcache();
-
-
-
-
-
- $this->success("幻灯片隐藏成功!");
- } else {
- $this->error('幻灯片隐藏失败!');
- }
- } else {
- $this->error('数据传入失败!');
- }
- }
- /**
- * 幻灯片页面显示
- * @adminMenu(
- * 'name' => '幻灯片页面显示',
- * 'parent' => 'index',
- * 'display'=> false,
- * 'hasView'=> false,
- * 'order' => 10000,
- * 'icon' => '',
- * 'remark' => '幻灯片页面显示',
- * 'param' => ''
- * )
- */
- public function cancelBan()
- {
- $id = $this->request->param('id', 0, 'intval');
- if ($id) {
- $slideItem = Db::name('slideItem')->find($id);
- $result = Db::name('slideItem')->where('id', $id)->update(['status' => 1]);
- if ($result) {
- $this->resetcache();
- $this->resetShopcache();
-
-
-
- $this->success("幻灯片启用成功!");
- } else {
- $this->error('幻灯片启用失败!');
- }
- } else {
- $this->error('数据传入失败!');
- }
- }
- /**
- * 幻灯片页面排序
- * @adminMenu(
- * 'name' => '幻灯片页面排序',
- * 'parent' => 'index',
- * 'display'=> false,
- * 'hasView'=> false,
- * 'order' => 10000,
- * 'icon' => '',
- * 'remark' => '幻灯片页面排序',
- * 'param' => ''
- * )
- */
- public function listOrder()
- {
- $slideItemModel = new SlideItemModel();
- parent::listOrders($slideItemModel);
- $this->resetcache();
- $this->resetShopcache();
-
-
- $this->success("排序更新成功!");
- }
-
- function resetcache(){
- $key='getSlide';
- $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();
- if($rs){
- foreach($rs as $k=>$v){
- $rs[$k]['slide_pic']=get_upload_path($v['slide_pic']);
- }
- setcaches($key,$rs);
- }else{
- delcache($key);
- }
- return 1;
- }
-
- function resetShopcache(){
- $key='getShopSlide';
- $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();
- if($rs){
- foreach($rs as $k=>$v){
- $rs[$k]['slide_pic']=get_upload_path($v['slide_pic']);
- }
- setcaches($key,$rs);
- }else{
- delcache($key);
- }
- return 1;
- }
- }
|