RechargeController.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <?php
  2. namespace mall\controllers;
  3. use bizHd\custom\classes\CustomClass;
  4. use bizHd\custom\classes\HdClass;
  5. use bizHd\merchant\classes\ShopClass;
  6. use bizHd\recharge\classes\RechargeClass;
  7. use bizHd\wx\classes\WxOpenClass;
  8. use common\components\dict;
  9. use common\components\noticeUtil;
  10. use common\components\orderSn;
  11. use common\components\util;
  12. use Yii;
  13. use common\components\lakala\Lakala;
  14. class RechargeController extends BaseController
  15. {
  16. public $guestAccess = ['recharge'];
  17. //充值 ssh 20240507
  18. public function actionRecharge()
  19. {
  20. ini_set('date.timezone', 'Asia/Shanghai');
  21. $post = Yii::$app->request->post();
  22. $payWay = isset($post['payWay']) ? $post['payWay'] : 0;
  23. $actPrice = $post['actPrice'] ?? 0;
  24. $totalFee = $actPrice;
  25. $shopId = $this->shopId;
  26. if (empty($shopId)) {
  27. util::fail('没有找到花店');
  28. }
  29. $shop = ShopClass::getById($shopId, true);
  30. if (empty($shop)) {
  31. util::fail('没有找到花店呢');
  32. }
  33. $mainId = $this->mainId;
  34. $hdId = $post['hdId'] ?? 0;
  35. $salt = $post['salt'] ?? '';
  36. $hd = HdClass::getById($hdId, true);
  37. if (empty($hd)) {
  38. util::fail('没有找到花店哦!');
  39. }
  40. if (empty($salt) || $hd->salt != $salt) {
  41. util::fail('不是你的花店哦');
  42. }
  43. $customId = $hd->customId ?? 0;
  44. $custom = CustomClass::getById($customId, true);
  45. if (empty($custom)) {
  46. util::fail('花店客户缺失');
  47. }
  48. $customName = $custom->name;
  49. $hd = HdClass::getById($hdId, true);
  50. if (empty($hd)) {
  51. util::fail('花店信息缺失');
  52. }
  53. $hdName = $hd->name;
  54. $capitalType = dict::getDict('capitalType', 'xhRecharge', 'id');
  55. $orderSn = orderSn::getRechargeSn();
  56. $rechargeData = [
  57. 'orderSn' => $orderSn,
  58. 'modPrice' => 0,
  59. 'payWay' => $payWay,
  60. 'returnCode' => '',
  61. 'shopId' => $shopId,
  62. 'mainId' => $mainId,
  63. 'hdId' => $hdId,
  64. 'hdName' => $hdName,
  65. 'amount' => $actPrice,
  66. 'onlinePay' => 1,
  67. 'payStatus' => 0,
  68. 'status' => 0,
  69. 'customId' => $customId,
  70. 'customName' => $customName,
  71. ];
  72. $respond = RechargeClass::addRecharge($rechargeData);
  73. $rechargeId = $respond->id;
  74. $subject = '线上充值,单号' . $orderSn;
  75. if ($payWay == 0) {
  76. $openId = !empty($post['currentMiniOpenId']) ? $post['currentMiniOpenId'] : '';
  77. if (empty($openId)) {
  78. if (!empty($this->admin)) {
  79. if (isset($this->admin->miniOpenId) && !empty($this->admin->miniOpenId)) {
  80. $openId = $this->admin->miniOpenId;
  81. }
  82. }
  83. }
  84. $merchantExtend = WxOpenClass::getMallWxInfo();
  85. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  86. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  87. $params = [
  88. 'appid' => 'OP00002119',
  89. 'serial_no' => '018b08cfddbd',
  90. 'merchant_no' => $shop->lklSjNo,
  91. 'term_no' => $shop->lklScanTermNo,
  92. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  93. 'lklCertificatePath' => $lklCertificatePath,
  94. ];
  95. $laResource = new Lakala($params);
  96. $notifyUrl = Yii::$app->params['mallHost'] . "/notice/pay-callback";
  97. $wxParams = [
  98. 'orderSn' => $orderSn,
  99. 'amount' => $totalFee,
  100. 'capitalType' => $capitalType,
  101. 'notifyUrl' => $notifyUrl,
  102. 'wxAppId' => $merchantExtend['miniAppId'],
  103. 'openId' => $openId,
  104. 'subject' => $subject,
  105. 'couponId' => 0,
  106. ];
  107. $response = $laResource->driveWxPay($wxParams);
  108. if ($response['code'] != 'BBS00000') {
  109. $errMsg = $response['msg'] ?? '';
  110. noticeUtil::push('编号666993:' . $errMsg, '15280215347');
  111. util::fail('支付失败');
  112. }
  113. $newParams = isset($response['resp_data']['acc_resp_fields']) ? $response['resp_data']['acc_resp_fields'] : [];
  114. $appId = $newParams['app_id'] ?? '';
  115. $nonceStr = $newParams['nonce_str'] ?? '';
  116. $paySign = $newParams['pay_sign'] ?? '';
  117. $package = $newParams['package'] ?? '';
  118. $signType = $newParams['sign_type'] ?? '';
  119. $timeStamp = $newParams['time_stamp'] ?? '';
  120. $new = [
  121. 'id' => $rechargeId,
  122. 'appId' => $appId,
  123. 'nonceStr' => $nonceStr,
  124. 'paySign' => $paySign,
  125. 'package' => $package,
  126. 'signType' => $signType,
  127. 'timeStamp' => $timeStamp,
  128. 'orderSn' => $orderSn,
  129. ];
  130. util::success($new);
  131. } elseif ($payWay == 1) {
  132. util::fail('开发中');
  133. // $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  134. // $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  135. // $params = [
  136. // 'appid' => 'OP00002119',
  137. // 'serial_no' => '018b08cfddbd',
  138. // 'merchant_no' => $ghsShop->lklSjNo,
  139. // 'term_no' => $ghsShop->lklB2BTermNo,
  140. // 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  141. // 'lklCertificatePath' => $lklCertificatePath,
  142. // ];
  143. // $laResource = new Lakala($params);
  144. // $notifyUrl = Yii::$app->params['hdHost'] . "/notice/cash-pay-callback";
  145. // $cashParams = [
  146. // 'orderSn' => $customOrderSn,
  147. // 'amount' => $totalFee,
  148. // 'capitalType' => $capitalType,
  149. // 'notifyUrl' => $notifyUrl,
  150. // 'subject' => $subject,
  151. // ];
  152. // $response = $laResource->cashierPay($cashParams);
  153. // if (isset($response['code']) == false || $response['code'] != '000000') {
  154. // util::fail('支付失败了');
  155. // }
  156. // $url = $response['resp_data']['counter_url'] ? $response['resp_data']['counter_url'] : '';
  157. // if (empty($url)) {
  158. // util::fail('支付失败');
  159. // }
  160. // util::success(['url' => $url]);
  161. } else {
  162. util::fail('暂不支持的付款方式');
  163. }
  164. }
  165. }