Article.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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\fastshop\controller;
  9. use app\common\controller\Manage;
  10. class Article extends Manage
  11. {
  12. public function initialize()
  13. {
  14. parent::initialize();
  15. if(!model('auth')->getAuth($this->user->id,1)){
  16. $this->error('无权限,你非【内容管理员】');
  17. }
  18. $this->assign('pathMaps', [['name'=>'内容管理','url'=>'javascript:;']]);
  19. }
  20. /**
  21. * 列表
  22. */
  23. public function index(){
  24. $view['lists'] = model('Article')->where(['member_miniapp_id' => $this->member_miniapp_id])->order('id desc')->paginate(20);
  25. return view()->assign($view);
  26. }
  27. /**
  28. * 添加
  29. */
  30. public function add(){
  31. if(request()->isAjax()){
  32. $data = [
  33. 'types' => input('post.types/d'),
  34. 'title' => input('post.title/s'),
  35. 'content' => input('post.content/s'),
  36. ];
  37. $validate = $this->validate($data,'article.save');
  38. if(true !== $validate){
  39. return json(['code'=>0,'msg'=>$validate]);
  40. }
  41. $result = model('Article')->edit($this->member_miniapp_id,$data);
  42. if($result){
  43. return json(['code'=>200,'url' => url('article/index'),'msg'=>'操作成功']);
  44. }else{
  45. return json(['code'=>0,'msg'=>'操作失败']);
  46. }
  47. }else{
  48. return view();
  49. }
  50. }
  51. /**
  52. * 编辑
  53. */
  54. public function edit(){
  55. if(request()->isAjax()){
  56. $data = [
  57. 'id' => input('post.id/d'),
  58. 'types' => input('post.types/d'),
  59. 'title' => input('post.title/s'),
  60. 'content' => input('post.content/s'),
  61. ];
  62. $validate = $this->validate($data,'article.save');
  63. if(true !== $validate){
  64. return json(['code'=>0,'msg'=>$validate]);
  65. }
  66. $result = model('Article')->edit($this->member_miniapp_id,$data);
  67. if($result){
  68. return json(['code'=>200,'url' => url('article/index'),'msg'=>'操作成功']);
  69. }else{
  70. return json(['code'=>0,'msg'=>'操作失败']);
  71. }
  72. }else{
  73. $id = input('get.id/d');
  74. $view['info'] = model('Article')->where(['id' => $id,'member_miniapp_id' => $this->member_miniapp_id])->find();
  75. return view()->assign($view);
  76. }
  77. }
  78. /**
  79. * 删除
  80. */
  81. public function delete(){
  82. $id = input('get.id/d');
  83. $result = model('Article')->where(['id' => $id,'member_miniapp_id' => $this->member_miniapp_id])->delete();
  84. if($result){
  85. return json(['code'=>200,'msg'=>'操作成功','data'=>[]]);
  86. }else{
  87. return json(['code'=>403,'msg'=>'操作失败']);
  88. }
  89. }
  90. }