payUtil.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. namespace common\components;
  3. use biz\notice\classes\NoticeClass;
  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. //流水类型列表
  29. switch ($capitalType) {
  30. case dict::getDict('capitalType', 'xhRecharge', 'id'):
  31. //商家充值
  32. $currentRecharge = RechargeClass::thirdPay($payWay, $orderSn, $totalFee, $attach);
  33. //有发红包的通知供货商
  34. WxMessageClass::customRechargeInformGhs($currentRecharge);
  35. $customName = $currentRecharge->customName ?? '';
  36. $rechargeAmount = $currentRecharge->amount ?? 0;
  37. $rechargeAmount = floatval($rechargeAmount);
  38. noticeUtil::push("客户 {$customName} 充值{$rechargeAmount}元", '15280215347');
  39. break;
  40. case dict::getDict('capitalType', 'xhPurchase', 'id'):
  41. //零售采购
  42. PurchaseService::thirdPay($payWay, $orderSn, $totalFee, $attach, $transactionId);
  43. $cg = PurchaseClass::getByCondition(['orderSn' => $orderSn], true);
  44. if (isset($cg->onlinePay) && $cg->onlinePay == dict::getDict('onlinePay', 'yes')) {
  45. $saleId = $cg->saleId ?? 0;
  46. $order = \bizGhs\order\classes\OrderClass::getById($saleId, true);
  47. if (isset($order->needPrint) && $order->needPrint == dict::getDict('needPrint', 'noNeed')) {
  48. $shopId = $order->shopId ?? 0;
  49. $shopExt = ShopExtClass::getByCondition(['shopId' => $shopId], true);
  50. if (isset($shopExt->lbSn) && !empty($shopExt->lbSn)) {
  51. $actPrice = floatval($order->actPrice) ?? 0;
  52. $payWay = $order->payWay ?? dict::getDict('payWay', 'wxPay');
  53. $sound = $payWay == dict::getDict('payWay', 'wxPay') ? "微信收款{$actPrice}元" : "支付宝收款{$actPrice}元";
  54. $url = "https://speaker.17laimai.cn/notify.php?id={$shopExt->lbSn}&token=HK1626595800&version=3&message=" . $sound;
  55. $curl = new curl\Curl();
  56. $curl->get($url);
  57. }
  58. }
  59. //app新订单通知
  60. NoticeClass::ghsNewOrderNotice($order);
  61. }
  62. break;
  63. case dict::getDict('capitalType', 'hdPurchaseClear', 'id'):
  64. //零售结帐
  65. PurchaseClearClass::thirdPay($payWay, $orderSn, $totalFee, $attach);
  66. break;
  67. case dict::getDict('capitalType', 'xhOrder', 'id'):
  68. //花粉下单
  69. OrderClass::thirdPay($payWay, $orderSn, $totalFee, $attach, $transactionId);
  70. //播放收款声音
  71. ShopExtClass::hdGatheringReport($orderSn);
  72. break;
  73. case dict::getDict('capitalType', 'xhRenew', 'id'):
  74. //商家续期
  75. RenewClass::thirdPay($payWay, $orderSn, $totalFee, $attach);
  76. break;
  77. case dict::getDict('capitalType', 'pxApply', 'id'):
  78. //培训报名
  79. PxApplyService::thirdPay($payWay, $orderSn, $totalFee, $attach);
  80. break;
  81. default:
  82. }
  83. }
  84. }