FundConfigModel.php 2.0 KB

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