2
0

PayMentService.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. <?php
  2. namespace App\Services;
  3. use App\Http\Controllers\Api\AegPayController;
  4. use App\Http\Controllers\Api\AppleStorePayController;
  5. use App\Http\Controllers\Api\CryptoController;
  6. use App\Http\Controllers\Api\GooglePayController;
  7. use App\Http\Controllers\Api\GoopagoController;
  8. use App\Http\Controllers\Api\SitoBankController;
  9. use App\Http\Controllers\Api\WiwiPayController;
  10. use App\Http\Controllers\Api\WDPayController;
  11. use App\Http\Controllers\Api\CoinPayController;
  12. use App\Http\Controllers\Api\AiPayController;
  13. use App\Http\Controllers\Api\PagYeepPayController;
  14. use App\Http\Controllers\Api\AiNewPayController;
  15. use Illuminate\Support\Facades\DB;
  16. use Illuminate\Support\Facades\Log;
  17. use Illuminate\Support\Facades\Redis;
  18. class PayMentService
  19. {
  20. public static function pay_order($transport = null)
  21. {
  22. switch ($transport) {
  23. case 'WiwiPay':
  24. return new WiwiPayController();
  25. case 'WDPay':
  26. return new WDPayController();
  27. case 'CoinPay':
  28. return new CoinPayController();
  29. case 'AiPay':
  30. return new AiPayController();
  31. case 'PagYeepPay':
  32. return new PagYeepPayController();
  33. case 'AiNewPay':
  34. return new AiNewPayController();
  35. case 'apple':
  36. return new AppleStorePayController();
  37. case 'google':
  38. return new GooglePayController();
  39. default:
  40. throw new \Exception('unknown pay channel:'.$transport);
  41. }
  42. }
  43. /**
  44. * 根据支付方式随机获取充值渠道
  45. * @param $method
  46. * @param $channel
  47. * @return bool|mixed
  48. */
  49. /*public static function getServiceByPayMethod3($method, $channel)
  50. {
  51. // $switch = Redis::get("recharge_config_switch_{$channel}");
  52. // if ($channel && $switch) {
  53. // $services = DB::connection('write')
  54. // ->table('QPPlatformDB.dbo.ChannelOpenRecharge')
  55. // ->join(
  56. // 'agent.dbo.admin_configs',
  57. // 'admin_configs.id',
  58. // '=',
  59. // 'ChannelOpenRecharge.ConfigID'
  60. // )
  61. // ->where('admin_configs.new_pay_type', $method)
  62. // ->where('admin_configs.type', 'pay')
  63. // ->where('admin_configs.status', 1)
  64. // ->where('ChannelOpenRecharge.Status', 1)
  65. // ->where('ChannelOpenRecharge.Channel', $channel)
  66. // ->where('ChannelOpenRecharge.Sort', '>', 0)
  67. // ->selectRaw('admin_configs.config_key, ChannelOpenRecharge.Sort as sort')
  68. // ->get();
  69. // }
  70. $services = DB::table('agent.dbo.admin_configs')->where([
  71. 'new_pay_type' => $method,
  72. 'type' => 'pay',
  73. 'status' => 1,
  74. ])->get();
  75. if (!$services->count()) {
  76. Log::error('支付渠道配置异常', [
  77. 'method' => $method,
  78. ]);
  79. return false;
  80. }
  81. $matrix = [];
  82. foreach ($services as $v) {
  83. for ($i = 0; $i < $v->sort; $i++) {
  84. $matrix[] = $v->config_key;
  85. }
  86. }
  87. $res = $matrix[mt_rand(0, count($matrix)-1)];
  88. return $res;
  89. }*/
  90. /**
  91. * 根据支付方式随机获取充值渠道
  92. * @param $method
  93. * @param $channel
  94. * @return bool|mixed
  95. */
  96. public static function getServiceByPayMethod($method, $payAmt,$pay_method)
  97. {
  98. // $except_configKeys=[$except_channelName];
  99. // $switch = Redis::get("recharge_config_switch_{$channel}");
  100. // if ($channel && $switch) {
  101. // $services = DB::connection('write')
  102. // ->table('QPPlatformDB.dbo.ChannelOpenRecharge')
  103. // ->join(
  104. // 'agent.dbo.admin_configs',
  105. // 'admin_configs.id',
  106. // '=',
  107. // 'ChannelOpenRecharge.ConfigID'
  108. // )
  109. // ->where('admin_configs.new_pay_type', $method)
  110. // ->whereNotIn('admin_configs.config_key',$except_configKeys)
  111. // ->where('admin_configs.type', 'pay')
  112. // ->where('admin_configs.status', 1)
  113. // ->where('ChannelOpenRecharge.Status', 1)
  114. // ->where('ChannelOpenRecharge.Channel', $channel)
  115. // ->where('ChannelOpenRecharge.Sort', '>', 0)
  116. // ->selectRaw('admin_configs.config_key, ChannelOpenRecharge.Sort as sort')
  117. // ->get();
  118. // }
  119. $services = DB::table('agent.dbo.admin_configs')->where([
  120. 'new_pay_type' => $method,
  121. 'type' => 'pay',
  122. 'status' => 1,
  123. ])->whereRaw('pay_types&'.$pay_method.'='.$pay_method)
  124. ->where('min_amount', '<=', $payAmt)
  125. ->where('max_amount', '>=', $payAmt)
  126. ->get();
  127. if (!$services->count()) {
  128. Log::error('支付渠道配置异常', [
  129. 'method' => $method,
  130. ]);
  131. return false;
  132. }
  133. $matrix = [];
  134. foreach ($services as $v) {
  135. for ($i = 0; $i < $v->sort; $i++) {
  136. if(Redis::exists("PayErro_".$v->config_key)) continue;
  137. $matrix[] = $v->config_key;
  138. }
  139. }
  140. if(count($matrix)==0) {
  141. foreach ($services as $v) {
  142. for ($i = 0; $i < $v->sort; $i++) {
  143. $matrix[] = $v->config_key;
  144. }
  145. }
  146. }
  147. $res = $matrix[mt_rand(0, count($matrix)-1)];
  148. return $res;
  149. }
  150. /**
  151. * 根据支付方式随机获取充值渠道
  152. * @param $method
  153. * @param $channel
  154. * @return bool|mixed
  155. */
  156. public static function getServiceByPayCountry($method, $channel,$country,$except_channelName="")
  157. {
  158. $except_configKeys=[$except_channelName];
  159. $switch = Redis::get("recharge_config_switch_{$channel}");
  160. if ($channel && $switch) {
  161. $services = DB::connection('write')
  162. ->table('QPPlatformDB.dbo.ChannelOpenRecharge')
  163. ->join(
  164. 'agent.dbo.admin_configs',
  165. 'admin_configs.id',
  166. '=',
  167. 'ChannelOpenRecharge.ConfigID'
  168. )
  169. ->where('admin_configs.new_pay_type', $method)
  170. ->whereNotIn('admin_configs.config_key',$except_configKeys)
  171. ->where('admin_configs.country', $country)
  172. ->where('admin_configs.type', 'pay')
  173. ->where('admin_configs.status', 1)
  174. ->where('ChannelOpenRecharge.Status', 1)
  175. ->where('ChannelOpenRecharge.Channel', $channel)
  176. ->where('ChannelOpenRecharge.Sort', '>', 0)
  177. ->selectRaw('admin_configs.config_key, ChannelOpenRecharge.Sort as sort')
  178. ->get();
  179. }
  180. if (!isset($services) || !$services->count()) {
  181. $services = DB::table('agent.dbo.admin_configs')->where([
  182. 'new_pay_type' => $method,
  183. 'type' => 'pay',
  184. 'status' => 1,
  185. 'country' => $country,
  186. ])->get();
  187. if (!$services->count()) {
  188. Log::error('支付渠道配置异常', [
  189. 'method' => $method,
  190. ]);
  191. return false;
  192. }
  193. }
  194. $matrix = [];
  195. foreach ($services as $v) {
  196. for ($i = 0; $i < $v->sort; $i++) {
  197. if(Redis::exists("PayErro_".$v->config_key)) continue;
  198. $matrix[] = $v->config_key;
  199. }
  200. }
  201. if(count($matrix)==0) {
  202. foreach ($services as $v) {
  203. for ($i = 0; $i < $v->sort; $i++) {
  204. $matrix[] = $v->config_key;
  205. }
  206. }
  207. }
  208. $res = $matrix[mt_rand(0, count($matrix)-1)];
  209. return $res;
  210. }
  211. }