// 处理返现促销 func (o *orderImpl) handleCashBackPromotion(pt merchant.IMerchant, m member.IMember, v *order.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 o._orderRep.SavePromotionBindForOrder(v) // 处理自定义返现 c := pm.(promotion.ICashBackPromotion) HandleCashBackDataTag(m, o._value, c, o._memberRep) //给自己返现 tit := fmt.Sprintf("返现¥%d元,订单号:%s", cpv.BackFee, o._value.OrderNo) err = acc.PresentBalance(tit, o.GetOrderNo(), float32(cpv.BackFee)) } return err }
// 获取促销 func (this *promotionService) GetPromotion(id int) (*promotion.PromotionInfo, interface{}) { var prom promotion.IPromotion = this._rep.GetPromotion(id) if prom != nil { return prom.GetValue(), prom.GetRelationValue() } return nil, nil }
// 绑定促销优惠 func (o *orderImpl) 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 := &order.OrderPromotionBind{ PromotionId: prom.GetAggregateRootId(), PromotionType: prom.Type(), OrderId: o.GetAggregateRootId(), Title: title, SaveFee: float32(fee), PresentIntegral: integral, IsConfirm: 1, IsApply: 0, } return o._orderRep.SavePromotionBindForOrder(v) }