payUtil.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. namespace common\components;
  3. use biz\recharge\classes\RechargeClass;
  4. use biz\renew\classes\RenewClass;
  5. use bizHd\order\classes\OrderClass;
  6. use bizHd\purchase\classes\PurchaseClearClass;
  7. use bizHd\purchase\services\PurchaseService;
  8. use bizHd\px\services\PxApplyService;
  9. use Yii;
  10. class payUtil
  11. {
  12. public static function thirdPay($payWay, $capitalType, $orderSn, $totalFee, $attach, $transactionId = '')
  13. {
  14. //2秒内不允许第三方重复通知
  15. $cacheKey = 'third_pay_' . $orderSn;
  16. $has = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  17. if (!empty($has)) {
  18. Yii::info("第三方2秒内重复通知:{$capitalType} {$orderSn}");
  19. return false;
  20. }
  21. Yii::$app->redis->executeCommand('SETEX', [$cacheKey, 2, 'has']);
  22. $connection = Yii::$app->db;
  23. $transaction = $connection->beginTransaction();
  24. try {
  25. //流水类型列表
  26. switch ($capitalType) {
  27. case dict::getDict('capitalType', 'xhRecharge', 'id'):
  28. //零售和供应商充值
  29. RechargeClass::thirdPay($payWay, $orderSn, $totalFee, $attach);
  30. break;
  31. case dict::getDict('capitalType', 'xhPurchase', 'id'):
  32. //零售采购订单
  33. PurchaseService::thirdPay($payWay, $orderSn, $totalFee, $attach, $transactionId);
  34. break;
  35. case dict::getDict('capitalType', 'hdPurchaseClear', 'id'):
  36. //零售采购订单结清欠款
  37. PurchaseClearClass::thirdPay($payWay, $orderSn, $totalFee, $attach);
  38. break;
  39. case dict::getDict('capitalType', 'xhOrder', 'id'):
  40. //零售订单
  41. OrderClass::thirdPay($payWay, $orderSn, $totalFee, $attach);
  42. break;
  43. case dict::getDict('capitalType', 'xhRenew', 'id'):
  44. //零售和供应商续费订单
  45. RenewClass::thirdPay($payWay, $orderSn, $totalFee, $attach);
  46. break;
  47. case dict::getDict('capitalType', 'pxApply', 'id'):
  48. //培训报名
  49. PxApplyService::thirdPay($payWay, $orderSn, $totalFee, $attach);
  50. break;
  51. default:
  52. }
  53. $transaction->commit();
  54. } catch
  55. (Exception $exception) {
  56. $transaction->rollBack();
  57. util::fail("支付回调处理失败 orderSn:{$orderSn} capitalType:{$capitalType}");
  58. }
  59. }
  60. }