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); } //免费领取商城 ssh 20230304 public function actionGetMall() { $shop = $this->shop; if (!empty($shop)) { util::complete('已经有店铺了'); } $get = Yii::$app->request->get(); $orderSn = isset($get['orderSn']) ? $get['orderSn'] : 0; $ljh = LjhApplyClass::getByCondition(['orderSn' => $orderSn], true); if (empty($ljh)) { util::complete('订单号无效'); } $mobile = $ljh->mobile ?? 0; if (empty($mobile)) { util::complete('手机号无效'); } $hasApply = ApplyClass::getByCondition(['mobile' => $mobile]); if (!empty($hasApply)) { util::complete('已有申请'); } $hasShop = ShopClass::getByCondition(['mobile' => $mobile]); if (!empty($hasShop)) { util::complete('已经开店'); } $ptStyle = Yii::$app->params['ptStyle']; $adminName = $ljh->adminName ?? ''; $shopName = $ljh->name ?? ''; $miniOpenId = $post['miniOpenId'] ?? ''; $adminInfo = ['name' => $adminName, 'mobile' => $mobile, 'style' => $ptStyle, 'miniOpenId' => $miniOpenId]; $fromApp = dict::getDict('userSourceGetId', 'app', 'id'); $admin = AdminClass::replaceAdmin($adminInfo, $fromApp); $adminId = $admin['id'] ?? 0; $currentShopId = $admin['currentShopId'] ?? 0; if (!empty($currentShopId)) { util::complete('已经有开店了'); } if (isset($admin['openShop']) && $admin['openShop'] == 2) { util::complete('已经有申请了'); } $post['adminId'] = $adminId; $post['adminName'] = $adminName; $post['long'] = $ljh->long ?? ''; $post['lat'] = $ljh->lat ?? ''; $post['from'] = ApplyClass::FROM_RETAIL; $post['style'] = SjClass::STYLE_RETAIL; //增加或更新申请 $respond = ApplyService::replaceRetail($post); $id = $respond['id'] ?? 0; //提交申请资料失败 if (empty($id)) { util::complete('申请失败了'); } $passInfo = ApplyService::pass($id); $mobile = $post['mobile'] ?? ''; //输出登录信息 $newShop = $passInfo['shop'] ?? []; $newMainId = $newShop->mainId ?? 0; $newShopId = $newShop->id ?? 0; $pfShopId = $newShop->pfShopId ?? 0; $onlyCg = 1; //前端用于判断是否注册 $admin['currentShopId'] = $newShopId; $adminId = $admin['id']; $shopAdmin = ShopAdminService::getByCondition(['adminId' => $adminId, 'mainId' => $newMainId], true); if (empty($shopAdmin)) { util::fail('没有找到管理员'); } $shopAdmin->lastLogin = date("Y-m-d H:i:s"); $shopAdmin->save(); $shopAdminId = $shopAdmin->id ?? 0; //是否有切换门店的权限 $switchShop = \biz\shop\classes\ShopAdminClass::hasSwitchShopRight($shopAdmin); $showDemo = 1; $token = jwt::getNewToken($adminId); noticeUtil::push("花店 {$shopName} 手机号 {$mobile} 注册", '15280215347'); $apiHost = Yii::$app->params['hdHost']; $imgUploadApi = $apiHost . '/upload/save-file'; //涉及几个登录的地方,需要同步修改,请搜索关键词uni_login_info util::success([ 'token' => $token, 'admin' => $admin, 'shopId' => $currentShopId, 'shopAdminId' => $shopAdminId, 'switchShop' => $switchShop, 'pfShopId' => $pfShopId, 'onlyCg' => $onlyCg, 'showDemo' => $showDemo, 'imgUploadApi' => $imgUploadApi, 'staff' => $shopAdmin, 'newUser' => 1, ]); } }