AdminpageController.php 5.0 KB

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