Example #1
0
func (this *configC) Profile_post(ctx *web.Context) {
	partnerId := this.GetPartnerId(ctx)
	r, w := ctx.Request, ctx.ResponseWriter
	var result gof.Message
	r.ParseForm()

	e := partner.ValuePartner{}
	web.ParseFormToEntity(r.Form, &e)

	//更新
	origin, _ := dps.PartnerService.GetPartner(partnerId)
	e.ExpiresTime = origin.ExpiresTime
	e.JoinTime = origin.JoinTime
	e.LastLoginTime = origin.LastLoginTime
	e.LoginTime = origin.LoginTime
	e.Pwd = origin.Pwd
	e.UpdateTime = time.Now().Unix()
	e.Id = partnerId

	id, err := dps.PartnerService.SavePartner(partnerId, &e)

	if err != nil {
		result.Message = err.Error()
	} else {
		result.Result = true
		result.Data = id
	}
	w.Write(result.Marshal())
}
Example #2
0
func (this *partnerService) SavePartner(partnerId int, v *partner.ValuePartner) (int, error) {
	var pt partner.IPartner
	var err error
	var isCreate bool

	v.Id = partnerId

	if partnerId > 0 {
		pt, _ = this._partnerRep.GetPartner(partnerId)
		if pt == nil {
			err = errors.New("no such partner")
		} else {
			err = pt.SetValue(v)
		}
	} else {
		isCreate = true
		pt, err = this._partnerRep.CreatePartner(v)
	}

	if err != nil {
		return 0, err
	}

	partnerId, err = pt.Save()

	if isCreate {
		this.initializePartner(partnerId)
	}

	return partnerId, err
}
Example #3
0
func (c *partnerC) CreatePartner_post(ctx *web.Context) {
	r, w := ctx.Request, ctx.ResponseWriter
	var result gof.Message
	var isCreate bool
	r.ParseForm()

	partner := partner.ValuePartner{}
	web.ParseFormToEntity(r.Form, &partner)

	dt := time.Now()
	anousPwd := strings.Repeat("*", 10) //匿名密码
	if len(partner.Pwd) != 0 && partner.Pwd != anousPwd {
		partner.Pwd = domain.Md5PartnerPwd(partner.Usr, partner.Pwd)
	}

	//更新
	if partner.Id > 0 {
		original, _ := dps.PartnerService.GetPartner(partner.Id)
		partner.JoinTime = original.JoinTime
		partner.ExpiresTime = original.ExpiresTime
		partner.UpdateTime = dt.Unix()

		if partner.Pwd == anousPwd {
			partner.Pwd = original.Pwd
		}
	} else {
		partner.JoinTime = dt.Unix()
		partner.ExpiresTime = dt.AddDate(10, 0, 0).Unix()
		partner.UpdateTime = dt.Unix()
		isCreate = true
	}

	id, err := dps.PartnerService.SavePartner(partner.Id, &partner)
	if err != nil {
		result.Message = err.Error()
	} else {
		result.Data = id
		result.Result = true
		if isCreate {
			// 初始化商户信息
			dps.PartnerService.InitDefaultLevels(id) // 初始化等级
			dps.SaleService.InitSaleTags(id)         // 初始化销售标签
		}
	}
	w.Write(result.Marshal())
}
Example #4
0
func (this *partnerService) SavePartner(partnerId int, v *partner.ValuePartner) (int, error) {
	var pt partner.IPartner
	var err error
	v.Id = partnerId

	if partnerId > 0 {
		pt, _ = this._partnerRep.GetPartner(partnerId)
		if pt == nil {
			err = errors.New("no such partner")
		} else {
			err = pt.SetValue(v)
		}
	} else {
		pt, err = this._partnerRep.CreatePartner(v)
	}

	if err != nil {
		return 0, err
	}

	return pt.Save()
}