| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- <?php
- namespace App\Models;
- class RechargeChannel extends BaseModel
- {
- protected $table = 'recharge_channel';
- protected $fillable = ['id','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 = '')
- {
- $query = self::where(['status' => 1]);
-
- if ($recharge_channel_group_id) {
- $type = RechargeChannelGroup::where('id', $recharge_channel_group_id)->value('type');
- if ($type) {
- $query = $query->whereIn('type', $type);
- }
- }
- $product = $query->orderBy('sort', 'asc')->select(['id','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);
- }
- }
|