|
|
@@ -13,6 +13,23 @@ import ( |
|
|
|
"xorm.io/xorm" |
|
|
|
) |
|
|
|
|
|
|
|
func GetComm(eg *xorm.Engine) map[string]string { |
|
|
|
virCfg, _ := db.SysCfgGetOne(eg, "virtual_coin_rebate_type") |
|
|
|
var virType = "price" |
|
|
|
if virCfg != nil && virCfg.Val != "" { |
|
|
|
virType = virCfg.Val |
|
|
|
} |
|
|
|
var arg = map[string]string{ |
|
|
|
"virType": virType, |
|
|
|
"integralRewardMultiple": "0", |
|
|
|
} |
|
|
|
chain := db.GetGreenChain(eg) |
|
|
|
if chain != nil { |
|
|
|
arg["integralRewardMultiple"] = zhios_order_relate_utils.IntToStr(chain.IntegralRewardMultiple) |
|
|
|
} |
|
|
|
return arg |
|
|
|
} |
|
|
|
|
|
|
|
// BatchGetCommission 批量分佣 商品显示 |
|
|
|
func BatchGetCommissionByGoods(eg *xorm.Engine, dbName string, commissionParamList []*md.CommissionFirstParam) (map[string]*comm_plan.LvUser, error) { |
|
|
|
var ( |
|
|
@@ -26,11 +43,7 @@ func BatchGetCommissionByGoods(eg *xorm.Engine, dbName string, commissionParamLi |
|
|
|
|
|
|
|
group, _ := errgroup.WithContext(context.Background()) |
|
|
|
var mu sync.Mutex |
|
|
|
virCfg, _ := db.SysCfgGetOne(eg, "virtual_coin_rebate_type") |
|
|
|
var virType = "price" |
|
|
|
if virCfg != nil && virCfg.Val != "" { |
|
|
|
virType = virCfg.Val |
|
|
|
} |
|
|
|
commArr := GetComm(eg) |
|
|
|
plan, commission, virtualCoinMoneyRate := svc.GetAllPlan(eg, dbName) |
|
|
|
for _, param := range commissionParamList { |
|
|
|
param := param // 为下面的闭包创建局部变量 |
|
|
@@ -47,8 +60,7 @@ func BatchGetCommissionByGoods(eg *xorm.Engine, dbName string, commissionParamLi |
|
|
|
param.CommissionParam.Oid = param.GoodsId |
|
|
|
param.CommissionParam.IsGoods = "1" |
|
|
|
param.CommissionParam.ShowLevel = param.ShowLevel |
|
|
|
|
|
|
|
_, _, _, _, lvUser, err := svc.GetRewardCommission(eg, ¶m.CommissionParam, isShare, param.Uid, param.Provider, dbName, isAllLevelReturn, map[string]string{}, virType, plan, commission, virtualCoinMoneyRate) |
|
|
|
_, _, _, _, lvUser, err := svc.GetRewardCommission(eg, ¶m.CommissionParam, isShare, param.Uid, param.Provider, dbName, isAllLevelReturn, map[string]string{}, commArr, plan, commission, virtualCoinMoneyRate) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
@@ -79,11 +91,8 @@ func BatchGetCommissionByGoodsExtend(eg *xorm.Engine, dbName string, commissionP |
|
|
|
|
|
|
|
group, _ := errgroup.WithContext(context.Background()) |
|
|
|
var mu sync.Mutex |
|
|
|
virCfg, _ := db.SysCfgGetOne(eg, "virtual_coin_rebate_type") |
|
|
|
var virType = "price" |
|
|
|
if virCfg != nil && virCfg.Val != "" { |
|
|
|
virType = virCfg.Val |
|
|
|
} |
|
|
|
commArr := GetComm(eg) |
|
|
|
|
|
|
|
plan, commission, virtualCoinMoneyRate := svc.GetAllPlan(eg, dbName) |
|
|
|
|
|
|
|
for _, param := range commissionParamList { |
|
|
@@ -102,7 +111,7 @@ func BatchGetCommissionByGoodsExtend(eg *xorm.Engine, dbName string, commissionP |
|
|
|
param.CommissionParam.IsGoods = "1" |
|
|
|
param.CommissionParam.IsShowExtend = param.IsShowExtend |
|
|
|
|
|
|
|
_, _, _, _, lvUser, err := svc.GetRewardCommission(eg, ¶m.CommissionParam, isShare, param.Uid, param.Provider, dbName, isAllLevelReturn, map[string]string{}, virType, plan, commission, virtualCoinMoneyRate) |
|
|
|
_, _, _, _, lvUser, err := svc.GetRewardCommission(eg, ¶m.CommissionParam, isShare, param.Uid, param.Provider, dbName, isAllLevelReturn, map[string]string{}, commArr, plan, commission, virtualCoinMoneyRate) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
@@ -120,66 +129,6 @@ func BatchGetCommissionByGoodsExtend(eg *xorm.Engine, dbName string, commissionP |
|
|
|
return goodsId2lvUser, nil |
|
|
|
} |
|
|
|
|
|
|
|
// BatchGetCommission 批量分佣 订单显示 |
|
|
|
func BatchGetCommissionByOrder(engine *xorm.Engine, dbName string, CommissionParamList []*md.CommissionFirstParam) (map[string]*comm_plan.SettleCommissionToGuide, error) { |
|
|
|
var ( |
|
|
|
isShare = false |
|
|
|
isAllLevelReturn = false |
|
|
|
) |
|
|
|
goodsId2lvUser := make(map[string]*comm_plan.SettleCommissionToGuide, len(CommissionParamList)) |
|
|
|
if len(CommissionParamList) == 0 { |
|
|
|
return goodsId2lvUser, errors.New("参数缺失") |
|
|
|
} |
|
|
|
|
|
|
|
group, _ := errgroup.WithContext(context.Background()) |
|
|
|
var mu sync.Mutex |
|
|
|
virCfg, _ := db.SysCfgGetOne(engine, "virtual_coin_rebate_type") |
|
|
|
var virType = "price" |
|
|
|
if virCfg != nil && virCfg.Val != "" { |
|
|
|
virType = virCfg.Val |
|
|
|
} |
|
|
|
plan, commission, virtualCoinMoneyRate := svc.GetAllPlan(engine, dbName) |
|
|
|
|
|
|
|
for _, param := range CommissionParamList { |
|
|
|
param := param // 为下面的闭包创建局部变量 |
|
|
|
group.Go(func() error { |
|
|
|
defer mu.Unlock() |
|
|
|
mu.Lock() |
|
|
|
if param.IsShare != 0 { |
|
|
|
isShare = true |
|
|
|
} |
|
|
|
if param.IsAllLevelReturn != 0 { |
|
|
|
isAllLevelReturn = true |
|
|
|
} |
|
|
|
|
|
|
|
if param.Oid == "" { |
|
|
|
return errors.New("订单缺失") |
|
|
|
} |
|
|
|
param.CommissionParam.OldPrice = param.CommissionParam.GoodsPrice |
|
|
|
param.CommissionParam.Oid = param.Oid |
|
|
|
|
|
|
|
profit, pvdFee, sysFee, subsidyFee, lvUser, err := svc.GetRewardCommission(engine, ¶m.CommissionParam, isShare, param.Uid, param.Provider, dbName, isAllLevelReturn, map[string]string{}, virType, plan, commission, virtualCoinMoneyRate) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
goodsId2lvUser[param.Oid] = &comm_plan.SettleCommissionToGuide{ |
|
|
|
Profit: profit, |
|
|
|
PvdFee: pvdFee, |
|
|
|
SysFee: sysFee, |
|
|
|
SubsidyFee: subsidyFee, |
|
|
|
LvUser: lvUser, |
|
|
|
} |
|
|
|
|
|
|
|
return nil |
|
|
|
}) |
|
|
|
} |
|
|
|
if err := group.Wait(); err != nil { |
|
|
|
return goodsId2lvUser, err |
|
|
|
} |
|
|
|
|
|
|
|
return goodsId2lvUser, nil |
|
|
|
} |
|
|
|
|
|
|
|
//商品详情等使用 |
|
|
|
func SettleCommWithGoodsDetail(eg *xorm.Engine, dbName string, CommissionParam md.CommissionFirstParam) (float64, float64, float64, float64, *comm_plan.LvUser, error) { |
|
|
|
var ( |
|
|
@@ -198,17 +147,14 @@ func SettleCommWithGoodsDetail(eg *xorm.Engine, dbName string, CommissionParam m |
|
|
|
"new_lv": CommissionParam.NewLv, |
|
|
|
"ownbuy_return_type": zhios_order_relate_utils.IntToStr(CommissionParam.OwnbuyReturnType), |
|
|
|
} |
|
|
|
virCfg, _ := db.SysCfgGetOne(eg, "virtual_coin_rebate_type") |
|
|
|
var virType = "price" |
|
|
|
if virCfg != nil && virCfg.Val != "" { |
|
|
|
virType = virCfg.Val |
|
|
|
} |
|
|
|
commArr := GetComm(eg) |
|
|
|
|
|
|
|
CommissionParam.CommissionParam.Oid = CommissionParam.GoodsId |
|
|
|
CommissionParam.CommissionParam.IsGoods = "1" |
|
|
|
CommissionParam.CommissionParam.ShowLevel = CommissionParam.ShowLevel |
|
|
|
plan, commission, virtualCoinMoneyRate := svc.GetAllPlan(eg, dbName) |
|
|
|
|
|
|
|
profit, pvdFee, sysFee, subsidyFee, lvUser, err := svc.GetRewardCommission(eg, &CommissionParam.CommissionParam, isShare, CommissionParam.Uid, CommissionParam.Provider, dbName, isAllLevelReturn, mapData, virType, plan, commission, virtualCoinMoneyRate) |
|
|
|
profit, pvdFee, sysFee, subsidyFee, lvUser, err := svc.GetRewardCommission(eg, &CommissionParam.CommissionParam, isShare, CommissionParam.Uid, CommissionParam.Provider, dbName, isAllLevelReturn, mapData, commArr, plan, commission, virtualCoinMoneyRate) |
|
|
|
return profit, pvdFee, sysFee, subsidyFee, lvUser, err |
|
|
|
} |
|
|
|
|
|
|
@@ -230,49 +176,18 @@ func SettleCommWithGoodsDetailExtend(eg *xorm.Engine, dbName string, CommissionP |
|
|
|
"new_lv": CommissionParam.NewLv, |
|
|
|
"ownbuy_return_type": zhios_order_relate_utils.IntToStr(CommissionParam.OwnbuyReturnType), |
|
|
|
} |
|
|
|
virCfg, _ := db.SysCfgGetOne(eg, "virtual_coin_rebate_type") |
|
|
|
var virType = "price" |
|
|
|
if virCfg != nil && virCfg.Val != "" { |
|
|
|
virType = virCfg.Val |
|
|
|
} |
|
|
|
commArr := GetComm(eg) |
|
|
|
|
|
|
|
CommissionParam.CommissionParam.Oid = CommissionParam.GoodsId |
|
|
|
CommissionParam.CommissionParam.IsGoods = "1" |
|
|
|
CommissionParam.CommissionParam.IsShowExtend = CommissionParam.IsShowExtend |
|
|
|
plan, commission, virtualCoinMoneyRate := svc.GetAllPlan(eg, dbName) |
|
|
|
|
|
|
|
profit, pvdFee, sysFee, subsidyFee, lvUser, err := svc.GetRewardCommission(eg, &CommissionParam.CommissionParam, isShare, CommissionParam.Uid, CommissionParam.Provider, dbName, isAllLevelReturn, mapData, virType, plan, commission, virtualCoinMoneyRate) |
|
|
|
profit, pvdFee, sysFee, subsidyFee, lvUser, err := svc.GetRewardCommission(eg, &CommissionParam.CommissionParam, isShare, CommissionParam.Uid, CommissionParam.Provider, dbName, isAllLevelReturn, mapData, commArr, plan, commission, virtualCoinMoneyRate) |
|
|
|
return profit, pvdFee, sysFee, subsidyFee, lvUser, err |
|
|
|
} |
|
|
|
func SettleCommWithOrder(eg *xorm.Engine, dbName string, CommissionParam md.CommissionFirstParam) (float64, float64, float64, float64, *comm_plan.LvUser, error) { |
|
|
|
var ( |
|
|
|
isShare = false |
|
|
|
isAllLevelReturn = false |
|
|
|
) |
|
|
|
if CommissionParam.IsShare != 0 { |
|
|
|
isShare = true |
|
|
|
} |
|
|
|
|
|
|
|
if CommissionParam.IsAllLevelReturn != 0 { |
|
|
|
isAllLevelReturn = true |
|
|
|
} |
|
|
|
var mapData = map[string]string{ |
|
|
|
"old_lv": CommissionParam.OldLv, |
|
|
|
"new_lv": CommissionParam.NewLv, |
|
|
|
"ownbuy_return_type": zhios_order_relate_utils.IntToStr(CommissionParam.OwnbuyReturnType), |
|
|
|
} |
|
|
|
virCfg, _ := db.SysCfgGetOne(eg, "virtual_coin_rebate_type") |
|
|
|
var virType = "price" |
|
|
|
if virCfg != nil && virCfg.Val != "" { |
|
|
|
virType = virCfg.Val |
|
|
|
} |
|
|
|
CommissionParam.CommissionParam.Oid = CommissionParam.GoodsId |
|
|
|
plan, commission, virtualCoinMoneyRate := svc.GetAllPlan(eg, dbName) |
|
|
|
|
|
|
|
profit, pvdFee, sysFee, subsidyFee, lvUser, err := svc.GetRewardCommission(eg, &CommissionParam.CommissionParam, isShare, CommissionParam.Uid, CommissionParam.Provider, dbName, isAllLevelReturn, mapData, virType, plan, commission, virtualCoinMoneyRate) |
|
|
|
return profit, pvdFee, sysFee, subsidyFee, lvUser, err |
|
|
|
} |
|
|
|
|
|
|
|
//获取自购分享佣金的 |
|
|
|
//获取自购分享佣金的 商品显示 |
|
|
|
func GetRewardCommission(eg *xorm.Engine, dbName, mode string, CommissionParam md.CommissionFirstParam) (float64, float64, *comm_plan.LvUser, error) { |
|
|
|
var ( |
|
|
|
isAll = false |
|
|
@@ -293,18 +208,100 @@ func GetRewardCommission(eg *xorm.Engine, dbName, mode string, CommissionParam m |
|
|
|
CommissionParam.CommissionParam.IsGoods = "1" |
|
|
|
CommissionParam.CommissionParam.ShowLevel = CommissionParam.ShowLevel |
|
|
|
plan, commissions, virtualCoinMoneyRate := svc.GetAllPlan(eg, dbName) |
|
|
|
|
|
|
|
commArr := GetComm(eg) |
|
|
|
var lvUser = &comm_plan.LvUser{} |
|
|
|
var mapsDta = map[string]string{"show_level": CommissionParam.ShowLevel} |
|
|
|
if isAll { |
|
|
|
shareCommission, _, _, _, lvUser, _ = svc.GetRewardCommission(eg, &CommissionParam.CommissionParam, true, CommissionParam.Uid, CommissionParam.Provider, dbName, isAllLevelReturn, mapsDta, mode, plan, commissions, virtualCoinMoneyRate) |
|
|
|
commission, _, _, _, lvUser, _ = svc.GetRewardCommission(eg, &CommissionParam.CommissionParam, false, CommissionParam.Uid, CommissionParam.Provider, dbName, isAllLevelReturn, mapsDta, mode, plan, commissions, virtualCoinMoneyRate) |
|
|
|
shareCommission, _, _, _, lvUser, _ = svc.GetRewardCommission(eg, &CommissionParam.CommissionParam, true, CommissionParam.Uid, CommissionParam.Provider, dbName, isAllLevelReturn, mapsDta, commArr, plan, commissions, virtualCoinMoneyRate) |
|
|
|
commission, _, _, _, lvUser, _ = svc.GetRewardCommission(eg, &CommissionParam.CommissionParam, false, CommissionParam.Uid, CommissionParam.Provider, dbName, isAllLevelReturn, mapsDta, commArr, plan, commissions, virtualCoinMoneyRate) |
|
|
|
} else { |
|
|
|
if isShare { |
|
|
|
shareCommission, _, _, _, lvUser, _ = svc.GetRewardCommission(eg, &CommissionParam.CommissionParam, isShare, CommissionParam.Uid, CommissionParam.Provider, dbName, isAllLevelReturn, mapsDta, mode, plan, commissions, virtualCoinMoneyRate) |
|
|
|
shareCommission, _, _, _, lvUser, _ = svc.GetRewardCommission(eg, &CommissionParam.CommissionParam, isShare, CommissionParam.Uid, CommissionParam.Provider, dbName, isAllLevelReturn, mapsDta, commArr, plan, commissions, virtualCoinMoneyRate) |
|
|
|
} else { |
|
|
|
commission, _, _, _, lvUser, _ = svc.GetRewardCommission(eg, &CommissionParam.CommissionParam, isShare, CommissionParam.Uid, CommissionParam.Provider, dbName, isAllLevelReturn, mapsDta, mode, plan, commissions, virtualCoinMoneyRate) |
|
|
|
commission, _, _, _, lvUser, _ = svc.GetRewardCommission(eg, &CommissionParam.CommissionParam, isShare, CommissionParam.Uid, CommissionParam.Provider, dbName, isAllLevelReturn, mapsDta, commArr, plan, commissions, virtualCoinMoneyRate) |
|
|
|
} |
|
|
|
} |
|
|
|
return commission, shareCommission, lvUser, nil |
|
|
|
} |
|
|
|
|
|
|
|
// BatchGetCommission 批量分佣 订单显示 |
|
|
|
func BatchGetCommissionByOrder(engine *xorm.Engine, dbName string, CommissionParamList []*md.CommissionFirstParam) (map[string]*comm_plan.SettleCommissionToGuide, error) { |
|
|
|
var ( |
|
|
|
isShare = false |
|
|
|
isAllLevelReturn = false |
|
|
|
) |
|
|
|
goodsId2lvUser := make(map[string]*comm_plan.SettleCommissionToGuide, len(CommissionParamList)) |
|
|
|
if len(CommissionParamList) == 0 { |
|
|
|
return goodsId2lvUser, errors.New("参数缺失") |
|
|
|
} |
|
|
|
|
|
|
|
group, _ := errgroup.WithContext(context.Background()) |
|
|
|
var mu sync.Mutex |
|
|
|
commArr := GetComm(engine) |
|
|
|
plan, commission, virtualCoinMoneyRate := svc.GetAllPlan(engine, dbName) |
|
|
|
|
|
|
|
for _, param := range CommissionParamList { |
|
|
|
param := param // 为下面的闭包创建局部变量 |
|
|
|
group.Go(func() error { |
|
|
|
defer mu.Unlock() |
|
|
|
mu.Lock() |
|
|
|
if param.IsShare != 0 { |
|
|
|
isShare = true |
|
|
|
} |
|
|
|
if param.IsAllLevelReturn != 0 { |
|
|
|
isAllLevelReturn = true |
|
|
|
} |
|
|
|
|
|
|
|
if param.Oid == "" { |
|
|
|
return errors.New("订单缺失") |
|
|
|
} |
|
|
|
param.CommissionParam.OldPrice = param.CommissionParam.GoodsPrice |
|
|
|
param.CommissionParam.Oid = param.Oid |
|
|
|
|
|
|
|
profit, pvdFee, sysFee, subsidyFee, lvUser, err := svc.GetRewardCommission(engine, ¶m.CommissionParam, isShare, param.Uid, param.Provider, dbName, isAllLevelReturn, map[string]string{}, commArr, plan, commission, virtualCoinMoneyRate) |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
goodsId2lvUser[param.Oid] = &comm_plan.SettleCommissionToGuide{ |
|
|
|
Profit: profit, |
|
|
|
PvdFee: pvdFee, |
|
|
|
SysFee: sysFee, |
|
|
|
SubsidyFee: subsidyFee, |
|
|
|
LvUser: lvUser, |
|
|
|
} |
|
|
|
|
|
|
|
return nil |
|
|
|
}) |
|
|
|
} |
|
|
|
if err := group.Wait(); err != nil { |
|
|
|
return goodsId2lvUser, err |
|
|
|
} |
|
|
|
|
|
|
|
return goodsId2lvUser, nil |
|
|
|
} |
|
|
|
|
|
|
|
func SettleCommWithOrder(eg *xorm.Engine, dbName string, CommissionParam md.CommissionFirstParam) (float64, float64, float64, float64, *comm_plan.LvUser, error) { |
|
|
|
var ( |
|
|
|
isShare = false |
|
|
|
isAllLevelReturn = false |
|
|
|
) |
|
|
|
if CommissionParam.IsShare != 0 { |
|
|
|
isShare = true |
|
|
|
} |
|
|
|
|
|
|
|
if CommissionParam.IsAllLevelReturn != 0 { |
|
|
|
isAllLevelReturn = true |
|
|
|
} |
|
|
|
var mapData = map[string]string{ |
|
|
|
"old_lv": CommissionParam.OldLv, |
|
|
|
"new_lv": CommissionParam.NewLv, |
|
|
|
"ownbuy_return_type": zhios_order_relate_utils.IntToStr(CommissionParam.OwnbuyReturnType), |
|
|
|
} |
|
|
|
commArr := GetComm(eg) |
|
|
|
|
|
|
|
CommissionParam.CommissionParam.Oid = CommissionParam.GoodsId |
|
|
|
plan, commission, virtualCoinMoneyRate := svc.GetAllPlan(eg, dbName) |
|
|
|
|
|
|
|
profit, pvdFee, sysFee, subsidyFee, lvUser, err := svc.GetRewardCommission(eg, &CommissionParam.CommissionParam, isShare, CommissionParam.Uid, CommissionParam.Provider, dbName, isAllLevelReturn, mapData, commArr, plan, commission, virtualCoinMoneyRate) |
|
|
|
return profit, pvdFee, sysFee, subsidyFee, lvUser, err |
|
|
|
} |