WithdrawRecord.php 3.6 KB
<?php
/**
+-----------------------------------------------------------------------------------------------------------------------
 * 模型层:用户-分佣记录 模型类
+-----------------------------------------------------------------------------------------------------------------------
 *
 * PHP version 7
 *
 * @category  App\Models\User
 * @package   App\Models\User
 * @author    Richer <yangzi1028@163.com>
 * @date      2023年5月8日11:48:37
 * @copyright 2020-2022 Richer (http://www.Richer.com/)
 * @license   http://www.Richer.com/ License
 * @link      http://www.Richer.com/
 */
namespace App\Models\User;

use App\Models\BaseModel;
use GuzzleHttp\Exception\GuzzleException;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\MorphMany;
use Illuminate\Database\Eloquent\Relations\MorphTo;
use Illuminate\Support\Arr;

/**
 * Class WithdrawRecord
 * @property mixed user_id
 * @property mixed times
 * @property mixed type
 * @property mixed type_show
 * @property mixed event
 * @property mixed event_show
 * @property mixed cardholder
 * @property mixed account
 * @property mixed bank_id
 * @property mixed bank_name
 * @property mixed receipt_code
 * @property mixed amount
 * @property mixed audited_at
 * @package App\Models\User
 */
class WithdrawRecord extends BaseModel
{
    // 指定数据库表
    const TABLE = 'user_withdraw_records';
    protected $table = self::TABLE;

    // 指定对象显示名称:方便系统统一查询和做其他处理
    const OBJ_NAME      = 'withdraw-record';
    const OBJ_NAME_ZH   = '提现记录';

    const BANK = 1;
    const WECHAT = 2;
    const ALIPAY = 3;
    const TYPE_OPTIONS = [
        self::BANK => '银行',
        self::WECHAT => '微信',
        self::ALIPAY => '支付宝',
    ];

    /**
     * 订单状态代码集
     */
    const UNAUDITED = 1;// 待审核
    const PASSED    = 2;// 申报不通过
    const FAILED    = 9;// 申报不通过

    const STATUS_OPTIONS = [
        self::UNAUDITED  => '待审核',
        self::PASSED     => '审核通过',
        self::FAILED    => '审核不通过',
    ];
    const STATUS_COLOR_OPTIONS = [
        self::UNAUDITED    => 'danger',
        self::PASSED        => 'success',
        self::FAILED        => 'info',
    ];

    /**
     * 访问器被附加到模型数组的形式。
     *
     * @var array
     */
    protected $appends = ['status_show', 'type_show'];

    /**
     * @return BelongsTo
     */
    public function user(): BelongsTo
    {
        return $this->belongsTo(User::class);
    }

    /**
     * @return MorphMany
     */
    public function records(): MorphMany
    {
        return $this->morphMany(WalletRecord::class, 'recordable');
    }

    /**
     * @param $value
     */
    public function setReceiptCodeAttribute($value)
    {
        // 需要判断前端传来的路径是否是全路径,如果是全路径需要截取为相对路径
        $this->attributes['receipt_code'] = substr_file_path($value);
    }

    /**
     * @param string $value 值
     *
     * @return array
     * @throws GuzzleException
     */
    public function getReceiptCodeAttribute($value)
    {
        return splice_file_path($value);
    }

    /**
     * 获取类型的中文显示
     *
     * @return mixed
     */
    public function getStatusShowAttribute()
    {
        return Arr::get(self::STATUS_OPTIONS, $this->status ? : self::UNAUDITED);
    }

    /**
     * 获取类型的中文显示
     *
     * @return mixed
     */
    public function getTypeShowAttribute()
    {
        return Arr::get(self::TYPE_OPTIONS, $this->type ? : self::BANK);
    }

}