PayMentService.php 8.3 KB

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