| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216 |
- <?php
- namespace App\Services;
- use App\Http\Controllers\Api\AegPayController;
- use App\Http\Controllers\Api\AppleStorePayController;
- use App\Http\Controllers\Api\CryptoController;
- use App\Http\Controllers\Api\GooglePayController;
- use App\Http\Controllers\Api\GoopagoController;
- use App\Http\Controllers\Api\SitoBankController;
- use App\Http\Controllers\Api\WiwiPayController;
- use App\Http\Controllers\Api\WDPayController;
- use App\Http\Controllers\Api\AiPayController;
- use Illuminate\Support\Facades\DB;
- use Illuminate\Support\Facades\Log;
- use Illuminate\Support\Facades\Redis;
- class PayMentService
- {
- public static function pay_order($transport = null)
- {
- switch ($transport) {
- case 'WiwiPay':
- return new WiwiPayController();
- case 'WDPay':
- return new WDPayController();
- case 'AiPay':
- return new AiPayController();
- case 'apple':
- return new AppleStorePayController();
- case 'google':
- return new GooglePayController();
- default:
- throw new \Exception('unknown pay channel:'.$transport);
- }
- }
- /**
- * 根据支付方式随机获取充值渠道
- * @param $method
- * @param $channel
- * @return bool|mixed
- */
- /*public static function getServiceByPayMethod3($method, $channel)
- {
- // $switch = Redis::get("recharge_config_switch_{$channel}");
- // if ($channel && $switch) {
- // $services = DB::connection('write')
- // ->table('QPPlatformDB.dbo.ChannelOpenRecharge')
- // ->join(
- // 'agent.dbo.admin_configs',
- // 'admin_configs.id',
- // '=',
- // 'ChannelOpenRecharge.ConfigID'
- // )
- // ->where('admin_configs.new_pay_type', $method)
- // ->where('admin_configs.type', 'pay')
- // ->where('admin_configs.status', 1)
- // ->where('ChannelOpenRecharge.Status', 1)
- // ->where('ChannelOpenRecharge.Channel', $channel)
- // ->where('ChannelOpenRecharge.Sort', '>', 0)
- // ->selectRaw('admin_configs.config_key, ChannelOpenRecharge.Sort as sort')
- // ->get();
- // }
- $services = DB::table('agent.dbo.admin_configs')->where([
- 'new_pay_type' => $method,
- 'type' => 'pay',
- 'status' => 1,
- ])->get();
- if (!$services->count()) {
- Log::error('支付渠道配置异常', [
- 'method' => $method,
- ]);
- return false;
- }
- $matrix = [];
- foreach ($services as $v) {
- for ($i = 0; $i < $v->sort; $i++) {
- $matrix[] = $v->config_key;
- }
- }
- $res = $matrix[mt_rand(0, count($matrix)-1)];
- return $res;
- }*/
- /**
- * 根据支付方式随机获取充值渠道
- * @param $method
- * @param $channel
- * @return bool|mixed
- */
- public static function getServiceByPayMethod($method, $payAmt,$pay_method)
- {
- // $except_configKeys=[$except_channelName];
- // $switch = Redis::get("recharge_config_switch_{$channel}");
- // if ($channel && $switch) {
- // $services = DB::connection('write')
- // ->table('QPPlatformDB.dbo.ChannelOpenRecharge')
- // ->join(
- // 'agent.dbo.admin_configs',
- // 'admin_configs.id',
- // '=',
- // 'ChannelOpenRecharge.ConfigID'
- // )
- // ->where('admin_configs.new_pay_type', $method)
- // ->whereNotIn('admin_configs.config_key',$except_configKeys)
- // ->where('admin_configs.type', 'pay')
- // ->where('admin_configs.status', 1)
- // ->where('ChannelOpenRecharge.Status', 1)
- // ->where('ChannelOpenRecharge.Channel', $channel)
- // ->where('ChannelOpenRecharge.Sort', '>', 0)
- // ->selectRaw('admin_configs.config_key, ChannelOpenRecharge.Sort as sort')
- // ->get();
- // }
- $services = DB::table('agent.dbo.admin_configs')->where([
- 'new_pay_type' => $method,
- 'type' => 'pay',
- 'status' => 1,
- ])->whereRaw('pay_types&'.$pay_method.'='.$pay_method)
- ->where('min_amount', '<=', $payAmt)
- ->where('max_amount', '>=', $payAmt)
- ->get();
- if (!$services->count()) {
- Log::error('支付渠道配置异常', [
- 'method' => $method,
- ]);
- return false;
- }
- $matrix = [];
- foreach ($services as $v) {
- for ($i = 0; $i < $v->sort; $i++) {
- if(Redis::exists("PayErro_".$v->config_key)) continue;
- $matrix[] = $v->config_key;
- }
- }
- if(count($matrix)==0) {
- foreach ($services as $v) {
- for ($i = 0; $i < $v->sort; $i++) {
- $matrix[] = $v->config_key;
- }
- }
- }
- $res = $matrix[mt_rand(0, count($matrix)-1)];
- return $res;
- }
- /**
- * 根据支付方式随机获取充值渠道
- * @param $method
- * @param $channel
- * @return bool|mixed
- */
- public static function getServiceByPayCountry($method, $channel,$country,$except_channelName="")
- {
- $except_configKeys=[$except_channelName];
- $switch = Redis::get("recharge_config_switch_{$channel}");
- if ($channel && $switch) {
- $services = DB::connection('write')
- ->table('QPPlatformDB.dbo.ChannelOpenRecharge')
- ->join(
- 'agent.dbo.admin_configs',
- 'admin_configs.id',
- '=',
- 'ChannelOpenRecharge.ConfigID'
- )
- ->where('admin_configs.new_pay_type', $method)
- ->whereNotIn('admin_configs.config_key',$except_configKeys)
- ->where('admin_configs.country', $country)
- ->where('admin_configs.type', 'pay')
- ->where('admin_configs.status', 1)
- ->where('ChannelOpenRecharge.Status', 1)
- ->where('ChannelOpenRecharge.Channel', $channel)
- ->where('ChannelOpenRecharge.Sort', '>', 0)
- ->selectRaw('admin_configs.config_key, ChannelOpenRecharge.Sort as sort')
- ->get();
- }
- if (!isset($services) || !$services->count()) {
- $services = DB::table('agent.dbo.admin_configs')->where([
- 'new_pay_type' => $method,
- 'type' => 'pay',
- 'status' => 1,
- 'country' => $country,
- ])->get();
- if (!$services->count()) {
- Log::error('支付渠道配置异常', [
- 'method' => $method,
- ]);
- return false;
- }
- }
- $matrix = [];
- foreach ($services as $v) {
- for ($i = 0; $i < $v->sort; $i++) {
- if(Redis::exists("PayErro_".$v->config_key)) continue;
- $matrix[] = $v->config_key;
- }
- }
- if(count($matrix)==0) {
- foreach ($services as $v) {
- for ($i = 0; $i < $v->sort; $i++) {
- $matrix[] = $v->config_key;
- }
- }
- }
- $res = $matrix[mt_rand(0, count($matrix)-1)];
- return $res;
- }
- }
|