Browse Source

add reverse:for v1.0.4 加入扣除商家分佣

tags/v1.0.4
huangjuajun 2 years ago
parent
commit
4af629e0f9
1 changed files with 61 additions and 0 deletions
  1. +61
    -0
      o2o/add_store_commission.go

+ 61
- 0
o2o/add_store_commission.go View File

@@ -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
}

Loading…
Cancel
Save