@@ -0,0 +1,109 @@ | |||
package db | |||
import ( | |||
"applet/app/db/model" | |||
"applet/app/utils" | |||
"fmt" | |||
) | |||
func GetLifeOrderByOne(oid, mid, types string) *model.LifeOrder { | |||
var data model.LifeOrder | |||
get, err := ZhimengDb.Where("uid=? and pvd_oid=? and pvd=?", mid, oid, types).Get(&data) | |||
if get == false || err != nil { | |||
fmt.Println(err) | |||
return nil | |||
} | |||
return &data | |||
} | |||
func GetLifeOrderList(args map[string]string) []model.LifeOrder { | |||
/*** | |||
p 页数 | |||
size 个数 | |||
start_time 开始时间 | |||
end_time 结束时间 | |||
ord_type 订单类型 | |||
video_type 视频类型 | |||
status 订单状态 | |||
settle_status 结算状态 | |||
oid 订单号 | |||
sort 排序 | |||
is_to_settle 智盟结算 | |||
to_settle_time 结算上月时间 | |||
*/ | |||
var data = make([]model.LifeOrder, 0) | |||
size := utils.StrToInt(args["size"]) | |||
offet := (utils.StrToInt(args["p"]) - 1) * size | |||
sess := ZhimengDb.Where("1=1") | |||
if args["start_time"] != "" { | |||
sess = sess.And("update_time>=?", args["start_time"]) | |||
} | |||
if args["end_time"] != "" { | |||
sess = sess.And("update_time<=?", args["end_time"]) | |||
} | |||
if args["type"] != "" { | |||
sess = sess.And("pvd=?", args["type"]) | |||
} | |||
if args["uid"] != "" { | |||
sess = sess.And("uid=?", args["uid"]) | |||
} | |||
if args["status"] != "" { | |||
sess = sess.And("status=?", args["status"]) | |||
} | |||
if args["to_settle_time"] != "" { | |||
sess = sess.And("platform_settle_time<?", args["to_settle_time"]) | |||
} | |||
sort := "update_time desc,id desc" | |||
if args["sort"] != "" { | |||
sort = args["sort"] | |||
} | |||
if args["is_to_settle"] == "1" { | |||
sess = sess.And("settle_time=?", 0) | |||
} | |||
if args["is_commission"] == "1" { | |||
sess = sess.And("real_commission>?", 0) | |||
} | |||
err := sess.Limit(size, offet).OrderBy(sort).Find(&data) | |||
fmt.Println(err) | |||
fmt.Println(sess.LastSQL()) | |||
return data | |||
} | |||
func GetLifeOrderListTotal(args map[string]string) ([]model.LifeOrder, int64) { | |||
var data = make([]model.LifeOrder, 0) | |||
size := utils.StrToInt(args["size"]) | |||
offet := (utils.StrToInt(args["p"]) - 1) * size | |||
sess := ZhimengDb.Where("1=1") | |||
if args["start_time"] != "" { | |||
sess = sess.And("create_time>=?", utils.TimeStdParseUnix(args["start_time"])) | |||
} | |||
if args["end_time"] != "" { | |||
sess = sess.And("create_time<=?", utils.TimeStdParseUnix(args["end_time"])) | |||
} | |||
if args["type"] != "" { | |||
sess = sess.And("pvd=?", args["type"]) | |||
} | |||
if args["settle_type"] == "0" { | |||
sess = sess.And("settle_time=?", 0) | |||
} | |||
if args["settle_type"] == "1" { | |||
sess = sess.And("settle_time>?", 0) | |||
} | |||
if args["uid"] != "" { | |||
sess = sess.And("uid=?", args["uid"]) | |||
} | |||
if args["zuid"] != "" { | |||
sess = sess.And("station_uid=?", args["zuid"]) | |||
} | |||
if args["status"] != "" { | |||
sess = sess.And("status=?", args["status"]) | |||
} | |||
sort := "create_time desc,id desc" | |||
if args["sort"] != "" { | |||
sort = args["sort"] | |||
} | |||
total, err := sess.Limit(size, offet).OrderBy(sort).FindAndCount(&data) | |||
fmt.Println(err) | |||
fmt.Println(sess.LastSQL()) | |||
return data, total | |||
} |
@@ -0,0 +1,27 @@ | |||
package model | |||
type LifeOrder struct { | |||
Id int `json:"id" xorm:"not null pk autoincr INT(11)"` | |||
Oid int64 `json:"oid" xorm:"default 0 BIGINT(20)"` | |||
Uid int `json:"uid" xorm:"default 0 INT(11)"` | |||
ExtendUid int `json:"extend_uid" xorm:"default 0 INT(11)"` | |||
StationUid int `json:"station_uid" xorm:"default 0 INT(11)"` | |||
PvdOid string `json:"pvd_oid" xorm:"VARCHAR(100)"` | |||
PvdParentOid string `json:"pvd_parent_oid" xorm:"VARCHAR(100)"` | |||
Status string `json:"status" xorm:"VARCHAR(100)"` | |||
CreateTime int `json:"create_time" xorm:"default 0 INT(11)"` | |||
UpdateTime int `json:"update_time" xorm:"default 0 INT(11)"` | |||
SettleTime int `json:"settle_time" xorm:"default 0 INT(11)"` | |||
PlatformSettleTime int `json:"platform_settle_time" xorm:"default 0 INT(11)"` | |||
Commission string `json:"commission" xorm:"default 0.00 DECIMAL(20,2)"` | |||
RealCommission string `json:"real_commission" xorm:"default 0.00 DECIMAL(20,2)"` | |||
Title string `json:"title" xorm:"VARCHAR(255)"` | |||
Payment string `json:"payment" xorm:"default 0.00 DECIMAL(20,2)"` | |||
Pvd string `json:"pvd" xorm:"VARCHAR(255)"` | |||
Img string `json:"img" xorm:"VARCHAR(255)"` | |||
IsShare int `json:"is_share" xorm:"default 0 INT(1)"` | |||
Ext string `json:"ext" xorm:"VARCHAR(3000)"` | |||
Gid string `json:"gid" xorm:"VARCHAR(255)"` | |||
TeamType string `json:"team_type" xorm:"VARCHAR(255)"` | |||
TaskType string `json:"task_type" xorm:"VARCHAR(255)"` | |||
} |
@@ -119,5 +119,6 @@ func initTasks() { | |||
jobs[taskMd.ZhimengCronKuaishouOrder] = taskKuaishouOrder // | |||
jobs[taskMd.ZhimengCronKuaishouAuth] = taskKuaishouAuth // | |||
jobs[taskMd.ZhimengCronMeituanOrder] = taskMeituanOrder // | |||
jobs[taskMd.ZhimengCronLifeOrderSettle] = taskLifeOrderSettle // | |||
} |
@@ -44,4 +44,5 @@ const ( | |||
ZhimengCronKuaishouAuth = "zhimeng_cron_kuaishou_auth" | |||
ZhimengCronTikTokLocalLifeOrder = "zhimeng_cron_tik_tok_local_life_order" | |||
ZhimengCronTikTokLocalLifeOrderSettle = "zhimeng_cron_tik_tok_local_life_order_settle" | |||
ZhimengCronLifeOrderSettle = "zhimeng_cron_life_order_settle" | |||
) |
@@ -0,0 +1,115 @@ | |||
package svc | |||
import ( | |||
"applet/app/db" | |||
"applet/app/db/model" | |||
"applet/app/utils" | |||
"applet/app/utils/cache" | |||
"fmt" | |||
"time" | |||
) | |||
func LifeOrderSettle() { | |||
day := time.Now().Day() | |||
if day < 20 { | |||
return | |||
} | |||
month := utils.GetTimeRange("current_month") | |||
fmt.Println(month) | |||
arg := map[string]string{ | |||
"status": "订单结算", | |||
"sort": "id desc", | |||
"is_to_settle": "1", | |||
"is_commission": "1", | |||
"to_settle_time": utils.Int64ToStr(month["start"]), | |||
"p": "1", | |||
"size": "100", | |||
} | |||
order := db.GetLifeOrderList(arg) | |||
if len(order) == 0 { | |||
return | |||
} | |||
fmt.Println(utils.SerializeStr(order)) | |||
platformMap := map[string]string{ | |||
"tikTok_life": "抖音本地生活", | |||
"csjp": "穿山甲抖音", | |||
"csjp_live": "穿山甲抖音直播商品", | |||
"kuaishou": "快手", | |||
"kuaishou_live": "快手直播商品", | |||
"meituan": "美团", | |||
} | |||
for _, v := range order { | |||
fmt.Println("=================00") | |||
// 加锁 防止并发提取 | |||
mutexKey := fmt.Sprintf("life_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 | |||
} |
@@ -128,7 +128,7 @@ func OrdersMeituanGet(nextPositionIndex string, pageSize int, sTime, eTime int64 | |||
"6": "订单结算", | |||
} | |||
for _, v := range list { | |||
var res = model.GuideOrder{ | |||
var res = model.LifeOrder{ | |||
PvdParentOid: v.OrderId, | |||
Pvd: "meituan", | |||
Status: meituanState[v.Status], | |||
@@ -157,8 +157,8 @@ func OrdersMeituanGet(nextPositionIndex string, pageSize int, sTime, eTime int64 | |||
if len(orderDetail) > 0 { | |||
allEnd := "1" | |||
for k1, v1 := range orderDetail { | |||
v2, ok := v1.(map[string]interface{}) | |||
if ok { | |||
v2, ok1 := v1.(map[string]interface{}) | |||
if ok1 { | |||
if k1 == 0 { | |||
state = utils.AnyToString(v2["couponStatus"]) | |||
} | |||
@@ -190,7 +190,7 @@ func OrdersMeituanGet(nextPositionIndex string, pageSize int, sTime, eTime int64 | |||
res.Gid = v.ProductId | |||
res.IsShare = orderType | |||
res.Payment = v.PayPrice | |||
one := db.GetGuideOrderByOne(res.PvdOid, utils.IntToStr(res.Uid), res.Pvd) | |||
one := db.GetLifeOrderByOne(res.PvdOid, utils.IntToStr(res.Uid), res.Pvd) | |||
if one == nil { | |||
insertOne, err := db.ZhimengDb.InsertOne(&res) | |||
fmt.Println(insertOne) | |||
@@ -0,0 +1,21 @@ | |||
package task | |||
import ( | |||
"applet/app/task/svc" | |||
"math/rand" | |||
"time" | |||
) | |||
func taskLifeOrderSettle() { | |||
for { | |||
if len(ch) > workerNum { | |||
time.Sleep(time.Millisecond * time.Duration(rand.Intn(1000))) | |||
} else { | |||
goto START | |||
} | |||
} | |||
START: | |||
ch <- 1 | |||
svc.LifeOrderSettle() | |||
<-ch | |||
} |