view; $view->params['site']= $this->site; $this->handleMallAccessCtrl(); return parent::beforeAction($action); } /** * @return string * @return string HTML */ public function actionIndex() { //获取当前用户的模型model $userId = $this->getUserId(); $engineer = new stdClass(); /** * 构造user的共用信息 */ $engineer = $this->buildUserResult($userId); return $this->render('index', [ 'engineer' => $engineer, ] ); } private function buildUserResult($userId) { $query = UserModel::find() ->select(['user.id', 'user.headimgurl','user.nickname']) ->where(['user.id' => $userId]); $query->asArray(); $engineerArray = $query->one(); if(empty($engineerArray)){ return false; } $engineer = new stdClass(); $engineer->id = (int)$engineerArray['id']; $engineer->headimgurl = $engineerArray['headimgurl']; $engineer->nickname = $engineerArray['nickname']; return $engineer; } /** * */ public function actionAjaxJweixin() { // 设置微信分享内容 $result = new stdClass(); $userId = $this->getUserId(); $baseUrl = $this->site->base_url; if (isset($_GET['from'])) { $url = $_GET['from']; } else { $url = $baseUrl; } $sign = WxHelper::getWxJSSDK()->getSignContext($url); $result->appid = $sign->appId; $result->timestamp = $sign->timestamp; $result->noncestr = $sign->nonceStr; $result->signature = $sign->signature; // 携带当前用户的邀请码参数,实现推荐用户功能 $sn = ''; $engineer = Engineer::findOne($userId); if ($engineer) { if (empty($engineer->invite_code)) { $engineer->invite_code = Engineer::createInviteCode($userId); $engineer->save(); } $sn = $engineer->invite_code; } $result->user_bridge_url = $baseUrl . '/wechat/bridging?sn=' . $sn . '&tourl=' . urlencode($url); $result->sn = $sn; if ($engineer) { $profile = EngineerProfile::findOne(['engineer_id' => $engineer->id]); $result->title = $this->wx->name; $result->icon = $profile->headimgurl; } else { $result->title = $this->wx->name; $result->icon = ''; } $result->desc = $this->wx->intro; return $this->renderJson($result); } /* * 错误页面 */ public function actionError() { $this->layout = '/error'; $exception = Yii::$app->errorHandler->exception; if ($exception && isset($exception->statusCode)) { $code = $exception->statusCode; } // $viewTpl = 'error/' . $code . '.php'; $viewTpl = 'error/404.php'; return $this->render($viewTpl); } /** 封号提示 * @return string */ public function actionBlock() { $this->layout = '/error'; $viewTpl = 'error/block.php'; $service_phone = SysSetting::getServicePhone(); return $this->render($viewTpl,['service_phone'=>$service_phone]); } /** 关注提示 * @return string */ public function actionSubscribe() { $this->layout = '/error'; $viewTpl = 'error/subscribe.php'; $service_phone = SysSetting::getServicePhone(); return $this->render($viewTpl,['service_phone'=>$service_phone]); } /** * 未授权提示 */ public function actionNoOauth() { $this->layout = '/error'; $viewTpl = 'error/block.php'; $id = $this->request->get('id'); $service_phone = SysSetting::getServicePhone(); $errorMsg = '当前没有权限查看该内容'; if ($id == 1) { $errorMsg = '请进行认证以后再来查看该页面'; } return $this->render($viewTpl,['service_phone'=>$service_phone, 'errorMsg' => $errorMsg]); } public function actionIndex2() { return $this->renderPartial('index2'); } }