request->post(); $payWay = $post['payWay'] ?? 0; $actPrice = $post['actPrice'] ?? 0; if ($actPrice <= 0) { util::fail('请输入数值'); } $actPrice = floor($actPrice * 100) / 100;//只保留2位小数 $totalFee = $actPrice; $ghsId = $post['ghsId'] ?? 0; $salt = $post['salt'] ?? ''; $ghs = GhsClass::getLockById($ghsId); if (empty($ghs)) { util::fail('没有找到供货商哦!'); } if ($ghs->salt != $salt) { util::fail('不是你的供货商哦'); } $customId = $ghs->customId ?? 0; $custom = CustomClass::getLockById($customId); if (empty($custom)) { util::fail('供货商信息不完整那'); } //检查余额是否有问题 //GhsClass::checkBalance($ghs, $custom); // 花店自助充值建单前:挂账并入净 balance AccountMoneyClass::ensureCustomMoneyReady($custom, true); AccountMoneyClass::ensureGhsMoneyReady($ghs, true); $capitalType = dict::getDict('capitalType', 'customRechargeToGhs', 'id'); $customOrderSn = orderSn::getGhsCustomRechargeSn(); $customShopId = $custom->shopId ?? 0; $customMainId = $custom->mainId ?? 0; $customBalance = $custom->balance ?? 0; $customName = $custom->name ?? ''; $ghsShopId = $ghs->shopId ?? 0; $ghsMainId = $ghs->mainId ?? 0; $ghsBalance = $ghs->balance ?? 0; $ghsName = $ghs->name ?? ''; $ghsShop = ShopClass::getById($ghsShopId, true); if (empty($ghsShop)) { util::fail('供货商信息不完全哦'); } $customStaffId = 0; $customStaffName = ''; if (isset($this->shopAdmin) && !empty($this->shopAdmin)) { $staff = $this->shopAdmin; $customStaffId = $staff->id ?? 0; $customStaffName = $staff->name ?? ''; } $cData = [ 'orderSn' => $customOrderSn, 'onlinePay' => 2, 'payWay' => $payWay, 'shopId' => $ghsShopId, 'mainId' => $ghsMainId, 'amount' => $actPrice, 'balance' => $customBalance, 'side' => 0, 'staffId' => 0, 'staffName' => '', 'payStatus' => 0, 'status' => 0, 'remark' => '', 'ghsId' => $ghsId, 'ghsShopId' => $ghsShopId, 'ghsName' => $ghsName, 'customId' => $customId, 'customShopId' => $customShopId, 'customName' => $customName, 'remark' => '', ]; $cRecharge = CustomRechargeClass::add($cData, true); $cRechargeId = $cRecharge->id ?? 0; $ghsOrderSn = orderSn::getGhsRechargeSn(); $gData = [ 'orderSn' => $ghsOrderSn, 'onlinePay' => 2, 'payWay' => $payWay, 'shopId' => $customShopId, 'mainId' => $customMainId, 'amount' => $actPrice, 'balance' => $ghsBalance, 'side' => 0, 'staffId' => $customStaffId, 'staffName' => $customStaffName, 'payStatus' => 0, 'status' => 0, 'remark' => '', 'ghsId' => $ghsId, 'ghsShopId' => $ghsShopId, 'ghsName' => $ghsName, 'customId' => $customId, 'customShopId' => $customShopId, 'customName' => $customName, 'remark' => '', ]; $gRecharge = GhsRechargeClass::add($gData, true); $gRechargeId = $gRecharge->id ?? 0; $cRecharge->ghsRechargeId = $gRechargeId; $cRecharge->save(); $gRecharge->customRechargeId = $cRechargeId; $gRecharge->save(); $subject = '充值销账 单号' . $customOrderSn; if ($payWay == 0) { $openId = ''; if (isset($post['currentMiniOpenId']) && !empty($post['currentMiniOpenId'])) { $openId = $post['currentMiniOpenId']; } if (empty($openId)) { if (isset($this->admin) && !empty($this->admin)) { if (isset($this->admin->miniOpenId) && !empty($this->admin->miniOpenId)) { $openId = $this->admin->miniOpenId; } } } if (empty($openId)) { $currentShop = ShopClass::getById($customShopId, true); $currentShopName = $currentShop->merchantName . ' ' . $currentShop->shopName; $currentMobile = $currentShop->mobile ?? ''; noticeUtil::push("花店向供货商充值时,发现没有openId。{$currentShopName} {$currentMobile}", '15280215347'); util::fail('用户信息不完整'); } $merchantExtend = WxOpenClass::getWxInfo(); $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' => $ghsShop->lklSjNo, 'term_no' => $ghsShop->lklScanTermNo, 'merchantPrivateKeyPath' => $merchantPrivateKeyPath, 'lklCertificatePath' => $lklCertificatePath, ]; $laResource = new Lakala($params); $notifyUrl = Yii::$app->params['hdHost'] . "/notice/pay-callback"; $wxParams = [ 'orderSn' => $customOrderSn, 'amount' => $totalFee, 'capitalType' => $capitalType, 'notifyUrl' => $notifyUrl, 'wxAppId' => $merchantExtend['miniAppId'], 'openId' => $openId, 'subject' => $subject, 'couponId' => 0, ]; $response = $laResource->driveWxPay($wxParams); if (isset($response['code']) == false || $response['code'] != 'BBS00000') { $errMsg = $response['msg'] ?? ''; $errCode = $response['code'] ?? ''; noticeUtil::push('编号19881507:' . $errCode . ' | ' . $errMsg . ' | ' . $ghsName . ' | ' . $customName . ' | ' . $actPrice, '15280215347'); if($errCode == 'BBS11109'){ util::fail('超过单笔限额,请分二笔支付'); } 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' => $gRechargeId, 'appId' => $appId, 'nonceStr' => $nonceStr, 'paySign' => $paySign, 'package' => $package, 'signType' => $signType, 'timeStamp' => $timeStamp, 'orderSn' => $customOrderSn, ]; util::success($new); } elseif ($payWay == 1) { $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' => $ghsShop->lklSjNo, 'term_no' => $ghsShop->lklB2BTermNo, 'merchantPrivateKeyPath' => $merchantPrivateKeyPath, 'lklCertificatePath' => $lklCertificatePath, ]; $laResource = new Lakala($params); $notifyUrl = Yii::$app->params['hdHost'] . "/notice/cash-pay-callback"; $cashParams = [ 'orderSn' => $customOrderSn, 'amount' => $totalFee, 'capitalType' => $capitalType, 'notifyUrl' => $notifyUrl, 'subject' => $subject, ]; $response = $laResource->cashierPay($cashParams); if (isset($response['code']) == false || $response['code'] != '000000') { util::fail('支付失败了'); } $url = $response['resp_data']['counter_url'] ? $response['resp_data']['counter_url'] : ''; if (empty($url)) { util::fail('支付失败'); } util::success(['url' => $url]); } else { util::fail('暂不支持的付款方式'); } } }