<?php

namespace App\Models;

use Dcat\Admin\Traits\HasDateTimeFormatter;
use Illuminate\Database\Eloquent\Model;

/**
 * App\Models\UserWithdraw.
 *
 * @property int                             $id
 * @property int                             $user_id     用户
 * @property string                          $name        姓名
 * @property string                          $phone_num   手机号
 * @property int                             $type        类型 1-微信
 * @property string                          $account     提现账号
 * @property string                          $price       提现金额
 * @property string                          $discount    手续费
 * @property string                          $desc        提现备注
 * @property int                             $status      提现状态
 * @property string|null                     $review_at   审核时间
 * @property string|null                     $withdraw_at 打款时间
 * @property \Illuminate\Support\Carbon|null $created_at
 * @property \Illuminate\Support\Carbon|null $updated_at
 *
 * @method static \Illuminate\Database\Eloquent\Builder|UserWithdraw newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|UserWithdraw newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|UserWithdraw query()
 * @method static \Illuminate\Database\Eloquent\Builder|UserWithdraw whereAccount($value)
 * @method static \Illuminate\Database\Eloquent\Builder|UserWithdraw whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|UserWithdraw whereDesc($value)
 * @method static \Illuminate\Database\Eloquent\Builder|UserWithdraw whereDiscount($value)
 * @method static \Illuminate\Database\Eloquent\Builder|UserWithdraw whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|UserWithdraw whereName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|UserWithdraw wherePhoneNum($value)
 * @method static \Illuminate\Database\Eloquent\Builder|UserWithdraw wherePrice($value)
 * @method static \Illuminate\Database\Eloquent\Builder|UserWithdraw whereReviewAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|UserWithdraw whereStatus($value)
 * @method static \Illuminate\Database\Eloquent\Builder|UserWithdraw whereType($value)
 * @method static \Illuminate\Database\Eloquent\Builder|UserWithdraw whereUpdatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|UserWithdraw whereUserId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|UserWithdraw whereWithdrawAt($value)
 *
 * @mixin \Eloquent
 *
 * @property \App\Models\User|null $user
 * @property mixed                 $status_name
 * @property mixed                 $type_name
 * @property string|null           $bank_name   所属银行
 *
 * @method static \Illuminate\Database\Eloquent\Builder|UserWithdraw whereBrankName($value)
 */
class UserWithdraw extends Model
{
    use HasDateTimeFormatter;
    protected $table = 'user_withdraw';

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

    public function setStatusNameAttribute($status)
    {
        $config                          = config('global.withdraw_status');
        $this->attributes['status_name'] = $config[$status] ?? '未知';
    }

    public function setTypeNameAttribute($status)
    {
        $config                        = config('global.withdraw_type');
        $this->attributes['type_name'] = $config[$status] ?? '未知';
    }
}
