Accept Merge Request #193: (su -> mark)
Merge Request: 饿鲜达订单缺少skuId Created By: @苏尹岚 Accepted By: @苏尹岚 URL: https://rosydev.coding.net/p/jx-callback/d/jx-callback/git/merge/193
This commit is contained in:
@@ -3,6 +3,8 @@ package cms
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"mime/multipart"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -1475,59 +1477,127 @@ func DeleteSkuNameExPrefixOverdue(db *dao.DaoDB) (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
func SumExianDaDepot(ctx *jxcontext.Context) (err error) {
|
||||
func SumExianDaDepot(ctx *jxcontext.Context, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||
db := dao.GetDB()
|
||||
result, err := api.EbaiAPI.GetExianDaSkuDepot("")
|
||||
for _, v := range result {
|
||||
skus, err := api.EbaiAPI.GetExianDaSku(utils.Str2Int64(v.ElemeGoodsID))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
dao.Begin(db)
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
dao.Rollback(db)
|
||||
panic(r)
|
||||
results, err := api.EbaiAPI.GetExianDaSkuDepot("")
|
||||
taskSeqFunc := func(task *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) {
|
||||
switch step {
|
||||
case 0:
|
||||
for _, v := range results {
|
||||
skus, err := api.EbaiAPI.GetExianDaSku(utils.Str2Int64(v.ElemeGoodsID))
|
||||
if err != nil {
|
||||
return result, err
|
||||
}
|
||||
skuNameExt := &model.SkuName{}
|
||||
sql2 := `
|
||||
SELECT a.*
|
||||
FROM sku_name a
|
||||
JOIN sku b ON b.name_id = a.id
|
||||
WHERE a.upc = ?
|
||||
`
|
||||
sqlParams2 := []interface{}{
|
||||
skus.UpcIds,
|
||||
}
|
||||
dao.GetRow(db, skuNameExt, sql2, sqlParams2)
|
||||
dao.Begin(db)
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
dao.Rollback(db)
|
||||
panic(r)
|
||||
}
|
||||
}()
|
||||
prefix, _, _, specUnit, unit, specQuality := jxutils.SplitSkuName(v.GoodsName)
|
||||
//京西库中存在此商品
|
||||
if skuNameExt.ID != 0 {
|
||||
if skuNameExt.Name != v.GoodsName {
|
||||
skuNameExt.Name = v.GoodsName
|
||||
_, err = dao.UpdateEntity(db, skuNameExt, "Name")
|
||||
if err != nil {
|
||||
dao.Rollback(db)
|
||||
return result, err
|
||||
}
|
||||
}
|
||||
} else {
|
||||
skuCat := &model.SkuCategory{}
|
||||
sql := `
|
||||
SELECT *
|
||||
FROM sku_category
|
||||
WHERE ebai_category_id = ?
|
||||
`
|
||||
sqlParams := []interface{}{
|
||||
skus.CategoryIDThird,
|
||||
}
|
||||
dao.GetRow(db, skuCat, sql, sqlParams)
|
||||
skuName := &model.SkuName{
|
||||
Prefix: prefix,
|
||||
Name: v.GoodsName,
|
||||
IsGlobal: model.YES,
|
||||
Unit: unit,
|
||||
SpecQuality: specQuality,
|
||||
SpecUnit: specUnit,
|
||||
Price: 100,
|
||||
Img: v.ImageURL,
|
||||
Upc: &v.UpcID,
|
||||
Status: model.SkuStatusNormal,
|
||||
}
|
||||
if skuCat.ID != 0 {
|
||||
skuName.CategoryID = skuCat.ID
|
||||
} else {
|
||||
skuName.CategoryID = -1 //默认给了个分类
|
||||
}
|
||||
dao.WrapAddIDCULDEntity(skuName, ctx.GetUserName())
|
||||
err = dao.CreateEntity(db, skuName)
|
||||
if err != nil {
|
||||
dao.Rollback(db)
|
||||
return result, err
|
||||
}
|
||||
sku := &model.Sku{
|
||||
NameID: skuName.ID,
|
||||
SpecQuality: specQuality,
|
||||
SpecUnit: specUnit,
|
||||
Weight: int(utils.Str2Int64(skus.Weight)),
|
||||
Status: model.SkuStatusNormal,
|
||||
ExdSkuID: v.ElemeGoodsID,
|
||||
ExdCategoryThirdID: skus.CategoryIDThird,
|
||||
}
|
||||
dao.WrapAddIDCULDEntity(sku, ctx.GetUserName())
|
||||
err = dao.CreateEntity(db, sku)
|
||||
if err != nil {
|
||||
dao.Rollback(db)
|
||||
return result, err
|
||||
}
|
||||
}
|
||||
dao.Commit(db)
|
||||
}
|
||||
}()
|
||||
prefix, _, _, specUnit, unit, specQuality := jxutils.SplitSkuName(v.GoodsName)
|
||||
skuName := &model.SkuName{
|
||||
Prefix: prefix,
|
||||
Name: v.GoodsName,
|
||||
CategoryID: skus.CategoryIDThird,
|
||||
IsGlobal: 1,
|
||||
Unit: unit,
|
||||
SpecQuality: specQuality,
|
||||
SpecUnit: specUnit,
|
||||
Price: 100,
|
||||
Img: v.ImageURL,
|
||||
Upc: &v.UpcID,
|
||||
Status: model.SkuStatusNormal,
|
||||
case 1:
|
||||
//刷新分类
|
||||
skus := &model.SkuAndName{}
|
||||
sql := `
|
||||
SELECT b.*, a.name, a.category_id real_category_id
|
||||
FROM sku_name a
|
||||
JOIN sku b ON b.name_id = a.id
|
||||
WHERE b.exd_sku_id <> ''
|
||||
AND a.deleted_at = ?
|
||||
AND b.deleted_at = ?
|
||||
AND a.category_id = -1
|
||||
`
|
||||
sqlParams := []interface{}{
|
||||
utils.DefaultTimeValue, utils.DefaultTimeValue,
|
||||
}
|
||||
err = dao.GetRows(db, &skus, sql, sqlParams)
|
||||
|
||||
}
|
||||
dao.WrapAddIDCULDEntity(skuName, ctx.GetUserName())
|
||||
err = dao.CreateEntity(db, skuName)
|
||||
if err != nil {
|
||||
dao.Rollback(db)
|
||||
return err
|
||||
}
|
||||
sku := &model.Sku{
|
||||
NameID: skuName.ID,
|
||||
SpecQuality: specQuality,
|
||||
SpecUnit: specUnit,
|
||||
Weight: int(utils.Str2Int64(skus.Weight)),
|
||||
Status: model.SkuStatusNormal,
|
||||
ExdSkuID: v.ElemeGoodsID,
|
||||
ExdCategoryThirdID: skus.CategoryIDThird,
|
||||
}
|
||||
dao.WrapAddIDCULDEntity(sku, ctx.GetUserName())
|
||||
err = dao.CreateEntity(db, sku)
|
||||
if err != nil {
|
||||
dao.Rollback(db)
|
||||
return err
|
||||
}
|
||||
dao.Commit(db)
|
||||
return result, err
|
||||
}
|
||||
return err
|
||||
taskSeq := tasksch.NewSeqTask2("合并饿鲜达商品库", ctx, isContinueWhenError, taskSeqFunc, 2)
|
||||
tasksch.HandleTask(taskSeq, nil, true).Run()
|
||||
if !isAsync {
|
||||
_, err = taskSeq.GetResult(0)
|
||||
hint = "1"
|
||||
} else {
|
||||
hint = taskSeq.GetID()
|
||||
}
|
||||
return hint, err
|
||||
}
|
||||
|
||||
func CopyEbaiSkuPriceToJx(ctx *jxcontext.Context, baiduShopID string) (err error) {
|
||||
@@ -1586,7 +1656,18 @@ func CopyEbaiStoreSkusToJx(ctx *jxcontext.Context, baiduShopID string, storeID i
|
||||
return err
|
||||
}
|
||||
|
||||
func AddExdSkuByExcel(ctx *jxcontext.Context, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||
func AddExdSkuByExcel(ctx *jxcontext.Context, files []*multipart.FileHeader, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||
if len(files) == 0 {
|
||||
return "", errors.New("没有文件上传!")
|
||||
}
|
||||
fileHeader := files[0]
|
||||
file, err := fileHeader.Open()
|
||||
hint, err = AddExdSkuByExcelBin(ctx, file, isAsync, isContinueWhenError)
|
||||
file.Close()
|
||||
return hint, err
|
||||
}
|
||||
|
||||
func AddExdSkuByExcelBin(ctx *jxcontext.Context, reader io.Reader, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
skuMap = make(map[string]string)
|
||||
@@ -1594,8 +1675,8 @@ func AddExdSkuByExcel(ctx *jxcontext.Context, isAsync, isContinueWhenError bool)
|
||||
taskSeqFunc := func(task *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) {
|
||||
switch step {
|
||||
case 0:
|
||||
xlsx, err := excelize.OpenFile("111.xlsx")
|
||||
// xlsx, err := excelize.OpenReader(reader)
|
||||
// xlsx, err := excelize.OpenFile("111.xlsx")
|
||||
xlsx, err := excelize.OpenReader(reader)
|
||||
if err != nil {
|
||||
return result, err
|
||||
}
|
||||
@@ -1620,11 +1701,13 @@ func AddExdSkuByExcel(ctx *jxcontext.Context, isAsync, isContinueWhenError bool)
|
||||
}
|
||||
case 1:
|
||||
for k, _ := range skuMap {
|
||||
fmt.Println(k, skuMap[k])
|
||||
result, err := api.EbaiAPI.GetExianDaSkuDepot(k)
|
||||
if err != nil {
|
||||
return result, err
|
||||
}
|
||||
if len(result) == 0 {
|
||||
continue
|
||||
}
|
||||
exdSku := result[0]
|
||||
skus, err := api.EbaiAPI.GetExianDaSku(utils.Str2Int64(exdSku.ElemeGoodsID))
|
||||
skuName := &model.SkuName{}
|
||||
@@ -1647,7 +1730,7 @@ func AddExdSkuByExcel(ctx *jxcontext.Context, isAsync, isContinueWhenError bool)
|
||||
}
|
||||
}()
|
||||
//表示京西库中已存在此饿鲜达商品,再判断更不更新名字
|
||||
if skuName != nil {
|
||||
if skuName.ID != 0 {
|
||||
if skuName.Name != skuMap[k] {
|
||||
skuName.Name = skuMap[k]
|
||||
_, err = dao.UpdateEntity(db, skuName, "Name")
|
||||
@@ -1659,10 +1742,19 @@ func AddExdSkuByExcel(ctx *jxcontext.Context, isAsync, isContinueWhenError bool)
|
||||
} else {
|
||||
//插入
|
||||
prefix, _, _, specUnit, unit, specQuality := jxutils.SplitSkuName(exdSku.GoodsName)
|
||||
skuCat := &model.SkuCategory{}
|
||||
sql := `
|
||||
SELECT *
|
||||
FROM sku_category
|
||||
WHERE ebai_category_id = ?
|
||||
`
|
||||
sqlParams := []interface{}{
|
||||
skus.CategoryIDThird,
|
||||
}
|
||||
dao.GetRow(db, skuCat, sql, sqlParams)
|
||||
skuName2 := &model.SkuName{
|
||||
Prefix: prefix,
|
||||
Name: skuMap[k],
|
||||
CategoryID: skus.CategoryIDThird,
|
||||
IsGlobal: 1,
|
||||
Unit: unit,
|
||||
SpecQuality: specQuality,
|
||||
@@ -1672,6 +1764,11 @@ func AddExdSkuByExcel(ctx *jxcontext.Context, isAsync, isContinueWhenError bool)
|
||||
Upc: &k,
|
||||
Status: model.SkuStatusNormal,
|
||||
}
|
||||
if skuCat.ID != 0 {
|
||||
skuName2.CategoryID = skuCat.ID
|
||||
} else {
|
||||
skuName2.CategoryID = skus.CategoryIDThird
|
||||
}
|
||||
dao.WrapAddIDCULDEntity(skuName2, ctx.GetUserName())
|
||||
err = dao.CreateEntity(db, skuName2)
|
||||
if err != nil {
|
||||
|
||||
@@ -185,6 +185,12 @@ type JdStoreSkus struct {
|
||||
Price int `json:"price"`
|
||||
}
|
||||
|
||||
type tUpdateSkuSpecTag struct {
|
||||
StoreID int `json:"storeID"`
|
||||
SkuID int `json:"skuID"`
|
||||
IsSpec int `json:"isSpec"`
|
||||
}
|
||||
|
||||
const (
|
||||
maxStoreNameBind = 10000 // 最大门店SkuName bind个数
|
||||
maxStoreNameBind2 = 10000 // 最大门店乘SkuName个数
|
||||
@@ -3315,8 +3321,8 @@ func UpdateStoreSkusSpecTag(ctx *jxcontext.Context, vendorIDs []int, files []*mu
|
||||
|
||||
func UpdateStoreSkusSpecTagBin(ctx *jxcontext.Context, reader io.Reader, vendorIDs []int, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
storeSkuMap = make(map[int][]*partner.StoreSkuInfo)
|
||||
db = dao.GetDB()
|
||||
results []*tUpdateSkuSpecTag
|
||||
)
|
||||
taskSeqFunc := func(task *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) {
|
||||
switch step {
|
||||
@@ -3331,30 +3337,51 @@ func UpdateStoreSkusSpecTagBin(ctx *jxcontext.Context, reader io.Reader, vendorI
|
||||
if rowNum < 1 {
|
||||
continue
|
||||
}
|
||||
getCellForSpecTag(rowNum, row, storeSkuMap)
|
||||
var (
|
||||
skuMap = &tUpdateSkuSpecTag{}
|
||||
storeID int
|
||||
skuID int
|
||||
isSpec int
|
||||
)
|
||||
for k, cell := range row {
|
||||
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.IsSpec = isSpec
|
||||
skuMap.StoreID = storeID
|
||||
results = append(results, skuMap)
|
||||
}
|
||||
case 1:
|
||||
for storeID, storeSkuInfos := range storeSkuMap {
|
||||
for i := 0; i < len(storeSkuInfos)/2; i++ {
|
||||
tmp := storeSkuInfos[i]
|
||||
storeSkuInfos[i] = storeSkuInfos[len(storeSkuInfos)-i-1]
|
||||
storeSkuInfos[len(storeSkuInfos)-i-1] = tmp
|
||||
for i := 0; i < len(results)/2; i++ {
|
||||
tmp := results[i]
|
||||
results[i] = results[len(results)-i-1]
|
||||
results[len(results)-i-1] = tmp
|
||||
}
|
||||
for _, v := range results {
|
||||
store, err := dao.GetStoreDetail(db, v.StoreID, model.VendorIDMTWM)
|
||||
food, err := api.MtwmAPI.RetailGet(store.VendorStoreID, utils.Int2Str(v.SkuID))
|
||||
if err != nil || store == nil {
|
||||
continue
|
||||
}
|
||||
for _, v := range storeSkuInfos {
|
||||
store, err := dao.GetStoreDetail(db, storeID, model.VendorIDMTWM)
|
||||
if err != nil || store == nil {
|
||||
continue
|
||||
}
|
||||
var foodData = make(map[string]interface{})
|
||||
if v.IsSpecialty != 0 && v.IsSpecialty == -1 {
|
||||
v.IsSpecialty = 0
|
||||
}
|
||||
foodData["is_specialty"] = v.IsSpecialty
|
||||
if globals.EnableMtwmStoreWrite {
|
||||
err = api.MtwmAPI.RetailInitData(ctx.GetTrackInfo(), store.VendorStoreID, utils.Int2Str(v.SkuID), foodData)
|
||||
}
|
||||
var foodData = make(map[string]interface{})
|
||||
if v.IsSpec != 0 && v.IsSpec == -1 {
|
||||
v.IsSpec = 0
|
||||
}
|
||||
foodData["is_specialty"] = v.IsSpec
|
||||
foodData["price"] = food.Price
|
||||
if globals.EnableMtwmStoreWrite {
|
||||
err = api.MtwmAPI.RetailInitData(ctx.GetTrackInfo(), store.VendorStoreID, utils.Int2Str(v.SkuID), foodData)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return result, err
|
||||
@@ -3370,31 +3397,6 @@ func UpdateStoreSkusSpecTagBin(ctx *jxcontext.Context, reader io.Reader, vendorI
|
||||
return hint, err
|
||||
}
|
||||
|
||||
func getCellForSpecTag(rowNum int, row []string, storeSkuMap map[int][]*partner.StoreSkuInfo) {
|
||||
var (
|
||||
skuMap = &partner.StoreSkuInfo{}
|
||||
storeID int
|
||||
skuID int
|
||||
isSpec int
|
||||
)
|
||||
for k, cell := range row {
|
||||
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
|
||||
|
||||
@@ -250,6 +250,7 @@ type SkuAndName struct {
|
||||
ActPrice int `json:"actPrice"`
|
||||
ActID int `orm:"column(act_id)" json:"actID"`
|
||||
ActType int `orm:"column(act_type)" json:"actType"`
|
||||
RealCategoryID int `orm:"column(real_category_id)" json:"realCategoryID"`
|
||||
|
||||
EarningPrice int `json:"earningPrice"`
|
||||
EarningActID int `orm:"column(earning_act_id)" json:"earningActID"`
|
||||
|
||||
Reference in New Issue
Block a user