Beispiel #1
0
func (this *merchantService) SaveMerchant(merchantId int, v *merchant.Merchant) (int, error) {
	var mch merchant.IMerchant
	var err error
	var isCreate bool

	v.Id = merchantId

	if merchantId > 0 {
		mch, _ = this._mchRep.GetMerchant(merchantId)
		if mch == nil {
			err = errors.New("no such partner")
		} else {
			err = mch.SetValue(v)
		}
	} else {
		isCreate = true
		mch, err = this._mchRep.CreateMerchant(v)
	}

	if err != nil {
		return 0, err
	}

	merchantId, err = mch.Save()

	if isCreate {
		this.initializeMerchant(merchantId)
	}

	return merchantId, err
}
Beispiel #2
0
// 三级返现
func (o *subOrderImpl) backFor3R(mch merchant.IMerchant, m member.IMember,
	back_fee float32, unixTime int64) (err error) {
	if back_fee > 0 {
		i := 0
		mName := m.Profile().GetProfile().Name
		saleConf := mch.ConfManager().GetSaleConf()
		percent := saleConf.CashBackTg2Percent
		for i < 2 {
			rl := m.GetRelation()
			if rl == nil || rl.RefereesId == 0 {
				break
			}

			m = o._memberRep.GetMember(rl.RefereesId)
			if m == nil {
				break
			}

			if i == 1 {
				percent = saleConf.CashBackTg1Percent
			}

			err = o.updateMemberAccount(m, mch.GetValue().Name, mName,
				back_fee*percent, unixTime)
			if err != nil {
				domain.HandleError(err, "domain")
				break
			}
			i++
		}
	}
	return err
}
Beispiel #3
0
func (this *profileManagerImpl) sendNotifyMail(pt merchant.IMerchant) error {
	tplId := pt.KvManager().GetInt(merchant.KeyMssTplIdOfProfileComplete)
	if tplId > 0 {
		mailTpl := this._member._mssRep.GetProvider().GetMailTemplate(tplId)
		if mailTpl != nil {
			v := &mss.Message{
				// 消息类型
				Type: notify.TypeEmailMessage,
				// 消息用途
				UseFor: mss.UseForNotify,
				// 发送人角色
				SenderRole: mss.RoleSystem,
				// 发送人编号
				SenderId: 0,
				// 发送的目标
				To: []mss.User{
					mss.User{
						Role: mss.RoleMember,
						Id:   this._memberId,
					},
				},
				// 发送的用户角色
				ToRole: -1,
				// 全系统接收
				AllUser: -1,
				// 是否只能阅读
				Readonly: 1,
			}
			val := &notify.MailMessage{
				Subject: mailTpl.Subject,
				Body:    mailTpl.Body,
			}
			msg := this._member._mssRep.MessageManager().CreateMessage(v, val)
			//todo:?? data
			var data = map[string]string{
				"Name":           this._profile.Name,
				"InvitationCode": this._member.GetValue().InvitationCode,
			}
			return msg.Send(data)
		}
	}
	return errors.New("no such email template")
}
Beispiel #4
0
// 更新返现到会员账户
func (o *orderImpl) updateShoppingMemberBackFee(pt merchant.IMerchant,
	m member.IMember, fee float32, unixTime int64) {
	if fee == 0 {
		return
	}
	v := o.GetValue()
	pv := pt.GetValue()

	//更新账户
	acc := m.GetAccount()
	acv := acc.GetValue()
	//acc.TotalFee += o._value.Fee
	//acc.TotalPay += o._value.PayFee
	acv.PresentBalance += fee // 更新赠送余额
	acv.TotalPresentFee += fee
	acv.UpdateTime = unixTime
	acc.Save()

	//给自己返现
	tit := fmt.Sprintf("订单:%s(商户:%s)返现¥%.2f元", v.OrderNo, pv.Name, fee)
	acc.PresentBalance(tit, v.OrderNo, float32(fee))
}