From 0b046abc685f5346eb922b78125a1f8c2d2d98fb Mon Sep 17 00:00:00 2001 From: zhengchanglong Date: Tue, 8 Oct 2019 14:01:50 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=A8=E5=B9=BF=E5=91=98=E9=A6=96=E9=A1=B5?= =?UTF-8?q?=E5=BC=80=E6=9C=8D=E4=BF=A1=E6=81=AF=E6=B7=BB=E5=8A=A0AJAX?= =?UTF-8?q?=E5=88=86=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controller/PromoteController.class.php | 59 +++++-- .../Home/View/default/Promote/index.html | 68 ++++---- ThinkPHP/Library/Think/AjaxPage.class.php | 149 ++++++++++++++++++ 3 files changed, 233 insertions(+), 43 deletions(-) create mode 100644 ThinkPHP/Library/Think/AjaxPage.class.php diff --git a/Application/Home/Controller/PromoteController.class.php b/Application/Home/Controller/PromoteController.class.php index b04f7d97c..18617c0af 100644 --- a/Application/Home/Controller/PromoteController.class.php +++ b/Application/Home/Controller/PromoteController.class.php @@ -66,9 +66,17 @@ class PromoteController extends BaseController ->join("left join tab_game gm on gm.id=sv.game_id") ->field('sv.*,gm.icon') ->order("sv.start_time desc") - //->page(1, 20) + ->page(1, 5) ->select(); + $count = M("server", "tab_") + ->where( + array("start_time"=>array("BETWEEN", array($today_start, $today_end)), + "show_status"=>1)) + ->count(); + + $page = $this->ajax_page($count,5,'seach'); + $this->assign("_page",$page); $user_count = M("user","tab_")->where("promote_id=".get_pid())->count(); $total_money = $this->pay_total(0,0); @@ -88,7 +96,6 @@ class PromoteController extends BaseController ->count(); $yesterday_total_money = $this->pay_total(1,0); - $this->assign("user_count",$user_count); $this->assign("total_money", $total_money); $this->assign("today_add_user_money", $today_add_user_money); @@ -199,24 +206,37 @@ class PromoteController extends BaseController public function home_read_data(){ $type = I("type","0"); $game_id = I("game_id"); - $start = mktime(0, 0, 0, date('m'), date('d'), date('Y')); - $end = mktime(0, 0, 0, date('m'), date('d') + 1, date('Y')) - 1; + $pg = I("page","0"); + $today_start = mktime(0, 0, 0, date('m'), date('d'), date('Y')); + $today_end = mktime(0, 0, 0, date('m'), date('d') + 1, date('Y')) - 1; if($game_id){ - $map['game_id'] = $game_id; + $map['sv.game_id'] = $game_id; + $count_map['game_id']= $game_id; } if($type>0){ - $map['sv.start_time']=array("GT", $end); + $map['sv.start_time']=array("GT", $today_end); + $count_map['start_time']= array("GT", $today_end); }else{ - $map['sv.start_time']=array("BETWEEN", array($start, $end)); + $map['sv.start_time']=array("BETWEEN", array($today_start, $today_end)); + $count_map['start_time']= array("BETWEEN", array($today_start, $today_end)); } $map['sv.show_status'] = 1; + $count_map['show_status'] = 1; $open_server_list = M("server as sv","tab_")->where($map) ->join("left join tab_game gm on gm.id=sv.game_id") ->field('sv.*,gm.icon') ->order("sv.start_time desc") - //->page(1, 20) - ->select();; + ->page($pg, 5) + ->select(); + + $count = M("server", "tab_") + ->where($count_map) + ->count(); + //var_dump($count); + $page = $this->ajax_page($count,5,'seach',$pg); + //$this->assign("_page",$page); + //$count = M("server", "tab_")->where($map)->count(); foreach ($open_server_list as $key => $server){ $open_server_list[$key]['icon']=get_cover($server['icon'],'path'); if($server['pay_type']==1){ @@ -229,7 +249,8 @@ class PromoteController extends BaseController $open_server_list[$key]['pay_type']; $open_server_list[$key]['start_time'] = date('Y-m-s h:i',$server['start_time']); } - $this->ajaxReturn(['status'=>1,'info'=>'调用成功','data'=>$open_server_list],"JSON"); + //$content = $this->fetch('Promote/home_read_data'); + $this->ajaxReturn(['status'=>1,'info'=>'调用成功','data'=>$open_server_list,'_page'=>$page],"JSON"); } @@ -1780,6 +1801,24 @@ class PromoteController extends BaseController } } } + + + function ajax_page($count, $row,$ajax_func='index',$current=1) { + $aside = ''; + $count=$count?$count:0; + $row=$row?$row:10; + if ($count > $row) { + $p = new \Think\AjaxPage($count,$row,$ajax_func); + $p->nowpage($count,$row,$current,$ajax_func); + $p->setConfig('theme', '%first% %upPage% %linkPage% %downPage% %end% %header%'); + //产生分页信息 + $html=$p->show(); + return "
".$html."
"; + } else { + //return '
' .$aside. '共 '.$count.' 条记录
'; + return '
共 '.$count.' 条记录
'; + } + } } diff --git a/Application/Home/View/default/Promote/index.html b/Application/Home/View/default/Promote/index.html index 69944d15c..f308c5f69 100644 --- a/Application/Home/View/default/Promote/index.html +++ b/Application/Home/View/default/Promote/index.html @@ -5,37 +5,37 @@
    -
  • -
  • -
  • -
  • +
  • 推广总用户

    {$user_count}
  • +
  • 推广总充值

    ¥{$total_money}
  • +
  • 当日新增用户充值

    ¥{$today_add_user_money}
  • +
  • 当月新增用户充值

    ¥{$month_add_user_money}
    -
  • -
  • -
  • -
  • +
  • 昨日注册用户

    {$yesterday_user_regist_count}
  • +
  • 昨日充值金额

    ¥{$yesterday_total_money}
  • +
  • 今日注册用户

    {$yesterday_regist_user_count}
  • +
  • 今日充值金额

    ¥{$yesterday_total_money}
  • -
    快捷菜单
    +
    快捷菜单自定义>
    暂无数据 - +
    @@ -118,19 +118,19 @@ 开服时间 服务器信息 - -

    暂无数据

    - - - - - {$data.game_name} - 安卓、iOS安卓iOS - {$data.start_time|date="m-d H:i",###} - {$data.server_name} - - -
    + +

    暂无数据

    + + + + + {$data.game_name} + 安卓、iOS安卓iOS + {$data.start_time|date="m-d H:i",###} + {$data.server_name} + + +
@@ -158,7 +158,7 @@ }) }); - function seach() { + function seach(page=1) { var game_id = $("select[name=game_id]").val(); var type = $("input[name=type]").val(); jQuery.ajax({ @@ -167,6 +167,7 @@ data: { 'type':type, 'game_id':game_id, + 'page':page }, dataType: 'JSON', cache: false, @@ -195,6 +196,7 @@ }); $(".odd").after(show); + $(".pagenation").html(result._page); } } }); diff --git a/ThinkPHP/Library/Think/AjaxPage.class.php b/ThinkPHP/Library/Think/AjaxPage.class.php new file mode 100644 index 000000000..8a4d37f74 --- /dev/null +++ b/ThinkPHP/Library/Think/AjaxPage.class.php @@ -0,0 +1,149 @@ + '共 %totalRow% 条记录', + 'prev' => '<<', + 'next' => '>>', + 'first' => '1...', + 'last' => '...%totalPage%', + 'theme' => '%first% %upPage% %linkPage% %downPage% %end%', + ); + // 默认分页变量名 + protected $varPage; + + + public function __construct($totalRows,$listRows='',$ajax_func,$parameter='') { + $this->totalRows = $totalRows; + $this->ajax_func = $ajax_func; + $this->parameter = $parameter; + $this->varPage = C('VAR_PAGE') ? C('VAR_PAGE') : 'p' ; + if(!empty($listRows)) { + $this->listRows = intval($listRows); + } + $this->totalPages = ceil($this->totalRows/$this->listRows); //总页数 + $this->coolPages = ceil($this->totalPages/$this->rollPage); + $this->nowPage = !empty($_GET[$this->varPage])?intval($_GET[$this->varPage]):1; + if(!empty($this->totalPages) && $this->nowPage>$this->totalPages) { + $this->nowPage = $this->totalPages; + } + $this->firstRow = $this->listRows*($this->nowPage-1); + } + + public function nowpage($totalRows,$listRows='',$nowPage=1,$ajax_func,$parameter='') { + $this->totalRows = $totalRows; + $this->ajax_func = $ajax_func; + $this->parameter = $parameter; + $this->varPage = C('VAR_PAGE') ? C('VAR_PAGE') : 'p' ; + //$this->varPage = $nowPage; + $this->nowPage = $nowPage; + if(!empty($listRows)) { + $this->listRows = intval($listRows); + } + $this->totalPages = ceil($this->totalRows/$this->listRows); //总页数 + $this->coolPages = ceil($this->totalPages/$this->rollPage); + //$this->nowPage = !empty($_GET[$this->varPage])?intval($_GET[$this->varPage]):1; + if(!empty($this->totalPages) && $this->nowPage>$this->totalPages) { + $this->nowPage = $this->totalPages; + } + $this->firstRow = $this->listRows*($this->nowPage-1); + + return $this->nowPage; + } + + public function setConfig($name,$value) { + if(isset($this->config[$name])) { + $this->config[$name] = $value; + } + } + + + public function show() { + if(0 == $this->totalRows) return ''; + $p = $this->varPage; + $nowCoolPage = ceil($this->nowPage/$this->rollPage); + $url = $_SERVER['REQUEST_URI'].(strpos($_SERVER['REQUEST_URI'],'?')?'':"?").$this->parameter; + $parse = parse_url($url); + if(isset($parse['query'])) { + parse_str($parse['query'],$params); + unset($params[$p]); + $url = $parse['path'].'?'.http_build_query($params); + } + //上下翻页字符串 + $upRow = $this->nowPage-1; + $downRow = $this->nowPage+1; + if ($upRow>0){ + $upPage=""; + }else{ + $upPage=""; + } + + if ($downRow <= $this->totalPages){ + $downPage=""; + }else{ + $downPage=""; + } + // << < > >> + if($nowCoolPage == 1){ + $theFirst = ""; + $prePage = ""; + }else{ + $preRow = $this->nowPage-$this->rollPage; + $prePage = ""; + $theFirst = "".$this->config['first'].""; + } + if($nowCoolPage == $this->coolPages){ + $nextPage = ""; + $theEnd=""; + }else{ + $nextRow = $this->nowPage+$this->rollPage; + $theEndRow = $this->totalPages; + $nextPage = ""; + $theEnd = "".$this->config['last'].""; + } + // 1 2 3 4 5 + $linkPage = ""; + for($i=1;$i<=$this->rollPage;$i++){ + $page=($nowCoolPage-1)*$this->rollPage+$i; + if($page!=$this->nowPage){ + if($page<=$this->totalPages){ + $linkPage .= " ".$page." "; + }else{ + break; + } + }else{ + if($this->totalPages != 1){ + $linkPage .= " ".$page.""; + } + } + } + $pageStr = str_replace( + array('%header%','%nowPage%','%totalRow%','%totalPage%','%upPage%','%downPage%','%first%','%prePage%','%linkPage%','%nextPage%','%end%'), + array($this->config['header'],$this->nowPage,$this->totalRows,$this->totalPages,$upPage,$downPage,$theFirst,$prePage,$linkPage,$nextPage,$theEnd), + $this->config['theme']); + return $pageStr; + } + +} \ No newline at end of file