shopAdminId; $addData['shopAdminId'] = $eId; $shopAdmin = $this->shopAdmin->attributes; $adminName = $shopAdmin['name'] ?? ''; $sjId = $shopAdmin['sjId'] ?? 0; $addData['shopAdminName'] = $adminName; $set = SetClass::getByCondition(['style' => SetClass::SET_STYLE_GHS], true, 'id asc'); if (empty($set)) { util::fail('没有找到套餐'); } $price = $set->price; $prePrice = $price; $actPrice = $price; $setId = $set->id; $addData['actPrice'] = $actPrice; $addData['prePrice'] = $prePrice; $addData['sjId'] = $this->sjId; $now = time(); $expireTime = $now + 300;//订单5分钟后过期 $addData['deadline'] = date("Y-m-d H:i:s", $expireTime); $order = RenewService::addOrder($addData); $orderId = $order['id']; $orderSn = $order['orderSn']; $couponId = 0; $name = $set->name . '开通及续费'; $totalFee = $actPrice; $admin = $this->admin->attributes; //小程序使用miniOpenId $openId = $admin['miniOpenId']; $capitalType = dict::getDict('capitalType', 'xhRenew', 'id'); //将流水类型、优惠卷传过去 $attach = 'capitalType=' . $capitalType . '&couponId=' . $couponId . '&setId=' . $setId . '&sjId=' . $sjId; $wx = Yii::getAlias("@vendor/weixin"); require_once($wx . '/lib/WxPay.Api.php'); require_once($wx . '/example/WxPay.JsApiPay.php'); $input = new \WxPayUnifiedOrder(); $input->SetBody($name); $input->SetOut_trade_no($orderSn); $input->SetTotal_fee($totalFee * 100); $input->SetTime_start(date("YmdHis", $now)); $input->SetAttach($attach); $input->SetTime_expire(date("YmdHis", $expireTime));//设置订单有效期5分钟 $input->SetNotify_url(Yii::$app->params['hdHost'] . '/notice/wx-callback/'); $input->SetTrade_type("JSAPI"); //花卉宝代为申请的微信支付 $merchantExtend = WxOpenClass::getWxInfo(); $input->SetOpenid($openId); //小程序使用miniAppId $merchantExtend['wxAppId'] = $merchantExtend['miniAppId']; Yii::info('renew:' . json_encode($merchantExtend)); $wxOrder = \WxPayApi::unifiedOrder($input, 6, $merchantExtend); $tools = new \JsApiPay(); $jsApiParameters = $tools->GetJsApiParameters($wxOrder, $merchantExtend); $newParams = json_decode($jsApiParameters, true); $newParams['orderId'] = $orderId; $newParams['sjId'] = $this->sjId; util::success($newParams); } }