| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- <?php
- namespace App\Models;
- class RechargeChannel extends BaseModel
- {
- protected $table = 'recharge_channel';
- protected $fillable = ['key', 'name', 'type', 'rate','min_amount','max_amount' ,'fixed_amounts' ,'sort'];
- protected $hidden = [];
- //获取充值通道
- 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) {
- $channel_ids = explode(',', $channel_ids);
- $where['id'] = ['in', $channel_ids];
- }
- }
- $product = self::where($where)->orderBy('sort', 'asc')->get()->toArray();
-
- $list = [];
- $config = [];
- foreach($product as $pv) {
- if ($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[] = [
- 'label' => lang($pv['type']),
- 'value' => $pv['type'],
- 'config' => $config ?? [],
- ];
-
- return $list;
- }
- }
|