<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Pay_orders extends Model
{
    //
    protected $table = 'pay_orders';
    public $timestamps = false;
    //获取订单详情

    /**
     * @param $id
     * @param bool $toArray
     * @return int
     */
    function getOrderDetails($id, bool $toArray = true)
    {
        $data = $this->where('pay_orders.id', $id)
            ->leftJoin('pay_gateways', 'pay_orders.gateway_id', '=', 'pay_gateways.id')
            ->leftJoin('pay_channels', 'pay_orders.channel_id', '=', 'pay_channels.id')
            ->leftJoin('pay_gateway_type', 'pay_gateways.gateway_type_id', '=', 'pay_gateway_type.id')
            ->select('pay_orders.*', 'pay_gateways.gateway_name as pay_gateway_name',
                'pay_channels.channel_name as pay_channel_name', 'pay_channels.gift_price_rate',
                'pay_channels.gift_black_list', 'pay_channels.black_list','pay_gateway_type.typename')
            ->first();
        if (!$data) {
            return -3021000402; //没有订单信息
        }
        return $toArray ? $data->toArray() : $data;
    }
}
