where('status', 1); $statuses = PaymentProviderService::statuses(); foreach (PaymentProviderCatalog::codes() as $code) { if (($statuses[$code] ?? 0) === 1) continue; foreach ([1, 2] as $direction) { $types = PaymentProviderCatalog::channelTypesForProvider($code, $direction); if ($types === []) continue; $query->whereNot(fn ($part) => $part->where('data_type', $direction)->whereIn('type', $types)); } } return $query; } 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); } $statuses = PaymentProviderService::statuses(); $channel = $query->orderBy('sort')->orderBy('id')->get(['type', 'name', 'from', 'data_type', 'status']) ->map(function ($row) use ($statuses) { $data = $row->toArray() + PaymentProviderCatalog::channelDisplay($row->toArray(), $statuses); return $data + ['disabled' => $data['company_status'] === 0, 'disabled_reason' => $data['company_status'] === 0 ? '支付公司已禁用' : '']; })->all(); $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)->available()->orderBy('sort', 'asc')->get()->toArray(); return array_column($list, null, 'key'); } public static function getFormatChannel($data_type, $recharge_channel_group_id = 1) { $recharge_channel_group_id = $recharge_channel_group_id > 0 ? $recharge_channel_group_id : 1; $query = self::where('data_type', $data_type)->available(); $field = 'recharge_type'; //充值类型 if ($data_type == 2) { //提现类型 $field = 'withdraw_type'; } elseif ($data_type == 3) { //提现类型 $field = 'activity_type'; } $group = RechargeChannelGroup::query()->find($recharge_channel_group_id); $types = $group ? (array)$group->{$field} : []; if (!$types) { return []; } $query = $query->whereIn('type', $types); $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['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); } //校验是否支持此提现方式 public static function checkWithdrawChannel($type, $recharge_channel_group_id = 1) { $recharge_channel_group_id = $recharge_channel_group_id > 0 ? $recharge_channel_group_id : 1; $group = RechargeChannelGroup::query()->find($recharge_channel_group_id); $withdrawTypes = $group ? (array)$group->withdraw_type : []; if (!in_array($type, $withdrawTypes, true)) { return false; } return self::query()->where('data_type', 2)->where('type', $type) ->available()->orderBy('sort')->first() ?: false; } //校验是否支持此充值方式 public static function checkRechargeChannel($type, $recharge_channel_group_id = 1) { $recharge_channel_group_id = $recharge_channel_group_id > 0 ? $recharge_channel_group_id : 1; $group = RechargeChannelGroup::query()->find($recharge_channel_group_id); $rechargeTypes = $group ? (array)$group->recharge_type : []; if (!in_array($type, $rechargeTypes, true)) { return false; } return self::query()->where('data_type', 1)->where('type', $type) ->available()->orderBy('sort')->first() ?: false; } }