| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- <?php
- namespace App\Module\Point\Models;
- use App\Module\Point\Enums\POINT_CURRENCY_TYPE;
- use App\Module\Point\Casts\PointCurrencyDisplayAttributesCast;
- use UCore\ModelCore;
- /**
- * 积分类型表
- *
- * 用于存储系统支持的各种积分类型信息,如经验积分、成就积分等。
- * 一个积分类型可以对应多个积分账户种类(PointConfigModel)。
- * 专注于整数积分处理,不涉及小数运算。
- *
- * field start
- * @property int $id 自增
- * @property string $identification 积分标识
- * @property \App\Module\Point\Enums\POINT_CURRENCY_TYPE $type 积分类型,关联POINT_CURRENCY_TYPE枚举
- * @property string $icon 积分图标
- * @property string $name 积分名称
- * @property \App\Module\Point\Casts\PointCurrencyDisplayAttributesCast $display_attributes 显示属性,如图标、颜色等
- * @property int $create_time
- * @property int $update_time 更新时间
- * field end
- */
- class PointCurrencyModel extends ModelCore
- {
- protected $table = 'point_currency';
- // attrlist start
- protected $fillable = [
- 'id',
- 'identification',
- 'type',
- 'icon',
- 'name',
- 'display_attributes',
- 'create_time',
- 'update_time',
- ];
- // attrlist end
- public $timestamps = false;
- protected $casts = [
- 'type' => POINT_CURRENCY_TYPE::class,
- 'display_attributes' => PointCurrencyDisplayAttributesCast::class,
- ];
- /**
- * 根据类型获取积分类型配置
- *
- * @param int $type 积分类型
- * @return PointCurrencyModel|null 积分类型模型
- */
- public static function getByType(int $type): ?PointCurrencyModel
- {
- return self::where('type', $type)->first();
- }
- /**
- * 根据标识获取积分类型配置
- *
- * @param string $identification 积分标识
- * @return PointCurrencyModel|null 积分类型模型
- */
- public static function getByIdentification(string $identification): ?PointCurrencyModel
- {
- return self::where('identification', $identification)->first();
- }
- /**
- * 获取所有积分类型
- *
- * @return \Illuminate\Database\Eloquent\Collection 积分类型集合
- */
- public static function getAllCurrencies()
- {
- return self::orderBy('type')->get();
- }
- /**
- * 检查积分类型是否存在
- *
- * @param int $type 积分类型
- * @return bool 是否存在
- */
- public static function typeExists(int $type): bool
- {
- return self::where('type', $type)->exists();
- }
- /**
- * 检查积分标识是否存在
- *
- * @param string $identification 积分标识
- * @return bool 是否存在
- */
- public static function identificationExists(string $identification): bool
- {
- return self::where('identification', $identification)->exists();
- }
- /**
- * 获取积分类型名称
- *
- * @return string 积分类型名称
- */
- public function getCurrencyName(): string
- {
- return $this->type->getCurrencyName();
- }
- /**
- * 获取积分类型标识
- *
- * @return string 积分类型标识
- */
- public function getIdentification(): string
- {
- return $this->type->getIdentification();
- }
- /**
- * 获取积分类型描述
- *
- * @return string 积分类型描述
- */
- public function getDescription(): string
- {
- return $this->type->getDescription();
- }
- /**
- * 获取积分类型图标
- *
- * @return string 积分类型图标
- */
- public function getTypeIcon(): string
- {
- return $this->type->getIcon();
- }
- /**
- * 关联积分配置表
- */
- public function configs()
- {
- return $this->hasMany(PointConfigModel::class, 'currency_id');
- }
- }
|