FundConfigModel.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. namespace App\Module\Fund\Models;
  3. use App\Module\Fund\Casts\FundDisplayAttributesCast;
  4. use App\Module\Fund\Enums\FUND_TYPE;
  5. use UCore\ModelCore;
  6. /**
  7. * 账户种类配置表
  8. *
  9. * 用于存储系统支持的各种账户种类,如可用账户、冻结账户等。
  10. * 同一个币种(FundCurrencyModel)可以有多个不同的账户种类。
  11. *
  12. * field start
  13. * @property int $id 自增
  14. * @property string $name 资金名字
  15. * @property int $currency_id 关联的币种ID,外键关联kku_fund_currency表
  16. * @property \App\Module\Fund\Enums\FUND_TYPE $type 账户种类类型,关联FUND_TYPE枚举
  17. * @property \App\Module\Fund\Casts\FundDisplayAttributesCast $display_attributes 显示属性,如图标、颜色等
  18. * @property int $create_time
  19. * @property int $update_time 更新时间
  20. * field end
  21. */
  22. class FundConfigModel extends ModelCore
  23. {
  24. protected $table = 'fund_config';
  25. // attrlist start
  26. protected $fillable = [
  27. 'id',
  28. 'name',
  29. 'currency_id',
  30. 'type',
  31. 'display_attributes',
  32. 'create_time',
  33. 'update_time',
  34. ];
  35. // attrlist end
  36. public $timestamps = false;
  37. /**
  38. * 应该被转换为原生类型的属性
  39. *
  40. * @var array
  41. */
  42. protected $casts = [
  43. 'type' => FUND_TYPE::class,
  44. 'display_attributes' => FundDisplayAttributesCast::class,
  45. ];
  46. /**
  47. * 获取关联的币种
  48. *
  49. * 一个账户种类属于一个币种,这是一对多关系中的"多"一方
  50. *
  51. * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
  52. */
  53. public function currency()
  54. {
  55. return $this->belongsTo(FundCurrencyModel::class, 'currency_id');
  56. }
  57. /**
  58. * 获取显示属性
  59. *
  60. * @return FundDisplayAttributesCast|null
  61. */
  62. public function getDisplayAttributes(): ?FundDisplayAttributesCast
  63. {
  64. return $this->display_attributes;
  65. }
  66. /**
  67. * 设置显示属性
  68. *
  69. * @param array|FundDisplayAttributesCast $attributes
  70. * @return $this
  71. */
  72. public function setDisplayAttributes($attributes)
  73. {
  74. $this->display_attributes = $attributes;
  75. return $this;
  76. }
  77. }