TransferApp.php 4.0 KB

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