<?php
namespace app\admin\controller;
use app\admin\common\Base;
use think\Db;
use think\Session;
class Lable extends Base
{
public function index()
{
$data = $this->request->param();
if (isset($data[‘ajax‘]) && $data[‘ajax‘] == 1) {
$page = isset($data[‘page‘]) ? $data[‘page‘] : 1;
$page = intval($page);
$limit = isset($data[‘rows‘]) ? $data[‘rows‘] : 10;
$limit = intval($limit);
// $start = $limit * ($page - 1);
$lists = $this->getLable($page, $limit);
return $this->json_data($lists[‘count‘], $lists[‘list‘]);
}
return $this->fetch();
}
public function getLable($page, $limit)
{
$list = [];
$count = 0;
$k = 0;
for ($i=0; $i < 10; $i++) {
$k = $i;
if($k == 0){
$k = ‘‘;
}
$temp = Db::name(‘product_lable‘.$k)->count();
$count += $temp;
$start = ($page - 1)*$limit;
$pre_page = ($count - $temp)/$limit;
$start = ($page - $pre_page - 1) * $limit;
$temp1 = Db::name(‘product_lable‘.$k)->limit($start, $limit)->select();
$list = $list + $temp1;
if($count >= $page*$limit){
break;
}
}
if(intval($k) < 10){
for ($j=$k+1; $j < 10; $j++) {
$temp = Db::name(‘product_lable‘.$j)->count();
$count += $temp;
}
}
return [‘list‘=>$list, ‘count‘=>$count];
}
}
原文:https://www.cnblogs.com/fyiyy/p/15008569.html