Пример #1
0
// 注册会员
func (this *memberService) RegisterMember(merchantId int, v *member.Member,
	pro *member.Profile, cardId string, invitationCode string) (int, error) {
	invitationId, err := this._rep.GetManager().CheckPostedRegisterInfo(v, pro, invitationCode)
	if err == nil {
		m := this._rep.CreateMember(v) //创建会员
		id, err := m.Save()
		if err == nil {
			pro.MemberId = id
			if len(pro.Name) == 0 {
				//如果未设置昵称,则默认为用户名
				pro.Name = "用户" + v.Usr
			}
			if len(pro.Avatar) == 0 {
				pro.Avatar = "res/no_avatar.gif"
			}
			err = m.Profile().SaveProfile(pro)
			if err == nil {
				// 保存关联信息
				rl := m.GetRelation()
				rl.RefereesId = invitationId
				rl.RegisterMerchantId = merchantId
				rl.CardId = cardId
				return id, m.SaveRelation(rl)
			}
		}
	}
	return -1, err
}
Пример #2
0
// 获取资料或初始化
func (this *MemberRep) GetProfile(memberId int) *member.Profile {
	e := member.Profile{}
	orm := this.Connector.GetOrm()
	if orm.Get(memberId, &e) != nil {
		e.MemberId = memberId
		e.UpdateTime = time.Now().Unix()
		orm.Save(nil, &e)
	}
	return &e
}