request->get(); $id = $get['id'] ?? 0; $info = LjhApplyClass::getById($id, true); if (empty($info)) { util::fail('没有信息'); } util::success($info); } public function actionApply() { $connection = Yii::$app->db; $transaction = $connection->beginTransaction(); try { $post = Yii::$app->request->post(); $shopName = $post['name'] ?? ''; if (empty($shopName)) { util::fail('名称不能为空'); } $mobile = $post['mobile'] ?? ''; if (stringUtil::isMobile($mobile) == false) { util::fail('请填写正确手机号'); } if (stringUtil::getWordNum($shopName) > 8) { util::fail('名称不能超过8个汉字'); } $authCode = $post['authCode'] ?? ''; $mobile = $post['mobile'] ?? ''; //避免重复提交 util::checkRepeatCommit($mobile, 5); $ptStyle = Yii::$app->params['ptStyle']; $cacheKey = 'register_mobile_code_' . $ptStyle . '_' . $mobile; $saveAuthCode = Yii::$app->redis->executeCommand('GET', [$cacheKey]); if (empty($saveAuthCode)) { util::fail('请填写验证码哦'); } if (empty($authCode)) { util::fail('请填写验证码'); } if ($saveAuthCode != $authCode) { util::fail('验证码错误'); } $post['long'] = isset($post['longitude']) ? $post['longitude'] : ''; $post['lat'] = isset($post['latitude']) ? $post['latitude'] : ''; $orderSn = orderSn::getLjhApplySn(); $post['orderSn'] = $orderSn; if (getenv('YII_ENV') == 'production') { $price = bcsub(790, 20, 2); } else { $price = bcsub(20.05, 20, 2); } $post['actPrice'] = $price; $post['realPrice'] = $price; $ljhApply = LjhApplyClass::addApply($post); $ljhApplyId = $ljhApply->id ?? 0; $transaction->commit(); util::success(['id' => $ljhApplyId, 'newUser' => 0,]); } catch (\Exception $exception) { $transaction->rollBack(); Yii::info("报名出错了:" . $exception->getMessage()); util::fail('报名出错了'); } } //微信支付 ssh 20230304 public function actionWxPay() { ini_set('date.timezone', 'Asia/Shanghai'); $post = Yii::$app->request->post(); $orderSn = isset($post['orderSn']) ? $post['orderSn'] : 0; $order = LjhApplyClass::getByCondition(['orderSn' => $orderSn], true); if (empty($order)) { util::fail('订单号无效'); } if ($order->status == 2) { util::fail('已报名成功了'); } $name = '零交会报名 ' . $orderSn; $totalFee = $order->actPrice; //强制使用小程序的miniOpenId $openId = isset($post['miniOpenId']) && !empty($post['miniOpenId']) ? $post['miniOpenId'] : ''; if (empty($openId)) { $admin = $this->admin; $openId = $admin->miniOpenId ?? ''; } //没有openId if (empty($openId)) { util::success(['hasNoMiniOpenId' => 1]); } $purchaseCapital = dict::getDict('capitalType', 'ljhApply', 'id'); //流水类型、优惠卷、微信支付(h5还是小程序支付)类型 带到回调 $wxPayType = httpUtil::isMiniProgram() ? 1 : 0; $couponId = 0; $attach = "couponId=" . $couponId . "&capitalType=" . $purchaseCapital . '&wxPayType=' . $wxPayType; //订单20天后过期 $now = time(); $expireTime = $now + 1728000; $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['hdHost'] . '/notice/wx-callback/'); $input->SetTrade_type("JSAPI"); //花卉宝代为申请的微信支付 $merchantExtend = WxOpenClass::getWxInfo(); if (isset($merchantExtend['wxPayApply']) && $merchantExtend['wxPayApply'] == 1) { $input->SetSub_openid($openId); } else { $input->SetOpenid($openId); } //强制使用小程序的miniAppId $merchantExtend['wxAppId'] = $merchantExtend['miniAppId']; $wxOrder = \WxPayApi::unifiedOrder($input, 6, $merchantExtend); $tools = new \JsApiPay(); $jsApiParameters = $tools->GetJsApiParameters($wxOrder, $merchantExtend); $newParams = json_decode($jsApiParameters, true); util::success($newParams); } }