Publish.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // |
  4. // +----------------------------------------------------------------------
  5. // |
  6. // +----------------------------------------------------------------------
  7. // |
  8. // +----------------------------------------------------------------------
  9. // |
  10. // +----------------------------------------------------------------------
  11. // +----------------------------------------------------------------------
  12. // | 稿件管理
  13. // +----------------------------------------------------------------------
  14. namespace app\admin\controller\cms;
  15. use app\admin\model\cms\Cms as CmsModel;
  16. use app\admin\model\cms\CmsContent as CmsContentModel;
  17. use app\common\controller\Backend;
  18. use think\facade\Db;
  19. class Publish extends Backend
  20. {
  21. protected $CmsModel = null;
  22. protected function initialize()
  23. {
  24. parent::initialize();
  25. $this->CmsModel = new CmsModel;
  26. }
  27. public function index()
  28. {
  29. if ($this->request->isAjax()) {
  30. $limit = $this->request->param('limit/d', 10);
  31. $page = $this->request->param('page/d', 10);
  32. $total = CmsContentModel::count();
  33. $list = CmsContentModel::page($page, $limit)->order("id DESC")->select();
  34. foreach ($list as $k => $v) {
  35. $modelid = getCategory($v['catid'], 'modelid');
  36. $info = Db::name(getModel($modelid, 'tablename'))->where(["id" => $v['content_id'], "sysadd" => 0])->find();
  37. if ($info) {
  38. $list[$k]['url'] = buildContentUrl($v['catid'], $v['content_id'], $info['url']);
  39. $list[$k]['title'] = $info['title'];
  40. $list[$k]['catname'] = getCategory($v['catid'], 'catname');
  41. }
  42. }
  43. $result = ["code" => 0, "count" => $total, "data" => $list];
  44. return json($result);
  45. }
  46. return $this->fetch();
  47. }
  48. //删除
  49. public function del()
  50. {
  51. $ids = $this->request->param('id/a', null);
  52. if (empty($ids)) {
  53. $this->error('请指定需要删除的信息!');
  54. }
  55. if (!is_array($ids)) {
  56. $ids = [0 => $ids];
  57. }
  58. foreach ($ids as $id) {
  59. //信息
  60. $row = CmsContentModel::where('id', $id)->find();
  61. if (!$row) {
  62. continue;
  63. }
  64. try {
  65. $this->CmsModel->deleteModelData($row['catid'], $row['content_id']);
  66. } catch (\Exception $e) {
  67. $this->error($e->getMessage());
  68. }
  69. }
  70. $this->success('删除成功!');
  71. }
  72. /**
  73. * 批量更新
  74. */
  75. public function multi()
  76. {
  77. if (false === $this->request->isPost()) {
  78. $this->error('未知参数');
  79. }
  80. $ids = $this->request->param('id/a', null);
  81. if (empty($ids)) {
  82. $this->error('参数错误!');
  83. }
  84. if (!is_array($ids)) {
  85. $ids = [0 => $ids];
  86. }
  87. if ($this->request->has('param')) {
  88. parse_str($this->request->param('param/s'), $values);
  89. $values = $this->auth->isAdministrator() ? $values : array_intersect_key($values, array_flip(is_array($this->multiFields) ? $this->multiFields : explode(',', $this->multiFields)));
  90. if (empty($values) && !isset($values['status'])) {
  91. $this->error('你没有权限操作!');
  92. }
  93. $adminIds = $this->getDataLimitAdminIds();
  94. $where = [];
  95. if (is_array($adminIds)) {
  96. $where[] = [$this->dataLimitField, 'in', $adminIds];
  97. }
  98. $where[] = ['id', 'in', $ids];
  99. $count = 0;
  100. Db::startTrans();
  101. try {
  102. $list = CmsContentModel::where($where)->select();
  103. foreach ($list as $item) {
  104. $count += $item->save($values);
  105. $modelid = getCategory($item['catid'], 'modelid');
  106. $values['status'] = $values['status'] == '-1' ? 0 : 1;
  107. Db::name(cms_cache("Model")[$modelid]['tablename'])->where('id', $item['content_id'])->update($values);
  108. }
  109. Db::commit();
  110. } catch (Exception $e) {
  111. Db::rollback();
  112. $this->error($e->getMessage());
  113. }
  114. if ($count) {
  115. $this->success("操作成功!");
  116. }
  117. $this->error('未更新任何行');
  118. }
  119. $this->error('Param参数不能为空');
  120. }
  121. }