request->get(); $classId = $get['classId'] ?? 0; $info = PxClassClass::getClassInfo($classId); PxClassClass::valid($info, $this->sjId); $customId = $this->customId; if (!empty($customId)) { $custom = CustomClass::getCustomInfo($customId); CustomClass::valid($custom, $this->sjId); } $get['sjId'] = $this->sjId; $get['prePrice'] = $info['tuition']; $get['actPrice'] = $info['tuition']; $get['shopId'] = $this->shopId; $get['shopAdminId'] = 0; $get['customId'] = $this->customId; $get['className'] = $info['name'] ?? ''; $get['classCover'] = $info['cover'] ?? ''; $get['applyTime'] = date("Y-m-d H:i:s"); $get['status'] = PxApplyClass::STATUS_UN_CONFIRM; PxApplyClass::addApply($get, $this->shop); util::complete(); } //新学员 学员管理 ssh 2021.3.17 public function actionList() { $where = ['shopId' => $this->shopId]; $respond = PxApplyClass::getApplyList($where); util::success($respond); } public function actionWxPay() { ini_set('date.timezone', 'Asia/Shanghai'); $post = Yii::$app->request->post(); $orderSn = isset($post['orderSn']) ? $post['orderSn'] : 0; $couponId = isset($post['couponId']) ? $post['couponId'] : 0; $order = PxApplyClass::getByCondition(['customId'=> $this->customId,'orderSn' => $orderSn,'status'=>PxApplyClass::STATUS_UN_CONFIRM]); if (empty($order)) { util::fail('订单号无效'); } //验证优惠券是否还有效 if (!empty($couponId)) { CouponService::checkBeforeUse($couponId, $order['prePrice'], $order['userId']); } $name = $orderSn; $totalFee = $order['actPrice']; $wxPayType = 0; //小程序使用miniOpenId if (httpUtil::isMiniProgram()) { $openId = $this->user['miniOpenId']; $wxPayType = 1; } else { $openId = $this->user['openId']; } $typeList = dict::getConfig('capitalType'); $capitalType = $typeList['pxApply']['id']; $attach = "couponId=" . $couponId . "&capitalType=" . $capitalType . '&wxPayType=' . $wxPayType; //订单30分钟后过期 $now = time(); $expireTime = $now + 1800; $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)); $input->SetNotify_url(Yii::$app->params['mallHost'] . '/notice/wx-callback/'); $input->SetTrade_type("JSAPI"); //花卉宝代为申请的微信支付 $sjExtend = $this->sjExtend; if ($sjExtend['wxPayApply'] == 1) { $input->SetSub_openid($openId); } else { $input->SetOpenid($openId); } //小程序使用miniAppId if (httpUtil::isMiniProgram()) { $sjExtend['wxAppId'] = $sjExtend['miniAppId']; } $wxOrder = \WxPayApi::unifiedOrder($input, 6, $sjExtend); $tools = new \JsApiPay(); $jsApiParameters = $tools->GetJsApiParameters($wxOrder, $sjExtend); $newParams = json_decode($jsApiParameters, true); $current = date("Y-m-d H:i:s"); $updateData = ['deadline' => $current, 'changePrice' => 2]; // PurchaseClass::updateById($id, $updateData); util::success($newParams); } }