package svc import ( "applet/app/db" "applet/app/md" "applet/app/utils" "applet/app/utils/logx" "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/lib/comm_plan" md2 "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/md" "code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git/rule" "errors" "fmt" "github.com/gin-gonic/gin" "github.com/jinzhu/copier" "xorm.io/xorm" ) // GetCommissionByCommApi 调用公共接口获取佣金 func GetCommissionByCommApi(eg *xorm.Engine, masterId string, req md.CommissionFirstParam) (*comm_plan.SettleCommissionToGuide, error) { profit, pvdFee, sysFee, subsidyFee, lvUser, err := SettleComm(eg, masterId, req) if err != nil { return nil, err } result := &comm_plan.SettleCommissionToGuide{ Profit: profit, PvdFee: pvdFee, SysFee: sysFee, SubsidyFee: subsidyFee, LvUser: lvUser, } return result, nil } func GetCommissionByCommApiExtend(eg *xorm.Engine, masterId string, reqs md.CommissionReq) (*comm_plan.LvUser, error) { var req md2.CommissionFirstParam copier.Copy(&req, reqs) _, _, _, _, lvUser, err := rule.SettleCommWithGoodsDetailExtend(eg, masterId, req) if err != nil { return nil, errors.New("分佣数据解析错误") } return lvUser, nil } func SettleComm(eg *xorm.Engine, masterId string, CommissionParam md.CommissionFirstParam) (float64, float64, float64, float64, *comm_plan.LvUser, error) { var CommissionParam1 = md2.CommissionFirstParam{} copier.Copy(&CommissionParam1, CommissionParam) profit, pvdFee, sysFee, subsidyFee, lvUser, err := rule.SettleCommWithOrder(eg, masterId, CommissionParam1) return profit, pvdFee, sysFee, subsidyFee, lvUser, err } // 批量计算分佣 func BatchGetCommissionByGoodsApi(c *gin.Context, eg *xorm.Engine, masterId string, reqs []md.CommissionFirstParam) (map[string]*comm_plan.LvUser, error) { var req []*md2.CommissionFirstParam for _, v := range reqs { var tmp = md2.CommissionFirstParam{} err2 := copier.Copy(&tmp, v) if err2 != nil { utils.FilePutContents(c.GetString("mid")+"_tik_tok_goods", "============"+c.GetString("postDataP")+"======"+utils.SerializeStr(err2)) } req = append(req, &tmp) } utils.FilePutContents(c.GetString("mid")+"_tik_tok_goods", "============"+c.GetString("postDataP")+"======"+utils.SerializeStr(req)) commissionList, err := rule.BatchGetCommissionByGoods(eg, masterId, req) if err != nil { return nil, logx.Error(err) } return commissionList, nil } // 批量计算分佣 func BatchGetCommissionByCommApi(eg *xorm.Engine, masterId string, reqs []md.CommissionFirstParam) (map[string]*comm_plan.SettleCommissionToGuide, error) { var req = make([]*md2.CommissionFirstParam, 0) for _, v := range reqs { var tmp = md2.CommissionFirstParam{} copier.Copy(&tmp, v) req = append(req, &tmp) } commissionList, err := rule.BatchGetCommissionByOrder(eg, masterId, req) if err != nil { return nil, logx.Error(err) } return commissionList, nil } // 批量计算分佣 func BatchGetCommissionByCommApiSecond(eg *xorm.Engine, masterId string, reqs []*md.CommissionReq) (map[string]*comm_plan.LvUser, error) { var req []*md2.CommissionFirstParam for _, v := range reqs { var tmp = md2.CommissionFirstParam{} copier.Copy(&tmp, v) req = append(req, &tmp) } commissionList, err := rule.BatchGetCommissionByGoods(eg, masterId, req) if err != nil { fmt.Println("=========================", err.Error()) commissionList = map[string]*comm_plan.LvUser{} } return commissionList, nil } func BatchGetCommissionByCommApiExtend(eg *xorm.Engine, masterId string, reqs []*md.CommissionReq) (map[string]*comm_plan.LvUser, error) { var req []*md2.CommissionFirstParam for _, v := range reqs { var tmp = md2.CommissionFirstParam{} copier.Copy(&tmp, v) req = append(req, &tmp) } commissionList, err := rule.BatchGetCommissionByGoodsExtend(eg, masterId, req) if err != nil { commissionList = map[string]*comm_plan.LvUser{} } return commissionList, nil } func GetCommission(eg *xorm.Engine, masterId, commission, Uid, Provider string, IsShare int, showLevel string) (respCommission, shareCommission string) { var t = md.CommissionFirstParam{} param := md.CommissionParam{Commission: commission} t.CommissionParam = param t.Uid = Uid t.Provider = Provider t.IsShare = IsShare t.ShowLevel = showLevel pvd, err2 := db.DbsPlanCommissionByPvd(eg, Provider) if err2 != nil || pvd == nil { return "0", "0" } var req = md2.CommissionFirstParam{} copier.Copy(&req, t) respCommission1, shareCommission1, _, err := rule.GetRewardCommission(eg, masterId, pvd.Mode, req) if err != nil { return "0", "0" } return utils.AnyToString(respCommission1), utils.AnyToString(shareCommission1) }