RechargeChannel.php 4.5 KB

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