huangjiajun před 10 měsíci
rodič
revize
913b7d3e22
10 změnil soubory, kde provedl 320 přidání a 1 odebrání
  1. +1
    -0
      app/db/model/guide_order.go
  2. +42
    -0
      app/db/official/db_sys_cfg.go
  3. +7
    -0
      app/db/official/model/sys_cfg.go
  4. +2
    -0
      app/task/init.go
  5. +2
    -0
      app/task/md/cron_key.go
  6. +25
    -0
      app/task/svc/svc_csjp_url.go
  7. +196
    -0
      app/task/svc/svc_tik_tok_csjp.go
  8. +22
    -0
      app/task/task_tik_tok_csjp.go
  9. +22
    -0
      app/task/task_tik_tok_csjp_activity.go
  10. +1
    -1
      go.mod

+ 1
- 0
app/db/model/guide_order.go Zobrazit soubor

@@ -16,6 +16,7 @@ type GuideOrder struct {
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)"`
Gid string `json:"gid" 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)"`


+ 42
- 0
app/db/official/db_sys_cfg.go Zobrazit soubor

@@ -0,0 +1,42 @@
package offical

import (
"applet/app/db"
officialModel "applet/app/db/model"
"applet/app/utils/logx"
)

func SysCfgByKey(key string) *officialModel.SysCfg {
var data officialModel.SysCfg
get, err := db.Db.Where("k=?", key).Get(&data)
if get == false || err != nil {
return nil
}
return &data
}
func SysCfgByKeyStr(key string) string {
var data officialModel.SysCfg
get, err := db.Db.Where("k=?", key).Get(&data)
if get == false || err != nil {
return ""
}
return data.V
}
func DbsSysCfgInserts(key, val string) bool {
cfg := officialModel.SysCfg{K: key, V: val}
_, err := db.Db.InsertOne(&cfg)
if err != nil {
logx.Error(err)
return false
}
return true
}
func DbsSysCfgUpdate(key, val string) bool {
cfg := officialModel.SysCfg{K: key, V: val}
_, err := db.Db.Where("`k`=?", key).Cols("v").Update(&cfg)
if err != nil {
logx.Error(err)
return false
}
return true
}

+ 7
- 0
app/db/official/model/sys_cfg.go Zobrazit soubor

@@ -0,0 +1,7 @@
package model

type SysCfg struct {
K string `json:"k" xorm:"not null pk comment('键') VARCHAR(127)"`
V string `json:"v" xorm:"comment('值') TEXT"`
Memo string `json:"memo" xorm:"not null default '' comment('备注') VARCHAR(255)"`
}

+ 2
- 0
app/task/init.go Zobrazit soubor

@@ -83,6 +83,8 @@ func doTask(fnName string) func() {

// 增加自动任务队列
func initTasks() {
jobs[taskMd.ZhimengCronTikTokCsjp] = taskTikTokCsjp //
jobs[taskMd.ZhimengCronTikTokCsjpActivity] = taskTikTokCsjpActivity //

jobs[taskMd.ZhimengCronTikTokTask] = taskTikTokTask //
jobs[taskMd.ZhimengCronTikTokTaskRelate] = taskTikTokTaskRelate //


+ 2
- 0
app/task/md/cron_key.go Zobrazit soubor

@@ -2,6 +2,8 @@ package md

const (
ZhimengCronTikTokTaskRelate = "zhimeng_cron_tik_tok_relate"
ZhimengCronTikTokCsjp = "zhimeng_cron_tik_tok_csjp"
ZhimengCronTikTokCsjpActivity = "zhimeng_cron_tik_tok_csjp_activity"
ZhimengCronTikTokTask = "zhimeng_cron_tik_tok_task" //短剧订单
ZhimengCronTikTokTaskMoney = "zhimeng_cron_tik_tok_task_money" //短剧订单
ZhimengCronTikTokTaskMoneyByYestday = "zhimeng_cron_tik_tok_task_money_by_yestday"


+ 25
- 0
app/task/svc/svc_csjp_url.go Zobrazit soubor

@@ -0,0 +1,25 @@
package svc

import (
offical "applet/app/db/official"
"code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/tik_tok"
)

func Base() map[string]string {

tikTokCsjpAppId := offical.SysCfgByKeyStr("tik_tok_csjp_app_id")
tikTokCsjpAppSecret := offical.SysCfgByKeyStr("tik_tok_csjp_app_secret")
var tmp = map[string]string{
"app_id": tikTokCsjpAppId,
"app_secret": tikTokCsjpAppSecret,
}
return tmp
}

func CsjpOrder(tikTokArgs map[string]string) map[string]interface{} {
base := Base()
tikTokArgs["app_id"] = base["app_id"]
tikTokArgs["app_secret"] = base["app_secret"]
order := tik_tok.CsjpOrderList(tikTokArgs)
return order
}

+ 196
- 0
app/task/svc/svc_tik_tok_csjp.go Zobrazit soubor

@@ -0,0 +1,196 @@
package svc

import (
"applet/app/db"
"applet/app/db/model"
offical "applet/app/db/official"
"applet/app/utils"
"fmt"
"strings"
"time"
)

var oilstationState = map[string]int{
"订单付款": 0,
"订单成功": 2,
"订单完成": 2,
"订单失效": 4,
"订单退款": 4,
"订单结算": 3,
}

func TikTokCsjp(ordType int) {
pvdTimeKey := "csjp_time_" + utils.IntToStr(ordType)

// 获得最后时间
latest := offical.SysCfgByKey(pvdTimeKey)
if latest == nil {
offical.DbsSysCfgInserts(pvdTimeKey, time.Now().String())
latest = offical.SysCfgByKey(pvdTimeKey)
}
// 所有时间都是在操作秒数
now := time.Now().Unix()
strs := strings.Split(latest.V, ":")
timeStr := latest.V
if len(strs) == 3 {
timeStr = strs[0] + ":" + strs[1] + ":00"
}
fmt.Println(timeStr)
past := utils.TimeParseStd(timeStr).Unix()
// 如果上次记录超过30天或者 过去时间大于当前时间戳, 把时间设置为此前20分钟
if past < now-180*86400 || past > now {
past = now
}
var (
beginTime int64 = 0
endTime int64 = 0
pageNo int = 1
pageSize int = 50
nextPositionIndex string = ""
)

//怕时间不是走最新的
leave := now - past
if leave > 500 {
leave = 0
}
past = past + leave
beginTime = past - 300
endTime = past

if endTime > now {
endTime = now
}

for {
ordData := new([]map[string]string)
var positionIndex = ""
var err error
if pageNo == 1 {
nextPositionIndex = "0"
}
if nextPositionIndex != "" {
ordData, positionIndex, err = OrdersTikTokGet(nextPositionIndex, pageSize, beginTime, endTime, "update", ordType)
}
count := 0
if ordData == nil {
nextPositionIndex = ""
goto ChkArg
}
count = len(*ordData)
if err != nil || ordData == nil || len(*ordData) == 0 {
nextPositionIndex = ""
goto ChkArg
}
if count > 0 {
count = pageSize
}
// 判断是否分页已经全部取完了
if count == pageSize {
nextPositionIndex = positionIndex
pageNo++
fmt.Println("========下一页========" + utils.IntToStr(pageNo))
ordData = nil
continue
}
ChkArg:
nextPositionIndex = ""

// 查询完后重置时间, 最后查询时间
if endTime < now {
pageNo = 1
offical.DbsSysCfgUpdate(pvdTimeKey, utils.TimeToStr(endTime))
beginTime = endTime
endTime = endTime + 300
if endTime > now {
endTime = now
}
ordData = nil
continue
}
ordData = nil
break
}
}
func OrdersTikTokGet(nextPositionIndex string, pageSize int, sTime, eTime int64, timeType string, pvd int) (*[]map[string]string, string, error) {

distributionType := pvd
tikTokArgs := map[string]string{
"size": utils.IntToStr(pageSize),
"cursor": nextPositionIndex,
"start_time": utils.Int64ToStr(time.Unix(sTime, 0).Unix()),
"end_time": utils.Int64ToStr(time.Unix(eTime, 0).Unix()),
"time_type": timeType,
"order_type": utils.IntToStr(distributionType),
}
//if cfg.Prd == false {
// tikTokArgs["start_time"] = "2023-09-18 15:59:00"
// tikTokArgs["end_time"] = "2023-09-18 16:02:00"
//}

order := CsjpOrder(tikTokArgs)
cursor := utils.AnyToString(order["cursor"])
list, ok := order["order"].([]map[string]string)

if ok {
for _, v := range list {
if utils.StrToInt(v["uid"]) == 0 {
continue
}
orderType := 0
if v["is_share"] == "1" {
orderType = 1
}
// 判断免单
if v["is_share"] == "2" {
orderType = 2
}
if v["is_share"] == "3" {
orderType = 10
}
if v["is_share"] == "4" {
orderType = 11
}
if v["is_share"] == "5" {
orderType = 12
}
if v["is_share"] == "6" {
orderType = 13
}

var ord = &model.GuideOrder{
Uid: utils.StrToInt(v["mid"]),
StationUid: utils.StrToInt(v["uid"]),
PvdOid: utils.AnyToString(v["oid"]),
Status: v["status"],
CreateTime: utils.StrToInt(v["create_time"]),
UpdateTime: int(time.Now().Unix()),
Commission: v["commission"],
Title: utils.AnyToString(v["info"]),
Payment: v["payment"],
Pvd: "csjp",
Img: v["product_img"],
IsShare: orderType,
Gid: v["product_id"],
Ext: utils.SerializeStr(order),
}
if utils.StrToInt(v["lm_js_time"]) > 0 {
ord.PlatformSettleTime = utils.StrToInt(v["lm_js_time"])
}
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
if one.PlatformSettleTime > 0 {
ord.PlatformSettleTime = one.PlatformSettleTime
}
db.ZhimengDb.Where("id=?", one.Id).AllCols().Update(ord)
}
}
return &list, cursor, nil
}
return nil, "", nil
}

+ 22
- 0
app/task/task_tik_tok_csjp.go Zobrazit soubor

@@ -0,0 +1,22 @@
package task

import (
"applet/app/task/svc"
"math/rand"
"time"
)

//
func taskTikTokCsjp() {
for {
if len(ch) > workerNum {
time.Sleep(time.Millisecond * time.Duration(rand.Intn(1000)))
} else {
goto START
}
}
START:
ch <- 1
svc.TikTokCsjp(1)
<-ch
}

+ 22
- 0
app/task/task_tik_tok_csjp_activity.go Zobrazit soubor

@@ -0,0 +1,22 @@
package task

import (
"applet/app/task/svc"
"math/rand"
"time"
)

//
func taskTikTokCsjpActivity() {
for {
if len(ch) > workerNum {
time.Sleep(time.Millisecond * time.Duration(rand.Intn(1000)))
} else {
goto START
}
}
START:
ch <- 1
svc.TikTokCsjp(3)
<-ch
}

+ 1
- 1
go.mod Zobrazit soubor

@@ -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.20231023083145-a61813d50051
code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git v1.1.21-0.20240131014841-ab7390becddd
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


Načítá se…
Zrušit
Uložit