RechargeChannel.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. namespace App\Models;
  3. class RechargeChannel extends BaseModel
  4. {
  5. protected $table = 'recharge_channel';
  6. protected $fillable = ['id','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($type = [])
  13. {
  14. $query = self::where('status', 1);
  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 $channel;
  21. }
  22. //获取充值通道
  23. public static function product($from = '')
  24. {
  25. $where['status'] = 1;
  26. if($from){
  27. $where['from'] = $from;
  28. }
  29. $list = self::where($where)->orderBy('sort', 'asc')->get()->toArray();
  30. return array_column($list, null, 'key');
  31. }
  32. public static function getFormatChannel($recharge_channel_group_id = '')
  33. {
  34. $query = self::where(['status' => 1]);
  35. if ($recharge_channel_group_id) {
  36. $type = RechargeChannelGroup::where('id', $recharge_channel_group_id)->value('type');
  37. if ($type) {
  38. $query = $query->whereIn('type', $type);
  39. }
  40. }
  41. $product = $query->orderBy('sort', 'asc')->select(['id','name','type','min','max','fixed','rate'])->get()->toArray();
  42. $list = [];
  43. foreach($product as $key => $pv) {
  44. if (isset($list[$pv['type']]['config'])) {
  45. $config = $list[$pv['type']]['config'];
  46. if (empty($config['range'])) {
  47. $config['range'][] = $config;
  48. }
  49. if ($pv['min'] < $config['min']) {
  50. $config['min'] = $pv['min'];
  51. }
  52. if ($pv['max'] > $config['max']) {
  53. $config['max'] = $pv['max'];
  54. }
  55. if ($pv['rate'] < $config['rate']) {
  56. $config['max_rate'] = $config['rate'];
  57. $config['min_rate'] = $pv['rate'];
  58. }
  59. if ($pv['rate'] > $config['rate']) {
  60. $config['max_rate'] = $pv['rate'];
  61. }
  62. $config['range'][] = $pv;
  63. } else {
  64. $config = $pv;
  65. }
  66. $list[$pv['type']] = [
  67. 'key' => $key,
  68. 'label' => lang($pv['name']),
  69. 'value' => $pv['type'],
  70. 'config' => $config ?? [],
  71. ];
  72. }
  73. $list = array_column($list, null, 'key');
  74. return array_values($list);
  75. }
  76. }