diff --git a/app/db/db_guide_order.go b/app/db/db_guide_order.go index 6581ef1..c185d08 100644 --- a/app/db/db_guide_order.go +++ b/app/db/db_guide_order.go @@ -52,6 +52,12 @@ func GetGuideOrderList(args map[string]string) []model.GuideOrder { if args["to_settle_time"] != "" { sess = sess.And("platform_settle_time 0 { ord.RealCommission = utils.Float64ToStr(float64(v.RealCommission) / 100) } + if utils.AnyToInt64(v.AfterSalesStatus) == 2 { + ord.Status = "结算后退款" + } one := db.GetGuideOrderByOne(ord.PvdOid, utils.IntToStr(ord.Uid), ord.Pvd) if one == nil { insertOne, err := db.ZhimengDb.InsertOne(ord) @@ -169,7 +173,44 @@ func OrdersTikTokChanxuanGet(page, pageSize int, sTime, eTime int64, userId stri ord.PlatformSettleTime = one.PlatformSettleTime } if one.Status == "违规订单" { - one.Status = "违规订单" + ord.Status = "违规订单" + } + if one.Status == "结算后退款" { + ord.Status = "结算后退款" + } + if ord.SettleTime > 0 && ord.Status == "结算后退款" { + ord.SettleTime = 0 + masterDb := db.MasterDb{} + masterDb.Set() + master := masterDb.GetMaster(utils.IntToStr(ord.Uid)) + if master != nil { + masterAmountDb := db.MasterAmountDb{} + masterAmountDb.Set() + amount := masterAmountDb.GetMasterAmountByExtendUid(utils.IntToStr(master.Id), utils.IntToStr(ord.ExtendUid), "playlet") + if amount != nil { + oldAmount := amount.Amount + amount.Amount = utils.Float64ToStr(utils.StrToFloat64(amount.Amount) - utils.StrToFloat64(ord.RealCommission)) + update := masterAmountDb.MasterAmountUpdate(amount.Id, amount) + if update { + var tmp = model.MasterAmountFlow{ + Uid: utils.IntToStr(ord.Uid), + Time: time.Now(), + BeforeAmount: oldAmount, + Amount: ord.RealCommission, + AfterAmount: amount.Amount, + Platform: "playlet", + Oid: utils.Int64ToStr(ord.Oid), + Title: "订单退款扣除", + FlowType: "order_refund_deduct", + IncomeType: 0, + ExtendUid: utils.IntToStr(ord.ExtendUid), + } + masterAmountFlowDb := db.MasterAmountFlowDb{} + masterAmountFlowDb.Set() + masterAmountFlowDb.MasterAmountFlowInsert(&tmp) + } + } + } } db.ZhimengDb.Where("id=?", one.Id).AllCols().Update(ord) } diff --git a/app/task/svc/svc_tik_tok_local_life_order_settle.go b/app/task/svc/svc_tik_tok_local_life_order_settle.go index ef3e511..a4e2115 100644 --- a/app/task/svc/svc_tik_tok_local_life_order_settle.go +++ b/app/task/svc/svc_tik_tok_local_life_order_settle.go @@ -20,6 +20,113 @@ func TikTokLocalLifeOrderSettle() { "status": "订单结算", "sort": "id desc", "is_to_settle": "1", + "is_not_in": "chan_xuan", + "is_commission": "1", + "to_settle_time": utils.Int64ToStr(month["start"]), + "p": "1", + "size": "100", + } + order := db.GetGuideOrderList(arg) + if len(order) == 0 { + return + } + fmt.Println(utils.SerializeStr(order)) + platformMap := map[string]string{ + "tikTok_life": "抖音本地生活", + "csjp": "穿山甲抖音", + "csjp_live": "穿山甲抖音直播商品", + "kuaishou": "快手", + "kuaishou_live": "快手直播商品", + "meituan": "美团", + "own_ele": "饿了么", + } + for _, v := range order { + fmt.Println("=================00") + // 加锁 防止并发提取 + mutexKey := fmt.Sprintf("guide_order_settle3:%d", v.Id) + withdrawAvailable, err := cache.Do("SET", mutexKey, 1, "EX", 1800, "NX") + if err != nil { + fmt.Println("=================0") + + fmt.Println(err) + continue + } + if withdrawAvailable != "OK" { + fmt.Println("=================1") + + continue + } + if v.SettleTime > 0 { + fmt.Println("=================2") + + continue + } + //加到上月结算 + if v.Uid == 0 { + fmt.Println("=================3") + + continue + } + masterDb := db.MasterDb{} + masterDb.Set() + master := masterDb.GetMaster(utils.IntToStr(v.Uid)) + if master == nil { + fmt.Println("=================4") + + continue + } + masterAmountDb := db.MasterAmountDb{} + masterAmountDb.Set() + amount := masterAmountDb.GetMasterAmountByExtendUid(utils.IntToStr(master.Id), utils.IntToStr(v.ExtendUid), "playlet") + if amount == nil { + fmt.Println("=================5") + continue + } + if utils.StrToFloat64(v.RealCommission) <= 0 { + v.SettleTime = int(time.Now().Unix()) + db.ZhimengDb.Where("id=?", v.Id).Update(&v) + continue + } + oldAmount := amount.LastMonthAmount + amount.LastMonthAmount = utils.Float64ToStr(utils.StrToFloat64(amount.LastMonthAmount) + utils.StrToFloat64(v.RealCommission)) + update := masterAmountDb.MasterAmountUpdate(amount.Id, amount) + if update == false { + fmt.Println("=================7") + + continue + } + var tmp = model.MasterLastMonthAmountFlow{ + Uid: utils.IntToStr(master.Id), + Time: time.Now(), + BeforeAmount: oldAmount, + Amount: v.RealCommission, + AfterAmount: amount.LastMonthAmount, + Platform: v.Pvd, + Oid: utils.Int64ToStr(v.Oid), + Title: platformMap[v.Pvd] + "结算", + FlowType: v.Pvd + "_settle", + ExtendUid: utils.IntToStr(v.ExtendUid), + } + masterLastMonthAmountFlowDb := db.MasterLastMonthAmountFlowDb{} + masterLastMonthAmountFlowDb.Set() + masterLastMonthAmountFlowDb.MasterLastMonthAmountFlowInsert(&tmp) + v.SettleTime = int(time.Now().Unix()) + db.ZhimengDb.Where("id=?", v.Id).Update(&v) + } + return +} +func ChanxuanOrderSettle() { + day := time.Now().Day() + if day < 28 { + return + } + month := utils.GetTimeRange("current_month") + fmt.Println(month) + arg := map[string]string{ + "status": "订单结算", + "sort": "id desc", + "is_to_settle": "1", + "is_in": "chan_xuan", "is_commission": "1", "to_settle_time": utils.Int64ToStr(month["start"]), "p": "1", diff --git a/app/task/task_chan_xuan_order_settle.go b/app/task/task_chan_xuan_order_settle.go new file mode 100644 index 0000000..9efdafc --- /dev/null +++ b/app/task/task_chan_xuan_order_settle.go @@ -0,0 +1,21 @@ +package task + +import ( + "applet/app/task/svc" + "math/rand" + "time" +) + +func taskChanxuanOrderSettle() { + for { + if len(ch) > workerNum { + time.Sleep(time.Millisecond * time.Duration(rand.Intn(1000))) + } else { + goto START + } + } +START: + ch <- 1 + svc.ChanxuanOrderSettle() + <-ch +} diff --git a/go.mod b/go.mod index e4dd27d..696ca3b 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.15 require ( code.fnuoos.com/go_rely_warehouse/zyos_go_es.git v1.0.1-0.20230707081910-52e70aa52998 - code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git v1.1.21-0.20241022083957-0babff5f367b + code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git v1.1.21-0.20241023030432-34a00dfd6f1a github.com/360EntSecGroup-Skylar/excelize v1.4.1 github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5 github.com/boombuler/barcode v1.0.1