Article.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <?php
  2. namespace app\admin\controller\system;
  3. use app\admin\logic\SystemAdminLogic;
  4. use app\admin\logic\SystemArticleLogic;
  5. use app\admin\model\dao\SystemArticle;
  6. use app\admin\model\dao\SystemArticleType;
  7. use app\common\controller\AdminController;
  8. use app\common\model\ArticleTypeModel;
  9. use app\common\model\CouponPlanModel;
  10. use app\common\model\SystemArticleModel;
  11. use app\common\model\SystemBannerModel;
  12. use app\common\model\UserModel;
  13. use think\App;
  14. use think\facade\Db;
  15. use think\Request;
  16. /**
  17. * @ControllerAnnotation(title="系统公告/文章配置")
  18. */
  19. class Article extends AdminController
  20. {
  21. use \app\admin\traits\Curd;
  22. public function __construct(App $app)
  23. {
  24. parent::__construct($app);
  25. $this->model = new SystemArticleModel();
  26. }
  27. public function index()
  28. {
  29. if ($this->request->isAjax()) {
  30. if (input('selectFields')) {
  31. return $this->selectList();
  32. }
  33. list($page, $limit, $where) = $this->buildTableParames();
  34. list($count, $list) = SystemArticleLogic::getList($page, $limit, $where, $this->sort);
  35. $data = [
  36. 'code' => 0,
  37. 'msg' => '',
  38. 'count' => $count,
  39. 'data' => $list,
  40. ];
  41. return json($data);
  42. }
  43. return $this->fetch();
  44. }
  45. /**
  46. * @NodeAnotation(title="修改")
  47. */
  48. public function edit($id)
  49. {
  50. $row = $this->model->find($id);
  51. empty($row) && $this->error('数据不存在');
  52. if ($this->request->isAjax()) {
  53. $post = $this->request->post();
  54. $rule = [];
  55. $this->validate($post, $rule);
  56. try {
  57. $post['banner_desc'] = htmlspecialchars_decode($post['banner_desc']);
  58. // $post['img_pic'] = __HTTPSAVEIMGADMIN($post['img_pic']);
  59. $save = $row->save($post);
  60. } catch (\Exception $e) {
  61. $this->error('保存失败');
  62. }
  63. $save ? $this->success('保存成功') : $this->error('保存失败');
  64. }
  65. $row['img_pic'] = __HTTPGETIMGADMIN($row['img_pic']);
  66. $this->assign('row', $row);
  67. return $this->fetch();
  68. }
  69. /**
  70. * @NodeAnotation(title="添加")
  71. */
  72. public function add()
  73. {
  74. if ($this->request->isAjax()) {
  75. $row = request()->post();
  76. list($save, $msg) = SystemArticleLogic::add($row);
  77. $save ? $this->success($msg) : $this->error($msg);
  78. }
  79. return $this->fetch();
  80. }
  81. public function articleType()
  82. {
  83. $list = SystemArticle::getIdNameMapByStatus(1);
  84. $this->success('成功', $list);
  85. }
  86. }