payUtil.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. namespace common\components;
  3. use biz\hb\classes\HbClass;
  4. use biz\recharge\classes\RechargeClass;
  5. use biz\renew\classes\RenewClass;
  6. use biz\shop\classes\ShopExtClass;
  7. use biz\wx\classes\WxMessageClass;
  8. use bizHd\order\classes\OrderClass;
  9. use bizHd\purchase\classes\PurchaseClass;
  10. use bizHd\purchase\classes\PurchaseClearClass;
  11. use bizHd\purchase\services\PurchaseService;
  12. use bizHd\px\services\PxApplyService;
  13. use Yii;
  14. use linslin\yii2\curl;
  15. class payUtil
  16. {
  17. public static function thirdPay($payWay, $capitalType, $orderSn, $totalFee, $attach, $transactionId = '')
  18. {
  19. //4秒内不允许第三方重复通知
  20. $cacheKey = 'third_pay_' . $orderSn;
  21. $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  22. if (!empty($has)) {
  23. Yii::info("支付回调短时间内出现重复通知,流水类型:{$capitalType} orderSn:{$orderSn}");
  24. //noticeUtil::push("支付回调短时间内出现重复通知:流水类型:{$capitalType} orderSn:{$orderSn}", '15280215347');
  25. return false;
  26. }
  27. Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 4, 'has']);
  28. $connection = Yii::$app->db;
  29. $transaction = $connection->beginTransaction();
  30. try {
  31. //流水类型列表
  32. switch ($capitalType) {
  33. case dict::getDict('capitalType', 'xhRecharge', 'id'):
  34. //商家充值
  35. $currentRecharge = RechargeClass::thirdPay($payWay, $orderSn, $totalFee, $attach);
  36. $transaction->commit();
  37. //有发红包的通知供货商
  38. WxMessageClass::customRechargeInformGhs($currentRecharge);
  39. $customName = $currentRecharge->customName ?? '';
  40. $rechargeAmount = $currentRecharge->amount ?? 0;
  41. $rechargeAmount = floatval($rechargeAmount);
  42. noticeUtil::push("客户 {$customName} 充值{$rechargeAmount}元", '15280215347');
  43. break;
  44. case dict::getDict('capitalType', 'xhPurchase', 'id'):
  45. //零售采购
  46. PurchaseService::thirdPay($payWay, $orderSn, $totalFee, $attach, $transactionId);
  47. $transaction->commit();
  48. $cg = PurchaseClass::getByCondition(['orderSn' => $orderSn], true);
  49. if (isset($cg->onlinePay) && $cg->onlinePay == dict::getDict('onlinePay', 'yes')) {
  50. $saleId = $cg->saleId ?? 0;
  51. $order = \bizGhs\order\classes\OrderClass::getById($saleId, true);
  52. if (isset($order->needPrint) && $order->needPrint == dict::getDict('needPrint', 'noNeed')) {
  53. $shopId = $order->shopId ?? 0;
  54. $shopExt = ShopExtClass::getByCondition(['shopId' => $shopId], true);
  55. if (isset($shopExt->lbSn) && !empty($shopExt->lbSn)) {
  56. $actPrice = floatval($order->actPrice) ?? 0;
  57. $payWay = $order->payWay ?? dict::getDict('payWay', 'wxPay');
  58. $sound = $payWay == dict::getDict('payWay', 'wxPay') ? "微信收款{$actPrice}元" : "支付宝收款{$actPrice}元";
  59. $url = "https://speaker.17laimai.cn/notify.php?id={$shopExt->lbSn}&token=HK1626595800&version=3&message=" . $sound;
  60. $curl = new curl\Curl();
  61. $curl->get($url);
  62. }
  63. }
  64. }
  65. break;
  66. case dict::getDict('capitalType', 'hdPurchaseClear', 'id'):
  67. //零售结帐
  68. PurchaseClearClass::thirdPay($payWay, $orderSn, $totalFee, $attach);
  69. $transaction->commit();
  70. break;
  71. case dict::getDict('capitalType', 'xhOrder', 'id'):
  72. //花粉下单
  73. OrderClass::thirdPay($payWay, $orderSn, $totalFee, $attach);
  74. $transaction->commit();
  75. //收款声音播放 shish 202010726
  76. $order = OrderClass::getByCondition(['orderSn' => $orderSn], true);
  77. if (isset($order->fromType) && $order->fromType == dict::getDict("fromType", "shop")) {
  78. $shopId = $order->shopId ?? 0;
  79. $shopExt = ShopExtClass::getByCondition(['shopId' => $shopId], true);
  80. if (isset($shopExt->lbSn) && !empty($shopExt->lbSn)) {
  81. $actPrice = floatval($order->actPrice) ?? 0;
  82. $payWay = $order->payWay ?? dict::getDict('payWay', 'wxPay');
  83. $sound = $payWay == dict::getDict('payWay', 'wxPay') ? "微信收款{$actPrice}元" : "支付宝收款{$actPrice}元";
  84. $url = "https://speaker.17laimai.cn/notify.php?id={$shopExt->lbSn}&token=HK1626595800&version=3&message=" . $sound;
  85. $curl = new curl\Curl();
  86. $curl->get($url);
  87. }
  88. }
  89. break;
  90. case dict::getDict('capitalType', 'xhRenew', 'id'):
  91. //商家续期
  92. RenewClass::thirdPay($payWay, $orderSn, $totalFee, $attach);
  93. $transaction->commit();
  94. break;
  95. case dict::getDict('capitalType', 'pxApply', 'id'):
  96. //培训报名
  97. PxApplyService::thirdPay($payWay, $orderSn, $totalFee, $attach);
  98. $transaction->commit();
  99. break;
  100. default:
  101. }
  102. } catch
  103. (Exception $exception) {
  104. $transaction->rollBack();
  105. util::fail("支付回调处理失败 orderSn:{$orderSn} capitalType:{$capitalType}");
  106. }
  107. }
  108. }