<?php

namespace App\Models\Virtual;

use App\Core\Model;
use App\Models\Card\Card;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * App\Models\Virtual\Order
 *
 * @property int $id 订单ID
 * @property string $sn 订单编号
 * @property int $source 订单来源（0:用户订单 1:后台订单）
 * @property int $type 订单类型（0:基础订单 1:套餐续费 2：续费包 3:加油包 4:可选包 5:附加包）
 * @property int $company_id 企业ID
 * @property int $package_id 套餐ID
 * @property string $transaction_no 交易流水号
 * @property string $pay_channel 支付频道
 * @property int $unit_price 单价
 * @property int $counts 数量
 * @property int $total_price 总价
 * @property int $custom_price 自定义总价
 * @property string|null $order_at 下单时间
 * @property string $area 区域
 * @property string $address 收货地址
 * @property string $contacts 联系人
 * @property string $mobile 电话
 * @property string $logistics_company 物流公司
 * @property string $logistics_no 物流单号
 * @property int $order_status 订单状态(0:已下单 1:已取消 2:已出库 3:已发货 4:已签收)
 * @property int $transaction_status 收款状态(0:未收款 1:已收款 2:已退款)
 * @property string|null $logistics_remark 物流备注
 * @property string|null $remark 订单备注
 * @property array|null $extends 扩展信息(cancel_remark:取消备注 refund_channel:退款频道 refund_account:退款账号 refund_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\Virtual\Company $company
 * @property-read \App\Models\Virtual\Package $package
 * @method static bool|null forceDelete()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Virtual\Order newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Virtual\Order newQuery()
 * @method static \Illuminate\Database\Query\Builder|\App\Models\Virtual\Order onlyTrashed()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Virtual\Order query()
 * @method static bool|null restore()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Virtual\Order whereAddress($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Virtual\Order whereArea($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Virtual\Order whereCompanyId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Virtual\Order whereContacts($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Virtual\Order whereCounts($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Virtual\Order whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Virtual\Order whereCustomPrice($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Virtual\Order whereDeletedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Virtual\Order whereExtends($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Virtual\Order whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Virtual\Order whereLogisticsCompany($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Virtual\Order whereLogisticsNo($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Virtual\Order whereLogisticsRemark($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Virtual\Order whereMobile($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Virtual\Order whereOrderAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Virtual\Order whereOrderStatus($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Virtual\Order wherePackageId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Virtual\Order wherePayChannel($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Virtual\Order whereProductId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Virtual\Order whereRemark($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Virtual\Order whereSn($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Virtual\Order whereSource($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Virtual\Order whereTotalPrice($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Virtual\Order whereTransactionNo($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Virtual\Order whereTransactionStatus($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Virtual\Order whereType($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Virtual\Order whereUnitPrice($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Virtual\Order whereUpdatedAt($value)
 * @method static \Illuminate\Database\Query\Builder|\App\Models\Virtual\Order withTrashed()
 * @method static \Illuminate\Database\Query\Builder|\App\Models\Virtual\Order withoutTrashed()
 * @mixin \Eloquent
 */
class Order extends Model
{
    use SoftDeletes;

    protected $table = 'virtual_orders';

    protected $casts = [
        'extends' => 'array',
        'area' => 'array',
    ];

    protected $fillable = [
        'id',
        'sn',
        'source',
        'type',
        'company_id',
        'package_id',
        'transaction_no',
        'pay_channel',
        'unit_price',
        'counts',
        'total_price',
        'custom_price',
        'order_at',
        'area',
        'address',
        'contacts',
        'mobile',
        'logistics_company',
        'logistics_no',
        'order_status',
        'transaction_status',
        'logistics_remark',
        'remark',
        'extends',
    ];

    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');
    }
}
