RechargeController.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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 20250709
  18. public function actionWxPayRecharge()
  19. {
  20. $post = Yii::$app->request->post();
  21. $id = $post['id'] ?? '';
  22. //避免重复提交
  23. util::checkRepeatCommit($id, 8);
  24. $recharge = RechargeClass::getById($id, true);
  25. if (empty($recharge)) {
  26. util::fail('没有充值单');
  27. }
  28. $userId = $this->userId;
  29. $shopId = $this->shopId;
  30. if ($recharge->userId != $userId || $recharge->shopId != $shopId) {
  31. util::fail('不是你的充值单');
  32. }
  33. $shop = $this->shop;
  34. $user = $this->user;
  35. if (empty($shop)) {
  36. util::fail('没有门店信息');
  37. }
  38. $shop = $this->shop;
  39. $orderSn = $recharge->orderSn;
  40. $openId = !empty($post['miniOpenId']) ? $post['miniOpenId'] : '';
  41. if (empty($openId)) {
  42. $openId = !empty($user['miniOpenId']) ? $user['miniOpenId'] : '';
  43. }
  44. if (empty($openId)) {
  45. util::fail('没有找到openId');
  46. }
  47. $name = '充值销账,单号' . $orderSn;
  48. $totalFee = $recharge->amount ?? 0;
  49. $orderId = $recharge->id;
  50. $capitalType = dict::getDict('capitalType', 'xhRecharge', 'id');
  51. $sjExtend = WxOpenClass::getMallWxInfo();
  52. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  53. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  54. $params = [
  55. 'appid' => 'OP00002119',
  56. 'serial_no' => '018b08cfddbd',
  57. 'merchant_no' => $shop->lklSjNo,
  58. 'term_no' => $shop->lklScanTermNo,
  59. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  60. 'lklCertificatePath' => $lklCertificatePath,
  61. ];
  62. $laResource = new Lakala($params);
  63. $notifyUrl = Yii::$app->params['mallHost'] . "/notice/pay-callback";
  64. $wxParams = [
  65. 'orderSn' => $orderSn,
  66. 'amount' => $totalFee,
  67. 'capitalType' => $capitalType,
  68. 'notifyUrl' => $notifyUrl,
  69. 'wxAppId' => $sjExtend['miniAppId'],
  70. 'openId' => $openId,
  71. 'subject' => $name,
  72. 'couponId' => 0,
  73. ];
  74. $response = $laResource->driveWxPay($wxParams);
  75. if (!isset($response['code']) || $response['code'] != 'BBS00000') {
  76. $errMsg = $response['msg'] ?? '';
  77. noticeUtil::push($errMsg, '15280215347');
  78. util::fail('充值失败');
  79. }
  80. $respData = $response['resp_data'] ?? [];
  81. $accRespFields = $respData['acc_resp_fields'] ?? [];
  82. if (empty($accRespFields)) {
  83. util::fail('充值失败,没有找到支付数据');
  84. }
  85. $appId = $accRespFields['app_id'] ?? '';
  86. $nonceStr = $accRespFields['nonce_str'] ?? '';
  87. $paySign = $accRespFields['pay_sign'] ?? '';
  88. $package = $accRespFields['package'] ?? '';
  89. $signType = $accRespFields['sign_type'] ?? '';
  90. $timeStamp = $accRespFields['time_stamp'] ?? '';
  91. $new = [
  92. 'id' => $orderId,
  93. 'appId' => $appId,
  94. 'nonceStr' => $nonceStr,
  95. 'paySign' => $paySign,
  96. 'package' => $package,
  97. 'signType' => $signType,
  98. 'timeStamp' => $timeStamp,
  99. 'orderSn' => $orderSn,
  100. ];
  101. util::success($new);
  102. }
  103. //获取充值订单的详情 ssh 20250709
  104. public function actionGetDetail()
  105. {
  106. $get = Yii::$app->request->get();
  107. $id = $get['id'] ?? 0;
  108. $recharge = RechargeClass::getById($id, true);
  109. if (empty($recharge)) {
  110. util::fail('没有找到充值订单');
  111. }
  112. $userId = $this->userId;
  113. $shopId = $this->shopId;
  114. if ($recharge->userId != $userId || $recharge->shopId != $shopId) {
  115. util::fail('不是你的充值单');
  116. }
  117. util::success($recharge);
  118. }
  119. //充值 ssh 20240507
  120. public function actionRecharge()
  121. {
  122. ini_set('date.timezone', 'Asia/Shanghai');
  123. $post = Yii::$app->request->post();
  124. $payWay = isset($post['payWay']) ? $post['payWay'] : 0;
  125. $actPrice = $post['actPrice'] ?? 0;
  126. $totalFee = $actPrice;
  127. $shopId = $this->shopId;
  128. if (empty($shopId)) {
  129. util::fail('没有找到花店');
  130. }
  131. $shop = ShopClass::getById($shopId, true);
  132. if (empty($shop)) {
  133. util::fail('没有找到花店呢');
  134. }
  135. $mainId = $this->mainId;
  136. $hdId = $post['hdId'] ?? 0;
  137. $salt = $post['salt'] ?? '';
  138. $hd = HdClass::getById($hdId, true);
  139. if (empty($hd)) {
  140. util::fail('没有找到花店哦!');
  141. }
  142. if (empty($salt)) {
  143. }else{
  144. if($hd->salt != $salt){
  145. util::fail('不是你的花店哦');
  146. }
  147. }
  148. $customId = $hd->customId ?? 0;
  149. $custom = CustomClass::getById($customId, true);
  150. if (empty($custom)) {
  151. util::fail('花店客户缺失');
  152. }
  153. $customName = $custom->name;
  154. $hd = HdClass::getById($hdId, true);
  155. if (empty($hd)) {
  156. util::fail('花店信息缺失');
  157. }
  158. $hdName = $hd->name;
  159. $capitalType = dict::getDict('capitalType', 'xhRecharge', 'id');
  160. $orderSn = orderSn::getRechargeSn();
  161. $rechargeData = [
  162. 'orderSn' => $orderSn,
  163. 'modPrice' => 0,
  164. 'payWay' => $payWay,
  165. 'returnCode' => '',
  166. 'shopId' => $shopId,
  167. 'mainId' => $mainId,
  168. 'hdId' => $hdId,
  169. 'hdName' => $hdName,
  170. 'amount' => $actPrice,
  171. 'onlinePay' => 1,
  172. 'payStatus' => 0,
  173. 'status' => 0,
  174. 'customId' => $customId,
  175. 'customName' => $customName,
  176. ];
  177. $respond = RechargeClass::addRecharge($rechargeData);
  178. $rechargeId = $respond->id;
  179. $subject = '线上充值,单号' . $orderSn;
  180. if ($payWay == 0) {
  181. $openId = !empty($post['currentMiniOpenId']) ? $post['currentMiniOpenId'] : '';
  182. if (empty($openId)) {
  183. if (!empty($this->admin)) {
  184. if (isset($this->admin->miniOpenId) && !empty($this->admin->miniOpenId)) {
  185. $openId = $this->admin->miniOpenId;
  186. }
  187. }
  188. }
  189. $merchantExtend = WxOpenClass::getMallWxInfo();
  190. $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  191. $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  192. $params = [
  193. 'appid' => 'OP00002119',
  194. 'serial_no' => '018b08cfddbd',
  195. 'merchant_no' => $shop->lklSjNo,
  196. 'term_no' => $shop->lklScanTermNo,
  197. 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  198. 'lklCertificatePath' => $lklCertificatePath,
  199. ];
  200. $laResource = new Lakala($params);
  201. $notifyUrl = Yii::$app->params['mallHost'] . "/notice/pay-callback";
  202. $wxParams = [
  203. 'orderSn' => $orderSn,
  204. 'amount' => $totalFee,
  205. 'capitalType' => $capitalType,
  206. 'notifyUrl' => $notifyUrl,
  207. 'wxAppId' => $merchantExtend['miniAppId'],
  208. 'openId' => $openId,
  209. 'subject' => $subject,
  210. 'couponId' => 0,
  211. ];
  212. $response = $laResource->driveWxPay($wxParams);
  213. if ($response['code'] != 'BBS00000') {
  214. $errMsg = $response['msg'] ?? '';
  215. noticeUtil::push('编号666993:' . $errMsg, '15280215347');
  216. util::fail('支付失败');
  217. }
  218. $newParams = isset($response['resp_data']['acc_resp_fields']) ? $response['resp_data']['acc_resp_fields'] : [];
  219. $appId = $newParams['app_id'] ?? '';
  220. $nonceStr = $newParams['nonce_str'] ?? '';
  221. $paySign = $newParams['pay_sign'] ?? '';
  222. $package = $newParams['package'] ?? '';
  223. $signType = $newParams['sign_type'] ?? '';
  224. $timeStamp = $newParams['time_stamp'] ?? '';
  225. $new = [
  226. 'id' => $rechargeId,
  227. 'appId' => $appId,
  228. 'nonceStr' => $nonceStr,
  229. 'paySign' => $paySign,
  230. 'package' => $package,
  231. 'signType' => $signType,
  232. 'timeStamp' => $timeStamp,
  233. 'orderSn' => $orderSn,
  234. ];
  235. util::success($new);
  236. } elseif ($payWay == 1) {
  237. util::fail('开发中');
  238. // $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem';
  239. // $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer';
  240. // $params = [
  241. // 'appid' => 'OP00002119',
  242. // 'serial_no' => '018b08cfddbd',
  243. // 'merchant_no' => $ghsShop->lklSjNo,
  244. // 'term_no' => $ghsShop->lklB2BTermNo,
  245. // 'merchantPrivateKeyPath' => $merchantPrivateKeyPath,
  246. // 'lklCertificatePath' => $lklCertificatePath,
  247. // ];
  248. // $laResource = new Lakala($params);
  249. // $notifyUrl = Yii::$app->params['hdHost'] . "/notice/cash-pay-callback";
  250. // $cashParams = [
  251. // 'orderSn' => $customOrderSn,
  252. // 'amount' => $totalFee,
  253. // 'capitalType' => $capitalType,
  254. // 'notifyUrl' => $notifyUrl,
  255. // 'subject' => $subject,
  256. // ];
  257. // $response = $laResource->cashierPay($cashParams);
  258. // if (isset($response['code']) == false || $response['code'] != '000000') {
  259. // util::fail('支付失败了');
  260. // }
  261. // $url = $response['resp_data']['counter_url'] ? $response['resp_data']['counter_url'] : '';
  262. // if (empty($url)) {
  263. // util::fail('支付失败');
  264. // }
  265. // util::success(['url' => $url]);
  266. } else {
  267. util::fail('暂不支持的付款方式');
  268. }
  269. }
  270. }