初始化本地仓库
This commit is contained in:
@@ -0,0 +1,228 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\model\member;
|
||||
|
||||
use app\enum\common\EnabledStatus;
|
||||
use app\enum\system\Sex;
|
||||
use core\base\BaseModel;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
/**
|
||||
* 会员模型
|
||||
*/
|
||||
class Member extends BaseModel
|
||||
{
|
||||
|
||||
/**
|
||||
* 启用软删除
|
||||
*/
|
||||
use SoftDeletes;
|
||||
|
||||
/**
|
||||
* 数据表名称
|
||||
*/
|
||||
protected $table = 'member';
|
||||
|
||||
/**
|
||||
* 数据表主键
|
||||
*/
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
protected static function booted(): void
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 可批量赋值的字段
|
||||
*/
|
||||
protected $fillable = [
|
||||
'id',
|
||||
'username',
|
||||
'email',
|
||||
'phone',
|
||||
'password',
|
||||
'nickname',
|
||||
'avatar',
|
||||
'level_id',
|
||||
'points',
|
||||
'balance',
|
||||
'gender',
|
||||
'birthday',
|
||||
'last_login_time',
|
||||
'last_login_ip',
|
||||
'login_count',
|
||||
'enabled',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'deleted_at',
|
||||
'bio'
|
||||
];
|
||||
|
||||
/**
|
||||
* 隐藏字段
|
||||
*/
|
||||
protected $hidden = [
|
||||
'password',
|
||||
];
|
||||
|
||||
/**
|
||||
* 追加字段
|
||||
*/
|
||||
protected $appends = [
|
||||
'gender_text',
|
||||
'enabled_text',
|
||||
];
|
||||
|
||||
/**
|
||||
* 获取性别文本
|
||||
*/
|
||||
public function getGenderTextAttribute(): string
|
||||
{
|
||||
return Sex::tryFrom($this->gender)?->label() ?? '未知';
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取状态文本
|
||||
*/
|
||||
public function getEnabledTextAttribute(): string
|
||||
{
|
||||
return EnabledStatus::tryFrom($this->enabled)?->label() ?? '未知';
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联会员等级
|
||||
*/
|
||||
public function level(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(MemberLevel::class, 'level_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联会员标签
|
||||
*/
|
||||
public function tags(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(MemberTag::class, MemberTagRelation::class, 'member_id', 'tag_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联签到记录
|
||||
*/
|
||||
public function signRecords(): Member|\Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Relations\HasMany
|
||||
{
|
||||
return $this->hasMany(MemberSign::class, 'member_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联第三方登录
|
||||
*/
|
||||
public function thirdParties(): Member|\Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Relations\HasMany
|
||||
{
|
||||
return $this->hasMany(MemberThirdParty::class, 'member_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联收货地址
|
||||
*/
|
||||
public function addresses(): Member|\Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Relations\HasMany
|
||||
{
|
||||
return $this->hasMany(MemberAddress::class, 'member_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联提现账号
|
||||
*/
|
||||
public function withdrawAccounts(): Member|\Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Relations\HasMany
|
||||
{
|
||||
return $this->hasMany(MemberWithdrawAccount::class, 'member_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联提现记录
|
||||
*/
|
||||
public function withdraws(): Member|\Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Relations\HasMany
|
||||
{
|
||||
return $this->hasMany(MemberWithdraw::class, 'member_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联账单记录
|
||||
*/
|
||||
public function bills(): Member|\Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Relations\HasMany
|
||||
{
|
||||
return $this->hasMany(MemberBill::class, 'member_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联积分记录
|
||||
*/
|
||||
public function pointsRecords(): Member|\Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Relations\HasMany
|
||||
{
|
||||
return $this->hasMany(MemberPoints::class, 'member_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联分组
|
||||
*/
|
||||
public function groups(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(MemberGroup::class, 'member_group_relation', 'member_id', 'group_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置密码
|
||||
*/
|
||||
public function setPasswordAttribute($value): void
|
||||
{
|
||||
$this->attributes['password'] = password_hash($value, PASSWORD_DEFAULT);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置生日
|
||||
*/
|
||||
public function setBirthdayAttribute($value): void
|
||||
{
|
||||
if (empty($value)) {
|
||||
$this->attributes['birthday'] = null;
|
||||
return;
|
||||
}
|
||||
|
||||
if (is_numeric($value)) {
|
||||
$this->attributes['birthday'] = $value;
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$carbon = \Carbon\Carbon::parse($value);
|
||||
$this->attributes['birthday'] = $carbon->timestamp;
|
||||
} catch (\Exception $e) {
|
||||
$this->attributes['birthday'] = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取生日
|
||||
*/
|
||||
public function getBirthdayAttribute($value): ?string
|
||||
{
|
||||
if (empty($value)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
return \Carbon\Carbon::createFromTimestamp($value)->toIso8601String();
|
||||
} catch (\Exception $e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证密码
|
||||
*/
|
||||
public function verifyPassword($password): bool
|
||||
{
|
||||
return password_verify($password, $this->password);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\model\member;
|
||||
|
||||
use app\enum\common\EnabledStatus;
|
||||
use core\base\BaseModel;
|
||||
|
||||
/**
|
||||
* 会员收货地址模型
|
||||
*/
|
||||
class MemberAddress extends BaseModel
|
||||
{
|
||||
/**
|
||||
* 数据表名称
|
||||
*/
|
||||
protected $table = 'member_address';
|
||||
|
||||
/**
|
||||
* 数据表主键
|
||||
*/
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
/**
|
||||
* 可批量赋值的字段
|
||||
*/
|
||||
protected $fillable = [
|
||||
'id',
|
||||
'member_id',
|
||||
'name',
|
||||
'phone',
|
||||
'province',
|
||||
'city',
|
||||
'district',
|
||||
'address',
|
||||
'zipcode',
|
||||
'is_default',
|
||||
'enabled',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'deleted_at',
|
||||
];
|
||||
|
||||
/**
|
||||
* 追加字段
|
||||
*/
|
||||
protected $appends = [
|
||||
'is_default_text',
|
||||
'enabled_text',
|
||||
'full_address',
|
||||
];
|
||||
|
||||
/**
|
||||
* 获取默认状态文本
|
||||
*/
|
||||
public function getIsDefaultTextAttribute(): string
|
||||
{
|
||||
return $this->is_default == 1 ? '默认' : '非默认';
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取状态文本
|
||||
*/
|
||||
public function getEnabledTextAttribute(): string
|
||||
{
|
||||
return EnabledStatus::tryFrom($this->enabled)?->label() ?? '未知';
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取完整地址
|
||||
*/
|
||||
public function getFullAddressAttribute(): string
|
||||
{
|
||||
return implode('', [
|
||||
$this->province,
|
||||
$this->city,
|
||||
$this->district,
|
||||
$this->address,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联会员
|
||||
*/
|
||||
public function member(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Member::class, 'member_id', 'id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\model\member;
|
||||
|
||||
use core\base\BaseModel;
|
||||
use app\enum\member\BillType;
|
||||
use app\enum\member\BillCategory;
|
||||
use app\enum\member\BillStatus;
|
||||
|
||||
/**
|
||||
* 会员账单模型
|
||||
*/
|
||||
class MemberBill extends BaseModel
|
||||
{
|
||||
/**
|
||||
* 数据表名称
|
||||
*/
|
||||
protected $table = 'member_bill';
|
||||
|
||||
/**
|
||||
* 数据表主键
|
||||
*/
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
/**
|
||||
* 可批量赋值的字段
|
||||
*/
|
||||
protected $fillable = [
|
||||
'id',
|
||||
'member_id',
|
||||
'type',
|
||||
'category',
|
||||
'amount',
|
||||
'balance',
|
||||
'description',
|
||||
'order_sn',
|
||||
'status',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
];
|
||||
|
||||
/**
|
||||
* 追加字段
|
||||
*/
|
||||
protected $appends = [
|
||||
'type_text',
|
||||
'category_text',
|
||||
'status_text',
|
||||
];
|
||||
|
||||
/**
|
||||
* 获取类型文本
|
||||
*/
|
||||
public function getTypeTextAttribute(): string
|
||||
{
|
||||
return BillType::tryFrom($this->type)?->text() ?? '未知';
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取分类文本
|
||||
*/
|
||||
public function getCategoryTextAttribute(): string
|
||||
{
|
||||
return BillCategory::tryFrom($this->category)?->text() ?? '未知';
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取状态文本
|
||||
*/
|
||||
public function getStatusTextAttribute(): string
|
||||
{
|
||||
return BillStatus::tryFrom($this->status)?->text() ?? '未知';
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联会员
|
||||
*/
|
||||
public function member(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Member::class, 'member_id', 'id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\model\member;
|
||||
|
||||
use core\base\BaseModel;
|
||||
|
||||
|
||||
/**
|
||||
* 会员等级模型
|
||||
*/
|
||||
class MemberLevel extends BaseModel
|
||||
{
|
||||
/**
|
||||
* 数据表名称
|
||||
*/
|
||||
protected $table = 'member_level';
|
||||
|
||||
/**
|
||||
* 数据表主键
|
||||
*/
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
/**
|
||||
* 可批量赋值的字段
|
||||
*/
|
||||
protected $fillable = [
|
||||
'id',
|
||||
'name',
|
||||
'level',
|
||||
'min_points',
|
||||
'max_points',
|
||||
'discount',
|
||||
'icon',
|
||||
'color',
|
||||
'description',
|
||||
'enabled',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
];
|
||||
|
||||
/**
|
||||
* 追加字段
|
||||
*/
|
||||
protected $appends = [
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* 关联会员
|
||||
*/
|
||||
public function members(): \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Relations\HasMany|MemberLevel
|
||||
{
|
||||
return $this->hasMany(Member::class, 'level_id', 'id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\model\member;
|
||||
|
||||
|
||||
|
||||
use core\base\BaseModel;
|
||||
|
||||
/**
|
||||
* 会员积分模型
|
||||
*/
|
||||
class MemberPoints extends BaseModel
|
||||
{
|
||||
|
||||
protected $table = 'member_points';
|
||||
|
||||
protected $fillable = [
|
||||
'id',
|
||||
'member_id',
|
||||
'points',
|
||||
'balance',
|
||||
'points_after',
|
||||
'type',
|
||||
'source',
|
||||
'remark',
|
||||
'operator',
|
||||
'order_id',
|
||||
'created_at',
|
||||
'create_time',
|
||||
];
|
||||
|
||||
/**
|
||||
* 主键类型
|
||||
*/
|
||||
protected $keyType = 'string';
|
||||
|
||||
/**
|
||||
* 是否自增
|
||||
*/
|
||||
public $incrementing = false;
|
||||
|
||||
protected static function booted(): void
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected $casts = [
|
||||
'points' => 'integer',
|
||||
'balance' => 'integer',
|
||||
'points_after' => 'integer',
|
||||
'type' => 'integer',
|
||||
];
|
||||
|
||||
/**
|
||||
* 关联会员模型
|
||||
*/
|
||||
public function member(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Member::class, 'member_id', 'id');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\model\member;
|
||||
|
||||
use core\base\BaseModel;
|
||||
|
||||
/**
|
||||
* 会员签到模型
|
||||
*/
|
||||
class MemberSign extends BaseModel
|
||||
{
|
||||
/**
|
||||
* 数据表名称
|
||||
*/
|
||||
protected $table = 'member_sign';
|
||||
|
||||
/**
|
||||
* 数据表主键
|
||||
*/
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
/**
|
||||
* 可批量赋值的字段
|
||||
*/
|
||||
protected $fillable = [
|
||||
'id',
|
||||
'member_id',
|
||||
'sign_date',
|
||||
'points',
|
||||
'continuous_days',
|
||||
'device_ip',
|
||||
'device_ua',
|
||||
'created_at',
|
||||
'updated_at'
|
||||
];
|
||||
|
||||
/**
|
||||
* 关联会员
|
||||
*/
|
||||
public function member(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Member::class, 'member_id', 'id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\model\member;
|
||||
|
||||
use app\model\web\Menu;
|
||||
use core\base\BaseModel;
|
||||
use app\enum\common\EnabledStatus;
|
||||
|
||||
/**
|
||||
* 会员标签模型
|
||||
*/
|
||||
class MemberTag extends BaseModel
|
||||
{
|
||||
/**
|
||||
* 数据表名称
|
||||
*/
|
||||
protected $table = 'member_tag';
|
||||
|
||||
/**
|
||||
* 数据表主键
|
||||
*/
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
/**
|
||||
* 可批量赋值的字段
|
||||
*/
|
||||
protected $fillable = [
|
||||
'id',
|
||||
'name',
|
||||
'color',
|
||||
'description',
|
||||
'sort',
|
||||
'enabled',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
];
|
||||
|
||||
/**
|
||||
* 追加字段
|
||||
*/
|
||||
protected $appends = [
|
||||
'enabled_text',
|
||||
];
|
||||
|
||||
/**
|
||||
* 获取状态文本
|
||||
*/
|
||||
public function getEnabledTextAttribute(): string
|
||||
{
|
||||
return EnabledStatus::tryFrom($this->enabled)?->label() ?? '未知';
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联会员
|
||||
*/
|
||||
public function members(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Member::class, 'member_tag_relation', 'tag_id', 'member_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联菜单权限
|
||||
*/
|
||||
public function permissions(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Menu::class, MemberTagPermission::class, 'tag_id', 'menu_id')->orderBy('sort');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\model\member;
|
||||
|
||||
use Illuminate\Database\Eloquent\Relations\Pivot;
|
||||
|
||||
/**
|
||||
* 会员标签菜单关联中间模型(Pivot)
|
||||
*
|
||||
* 用于 MemberTag 和 Menu 之间的多对多关联
|
||||
*/
|
||||
class MemberTagPermission extends Pivot
|
||||
{
|
||||
/**
|
||||
* 关联的表名
|
||||
*/
|
||||
protected $table = 'member_tag_permission';
|
||||
|
||||
|
||||
/**
|
||||
* 可批量赋值的字段
|
||||
*/
|
||||
protected $fillable = [
|
||||
'tag_id',
|
||||
'menu_id',
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\model\member;
|
||||
|
||||
use Illuminate\Database\Eloquent\Relations\Pivot;
|
||||
|
||||
/**
|
||||
* 会员标签关系模型
|
||||
*/
|
||||
class MemberTagRelation extends Pivot
|
||||
{
|
||||
/**
|
||||
* 数据表名称
|
||||
*/
|
||||
protected $table = 'member_tag_relation';
|
||||
|
||||
/**
|
||||
* 可批量赋值的字段
|
||||
*/
|
||||
protected $fillable = [
|
||||
'member_id',
|
||||
'tag_id',
|
||||
];
|
||||
|
||||
/**
|
||||
* 关联会员
|
||||
*/
|
||||
public function member(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Member::class, 'member_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联标签
|
||||
*/
|
||||
public function tag(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(MemberTag::class, 'tag_id', 'id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\model\member;
|
||||
|
||||
use app\enum\common\EnabledStatus;
|
||||
use app\enum\member\ThirdPartyPlatform;
|
||||
use core\base\BaseModel;
|
||||
|
||||
/**
|
||||
* 会员第三方登录模型
|
||||
*
|
||||
* @property int|mixed $enabled*/
|
||||
class MemberThirdParty extends BaseModel
|
||||
{
|
||||
/**
|
||||
* 数据表名称
|
||||
*/
|
||||
protected $table = 'member_third_party';
|
||||
|
||||
/**
|
||||
* 数据表主键
|
||||
*/
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
/**
|
||||
* 可批量赋值的字段
|
||||
*/
|
||||
protected $fillable = [
|
||||
'id',
|
||||
'member_id',
|
||||
'platform',
|
||||
'openid',
|
||||
'unionid',
|
||||
'nickname',
|
||||
'avatar',
|
||||
'gender',
|
||||
'country',
|
||||
'province',
|
||||
'city',
|
||||
'access_token',
|
||||
'refresh_token',
|
||||
'enabled',
|
||||
'expires_at',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
];
|
||||
|
||||
/**
|
||||
* 追加字段
|
||||
*/
|
||||
protected $appends = [
|
||||
'platform_text',
|
||||
'enabled_text',
|
||||
];
|
||||
|
||||
/**
|
||||
* 获取平台文本
|
||||
*/
|
||||
public function getPlatformTextAttribute(): string
|
||||
{
|
||||
return ThirdPartyPlatform::tryFrom($this->platform)?->text() ?? '未知';
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取状态文本
|
||||
*/
|
||||
public function getEnabledTextAttribute(): string
|
||||
{
|
||||
return EnabledStatus::tryFrom($this->enabled)?->label() ?? '未知';
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联会员
|
||||
*/
|
||||
public function member(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Member::class, 'member_id', 'id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\model\member;
|
||||
|
||||
use core\base\BaseModel;
|
||||
use app\enum\member\WithdrawStatus;
|
||||
|
||||
/**
|
||||
* 会员提现模型
|
||||
*/
|
||||
class MemberWithdraw extends BaseModel
|
||||
{
|
||||
/**
|
||||
* 数据表名称
|
||||
*/
|
||||
protected $table = 'member_withdraw';
|
||||
|
||||
/**
|
||||
* 数据表主键
|
||||
*/
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
/**
|
||||
* 可批量赋值的字段
|
||||
*/
|
||||
protected $fillable = [
|
||||
'id',
|
||||
'member_id',
|
||||
'account_id',
|
||||
'amount',
|
||||
'fee',
|
||||
'actual_amount',
|
||||
'status',
|
||||
'bank_name',
|
||||
'bank_account',
|
||||
'bank_cardholder',
|
||||
'order_sn',
|
||||
'remark',
|
||||
'audit_remark',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'audit_at',
|
||||
];
|
||||
|
||||
/**
|
||||
* 追加字段
|
||||
*/
|
||||
protected $appends = [
|
||||
'status_text',
|
||||
];
|
||||
|
||||
/**
|
||||
* 获取状态文本
|
||||
*/
|
||||
public function getStatusTextAttribute(): string
|
||||
{
|
||||
return WithdrawStatus::tryFrom($this->status)?->text() ?? '未知';
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联会员
|
||||
*/
|
||||
public function member(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Member::class, 'member_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联提现账号
|
||||
*/
|
||||
public function account(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(MemberWithdrawAccount::class, 'account_id', 'id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace app\model\member;
|
||||
|
||||
use app\enum\common\EnabledStatus;
|
||||
use app\enum\member\WithdrawAccountType;
|
||||
use core\base\BaseModel;
|
||||
|
||||
/**
|
||||
* 会员提现账号模型
|
||||
*/
|
||||
class MemberWithdrawAccount extends BaseModel
|
||||
{
|
||||
/**
|
||||
* 数据表名称
|
||||
*/
|
||||
protected $table = 'member_withdraw_account';
|
||||
|
||||
/**
|
||||
* 数据表主键
|
||||
*/
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
/**
|
||||
* 可批量赋值的字段
|
||||
*/
|
||||
protected $fillable = [
|
||||
'id',
|
||||
'member_id',
|
||||
'type',
|
||||
'bank_name',
|
||||
'account_name',
|
||||
'account_number',
|
||||
'branch_name',
|
||||
'is_default',
|
||||
'enabled',
|
||||
'created_at',
|
||||
'updated_at',
|
||||
'deleted_at',
|
||||
];
|
||||
|
||||
/**
|
||||
* 追加字段
|
||||
*/
|
||||
protected $appends = [
|
||||
'type_text',
|
||||
'is_default_text',
|
||||
'enabled_text',
|
||||
];
|
||||
|
||||
/**
|
||||
* 获取类型文本
|
||||
*/
|
||||
public function getTypeTextAttribute(): string
|
||||
{
|
||||
return WithdrawAccountType::tryFrom($this->type)?->label() ?? '未知';
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取默认状态文本
|
||||
*/
|
||||
public function getIsDefaultTextAttribute(): string
|
||||
{
|
||||
return $this->is_default == 1 ? '默认' : '非默认';
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取状态文本
|
||||
*/
|
||||
public function getEnabledTextAttribute(): string
|
||||
{
|
||||
return EnabledStatus::tryFrom($this->enabled)?->label() ?? '未知';
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联会员
|
||||
*/
|
||||
public function member(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Member::class, 'member_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联提现记录
|
||||
*/
|
||||
public function withdraws(): MemberWithdrawAccount|\Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Relations\HasMany
|
||||
{
|
||||
return $this->hasMany(MemberWithdraw::class, 'account_id', 'id');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user