payUtil.php 3.8 KB

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