From a7a83f54f0f5db57c4e995a7301d52001a3052bf Mon Sep 17 00:00:00 2001 From: huangjiajun <582604932@qq.com> Date: Sun, 4 Aug 2024 08:43:38 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/db/db_order_ralate.go | 9 +- app/db/db_virtaul_coin_cfg.go | 10 +- app/db/model/ord_list.go | 1 + app/md/commission.go | 1 + app/md/mq.go | 18 +- app/svc/svc_goods_commission.go | 27 ++ app/svc/svc_order_track_save.go | 274 +++++++++++++++++- app/svc/svc_order_track_save_create.go | 37 ++- app/svc/svc_order_track_save_create_update.go | 32 +- app/svc/svc_order_track_save_update.go | 8 +- ...zhios_order_track_create_for_jd_consume.go | 2 +- ...hios_order_track_create_for_pdd_consume.go | 2 +- ...zhios_order_track_create_for_tb_consume.go | 2 +- ...r_track_create_for_tik_tok_team_consume.go | 2 +- ...hios_order_track_create_for_wph_consume.go | 2 +- ...zhios_order_track_update_for_jd_consume.go | 2 +- ...zhios_order_track_update_for_tb_consume.go | 2 +- go.mod | 2 +- 18 files changed, 402 insertions(+), 31 deletions(-) diff --git a/app/db/db_order_ralate.go b/app/db/db_order_ralate.go index 2934f58..ea01a99 100644 --- a/app/db/db_order_ralate.go +++ b/app/db/db_order_ralate.go @@ -82,7 +82,14 @@ func OrderRelateListByOidWithLevel(Db *xorm.Engine, oid int64) (*model.OrdListRe return &ol, nil } func OrderRelateDeleteByOid(Db *xorm.Engine, oid int64, pvd string) (int64, error) { - _, err := Db.Where("oid=? and pvd=?", oid, pvd).Delete(model.OrdListRelate{}) + _, err := Db.Where("oid=? and pvd=? and extend_type!=8", oid, pvd).Delete(model.OrdListRelate{}) + if err != nil { + return 0, err + } + return 1, nil +} +func OrderRelateDeleteByOidService(Db *xorm.Engine, oid int64, pvd string) (int64, error) { + _, err := Db.Where("oid=? and pvd=? and extend_type=?", oid, pvd, 8).Delete(model.OrdListRelate{}) if err != nil { return 0, err } diff --git a/app/db/db_virtaul_coin_cfg.go b/app/db/db_virtaul_coin_cfg.go index 4e1528d..b14be85 100644 --- a/app/db/db_virtaul_coin_cfg.go +++ b/app/db/db_virtaul_coin_cfg.go @@ -94,13 +94,19 @@ func VirtualCoinGetOneById(Db *xorm.Engine, coinId string) (*model.VirtualCoin, } func VirtualCoinOrderRelateDeleteByOid(Db *xorm.Engine, oid int64, pvd string) (int64, error) { - _, err := Db.Where("oid=? and pvd=?", oid, pvd).Delete(model.VirtualCoinRelate{}) + _, err := Db.Where("oid=? and pvd=? and extend_type!=8", oid, pvd).Delete(model.VirtualCoinRelate{}) + if err != nil { + return 0, err + } + return 1, nil +} +func VirtualCoinOrderRelateDeleteByOidService(Db *xorm.Engine, oid int64, pvd string) (int64, error) { + _, err := Db.Where("oid=? and pvd=? and extend_type=?", oid, pvd, 8).Delete(model.VirtualCoinRelate{}) if err != nil { return 0, err } return 1, nil } - func VirtualCoinMapInUse(Db *xorm.Engine, masterId string) (map[string]model.VirtualCoin, error) { virtualCoinMap := make(map[string]model.VirtualCoin) listInUse, err := VirtualCoinListInUse(Db, masterId) diff --git a/app/db/model/ord_list.go b/app/db/model/ord_list.go index 1f7f645..4a37349 100644 --- a/app/db/model/ord_list.go +++ b/app/db/model/ord_list.go @@ -1,6 +1,7 @@ package model type OrdList struct { + ServiceUid int `xorm:"not null default 0 INT(1)" json:"service_uid"` OrdId int64 `xorm:"pk autoincr BIGINT(20)" json:"ord_id"` Uid int `xorm:"not null index INT(10)" json:"uid"` PvdOid string `xorm:"not null index(IDX_PVD) VARCHAR(50)" json:"pvd_oid"` diff --git a/app/md/commission.go b/app/md/commission.go index 218c337..a023c03 100644 --- a/app/md/commission.go +++ b/app/md/commission.go @@ -94,4 +94,5 @@ type CommissionFirstParam struct { Oid string `json:"oid"` ShowLevel string `json:"show_level"` IsShowExtend string `json:"is_show_extend"` + ServiceUid string `json:"service_uid"` } diff --git a/app/md/mq.go b/app/md/mq.go index 532ddb3..d40fa3d 100644 --- a/app/md/mq.go +++ b/app/md/mq.go @@ -135,17 +135,19 @@ type ZhiosOrderBuckle struct { } type ZhiosOrderTrackUpdateRoutKeyForTb struct { - Pvd string `json:"pvd"` - OrderData *[]OrderInfo `json:"order_data"` - Opts map[string]*plan.PlanOpt `json:"opts"` - DbName string `json:"db_name"` + Pvd string `json:"pvd"` + OrderData *[]OrderInfo `json:"order_data"` + Opts map[string]*plan.PlanOpt `json:"opts"` + SecondOpts map[string]*plan.PlanOpt `json:"second_opts"` + DbName string `json:"db_name"` } type ZhiosOrderTrackCreateRoutKeyForTb struct { - Pvd string `json:"pvd"` - OrderData *[]OrderInfo `json:"order_data"` - Opts map[string]*plan.PlanOpt `json:"opts"` - DbName string `json:"db_name"` + Pvd string `json:"pvd"` + OrderData *[]OrderInfo `json:"order_data"` + Opts map[string]*plan.PlanOpt `json:"opts"` + SecondOpts map[string]*plan.PlanOpt `json:"second_opts"` + DbName string `json:"db_name"` } type ZhiosOrderTrackRefundRoutKeyForTbPart struct { diff --git a/app/svc/svc_goods_commission.go b/app/svc/svc_goods_commission.go index c4de775..cedfb4f 100644 --- a/app/svc/svc_goods_commission.go +++ b/app/svc/svc_goods_commission.go @@ -2,7 +2,11 @@ package svc import ( "applet/app/md" + "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" + "github.com/jinzhu/copier" "xorm.io/xorm" ) @@ -17,3 +21,26 @@ func GetMoreRebateResult(eg *xorm.Engine, dbName, returnMoneyType string, reqLis } return commissionListArr, returnListArr } +func GetMoreRebateResultService(eg *xorm.Engine, dbName, returnMoneyType string, reqList []md.CommissionFirstParam, goodsList []map[string]string) (map[string]*comm_plan.SettleCommissionToGuide, map[string]interface{}) { + var commissionListArr = make(map[string]*comm_plan.SettleCommissionToGuide, 0) + var returnListArr = make(map[string]interface{}, 0) + commissionListArr, _ = BatchGetOrderCommissionByCommApiService(eg, dbName, reqList) + return commissionListArr, returnListArr +} + +// 批量计算分佣 +func BatchGetOrderCommissionByCommApiService(eg *xorm.Engine, masterId string, reqs []md.CommissionFirstParam) (map[string]*comm_plan.SettleCommissionToGuide, error) { + + var req []*md2.CommissionFirstParam + for _, v := range reqs { + var tmp = md2.CommissionFirstParam{} + copier.Copy(&tmp, v) + req = append(req, &tmp) + } + commissionList, err := rule.BatchGetCommissionByOrderService(eg, masterId, req) + if err != nil { + return nil, logx.Error(err) + } + + return commissionList, nil +} diff --git a/app/svc/svc_order_track_save.go b/app/svc/svc_order_track_save.go index 64ef76d..03d93f1 100644 --- a/app/svc/svc_order_track_save.go +++ b/app/svc/svc_order_track_save.go @@ -24,7 +24,7 @@ import ( ) //公共判断订单是否要绑定用户 -func commCheckUser(eg *xorm.Engine, existOrd model.OrdList, ords map[string]md.OrderInfo, pvd string, pidToUser map[string]*md.UserPid, opts map[string]*plan.PlanOpt, dbName string, isCheck bool, returnMoneyType string) { +func commCheckUser(eg *xorm.Engine, existOrd model.OrdList, ords map[string]md.OrderInfo, pvd string, pidToUser map[string]*md.UserPid, opts map[string]*plan.PlanOpt, secondOpts map[string]*plan.PlanOpt, dbName string, isCheck bool, returnMoneyType string) { pid := ords[existOrd.PvdOid].Pid if utils.InArr(pvd, []string{md.PVD_TB, "ele", md.PVD_TB12, md.PVD_TB13, md.PVD_TB14, md.PVD_TB3, md.PVD_TBBYPAY, md.PVD_TBBYCREATETIME, md.PVD_TBBYSETTLE}) { //如果是淘宝要处理下类型拿用户 @@ -132,6 +132,8 @@ func commCheckUser(eg *xorm.Engine, existOrd model.OrdList, ords map[string]md.O } } newOpts := opts[newPvds] + secondOpt := secondOpts[newPvds] + if pvd == "oil" && newOpts == nil { newOpts = opts["oilstation"] } @@ -139,10 +141,15 @@ func commCheckUser(eg *xorm.Engine, existOrd model.OrdList, ords map[string]md.O newOpts = opts[md.PVD_JDOwn] newPvds = md.PVD_JDOwn } + if existOrd.OrderFormType == 1 && secondOpts[md.PVD_JDOwn] != nil { + secondOpt = secondOpts[md.PVD_JDOwn] + } if newOpts != nil && newOpts.Mode == "public_platoon" && isCheck == false { //如果是公牌 并且不是没有分佣记录的 不能改了 return } var lvUser *comm_plan.LvUser + var secondLvUser *comm_plan.LvUser + var pvdFee float64 var sysFee float64 var subsidyFee float64 @@ -159,6 +166,8 @@ func commCheckUser(eg *xorm.Engine, existOrd model.OrdList, ords map[string]md.O isShare = 1 } var commissionReqList = make([]md.CommissionFirstParam, 0) + var secondCommissionReqList = make([]md.CommissionFirstParam, 0) + var returnMoneyReqList = make([]map[string]string, 0) IsTikTokTeamOrder := ords[existOrd.PvdOid].IsTikTokTeamOrder TikTokTeamCommission := ords[existOrd.PvdOid].TikTokTeamCommission @@ -181,6 +190,12 @@ func commCheckUser(eg *xorm.Engine, existOrd model.OrdList, ords map[string]md.O if pvd == "kuaishou" && IsTikTokTeamOrder == 1 && opts["kuaishouTeam"] != nil && opts["kuaishouTeam"].PlanCommissionId > 0 { newOpts = opts["kuaishouTeam"] } + if (pvd == "tikTok" || pvd == "csjp") && IsTikTokTeamOrder == 1 && secondOpts["tikTokTeam"] != nil && secondOpts["tikTokTeam"].PlanCommissionId > 0 { + secondOpt = secondOpts["tikTokTeam"] + } + if pvd == "kuaishou" && IsTikTokTeamOrder == 1 && secondOpts["kuaishouTeam"] != nil && secondOpts["kuaishouTeam"].PlanCommissionId > 0 { + secondOpt = secondOpts["kuaishouTeam"] + } req := md.CommissionFirstParam{ CommissionParam: md.CommissionParam{ Commission: utils.Float64ToStr(ords[existOrd.PvdOid].Commission), @@ -196,6 +211,10 @@ func commCheckUser(eg *xorm.Engine, existOrd model.OrdList, ords map[string]md.O Oid: existOrd.PvdOid, } commissionReqList = append(commissionReqList, req) + if existOrd.ServiceUid > 0 && secondOpt != nil { + req.ServiceUid = utils.IntToStr(existOrd.ServiceUid) + secondCommissionReqList = append(secondCommissionReqList, req) + } returnMoneyReq := map[string]string{ "commission": utils.Float64ToStr(ords[existOrd.PvdOid].Commission), "goods_price": utils.Float64ToStr(ords[existOrd.PvdOid].PaidPrice), @@ -207,6 +226,7 @@ func commCheckUser(eg *xorm.Engine, existOrd model.OrdList, ords map[string]md.O } returnMoneyReqList = append(returnMoneyReqList, returnMoneyReq) commissionListArr, returnListArr := GetMoreRebateResult(eg, dbName, returnMoneyType, commissionReqList, returnMoneyReqList) + secondCommissionListArr, _ := GetMoreRebateResultService(eg, dbName, returnMoneyType, secondCommissionReqList, returnMoneyReqList) if returnMoneyType == "0" { //调用公共的分佣 @@ -216,6 +236,10 @@ func commCheckUser(eg *xorm.Engine, existOrd model.OrdList, ords map[string]md.O subsidyFee = commissionList.SubsidyFee lvUser = commissionList.LvUser profit = commissionList.Profit + secondCommissionList := secondCommissionListArr[existOrd.PvdOid] + if secondCommissionList != nil { + secondLvUser = secondCommissionList.LvUser + } } else { returnMoneyList := returnListArr[existOrd.PvdOid] var ok = true @@ -309,6 +333,9 @@ func commCheckUser(eg *xorm.Engine, existOrd model.OrdList, ords map[string]md.O } else if returnMoneyType == "1" { OrderReturnMoneyRelateInsert(eg, oid, newPvds, existOrd.CreateAt, returnMoneyOne, &existOrd, dbName, isDelete) } + if secondLvUser != nil && returnMoneyType == "0" { + OrderRelateInsertService(eg, oid, newPvds, existOrd.CreateAt, secondLvUser, &existOrd, dbName, isDelete, mode, "0") + } if oldUid == 0 && uid > 0 { //写入区域代理订单 //商家分佣 args := map[string]string{ @@ -385,6 +412,47 @@ func commRefundCoupon(eg *xorm.Engine, uid int, itemId string, state, newState i } // 免单记录修改 +func OrderRelateInsertCommService(eg *xorm.Engine, oid int64, pvd string, createTime int, lvUser *comm_plan.LvUser, newOrd *model.OrdList, masterId string, mode string) []*model.OrdListRelate { + var datas []*model.OrdListRelate + if lvUser == nil { + return datas + } + level := 0 + fmt.Println("关系链---"+utils.Int64ToStr(oid)+"---"+pvd+"---", utils.SerializeStr(lvUser)) + var ownSubsidyFee float64 = 0 + ownSubsidyFee1, ok := lvUser.OwnSubsidyFeeList["0"] + if ok { + ownSubsidyFee = ownSubsidyFee1 + } + profit := utils.FloatFormat(lvUser.Profit+lvUser.SubsidyFee+ownSubsidyFee, 9) + data := []*model.OrdListRelate{{Oid: oid, Uid: lvUser.Uid, Amount: profit, AdditionalSubsidy: utils.Float64ToStrByPrec(lvUser.AdditionalSubsidy, 9), Pvd: pvd, CreateAt: createTime, Level: level, Mode: mode, ExtendType: lvUser.ExtendType}} + for lvUser.ParentUser != nil { + lvUser = lvUser.ParentUser + fmt.Println(lvUser) + level = level + 1 + profit = utils.FloatFormat(lvUser.Profit+lvUser.SubsidyFee, 9) + var additionalSubsidy float64 = 0 + if utils.InArr(mode, []string{"lv_winery", "public_platoon"}) { + profit = utils.FloatFormat(lvUser.Profit, 6) + additionalSubsidy = lvUser.SubsidyFee + } + if lvUser.Uid == 0 { + continue + } + data = append(data, &model.OrdListRelate{ + Oid: oid, + Uid: lvUser.Uid, + Amount: profit, + Pvd: pvd, + CreateAt: createTime, + Level: level, + Mode: mode, + AdditionalSubsidy: utils.Float64ToStrByPrec(additionalSubsidy, 9), + ExtendType: lvUser.ExtendType, + }) + } + return data +} func OrderRelateInsertComm(eg *xorm.Engine, oid int64, pvd string, createTime int, lvUser *comm_plan.LvUser, newOrd *model.OrdList, masterId string, mode string) []*model.OrdListRelate { var datas []*model.OrdListRelate if lvUser == nil { @@ -607,6 +675,141 @@ func OrderRelateInsert(eg *xorm.Engine, oid int64, pvd string, createTime int, l } } +} +func OrderRelateInsertService(eg *xorm.Engine, oid int64, pvd string, createTime int, lvUser *comm_plan.LvUser, newOrd *model.OrdList, masterId string, isDelete bool, mode string, isNew string) { + + if lvUser == nil { + return + } + uid := lvUser.Uid + if uid == 0 { + return + } + oldLvUser := lvUser + oldLevel := 0 + data := OrderRelateInsertCommService(eg, oid, pvd, createTime, lvUser, newOrd, masterId, mode) + fmt.Println("=====================写入明细", newOrd.PvdOid) + fmt.Println(data) + + if data == nil || len(data) == 0 { + return + } + fmt.Println("=====================写入明细1", newOrd.PvdOid) + fmt.Println(isDelete) + //先删掉 + if isDelete { + fmt.Println("=====================写入明细2", newOrd.PvdOid) + if pvd == md.PVD_JDOwn { + db.OrderRelateDeleteByOidService(eg, oid, md.PVD_JD) + db.VirtualCoinOrderRelateDeleteByOidService(eg, oid, md.PVD_JD) + } + if pvd == md.PVD_JD { + db.OrderRelateDeleteByOidService(eg, oid, md.PVD_JDOwn) + db.VirtualCoinOrderRelateDeleteByOidService(eg, oid, md.PVD_JDOwn) + } + db.OrderRelateDeleteByOidService(eg, oid, pvd) + db.VirtualCoinOrderRelateDeleteByOidService(eg, oid, pvd) + } + if masterId == "68747754" && pvd == "taobao" { + fmt.Println("========================", utils.SerializeStr(data)) + } + //后写入 + err := db.DbInsertBatch(eg, data) + fmt.Println("=====================写入明细3", newOrd.PvdOid) + fmt.Println(err) + fmt.Println("=====================写入明细4", newOrd.PvdOid) + if err != nil { + return + } else if lvUser.ProfitList != nil { + // 插入虚拟币数据 + vcrData := CombineVirtualCoinRelateDataService(oldLvUser, oid, pvd, oldLevel, mode) + db.DbInsertBatch(eg, vcrData) + if mode == "lv_integral_release" && utils.InArr(utils.IntToStr(newOrd.State), []string{"0", "1", "2", "3"}) { + AddVirCoin(eg, oid, vcrData, masterId) + } + //for _, item := range vcrData { + // fmt.Println(item) + //} + //if err2 != nil { + // return + //} + } + if lvUser.TikTokOwnSubsidyFeeList != nil { + db.TikTokTeamOrderRelateDeleteByOid(eg, oid, pvd) + var teamData []model.TikTokTeamOrderRelate + TikTokTeamCommission := newOrd.TikTokTeamCommission + if utils.StrToFloat64(newOrd.TikTokTeamRealCommission) > 0 { + TikTokTeamCommission = newOrd.TikTokTeamRealCommission + } + for k, v := range lvUser.TikTokOwnSubsidyFeeList { + tmp := model.TikTokTeamOrderRelate{ + CoinId: utils.StrToInt(k), + Uid: uid, + Amount: utils.Float64ToStrByPrec(v, 8), + Oid: utils.Int64ToStr(oid), + Time: time.Now(), + Commission: TikTokTeamCommission, + Pvd: pvd, + } + teamData = append(teamData, tmp) + } + db.DbInsertBatch(eg, &teamData) + } + if newOrd.IsFastSign == 0 { + FastReturnCreateOrder(eg, newOrd.Uid, utils.Int64ToStr(newOrd.OrdId), masterId) + } + newOrds, _ := db.OrderListByOid(eg, newOrd.PvdOid) + if newOrds == nil { + return + } + //后台推送 + appName := db.SysCfgGetWithDb(eg, masterId, "app_name_cn") + if uid == 0 { + return + } + users, err := db.UserFindByID(eg, uid) + if users == nil || err != nil { + return + } + fmt.Println("-=========用户=========") + fmt.Println(lvUser.Uid) + fmt.Println(users) + if newOrds.IsSendMsg == 1 { //不发送 + return + } + newOrds.IsSendMsg = 1 + _, _ = db.OrdUpdateOne(eg, newOrds) + IsShowPoint := db.SysCfgGetWithDb(eg, masterId, "is_show_point") + CommissionPrec := db.SysCfgGetWithDb(eg, masterId, "commission_prec") + for _, v := range data { + var args md.PushParams + args.AppName = appName + args.Nickname = users.Nickname + args.RegNickname = users.Nickname + args.RegPhone = users.Phone + args.Pvd = md.PVD_LIST[newOrds.Pvd] + args.Payment = utils.Float64ToStr(newOrd.PaidPrice) + args.OrderNickname = users.Nickname + args.OrderNo = newOrd.PvdOid + args.OrderTime = time.Unix(int64(newOrd.CreateAt), 0).Format("2006-1-02 15:04:05") + args.Fcommission = GetCommissionPrecEg(utils.Float64ToStrByPrec(v.Amount, 8), CommissionPrec, IsShowPoint) + args.Money = GetCommissionPrecEg(utils.Float64ToStrByPrec(v.Amount, 8), CommissionPrec, IsShowPoint) + args.Uid = v.Uid + args.MasterId = masterId + args.PushType = "order_team" + if v.Level == 0 && newOrd.OrderType == 0 { + args.PushType = "order_self" + } + if v.Level == 0 && newOrd.OrderType == 1 { + args.PushType = "order_share" + } + if v.Level == 0 || v.Amount > 0 { + fmt.Println("----开始----") + fmt.Println(args) + push.CommAddPush(eg, args) + } + } + } func AddVirCoin(eg *xorm.Engine, oid int64, vcrData []*model.VirtualCoinRelate, masterId string) { integralRelease, _ := db2.IntegralReleaseGetOneByParamsEg(eg, map[string]interface{}{ @@ -719,6 +922,75 @@ func CombineVirtualCoinRelateData(lvUser *comm_plan.LvUser, oid int64, pvd strin } return data } +func CombineVirtualCoinRelateDataService(lvUser *comm_plan.LvUser, oid int64, pvd string, level int, mode string) []*model.VirtualCoinRelate { + var data []*model.VirtualCoinRelate + //可能没有极差返利 只有补贴 + profitList := lvUser.ProfitList + if len(profitList) == 0 { + profitList = lvUser.SubsidyFeeList + } + if profitList != nil { + var subsidyFeeList map[string]float64 + if lvUser.SubsidyFeeList != nil && len(lvUser.ProfitList) > 0 { + subsidyFeeList = convertList2Map(lvUser.SubsidyFeeList) + } + var coinList = make([]string, 0) + for _, v := range profitList { + coinList = append(coinList, v.Cid) + } + if utils.InArr(mode, []string{"lv_winery", "public_platoon"}) && lvUser.SubsidyFeeList != nil { //补贴类型 没有的要补上 + subsidyFeeList = convertList2Map(lvUser.SubsidyFeeList) + for _, v := range lvUser.SubsidyFeeList { + if utils.InArr(v.Cid, coinList) == false && v.Val > 0 { + v.Val = 0 + profitList = append(profitList, v) + } + } + } + for _, item := range profitList { + if item.Cid != "0" && item.Cid != "commission" { + //加上补贴 + subsidyFee := subsidyFeeList[item.Cid] + var ownSubsidyFee float64 = 0 + ownSubsidyFee1, ok := lvUser.OwnSubsidyFeeList[item.Cid] + if ok { + ownSubsidyFee = ownSubsidyFee1 + } + var additionalSubsidy float64 = 0 + profit := utils.Float64ToStrByPrec(item.Val+subsidyFee+ownSubsidyFee, 9) + if utils.InArr(mode, []string{"lv_winery", "public_platoon"}) { + profit = utils.Float64ToStrByPrec(item.Val+ownSubsidyFee, 9) + additionalSubsidy = subsidyFee + + } + if mode == "public_platoon" && level > 1 { + profit = "0" + } + if lvUser.Uid == 0 { + continue + } + var virtualCoinRelate = &model.VirtualCoinRelate{ + Oid: oid, + Uid: lvUser.Uid, + CoinId: utils.StrToInt(item.Cid), + Amount: profit, + Pvd: pvd, + CreateAt: int(time.Now().Unix()), + Level: level, + Mode: mode, + AdditionalSubsidy: utils.Float64ToStrByPrec(additionalSubsidy, 6), + ExtendType: 8, + } + data = append(data, virtualCoinRelate) + } + } + } + if lvUser.ParentUser != nil { + level += 1 + data = append(data, CombineVirtualCoinRelateDataService(lvUser.ParentUser, oid, pvd, level, mode)...) + } + return data +} func convertList2Map(a []*comm_plan.VirtualCoinCommission) (b map[string]float64) { b = make(map[string]float64) for _, i := range a { diff --git a/app/svc/svc_order_track_save_create.go b/app/svc/svc_order_track_save_create.go index 87bbfea..a517db2 100644 --- a/app/svc/svc_order_track_save_create.go +++ b/app/svc/svc_order_track_save_create.go @@ -24,7 +24,7 @@ import ( ) // 订单入库, TODO 1. 入库, 判断订单是否已经在库, 并到各个会员里面进行订单判断分润状态, 2.算利并进行分配, 所有订单都要进行拆单, 包括从智盟获取的订单 -func OrderSaveCreate(eg *xorm.Engine, pvd string, ordData *[]md.OrderInfo, opts map[string]*plan.PlanOpt, dbName string) error { +func OrderSaveCreate(eg *xorm.Engine, pvd string, ordData *[]md.OrderInfo, opts map[string]*plan.PlanOpt, secondOpts map[string]*plan.PlanOpt, dbName string) error { var ( allOrdIds []string pids []string // @@ -171,6 +171,8 @@ func OrderSaveCreate(eg *xorm.Engine, pvd string, ordData *[]md.OrderInfo, opts } var commissionReqList = make([]md.CommissionFirstParam, 0) var returnMoneyReqList = make([]map[string]string, 0) + var secondCommissionReqList = make([]md.CommissionFirstParam, 0) + for k, v := range ords { if v.StartTime < syncTime && syncTime > 0 { //根据后台的时间配置来 continue @@ -323,6 +325,13 @@ func OrderSaveCreate(eg *xorm.Engine, pvd string, ordData *[]md.OrderInfo, opts req.CommissionParam.GoodsPrice = utils.Float64ToStr(v.PaidPrice) } commissionReqList = append(commissionReqList, req) + if secondOpts[req.Provider] != nil && opts[req.Provider].PlanCommissionId > 0 { + //TODO 待确认 + req.ServiceUid = "" + if utils.StrToInt(req.ServiceUid) > 0 { + secondCommissionReqList = append(secondCommissionReqList, req) + } + } returnMoneyReq := map[string]string{ "commission": utils.Float64ToStr(v.Commission), "goods_price": utils.Float64ToStr(v.PaidPrice), @@ -336,6 +345,8 @@ func OrderSaveCreate(eg *xorm.Engine, pvd string, ordData *[]md.OrderInfo, opts } } commissionListArr, returnListArr := GetMoreRebateResult(eg, dbName, returnMoneyType, commissionReqList, returnMoneyReqList) + secondCommissionListArr, _ := GetMoreRebateResultService(eg, dbName, returnMoneyType, secondCommissionReqList, returnMoneyReqList) + // 如果不存在的订单, 则进行计算更新 for _, v := range ords { utils.FilePutContents("order", v.PvdOid) @@ -412,14 +423,20 @@ func OrderSaveCreate(eg *xorm.Engine, pvd string, ordData *[]md.OrderInfo, opts } optPvd := newPvd opt := opts[newPvd] + secondOpt := secondOpts[newPvd] + if v.Pvd == md.PVD_JDOwn && (opt == nil || (opt != nil && opt.PlanCommissionId == 0)) { opt = opts[md.PVD_JD] } + if v.Pvd == md.PVD_JDOwn && (secondOpt == nil || (secondOpt != nil && secondOpt.PlanCommissionId == 0)) { + secondOpt = secondOpts[md.PVD_JD] + } //判断是否加油 if newPvd == "oil" { var ok = true optPvd = "oilstation" opt, ok = opts["oilstation"] + secondOpt, ok = secondOpts["oilstation"] if ok == false { continue } @@ -432,6 +449,12 @@ func OrderSaveCreate(eg *xorm.Engine, pvd string, ordData *[]md.OrderInfo, opts if pvd == "kuaishou" && v.IsTikTokTeamOrder == 1 && opts["kuaishouTeam"] != nil && opts["kuaishouTeam"].PlanCommissionId > 0 { opt = opts["kuaishouTeam"] } + if (pvd == "tikTok" || pvd == "csjp") && v.IsTikTokTeamOrder == 1 && secondOpts["tikTokTeam"] != nil && secondOpts["tikTokTeam"].PlanCommissionId > 0 { + secondOpt = secondOpts["tikTokTeam"] + } + if pvd == "kuaishou" && v.IsTikTokTeamOrder == 1 && secondOpts["kuaishouTeam"] != nil && secondOpts["kuaishouTeam"].PlanCommissionId > 0 { + secondOpt = secondOpts["kuaishouTeam"] + } priceType := 0 secondPriceType := 0 if !strings.Contains(v.Pid, "moreFree") && !strings.Contains(v.Pid, "shareSeFree") && !strings.Contains(v.Pid, "seFree") && !strings.Contains(v.Pid, "cloud") && !strings.Contains(v.Pid, "share") && !strings.Contains(v.Pid, "self") && !strings.Contains(v.Pid, "free") && !strings.Contains(v.Pid, "actself") && !strings.Contains(v.Pid, "wechatactself") && !strings.Contains(v.Pid, "wechatactselfnew") && !strings.Contains(v.Pid, "wechatactshare") { @@ -484,11 +507,11 @@ func OrderSaveCreate(eg *xorm.Engine, pvd string, ordData *[]md.OrderInfo, opts var returnProfit float64 = 0 var selfRate float64 = 0 var returnMoneyOne map[string]interface{} + pvdOid := v.PvdOid if user != nil { user.OwnbuyReturnType = ownbuyReturnType //是否有自购奖励 uid = user.Uid userLv := user.Lv - pvdOid := v.PvdOid fmt.Println(optPvd) if returnMoneyType == "0" { commissionList := commissionListArr[pvdOid] @@ -556,8 +579,11 @@ func OrderSaveCreate(eg *xorm.Engine, pvd string, ordData *[]md.OrderInfo, opts newPvd = md.PVD_JD orderFormType = 1 } + //TODO 待确认 + ServiceUid := "" // 插入新订单 newOrd := &model.OrdList{ + ServiceUid: utils.StrToInt(ServiceUid), TaskType: v.TaskType, OrderFormType: orderFormType, OrdId: oid, @@ -642,6 +668,13 @@ func OrderSaveCreate(eg *xorm.Engine, pvd string, ordData *[]md.OrderInfo, opts } else if returnMoneyOne != nil && returnMoneyType == "1" { OrderReturnMoneyRelateInsert(eg, oid, newPvd, newOrd.CreateAt, returnMoneyOne, newOrd, dbName, false) } + secondCommissionList := secondCommissionListArr[pvdOid] + if secondCommissionList != nil { + secondLvUser := secondCommissionList.LvUser + if secondLvUser != nil && returnMoneyType == "0" { + OrderRelateInsertService(eg, oid, newPvd, newOrd.CreateAt, secondLvUser, newOrd, dbName, false, mode, "1") + } + } AcquisitionHookFirstOrder(eg, dbName, newOrd) if uid > 0 { //商家分佣 diff --git a/app/svc/svc_order_track_save_create_update.go b/app/svc/svc_order_track_save_create_update.go index b909036..29b1cb5 100644 --- a/app/svc/svc_order_track_save_create_update.go +++ b/app/svc/svc_order_track_save_create_update.go @@ -23,7 +23,7 @@ import ( ) // 订单入库, TODO 1. 入库, 判断订单是否已经在库, 并到各个会员里面进行订单判断分润状态, 2.算利并进行分配, 所有订单都要进行拆单, 包括从智盟获取的订单 -func OrderSaveCreateUpdate(eg *xorm.Engine, pvd string, ordData *[]md.OrderInfo, opts map[string]*plan.PlanOpt, dbName string) error { +func OrderSaveCreateUpdate(eg *xorm.Engine, pvd string, ordData *[]md.OrderInfo, opts map[string]*plan.PlanOpt, secondOpts map[string]*plan.PlanOpt, dbName string) error { var ( allOrdIds []string pids []string // @@ -411,7 +411,7 @@ func OrderSaveCreateUpdate(eg *xorm.Engine, pvd string, ordData *[]md.OrderInfo, _ = db.DbsOrderUpdate(eg, v.OrdId, &v) } //如果没有用户这里要做处理 仅针对淘宝 或美团联盟没有佣金的情况 - commCheckUser(eg, v, ords, pvd, pidToUser, opts, dbName, false, returnMoneyType) + commCheckUser(eg, v, ords, pvd, pidToUser, opts, secondOpts, dbName, false, returnMoneyType) } //处理下没有分佣明细的订单 @@ -426,7 +426,7 @@ func OrderSaveCreateUpdate(eg *xorm.Engine, pvd string, ordData *[]md.OrderInfo, result := in(v.OrdId, stationOrdIds) if result == false { //如果没有用户这里要做处理 仅针对淘宝 或美团联盟没有佣金的情况 - commCheckUser(eg, v, ords, pvd, pidToUser, opts, dbName, true, returnMoneyType) + commCheckUser(eg, v, ords, pvd, pidToUser, opts, secondOpts, dbName, true, returnMoneyType) } // 去除已存在订单 delete(ords, v.PvdOid) @@ -483,7 +483,7 @@ func OrderSaveCreateUpdate(eg *xorm.Engine, pvd string, ordData *[]md.OrderInfo, _ = db.DbsOrderUpdate(eg, v.OrdId, &v) } //如果没有用户这里要做处理 仅针对淘宝 - commCheckUser(eg, v, ords, pvd, pidToUser, opts, dbName, false, returnMoneyType) + commCheckUser(eg, v, ords, pvd, pidToUser, opts, secondOpts, dbName, false, returnMoneyType) // 去除已存在订单 delete(ords, v.PvdOid) } @@ -494,6 +494,8 @@ func OrderSaveCreateUpdate(eg *xorm.Engine, pvd string, ordData *[]md.OrderInfo, } var commissionReqList = make([]md.CommissionFirstParam, 0) var returnMoneyReqList = make([]map[string]string, 0) + var secondCommissionReqList = make([]md.CommissionFirstParam, 0) + for k, v := range ords { if v.StartTime < syncTime && syncTime > 0 { //根据后台的时间配置来 continue @@ -646,6 +648,13 @@ func OrderSaveCreateUpdate(eg *xorm.Engine, pvd string, ordData *[]md.OrderInfo, req.CommissionParam.GoodsPrice = utils.Float64ToStr(v.PaidPrice) } commissionReqList = append(commissionReqList, req) + if secondOpts[req.Provider] != nil && opts[req.Provider].PlanCommissionId > 0 { + //TODO 待确认 + req.ServiceUid = "" + if utils.StrToInt(req.ServiceUid) > 0 { + secondCommissionReqList = append(secondCommissionReqList, req) + } + } returnMoneyReq := map[string]string{ "commission": utils.Float64ToStr(v.Commission), "goods_price": utils.Float64ToStr(v.PaidPrice), @@ -659,6 +668,8 @@ func OrderSaveCreateUpdate(eg *xorm.Engine, pvd string, ordData *[]md.OrderInfo, } } commissionListArr, returnListArr := GetMoreRebateResult(eg, dbName, returnMoneyType, commissionReqList, returnMoneyReqList) + secondCommissionListArr, _ := GetMoreRebateResultService(eg, dbName, returnMoneyType, secondCommissionReqList, returnMoneyReqList) + // 如果不存在的订单, 则进行计算更新 for _, v := range ords { utils.FilePutContents("order", v.PvdOid) @@ -807,11 +818,12 @@ func OrderSaveCreateUpdate(eg *xorm.Engine, pvd string, ordData *[]md.OrderInfo, var returnProfit float64 = 0 var selfRate float64 = 0 var returnMoneyOne map[string]interface{} + pvdOid := v.PvdOid if user != nil { user.OwnbuyReturnType = ownbuyReturnType //是否有自购奖励 uid = user.Uid userLv := user.Lv - pvdOid := v.PvdOid + fmt.Println(optPvd) if returnMoneyType == "0" { commissionList := commissionListArr[pvdOid] @@ -879,8 +891,11 @@ func OrderSaveCreateUpdate(eg *xorm.Engine, pvd string, ordData *[]md.OrderInfo, newPvd = md.PVD_JD orderFormType = 1 } + //TODO 待确认 + ServiceUid := "" // 插入新订单 newOrd := &model.OrdList{ + ServiceUid: utils.StrToInt(ServiceUid), WaitSettleAt: int(v.WaitSettleAt), NumItemId: v.SkuId, TaskType: v.TaskType, @@ -966,6 +981,13 @@ func OrderSaveCreateUpdate(eg *xorm.Engine, pvd string, ordData *[]md.OrderInfo, } else if returnMoneyOne != nil && returnMoneyType == "1" { OrderReturnMoneyRelateInsert(eg, oid, newPvd, newOrd.CreateAt, returnMoneyOne, newOrd, dbName, false) } + secondCommissionList := secondCommissionListArr[pvdOid] + if secondCommissionList != nil { + secondLvUser := secondCommissionList.LvUser + if secondLvUser != nil && returnMoneyType == "0" { + OrderRelateInsertService(eg, oid, newPvd, newOrd.CreateAt, secondLvUser, newOrd, dbName, false, mode, "1") + } + } AcquisitionHookFirstOrder(eg, dbName, newOrd) if uid > 0 { //商家分佣 diff --git a/app/svc/svc_order_track_save_update.go b/app/svc/svc_order_track_save_update.go index bf03407..a0f791b 100644 --- a/app/svc/svc_order_track_save_update.go +++ b/app/svc/svc_order_track_save_update.go @@ -19,7 +19,7 @@ import ( ) // 订单入库, TODO 1. 入库, 判断订单是否已经在库, 并到各个会员里面进行订单判断分润状态, 2.算利并进行分配, 所有订单都要进行拆单, 包括从智盟获取的订单 -func OrderSaveUpdate(eg *xorm.Engine, pvd string, ordData *[]md.OrderInfo, opts map[string]*plan.PlanOpt, dbName string) error { +func OrderSaveUpdate(eg *xorm.Engine, pvd string, ordData *[]md.OrderInfo, opts map[string]*plan.PlanOpt, secondOpts map[string]*plan.PlanOpt, dbName string) error { var ( allOrdIds []string allStationOrdIds []int64 @@ -400,7 +400,7 @@ func OrderSaveUpdate(eg *xorm.Engine, pvd string, ordData *[]md.OrderInfo, opts _ = db.DbsOrderUpdate(eg, v.OrdId, &v) } //如果没有用户这里要做处理 仅针对淘宝 或美团联盟没有佣金的情况 - commCheckUser(eg, v, ords, pvd, pidToUser, opts, dbName, false, returnMoneyType) + commCheckUser(eg, v, ords, pvd, pidToUser, opts, secondOpts, dbName, false, returnMoneyType) } //处理下没有分佣明细的订单 @@ -415,7 +415,7 @@ func OrderSaveUpdate(eg *xorm.Engine, pvd string, ordData *[]md.OrderInfo, opts result := in(v.OrdId, stationOrdIds) if result == false { //如果没有用户这里要做处理 仅针对淘宝 或美团联盟没有佣金的情况 - commCheckUser(eg, v, ords, pvd, pidToUser, opts, dbName, true, returnMoneyType) + commCheckUser(eg, v, ords, pvd, pidToUser, opts, secondOpts, dbName, true, returnMoneyType) } // 去除已存在订单 delete(ords, v.PvdOid) @@ -472,7 +472,7 @@ func OrderSaveUpdate(eg *xorm.Engine, pvd string, ordData *[]md.OrderInfo, opts _ = db.DbsOrderUpdate(eg, v.OrdId, &v) } //如果没有用户这里要做处理 仅针对淘宝 - commCheckUser(eg, v, ords, pvd, pidToUser, opts, dbName, false, returnMoneyType) + commCheckUser(eg, v, ords, pvd, pidToUser, opts, secondOpts, dbName, false, returnMoneyType) // 去除已存在订单 delete(ords, v.PvdOid) } diff --git a/consume/zhios_order_track_create_for_jd_consume.go b/consume/zhios_order_track_create_for_jd_consume.go index df991ef..4d984c1 100644 --- a/consume/zhios_order_track_create_for_jd_consume.go +++ b/consume/zhios_order_track_create_for_jd_consume.go @@ -104,7 +104,7 @@ func handleZhiosOrderTrackCreateForJdConsume(msgData []byte) error { OrderData = append(OrderData, v) } msg.OrderData = &OrderData - err = svc2.OrderSaveCreate(engine, msg.Pvd, msg.OrderData, msg.Opts, msg.DbName) + err = svc2.OrderSaveCreate(engine, msg.Pvd, msg.OrderData, msg.Opts, msg.SecondOpts, msg.DbName) if err != nil { fmt.Println("order_track_create_for_Jd_ERR:::::::::::>>>>>>>>>", err.Error()) return err diff --git a/consume/zhios_order_track_create_for_pdd_consume.go b/consume/zhios_order_track_create_for_pdd_consume.go index 6b7ae68..25fb3ff 100644 --- a/consume/zhios_order_track_create_for_pdd_consume.go +++ b/consume/zhios_order_track_create_for_pdd_consume.go @@ -81,7 +81,7 @@ func handleZhiosOrderTrackCreateForPddConsume(msgData []byte) error { return nil } engine := db.DBs[msg.DbName] - err = svc2.OrderSaveCreateUpdate(engine, msg.Pvd, msg.OrderData, msg.Opts, msg.DbName) + err = svc2.OrderSaveCreateUpdate(engine, msg.Pvd, msg.OrderData, msg.Opts, msg.SecondOpts, msg.DbName) if err != nil { fmt.Println("order_track_create_for_Pdd_ERR:::::::::::>>>>>>>>>", err.Error()) return err diff --git a/consume/zhios_order_track_create_for_tb_consume.go b/consume/zhios_order_track_create_for_tb_consume.go index 942dc4a..8d4f615 100644 --- a/consume/zhios_order_track_create_for_tb_consume.go +++ b/consume/zhios_order_track_create_for_tb_consume.go @@ -81,7 +81,7 @@ func handleZhiosOrderTrackCreateForTbConsume(msgData []byte) error { return nil } engine := db.DBs[msg.DbName] - err = svc2.OrderSaveUpdate(engine, msg.Pvd, msg.OrderData, msg.Opts, msg.DbName) + err = svc2.OrderSaveUpdate(engine, msg.Pvd, msg.OrderData, msg.Opts, msg.SecondOpts, msg.DbName) if err != nil { fmt.Println("order_track_create_for_tb_ERR:::::::::::>>>>>>>>>", err.Error()) return err diff --git a/consume/zhios_order_track_create_for_tik_tok_team_consume.go b/consume/zhios_order_track_create_for_tik_tok_team_consume.go index 6e2f990..3fa40ff 100644 --- a/consume/zhios_order_track_create_for_tik_tok_team_consume.go +++ b/consume/zhios_order_track_create_for_tik_tok_team_consume.go @@ -81,7 +81,7 @@ func handleZhiosOrderTrackCreateForTikTokTeamConsume(msgData []byte) error { return nil } engine := db.DBs[msg.DbName] - err = svc2.OrderSaveCreateUpdate(engine, msg.Pvd, msg.OrderData, msg.Opts, msg.DbName) + err = svc2.OrderSaveCreateUpdate(engine, msg.Pvd, msg.OrderData, msg.Opts, msg.SecondOpts, msg.DbName) if err != nil { fmt.Println("order_track_create_for_TikTokTeam_ERR:::::::::::>>>>>>>>>", err.Error()) return err diff --git a/consume/zhios_order_track_create_for_wph_consume.go b/consume/zhios_order_track_create_for_wph_consume.go index a7d7757..62b5854 100644 --- a/consume/zhios_order_track_create_for_wph_consume.go +++ b/consume/zhios_order_track_create_for_wph_consume.go @@ -81,7 +81,7 @@ func handleZhiosOrderTrackCreateForWphConsume(msgData []byte) error { return nil } engine := db.DBs[msg.DbName] - err = svc2.OrderSaveCreateUpdate(engine, msg.Pvd, msg.OrderData, msg.Opts, msg.DbName) + err = svc2.OrderSaveCreateUpdate(engine, msg.Pvd, msg.OrderData, msg.Opts, msg.SecondOpts, msg.DbName) if err != nil { fmt.Println("order_track_create_for_Pdd_ERR:::::::::::>>>>>>>>>", err.Error()) return err diff --git a/consume/zhios_order_track_update_for_jd_consume.go b/consume/zhios_order_track_update_for_jd_consume.go index eb8d1f3..9e00dc3 100644 --- a/consume/zhios_order_track_update_for_jd_consume.go +++ b/consume/zhios_order_track_update_for_jd_consume.go @@ -81,7 +81,7 @@ func handleZhiosOrderTrackUpdateForJdConsume(msgData []byte) error { return nil } engine := db.DBs[msg.DbName] - err = svc2.OrderSaveUpdate(engine, msg.Pvd, msg.OrderData, msg.Opts, msg.DbName) + err = svc2.OrderSaveUpdate(engine, msg.Pvd, msg.OrderData, msg.Opts, msg.SecondOpts, msg.DbName) if err != nil { fmt.Println("order_track_Update_for_Jd_ERR:::::::::::>>>>>>>>>", err.Error()) return err diff --git a/consume/zhios_order_track_update_for_tb_consume.go b/consume/zhios_order_track_update_for_tb_consume.go index 192be31..be2b8c2 100644 --- a/consume/zhios_order_track_update_for_tb_consume.go +++ b/consume/zhios_order_track_update_for_tb_consume.go @@ -81,7 +81,7 @@ func handleZhiosOrderTrackUpdateForTbConsume(msgData []byte) error { return nil } engine := db.DBs[msg.DbName] - err = svc2.OrderSaveUpdate(engine, msg.Pvd, msg.OrderData, msg.Opts, msg.DbName) + err = svc2.OrderSaveUpdate(engine, msg.Pvd, msg.OrderData, msg.Opts, msg.SecondOpts, msg.DbName) if err != nil { fmt.Println("order_track_update_for_tb_ERR:::::::::::>>>>>>>>>", err.Error()) return err diff --git a/go.mod b/go.mod index 3e4b030..679a5a8 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( code.fnuoos.com/go_rely_warehouse/zyos_go_jg_push.git v1.0.5 code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git v0.0.5 code.fnuoos.com/go_rely_warehouse/zyos_go_o2o_business.git v1.0.9 - code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git v1.9.10-0.20240722064401-49d2884770db + code.fnuoos.com/go_rely_warehouse/zyos_go_order_relate_rule.git v1.9.10-0.20240803025327-ae79ed3b3a0f code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git v1.1.21-0.20240706080117-2babe132fe43 github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5 github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751