// 三级返现 func (this *Order) backFor3R(pt partner.IPartner, m member.IMember, back_fee float32, unixTime int64) { if back_fee == 0 { return } i := 0 mName := m.GetValue().Name saleConf := pt.GetSaleConf() percent := saleConf.CashBackTg2Percent for i < 2 { rl := m.GetRelation() if rl == nil || rl.InvitationMemberId == 0 { break } m = this._memberRep.GetMember(rl.InvitationMemberId) if m == nil { break } if i == 1 { percent = saleConf.CashBackTg1Percent } this.updateMemberAccount(m, pt.GetValue().Name, mName, back_fee*percent, unixTime) i++ } }
// 是否可用 func (this *Coupon) CanUse(m member.IMember, fee float32) (bool, error) { mv := m.GetValue() cv := this.GetValue() if cv.AllowEnable == 0 { return false, errors.New("无效的优惠券") } dtUnix := time.Now().Unix() stUnix := cv.BeginTime ovUnix := cv.OverTime if dtUnix < stUnix { return false, errors.New(fmt.Sprintf("优惠券必须在%s~%s使用", time.Unix(cv.BeginTime, 0).Format("2006-01-02"), time.Unix(cv.OverTime, 0).Format("2006-01-02")), ) } else if dtUnix > ovUnix { return false, errors.New("优惠拳已过期") } if cv.NeedBind == 0 && cv.Amount == 0 { return false, errors.New("优惠券不足") } if mv.Level < cv.MinLevel { return false, errors.New("会员等级不满足要求") } if fee < float32(cv.MinFee) { return false, errors.New(fmt.Sprintf("订单金额需达到¥%d", cv.MinFee)) } return true, nil }
// 处理返现促销 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 }
func (this *Order) updateMemberAccount(m member.IMember, ptName, mName string, fee float32, unixTime int64) { if fee == 0 { return } //更新账户 acc := m.GetAccount() acv := acc.GetValue() acv.PresentBalance += fee acv.TotalPresentFee += fee acv.UpdateTime = unixTime acc.Save() //给自己返现 icLog := &member.IncomeLog{ MemberId: this._value.MemberId, Type: "backcash", Fee: fee, Log: fmt.Sprintf("订单:%s(商家:%s,会员:%s)收入¥%.2f元", this._value.OrderNo, ptName, mName, fee), State: 1, RecordTime: unixTime, } m.SaveIncomeLog(icLog) }
// 更新返现到会员账户 func (this *Order) updateShoppingMemberBackFee(pt partner.IPartner, m member.IMember, fee float32, unixTime int64) { if fee == 0 { return } v := this.GetValue() pv := pt.GetValue() //更新账户 acc := m.GetAccount() acv := acc.GetValue() //acc.TotalFee += this._value.Fee //acc.TotalPay += this._value.PayFee acv.PresentBalance += fee // 更新赠送余额 acv.TotalPresentFee += fee acv.UpdateTime = unixTime acc.Save() //给自己返现 icLog := &member.IncomeLog{ MemberId: this._value.MemberId, OrderId: v.Id, Type: "backcash", Fee: fee, Log: fmt.Sprintf("订单:%s(商家:%s)返现¥%.2f元", v.OrderNo, pv.Name, fee), State: 1, RecordTime: unixTime, } m.SaveIncomeLog(icLog) }
// 更新账户 func updateAccountForOrder(m member.IMember, order shopping.IOrder) { acc := m.GetAccount() ov := order.GetValue() acc.TotalFee += ov.Fee acc.TotalPay += ov.PayFee acc.UpdateTime = time.Now().Unix() m.SaveAccount() }
func cashBack3R(m member.IMember, order *shopping.ValueOrder, c promotion.ICashBackPromotion, memberRep member.IMemberRep) { var fee1 int var fee2 int dt := c.GetDataTag() fee1, _ = strconv.Atoi(dt["G1"]) fee2, _ = strconv.Atoi(dt["G2"]) var cm member.IMember = m var pm member.IMember = m // fmt.Println("------ START BACK ------") var backFunc = func(m member.IMember, parentM member.IMember, fee int) { // fmt.Println("---------[ back ]",parentM.GetValue().Name,fee) backCashForMember(m, order, fee, parentM.GetValue().Name) } var i int = 0 for true { rl := cm.GetRelation() // fmt.Println("-------- BACK - ID - ",rl.InvitationMemberId) if rl == nil || rl.InvitationMemberId == 0 { break } cm = memberRep.GetMember(rl.InvitationMemberId) // fmt.Println("-------- BACK ",cm == nil) if m == nil { break } if i == 0 { backFunc(cm, pm, fee2) } else if i == 1 { backFunc(cm, pm, fee1) } pm = cm i++ if i > 1 { break } } }
// 获取结算数据 func (this *Cart) GetSettleData() (s partner.IShop, d member.IDeliver, paymentOpt, deliverOpt int) { var err error if this.value.ShopId > 0 && this._shop == nil { var pt partner.IPartner pt, err = this.partnerRep.GetPartner(this.partnerId) if err == nil { this._shop = pt.GetShop(this.value.ShopId) } } if this.value.DeliverId > 0 && this._deliver == nil { var m member.IMember m, err = this.memberRep.GetMember(this.value.BuyerId) if err == nil { this._deliver = m.GetDeliver(this.value.DeliverId) } } return this._shop, this._deliver, this.value.PaymentOpt, this.value.DeliverOpt }
func backCashForMember(m member.IMember, order *shopping.ValueOrder, fee int, refName string) error { //更新账户 acc := m.GetAccount() acv := acc.GetValue() bFee := float32(fee) acv.PresentBalance += bFee // 更新赠送余额 acv.TotalPresentFee += bFee acv.UpdateTime = time.Now().Unix() _, err := acc.Save() if err == nil { tit := fmt.Sprintf("推广返现¥%s元,订单号:%s,来源:%s", format.FormatFloat(bFee), order.OrderNo, refName) err = acc.PresentBalance(tit, order.OrderNo, float32(fee)) } return err }
func (this *Order) updateMemberAccount(m member.IMember, ptName, mName string, fee float32, unixTime int64) { if fee == 0 { return } //更新账户 acc := m.GetAccount() acv := acc.GetValue() acv.PresentBalance += fee acv.TotalPresentFee += fee acv.UpdateTime = unixTime acc.Save() //给自己返现 tit := fmt.Sprintf("订单:%s(商家:%s,会员:%s)收入¥%.2f元", this._value.OrderNo, ptName, mName, fee) acc.PresentBalance(tit, this._value.OrderNo, fee) }
func cashBack3R(level int, m member.IMember, order *shopping.ValueOrder, c promotion.ICashBackPromotion, memberRep member.IMemberRep) { dt := c.GetDataTag() var cm member.IMember = m var pm member.IMember = m // fmt.Println("------ START BACK ------") var backFunc = func(m member.IMember, parentM member.IMember, fee int) { // fmt.Println("---------[ back ]",parentM.GetValue().Name,fee) backCashForMember(m, order, fee, parentM.GetValue().Name) } var i int = 0 for true { rl := cm.GetRelation() // fmt.Println("-------- BACK - ID - ",rl.InvitationMemberId) if rl == nil || rl.RefereesId == 0 { break } cm = memberRep.GetMember(rl.RefereesId) // fmt.Println("-------- BACK ",cm == nil) if m == nil { break } if fee, err := strconv.Atoi(dt[fmt.Sprintf("G%d", i)]); err == nil { //log.Println("[ Back][ Cash] - ",i," back ",fee) backFunc(cm, pm, fee) } pm = cm i++ if i >= level { break } } }
func backCashForMember(m member.IMember, order *shopping.ValueOrder, fee int, refName string) error { //更新账户 acc := m.GetAccount() acv := acc.GetValue() bFee := float32(fee) acv.PresentBalance += bFee // 更新赠送余额 acv.TotalPresentFee += bFee acv.UpdateTime = time.Now().Unix() _, err := acc.Save() if err == nil { //给自己返现 icLog := &member.IncomeLog{ MemberId: m.GetAggregateRootId(), OrderId: order.Id, Type: "backcash", Fee: float32(fee), Log: fmt.Sprintf("推广返现¥%s元,订单号:%s,来源:%s", format.FormatFloat(bFee), order.OrderNo, refName), State: 1, RecordTime: acv.UpdateTime, } err = m.SaveIncomeLog(icLog) } return err }
// 处理返现促销 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 }
// 更新返现到会员账户 func (this *Order) updateShoppingMemberBackFee(pt partner.IPartner, m member.IMember, fee float32, unixTime int64) { if fee == 0 { return } v := this.GetValue() pv := pt.GetValue() //更新账户 acc := m.GetAccount() acv := acc.GetValue() //acc.TotalFee += this._value.Fee //acc.TotalPay += this._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)) }
// 结算数据持久化 func (this *Cart) SettlePersist(shopId, paymentOpt, deliverOpt, deliverId int) error { var shop partner.IShop var deliver member.IDeliver var err error if shopId > 0 { var pt partner.IPartner pt, err = this._partnerRep.GetPartner(this._partnerId) if err != nil { return err } shop = pt.GetShop(shopId) if shop == nil { return partner.ErrNoSuchShop } this._shop = shop this._value.ShopId = shopId } if this._value.BuyerId > 0 && deliverId > 0 { var m member.IMember m, err = this._memberRep.GetMember(this._value.BuyerId) if err != nil { return err } deliver = m.GetDeliver(deliverId) fmt.Println("-----", m.GetAggregateRootId(), deliverId) if deliver == nil { return member.ErrInvalidSession } this._deliver = deliver this._value.DeliverId = deliverId } this._value.PaymentOpt = paymentOpt this._value.DeliverOpt = deliverOpt return nil }
// 获取会员汇总信息 func (this *memberService) GetMemberSummary(memberId int) *dto.MemberSummary { var m member.IMember = this._memberRep.GetMember(memberId) if m != nil { mv := m.GetValue() acv := m.GetAccount().GetValue() lv := m.GetLevel() return &dto.MemberSummary{ Id: m.GetAggregateRootId(), Usr: mv.Usr, Name: mv.Name, Exp: mv.Exp, Level: mv.Level, LevelName: lv.Name, Integral: acv.Integral, Balance: acv.Balance, PresentBalance: acv.PresentBalance, UpdateTime: mv.UpdateTime, } } return nil }