@@ -0,0 +1,109 @@ | |||
package db | |||
import ( | |||
"applet/app/db/model" | |||
"applet/app/utils" | |||
"fmt" | |||
) | |||
func GetGuideOrderByOne(oid, mid, types string) *model.GuideOrder { | |||
var data model.GuideOrder | |||
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 GetGuideOrderList(args map[string]string) []model.GuideOrder { | |||
/*** | |||
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.GuideOrder, 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("create_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 GetGuideOrderListTotal(args map[string]string) ([]model.GuideOrder, int64) { | |||
var data = make([]model.GuideOrder, 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>=?", args["start_time"]) | |||
} | |||
if args["end_time"] != "" { | |||
sess = sess.And("create_time<=?", 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,24 @@ | |||
package model | |||
type GuideOrder 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.0000 DECIMAL(20,4)"` | |||
RealCommission string `json:"real_commission" xorm:"default 0.0000 DECIMAL(20,4)"` | |||
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)"` | |||
} |
@@ -0,0 +1,66 @@ | |||
package zhimeng_platform | |||
import ( | |||
"applet/app/e" | |||
"applet/app/svc/platform" | |||
"applet/app/utils" | |||
"github.com/gin-gonic/gin" | |||
) | |||
func GuideOrderList(c *gin.Context) { | |||
var args map[string]string | |||
if err := c.ShouldBindJSON(&args); err != nil { | |||
e.OutErr(c, e.ERR_INVALID_ARGS, err) | |||
return | |||
} | |||
platformMap := map[string]string{ | |||
"tikTok_life": "抖音本地生活", | |||
} | |||
data, total := platform.GuideOrderList(c, args) | |||
var sourceList []map[string]string | |||
for k, v := range platformMap { | |||
tmp := map[string]string{ | |||
"name": v, "value": k, | |||
} | |||
sourceList = append(sourceList, tmp) | |||
} | |||
statusList := []map[string]string{ | |||
{"name": "订单付款", "value": "订单付款"}, | |||
{"name": "部分核销", "value": "部分核销"}, | |||
{"name": "订单成功", "value": "订单成功"}, | |||
{"name": "订单结算", "value": "订单结算"}, | |||
{"name": "订单退款", "value": "订单退款"}, | |||
{"name": "部分退款", "value": "部分退款"}, | |||
} | |||
settleStatusList := []map[string]string{ | |||
{"name": "未结算", "value": "未结算"}, | |||
{"name": "已结算", "value": "已结算"}, | |||
} | |||
var res = map[string]interface{}{ | |||
"list": data, | |||
"total": total, | |||
"source_list": sourceList, | |||
"status_list": statusList, | |||
"settle_status_list": settleStatusList, | |||
} | |||
e.OutSuc(c, res, nil) | |||
return | |||
} | |||
func GuideOrderOutput(c *gin.Context) { | |||
var args map[string]string | |||
if err := c.ShouldBindJSON(&args); err != nil { | |||
e.OutErr(c, e.ERR_INVALID_ARGS, err) | |||
return | |||
} | |||
name, data := platform.GuideOrderOutput(c, args) | |||
file := utils.Output(c, name, data) | |||
filename := name + ".xlsx" | |||
r := map[string]string{ | |||
"file": file, | |||
"filename": filename, | |||
} | |||
e.OutSuc(c, r, nil) | |||
return | |||
} |
@@ -0,0 +1,64 @@ | |||
package zhimeng_platform | |||
import ( | |||
"applet/app/e" | |||
"applet/app/svc/platform" | |||
"applet/app/utils" | |||
"github.com/gin-gonic/gin" | |||
) | |||
func HwOrderList(c *gin.Context) { | |||
var args map[string]string | |||
if err := c.ShouldBindJSON(&args); err != nil { | |||
e.OutErr(c, e.ERR_INVALID_ARGS, err) | |||
return | |||
} | |||
platformMap := map[string]string{ | |||
"starbucks": "星巴克", "movie": "电影", "mcdonald": "麦当劳", "nayuki": "奈雪", "luckin": "瑞幸咖啡", "pizza": "必胜客", | |||
"pagoda": "百果园", "burger_king": "汉堡王", "heytea": "喜茶", "to_kfc": "肯德基", "wallace": "华莱士", "flowerCake": "鲜花", "delivery": "比价寄", "tourism": "出游", | |||
} | |||
data, total := platform.HwOrderList(c, args) | |||
var sourceList []map[string]string | |||
for k, v := range platformMap { | |||
tmp := map[string]string{ | |||
"name": v, "value": k, | |||
} | |||
sourceList = append(sourceList, tmp) | |||
} | |||
statusList := []map[string]string{ | |||
{"name": "订单付款", "value": "订单付款"}, | |||
{"name": "订单成功", "value": "订单成功"}, | |||
{"name": "订单结算", "value": "订单结算"}, | |||
} | |||
settleStatusList := []map[string]string{ | |||
{"name": "未结算", "value": "未结算"}, | |||
{"name": "已结算", "value": "已结算"}, | |||
} | |||
var res = map[string]interface{}{ | |||
"list": data, | |||
"total": total, | |||
"source_list": sourceList, | |||
"status_list": statusList, | |||
"settle_status_list": settleStatusList, | |||
} | |||
e.OutSuc(c, res, nil) | |||
return | |||
} | |||
func HwOrderOutput(c *gin.Context) { | |||
var args map[string]string | |||
if err := c.ShouldBindJSON(&args); err != nil { | |||
e.OutErr(c, e.ERR_INVALID_ARGS, err) | |||
return | |||
} | |||
name, data := platform.HwOrderOutput(c, args) | |||
file := utils.Output(c, name, data) | |||
filename := name + ".xlsx" | |||
r := map[string]string{ | |||
"file": file, | |||
"filename": filename, | |||
} | |||
e.OutSuc(c, r, nil) | |||
return | |||
} |
@@ -74,6 +74,11 @@ func routeZhimeng(r *gin.RouterGroup) { | |||
{ | |||
r.POST("/order_list", platformHdl.OrderList) | |||
r.POST("/order_output", platformHdl.OrderOutput) | |||
r.POST("/hw_order_list", platformHdl.HwOrderList) | |||
r.POST("/hw_order_output", platformHdl.HwOrderOutput) | |||
r.POST("/guide_order_list", platformHdl.GuideOrderList) | |||
r.POST("/guide_order_output", platformHdl.GuideOrderOutput) | |||
r.POST("/withdrawal_income", platformHdl.WithdrawalIncome) | |||
r.POST("/withdrawal_bind_alipay", platformHdl.WithdrawalBindAlipay) | |||
r.POST("/withdrawal_list", platformHdl.WithdrawalList) | |||
@@ -0,0 +1,92 @@ | |||
package platform | |||
import ( | |||
"applet/app/db" | |||
"applet/app/utils" | |||
"github.com/gin-gonic/gin" | |||
"time" | |||
) | |||
func GuideOrderList(c *gin.Context, args map[string]string) ([]map[string]string, int64) { | |||
masterId, _ := c.Get("master_id") | |||
args["uid"] = utils.AnyToString(masterId) | |||
list, total := db.GetGuideOrderListTotal(args) | |||
var data = make([]map[string]string, 0) | |||
platformMap := map[string]string{ | |||
"tikTok_life": "抖音本地生活", | |||
} | |||
if len(list) > 0 { | |||
for _, v := range list { | |||
settleStatus := "未结算" | |||
settleTime := "-" | |||
if v.SettleTime > 0 { | |||
settleStatus = "已结算" | |||
settleTime = time.Unix(int64(v.SettleTime), 0).Format("2006-01-02 15:04:05") | |||
} | |||
var tmp = map[string]string{ | |||
"oid": v.PvdOid, | |||
"uid": utils.IntToStr(v.StationUid), | |||
"title": v.Title, | |||
"platform_fee": "0", | |||
"commission_bili": "", | |||
"source": platformMap[v.Pvd], | |||
"amount": v.Payment, | |||
"commission": v.Commission, | |||
"real_commission": v.RealCommission, | |||
"status": v.Status, | |||
"settle_status": settleStatus, | |||
"create_time": time.Unix(int64(v.CreateTime), 0).Format("2006-01-02 15:04:05"), | |||
"settle_time": settleTime, | |||
} | |||
data = append(data, tmp) | |||
} | |||
} | |||
return data, total | |||
} | |||
func GuideOrderOutput(c *gin.Context, args map[string]string) (string, map[string]string) { | |||
masterId, _ := c.Get("master_id") | |||
args["mid"] = utils.AnyToString(masterId) | |||
args["size"] = "3000" | |||
if args["ids"] != "" { | |||
args["size"] = "0" | |||
} | |||
name := "订单_" + args["p"] | |||
//写入数据 | |||
data := map[string]string{ | |||
"A1": "订单号", | |||
"B1": "会员ID", | |||
"C1": "标题", | |||
"D1": "来源", | |||
"E1": "结算时间", | |||
"F1": "订单状态", | |||
"G1": "金额", | |||
"H1": "预估佣金", | |||
"I1": "实际佣金", | |||
} | |||
platformMap := map[string]string{ | |||
"tikTok_life": "抖音本地生活", | |||
} | |||
list, _ := db.GetGuideOrderListTotal(args) | |||
if len(list) > 0 { | |||
for k, v := range list { | |||
settleTime := "-" | |||
if v.SettleTime > 0 { | |||
settleTime = time.Unix(int64(v.SettleTime), 0).Format("2006-01-02 15:04:05") | |||
} | |||
i := utils.IntToStr(k + 2) | |||
data["A"+i] = v.PvdOid | |||
data["B"+i] = utils.IntToStr(v.StationUid) | |||
data["C"+i] = v.Title | |||
data["D"+i] = platformMap[v.Pvd] | |||
data["E"+i] = settleTime | |||
data["F"+i] = v.Status | |||
data["G"+i] = v.Payment | |||
data["H"+i] = v.Commission | |||
data["I"+i] = v.RealCommission | |||
} | |||
} | |||
return name, data | |||
} |
@@ -108,5 +108,7 @@ func initTasks() { | |||
jobs[taskMd.ZhimengCronHwFlowerCakeOrder] = taskHwFlowerCakeOrder // | |||
jobs[taskMd.ZhimengCronHwDeliveryOrder] = taskHwDeliveryOrder // | |||
jobs[taskMd.ZhimengCronHwTourismOrder] = taskHwTourismOrder // | |||
jobs[taskMd.ZhimengCronTikTokLocalLifeOrder] = taskTikTokLocalLifeOrder // | |||
jobs[taskMd.ZhimengCronTikTokLocalLifeOrderSettle] = taskTikTokLocalLifeOrderSettle // | |||
} |
@@ -10,21 +10,23 @@ const ( | |||
ZhimengCronPlayletAdvOrderYesterDayToMoney = "zhimeng_cron_playlet_adv_order_yesterday_to_money" | |||
ZhimengCronPlayletGoods = "zhimeng_cron_playlet_goods" | |||
ZhimengCronPlayletOrderSettle = "zhimeng_cron_playlet_order_settle" | |||
ZhimengCronHwOrderSettle = "zhimeng_cron_hw_order_settle" | |||
ZhimengCronMasterMonthSettle = "zhimeng_cron_master_month_settle" | |||
ZhimengCronHwStarbucksOrder = "zhimeng_cron_hw_starbucks_order" | |||
ZhimengCronHwMovieOrder = "zhimeng_cron_hw_movie_order" | |||
ZhimengCronHwMcdonaldOrder = "zhimeng_cron_hw_mcdonald_order" | |||
ZhimengCronHwNayukiOrder = "zhimeng_cron_hw_nayuki_order" | |||
ZhimengCronHwLuckinOrder = "zhimeng_cron_hw_luckin_order" | |||
ZhimengCronHwPizzaOrder = "zhimeng_cron_hw_pizza_order" | |||
ZhimengCronHwPagodaOrder = "zhimeng_cron_hw_pagoda_order" | |||
ZhimengCronHwBurgerKingOrder = "zhimeng_cron_hw_burger_king_order" | |||
ZhimengCronHwHeyteaOrder = "zhimeng_cron_hw_heytea_order" | |||
ZhimengCronHwToKfcOrder = "zhimeng_cron_hw_to_kfc_order" | |||
ZhimengCronHwWallaceOrder = "zhimeng_cron_hw_wallace_order" | |||
ZhimengCronHwFlowerCakeOrder = "zhimeng_cron_hw_flowerCake_order" | |||
ZhimengCronHwDeliveryOrder = "zhimeng_cron_hw_delivery_order" | |||
ZhimengCronHwTourismOrder = "zhimeng_cron_hw_tourism_order" | |||
ZhimengCronPlayletOrderSettle = "zhimeng_cron_playlet_order_settle" | |||
ZhimengCronHwOrderSettle = "zhimeng_cron_hw_order_settle" | |||
ZhimengCronMasterMonthSettle = "zhimeng_cron_master_month_settle" | |||
ZhimengCronHwStarbucksOrder = "zhimeng_cron_hw_starbucks_order" | |||
ZhimengCronHwMovieOrder = "zhimeng_cron_hw_movie_order" | |||
ZhimengCronHwMcdonaldOrder = "zhimeng_cron_hw_mcdonald_order" | |||
ZhimengCronHwNayukiOrder = "zhimeng_cron_hw_nayuki_order" | |||
ZhimengCronHwLuckinOrder = "zhimeng_cron_hw_luckin_order" | |||
ZhimengCronHwPizzaOrder = "zhimeng_cron_hw_pizza_order" | |||
ZhimengCronHwPagodaOrder = "zhimeng_cron_hw_pagoda_order" | |||
ZhimengCronHwBurgerKingOrder = "zhimeng_cron_hw_burger_king_order" | |||
ZhimengCronHwHeyteaOrder = "zhimeng_cron_hw_heytea_order" | |||
ZhimengCronHwToKfcOrder = "zhimeng_cron_hw_to_kfc_order" | |||
ZhimengCronHwWallaceOrder = "zhimeng_cron_hw_wallace_order" | |||
ZhimengCronHwFlowerCakeOrder = "zhimeng_cron_hw_flowerCake_order" | |||
ZhimengCronHwDeliveryOrder = "zhimeng_cron_hw_delivery_order" | |||
ZhimengCronHwTourismOrder = "zhimeng_cron_hw_tourism_order" | |||
ZhimengCronTikTokLocalLifeOrder = "zhimeng_cron_tik_tok_local_life_order" | |||
ZhimengCronTikTokLocalLifeOrderSettle = "zhimeng_cron_tik_tok_local_life_order_settle" | |||
) |
@@ -0,0 +1,34 @@ | |||
package md | |||
type TikTokLocalLifeOrder struct { | |||
Cursor string `json:"cursor"` | |||
HasMore bool `json:"has_more"` | |||
ItemOrders []TikTokLocalLifeOrderDetail `json:"item_orders"` | |||
} | |||
type TikTokLocalLifeOrderDetail struct { | |||
Status int `json:"status"` | |||
UpdateTime int `json:"update_time"` | |||
CommissionInfo struct { | |||
AllSettleRemitFinish bool `json:"all_settle_remit_finish"` | |||
CommissionRate int `json:"commission_rate"` | |||
DistributionInfo struct { | |||
ExternalInfo string `json:"external_info"` | |||
Pid string `json:"pid"` | |||
} `json:"distribution_info"` | |||
EstimateCommission int `json:"estimate_commission"` | |||
SettleInfoMap map[string]interface{} `json:"settle_info_map"` | |||
} `json:"commission_info"` | |||
ItemOrderId string `json:"item_order_id"` | |||
PayAmount int `json:"pay_amount"` | |||
PayTime int `json:"pay_time"` | |||
ProductList []struct { | |||
SkuId int64 `json:"sku_id"` | |||
Count int `json:"count"` | |||
Img string `json:"img"` | |||
Name string `json:"name"` | |||
ProductId int64 `json:"product_id"` | |||
} `json:"product_list"` | |||
RootOrderInfo struct { | |||
RootOrderId string `json:"root_order_id"` | |||
} `json:"root_order_info"` | |||
} |
@@ -0,0 +1,166 @@ | |||
package svc | |||
import ( | |||
"applet/app/db" | |||
"applet/app/db/model" | |||
offical "applet/app/db/official" | |||
"applet/app/task/md" | |||
"applet/app/utils" | |||
"applet/app/utils/cache" | |||
"code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/tik_tok" | |||
zhios_third_party_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/utils" | |||
"encoding/json" | |||
"fmt" | |||
"github.com/tidwall/gjson" | |||
"strings" | |||
"time" | |||
) | |||
func TikTokLocalLifeOrder() { | |||
all := offical.MasterListCfgGetKeyAll("tik_tok_open_appkey") | |||
if all == nil { | |||
return | |||
} | |||
for _, v := range *all { | |||
if v.V == "" { | |||
continue | |||
} | |||
data := offical.MasterListCfgGetOneData(v.Uid, "tik_tok_open") | |||
if data != "1" && utils.StrToInt(v.Uid) > 0 { | |||
continue | |||
} | |||
p := "" | |||
for true { | |||
_, curor, hasMore := GetTikTokLocalLifeOrder(p, v.Uid) | |||
if hasMore == false { | |||
break | |||
} | |||
p = curor | |||
} | |||
} | |||
} | |||
func TikTokToken(uid string) string { | |||
tikTokOpenAppkey := offical.MasterListCfgGetOneData(uid, "tik_tok_open_appkey") | |||
tikTokOpenAppSecret := offical.MasterListCfgGetOneData(uid, "tik_tok_open_app_secret") | |||
args := map[string]string{ | |||
"appkey": tikTokOpenAppkey, | |||
"appSecret": tikTokOpenAppSecret, | |||
} | |||
key := "tikTok_client_" + args["appkey"] | |||
tokeStr, err := cache.GetString(key) | |||
if tokeStr == "" || err != nil { | |||
token := tik_tok.GetClientToken(args) | |||
if token["tik_tok_acc_token"] != "" { | |||
tokeStr = token["tik_tok_acc_token"] | |||
cache.SetEx(key, token["tik_tok_acc_token"], utils.StrToInt(token["expires_in"])) | |||
} | |||
} | |||
return tokeStr | |||
} | |||
func GetTikTokLocalLifeOrder(p string, uid string) (int, string, bool) { | |||
tikTokOpenUid := offical.MasterListCfgGetOneData(uid, "tik_tok_open_uid") | |||
endTime := time.Now().Unix() | |||
startTime := endTime - 86400 | |||
param := map[string]interface{}{ | |||
"uid": tikTokOpenUid, | |||
"cursor": p, | |||
"count": "50", | |||
"update_time_begin": startTime, | |||
"update_time_end": endTime, | |||
} | |||
fmt.Println(param) | |||
api, _ := tik_tok.LocalApi("query_order/", TikTokToken(uid), zhios_third_party_utils.SerializeStr(param)) | |||
count := 0 | |||
data := gjson.Get(api, "data").String() | |||
if data != "" { | |||
var list = md.TikTokLocalLifeOrder{} | |||
json.Unmarshal([]byte(data), &list) | |||
count = len(list.ItemOrders) | |||
for _, v := range list.ItemOrders { | |||
AddTikTokLocalLifeOrder(v) | |||
} | |||
return count, list.Cursor, list.HasMore | |||
} | |||
return count, "", false | |||
} | |||
func AddTikTokLocalLifeOrder(order md.TikTokLocalLifeOrderDetail) { | |||
statusArr := map[int]string{1: "订单付款", 2: "订单退款", 3: "订单成功", 4: "部分核销", 5: "部分退款"} | |||
userId := order.CommissionInfo.DistributionInfo.ExternalInfo | |||
isShare := 0 | |||
if strings.Contains(utils.AnyToString(userId), "s") { | |||
isShare = 1 | |||
} | |||
split := strings.Split(utils.AnyToString(userId), "_") | |||
if len(split) < 3 { | |||
return | |||
} | |||
mid := split[2] | |||
puid := "" | |||
if len(split) == 4 { | |||
puid = split[2] | |||
} | |||
uid := split[1] | |||
title := "" | |||
img := "" | |||
if len(order.ProductList) > 0 { | |||
title = order.ProductList[0].Name | |||
img = order.ProductList[0].Img | |||
} | |||
var ord = &model.GuideOrder{ | |||
Oid: utils.StrToInt64(utils.OrderUUID(utils.StrToInt(uid))), | |||
Uid: utils.StrToInt(mid), | |||
ExtendUid: utils.StrToInt(puid), | |||
StationUid: utils.StrToInt(uid), | |||
PvdOid: order.ItemOrderId, | |||
PvdParentOid: order.RootOrderInfo.RootOrderId, | |||
Status: statusArr[order.Status], | |||
CreateTime: order.PayTime, | |||
UpdateTime: int(time.Now().Unix()), | |||
Commission: utils.Float64ToStr(float64(order.CommissionInfo.EstimateCommission) / 100), | |||
Title: title, | |||
Payment: utils.Float64ToStr(float64(order.PayAmount) / 100), | |||
Pvd: "tikTok_life", | |||
Img: img, | |||
IsShare: isShare, | |||
Ext: utils.SerializeStr(order), | |||
} | |||
if order.CommissionInfo.AllSettleRemitFinish || order.Status != 2 { | |||
var amount int64 = 0 | |||
isEnd := 1 | |||
for _, v := range order.CommissionInfo.SettleInfoMap { | |||
tmp, ok := v.(map[string]interface{}) | |||
if ok == false || utils.AnyToInt64(tmp["status"]) < 3 { | |||
isEnd = 0 | |||
} | |||
if ok && utils.AnyToInt64(tmp["status"]) == 3 { | |||
amount += utils.AnyToInt64(tmp["settle_amount"]) | |||
} | |||
} | |||
if len(order.CommissionInfo.SettleInfoMap) == 0 { | |||
isEnd = 0 | |||
} | |||
if isEnd == 1 { | |||
ord.Status = "订单结算" | |||
if order.Status == 5 { | |||
ord.Status = "部分结算" | |||
} | |||
ord.PlatformSettleTime = order.UpdateTime | |||
ord.RealCommission = utils.Float64ToStr(float64(amount) / 100) | |||
} | |||
} | |||
one := db.GetGuideOrderByOne(ord.PvdOid, utils.IntToStr(ord.Uid), ord.Pvd) | |||
if one == nil { | |||
insertOne, err := db.ZhimengDb.InsertOne(ord) | |||
fmt.Println(insertOne) | |||
fmt.Println(err) | |||
} else { | |||
ord.SettleTime = one.SettleTime | |||
db.ZhimengDb.Where("id=?", one.Id).AllCols().Update(ord) | |||
} | |||
return | |||
} |
@@ -0,0 +1,110 @@ | |||
package svc | |||
import ( | |||
"applet/app/db" | |||
"applet/app/db/model" | |||
"applet/app/utils" | |||
"applet/app/utils/cache" | |||
"fmt" | |||
"time" | |||
) | |||
func TikTokLocalLifeOrderSettle() { | |||
day := time.Now().Day() | |||
if day < 15 { | |||
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.GetGuideOrderList(arg) | |||
if len(order) == 0 { | |||
return | |||
} | |||
fmt.Println(utils.SerializeStr(order)) | |||
platformMap := map[string]string{ | |||
"tikTok_life": "抖音本地生活", | |||
} | |||
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 | |||
} |
@@ -0,0 +1,21 @@ | |||
package task | |||
import ( | |||
"applet/app/task/svc" | |||
"math/rand" | |||
"time" | |||
) | |||
func taskTikTokLocalLifeOrder() { | |||
for { | |||
if len(ch) > workerNum { | |||
time.Sleep(time.Millisecond * time.Duration(rand.Intn(1000))) | |||
} else { | |||
goto START | |||
} | |||
} | |||
START: | |||
ch <- 1 | |||
svc.TikTokLocalLifeOrder() | |||
<-ch | |||
} |
@@ -0,0 +1,22 @@ | |||
package task | |||
import ( | |||
"applet/app/task/svc" | |||
"math/rand" | |||
"time" | |||
) | |||
// | |||
func taskTikTokLocalLifeOrderSettle() { | |||
for { | |||
if len(ch) > workerNum { | |||
time.Sleep(time.Millisecond * time.Duration(rand.Intn(1000))) | |||
} else { | |||
goto START | |||
} | |||
} | |||
START: | |||
ch <- 1 | |||
svc.TikTokLocalLifeOrderSettle() | |||
<-ch | |||
} |
@@ -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.20230921025810-033e82ffb46e | |||
code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git v1.1.21-0.20231018082154-13bedd001842 | |||
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 | |||