WiwiPayCashierLogic.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. namespace App\Http\logic\api;
  3. use App\Http\helper\NumConfig;
  4. use App\Inter\CashierInterFace;
  5. use App\Models\PrivateMail;
  6. use App\Services\WiwiPay;
  7. use App\Services\PayConfig;
  8. use App\Util;
  9. use Illuminate\Support\Facades\DB;
  10. use Illuminate\Support\Facades\Log;
  11. class WiwiPayCashierLogic implements CashierInterFace
  12. {
  13. const AGENT = 99; // 需要根据实际情况修改
  14. protected $agent = 99;
  15. public function payment($RecordID, $amount, $accountName, $phone, $email, $OrderId, $PixNum, $PixType, $IFSCNumber, $BranchBank, $BankNO)
  16. {
  17. // 查询订单号
  18. $query = DB::connection('write')->table('QPAccountsDB.dbo.OrderWithDraw')->where('RecordID', $RecordID)->first();
  19. if (!$query) return 'fail'; // 订单不存在
  20. $service = new WiwiPay();
  21. $config = $service->config;
  22. // 构建提现请求参数
  23. $params = [
  24. "mchNo" => $service->mchNo,
  25. "mchOrderNo" => $OrderId,
  26. "amount" => intval($amount),
  27. "currency" => $config['currency'] ?? "usd",
  28. "accountName" => $accountName,
  29. "accountNo" => $phone, // 根据实际情况调整
  30. "notifyUrl" => $config['cashNotify'] ?? $config['notify'] ?? '',
  31. "timestamp" => round(microtime(true) * 1000),
  32. "signType" => $config['signType'] ?? "MD5"
  33. ];
  34. // 签名
  35. $signedParams = $service->sign($params);
  36. $url = $config['cash_url'] ?? $service->apiUrl;
  37. Log::info('WiwiPay 提现参数:', $signedParams);
  38. try {
  39. $result = $service->curlPost($url, $signedParams);
  40. } catch (\Exception $exception) {
  41. Log::info('WiwiPay 提现请求异常:', [$exception->getMessage()]);
  42. return 'fail';
  43. }
  44. Log::info('WiwiPay 提现结果:', [$result ?? "no result"]);
  45. try {
  46. $data = \GuzzleHttp\json_decode($result, true);
  47. } catch (\Exception $e) {
  48. Util::WriteLog("WiwiPay_error", [$result, $e->getMessage(), $e->getTraceAsString()]);
  49. return 'fail';
  50. }
  51. if (isset($data['status'])) {
  52. return $data;
  53. } else {
  54. if ($query->State == 5) {
  55. // 同步失败,发送邮件给玩家,退还金币
  56. $msg = 'Liquidation failure';
  57. $WithDraw = $query->WithDraw + $query->ServiceFee;
  58. $bonus = '30000,' . $WithDraw;
  59. PrivateMail::failMail($query->UserID, $OrderId, $WithDraw, $msg, $bonus);
  60. $data = [
  61. 'updated_at' => date('Y-m-d H:i:s'),
  62. 'State' => 5,
  63. ];
  64. DB::connection('write')->table('QPAccountsDB.dbo.OrderWithDraw')->where('RecordID', $RecordID)->update($data);
  65. }
  66. return 'fail';
  67. }
  68. }
  69. public function notify($post)
  70. {
  71. $OrderId = $post['mchOrderNo'] ?? '';
  72. Util::WriteLog('WiwiPay', 'WiwiPay 提现回调:' . json_encode($post));
  73. // 查询订单号
  74. $query = DB::connection('write')->table('QPAccountsDB.dbo.OrderWithDraw')->where('OrderID', $OrderId)->first();
  75. if (!$query) {
  76. return 'fail'; // 订单不存在
  77. }
  78. $orderStatus = $post['status'] ?? $post['orderStatus'] ?? '';
  79. if ($orderStatus == 'SUCCESS' || $orderStatus == 'PAID' || $orderStatus == 2) {
  80. // 订单成功
  81. $data = [
  82. 'updated_at' => date('Y-m-d H:i:s'),
  83. 'State' => 2,
  84. ];
  85. DB::connection('write')->table('QPAccountsDB.dbo.OrderWithDraw')->where('OrderID', $OrderId)->update($data);
  86. Util::WriteLog('WiwiPay', 'WiwiPay 提现成功:' . $OrderId);
  87. return 'SUCCESS';
  88. } else if ($orderStatus == 'REJECTED' || $orderStatus == 'FAILED' || $orderStatus == 3) {
  89. // 订单失败,退还金币
  90. $msg = 'Liquidation failure';
  91. $WithDraw = $query->WithDraw + $query->ServiceFee;
  92. $bonus = '30000,' . $WithDraw;
  93. PrivateMail::failMail($query->UserID, $OrderId, $WithDraw, $msg, $bonus);
  94. $data = [
  95. 'updated_at' => date('Y-m-d H:i:s'),
  96. 'State' => 5,
  97. ];
  98. DB::connection('write')->table('QPAccountsDB.dbo.OrderWithDraw')->where('OrderID', $OrderId)->update($data);
  99. Util::WriteLog('WiwiPay', 'WiwiPay 提现失败:' . $OrderId);
  100. return 'SUCCESS';
  101. } else {
  102. // 处理中
  103. Util::WriteLog('WiwiPay', 'WiwiPay 提现处理中:' . $OrderId . ' status:' . $orderStatus);
  104. return 'SUCCESS';
  105. }
  106. }
  107. }