ThinkPHP5 分页后追加数据方法
因为分页后数是对象而不是数组,所以不能用foreach方式,而是采用each遍历处理。另外包闭函数传参了解一下!
<?php
function index()
{
//查询运营商数据
$operator = Db::name("Operator")->where("status", "EQ", 1)->select();
//查询会员
$list = Db::name("Member")->field("id,name,nick_name");
$select['name'] = $name = trim(input("name", ''));
if (!empty($name)) {
$list = $list->where("name", "EQ", $name);
}
$select['mobile'] = $mobile = trim(input('mobile', ''));
if (!empty($mobile)) {
$list = $list->where("mobile", "EQ", $mobile);
}
$list = $list->order('id DESC')
->paginate(2, false, ['query' => Request::instance()->param()])->each(function ($item, $key) use ($operator) {
$member_id = $item['id'];
$item['rowspan'] = count($operator);
$item['order_number'] = Db::name("Order")->where("member_id", "EQ", $member_id)->count();
//统计每个会员拥有产品数量
foreach ($operator as $k => $v) {
$operator_id = $v['id'];
$row[] = [
'operator' => $v['name'],
'card_number' => self::number_count("MemberCard", $member_id, $operator_id),
'package_number' => self::number_count("MemberPackage", $member_id, $operator_id),
'traffic_number' => self::number_count("MemberTraffic", $member_id, $operator_id),
'pool_number' => self::number_count("MemberPool", $member_id, $operator_id),
'backward_number' => self::number_count("MemberBackward", $member_id, $operator_id),
];
}
$item['child'] = $row;
return $item;
});
$this->assign([
'list' => $list,
'select' => $select
]);
return $this->fetch();
}
?>
解压密码: detechn或detechn.com
免责声明
本站所有资源出自互联网收集整理,本站不参与制作,如果侵犯了您的合法权益,请联系本站我们会及时删除。
本站发布资源来源于互联网,可能存在水印或者引流等信息,请用户自行鉴别,做一个有主见和判断力的用户。
本站资源仅供研究、学习交流之用,若使用商业用途,请购买正版授权,否则产生的一切后果将由下载用户自行承担。