|
- package svc
-
- import (
- "applet/app/db"
- "applet/app/db/model"
- offical "applet/app/db/official"
- "applet/app/task/md"
- "applet/app/utils"
- "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/cinema_5bms"
- "encoding/json"
- "github.com/tidwall/gjson"
- "strings"
- "time"
- )
-
- func Cinema5bmsOrder() {
- cinema5bmsAppid := offical.SysCfgByKeyStr("cinema5bms_appid")
- cinema5bmsAppsecret := offical.SysCfgByKeyStr("cinema5bms_appSecret")
- uid := "0"
- // 获取上次获取订单时候的时间戳
- pvdTimeKey := "cinema5bms_order_time"
- now := time.Now().Unix()
- past := GetRunTime(uid, pvdTimeKey, "短剧获取订单时间")
- var (
- beginTime int64 = 0
- endTime int64 = 0
- pageNo int = 1
- pageSize int = 50
- )
- //怕时间不是走最新的
- leave := now - past
- if leave > 500 {
- leave = 0
- }
- var eveTime int64 = 3600
- past = past + leave
- beginTime = past - eveTime
- endTime = past
- if endTime > now {
- endTime = now
- }
- for {
- // 分配堆内存
- time.Sleep(time.Microsecond * 500) // 等待500毫秒
- //获取订单
- arg := map[string]string{
- "app_id": cinema5bmsAppid,
- "pay_start_date": time.Unix(beginTime, 0).Format("2006-01-02 15:04:05"),
- "pay_end_date": time.Unix(endTime, 0).Format("2006-01-02 15:04:05"),
- "limit": utils.IntToStr(pageSize),
- "p": utils.IntToStr(pageNo),
- }
-
- count := GetNewVideoOrder(uid, cinema5bmsAppsecret, arg)
- if count == 0 {
- goto ChkArg
- }
- if count <= pageSize {
- pageNo++
- continue
- }
- ChkArg:
- // 查询完后重置时间, 最后查询时间
- if endTime < now {
- pageNo = 1
- SetRunTime(uid, pvdTimeKey, utils.TimeToStr(endTime))
- beginTime = endTime
- endTime = endTime + eveTime
- if endTime > now {
- endTime = now
- }
- continue
- }
- break
- }
- // 更新最后供应商执行订单时间
- SetRunTime(uid, pvdTimeKey, utils.TimeToStr(now))
- }
- func Cinema5bmsOrderDate() {
- cinema5bmsAppid := offical.SysCfgByKeyStr("cinema5bms_appid")
- cinema5bmsAppsecret := offical.SysCfgByKeyStr("cinema5bms_appSecret")
- yesterday := utils.GetTimeRange("yesterday")
- var (
- pageNo int = 1
- pageSize int = 50
- )
- uid := "0"
- for {
- // 分配堆内存
- time.Sleep(time.Microsecond * 500) // 等待500毫秒
- //获取订单
- arg := map[string]string{
- "app_id": cinema5bmsAppid,
- "show_time": time.Unix(yesterday["start"], 0).Format("2006-01-02"),
- "limit": utils.IntToStr(pageSize),
- "p": utils.IntToStr(pageNo),
- }
-
- count := GetNewVideoOrder(uid, cinema5bmsAppsecret, arg)
- if count == 0 {
- break
- }
- if count <= pageSize {
- pageNo++
- continue
- }
- }
- }
- func GetNewVideoOrder(uids string, cinema5bmsAppsecret string, arg map[string]string) int {
- cinema, _ := cinema_5bms.GetCinema("open/getOrderList", cinema5bmsAppsecret, arg)
- data := make([]md.Cinema5bmsOrder, 0)
- json.Unmarshal([]byte(gjson.Get(cinema, "data.list").String()), &data)
- statusMap := map[string]string{
- "等待核销": "订单付款",
- "核销成功": "订单完成",
- "核销失败": "订单失败",
- }
- for _, v := range data {
- sourceIdArr := strings.Split(v.CustomParams, "_")
- mid := ""
- uid := ""
- if len(sourceIdArr) == 2 {
- mid = sourceIdArr[0]
- uid = sourceIdArr[1]
- }
- if mid == "" || uid == "" {
- continue
- }
- Channel := "douyin"
- if v.Nsource == "2" {
- Channel = "kuaishou"
- }
- money := v.OrderAmount
- commission := utils.StrToFloat64(v.OrderAmount) * (10.0 / 100)
- var tmp = model.PlayletSaleOrder{
- Uid: mid,
- SubUid: utils.StrToInt(uid),
- Data: utils.SerializeStr(v),
- Oid: v.OrderSn,
- Amount: money,
- Commission: utils.Float64ToStr(commission),
- CreateTime: utils.TimeParseStd(v.PayTime),
- UpdateTime: time.Now(),
- Title: v.CinemaName + "-" + v.FilmName,
- VideoType: Channel,
- PlatformType: "5bms",
- GoodsType: "playlet",
- OrdType: "cinema",
- ExtendUid: uids,
- }
- playletSaleOrderDb := db.PlayletSaleOrderDb{}
- playletSaleOrderDb.Set()
- ord := playletSaleOrderDb.GetPlayletVideoOrderByOid(v.OrderSn, tmp.OrdType)
- tmp.Status = statusMap[v.OrderStatus]
- if v.RefundTime != "" {
- tmp.RefundTime = utils.TimeParseStd(v.RefundTime)
- }
- if ord != nil {
- playletSaleOrderDb.PlayletVideoOrderUpdate(ord.Id, &tmp)
- } else {
- tmp.CustomOid = utils.OrderUUID(tmp.SubUid)
- playletSaleOrderDb.PlayletVideoOrderInsert(&tmp)
- }
- }
- return len(data)
- }
|