GuideController.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. <?php
  2. /**
  3. * 引导图
  4. */
  5. namespace app\admin\controller;
  6. use cmf\controller\AdminBaseController;
  7. use think\facade\Db;
  8. class GuideController extends AdminBaseController{
  9. public function set(){
  10. $this->assign('config', cmf_get_option('guide'));
  11. return $this->fetch();
  12. }
  13. public function set_post(){
  14. if($this->request->isPost()){
  15. $options = $this->request->param('post/a');
  16. cmf_set_option('guide', $options);
  17. $this->success("保存成功!", '');
  18. }
  19. }
  20. //列表
  21. public function index(){
  22. $config = cmf_get_option('guide');
  23. $type=$config['type'];
  24. $map['type']=$type;
  25. $guide=Db::name("guide");
  26. $lists = $guide
  27. ->where($map)
  28. ->order("orderno asc, id desc")
  29. ->paginate(20);
  30. $page = $lists->render();
  31. $this->assign("page", $page);
  32. $this->assign('lists', $lists);
  33. $this->assign('type', $type);
  34. return $this->fetch();
  35. }
  36. //添加
  37. public function add(){
  38. $config = cmf_get_option('guide');
  39. $type=$config['type'];
  40. if($type==1){
  41. $map['type']=$type;
  42. $count=Db::name("guide")->where($map)->count();
  43. if($count>=1){
  44. $this->error("引导页视频只能存在一个");
  45. }
  46. }
  47. $this->assign('type', $type);
  48. return $this->fetch();
  49. }
  50. public function add_post(){
  51. if ($this->request->isPost()) {
  52. $data = $this->request->param();
  53. $type=$data['type'];
  54. if($type==1){
  55. $count=Db::name("guide")->where("type=1")->count();
  56. if($count>=1){
  57. $this->error("引导页视频只能存在一个");
  58. }
  59. if($_FILES){
  60. $files["file"]=$_FILES["file"];
  61. $type='video';
  62. $uploadSetting = cmf_get_upload_setting();
  63. $extensions=$uploadSetting['file_types']['video']['extensions'];
  64. $allow=explode(",",$extensions);
  65. if (!get_file_suffix($files['file']['name'],$allow)){
  66. $this->error("请上传正确格式的视频文件或检查上传设置中视频文件设置的文件类型");
  67. }
  68. $rs=adminUploadFiles($files,$type);
  69. if($rs['code']!=0){
  70. $this->error($rs['msg']);
  71. }
  72. $data['thumb']=$rs['filepath'];
  73. }else{
  74. $this->error("请上传视频");
  75. }
  76. }
  77. if(!$data['thumb']){
  78. $this->error("请上传图片");
  79. }
  80. unset($data['file']);
  81. $data['addtime']=time();
  82. $data['uptime']=time();
  83. $result=Db::name("guide")->insert($data);
  84. if($result){
  85. $this->success('添加成功');
  86. }else{
  87. $this->error('添加失败');
  88. }
  89. }
  90. }
  91. //删除
  92. public function del(){
  93. $id = $this->request->param('id');
  94. if($id){
  95. $result=Db::name("guide")->delete($id);
  96. if($result){
  97. $this->success('删除成功', '');
  98. }else{
  99. $this->error('删除失败');
  100. }
  101. }else{
  102. $this->error('数据传入失败!');
  103. }
  104. return $this->fetch();
  105. }
  106. //编辑
  107. public function edit(){
  108. $id = $this->request->param('id');
  109. if($id){
  110. $data=Db::name("guide")->find($id);
  111. $this->assign('data', $data);
  112. }else{
  113. $this->error('数据传入失败!');
  114. }
  115. return $this->fetch();
  116. }
  117. public function edit_post(){
  118. if ($this->request->isPost()) {
  119. $data = $this->request->param();
  120. $type=$data['type'];
  121. if($type==1){
  122. if($_FILES){
  123. $files["file"]=$_FILES["file"];
  124. $type='video';
  125. $uploadSetting = cmf_get_upload_setting();
  126. $extensions=$uploadSetting['file_types']['video']['extensions'];
  127. $allow=explode(",",$extensions);
  128. if (!get_file_suffix($files['file']['name'],$allow)){
  129. $this->error("请上传正确格式的视频文件或检查上传设置中视频文件设置的文件类型");
  130. }
  131. $rs=adminUploadFiles($files,$type);
  132. if($rs['code']!=0){
  133. $this->error($rs['msg']);
  134. }
  135. $data['thumb']=$rs['filepath'];
  136. }else{
  137. $this->error("请上传视频");
  138. }
  139. }
  140. if(!$data['thumb']){
  141. $this->error("请上传图片");
  142. }
  143. unset($data['file']);
  144. $data['uptime']=time();
  145. $result=Db::name("guide")->update($data);
  146. if($result){
  147. $this->success('编辑成功');
  148. }else{
  149. $this->error('编辑失败');
  150. }
  151. }
  152. }
  153. //排序
  154. public function listsorders() {
  155. $ids = $this->request->param('listsorders');
  156. foreach ($ids as $key => $r) {
  157. $data['orderno'] = $r;
  158. Db::name("guide")
  159. ->where(array('id' => $key))
  160. ->update($data);
  161. }
  162. $status = true;
  163. if($status){
  164. $this->success("排序更新成功!", '');
  165. }else{
  166. $this->error("排序更新失败!");
  167. }
  168. }
  169. }