TransferApp.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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 string $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 是否启用
  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. /**
  39. * 可批量赋值的属性
  40. */
  41. protected $fillable = [
  42. 'keyname',
  43. 'title',
  44. 'description',
  45. 'out_id',
  46. 'out_id2',
  47. 'out_id3',
  48. 'currency_id',
  49. 'fund_id',
  50. 'fund_to_uid',
  51. 'fund_in_uid',
  52. 'exchange_rate',
  53. 'order_callback_url',
  54. 'order_in_info_url',
  55. 'order_out_create_url',
  56. 'order_out_info_url',
  57. 'is_enabled',
  58. ];
  59. // attrlist end
  60. /**
  61. * 属性类型转换
  62. */
  63. protected $casts = [
  64. 'id' => 'integer',
  65. 'out_id' => 'integer',
  66. 'out_id2' => 'integer',
  67. 'out_id3' => 'integer',
  68. 'currency_id' => 'integer',
  69. 'fund_id' => 'integer',
  70. 'fund_to_uid' => 'integer',
  71. 'fund_in_uid' => 'integer',
  72. 'exchange_rate' => 'decimal:4',
  73. 'is_enabled' => 'boolean',
  74. 'created_at' => 'datetime',
  75. 'updated_at' => 'datetime',
  76. 'deleted_at' => 'datetime',
  77. ];
  78. /**
  79. * 软删除
  80. */
  81. protected $dates = ['deleted_at'];
  82. /**
  83. * 隐藏字段
  84. */
  85. protected $hidden = [];
  86. /**
  87. * 关联划转订单
  88. */
  89. public function orders()
  90. {
  91. return $this->hasMany(TransferOrder::class, 'transfer_app_id');
  92. }
  93. /**
  94. * 获取启用状态文本
  95. */
  96. public function getEnabledTextAttribute(): string
  97. {
  98. return $this->is_enabled ? '启用' : '禁用';
  99. }
  100. /**
  101. * 获取启用状态颜色
  102. */
  103. public function getEnabledColorAttribute(): string
  104. {
  105. return $this->is_enabled ? 'success' : 'danger';
  106. }
  107. /**
  108. * 判断是否为农场内部模式
  109. */
  110. public function isInternalMode(): bool
  111. {
  112. return empty($this->order_callback_url) &&
  113. empty($this->order_in_info_url) &&
  114. empty($this->order_out_create_url) &&
  115. empty($this->order_out_info_url);
  116. }
  117. /**
  118. * 判断是否支持转入
  119. */
  120. public function supportsTransferIn(): bool
  121. {
  122. return !empty($this->order_in_info_url) || $this->isInternalMode();
  123. }
  124. /**
  125. * 判断是否支持转出
  126. */
  127. public function supportsTransferOut(): bool
  128. {
  129. return !empty($this->order_out_create_url) || $this->isInternalMode();
  130. }
  131. /**
  132. * 判断是否支持回调
  133. */
  134. public function supportsCallback(): bool
  135. {
  136. return !empty($this->order_callback_url);
  137. }
  138. }