| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- <?php
- namespace App\Models;
- class RechargeChannel extends BaseModel
- {
- protected $table = 'recharge_channel';
- protected $fillable = ['key', 'name', 'type', 'rate','min','max' ,'fixed' ,'sort'];
- protected $hidden = [];
- public function getFixedAttribute($value)
- {
- return $value ? explode(',', $value) : null;
- }
- //获取充值通道
- public static function product($from = '')
- {
- $where['status'] = 1;
- if($from){
- $where['from'] = $from;
- }
- $list = self::where($where)->orderBy('sort', 'asc')->get()->toArray();
- return array_column($list, null, 'key');
- }
- public static function getFormatChannel($recharge_channel_group_id = '')
- {
- $where['status'] = 1;
- if ($recharge_channel_group_id) {
- $channel_ids = RechargeChannelGroup::where('id', $recharge_channel_group_id)->value('channel_ids');
- if ($channel_ids) {
- $where['id'] = ['in', $channel_ids];
- }
- }
- $product = self::where($where)->orderBy('sort', 'asc')->select(['name','type','min','max','fixed','rate'])->get()->toArray();
-
- $list = [];
- foreach($product as $key => $pv) {
- if (isset($list[$pv['type']]['config'])) {
- $config = $list[$pv['type']]['config'];
- if (empty($config['range'])) {
- $config['range'][] = $config;
- }
- if ($pv['min'] < $config['min']) {
- $config['min'] = $pv['min'];
- }
- if ($pv['max'] > $config['max']) {
- $config['max'] = $pv['max'];
- }
- if ($pv['rate'] < $config['rate']) {
- $config['max_rate'] = $config['rate'];
- $config['min_rate'] = $pv['rate'];
- }
- if ($pv['rate'] > $config['rate']) {
- $config['max_rate'] = $pv['rate'];
- }
- $config['range'][] = $pv;
- } else {
- $config = $pv;
- }
-
- $list[$pv['type']] = [
- 'key' => $key,
- 'label' => lang($pv['name']),
- 'value' => $pv['type'],
- 'config' => $config ?? [],
- ];
- }
- $list = array_column($list, null, 'key');
-
- return array_values($list);
- }
- }
|