RechargeChannel.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. namespace App\Models;
  3. class RechargeChannel extends BaseModel
  4. {
  5. protected $table = 'recharge_channel';
  6. protected $fillable = ['id','data_type','key', 'name', 'type', 'rate','min','max' ,'fixed' ,'sort'];
  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. $query = self::where(['status' => 1, 'data_type' => $data_type]);
  36. $field = 'recharge_type'; //充值类型
  37. if ($data_type == 2) {
  38. //提现类型
  39. $field = 'withdraw_type';
  40. } elseif ($data_type == 3) {
  41. //提现类型
  42. $field = 'activity_type';
  43. }
  44. $type = RechargeChannelGroup::where('id', $recharge_channel_group_id)->value($field);
  45. if (!$type) {
  46. return [];
  47. }
  48. $query = $query->whereIn('type', $type);
  49. $product = $query->orderBy('sort', 'asc')->select(['id', 'data_type','name','type', 'min','max','fixed','rate'])->get()->toArray();
  50. $list = [];
  51. foreach($product as $key => $pv) {
  52. if (isset($list[$pv['type']]['config'])) {
  53. $config = $list[$pv['type']]['config'];
  54. if (empty($config['range'])) {
  55. $config['range'][] = $config;
  56. }
  57. if ($pv['min'] < $config['min']) {
  58. $config['min'] = $pv['min'];
  59. }
  60. if ($pv['max'] > $config['max']) {
  61. $config['max'] = $pv['max'];
  62. }
  63. if ($pv['rate'] < $config['rate']) {
  64. $config['max_rate'] = $config['rate'];
  65. $config['min_rate'] = $pv['rate'];
  66. }
  67. if ($pv['rate'] > $config['rate']) {
  68. $config['max_rate'] = $pv['rate'];
  69. }
  70. $config['range'][] = $pv;
  71. } else {
  72. $config = $pv;
  73. }
  74. $list[$pv['type']] = [
  75. 'key' => $key,
  76. 'label' => lang($pv['name']),
  77. 'value' => $pv['type'],
  78. 'config' => $config ?? [],
  79. ];
  80. }
  81. $list = array_column($list, null, 'key');
  82. return array_values($list);
  83. }
  84. //校验是否支持此提现方式
  85. public static function checkWithdrawChannel($type, $recharge_channel_group_id = 1) {
  86. $withdraw_type = RechargeChannelGroup::where('id', $recharge_channel_group_id)->value('withdraw_type');
  87. if (in_array($type, $withdraw_type)) {
  88. return true;
  89. } else {
  90. return false;
  91. }
  92. }
  93. //校验是否支持此充值方式
  94. public static function checkRechargeChannel($type, $recharge_channel_group_id = 1) {
  95. $recharge_type = RechargeChannelGroup::where('id', $recharge_channel_group_id)->value('recharge_type');
  96. if (in_array($type, $recharge_type)) {
  97. return true;
  98. } else {
  99. return false;
  100. }
  101. }
  102. }