payUtil.php 4.5 KB

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