public function beforeAction($action) { if ($action->actionMethod == 'actionWxNotify') { $action->controller->enableCsrfValidation = false; } $alipay = Yii::$app->alipay; $wxpay = Yii::$app->wxpay; $request = Yii::$app->getRequest(); $get = $request->get(); $appId = isset($get['app_id']) && $get['app_id'] ? $get['app_id'] : '100002'; if (!$appId) { // app_id 为必须参数 die('app_id required'); } $sso = new SsoSettingInfo(); $mch = $sso->getMchByAppid($appId); $mch = json_decode($mch['mch_info'], true); if (arr_null($mch)) { // TODO:: 应用sso配置中没有设置商户信息 die('mch information required'); } $wxpayi = $mch['wxpay']; $alipayi = $mch['alipay']; WxPayConfig::$appId = $wxpayi['app_id']; WxPayConfig::$appSecret = $wxpayi['app_secret']; WxPayConfig::$mchId = $wxpayi['mch_id']; WxPayConfig::$key = $wxpayi['key']; WxPayConfig::$sslcert_path = $wxpayi['sslcert_path']; WxPayConfig::$sslkey_path = $wxpayi['sslkey_path']; $alipay->sellerEmail = $alipayi['seller_email']; $alipay->partner = $alipayi['partner']; $alipay->key = $alipayi['key']; $login = UserBaseInfo::isLogin(); if ($login) { return parent::beforeAction($action); } return $this->redirect(['user/login']); }
</li> <?php } ?> </ul> </li> <!-- 这个别删啊,未登录嵌套这个li --> <!-- <li class="prelogin"> <a href="">登录</a> </li> --> <li class="news" style='display:none'> <span class="news-num">3</span> </li> <li class="portrait"> <?php if (UserBaseInfo::isLogin()) { ?> <?php if (empty($avatar)) { ?> <img src="<?php echo Yii::$app->params['res']; ?> /images/avatar.png" alt="<?php echo $name; ?> "> <?php } else { ?> <img width='48px' height='48px' src="<?php
/** * 获取订单列表信息 */ public function actionList() { $this->layout = 'main'; //判断用户是否登录 if (!UserBaseInfo::isLogin()) { return $this->redirect(Url::toRoute('user/login')); } //从session或cookie中获取open_id $openId = UserBaseInfo::getOpenId(); $data['open_id'] = $openId; $data['status'] = Order::ORDER_USABLE_STATUS; $params = Yii::$app->request->get(); $startTime = false; $endTime = false; $time = Yii::$app->util->loadConfig('user-order-time', '/platform_i/config/'); if ($params) { if (isset($params['startTime']) && isset($params['endTime'])) { $data['startTime'] = strtotime($params['startTime'] . ' 00:00:00'); $data['endTime'] = strtotime($params['endTime'] . ' 23:59:59'); $checkTime = $this->checkTime($params['startTime'], $params['endTime']); if ($checkTime['startTime'] && $checkTime['endTime']) { $data['startTime'] = strtotime($checkTime['startTime'] . ' 00:00:00'); $data['endTime'] = strtotime($checkTime['endTime'] . '23:59:59'); $params['startTime'] = $checkTime['startTime']; $params['endTime'] = $checkTime['endTime']; } if ($data['startTime'] > $data['endTime']) { $tmpParam = $params['startTime']; $params['startTime'] = $params['endTime']; $params['endTime'] = $tmpParam; $tmpData = $data['startTime']; $data['startTime'] = $data['endTime']; $data['endTime'] = $tmpData; } $timeInterval = $params['startTime'] . '_' . $params['endTime']; foreach ($time as $key => &$value) { if ($timeInterval == $value['timeInterval']) { $value['class'] = true; } } } else { if (isset($params['timeRange'])) { if (in_array($params['timeRange'], array_keys($time))) { $time[$params['timeRange']]['class'] = true; } else { $time[1]['class'] = true; } } else { //默认为今天 $time[1]['class'] = true; $params['timeRange'] = 1; } $data['endTime'] = strtotime(date('Y-m-d 23:59:59')); $data['startTime'] = $this->getTime($params['timeRange']); } if (isset($params['payStatus'])) { if ($params['payStatus'] != 0 && $params['payStatus'] != 1 && $params['payStatus'] != 5) { unset($params['payStatus']); } else { $data['pay_status'] = $params['payStatus']; } } } else { $params['timeRange'] = 1; $data['endTime'] = strtotime(date('Y-m-d 23:59:59')); $data['startTime'] = $this->getTime($params['timeRange']); $time[1]['class'] = true; } $result = Order::getData($data, $startTime, $endTime); $pages = new Pagination(['totalCount' => $result->count(), 'pageSize' => '10']); $result = $result->offset($pages->offset)->limit($pages->limit)->asArray()->all(); //从缓存中取出应用配置信息 $appConfig = AppConfig::getConfigUrl(); if (is_array($appConfig)) { foreach ($result as $key => &$value) { $value['config_urls'] = $appConfig[$value['app_id']]; } } return $this->render('list', ['result' => $result, 'pages' => $pages, 'time' => $time]); }
public function beforeAction($action) { $this->isLogin = UserBaseInfo::isLogin(); parent::beforeAction($action); return true; }
/** * 用户地址接口 */ public function actionInfo($id) { $util = Yii::$app->util; $request = Yii::$app->getRequest(); $params = Yii::$app->request->get(); //判断用户是否登录 if (!UserBaseInfo::isLogin()) { $util->formatResData(1202, 'please_login', ['msg' => '请你登录']); } $id = intval($id); //判断参数的是否为空 if (!$id) { $util->formatResData(1101, 'address_param_missing', ['msg' => '地址信息参数缺失']); } //判断是否是Ajax请求 if (!$request->getIsAjax($id)) { $util->formatResData(1301, 'illegal_request', ['msg' => '非法请求']); } $address = new Address(); $data = $address->getByUserId($id); //通过地址ID获取对应的地址信息 $data = $address->getById($id); if (!$data) { $util->formatResData(1102, 'id_not_exists', ['msg' => 'ID信息不存在']); } //从session或cookie中获取用户id $userId = UserBaseInfo::getUserId(); if ($data['user_id'] != $userId) { $util->formatResData(1103, 'can_not_operate_other\'s_order_message', ['msg' => '不能操作其他人的订单信息']); } if (!$data['post_code']) { unset($data['post_code']); } //根据子区域id获取区域信息 $region = District::getById($data['county'], true); if (!$region) { $util->formatResData(1104, 'region_message_not_exists', ['msg' => '该子区域ID对应的区域信息不存在']); } $result = ['city' => $region['upid'], 'province' => $region['parent']['upid']]; $result = array_merge($data, $result); if ($result) { $util->formatResData(0, 'success', $result); } else { $util->formatResData(1201, 'get_address_fail', ['msg' => '获取地区信息失败']); } }
<?php $this->beginBody(); ?> <header> <div class="top"> <a href="<?php echo Url::toRoute('ucenter/index'); ?> "> <img src="<?php echo Yii::$app->params['res']; ?> /images/logo-chuangyejia.png" width="90" height="48"> </a> <?php $result = UserBaseInfo::isLogin(); if ($result) { ?> <a href="<?php echo Url::toRoute('user/logout'); ?> " style ="margin-left:15px" class="log-out ajax-logout">退出</a> <?php } else { ?> <a href="<?php echo Url::toRoute('user/login'); ?> " style ="margin-left:15px" class="log-out">登录</a> <a href="<?php echo Url::toRoute('user/register');