AdminpageController.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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-04-30
  10. // +—————————————————————————————————————————————————————————————————————
  11. namespace app\admin\controller;
  12. use cmf\controller\AdminBaseController;
  13. use think\Db;
  14. use think\db\Query;
  15. class AdminpageController extends AdminBaseController{
  16. protected function initialize()
  17. {
  18. parent::initialize();
  19. $adminId = cmf_get_current_admin_id(); //获取后台管理员id,可判断是否登录
  20. if (!empty($adminId)) {
  21. $this->assign('admin_id', $adminId);
  22. }
  23. }
  24. // 后台页面列表
  25. public function index(){
  26. //页面
  27. $posts=Db::name('posts')
  28. ->where(function (Query $query) {
  29. $data = $this->request->param();
  30. $query->where('post_type', 1);
  31. if ($data['id']!='') {
  32. $query->where('id', $data['id']);
  33. }
  34. if ($data['termid']!='') {
  35. $query->where('termid', $data['termid']);
  36. }
  37. if (!empty($data['keyword'])) {
  38. $keyword = $data['keyword'];
  39. $query->where('post_title|post_keywords', 'like', "%$keyword%");
  40. }
  41. })
  42. ->order("orderno DESC")
  43. ->paginate(20);
  44. $posts->each(function($v,$k){
  45. $userinfo=Db::name("user")
  46. ->field("user_nicename")
  47. ->where("id='$v[post_author]'")
  48. ->find();
  49. if(!$userinfo){
  50. $userinfo=array(
  51. 'user_nicename'=>'已删除',
  52. );
  53. }
  54. $v['userinfo']= $userinfo;
  55. return $v;
  56. });
  57. //分页-->筛选条件参数
  58. $data = $this->request->param();
  59. $posts->appends($data);
  60. // 获取分页显示
  61. $page = $posts->render();
  62. $this->assign('posts', $posts);
  63. $this->assign('page', $page);
  64. $configpub=getConfigPub();
  65. $this->assign("site",$configpub['site']);
  66. return $this->fetch();
  67. }
  68. //页面添加
  69. public function add(){
  70. //页面分类
  71. return $this->fetch();
  72. }
  73. public function add_post(){
  74. $data = input('post.post');
  75. if($data['post_type']==''){
  76. $this->error("请至少选择一个分类!");
  77. }else if(empty($data['post_title'])){
  78. $this->error('请输入标题!');
  79. }
  80. $data['post_author']=cmf_get_current_admin_id(); //获取后台管理员id
  81. $data['post_content']=html_entity_decode($data['post_content']);
  82. $data['post_status']='1';
  83. $data['post_type']='1';
  84. $data['post_date']=time();
  85. $add=Db::name('posts')->insert($data);
  86. if($add){
  87. $this->success('添加成功!');
  88. }else{
  89. $this->error('添加失败!');
  90. }
  91. }
  92. //页面分类编辑
  93. public function edit(){
  94. $id = input('param.id');
  95. if($id){
  96. $info=Db::name('posts')->where('id',$id)->find();
  97. $info['post_content']=str_replace('../../','/upload/',$info['post_content']);
  98. $this->assign('info',$info);
  99. }else{
  100. $this->error('数据传入失败!');
  101. }
  102. return $this->fetch();
  103. }
  104. public function edit_post(){
  105. $data = input('post.post');
  106. if($data['post_type']==''){
  107. $this->error("请至少选择一个分类!");
  108. }else if(empty($data['post_title'])){
  109. $this->error('请输入标题!');
  110. }
  111. $data['post_content']=html_entity_decode($data['post_content']);
  112. $data['post_type']='1';
  113. $save=Db::name('posts')->where('id',$data['id'])->update($data);
  114. if($save){
  115. $this->success('保存成功!');
  116. }else{
  117. $this->error('保存失败!');
  118. }
  119. }
  120. // 页面分类删除
  121. public function del(){
  122. $id = input('param.id');
  123. if($id){
  124. $result=Db::name('posts')->delete($id);
  125. if($result){
  126. $this->success('删除成功');
  127. }else{
  128. $this->error('删除失败');
  129. }
  130. }else{
  131. $this->error('数据传入失败!');
  132. }
  133. }
  134. // 页面批量删除
  135. public function deletes(){
  136. $data = input();
  137. foreach ($data['ids'] as $k => $r) {
  138. Db::name('posts')->where(['id'=>$r])->delete();
  139. }
  140. $status = true;
  141. if ($status) {
  142. $this->success("操作成功!");
  143. } else {
  144. $this->error("操作失败!");
  145. }
  146. }
  147. // 页面排序
  148. public function listordersset(){
  149. $ids=$this->request->param('listordersset');
  150. foreach ($ids as $key => $r) {
  151. $data['orderno'] = $r;
  152. Db::name("posts")
  153. ->where(array('id' => $key))
  154. ->update($data);
  155. }
  156. $status = true;
  157. if ($status) {
  158. $this->success("排序更新成功!");
  159. } else {
  160. $this->error("排序更新失败!");
  161. }
  162. }
  163. }