payUtil.php 6.1 KB

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