Esempio n. 1
0
File: order.go Progetto: zoe527/go2o
// 处理返现促销
func (this *Order) handleCashBackPromotion(pt partner.IPartner, m member.IMember,
	v *shopping.OrderPromotionBind, pm promotion.IPromotion) error {
	cpv := pm.GetRelationValue().(*promotion.ValueCashBack)

	//更新账户
	bFee := float32(cpv.BackFee)
	acc := m.GetAccount()
	acv := acc.GetValue()
	acv.PresentBalance += bFee // 更新赠送余额
	acv.TotalPresentFee += bFee
	// 赠送金额,不应该计入到余额,可采取充值到余额
	//acc.Balance += float32(cpv.BackFee)                            // 更新账户余额

	acv.UpdateTime = time.Now().Unix()
	_, err := acc.Save()

	if err == nil {
		// 优惠绑定生效
		v.IsApply = 1
		this._shoppingRep.SavePromotionBindForOrder(v)

		// 处理自定义返现
		c := pm.(promotion.ICashBackPromotion)
		HandleCashBackDataTag(m, this._value, c, this._memberRep)

		//给自己返现
		tit := fmt.Sprintf("返现¥%d元,订单号:%s", cpv.BackFee, this._value.OrderNo)
		err = acc.PresentBalance(tit, v.OrderNo, float32(cpv.BackFee))
	}
	return err
}
Esempio n. 2
0
// 获取促销
func (this *promotionService) GetPromotion(id int) (*promotion.ValuePromotion, interface{}) {
	var prom promotion.IPromotion = this._rep.GetPromotion(id)
	if prom != nil {
		return prom.GetValue(), prom.GetRelationValue()
	}
	return nil, nil
}
Esempio n. 3
0
// 处理返现促销
func (this *Order) handleCashBackPromotion(pt partner.IPartner, m member.IMember,
	v *shopping.OrderPromotionBind, pm promotion.IPromotion) error {
	cpv := pm.GetRelationValue().(*promotion.ValueCashBack)

	//更新账户
	acc := m.GetAccount()
	acc.PresentBalance = acc.PresentBalance + float32(cpv.BackFee) // 更新赠送余额
	acc.Balance += float32(cpv.BackFee)                            // 更新账户余额
	acc.UpdateTime = time.Now().Unix()
	err := m.SaveAccount()

	if err == nil {
		// 优惠绑定生效
		v.IsApply = 1
		this._shoppingRep.SavePromotionBindForOrder(v)

		// 处理自定义返现
		c := pm.(promotion.ICashBackPromotion)
		HandleCashBackDataTag(m, this._value, c, this._memberRep)

		//给自己返现
		icLog := &member.IncomeLog{
			MemberId:   this._value.MemberId,
			OrderId:    this.GetDomainId(),
			Type:       "backcash",
			Fee:        float32(cpv.BackFee),
			Log:        fmt.Sprintf("返现¥%d元,订单号:%s", cpv.BackFee, this._value.OrderNo),
			State:      1,
			RecordTime: acc.UpdateTime,
		}
		err = m.SaveIncomeLog(icLog)
	}
	return err
}
Esempio n. 4
0
// 保存促销
func (this *promotionService) SavePromotion(v *promotion.ValuePromotion) (int, error) {
	var prom promotion.IPromotion
	if v.Id > 0 {
		prom = this._newRep.GetPromotion(v.Id)
		prom.SetValue(v)
	} else {
		prom = this._newRep.CreatePromotion(v)
	}
	return prom.Save()
}
Esempio n. 5
0
// 保存促销
func (this *promotionService) SavePromotion(v *promotion.ValuePromotion) (int, error) {
	var prom promotion.IPromotion
	if v.Id > 0 {
		prom = this._rep.GetPromotion(v.Id)
		err := prom.SetValue(v)
		if err != nil {
			return v.Id, err
		}
	} else {
		prom = this._rep.CreatePromotion(v)
	}
	return prom.Save()
}
Esempio n. 6
0
func DeletePromotion(p promotion.IPromotion) error {
	var err error
	var rep promotion.IPromotionRep = nil
	if p.Type() == promotion.TypeFlagCashBack {
		v := p.(*CashBackPromotion)
		rep = v._promRep
		err = rep.DeleteValueCashBack(v.GetAggregateRootId())
	} else if p.Type() == promotion.TypeFlagCoupon {
		v := p.(*Coupon)
		rep = v._promRep
		err = rep.DeleteValueCoupon(v.GetAggregateRootId())
	}
	if err == nil && rep != nil {
		err = rep.DeletePromotion(p.GetAggregateRootId())
	}
	return err
}
Esempio n. 7
0
func (this *promotionService) SaveCashBackPromotion(partnerId int, v *promotion.ValuePromotion,
	v1 *promotion.ValueCashBack) (int, error) {
	var prom promotion.IPromotion
	if v.Id > 0 {
		prom = this._newRep.GetPromotion(v.Id)
		if prom.GetValue().PartnerId != partnerId {
			return -1, partner.ErrNotMatch
		}
		prom.SetValue(v)
	} else {
		prom = this._newRep.CreatePromotion(v)
	}

	cb := prom.(promotion.ICashBackPromotion)

	if err := cb.SetDetailsValue(v1); err != nil {
		return v.Id, err
	}

	return prom.Save()
}
Esempio n. 8
0
/**************   Coupon ************/
func (this *promotionService) SaveCoupon(partnerId int, v *promotion.ValuePromotion, v1 *promotion.ValueCoupon) (int, error) {
	var prom promotion.IPromotion
	var err error
	if v.Id > 0 {
		prom = this._rep.GetPromotion(v.Id)
		if prom.GetValue().PartnerId != partnerId {
			return -1, partner.ErrNotMatch
		}
	} else {
		prom = this._rep.CreatePromotion(v)
	}

	if err = prom.SetValue(v); err == nil {
		cb := prom.(promotion.ICouponPromotion)
		err = cb.SetDetailsValue(v1)
	}

	if err != nil {
		return v.Id, err
	}

	return prom.Save()
}
Esempio n. 9
0
func (this *Order) bindPromotionOnSubmit(orderNo string, prom promotion.IPromotion) (int, error) {
	var title string
	var integral int
	var fee int

	//todo: 需要重构,其他促销
	if prom.Type() == promotion.TypeFlagCashBack {
		fee = prom.GetRelationValue().(*promotion.ValueCashBack).BackFee
		title = prom.TypeName() + ":" + prom.GetValue().ShortName
	}

	v := &shopping.OrderPromotionBind{
		PromotionId:     prom.GetAggregateRootId(),
		PromotionType:   prom.Type(),
		OrderNo:         orderNo,
		Title:           title,
		SaveFee:         float32(fee),
		PresentIntegral: integral,
		IsConfirm:       1,
		IsApply:         0,
	}
	return this._shoppingRep.SavePromotionBindForOrder(v)
}