GuideController.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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. /**
  12. * 引导页
  13. */
  14. namespace app\admin\controller;
  15. use cmf\controller\AdminBaseController;
  16. use think\Db;
  17. class GuideController extends AdminbaseController {
  18. public function set(){
  19. $config=DB::name("option")->where("option_name='guide'")->value("option_value");
  20. $this->assign('config',json_decode($config,true) );
  21. return $this->fetch();
  22. }
  23. public function setPost(){
  24. if ($this->request->isPost()) {
  25. $config = $this->request->param('post/a');
  26. $time=$config['time'];
  27. if(!$time||$time<1){
  28. $this->error("图片展示时间错误");
  29. }
  30. if(floor($time)!=$time){
  31. $this->error("图片展示时间错误");
  32. }
  33. //查询已存在的内容
  34. $info=DB::name("option")->where("option_name='guide'")->value("option_value");
  35. $rs = DB::name('option')->where("option_name='guide'")->update(['option_value'=>json_encode($config)] );
  36. if($rs===false){
  37. $this->error("保存失败!");
  38. }
  39. if($info){
  40. $option_value=json_decode($info,true);
  41. }
  42. $this->success("保存成功!");
  43. }
  44. }
  45. public function index(){
  46. $config=DB::name("option")->where("option_name='guide'")->value("option_value");
  47. $config = json_decode($config,true);
  48. $type=$config['type'];
  49. $map['type']=$type;
  50. $lists = Db::name("guide")
  51. ->where($map)
  52. ->order("list_order asc, id desc")
  53. ->paginate(20);
  54. $lists->each(function($v,$k){
  55. $v['thumb']=get_upload_path($v['thumb']);
  56. return $v;
  57. });
  58. $page = $lists->render();
  59. $this->assign('lists', $lists);
  60. $this->assign("page", $page);
  61. $this->assign('type', $type);
  62. return $this->fetch();
  63. }
  64. public function del(){
  65. $id = $this->request->param('id', 0, 'intval');
  66. $rs = DB::name('guide')->where("id={$id}")->delete();
  67. if(!$rs){
  68. $this->error("删除失败!");
  69. }
  70. $this->success("删除成功!");
  71. }
  72. //排序
  73. public function listOrder() {
  74. $model = DB::name('guide');
  75. parent::listOrders($model);
  76. $this->success("排序更新成功!");
  77. }
  78. public function add(){
  79. $config=DB::name("option")->where("option_name='guide'")->value("option_value");
  80. $config = json_decode($config,true);
  81. $type=$config['type'];
  82. if($type==1){
  83. $map['type']=$type;
  84. $count=DB::name("guide")->where($map)->count();
  85. if($count>=1){
  86. $this->error("引导页视频只能存在一个");
  87. }
  88. }
  89. $this->assign('type', $type);
  90. return $this->fetch();
  91. }
  92. public function addPost(){
  93. if ($this->request->isPost()) {
  94. $data = $this->request->param();
  95. $thumb=$data['thumb'];
  96. if(!$thumb){
  97. $this->error("请上传引导页图片/视频");
  98. }
  99. $data['href']=html_entity_decode($data['href']);
  100. $data['addtime']=time();
  101. $data['uptime']=time();
  102. $id = DB::name('guide')->insertGetId($data);
  103. if(!$id){
  104. $this->error("添加失败!");
  105. }
  106. $this->success("添加成功!");
  107. }
  108. }
  109. public function edit(){
  110. $id = $this->request->param('id', 0, 'intval');
  111. $data=Db::name('guide')
  112. ->where("id={$id}")
  113. ->find();
  114. if(!$data){
  115. $this->error("信息错误");
  116. }
  117. $this->assign('data', $data);
  118. return $this->fetch();
  119. }
  120. public function editPost(){
  121. if ($this->request->isPost()) {
  122. $data = $this->request->param();
  123. $thumb=$data['thumb'];
  124. if(!$thumb){
  125. $this->error("请上传引导页图片");
  126. }
  127. $data['href']=html_entity_decode($data['href']);
  128. $data['uptime']=time();
  129. $rs = DB::name('guide')->update($data);
  130. if($rs===false){
  131. $this->error("修改失败!");
  132. }
  133. $this->success("修改成功!");
  134. }
  135. }
  136. }