title='新闻列表'; $this->class = DataXwCategory::where('status',1)->select(); $category_id = input('category_id'); $where = []; if($category_id != ''){ $where['category_id'] = $category_id; } DataXw::mQuery() ->with('category') ->where($where) ->withCount(['comments','likes']) ->like('title')->dateBetween('create_time')->layTable(); } /** * 新闻添加 * @auth true * @menu true */ public function add(){ $this->xw_vali(); $this->assign('category',DataXwCategory::show()->select()); DataXw::mForm('form'); } /** * 新闻编辑 * @auth true * @menu true */ public function edit(){ $this->xw_vali(); $this->assign('category',DataXwCategory::show()->select()); DataXw::mForm('form'); } protected function xw_vali(){ if($this->request->isPost()){ $this->_vali([ 'title.max:50'=>'标题过长', ]); } } /** * 新闻删除 * @auth true * @menu true */ public function remove(){ $ids=$this->request->post('id'); DataXw::whereIn('id',$ids)->select()->each(function ($d){$d->delete();}); $this->success('删除成功'); } /** * 新闻分类 * @auth true * @menu true */ public function category(){ $this->title='分类'; DataXwCategory::mQuery() ->like('name') ->layTable(); } /** * 新闻分类添加 * @auth true * @menu true */ public function category_add(){ if($this->request->isPost()) { $this->cate_vali(); } DataXwCategory::mForm('form_category'); } protected function cate_vali(){ $this->_vali([ 'name.require'=>'分类名必须', 'name.max:50'=>'分类名过长', 'sort.require'=>'排序必须', 'sort.egt:0'=>'排序必须大于0', 'sort.integer'=>'排序必须是数字', ]); } /** * 新闻分类编辑 * @auth true * @menu true */ public function category_edit(){ if($this->request->isPost()) { $this->cate_vali(); } DataXwCategory::mForm('form_category'); } /** * 新闻分类删除 * @auth true * @menu true */ public function category_del(){ $id=$this->request->post('id'); $all=DataXwCategory::whereIn('id',$id)->select(); $all->each(function ($c){ $c->delete(); }); $this->success('删除成功'); } /** * 新闻分类上下架 * @auth true * @menu true */ public function cate_state(){ DataXwCategory::mSave([ 'status'=>$this->request->post('status'), ]); } /** * 新闻上下架 * @auth true * @menu true */ public function state(){ DataXw::mSave([ 'status'=>$this->request->post('status'), ]); } /** * 新闻广告列表 * @auth true * @menu true */ public function ad_index(){ $this->title='广告列表'; DataXwAd::mQuery()->layTable(); } /** * 新闻广告添加 * @auth true * @menu true */ public function ad_add(){ $this->ad_vali(); $this->assign('category',DataXwCategory::show()->select()); DataXwAd::mForm('ad_form'); } /** * 新闻广告编辑 * @auth true * @menu true */ public function ad_edit(){ $this->ad_vali(); $this->assign('category',DataXwCategory::show()->select()); DataXwAd::mForm('ad_form'); } protected function ad_vali(){ if($this->request->isPost()){ $this->_vali([ 'title.max:50'=>'标题过长', ]); } } /** * 新闻广告删除 * @auth true * @menu true */ public function ad_del(){ $ids=$this->request->post('id'); DataXwAd::whereIn('id',$ids)->select()->each(function ($d){$d->delete();}); $this->success('删除成功'); } /** * 新闻广告上下架 * @auth true * @menu true */ public function ad_state(){ DataXwAd::mSave([ 'status'=>$this->request->post('status'), ]); } /** * 表单结果处理 * @param boolean $state */ protected function _form_result(bool $state) { if ($state) { $this->success('保存成功1!',in_array($this->request->action(),['add','edit','ad_add','ad_edit'])? 'javascript:history.back()':''); } } /** * 新闻报道设置 * @auth true * @menu true */ public function config(){ if($this->request->isGet()){ $this->title='新闻报道设置'; $this->assign('vo',sysconf('config_xw.')); $this->fetch(); }else{ $data=$this->_vali([ 'split_num.require'=>'间隔数必须', 'user_avatar.require'=>'头像数必须', 'user_avatar.url'=>'头像链接有误', 'username.require'=>'名称必须', 'split_num.gt:0'=>'间隔数必须大于0', ]); sysconf('config_xw',$data); $this->success('保存成功'); } } }