<?php

namespace App\Models;

use App\Models\User\UserModel;

/**
 * App\Models\OrderModel
 *
 * @property int $id 主键
 * @property int $create_at 下单时间
 * @property float|null $flower 充值fa数量
 * @property string $out_trade_no 订单编号
 * @property string|null $transaction_id 微信支付订单号
 * @property int $total_amount 业务订单金额;单位:分
 * @property int $total_fee 订单金额;单位:分
 * @property int $cash_fee 支付金额;单位:分
 * @property string $openid 付款用户openid
 * @property int $uid 下单用户uid
 * @property int $order_state 订单状态.0:待支付;1:支付成功SUCCESS;2:转入退款REFUND;3:已关闭CLOSED;4:支付失败PAYERROR
 * @property int $type 1:小fa充值;2:服务费;3:72小时;9:小花充值10朵;
 * 10:小花充值100朵;
 * 12:超级会员1个月;
 * 13:超级会员3个月;
 * 14:超级会员12个月;
 * @property int|null $type_id type[1:无意义;2表白id]
 * @property int $coupon_id 优惠券ID
 * @property string|null $attach_data 附加数据
 * @property string|null $device 支付设备
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\OrderModel newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\OrderModel newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\OrderModel query()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\OrderModel whereAttachData($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\OrderModel whereCashFee($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\OrderModel whereCouponId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\OrderModel whereCreateAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\OrderModel whereDevice($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\OrderModel whereFlower($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\OrderModel whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\OrderModel whereOpenid($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\OrderModel whereOrderState($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\OrderModel whereOutTradeNo($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\OrderModel whereTotalAmount($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\OrderModel whereTotalFee($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\OrderModel whereTransactionId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\OrderModel whereType($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\OrderModel whereTypeId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\OrderModel whereUid($value)
 * @mixin \Eloquent
 */
class OrderModel extends Model
{

    protected $table = "kdgx_partner_charge_order";

    protected $dateFormat = 'U';

    public const CREATED_AT = 'create_at';

    public const UPDATED_AT = null;

    public $fillable = [
        'flower',
        'out_trade_no',
        'total_amount',
        'total_fee',
        'cash_fee',
        'openid',
        'uid',
        'type',
        'type_id',
        'coupon_id',
        'attach_data',
        'device'
    ];

    protected $casts = array(
        'create_at' => 'int'
    );

    // 商品信息
    public const GOODS = [
        1 => [
            'goods_id' => 1,
            'desc' => '金fa充值',
            'total_fee' => 100,
            'gold_flower' => 1,
            'red_flower' => 0,
            'body' => '卖室友充值',
            'notify_url' => "/api/core/pay/notify"
        ],
        2 => [
            'goods_id' => 2,
            'desc' => '卖室友表白',
            'total_fee' => 100,
            'gold_flower' => 0,
            'red_flower' => 0,
            'body' => '卖室友表白',
            'notify_url' => "/api/core/pay/notify"
        ],
        3 => [
            'goods_id' => 3,
            'desc' => '72小时恋爱体验报名',
            'total_fee' => 990,
            'gold_flower' => 0,
            'red_flower' => 0,
            'body' => '72小时入场券',
            'notify_url' => "/api/core/pay/notify"
        ],
        9 => [
            'goods_id' => 9,
            'desc' => '购买小fa充值',
            'total_fee' => 900,
            'gold_flower' => 10,
            'red_flower' => 0,
            'body' => '卖室友充值',
            'notify_url' => "/api/core/pay/notify"
        ],
        10 => [
            'goods_id' => 10,
            'desc' => '购买小fa充值',
            'total_fee' => 8800,
            'gold_flower' => 100,
            'red_flower' => 0,
            'body' => '卖室友充值',
            'notify_url' => "/api/core/pay/notify"
        ],
        12 => [
            'goods_id' => 12,
            'desc' => "「1个月」超级会员充值",
            'total_fee' => 2990,
            'gold_flower' => 0,
            'red_flower' => 0,
            'body' => '分配对象「1个月」超级会员充值',
            'notify_url' => "/api/pay/notify/supervip"
        ],
        13 => [
            'goods_id' => 13,
            'desc' => "「3个月」超级会员充值",
            'total_fee' => 7200,
            'gold_flower' => 0,
            'red_flower' => 0,
            'body' => '分配对象「3个月」超级会员充值',
            'notify_url' => "/api/pay/notify/supervip"
        ],
        14 => [
            'goods_id' => 14,
            'desc' => "「12个月」超级会员充值",
            'total_fee' => 25200,
            'gold_flower' => 0,
            'red_flower' => 0,
            'body' => '分配对象「12个月」超级会员充值',
            'notify_url' => "/api/pay/notify/supervip"
        ],
    ];

    public function user()
    {
        return $this->belongsTo(UserModel::class, 'uid', 'uid');
    }

    public function coupon()
    {
        return $this->belongsTo(CouponModel::class, 'coupon_id');
    }
}
