Example #1
0
 /**
  * 同步个人信息
  *
  * @param array $data 变更数据
  *  $data中必须包含为id的Key
  * @return boolean
  */
 protected function syncProfile($data)
 {
     $res = false;
     $mUser = new UserBaseInfo();
     $uid = isset($data['id']) && $data['id'] ? $data['id'] : false;
     if (!$uid) {
         return $uid;
     }
     unset($data['id']);
     $user = $mUser->getUserById($uid);
     if ($user) {
         $industry = Yii::$app->util->loadConfig('user-industry', '/platform_i/config/');
         $user = array_merge($user, $data);
         // 设置默认同步数据
         $data = ['open_id' => $user['open_id'], 'name' => $user['username'], 'password' => $user['password'], 'salt' => $user['password_salt'], 'birthday' => $user['birthday'], 'city' => $user['city'], 'industry' => $user['industry'], 'company' => $user['company'], 'position' => $user['position'], 'dc_avatar' => $user['avatar']];
         // $data = array_merge($defData, $data);
         $data['industry'] = !$industry || !$data['industry'] || !isset($industry[$data['industry']]) ? '' : $industry[$data['industry']];
         $data['user_trade'] = $data['industry'];
         $data['job'] = $data['position'];
         unset($data['industry']);
         unset($data['position']);
         $mDistrict = new District();
         $city = $mDistrict->getByCity($data['city']);
         $data['city'] = (!isset($city['parent']) ? '' : $city['parent']['name']) . ' ' . $city['name'];
         try {
             $sso = Yii::$app->sso;
             $res = $sso->sync('profile', $data);
             $sso->syncProfileLog($res, json_encode($data), 'profile');
         } catch (\Exception $e) {
         }
         // TODO: 针对同步结果进行相关操作
         if ($res) {
         } else {
         }
     }
     return $res;
 }