RechargeChannel.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. namespace App\Models;
  3. use App\Services\Payment\PaymentProviderCatalog;
  4. class RechargeChannel extends BaseModel
  5. {
  6. protected $table = 'recharge_channel';
  7. protected $fillable = ['id', 'data_type', 'from', 'key', 'name', 'type', 'rate', 'min', 'max', 'fixed', 'sort', 'status'];
  8. protected $hidden = [];
  9. public function getFixedAttribute($value)
  10. {
  11. return $value ? explode(',', $value) : null;
  12. }
  13. public static function getChannel($data_type, $type = [])
  14. {
  15. $query = self::where('status', 1)->where('data_type', $data_type);
  16. if ($type) {
  17. $query = $query->whereIn('type', $type);
  18. }
  19. $channel = $query->orderBy('sort')->orderBy('id')->get(['type', 'name', 'from', 'data_type'])
  20. ->map(fn ($row) => $row->toArray() + PaymentProviderCatalog::channelDisplay($row->toArray()))->all();
  21. $channel = array_column($channel, null, 'type');
  22. return array_values($channel);
  23. }
  24. //获取充值通道
  25. public static function product($from = '')
  26. {
  27. $where['status'] = 1;
  28. $where['data_type'] = 1;
  29. if($from){
  30. $where['from'] = $from;
  31. }
  32. $list = self::where($where)->orderBy('sort', 'asc')->get()->toArray();
  33. return array_column($list, null, 'key');
  34. }
  35. public static function getFormatChannel($data_type, $recharge_channel_group_id = 1)
  36. {
  37. $recharge_channel_group_id = $recharge_channel_group_id > 0 ? $recharge_channel_group_id : 1;
  38. $query = self::where(['status' => 1, 'data_type' => $data_type]);
  39. $field = 'recharge_type'; //充值类型
  40. if ($data_type == 2) {
  41. //提现类型
  42. $field = 'withdraw_type';
  43. } elseif ($data_type == 3) {
  44. //提现类型
  45. $field = 'activity_type';
  46. }
  47. $group = RechargeChannelGroup::query()->find($recharge_channel_group_id);
  48. $types = $group ? (array)$group->{$field} : [];
  49. if (!$types) {
  50. return [];
  51. }
  52. $query = $query->whereIn('type', $types);
  53. $product = $query->orderBy('sort', 'asc')->select(['id', 'data_type','name','type', 'min','max','fixed','rate'])->get()->toArray();
  54. $list = [];
  55. foreach($product as $key => $pv) {
  56. if (isset($list[$pv['type']]['config'])) {
  57. $config = $list[$pv['type']]['config'];
  58. if (empty($config['range'])) {
  59. $config['range'][] = $config;
  60. }
  61. if ($pv['min'] < $config['min']) {
  62. $config['min'] = $pv['min'];
  63. }
  64. if ($pv['max'] > $config['max']) {
  65. $config['max'] = $pv['max'];
  66. }
  67. if ($pv['rate'] < $config['rate']) {
  68. $config['max_rate'] = $config['rate'];
  69. $config['min_rate'] = $pv['rate'];
  70. }
  71. if ($pv['rate'] > $config['rate']) {
  72. $config['max_rate'] = $pv['rate'];
  73. }
  74. $config['range'][] = $pv;
  75. } else {
  76. $config = $pv;
  77. }
  78. $list[$pv['type']] = [
  79. 'key' => $key,
  80. 'label' => lang($pv['name']),
  81. 'value' => $pv['type'],
  82. 'config' => $config ?? [],
  83. ];
  84. }
  85. $list = array_column($list, null, 'key');
  86. return array_values($list);
  87. }
  88. //校验是否支持此提现方式
  89. public static function checkWithdrawChannel($type, $recharge_channel_group_id = 1) {
  90. $recharge_channel_group_id = $recharge_channel_group_id > 0 ? $recharge_channel_group_id : 1;
  91. $group = RechargeChannelGroup::query()->find($recharge_channel_group_id);
  92. $withdrawTypes = $group ? (array)$group->withdraw_type : [];
  93. if (!in_array($type, $withdrawTypes, true)) {
  94. return false;
  95. }
  96. return self::query()->where('data_type', 2)->where('type', $type)
  97. ->where('status', 1)->orderBy('sort')->first() ?: false;
  98. }
  99. //校验是否支持此充值方式
  100. public static function checkRechargeChannel($type, $recharge_channel_group_id = 1) {
  101. $recharge_channel_group_id = $recharge_channel_group_id > 0 ? $recharge_channel_group_id : 1;
  102. $group = RechargeChannelGroup::query()->find($recharge_channel_group_id);
  103. $rechargeTypes = $group ? (array)$group->recharge_type : [];
  104. if (!in_array($type, $rechargeTypes, true)) {
  105. return false;
  106. }
  107. return self::query()->where('data_type', 1)->where('type', $type)
  108. ->where('status', 1)->orderBy('sort')->first() ?: false;
  109. }
  110. }