getListForCount($map); $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); } $data_list = $model->getListForPage($map, $page->nowPage, $page->listRows, 'sort asc,id desc'); // 使用Builder快速建立列表页面。 $builder = new ListBuilder(); $builder = $builder->setMetaTitle('公众号管理');// 设置页面标题 $builder->addTopButton('addnew'); $builder->addTopButton('save', array('title' => '保存排序')); $builder ->setNIDByNode(MODULE_NAME, CONTROLLER_NAME, 'index') ->addSearchItem('title', 'select_text', '单行输入', array('name' => '名称')) ->addTableColumn('name', '名称') ->addTableColumn('sort', '排序','','',true) ->addTableColumn('status', '状态', 'status', '', false) ->addTableColumn('right_button', '操作', 'btn') ->setTableDataList($data_list)// 数据列表 ->setTableDataPage($page->show())// 数据列表分页 ->addRightButton('edit')// 添加编辑按钮 ->addRightButton('delete')// 添加删除按钮 ->addRightButton('forbid')// 添加禁用按钮 ->display(); } public function add() { if (IS_POST) { parent::autoCheckToken(); $data = I('post.'); $model = D('Focus'); $r = $model->checkQrCodeOrUrl($data); if ($r === false) { $this->error($model->getError()); } $r = $model->createAdd($data); if ($r === false) { $this->error($model->getError()); } else { // sysLogs('新增内容id:' . $r); $this->success(l('add') . l('success'), U(CONTROLLER_NAME . '/index')); } } else { // 使用FormBuilder快速建立表单页面。 $builder = new FormBuilder(); $data_list = array( "status" => 1, ); if ($data_list) { $builder->setFormData($data_list); } $builder->setMetaTitle('添加公众号')//设置页面标题 ->setNIDByNode(MODULE_NAME, CONTROLLER_NAME, 'index') ->setPostUrl(U('add'))//设置表单提交地址 ->addFormItem('name', 'text', '名称') ->addFormItem('logo', 'picture', 'LOGO图','尺寸为33*27px,格式JPG、PNG、JPEG') ->addFormItem('code_name', 'text', '二维码标题') ->addFormItem('qr_code', 'picture', '二维码','200*200px,格式JPG、PNG、JPEG') ->addFormItem('url', 'text', '链接地址' ,'地址请以https://或http://开头(非必填,如不填则不跳转)') ->addFormItem('sort', 'num', '排序') ->addFormItem('status', 'select', '状态', '', DBCont::getStatusList()) ->display(); } } public function save(){ if(IS_POST){ $data = I('post.'); foreach($data['id'] as $k=>$v){ $save_data['sort'] = $data['sort'][$k]; D('Focus')->where('id=' . $v)->save($save_data); } $this->success('保存成功', U('index')); } } public function edit($id) { if (IS_POST) { parent::autoCheckToken(); $m_id = I('post.id'); $data = I('post.'); $model = D('Focus'); $r = $model->checkQrCodeOrUrl($data); if ($r === false) { $this->error($model->getError()); } if (!$m_id) { E('缺少内容ID'); } $ent = $model->getOne($m_id); if (!$ent) { E('不存在内容'); } $ent['name'] = $data['name']; $ent['logo'] = $data['logo']; $ent['qr_code'] = $data['qr_code']; $ent['code_name'] = $data['code_name']; $ent['url'] = $data['url']; $ent['sort'] = $data['sort']; $ent['status'] = $data['status']; if ($model->createSave($ent) === false) { $this->error($model->getError()); } else { $this->success('修改成功', U('index')); } } else { $info = D('Focus')->getOne($id); $builder = new FormBuilder(); $builder->setMetaTitle('编辑'.$info['name']) ->setPostUrl(U('edit')) // ->setExtraHtml($this->fetch('Focus/detail')) ->setNIDByNode(MODULE_NAME, CONTROLLER_NAME, 'index') ->addFormItem('id', 'hidden', 'ID') ->addFormItem('name', 'text', '名称') ->addFormItem('logo', 'picture', 'LOGO图','尺寸为33*27px,格式JPG、PNG、JPEG') ->addFormItem('code_name', 'text', '二维码标题') ->addFormItem('qr_code', 'picture', '二维码','尺寸为200*200px,格式JPG、PNG、JPEG') ->addFormItem('url', 'text', '链接地址' ,'地址请以https://或http://开头(非必填,如不填则不跳转)') ->addFormItem('sort', 'num', '排序') ->addFormItem('status', 'select', '状态', '', DBCont::getStatusList()) ->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')); } } }