模型查询数据

控制器
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
                        }
                    }
           }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值