| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228 |
- <?php
- /**
- * 直播上热门投放金额规则
- */
- namespace app\admin\controller;
- use cmf\controller\AdminBaseController;
- use think\facade\Db;
- use think\db\Query;
- class HotliverulesController extends AdminbaseController {
- //列表
- public function index(){
- $lists=Db::name("hotlive_rules")
- ->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;
- }
-
- }
|