CustomRechargeController.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <?php
  2. namespace hd\controllers;
  3. use bizGhs\custom\classes\CustomClass;
  4. use bizGhs\custom\classes\CustomRechargeClass;
  5. use bizGhs\ghs\classes\GhsRechargeClass;
  6. use bizHd\ghs\classes\GhsClass;
  7. use bizHd\shop\classes\ShopClass;
  8. use common\components\lakala\Lakala;
  9. use common\components\dict;
  10. use common\components\orderSn;
  11. use common\components\util;
  12. use Yii;
  13. class CustomRechargeController extends BaseController
  14. {
  15. public $guestAccess = ['recharge'];
  16. //充值 ssh 20240507
  17. public function actionRecharge()
  18. {
  19. ini_set('date.timezone', 'Asia/Shanghai');
  20. $post = Yii::$app->request->post();
  21. $payWay = isset($post['payWay']) ? $post['payWay'] : 0;
  22. $actPrice = $post['actPrice'] ?? 0;
  23. $ghsId = $post['ghsId'] ?? 0;
  24. $salt = $post['salt'] ?? '';
  25. $ghs = GhsClass::getById($ghsId, true);
  26. if (empty($ghs)) {
  27. util::fail('没有找到供货商那');
  28. }
  29. if ($ghs->salt != $salt) {
  30. util::fail('不是你的供货商那');
  31. }
  32. $customId = $ghs->customId ?? 0;
  33. $custom = CustomClass::getById($customId, true);
  34. if (empty($custom)) {
  35. util::fail('供货商信息不完整那');
  36. }
  37. $capitalType = dict::getDict('capitalType', 'customRechargeToGhs', 'id');
  38. $customOrderSn = orderSn::getGhsCustomRechargeSn();
  39. $customShopId = $custom->shopId ?? 0;
  40. $customMainId = $custom->mainId ?? 0;
  41. $customBalance = $custom->balance ?? 0;
  42. $customName = $custom->name ?? '';
  43. $ghsShopId = $ghs->shopId ?? 0;
  44. $ghsMainId = $ghs->mainId ?? 0;
  45. $ghsBalance = $ghs->balance ?? 0;
  46. $ghsName = $ghs->name ?? '';
  47. $ghsShop = ShopClass::getById($ghsShopId, true);
  48. if (empty($ghsShop)) {
  49. util::fail('供货商信息不完全哦');
  50. }
  51. $customStaffId = 0;
  52. $customStaffName = '';
  53. if (isset($this->shopAdmin) && !empty($this->shopAdmin)) {
  54. $staff = $this->shopAdmin;
  55. $customStaffId = $staff->id ?? 0;
  56. $customStaffName = $staff->name ?? '';
  57. }
  58. $cData = [
  59. 'orderSn' => $customOrderSn,
  60. 'onlinePay' => 2,
  61. 'payWay' => $payWay,
  62. 'shopId' => $ghsShopId,
  63. 'mainId' => $ghsMainId,
  64. 'amount' => $actPrice,
  65. 'balance' => $customBalance,
  66. 'side' => 0,
  67. 'staffId' => 0,
  68. 'staffName' => '',
  69. 'payStatus' => 0,
  70. 'status' => 0,
  71. 'remark' => '',
  72. 'ghsId' => $ghsId,
  73. 'ghsShopId' => $ghsShopId,
  74. 'ghsName' => $ghsName,
  75. 'customId' => $customId,
  76. 'customShopId' => $customShopId,
  77. 'customName' => $customName,
  78. 'remark' => '',
  79. ];
  80. $cRecharge = CustomRechargeClass::add($cData, true);
  81. $cRechargeId = $cRecharge->id ?? 0;
  82. $ghsOrderSn = orderSn::getGhsRechargeSn();
  83. $gData = [
  84. 'orderSn' => $ghsOrderSn,
  85. 'onlinePay' => 2,
  86. 'payWay' => $payWay,
  87. 'shopId' => $customShopId,
  88. 'mainId' => $customMainId,
  89. 'amount' => $actPrice,
  90. 'balance' => $ghsBalance,
  91. 'side' => 0,
  92. 'staffId' => $customStaffId,
  93. 'staffName' => $customStaffName,
  94. 'payStatus' => 0,
  95. 'status' => 0,
  96. 'remark' => '',
  97. 'ghsId' => $ghsId,
  98. 'ghsShopId' => $ghsShopId,
  99. 'ghsName' => $ghsName,
  100. 'customId' => $customId,
  101. 'customShopId' => $customShopId,
  102. 'customName' => $customName,
  103. 'remark' => '',
  104. ];
  105. $gRecharge = GhsRechargeClass::add($gData, true);
  106. $gRechargeId = $gRecharge->id ?? 0;
  107. $cRecharge->ghsRechargeId = $gRechargeId;
  108. $cRecharge->save();
  109. $gRecharge->customRechargeId = $cRechargeId;
  110. $gRecharge->save();
  111. if ($payWay == 0) {
  112. } elseif ($payWay == 1) {
  113. $totalFee = $actPrice;
  114. $subject = '充值销账 单号' . $customOrderSn;
  115. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  116. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  117. $params = [
  118. 'appid' => 'OP00002119',
  119. 'serial_no' => '018b08cfddbd',
  120. 'merchant_no' => $ghsShop->lklSjNo,
  121. 'term_no' => $ghsShop->lklB2BTermNo,
  122. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  123. 'lklCertificatePath' => $lklCertificatePath,
  124. ];
  125. $laResource = new Lakala($params);
  126. $notifyUrl = Yii::$app->params['hdHost'] . "/notice/cash-pay-callback";
  127. $cashParams = [
  128. 'orderSn' => $customOrderSn,
  129. 'amount' => $totalFee,
  130. 'capitalType' => $capitalType,
  131. 'notifyUrl' => $notifyUrl,
  132. 'subject' => $subject,
  133. ];
  134. $response = $laResource->cashierPay($cashParams);
  135. if (isset($response['code']) == false || $response['code'] != '000000') {
  136. util::fail('支付失败了');
  137. }
  138. $url = $response['resp_data']['counter_url'] ? $response['resp_data']['counter_url'] : '';
  139. if (empty($url)) {
  140. util::fail('支付失败');
  141. }
  142. util::success(['url' => $url]);
  143. } else {
  144. util::fail('暂不支持的付款方式');
  145. }
  146. }
  147. }