| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- <?php
- namespace App\Models;
- class RechargeChannel extends BaseModel
- {
- protected $table = 'recharge_channel';
- protected $fillable = ['id','data_type','key', 'name', 'type', 'rate','min','max' ,'fixed' ,'sort'];
- protected $hidden = [];
- public function getFixedAttribute($value)
- {
- return $value ? explode(',', $value) : null;
- }
- public static function getChannel($data_type, $type = [])
- {
- $query = self::where('status', 1)->where('data_type', $data_type);
- if ($type) {
- $query = $query->whereIn('type', $type);
- }
- $channel = $query->select(['type','name'])->get()->toArray();
- $channel = array_column($channel, null, 'type');
- return array_values($channel);
- }
- //获取充值通道
- public static function product($from = '')
- {
- $where['status'] = 1;
- $where['data_type'] = 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($data_type, $recharge_channel_group_id = 1)
- {
- $query = self::where(['status' => 1, 'data_type' => $data_type]);
-
- $field = 'recharge_type'; //充值类型
- if ($data_type == 2) {
- //提现类型
- $field = 'withdraw_type';
- } elseif ($data_type == 3) {
- //提现类型
- $field = 'activity_type';
- }
- $type = RechargeChannelGroup::where('id', $recharge_channel_group_id)->value($field);
- if ($type) {
- $query = $query->whereIn($field, $type);
- }
-
- $product = $query->orderBy('sort', 'asc')->select(['id', 'data_type','name','type', 'min','max','fixed','rate'])->get()->toArray();
-
- $list = [];
- foreach($product as $key => $pv) {
- if (isset($list[$pv[$field]]['config'])) {
- $config = $list[$pv[$field]]['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[$field]] = [
- 'key' => $key,
- 'label' => lang($pv['name']),
- 'value' => $pv[$field],
- 'config' => $config ?? [],
- ];
- }
- $list = array_column($list, null, 'key');
-
- return array_values($list);
- }
- }
|