Article.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2017 https://www.sapixx.com All rights reserved.
  4. * @license Licensed (http://www.apache.org/licenses/LICENSE-2.0).
  5. * @author pillar<ltmn@qq.com>
  6. * 文章管理
  7. */
  8. namespace app\popupshop\controller;
  9. use app\common\controller\Manage;
  10. class Article extends Manage
  11. {
  12. public function initialize()
  13. {
  14. parent::initialize();
  15. $this->assign('pathMaps', [['name'=>'内容管理','url'=>'javascript:;']]);
  16. }
  17. /**
  18. * 列表
  19. */
  20. public function index(){
  21. $view['lists'] = model('Article')->where(['member_miniapp_id' => $this->member_miniapp_id])->order('id desc')->paginate(20);
  22. return view()->assign($view);
  23. }
  24. /**
  25. * 添加
  26. */
  27. public function add(){
  28. if(request()->isAjax()){
  29. $data = [
  30. 'types' => input('post.types/d'),
  31. 'title' => input('post.title/s'),
  32. 'content' => input('post.content/s'),
  33. ];
  34. $validate = $this->validate($data,'article.save');
  35. if(true !== $validate){
  36. return json(['code'=>0,'msg'=>$validate]);
  37. }
  38. $result = model('Article')->edit($this->member_miniapp_id,$data);
  39. if($result){
  40. return json(['code'=>200,'url' => url('article/index'),'msg'=>'操作成功']);
  41. }else{
  42. return json(['code'=>0,'msg'=>'操作失败']);
  43. }
  44. }else{
  45. return view();
  46. }
  47. }
  48. /**
  49. * 编辑
  50. */
  51. public function edit(){
  52. if(request()->isAjax()){
  53. $data = [
  54. 'id' => input('post.id/d'),
  55. 'types' => input('post.types/d'),
  56. 'title' => input('post.title/s'),
  57. 'content' => input('post.content/s'),
  58. ];
  59. $validate = $this->validate($data,'article.save');
  60. if(true !== $validate){
  61. return json(['code'=>0,'msg'=>$validate]);
  62. }
  63. $result = model('Article')->edit($this->member_miniapp_id,$data);
  64. if($result){
  65. return json(['code'=>200,'url' => url('article/index'),'msg'=>'操作成功']);
  66. }else{
  67. return json(['code'=>0,'msg'=>'操作失败']);
  68. }
  69. }else{
  70. $id = input('get.id/d');
  71. $view['info'] = model('Article')->where(['id' => $id,'member_miniapp_id' => $this->member_miniapp_id])->find();
  72. return view()->assign($view);
  73. }
  74. }
  75. /**
  76. * 删除
  77. */
  78. public function delete(){
  79. $id = input('get.id/d');
  80. $result = model('Article')->where(['id' => $id,'member_miniapp_id' => $this->member_miniapp_id])->delete();
  81. if($result){
  82. return json(['code'=>200,'msg'=>'操作成功','data'=>[]]);
  83. }else{
  84. return json(['code'=>403,'msg'=>'操作失败']);
  85. }
  86. }
  87. }