// +---------------------------------------------------------------------- // +---------------------------------------------------------------------- // | 稿件管理 // +---------------------------------------------------------------------- namespace app\admin\controller\cms; use app\admin\model\cms\Cms as Cms_Model; use app\cms\model\CmsContent as CmsContentModel; use app\common\controller\Adminbase; use think\Db; class Publish extends Adminbase { protected function initialize() { parent::initialize(); $this->Cms_Model = new Cms_Model; } public function index() { if ($this->request->isAjax()) { $limit = $this->request->param('limit/d', 10); $page = $this->request->param('page/d', 10); $total = CmsContentModel::count(); $_list = CmsContentModel::page($page, $limit)->order(["id" => "DESC"])->select(); foreach ($_list as $k => $v) { $modelid = getCategory($v['catid'], 'modelid'); $tablename = ucwords(getModel($modelid, 'tablename')); $info = Db::name($tablename)->where(["id" => $v['content_id'], "sysadd" => 0])->find(); if ($info) { $_list[$k]['url'] = buildContentUrl($v['catid'], $v['content_id'], $info['url']); $_list[$k]['title'] = $info['title']; $_list[$k]['catname'] = getCategory($v['catid'], 'catname'); } } $result = ["code" => 0, "count" => $total, "data" => $_list]; return json($result); } return $this->fetch(); } //删除 public function del() { $ids = $this->request->param('id/a', null); if (empty($ids)) { $this->error('请指定需要删除的信息!'); } if (!is_array($ids)) { $ids = [0 => $ids]; } foreach ($ids as $id) { //信息 $info = CmsContentModel::where('id', $id)->find(); //取得栏目信息 $category = getCategory($info['catid']); if (!$category) { $this->success('栏目不存在!'); } try { $this->Cms_Model->deleteModelData($category['modelid'], $info['content_id']); } catch (\Exception $ex) { $this->error($ex->getMessage()); } } $this->success('删除成功!'); } //通过审核 public function pass() { $ids = $this->request->param('id/a', null); if (empty($ids)) { $this->error('请指定需要操作的信息!'); } if (!is_array($ids)) { $ids = [0 => $ids]; } foreach ($ids as $id) { $info = CmsContentModel::get($id); $info->status = 1; $info->save(); $modelid = getCategory($info['catid'], 'modelid'); $model_cache = cache("Model"); $tablename = ucwords($model_cache[$modelid]['tablename']); Db::name($tablename)->where('id', $info['content_id'])->setField('status', 1); } $this->success('操作成功!'); } //退稿 public function reject() { $ids = $this->request->param('id/a', null); if (empty($ids)) { $this->error('请指定需要操作的信息!'); } if (!is_array($ids)) { $ids = [0 => $ids]; } foreach ($ids as $id) { $info = CmsContentModel::get($id); $info->status = -1; $info->save(); $modelid = getCategory($info['catid'], 'modelid'); $model_cache = cache("Model"); $tablename = ucwords($model_cache[$modelid]['tablename']); Db::name($tablename)->where('id', $info['content_id'])->setField('status', 0); } $this->success('操作成功!'); } }