控制器
public function test($page,$num){
$list=User::with('orders')->with('orders.product')->limit(10)->paginate($num,true);
return $this->returnSuccess($list);
}
User模型
public function user_bank(){
return $this->hasMany('UserBank','uid','id');
}
public function orders(){
return $this->hasMany('Order','uid','id');
}
public function balance(){
return $this->hasMany('Balance','uid','id');
}
order模型
public function product(){
return $this->belongsTo('Product','pid','id');
}
结果
{
"id": 24,
"pid": 19,
"path": "1,19",
"phone": "16611110001",
"password": "b530ef58685a27720826455e4345769c",
"nick_name": "模拟1",
"money": "500000.00",
"frozen_money": "0.00",
"avatar": "/static/common/images/1.jpg",
"token": "0",
"status": 1,
"real_name": "模拟1",
"reg_time": 1569046948,
"login_time": 0,
"positive_id_card": "",
"reverse_id_card": "",
"is_partner": -1,
"kline": 0,
"dividend": "0.00",
"commission": "0.00",
"lang": 1,
"is_buy": 1,
"single_control": 0,
"delete_time": null,
"orders": []
}
],
"data": [
{
"id": 1,
"pid": 0,
"path": "",
"phone": "15306582897",
"password": "b530ef58685a27720826455e4345769c",
"nick_name": "总后台",
"money": "82653492.04",
"frozen_money": "400.00",
"avatar": "/uploads//20190924/37cac10e9b6b7842e7bec8ebd28eabe0.png",
"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOjEsImlhdCI6MTU3MzgwNDk2OH0.5e3m1epQk-jEIRFPxZ8igETMYrO3WplxdawzY_jJJAM",
"status": 1,
"real_name": "测试",
"reg_time": 1568815317,
"login_time": 1573804968,
"positive_id_card": "",
"reverse_id_card": "",
"is_partner": 1,
"kline": 1,
"dividend": "1.00",
"commission": "1.00",
"lang": 1,
"is_buy": 1,
"single_control": 1,
"delete_time": 1573809112,
"orders": [
{
"id": 1,
"order_sn": "201909182205261775",
"uid": 1,
"pid": 6,
"symbol": "BCH",
"opening_price": "330.050000",
"closing_price": "330.130000",
"point": 30,
"profit_rate": "0.88",
"amount": "100.00",
"fee": "2.00",
"user_money": "123354.00",
"profit": "88.00",
"profit_or_loss": "188.00",
"type": 1,
"status": 2,
"result": 1,
"risk_control": 0,
"closing_time": 1568815556,
"add_time": "2019-09-18 22:05:26",
"product": {
"id": 6,
"symbol": "BCH",
"name": "比特币现金",
"time": "30,60,180,300",
"profit": "0.88,0.9,0.92,0.94",
"open_time": "",
"status": 1
}
}
}
模型查询数据
最新推荐文章于 2021-12-09 11:08:57 发布