thinkphp 查找订单分页 如果直接用foreach循环再查链接表的话会报错 但是这样写能避免
第一种方法
$orderInfo =db('order_goods')->field('og.id,og.goods_id,og.goods_name,og.goods_num,og.order_id,g.sm_thumb,g.shop_price,o.out_trade_no,o.order_total_price,o.order_time, o.order_status,o.pay_status,o.post_status,o.name')->alias('og')->join('order o','og.order_id = o.id ','LEFT')->join('goods g','og.goods_id = g.id ')->where('o.user_id',$uid)->group('og.id')->order('og.id desc')->paginate(2);
第二种方法
//获取数据
$orderRes = $order
->field('id,out_trade_no,user_id,order_total_price,order_status,pay_status,post_status,order_time,name')
->where('user_id',$uid)
->where('del_status',0)
->where($map)
->paginate(2,false,['query'=>request()->param()])
->each(
function($item, $key){
$orderid = $item["id"]; //获取数据集中的id
$goodsRes = db('orderGoods')
->alias('og')
->field('g.mid_thumb,g.goods_name,og.member_price,og.goods_attr_str,og.goods_num')
->join('goods g',"g.id = og.goods_id")
->where('order_id',$orderid)
->select(); //根据ID查询相关其他信息
仔细研究一些就明白这些操作了!