127 lines
2.8 KiB
PHP
127 lines
2.8 KiB
PHP
<?php
|
|
|
|
namespace Modules\Withdraw\Models;
|
|
|
|
use App\Models\Model;
|
|
use Carbon\Carbon;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Modules\User\Traits\BelongsToUser;
|
|
use Modules\Withdraw\Models\Traits\WithdrawActions;
|
|
|
|
class Withdraw extends Model
|
|
{
|
|
|
|
use BelongsToUser, WithdrawActions;
|
|
|
|
const STATUS_INIT = 0;
|
|
const STATUS_PASS = 1;
|
|
const STATUS_REJECT = 2;
|
|
|
|
const STATUS = [
|
|
self::STATUS_INIT => '待审核',
|
|
self::STATUS_PASS => '通过',
|
|
self::STATUS_REJECT => '驳回',
|
|
];
|
|
|
|
const TYPE_BANK = 1;
|
|
const TYPE_ALIPAY = 2;
|
|
|
|
const TYPES = [
|
|
self::TYPE_BANK => '银行卡',
|
|
self::TYPE_ALIPAY => '支付宝',
|
|
];
|
|
|
|
const TYPES_LABEL = [
|
|
self::TYPE_BANK => 'primary',
|
|
self::TYPE_ALIPAY => 'success',
|
|
];
|
|
|
|
protected $casts = [
|
|
'source' => 'json',
|
|
];
|
|
|
|
public static function boot()
|
|
{
|
|
parent::boot();
|
|
|
|
self::creating(function ($model) {
|
|
$time = explode(' ', microtime());
|
|
|
|
$counter = $model->whereDate('created_at', Carbon::today())->count() + 1;
|
|
|
|
$len = config('withdraw.withdraw_no_counter_length');
|
|
|
|
$len = $len < 6 ? 6 : $len;
|
|
$len = $len > 16 ? 16 : $len;
|
|
|
|
$model->withdraw_no = date('YmdHis').
|
|
sprintf('%06d', $time[0] * 1e6).
|
|
sprintf('%0'.$len.'d', $counter);
|
|
|
|
$model->status = self::STATUS_INIT;
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Notes: 关联银行账号
|
|
*
|
|
* @Author: 玄尘
|
|
* @Date : 2021/9/27 8:39
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
*/
|
|
public function bankAccount(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Account::class);
|
|
}
|
|
|
|
/**
|
|
* Notes: 支付宝账号
|
|
*
|
|
* @Author: 玄尘
|
|
* @Date : 2021/11/3 15:58
|
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
|
*/
|
|
public function alipayAccount(): BelongsTo
|
|
{
|
|
return $this->belongsTo(AlipayAccount::class);
|
|
}
|
|
|
|
/**
|
|
* Notes: 提现状态
|
|
*
|
|
* @Author: 玄尘
|
|
* @Date : 2021/9/26 15:06
|
|
* @return string
|
|
*/
|
|
public function getStatusTextAttribute(): string
|
|
{
|
|
return self::STATUS[$this->status] ?? '未知';
|
|
}
|
|
|
|
/**
|
|
* Notes: 是否可以审核
|
|
*
|
|
* @Author: 玄尘
|
|
* @Date : 2021/9/26 15:06
|
|
* @return bool
|
|
*/
|
|
public function canAudit(): bool
|
|
{
|
|
return $this->status == self::STATUS_INIT;
|
|
}
|
|
|
|
/**
|
|
* Notes: 操作记录
|
|
*
|
|
* @Author: 玄尘
|
|
* @Date : 2021/9/27 8:53
|
|
* @return \Illuminate\Database\Eloquent\Relations\HasMany
|
|
*/
|
|
public function logs(): HasMany
|
|
{
|
|
return $this->hasMany(Log::class);
|
|
}
|
|
|
|
}
|