| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- <?php
- namespace App\Module\Point\Models;
- use App\Module\Point\Enums\POINT_TYPE;
- use App\Module\Point\Casts\PointDisplayAttributesCast;
- use UCore\ModelCore;
- /**
- * 积分配置表
- *
- * 用于存储系统支持的各种积分账户类型,如经验积分、成就积分等。
- * 同一个积分类型(PointCurrencyModel)可以有多个不同的账户种类。
- *
- * field start
- * @property int $id 自增
- * @property string $name 积分名称
- * @property int $currency_id 关联的积分类型ID,外键关联kku_point_currency表
- * @property \App\Module\Point\Enums\POINT_TYPE $type 积分账户类型,关联POINT_TYPE枚举
- * @property \App\Module\Point\Casts\PointDisplayAttributesCast $display_attributes 显示属性,如图标、颜色等
- * @property int $create_time
- * @property int $update_time 更新时间
- * field end
- */
- class PointConfigModel extends ModelCore
- {
- protected $table = 'point_config';
- // attrlist start
- protected $fillable = [
- 'id',
- 'name',
- 'currency_id',
- 'type',
- 'display_attributes',
- 'create_time',
- 'update_time',
- ];
- // attrlist end
- public $timestamps = false;
- protected $casts = [
- 'type' => POINT_TYPE::class,
- 'display_attributes' => PointDisplayAttributesCast::class,
- ];
- /**
- * 获取积分类型配置
- *
- * @param int $pointType 积分类型
- * @return PointConfigModel|null 配置模型
- */
- public static function getByType(int $pointType): ?PointConfigModel
- {
- return self::where('type', $pointType)->first();
- }
- /**
- * 获取所有积分配置
- *
- * @return \Illuminate\Database\Eloquent\Collection 配置集合
- */
- public static function getAllConfigs()
- {
- return self::orderBy('type')->get();
- }
- /**
- * 根据积分类型ID获取配置
- *
- * @param int $currencyId 积分类型ID
- * @return \Illuminate\Database\Eloquent\Collection 配置集合
- */
- public static function getByCurrencyId(int $currencyId)
- {
- return self::where('currency_id', $currencyId)->get();
- }
- /**
- * 检查积分类型是否存在
- *
- * @param int $pointType 积分类型
- * @return bool 是否存在
- */
- public static function typeExists(int $pointType): bool
- {
- return self::where('type', $pointType)->exists();
- }
- /**
- * 获取积分类型名称
- *
- * @return string 积分类型名称
- */
- public function getTypeName(): string
- {
- return $this->type->getTypeName();
- }
- /**
- * 获取积分类型描述
- *
- * @return string 积分类型描述
- */
- public function getTypeDescription(): string
- {
- return $this->type->getDescription();
- }
- /**
- * 关联积分类型表
- */
- public function currency()
- {
- return $this->belongsTo(PointCurrencyModel::class, 'currency_id');
- }
- }
|