RechargeChannel.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. namespace App\Models;
  3. class RechargeChannel extends BaseModel
  4. {
  5. protected $table = 'recharge_channel';
  6. protected $fillable = ['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. $where['status'] = 1;
  25. if ($recharge_channel_group_id) {
  26. $channel_ids = RechargeChannelGroup::where('id', $recharge_channel_group_id)->value('channel_ids');
  27. if ($channel_ids) {
  28. $channel_ids = explode(',', $channel_ids);
  29. $where['id'] = ['in', $channel_ids];
  30. }
  31. }
  32. $product = self::where($where)->orderBy('sort', 'asc')->select(['name','type','min','max','fixed','rate'])->get()->toArray();
  33. $list = [];
  34. foreach($product as $key => $pv) {
  35. if (isset($list[$pv['type']]['config'])) {
  36. $config = $list[$pv['type']]['config'];
  37. if (empty($config['range'])) {
  38. $config['range'][] = $config;
  39. }
  40. if ($pv['min'] < $config['min']) {
  41. $config['min'] = $pv['min'];
  42. }
  43. if ($pv['max'] > $config['max']) {
  44. $config['max'] = $pv['max'];
  45. }
  46. if ($pv['rate'] < $config['rate']) {
  47. $config['max_rate'] = $config['rate'];
  48. $config['min_rate'] = $pv['rate'];
  49. }
  50. if ($pv['rate'] > $config['rate']) {
  51. $config['max_rate'] = $pv['rate'];
  52. }
  53. $config['range'][] = $pv;
  54. } else {
  55. $config = $pv;
  56. }
  57. $list[$pv['type']] = [
  58. 'key' => $key,
  59. 'label' => lang($pv['name']),
  60. 'value' => $pv['type'],
  61. 'config' => $config ?? [],
  62. ];
  63. }
  64. $list = array_column($list, null, 'key');
  65. return array_values($list);
  66. }
  67. }