Ejemplo n.º 1
0
 /**
  * 登录方法
  */
 public function actionDoLogin()
 {
     $this->layout = false;
     $util = new Util();
     $session = Yii::$app->session;
     $request = Yii::$app->getRequest();
     if (empty($_POST)) {
         return $this->redirect(['login/login']);
     }
     $post = Yii::$app->request->post();
     $username = $post['username'];
     $password = $post['password'];
     // 判断管理员是否存在
     $admin = new AdminBaseInfo();
     $id = $admin->login($username, $password);
     // id不存在
     if (is_array($id)) {
         return $this->render('login', ['error' => $id['error']]);
     }
     // 存放session
     $session[AdminBaseInfo::SESSION_KEY_ADMIN] = [AdminBaseInfo::ADMIN_BASE => 'admin', 'id' => $id, 'mobile' => $username];
     // 存放cookie
     $cookies = Yii::$app->response->cookies;
     $times = time() + 60 * 60 * 24;
     $admin = ['name' => AdminBaseInfo::ADMIN_BASE, 'value' => 'admin'];
     $id = ['name' => AdminBaseInfo::COOKIE_KEY_ID, 'value' => $id];
     $username = ['name' => AdminBaseInfo::COOKIE_KEY_NAME, 'value' => $username];
     $cookie = ['admin' => $admin, 'id' => $id, 'adminName' => $username];
     $util->cookie($cookie, $times);
     // $util->formatResData(0,'success');
     $this->layout = 'index';
     return $this->redirect(['login/index']);
 }
Ejemplo n.º 2
0
 public function actionProfile()
 {
     $mInvest = new InvestTendency();
     $params = Yii::$app->request->post();
     if (isset($params['currency'])) {
         $params['currency'] = intval($params['currency']);
     }
     if (isset($params['min_invest_quota']) || isset($params['max_invest_quota'])) {
         $params['min_invest_quota'] = intval($params['min_invest_quota']);
         $params['max_invest_quota'] = intval($params['max_invest_quota']);
         if ($params['min_invest_quota'] > $params['max_invest_quota']) {
             $tmp = $params['max_invest_quota'];
             $params['max_invest_quota'] = $params['min_invest_quota'];
             $params['min_invest_quota'] = $tmp;
         }
     }
     if (isset($params['invest_stage']) && is_array($params['invest_stage'])) {
         $params['invest_stage'] = array_sum($params['invest_stage']);
     }
     if (isset($params['uid']) && $params['uid']) {
         $invests = $mInvest->getByUid($params['uid']);
         //如果用户投资信息存在
         if ($invests) {
             $result = $mInvest->renew($params);
         } else {
             //如果投资信息不存在
             $result = $mInvest->add($params);
         }
     }
     if ($result) {
         return Util::setAlert('更新成功', 'user/profile');
     } else {
         return Util::setAlert('更新失败', 'user/profile');
     }
 }
Ejemplo n.º 3
0
 public function actionHave()
 {
     try {
         $request = Yii::$app->getRequest();
         $connection = Yii::$app->getDb();
         $authManager = Yii::$app->getAuthManager();
         $role = $request->post('role');
         // 根据名称获取角色/权限信息
         $sql = "SELECT child FROM " . $authManager->itemChildTable . " WHERE parent=:role";
         $command = $connection->createCommand($sql, [':role' => $role]);
         $child = $command->queryAll();
         if (empty($child)) {
             exit('不存在或已删除');
         }
         Util::formatResData(0, $child);
     } catch (\Exception $ex) {
         exit('System Error!!!');
     }
 }
Ejemplo n.º 4
0
<?php

use yii\helpers\Html;
use yii\helpers\Url;
use common\helpers\Util;
use common\models\user\UserBaseInfo;
use common\models\ApplicationBase;
$route = Yii::$app->util->getCurRoute();
$title = Util::getWebTitle($route);
if ($title) {
    $this->title = $title;
}
//获取session
$session = Yii::$app->session;
$sessionAvatar = $session[UserBaseInfo::SESSION_KEY_USER]['avatar'] ? $session[UserBaseInfo::SESSION_KEY_USER]['avatar'] : '';
$sessionName = $session[UserBaseInfo::SESSION_KEY_USER]['name'] ? $session[UserBaseInfo::SESSION_KEY_USER]['name'] : '';
//获取cookie
$cookies = Yii::$app->getRequest()->cookies;
$cookieAvatar = $cookies->getValue('avatar');
$avatar = $sessionAvatar ? $sessionAvatar : $cookieAvatar;
$cookieName = $cookies->getValue('username');
$avatar = $sessionAvatar ? $sessionAvatar : $cookieAvatar;
$name = $sessionName ? $sessionName : $cookieName;
$result = ApplicationBase::getApp(ApplicationBase::AUDITING_PASS_STATUS, ApplicationBase::TYPE_EXTERNAL, 6);
$this->beginPage();
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <?php 
Ejemplo n.º 5
0
 /**
  * 添加管理员
  */
 public function addAdmin()
 {
     try {
         $session = Yii::$app->getSession();
         $now = time();
         $ip = Yii::$app->util->getClientIP();
         $salt = random(6);
         if (!empty($_FILES[self::ADMIN_BASE_INFO]['name']['avatar'])) {
             $pathName = $this->upload('uploads/', $this);
             if (!$pathName) {
                 return ['error' => '图片格式不符'];
             }
         }
         // 手机号和密码不能为空
         if (empty($this->mobile) || empty($this->password)) {
             return ['error' => '手机号和密码不能为空'];
         }
         $util = new Util();
         // 判断手机格式
         if (!$util->regularMobile($this->mobile)) {
             return ['error' => '手机格式不符'];
         }
         // 判断密码格式
         if (!Yii::$app->util->regularPassword($this->password)) {
             return ['error' => '密码格式不符'];
         }
         // 判断邮箱格式
         if (!$util->regularEmail($this->email) && !empty($this->email)) {
             return ['error' => '邮箱格式不符'];
         }
         // 判断部门长度
         if (strlen($this->department) > 30) {
             return ['error' => '部门名称过长'];
         }
         // 判断管理员名格式
         if (!empty($this->adminname) && !Yii::$app->util->regularUserName($this->adminname)) {
             return ['error' => '管理员名格式不符'];
         }
         $this->gender ? $this->gender : ($this->gender = self::ADMIN_GENDER);
         $this->role_id ? $this->role_id : ($this->role_id = self::ADMIN_ROLE_ID);
         $this->status ? $this->status : ($this->status = self::ADMIN_NORMAL_STATUS);
         if (self::getAdminById($session[self::SESSION_KEY_ADMIN]['id'])['role_id'] != 0) {
             $this->role_id = self::getAdminById($session[self::SESSION_KEY_ADMIN]['id'])['role_id'];
         }
         $this->password = md5(md5($this->password) . $salt);
         $this->password_salt = $salt;
         $this->create_ip = $ip;
         $this->create_id = $session[self::SESSION_KEY_ADMIN]['id'];
         $this->create_time = $now;
         $this->update_time = $now;
         return $this->save() ? $this->id : ['error' => '系统错误,请稍后'];
     } catch (Exception $e) {
         return ['error' => '网络繁忙,请稍后'];
     }
 }
Ejemplo n.º 6
0
 public function actionDelete()
 {
     $mUser = new UserBaseInfo();
     $params = Yii::$app->request->get();
     $params = array_map('trim', $params);
     if (isset($params['city'])) {
         $params['city'] = 0;
         $params['city_addr'] = null;
     } else {
         if (isset($params['hometown'])) {
             $params['hometown'] = 0;
             $params['hometown_addr'] = null;
         }
     }
     //修改用户基本资料
     $result = $mUser->updateUserById($params);
     if ($result) {
         return Util::setAlert('删除成功', 'user/profile');
     } else {
         return Util::setAlert('删除失败', 'user/profile');
     }
 }
Ejemplo n.º 7
0
 /**
  * 更新并返回更新结果
  *
  * @param array $data 更新收货地址数据
  *              ~
  *              [
  *                  'id' => '主键ID', 'addressee' => '', 'mobile' => '',
  *                  'county' => '', 'address' => ''
  *              ]
  *              ~
  * @param \api\group\v1\models\Address $addressModel 收货地址model对象
  * @param \common\helpers\Util $util
  *
  * @return mixed
  */
 private function update($data, $addressModel, $util)
 {
     $addr = $addressModel->getAddrById($data['id'], Address::STATUS_ENABLE, false);
     if (!$addr) {
         return $util->responseArray(6104, 'address_notexists_disable', '收货地址不存在或已被删除');
     }
     $ret = $addressModel->updateAddr($addr, $data);
     if ($ret) {
         return $util->responseArray(0, 'success', '修改成功', ['id' => $data['id'], 'addressee' => $data['addressee'], 'mobile' => $data['mobile'], 'address' => $data['address']]);
     } else {
         return $util->responseArray(-1, 'system_busy', '系统繁忙,请稍后重试');
     }
 }
Ejemplo n.º 8
0
 /**
  * 删除用户地址信息
  */
 public function actionDelete($id)
 {
     //判断用户是否登录
     if (!UserBaseInfo::isLogin()) {
         return $this->redirect(Url::toRoute('user/login'));
     }
     $id = intval($id);
     if (!$id) {
         return Util::setAlert('地址id不存在', 'address/index');
     }
     //从session或cookie中获取用户id
     $userId = UserBaseInfo::getUserId();
     $address = new Address();
     $data = $address->getById($id);
     if (!$data) {
         return Util::setAlert('地址信息不存在', 'address/index');
     }
     if ($data['user_id'] != $userId) {
         return Util::setAlert('不能操作其他用户的地址信息', 'address/index');
     }
     $result = $address->del($id);
     $addressLog = new UserOperateLog();
     if ($result) {
         $data = $addressLog->store('用户地址删除', '', '{"id" : ' . $id . '}', $result);
         if (!$data) {
             FileLogger::getInstance(date('Ymd') . '_address_operate_fail.log')->writeOne($id, Logger::LEVEL_ERROR, 'add_log_fail');
         }
         return $this->redirect(Url::toRoute('address/index'));
     } else {
         $data = $addressLog->store('用户地址删除', '', '{"id" : ' . $id . '}', $result);
         if (!$data) {
             FileLogger::getInstance(date('Ymd') . '_address_operate_fail.log')->writeOne($id, Logger::LEVEL_ERROR, 'add_log_fail');
         }
         return Util::setAlert('删除失败', 'address/index');
     }
 }
Ejemplo n.º 9
0
 /**
  * 通过IP获取地址位置信息
  *
  * @param string $ip ip地址
  * @return array|null
  */
 public function getByIp($ip)
 {
     $address = null;
     if (!empty($ip)) {
         $util = new Util();
         //判断ip是否符合规则
         $isIp = $util->regularIp($ip);
         if (!$isIp) {
             return null;
         }
         $content = file_get_contents("http://ip.taobao.com/service/getIpInfo.php?ip=" . $ip);
         $data = json_decode($content);
         $country = $data->data->country;
         $region = $data->data->region;
         $city = $data->data->city;
         $address = $country . $region . $city;
     }
     return $address;
 }
Ejemplo n.º 10
0
 /**
  * Updates an existing UserBaseInfo model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $this->layout = 'index';
     $model = $this->findModel($id);
     $session = Yii::$app->getSession();
     if ($model->load(Yii::$app->request->post())) {
         // 判断手机号格式
         $util = new Util();
         // if (!$util->regularMobile($model->mobile)) {
         //     return $this->render('update', [
         //         'model' => $model,
         //         'error' => '手机号格式不正确',
         //     ]);
         // }
         // 判断邮箱格式
         if (!$util->regularEmail($model->email) && !empty($model->email)) {
             return $this->render('update', ['model' => $model, 'error' => '邮箱格式不正确']);
         }
         if (strlen($model->company) > 50) {
             return $this->render('update', ['model' => $model, 'error' => '公司名称过长']);
         }
         if (strlen($model->position) > 90) {
             return $this->render('update', ['model' => $model, 'error' => '就任职位名过长']);
         }
         // if (!empty($model->username) && !Yii::$app->util->regularUserName($model->username)) {
         //     return $this->render('update', [
         //         'model' => $model,
         //         'error' => '用户名格式不符',
         //     ]);
         // }
         $model->update_time = time();
         // 上传图片
         if (!empty($_FILES[UserBaseInfo::USER_BASE_INFO]['name']['avatar'])) {
             $types = ['jpg', 'png', 'gif'];
             $adminPath = "uploads/";
             // 图片储存路径
             $avatar = UploadedFile::getInstance($model, 'avatar');
             $ext = $avatar->getExtension();
             if (!in_array($ext, $types)) {
                 return $this->render('update', ['model' => $model, 'error' => '上传图片格式不符']);
             }
             $adminName = time() . rand(1000, 9999) . "." . $ext;
             $path = abs(crc32($model->mobile) % 500);
             // 多项式加密取绝对值
             $adminPath .= $path . "/";
             if (!file_exists($adminPath)) {
                 mkdir($adminPath, 0777, true);
             }
             $avatar->saveAs($adminPath . $adminName);
             $model->avatar = $adminPath . $adminName;
         } else {
             unset($model->avatar);
         }
         if (empty($model->gender)) {
             $model->gender = UserBaseInfo::USER_GENDER_CONFIDENTIAL;
         }
         if ($model->save()) {
             return $this->redirect(['view', 'id' => $model->id]);
         } else {
             return $this->render('update', ['model' => $model, 'error' => '网络繁忙,操作数据失败请稍后']);
         }
     } else {
         return $this->render('update', ['model' => $model]);
     }
 }