request->get(); $id = $get['id'] ?? 0; $recharge = \bizMall\recharge\classes\RechargeClass::getLockById($id); if (empty($recharge)) { util::fail('没有找到充值记录'); } if ($recharge->userId != $this->userId) { util::fail('不是你的充值单'); } if ($recharge->shopId != $this->shopId) { util::fail('不是你的充值记录'); } if ($recharge->status == 1) { util::fail('已充值成功,不能取消'); } if ($recharge->status == 2) { util::fail('已经取消过了'); } $shop = $this->shop; \bizMall\recharge\classes\RechargeClass::cancelMyRecharge($recharge, $shop); util::complete('取消成功'); } public function actionList() { $get = Yii::$app->request->get(); $hdId = $get['hdId'] ?? 0; $status = $get['status'] ?? -1; $hd = \bizMall\hd\classes\HdClass::getById($hdId, true); $where = ['mainId' => $this->mainId]; if (!empty($hd)) { if ($hd->shopId != $this->shopId) { util::fail('不是你的门店'); } $customId = $hd->customId ?? 0; $where['customId'] = $customId; } if ($status > -1) { $where['status'] = $status; } $list = \bizMall\recharge\classes\RechargeClass::getRechargeList($where); util::success($list); } //用微信支付进行充值 ssh 20250709 public function actionWxPayRecharge() { $post = Yii::$app->request->post(); $id = $post['id'] ?? ''; //避免重复提交 util::checkRepeatCommit($id, 8); $recharge = RechargeClass::getById($id, true); if (empty($recharge)) { util::fail('没有充值单'); } $userId = $this->userId; $shopId = $this->shopId; if ($recharge->userId != $userId || $recharge->shopId != $shopId) { util::fail('不是你的充值单'); } $shop = $this->shop; $user = $this->user; if (empty($shop)) { util::fail('没有门店信息'); } $shop = $this->shop; $orderSn = $recharge->orderSn; $openId = !empty($post['miniOpenId']) ? $post['miniOpenId'] : ''; if (empty($openId)) { $openId = !empty($user['miniOpenId']) ? $user['miniOpenId'] : ''; } if (empty($openId)) { util::fail('没有找到openId'); } //已经发起过支付,需要更换单号 if ($recharge->payRequest == 1 || $recharge->payRequest == 2) { $closeOrderSn = $orderSn; //老单号需要关单,否则有付款成功的风险,老单号关闭成功了,才能生成新单号 $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem'; $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer'; $params = [ 'appid' => 'OP00002119', 'serial_no' => '018b08cfddbd', 'merchant_no' => $shop->lklSjNo, 'term_no' => $shop->lklScanTermNo, 'merchantPrivateKeyPath' => $merchantPrivateKeyPath, 'lklCertificatePath' => $lklCertificatePath, ]; $laResource = new Lakala($params); $closeParams = ['orderSn' => $closeOrderSn]; if ($recharge->payRequest == 1) { //聚合支付关单 $response = $laResource->close($closeParams); if (!isset($response['code']) || $response['code'] != 'BBS00000') { $msg = $response['msg'] ?? ''; noticeUtil::push('重点注意,充值换单号没有成功,单号:' . $closeOrderSn . ',关单没有成功,' . $msg, '15280215347'); util::fail('出错了哦,请重新操作哈'); } } else { //收银台关单 $response = $laResource->cashClose($closeParams); if (!isset($response['code']) || $response['code'] != '000000') { $msg = $response['msg'] ?? ''; noticeUtil::push('重点注意,充值换单,收银台的单号:' . $closeOrderSn . ',关单没有成功,' . $msg, '15280215347'); util::fail('出错了哦,请重新操作呢'); } } //生成新的订单,避免重复 $orderSn = orderSn::getRechargeSn(); $recharge->orderSn = $orderSn; $recharge->save(); } $name = '充值销账,单号' . $orderSn; $totalFee = $recharge->amount ?? 0; $orderId = $recharge->id; $capitalType = dict::getDict('capitalType', 'xhRecharge', 'id'); $sjExtend = WxOpenClass::getMallWxInfo(); $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem'; $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer'; $params = [ 'appid' => 'OP00002119', 'serial_no' => '018b08cfddbd', 'merchant_no' => $shop->lklSjNo, 'term_no' => $shop->lklScanTermNo, 'merchantPrivateKeyPath' => $merchantPrivateKeyPath, 'lklCertificatePath' => $lklCertificatePath, ]; $laResource = new Lakala($params); $notifyUrl = Yii::$app->params['mallHost'] . "/notice/pay-callback"; $wxParams = [ 'orderSn' => $orderSn, 'amount' => $totalFee, 'capitalType' => $capitalType, 'notifyUrl' => $notifyUrl, 'wxAppId' => $sjExtend['miniAppId'], 'openId' => $openId, 'subject' => $name, 'couponId' => 0, ]; $response = $laResource->driveWxPay($wxParams); //0没有唤起过第三方支付,1唤起过聚合支付,2唤起过收银台。主要针对拉卡拉支付。 $recharge->payRequest = 1; $recharge->save(); if (!isset($response['code']) || $response['code'] != 'BBS00000') { $errMsg = $response['msg'] ?? ''; noticeUtil::push($errMsg, '15280215347'); util::fail('充值失败'); } $respData = $response['resp_data'] ?? []; $accRespFields = $respData['acc_resp_fields'] ?? []; if (empty($accRespFields)) { util::fail('充值失败,没有找到支付数据'); } $appId = $accRespFields['app_id'] ?? ''; $nonceStr = $accRespFields['nonce_str'] ?? ''; $paySign = $accRespFields['pay_sign'] ?? ''; $package = $accRespFields['package'] ?? ''; $signType = $accRespFields['sign_type'] ?? ''; $timeStamp = $accRespFields['time_stamp'] ?? ''; $new = [ 'id' => $orderId, 'appId' => $appId, 'nonceStr' => $nonceStr, 'paySign' => $paySign, 'package' => $package, 'signType' => $signType, 'timeStamp' => $timeStamp, 'orderSn' => $orderSn, ]; util::success($new); } //获取充值订单的详情 ssh 20250709 public function actionGetDetail() { $get = Yii::$app->request->get(); $id = $get['id'] ?? 0; $recharge = RechargeClass::getById($id, true); if (empty($recharge)) { util::fail('没有找到充值订单'); } $userId = $this->userId; $shopId = $this->shopId; if ($recharge->userId != $userId || $recharge->shopId != $shopId) { util::fail('不是你的单'); } util::success($recharge); } //充值 ssh 20240507 public function actionRecharge() { ini_set('date.timezone', 'Asia/Shanghai'); $post = Yii::$app->request->post(); $payWay = isset($post['payWay']) ? $post['payWay'] : 0; $actPrice = $post['actPrice'] ?? 0; $totalFee = $actPrice; $shopId = $this->shopId; if (empty($shopId)) { util::fail('没有找到花店'); } $shop = ShopClass::getById($shopId, true); if (empty($shop)) { util::fail('没有找到花店呢'); } $mainId = $this->mainId; $userId = $this->userId; $hdId = $post['hdId'] ?? 0; $salt = $post['salt'] ?? ''; $hd = HdClass::getById($hdId, true); if (empty($hd)) { util::fail('没有找到花店哦!'); } if (empty($salt)) { } else { if ($hd->salt != $salt) { util::fail('不是你的花店哦'); } } $customId = $hd->customId ?? 0; $custom = CustomClass::getById($customId, true); if (empty($custom)) { util::fail('花店客户缺失'); } $customName = $custom->name; $hd = HdClass::getById($hdId, true); if (empty($hd)) { util::fail('花店信息缺失,编号6663'); } $hdName = $hd->name; $capitalType = dict::getDict('capitalType', 'xhRecharge', 'id'); $orderSn = orderSn::getRechargeSn(); $rechargeData = [ 'orderSn' => $orderSn, 'modPrice' => 0, 'payWay' => $payWay, 'returnCode' => '', 'shopId' => $shopId, 'mainId' => $mainId, 'hdId' => $hdId, 'hdName' => $hdName, 'amount' => $actPrice, 'onlinePay' => 1, 'payStatus' => 0, 'status' => 0, 'customId' => $customId, 'customName' => $customName, 'userId' => $userId, ]; $respond = RechargeClass::addRecharge($rechargeData); $rechargeId = $respond->id; $respond->payRequest = 1; $respond->save(); $subject = '线上充值,单号' . $orderSn; if ($payWay == 0) { $openId = !empty($post['currentMiniOpenId']) ? $post['currentMiniOpenId'] : ''; if (empty($openId)) { if (!empty($this->admin)) { if (isset($this->admin->miniOpenId) && !empty($this->admin->miniOpenId)) { $openId = $this->admin->miniOpenId; } } } $merchantExtend = WxOpenClass::getMallWxInfo(); $merchantPrivateKeyPath = Yii::getAlias("@vendor/lakala") . '/production/api_private_key.pem'; $lklCertificatePath = Yii::getAlias("@vendor/lakala") . '/production/lkl-apigw-v1.cer'; $params = [ 'appid' => 'OP00002119', 'serial_no' => '018b08cfddbd', 'merchant_no' => $shop->lklSjNo, 'term_no' => $shop->lklScanTermNo, 'merchantPrivateKeyPath' => $merchantPrivateKeyPath, 'lklCertificatePath' => $lklCertificatePath, ]; $laResource = new Lakala($params); $notifyUrl = Yii::$app->params['mallHost'] . "/notice/pay-callback"; $wxParams = [ 'orderSn' => $orderSn, 'amount' => $totalFee, 'capitalType' => $capitalType, 'notifyUrl' => $notifyUrl, 'wxAppId' => $merchantExtend['miniAppId'], 'openId' => $openId, 'subject' => $subject, 'couponId' => 0, ]; $response = $laResource->driveWxPay($wxParams); if ($response['code'] != 'BBS00000') { $errMsg = $response['msg'] ?? ''; noticeUtil::push('编号666993:' . $errMsg, '15280215347'); util::fail('支付失败'); } $newParams = isset($response['resp_data']['acc_resp_fields']) ? $response['resp_data']['acc_resp_fields'] : []; $appId = $newParams['app_id'] ?? ''; $nonceStr = $newParams['nonce_str'] ?? ''; $paySign = $newParams['pay_sign'] ?? ''; $package = $newParams['package'] ?? ''; $signType = $newParams['sign_type'] ?? ''; $timeStamp = $newParams['time_stamp'] ?? ''; $new = [ 'id' => $rechargeId, 'appId' => $appId, 'nonceStr' => $nonceStr, 'paySign' => $paySign, 'package' => $package, 'signType' => $signType, 'timeStamp' => $timeStamp, 'orderSn' => $orderSn, ]; util::success($new); } elseif ($payWay == 1) { util::fail('开发中'); } else { util::fail('暂不支持的付款方式'); } } }