From 4af629e0f91b9399ae587e1c7e189c7a708341c3 Mon Sep 17 00:00:00 2001 From: huangjuajun <102564160@qq.com> Date: Wed, 8 Jun 2022 10:04:30 +0800 Subject: [PATCH] =?UTF-8?q?add=20reverse:for=20v1.0.4=20=E5=8A=A0=E5=85=A5?= =?UTF-8?q?=E6=89=A3=E9=99=A4=E5=95=86=E5=AE=B6=E5=88=86=E4=BD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- o2o/add_store_commission.go | 61 +++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/o2o/add_store_commission.go b/o2o/add_store_commission.go index fbf191a..8361a34 100644 --- a/o2o/add_store_commission.go +++ b/o2o/add_store_commission.go @@ -113,3 +113,64 @@ func SettleStoreCommission(eg *xorm.Engine, session *xorm.Session, args map[stri } return true } + +//扣除商家分佣 商家抽成部分 +/*** +oid 订单号 +pvd 渠道 +title 描述 +*/ +func DeductStoreCommission(eg *xorm.Engine, session *xorm.Session, args map[string]string) bool { + relate, err := db.GetStoreCommissionRelateWithSession(session, args["oid"], args["pvd"]) + if err != nil { + return false + } + if relate == nil { + return true + } + if relate.SettleTime.IsZero() { + return true + } + //判断是不是商家 + merchant, manager := GetO2oStore(eg, zhios_o2o_business_utils.IntToStr(relate.Uid)) + if manager == nil { + return true + } + if manager.Id > 0 { + amount := zhios_o2o_business_utils.StrToFloat64(relate.Amount) + mBeforeAmount := merchant.Amount + mAfterAmount := mBeforeAmount - amount + // o2o_fin_user_flow 新增流水记录 + var o2oFinUserFlow = model.O2oFinUserFlow{ + Uid: relate.Uid, + MerchantId: relate.Uid, + StoreId: manager.Id, + Type: 1, + Amount: strconv.FormatFloat(amount, 'f', 4, 64), + BeforeAmount: strconv.FormatFloat(mBeforeAmount, 'f', 4, 64), + AfterAmount: strconv.FormatFloat(mAfterAmount, 'f', 4, 64), + OrdType: relate.Pvd, + OrdId: relate.Oid, + OrdTitle: args["title"], + OrdAction: 11, + OrdTime: int(time.Now().Unix()), + State: 2, + CreateAt: time.Now(), + UpdateAt: time.Now(), + } + merchant.Amount = mAfterAmount + affected, err := db.MerchantUpdateWithSession(session, merchant, "amount") + has, errs := session.Insert(&o2oFinUserFlow) + if affected == 0 || err != nil || errs != nil || has == 0 { + _ = zhios_o2o_business_logx.Warn(err) + return false + } + relate.SettleTime = time.Time{} + update, err := session.Where("id=?", relate.Id).Cols("settle_time").Update(relate) + if update == 0 || err != nil { + _ = zhios_o2o_business_logx.Warn(err) + return false + } + } + return true +}