/**
  * 修改用户地址信息
  */
 public function actionUpdate()
 {
     $util = Yii::$app->util;
     $request = Yii::$app->getRequest();
     $params = Yii::$app->request->post();
     //判断用户是否登录
     if (!UserBaseInfo::isLogin()) {
         $util->formatResData(1202, 'please_login', ['redirect' => Url::toRoute('user/login')]);
     }
     //判断是否是Ajax请求
     if (!$request->getIsAjax($params)) {
         $util->formatResData(1301, 'illegal_request', ['msg' => '非法请求']);
     }
     if (!isset($params['id'])) {
         $util->formatResData(1101, 'addressid_not_empty', ['msg' => '地址ID不能为空']);
     }
     $id = intval($params['id']);
     $address = new Address();
     $result = $address->getById($id);
     if (!$result) {
         $util->formatResData(1102, 'address_message_not_exist', ['msg' => '地址信息不存在']);
     }
     //从session或cookie中获取用户id
     $userId = UserBaseInfo::getUserId();
     if ($result['user_id'] != $userId) {
         $util->formatResData(1103, 'can_not_operate_other\'s_order_message', ['msg' => '不能操作其他人的地址信息']);
     }
     $data['id'] = $id;
     $params['addressee'] = strip_tags(trim($params['addressee']));
     if (!$params['addressee']) {
         $util->formatResData(1104, 'name_not_empty', ['msg' => '姓名不能为空']);
     }
     $length = mb_strlen($params['addressee'], 'utf8');
     if ($length > 10) {
         $util->formatResData(1105, 'name_over_specified_length', ['msg' => '名字长度不能超过10']);
     }
     $data['addressee'] = $params['addressee'];
     if (!$params['mobile']) {
         $util->formatResData(1106, 'mobile_not_empty', ['msg' => '手机号码不能为空']);
     }
     $mobile = Yii::$app->util->regularMobile($params['mobile']);
     if (!$mobile) {
         $util->formatResData(1107, 'mobile_format_illegal', ['msg' => '手机号码格式非法']);
     }
     $data['mobile'] = $params['mobile'];
     if (!$params['province']) {
         $util->formatResData(1108, 'province_message_not_exists', ['msg' => '请选择省']);
     }
     if (!$params['city']) {
         $util->formatResData(1109, 'city_message_not_exists', ['msg' => '请选择市']);
     }
     if (!$params['county']) {
         $util->formatResData(1110, 'county_message_not_exists', ['msg' => '请选择区/县']);
     }
     $region = District::getById($params['county'], true);
     if (!$region) {
         $util->formatResData(1111, 'region_message_not_exists', ['msg' => '区域信息不存在']);
     }
     if ($region['level'] != 3) {
         $util->formatResData(1112, 'region_message_not_exists', ['msg' => '不属于区/县']);
     }
     $data['county'] = $params['county'];
     $params['countyName'] = $region['name'];
     $params['cityName'] = $region['parent']['name'];
     $params['provinceName'] = District::getById($region['parent']['upid'])['name'];
     $params['address'] = strip_tags(trim($params['address']));
     if (!$params['address']) {
         $util->formatResData(1113, 'address_not_empty', ['msg' => '地址不能为空']);
     }
     $length = mb_strlen($params['address'], 'utf8');
     if ($length > 30) {
         $util->formatResData(1114, 'address_over_specified_length', ['msg' => '地址长度不能超过30']);
     }
     if ($result['county'] == $params['county']) {
         $data['address'] = $params['address'];
     } else {
         $data['address'] = $params['provinceName'] . $params['cityName'] . $params['countyName'] . ' ' . $params['address'];
         $params['address'] = $params['provinceName'] . $params['cityName'] . $params['countyName'] . ' ' . $params['address'];
     }
     $data['user_id'] = $userId;
     if (isset($params['post_code'])) {
         $postCode = YII::$app->util->regularPostCode($params['post_code']);
         if (!$postCode) {
             $util->formatResData(1115, 'postcode_illegal', ['msg' => '邮政编码非法']);
         }
         $data['post_code'] = $params['post_code'];
     } else {
         unset($params['post_code']);
     }
     $result = $address->renew($data);
     $addressLog = new UserOperateLog();
     if ($result) {
         $data = json_encode($data);
         $data = $addressLog->store('用户地址修改', '', $data, $result);
         if (!$data) {
             FileLogger::getInstance(date('Ymd') . '_address_operate_fail.log')->writeOne($id, Logger::LEVEL_ERROR, 'add_log_fail');
         }
         $util->formatResData(0, 'success', $params);
     } else {
         $data = $addressLog->index($userId, 'update-yes', json_encode($data));
         $data = $addressLog->store('用户地址修改', '', $data, $result);
         if (!$data) {
             FileLogger::getInstance(date('Ymd') . '_address_operate_fail.log')->writeOne($id, Logger::LEVEL_ERROR, 'add_log_fail');
         }
         $util->formatResData(1201, 'update_fail', ['msg' => '修改失败']);
     }
 }
Example #2
0
 protected function profileLog($user, $params)
 {
     $data = array_diff($user, $params);
     unset($data['name']);
     $oriData = [];
     $newData = [];
     if (!array_key_exists('avatar', $params)) {
         unset($data['avatar']);
     }
     foreach ($data as $key => $value) {
         $oriData[$key] = $user[$key];
         $newData[$key] = $params[$key];
     }
     $oriData = json_encode($oriData);
     $newData = json_encode($newData);
     $log = new UserOperateLog();
     $logs = $log->store('用户个人信息修改', $oriData, $newData, true);
 }
Example #3
0
 public function modifyEmail($params = array())
 {
     $email = isset($params['mobile']) && $params['mobile'] ? $params['mobile'] : '';
     $id = isset($params['id']) && $params['id'] ? $params['id'] : 0;
     if ($id && $email) {
         $mUserOpLog = new UserOperateLog();
         $mUser = new UserBaseInfo();
         $preg = '/^([a-zA-Z0-9_\\.\\-])+\\@(([a-zA-Z0-9\\-])+\\.)+([a-zA-Z]{2,5})$/';
         if (!preg_match($preg, $email)) {
             Yii::$app->util->formatResData(1107, '', ['msg' => '邮箱格式有误']);
         }
         $data = ['id' => $id, 'email' => $email];
         $user = $mUser->getUserById($id);
         $result = $mUser->updateUserById($data);
         $opMsg = empty($user['email']) ? '安全邮箱绑定' : '安全邮箱修改';
         $mUserOpLog->store($opMsg, $user['email'], $email, $result);
         if (!$result) {
             Yii::$app->util->formatResData(1302, 'error_update_email', ['msg' => '更新邮箱失败']);
         }
         $data = ['open_id' => $user['open_id'], 'email' => $email];
         // 针对SSO用户同步相关信息
         try {
             $sso = Yii::$app->sso;
             $res = $sso->sync('email', $data);
             $sso->syncProfileLog($res, json_encode($data), 'email');
         } catch (\Exception $e) {
         }
     }
 }