75 lines
1.6 KiB
PHP
75 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Casts\Attribute;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Illuminate\Database\Eloquent\Relations\HasOne;
|
|
use Modules\SystemTool\Models\SysFileModel;
|
|
|
|
/**
|
|
* 客户等级模型(同一商品按客户等级定价)
|
|
*/
|
|
class CustomerLevelModel extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
/** 状态:停用 */
|
|
public const int STATUS_DISABLED = 0;
|
|
/** 状态:正常 */
|
|
public const int STATUS_NORMAL = 1;
|
|
|
|
protected $table = 'customer_level';
|
|
protected $primaryKey = 'id';
|
|
|
|
protected $fillable = [
|
|
'name',
|
|
'sort',
|
|
'status',
|
|
'icon'
|
|
];
|
|
|
|
protected $casts = [
|
|
'sort' => 'integer',
|
|
'status' => 'integer',
|
|
'created_at' => 'datetime:Y-m-d H:i:s',
|
|
'updated_at' => 'datetime:Y-m-d H:i:s',
|
|
];
|
|
|
|
protected $appends = ['icon_url'];
|
|
|
|
/**
|
|
* 关联图标
|
|
*/
|
|
public function icon(): HasOne
|
|
{
|
|
return $this->hasOne(SysFileModel::class, 'id', 'icon');
|
|
}
|
|
|
|
// 图标链接
|
|
public function icon_url(): Attribute
|
|
{
|
|
return Attribute::make(
|
|
get: fn () => $this->icon->preview_url,
|
|
);
|
|
}
|
|
|
|
/**
|
|
* 该等级下的门店
|
|
*/
|
|
public function stores(): HasMany
|
|
{
|
|
return $this->hasMany(StoreModel::class, 'level_id', 'id');
|
|
}
|
|
|
|
/**
|
|
* 该等级下的商品价格
|
|
*/
|
|
public function prices(): HasMany
|
|
{
|
|
return $this->hasMany(ProductPriceModel::class, 'level_id', 'id');
|
|
}
|
|
}
|