<?php

namespace App\Models\Real;

use App\Core\Model;
use App\Models\Real\OrderCard;
use App\Models\Virtual\OrderCard as VirtualOrderCard;

/**
 * App\Models\Real\Order
 *
 * @property int $id 订单ID
 * @property string $sn 订单编号
 * @property int $type 订单类型（0:基础套餐）
 * @property int $company_id 企业ID
 * @property string $transaction_no 交易流水号
 * @property string $pay_channel 支付频道
 * @property int $unit_price 单价
 * @property int $counts 数量
 * @property int $total_price 总价
 * @property string|null $order_at 下单时间
 * @property string $address 收货地址
 * @property string $contacts 联系人
 * @property string $mobile 电话
 * @property string|null $logistics_remark 物流备注
 * @property string|null $remark 订单备注
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 * @property string|null $deleted_at
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Card\Card[] $cards
 * @property-read \App\Models\Real\Company $company
 * @property-read \App\Models\Real\Package $package
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Real\Order newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Real\Order newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Real\Order query()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Real\Order whereAddress($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Real\Order whereCompanyId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Real\Order whereContacts($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Real\Order whereCounts($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Real\Order whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Real\Order whereDeletedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Real\Order whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Real\Order whereLogisticsRemark($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Real\Order whereMobile($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Real\Order whereOrderAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Real\Order wherePayChannel($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Real\Order whereRemark($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Real\Order whereSn($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Real\Order whereTotalPrice($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Real\Order whereTransactionNo($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Real\Order whereType($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Real\Order whereUnitPrice($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Real\Order whereUpdatedAt($value)
 * @mixin \Eloquent
 */
class Order extends Model
{
    protected $table = 'real_orders';

    public function company()
    {
        return $this->belongsTo(Company::class, 'company_id', 'id');
    }

    public function package()
    {
        return $this->belongsTo(Package::class, 'package_id', 'id');
    }

    public function cards()
    {
        return $this->hasMany(OrderCardPartition::class, 'order_id', 'id');
    }

    public function virtual_order_cards()
    {
        return $this->hasManyThrough(VirtualOrderCard::class, OrderCardPartition::class, 'order_id', 'sim', 'id', 'sim');
    }
}
