新增各平台爆品报警(测试)
This commit is contained in:
@@ -13,12 +13,15 @@ import (
|
||||
"time"
|
||||
"unicode"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/globals/api"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/globals/refutil"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/business/jxstore/event"
|
||||
|
||||
"git.rosy.net.cn/baseapi"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/ddmsg"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/excel"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/tasksch"
|
||||
"git.rosy.net.cn/jx-callback/business/partner/purchase/jd"
|
||||
@@ -26,6 +29,7 @@ import (
|
||||
|
||||
"git.rosy.net.cn/jx-callback/business/partner"
|
||||
|
||||
"git.rosy.net.cn/baseapi/platformapi/dingdingapi"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/baseapi/utils/errlist"
|
||||
"git.rosy.net.cn/jx-callback/business/auth2/authprovider/weixin"
|
||||
@@ -164,6 +168,12 @@ type tUpdateStoresSkus struct {
|
||||
SkuBindInfos []*StoreSkuBindInfo
|
||||
}
|
||||
|
||||
type tStoreSkusSecKill struct {
|
||||
StoreID int
|
||||
SecKillCount int
|
||||
SecKillCount2 int
|
||||
}
|
||||
|
||||
const (
|
||||
maxStoreNameBind = 10000 // 最大门店SkuName bind个数
|
||||
maxStoreNameBind2 = 10000 // 最大门店乘SkuName个数
|
||||
@@ -3320,17 +3330,137 @@ func getCellForSpecTag(rowNum int, row []string, storeSkuMap map[int][]*partner.
|
||||
isSpec int
|
||||
)
|
||||
for k, cell := range row {
|
||||
if k == 0 {
|
||||
storeID = int(utils.Str2Int64(cell))
|
||||
}
|
||||
if k == 1 {
|
||||
skuID = int(utils.Str2Int64(cell))
|
||||
}
|
||||
if k == 2 {
|
||||
isSpec = int(utils.Str2Int64(cell))
|
||||
if cell != "" {
|
||||
if k == 0 {
|
||||
storeID = int(utils.Str2Int64(cell))
|
||||
}
|
||||
if k == 1 {
|
||||
skuID = int(utils.Str2Int64(cell))
|
||||
}
|
||||
if k == 2 {
|
||||
isSpec = int(utils.Str2Int64(cell))
|
||||
}
|
||||
}
|
||||
}
|
||||
skuMap.SkuID = skuID
|
||||
skuMap.IsSpecialty = isSpec
|
||||
storeSkuMap[storeID] = append(storeSkuMap[storeID], skuMap)
|
||||
}
|
||||
|
||||
func SendSeckillSkusCountMsg(ctx *jxcontext.Context, vendorIDs []int, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||
// 1. 如果爆品低于8个,报警 type1
|
||||
// 2. 爆品价格低于1元商品小于5个,报警 type2
|
||||
var (
|
||||
type1Count = 8
|
||||
type2Count = 5
|
||||
)
|
||||
db := dao.GetDB()
|
||||
storeList, err := dao.GetStoreList(db, nil, nil, []int{model.StoreStatusOpened, model.StoreStatusClosed, model.StoreStatusHaveRest}, nil, "")
|
||||
task := tasksch.NewParallelTask("SendSeckillSkusCountMsg", tasksch.NewParallelConfig().SetIsContinueWhenError(isContinueWhenError), ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
store := batchItemList[0].(*model.Store)
|
||||
for _, vendorID := range vendorIDs {
|
||||
storeDetial, _ := dao.GetStoreDetail(db, store.ID, vendorID)
|
||||
var type1, type2 int
|
||||
switch vendorID {
|
||||
case model.VendorIDEBAI:
|
||||
result, err := api.EbaiAPI.GetStoresShowWindowSkus(utils.Str2Int64(storeDetial.VendorStoreID))
|
||||
if err != nil {
|
||||
return retVal, err
|
||||
}
|
||||
for _, v := range result.SkuList {
|
||||
type1++
|
||||
if v.SalePrice < 1 {
|
||||
type2++
|
||||
}
|
||||
}
|
||||
case model.VendorIDMTWM:
|
||||
handler := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.ISingleStoreStoreSkuHandler)
|
||||
remoteSkuList, err := handler.GetStoreSkusFullInfo(ctx, nil, store.ID, storeDetial.VendorStoreID, nil)
|
||||
if err != nil {
|
||||
return retVal, err
|
||||
}
|
||||
for _, v := range remoteSkuList {
|
||||
for _, vv := range v.SkuList {
|
||||
if vv.IsSpecialty == 1 {
|
||||
type1++
|
||||
}
|
||||
if vv.IsSpecialty == 1 && vv.VendorPrice < 100 {
|
||||
type2++
|
||||
}
|
||||
}
|
||||
}
|
||||
case model.VendorIDJD:
|
||||
var storeSecKill *tStoreSkusSecKill
|
||||
sql := `
|
||||
SELECT t1.store_id,count(*) sec_kill_count, count(t1.price < 100 or NULL) sec_kill_count2
|
||||
FROM(
|
||||
SELECT a.store_id, a.sku_id, d.type, MIN(b.act_price) price
|
||||
FROM store_sku_bind a
|
||||
LEFT JOIN act_store_sku b ON a.store_id = b.store_id AND b.sku_id = a.sku_id
|
||||
LEFT JOIN act_map c ON c.act_id = b.act_id
|
||||
LEFT JOIN act d ON d.id = c.act_id
|
||||
WHERE 1=1
|
||||
AND a.store_id = ?
|
||||
AND c.vendor_id = ?
|
||||
AND NOW() BETWEEN d.begin_at AND d.end_at
|
||||
AND d.type = ?
|
||||
AND a.status = ?
|
||||
AND a.deleted_at = ?
|
||||
GROUP BY 1,2,3)t1
|
||||
GROUP BY 1
|
||||
`
|
||||
sqlParams := []interface{}{
|
||||
model.ActSkuSecKill,
|
||||
store.ID, vendorID,
|
||||
model.ActSkuSecKill, model.StoreSkuBindStatusNormal,
|
||||
utils.DefaultTimeValue,
|
||||
}
|
||||
err = dao.GetRow(db, &storeSecKill, sql, sqlParams...)
|
||||
type1 = storeSecKill.SecKillCount
|
||||
type2 = storeSecKill.SecKillCount2
|
||||
}
|
||||
if type1 < type1Count || type2 < type2Count {
|
||||
err = sendDDMsgBySpecSkusCount(db, type1, type2, storeDetial, vendorID)
|
||||
}
|
||||
fmt.Println(type1, type2, vendorID)
|
||||
}
|
||||
return retVal, err
|
||||
}, storeList)
|
||||
tasksch.HandleTask(task, nil, true).Run()
|
||||
if !isAsync {
|
||||
_, err = task.GetResult(0)
|
||||
} else {
|
||||
hint = task.GetID()
|
||||
}
|
||||
return hint, err
|
||||
}
|
||||
|
||||
func sendDDMsgBySpecSkusCount(db *dao.DaoDB, type1Count, type2Count int, store *dao.StoreDetail, vendorID int) (err error) {
|
||||
var (
|
||||
operatorName string
|
||||
operatorPhone string
|
||||
type1 = "爆品数量低于8个!"
|
||||
type2 = "爆品价格小于1元的爆品数量低于5个!"
|
||||
typeResult = ""
|
||||
)
|
||||
if store.OperatorPhone != "" {
|
||||
operatorName = store.OperatorName
|
||||
operatorPhone = store.OperatorPhone
|
||||
} else if store.OperatorPhone2 != "" {
|
||||
operatorName = store.OperatorName2
|
||||
operatorPhone = store.OperatorPhone2
|
||||
}
|
||||
if type1Count < 8 {
|
||||
typeResult += type1
|
||||
}
|
||||
if type2Count < 5 {
|
||||
typeResult += type2
|
||||
}
|
||||
noticeMsg := fmt.Sprintf("运营负责人:[%v],门店ID:[%v],平台门店ID[%v],门店名:[%v],平台:[%v],警告类型:[%v]", operatorName, store.ID, store.VendorStoreID, store.Name, model.VendorChineseNames[vendorID], typeResult)
|
||||
user, err := dao.GetUserByID(db, "mobile", operatorPhone)
|
||||
user2, err := dao.GetUserByID(db, "mobile", store.MarketManPhone)
|
||||
ddmsg.SendUserMessage(dingdingapi.MsgTyeText, user.UserID, "警告!门店爆品数量异常!", noticeMsg)
|
||||
ddmsg.SendUserMessage(dingdingapi.MsgTyeText, user2.UserID, "警告!门店爆品数量异常!", noticeMsg)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -495,7 +495,7 @@ func vendorSku2Jx(appFood *mtwmapi.AppFood) (skuName *partner.SkuNameInfo) {
|
||||
StoreSkuInfo: partner.StoreSkuInfo{
|
||||
VendorSkuID: vendorSku.SkuID,
|
||||
SkuID: skuID,
|
||||
|
||||
IsSpecialty: appFood.IsSpecialty,
|
||||
Stock: int(utils.Str2Int64WithDefault(vendorSku.Stock, partner.UnlimitedStoreSkuStock)),
|
||||
VendorPrice: jxutils.StandardPrice2Int(utils.Str2Float64WithDefault(vendorSku.Price, 0)),
|
||||
Status: mtwmSkuStatus2Jx(appFood.IsSoldOut),
|
||||
|
||||
Reference in New Issue
Block a user