PayMentService.php 8.2 KB

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