TransferApp.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <?php
  2. namespace App\Module\Transfer\Models;
  3. use App\Module\Transfer\Casts\TransferAppCast;
  4. use UCore\ModelCore;
  5. /**
  6. * 划转应用配置模型
  7. *
  8. * field start
  9. * @property int $id 主键ID
  10. * @property string $keyname 应用标识符
  11. * @property string $title 应用显示名称
  12. * @property string $description 应用描述信息
  13. * @property int $out_id 外部应用ID
  14. * @property int $out_id2 外部应用ID2-开放接口
  15. * @property int $out_id3 外部应用ID3-三方平台ID
  16. * @property int $currency_id 货币类型ID
  17. * @property int $fund_id 资金账户类型ID
  18. * @property int $fund_to_uid 转入目标账户UID
  19. * @property int $fund_in_uid 转入来源账户UID
  20. * @property float $exchange_rate 汇率(钱包:业务)
  21. * @property string $order_callback_url 结果通知API地址(为空则不通知)
  22. * @property string $order_in_info_url 转入查询API地址(为空则不查询)
  23. * @property string $order_out_create_url 转出创建API地址(为空则不创建)
  24. * @property string $order_out_info_url 转出查询API地址(为空则不查询)
  25. * @property bool $is_enabled 是否启用(1=启用,0=禁用)
  26. * @property \Carbon\Carbon $created_at 创建时间
  27. * @property \Carbon\Carbon $updated_at 更新时间
  28. * @property \Carbon\Carbon $deleted_at 删除时间
  29. * field end
  30. */
  31. class TransferApp extends ModelCore
  32. {
  33. /**
  34. * 数据表名
  35. */
  36. protected $table = 'transfer_apps';
  37. // attrlist start
  38. protected $fillable = [
  39. 'id',
  40. 'keyname',
  41. 'title',
  42. 'description',
  43. 'out_id',
  44. 'out_id2',
  45. 'out_id3',
  46. 'currency_id',
  47. 'fund_id',
  48. 'fund_to_uid',
  49. 'fund_in_uid',
  50. 'exchange_rate',
  51. 'order_callback_url',
  52. 'order_in_info_url',
  53. 'order_out_create_url',
  54. 'order_out_info_url',
  55. 'is_enabled',
  56. ];
  57. // attrlist end
  58. /**
  59. * 属性类型转换
  60. */
  61. protected $casts = [
  62. 'id' => 'integer',
  63. 'out_id' => 'integer',
  64. 'out_id2' => 'integer',
  65. 'out_id3' => 'integer',
  66. 'currency_id' => 'integer',
  67. 'fund_id' => 'integer',
  68. 'fund_to_uid' => 'integer',
  69. 'fund_in_uid' => 'integer',
  70. 'exchange_rate' => 'decimal:4',
  71. 'is_enabled' => 'boolean',
  72. 'created_at' => 'datetime',
  73. 'updated_at' => 'datetime',
  74. 'deleted_at' => 'datetime',
  75. ];
  76. /**
  77. * 软删除
  78. */
  79. protected $dates = ['deleted_at'];
  80. /**
  81. * 隐藏字段
  82. */
  83. protected $hidden = [];
  84. /**
  85. * 关联划转订单
  86. */
  87. public function orders()
  88. {
  89. return $this->hasMany(TransferOrder::class, 'transfer_app_id');
  90. }
  91. /**
  92. * 获取启用状态文本
  93. */
  94. public function getEnabledTextAttribute(): string
  95. {
  96. return $this->is_enabled ? '启用' : '禁用';
  97. }
  98. /**
  99. * 获取启用状态颜色
  100. */
  101. public function getEnabledColorAttribute(): string
  102. {
  103. return $this->is_enabled ? 'success' : 'danger';
  104. }
  105. /**
  106. * 判断是否为农场内部模式
  107. */
  108. public function isInternalMode(): bool
  109. {
  110. return empty($this->order_callback_url) &&
  111. empty($this->order_in_info_url) &&
  112. empty($this->order_out_create_url) &&
  113. empty($this->order_out_info_url);
  114. }
  115. /**
  116. * 判断是否支持转入
  117. */
  118. public function supportsTransferIn(): bool
  119. {
  120. return !empty($this->order_in_info_url) || $this->isInternalMode();
  121. }
  122. /**
  123. * 判断是否支持转出
  124. */
  125. public function supportsTransferOut(): bool
  126. {
  127. return !empty($this->order_out_create_url) || $this->isInternalMode();
  128. }
  129. /**
  130. * 判断是否支持回调
  131. */
  132. public function supportsCallback(): bool
  133. {
  134. return !empty($this->order_callback_url);
  135. }
  136. }