where(function (Query $query) { }) ->order("orderno asc") ->paginate(20); //分页-->筛选条件参数 $data = $this->request->param(); $lists->appends($data); // 获取分页显示 $page = $lists->render(); $configpub=getConfigPub(); $this->assign('lists', $lists); $this->assign('page', $page); $this->assign('name_coin', $configpub['name_coin']); return $this->fetch(); } /*添加*/ public function add(){ $configPub=getConfigPub(); $this->assign("name_coin",$configPub['name_coin']); return $this->fetch(); } /*添加提交*/ public function add_post(){ if($this->request->isPost()) { $data = $this->request->param(); $configpub=getConfigPub(); $orderno=$data['orderno']; $coin=$data['coin']; if(!is_numeric($orderno)){ $this->error("排序号请填写数字"); } if($orderno<0){ $this->error("排序号必须大于0"); } if(!$coin){ $this->error("请填写".$configpub['name_coin']); } if(!is_numeric($coin)){ $this->error($configpub['name_coin']."必须为数字"); } if($coin<100||$coin>99999999){ $this->error($configpub['name_coin']."在100-99999999之间"); } if(floor($coin)!=$coin){ $this->error($configpub['name_coin']."必须为整数"); } if($coin % 10 >0){ $this->error($configpub['name_coin']."数必须为10的倍数"); } $isexit=Db::name("hotlive_rules") ->where("coin={$coin}") ->find(); if($isexit){ $this->error('该规则已存在'); } $result=Db::name("hotlive_rules")->insert($data); if($result){ $this->resetcache(); $this->success('添加成功'); }else{ $this->error('添加失败'); } } } /*删除*/ public function del(){ $id = $this->request->param('id'); if($id){ $result=Db::name("hotlive_rules") ->where("id={$id}") ->delete(); if($result){ $this->resetcache(); $this->success('删除成功'); }else{ $this->error('删除失败'); } }else{ $this->error('数据传入失败!'); } } /*分类编辑*/ public function edit(){ $id = $this->request->param('id'); if($id){ $info=Db::name("hotlive_rules") ->where("id={$id}") ->find(); $configPub=getConfigPub(); $this->assign("name_coin",$configPub['name_coin']); $this->assign("info",$info); }else{ $this->error('数据传入失败!'); } return $this->fetch(); } /*分类编辑提交*/ public function edit_post(){ if($this->request->isPost()) { $data = $this->request->param(); $configpub=getConfigPub(); $id=$data["id"]; $coin=$data['coin']; if(!$coin){ $this->error("请填写".$configpub['name_coin']); } if(!is_numeric($coin)){ $this->error($configpub['name_coin']."必须为数字"); } if($coin<100||$coin>99999999){ $this->error($configpub['name_coin']."在100-99999999之间"); } if(floor($coin)!=$coin){ $this->error($configpub['name_coin']."必须为整数"); } if($coin % 10 >0){ $this->error($configpub['name_coin']."数必须为10的倍数"); } $isexit=Db::name("hotlive_rules") ->where("id!={$id} and coin={$coin}") ->find(); if($isexit){ $this->error('该规则已存在'); } $result=Db::name("hotlive_rules") ->update($data); if($result!==false){ $this->resetcache(); $this->success('修改成功'); }else{ $this->error('修改失败'); } } } public function listorder(){ $ids=$this->request->param('listorders'); foreach ($ids as $key => $r) { $data['orderno'] = $r; Db::name("hotlive_rules")->where(array('id' => $key))->update($data); } $status = true; if ($status) { $this->resetcache(); $this->success("排序更新成功!"); } else { $this->error("排序更新失败!"); } } public function resetcache(){ $key='getHotLiveRules'; $rules= Db::name("hotlive_rules") ->field('id,coin') ->order('orderno asc') ->select(); setcaches($key,$rules); return 1; } }