1
This commit is contained in:
@@ -1,11 +1,17 @@
|
||||
package bidding
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"git.rosy.net.cn/baseapi/platformapi/mtwmapi"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
func GetMTInfo() {
|
||||
@@ -29,21 +35,160 @@ func GetMTInfo() {
|
||||
VendorID: model.VendorIDMTWM,
|
||||
VendorStoreID: v.VendorStoreID,
|
||||
BrandID: v.VendorOrgCode,
|
||||
Activity1: 0,
|
||||
Activity2: 0,
|
||||
Activity: 0,
|
||||
StoreSkuNum: 0,
|
||||
StoreRating: "",
|
||||
DeliveryFee: "",
|
||||
DeliveryFee2: "",
|
||||
PromotionFee: "",
|
||||
BusinessHours: "",
|
||||
//Activity1: 0,
|
||||
//Activity2: 0,
|
||||
//Activity: 0,
|
||||
//StoreSkuNum: 0,
|
||||
//StoreRating: 0,
|
||||
DeliveryFee: "",
|
||||
//DeliveryFee2: "",
|
||||
PromotionFee: "",
|
||||
//BusinessHours: "",
|
||||
}
|
||||
dao.WrapAddIDCULEntity(statistics, "system")
|
||||
// 获取美团活动
|
||||
mtApi.RetailDiscountList(v.VendorStoreID, mtwmapi.RetailActTypeDirectDown) // 折扣活动
|
||||
mtApi.RetailDiscountList(v.VendorStoreID, mtwmapi.RetailActTypeSecKill) // 爆品活动
|
||||
down, up := getActivityCount(mtApi, v.VendorStoreID)
|
||||
statistics.Activity1 = int64(down)
|
||||
statistics.Activity2 = int64(up)
|
||||
statistics.Activity = int64(down + up)
|
||||
score, err := mtApi.CommentScore(v.VendorStoreID)
|
||||
if err != nil {
|
||||
globals.SugarLogger.Debugf("门店评分获取错误:%v", err)
|
||||
}
|
||||
if score != nil {
|
||||
statistics.StoreRating = score.AvgPoiScore
|
||||
} else {
|
||||
statistics.StoreRating = 0
|
||||
}
|
||||
|
||||
detail, _ := mtApi.PoiMGet([]string{v.VendorStoreID})
|
||||
if detail != nil {
|
||||
statistics.BusinessHours, err = getStoreShippingTime(detail[0].ShippingTime)
|
||||
if err != nil {
|
||||
statistics.BusinessHours = err.Error()
|
||||
}
|
||||
statistics.DeliveryFee2 = utils.Float64ToStr(detail[0].ShippingFee)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 获取门店折扣活动商品数量
|
||||
func getActivityCount(api *mtwmapi.API, vendorStoreId string) (int, int) {
|
||||
threefoldDown := 0 // 0-3 折活动数量
|
||||
threefoldUp := 0 // 3.01-9 折活动
|
||||
// 获取美团活动
|
||||
directList, _ := api.RetailDiscountList(vendorStoreId, mtwmapi.RetailActTypeDirectDown) // 折扣活动
|
||||
for _, v := range directList {
|
||||
if v.ActPrice/v.OriginalPrice >= 3.01 {
|
||||
threefoldUp++
|
||||
} else {
|
||||
threefoldDown++
|
||||
}
|
||||
}
|
||||
secKillList, _ := api.RetailDiscountList(vendorStoreId, mtwmapi.RetailActTypeSecKill) // 爆品活动
|
||||
if secKillList != nil {
|
||||
threefoldDown = threefoldDown + len(secKillList)
|
||||
}
|
||||
|
||||
return threefoldDown, threefoldUp
|
||||
}
|
||||
|
||||
func getStoreShippingTime(storeTime string) (string, error) {
|
||||
time2 := strings.Split(storeTime, ";")
|
||||
aa := int(time.Now().Weekday())
|
||||
if aa == 0 {
|
||||
aa = 7
|
||||
}
|
||||
if len(time2) == 1 {
|
||||
aa = 1
|
||||
}
|
||||
intervals, err := parseIntervals(time2[aa-1])
|
||||
if err != nil {
|
||||
fmt.Printf("解析错误: %v\n", err)
|
||||
return "", err
|
||||
}
|
||||
|
||||
merged := mergeIntervals(intervals)
|
||||
|
||||
totalMinutes := 0
|
||||
for _, iv := range merged {
|
||||
totalMinutes += iv.end - iv.start
|
||||
}
|
||||
return fmt.Sprintf("%.2f", float64(totalMinutes)/float64(60)), err
|
||||
}
|
||||
|
||||
// timeToMinutes 将 "HH:MM" 转为当天第几分钟(0 ~ 1439)
|
||||
func timeToMinutes(t string) (int, error) {
|
||||
parts := strings.Split(t, ":")
|
||||
if len(parts) != 2 {
|
||||
return 0, fmt.Errorf("invalid time format: %s", t)
|
||||
}
|
||||
h, err := strconv.Atoi(parts[0])
|
||||
if err != nil || h < 0 || h > 23 {
|
||||
return 0, fmt.Errorf("invalid hour in %s", t)
|
||||
}
|
||||
m, err := strconv.Atoi(parts[1])
|
||||
if err != nil || m < 0 || m > 59 {
|
||||
return 0, fmt.Errorf("invalid minute in %s", t)
|
||||
}
|
||||
return h*60 + m, nil
|
||||
}
|
||||
|
||||
// parseIntervals 解析 "00:00-01:00,01:05-23:59" → []interval
|
||||
type interval struct {
|
||||
start, end int // minutes since 00:00
|
||||
}
|
||||
|
||||
func parseIntervals(s string) ([]interval, error) {
|
||||
var intervals []interval
|
||||
for _, seg := range strings.Split(s, ",") {
|
||||
seg = strings.TrimSpace(seg)
|
||||
if seg == "" {
|
||||
continue
|
||||
}
|
||||
parts := strings.Split(seg, "-")
|
||||
if len(parts) != 2 {
|
||||
return nil, fmt.Errorf("invalid interval format: %s", seg)
|
||||
}
|
||||
startMins, err := timeToMinutes(strings.TrimSpace(parts[0]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
endMins, err := timeToMinutes(strings.TrimSpace(parts[1]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if startMins > endMins {
|
||||
return nil, fmt.Errorf("start after end in interval: %s", seg)
|
||||
}
|
||||
intervals = append(intervals, interval{start: startMins, end: endMins})
|
||||
}
|
||||
return intervals, nil
|
||||
}
|
||||
|
||||
// mergeIntervals 合并重叠/相邻区间(如 [0,60], [65,1439] → 保留两个;若 [0,60], [60,120] → 可合并为 [0,120])
|
||||
func mergeIntervals(ints []interval) []interval {
|
||||
if len(ints) == 0 {
|
||||
return ints
|
||||
}
|
||||
// 排序
|
||||
sort.Slice(ints, func(i, j int) bool {
|
||||
return ints[i].start < ints[j].start
|
||||
})
|
||||
|
||||
merged := make([]interval, 0, len(ints))
|
||||
curr := ints[0]
|
||||
for i := 1; i < len(ints); i++ {
|
||||
if ints[i].start <= curr.end { // 重叠或紧邻(如 end=60, next.start=60 → 合并)
|
||||
if ints[i].end > curr.end {
|
||||
curr.end = ints[i].end
|
||||
}
|
||||
} else {
|
||||
merged = append(merged, curr)
|
||||
curr = ints[i]
|
||||
}
|
||||
}
|
||||
merged = append(merged, curr)
|
||||
return merged
|
||||
}
|
||||
|
||||
@@ -2,19 +2,19 @@ package model
|
||||
|
||||
type ActivityStation struct {
|
||||
ModelIDCUL
|
||||
StoreID int `orm:"column(store_id);size(16)" json:"store_id"` // 门店ID
|
||||
VendorID int `orm:"column(vendor_id);size(2)" json:"vendor_id"` // 平台ID
|
||||
VendorStoreID string `orm:"column(vendor_store_id);size(48)" json:"vendor_store_id"` // 平台门店ID
|
||||
BrandID string `orm:"column(brand_id);size(16)" json:"brand_id"` // 品牌ID
|
||||
Activity1 int64 `orm:"column(activity_1);size(16)" json:"activity_1"` // 活动0-3折商品数量
|
||||
Activity2 int64 `orm:"column(activity_2);size(16)" json:"activity_2"` // 活动3-9折商品数量
|
||||
Activity int64 `orm:"column(activity);size(16)" json:"activity"` // 总的活动数量
|
||||
StoreSkuNum int64 `orm:"column(store_sku_num);size(48)" json:"store_sku_num"` // 门店商品数量
|
||||
StoreRating string `orm:"column(store_rating);size(16)" json:"store_rating"` // 评分
|
||||
DeliveryFee string `orm:"column(delivery_fee);size(4)" json:"delivery_fee"` // 超过1.5km起送价不大于20
|
||||
DeliveryFee2 string `orm:"column(delivery_fee2);size(4)" json:"delivery_fee2"` // 超过1.5km配送费不大于0
|
||||
PromotionFee string `orm:"column(promotion_fee);size(4)" json:"promotion_fee"` // 推广费超过三十五元
|
||||
BusinessHours string `orm:"column(business_hours);size(4)" json:"business_hours"` // 营业时间超过11小时
|
||||
StoreID int `orm:"column(store_id);size(16)" json:"store_id"` // 门店ID
|
||||
VendorID int `orm:"column(vendor_id);size(2)" json:"vendor_id"` // 平台ID
|
||||
VendorStoreID string `orm:"column(vendor_store_id);size(48)" json:"vendor_store_id"` // 平台门店ID
|
||||
BrandID string `orm:"column(brand_id);size(16)" json:"brand_id"` // 品牌ID
|
||||
Activity1 int64 `orm:"column(activity_1);size(16)" json:"activity_1"` // 活动0-3折商品数量
|
||||
Activity2 int64 `orm:"column(activity_2);size(16)" json:"activity_2"` // 活动3-9折商品数量
|
||||
Activity int64 `orm:"column(activity);size(16)" json:"activity"` // 总的活动数量
|
||||
StoreSkuNum int64 `orm:"column(store_sku_num);size(48)" json:"store_sku_num"` // 门店商品数量
|
||||
StoreRating float64 `orm:"column(store_rating);size(16)" json:"store_rating"` // 评分
|
||||
DeliveryFee string `orm:"column(delivery_fee);size(4)" json:"delivery_fee"` // 超过1.5km起送价不大于20
|
||||
DeliveryFee2 string `orm:"column(delivery_fee2);size(4)" json:"delivery_fee2"` // 超过1.5km配送费不大于0
|
||||
PromotionFee string `orm:"column(promotion_fee);size(4)" json:"promotion_fee"` // 推广费超过三十五元
|
||||
BusinessHours string `orm:"column(business_hours);size(4)" json:"business_hours"` // 营业时间超过11小时
|
||||
}
|
||||
type EffectiveStores struct {
|
||||
JxStoreID int `orm:"column(jx_store_id)" json:"jxStoreID"` // 根据VendorStoreID在本地系统里查询出来的 jxstoreid
|
||||
|
||||
@@ -188,10 +188,14 @@ func onTLpayFinished(call *tonglianpayapi.CallBackResult) (err error) {
|
||||
Openid: authList[0].AuthID,
|
||||
},
|
||||
}
|
||||
|
||||
if err = api.WeixinMiniAPI2.SNSSendGoodsOrder(param); err != nil {
|
||||
ddmsg.SendUserMessage(dingdingapi.MsgTyeText, "2452A93EEB9111EC9B06525400E86DC0", "物料发货推送", fmt.Sprintf("物料商城下单,发货错误:%s,请注意查看,err:%s,%s", order.VendorOrderID, err.Error(), utils.Format4Output(param, false)))
|
||||
}
|
||||
jxutils.CallMsgHandlerAsync(func() {
|
||||
select {
|
||||
case <-time.After(2 * time.Second):
|
||||
if err = api.WeixinMiniAPI2.SNSSendGoodsOrder(param); err != nil {
|
||||
ddmsg.SendUserMessage(dingdingapi.MsgTyeText, "2452A93EEB9111EC9B06525400E86DC0", "物料发货推送", fmt.Sprintf("物料商城下单,发货错误:%s,请注意查看,err:%s,%s", order.VendorOrderID, err.Error(), utils.Format4Output(param, false)))
|
||||
}
|
||||
}
|
||||
}, call.ChnlTrxID)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user