RechargeChannel.php 2.1 KB

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