'“解困”播客', 2 => '解困资源库', 3 => '解困者说']; public function index() { $map = []; $model = D('ContentRes'); $count = $model->getListForCount(); $per_page = C('ADMIN_PER_PAGE_NUM', null, false); if ($per_page === false) { $page = new \Gy_Library\GyPage($count); } else { $page = new \Gy_Library\GyPage($count, $per_page); } $order = 'id desc'; $data_list = $model->getListForPage($map, $page->nowPage, $page->listRows, $order); foreach ($data_list as &$data) { $type = $data['type']; $data['type_name'] = $this->types[$type]; $data['res_num'] = empty(trim($data['res_id'])) ? "" : "共 " . count(explode(',', $data['res_id'])) . " 个文件"; if ($data['cate'] > 0) $data['cate_name'] = $data['cate'] == 1 ? "中国" : "世界"; } $builder = new ListBuilder(); $builder = $builder->setMetaTitle('资源管理'); $builder->addTopButton('addnew'); $builder ->setNIDByNode(MODULE_NAME, CONTROLLER_NAME, 'index') // ->addSearchItem('news_name', 'select_text', '单行输入', array('name' => '名称')) ->addTableColumn('type_name', '模块') ->addTableColumn('content', '内容') ->addTableColumn('res_num', '文件个数') ->addTableColumn('url', '跳转链接') ->addTableColumn('cate_name', '分类名') ->addTableColumn('right_button', '操作', 'btn') ->setTableDataList($data_list) // 数据列表 ->setTableDataPage($page->show()) // 数据列表分页 ->addRightButton('edit') // 添加编辑按钮 ->addRightButton('delete') // 添加删除按钮 ->display(); } public function add() { if (IS_POST) { parent::autoCheckToken(); $data = I('post.'); $model = D('ContentRes'); $data['cate'] = $data['cate'] ?? 0; if ($model->createAdd($data) === false) { $this->error($model->getError()); } else { $this->success('增加成功', U('index')); } } else { $model = D('ContentRes'); $builder = new FormBuilder(); $builder->setMetaTitle('增加资源') ->setPostUrl(U('add')) ->setNIDByNode(MODULE_NAME, CONTROLLER_NAME, 'index') ->addFormItem('id', 'hidden', 'ID') ->addFormItem('type', 'radio', '类型', '', $this->types) ->addFormItem('content', 'textarea', '文字内容') ->addFormItem('res_id', 'files', '相关资源') ->addFormItem('url', 'text', '跳转链接') ->addFormItem('cate', 'radio', '分类', '如果类型不是解困资源库则将此项留空,否则应选择正确的分类', [ 1 => "解困在中国", 2 => "解困在世界", ])->addFormItem('sort', 'num', '排序', '数字越小越靠前') ->display(); } } public function edit($id) { if (IS_POST) { parent::autoCheckToken(); $m_id = I('post.id'); $data = I('post.'); $model = D('ContentRes'); if (!$m_id) { E('缺少内容ID'); } $ent = $model->getOne($m_id); if (!$ent) { E('不存在内容'); } $ent['content'] = $data['content']; $ent['res_id'] = $data['res_id']; $ent['url'] = $data['url']; $ent['type'] = $data['type']; $ent['cate'] = $data['cate'] ?? 0; $ent['sort'] = $data['sort']; if ($model->createSave($ent) === false) { $this->error($model->getError()); } else { $this->success('修改成功', U('index')); } } else { $model = D('ContentRes'); $info = $model->getOne($id); $is_res = $info['type'] == 2; $builder = new FormBuilder(); $builder->setMetaTitle('修改资源') ->setPostUrl(U('edit')) ->setNIDByNode(MODULE_NAME, CONTROLLER_NAME, 'index') ->addFormItem('id', 'hidden', 'ID') ->addFormItem('type', 'radio', '类型', '', $this->types) ->addFormItem('content', 'textarea', '文字内容') ->addFormItem('res_id', 'files', '相关资源') ->addFormItem('url', 'text', '跳转链接'); // ->addFormItem('url', 'text', '跳转链接', '请填写 http:// 或者 https:// 开头的完整链接'); if ($is_res) { $builder->addFormItem('cate', 'radio', '分类', '', [ 1 => "解困在中国", 2 => "解困在世界", ]); } $builder->addFormItem('sort', 'num', '排序', '数字越小越靠前') ->setFormData($info) ->display(); } } public function forbid() { $ids = I('ids'); if (!$ids) { $this->error('请选择要禁用的数据'); } $r = parent::_forbid($ids); if ($r !== false) { // sysLogs('新闻分类id: ' . $ids . ' 禁用'); $this->success('禁用成功', U(CONTROLLER_NAME . '/index')); } else { $this->error($this->_getError()); } } public function resume() { $ids = I('ids'); if (!$ids) { $this->error('请选择要启用的数据'); } $r = parent::_resume($ids); if ($r !== false) { $this->success('启用成功', U(CONTROLLER_NAME . '/index')); } else { $this->error($this->_getError()); } } public function delete() { $ids = I('ids'); if (!$ids) { $this->error('请选择要删除的数据'); } $r = parent::_del($ids); if ($r === false) { $this->error($this->_getError()); } else { $this->success('删除成功', U(MODULE_NAME . '/' . CONTROLLER_NAME . '/index')); } } }