RechargeChannel.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. //获取充值通道
  13. public static function product($from = '')
  14. {
  15. $where['status'] = 1;
  16. if($from){
  17. $where['from'] = $from;
  18. }
  19. $list = self::where($where)->orderBy('sort', 'asc')->get()->toArray();
  20. return array_column($list, null, 'key');
  21. }
  22. public static function getFormatChannel($recharge_channel_group_id = '')
  23. {
  24. $query = self::where(['status' => 1]);
  25. if ($recharge_channel_group_id) {
  26. $type = RechargeChannelGroup::where('id', $recharge_channel_group_id)->value('type');
  27. if ($type) {
  28. $query = $query->whereIn('type', $type);
  29. }
  30. }
  31. $product = $query->orderBy('sort', 'asc')->select(['id','name','type','min','max','fixed','rate'])->get()->toArray();
  32. $list = [];
  33. foreach($product as $key => $pv) {
  34. if (isset($list[$pv['type']]['config'])) {
  35. $config = $list[$pv['type']]['config'];
  36. if (empty($config['range'])) {
  37. $config['range'][] = $config;
  38. }
  39. if ($pv['min'] < $config['min']) {
  40. $config['min'] = $pv['min'];
  41. }
  42. if ($pv['max'] > $config['max']) {
  43. $config['max'] = $pv['max'];
  44. }
  45. if ($pv['rate'] < $config['rate']) {
  46. $config['max_rate'] = $config['rate'];
  47. $config['min_rate'] = $pv['rate'];
  48. }
  49. if ($pv['rate'] > $config['rate']) {
  50. $config['max_rate'] = $pv['rate'];
  51. }
  52. $config['range'][] = $pv;
  53. } else {
  54. $config = $pv;
  55. }
  56. $list[$pv['type']] = [
  57. 'key' => $key,
  58. 'label' => lang($pv['name']),
  59. 'value' => $pv['type'],
  60. 'config' => $config ?? [],
  61. ];
  62. }
  63. $list = array_column($list, null, 'key');
  64. return array_values($list);
  65. }
  66. }