RechargeChannel.php 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. $query = $query->whereIn($field, $type);
  47. }
  48. $product = $query->orderBy('sort', 'asc')->select(['id', 'data_type','name','type', 'min','max','fixed','rate'])->get()->toArray();
  49. $list = [];
  50. foreach($product as $key => $pv) {
  51. if (isset($list[$pv[$field]]['config'])) {
  52. $config = $list[$pv[$field]]['config'];
  53. if (empty($config['range'])) {
  54. $config['range'][] = $config;
  55. }
  56. if ($pv['min'] < $config['min']) {
  57. $config['min'] = $pv['min'];
  58. }
  59. if ($pv['max'] > $config['max']) {
  60. $config['max'] = $pv['max'];
  61. }
  62. if ($pv['rate'] < $config['rate']) {
  63. $config['max_rate'] = $config['rate'];
  64. $config['min_rate'] = $pv['rate'];
  65. }
  66. if ($pv['rate'] > $config['rate']) {
  67. $config['max_rate'] = $pv['rate'];
  68. }
  69. $config['range'][] = $pv;
  70. } else {
  71. $config = $pv;
  72. }
  73. $list[$pv[$field]] = [
  74. 'key' => $key,
  75. 'label' => lang($pv['name']),
  76. 'value' => $pv[$field],
  77. 'config' => $config ?? [],
  78. ];
  79. }
  80. $list = array_column($list, null, 'key');
  81. return array_values($list);
  82. }
  83. }