Esempio n. 1
0
func setInfoHandler(request *http.Request, resp http.ResponseWriter, redis *models.RedisLogger,
	user *models.Account, p Parameter) {

	form := p.(setInfoForm)
	setinfo := &models.SetInfo{
		Phone:    form.UserInfo.Phone,
		Nickname: form.UserInfo.Nickname,
		Height:   form.UserInfo.Height,
		Weight:   form.UserInfo.Weight,
		Birth:    form.UserInfo.Birth,
		Gender:   form.UserInfo.Gender,

		Sign:        form.UserInfo.Sign,
		Emotion:     form.UserInfo.Emotion,
		Profession:  form.UserInfo.Profession,
		Hobby:       form.UserInfo.Hobby,
		Hometown:    form.UserInfo.Hometown,
		OftenAppear: form.UserInfo.OftenAppear,
		CoverImage:  form.UserInfo.CoverImage,

		Setinfo:    user.Setinfo,
		SetinfoAll: user.SetinfoAll,
	}

	addr := &models.Address{
		Country:  form.UserInfo.Country,
		Province: form.UserInfo.Province,
		City:     form.UserInfo.City,
		Area:     form.UserInfo.Area,
		Desc:     form.UserInfo.LocDesc,
	}
	if addr.String() != "" {
		setinfo.Address = addr
	}

	if len(setinfo.Phone) > 0 && setinfo.Phone != user.Phone {
		user.Phone = setinfo.Phone
		//setinfo.Setinfo = false
		if b, _ := user.Exists("phone"); b {
			writeResponse(request.RequestURI, resp, nil,
				errors.NewError(errors.UserExistError, "绑定失败,当前手机号已绑定"))
			return
		}
	}

	if len(setinfo.Nickname) > 0 && setinfo.Nickname != user.Nickname {
		u := &models.Account{}
		if find, _ := u.FindByNickname(setinfo.Nickname); find {
			writeResponse(request.RequestURI, resp, nil, errors.NewError(errors.UserExistError, "昵称已被占用"))
			return
		}
	}

	awards := Awards{}
	if !user.Setinfo || !user.SetinfoAll {
		ratio := calcInfo(user, setinfo)

		if ratio >= 80 && !user.Setinfo {
			setinfo.Setinfo = true
			awards.Wealth = 30 * models.Satoshi
			awards.Score = 30
		}
		if ratio == 100 && !user.SetinfoAll {
			setinfo.SetinfoAll = true
			awards.Wealth = 50 * models.Satoshi
			awards.Score = 50
		}
	}

	if err := user.SetInfo(setinfo); err != nil {
		writeResponse(request.RequestURI, resp, nil, err)
		return
	}

	GiveAwards(user, awards, redis)

	writeResponse(request.RequestURI, resp, map[string]interface{}{"ExpEffect": awards}, nil)

	user.UpdateAction(ActInfo, nowDate())
	//redis.SetOnlineUser(form.Token, user, false)
}