饿鲜达商品库合并
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 {
|
||||
|
||||
@@ -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"`
|
||||
|
||||
@@ -423,12 +423,14 @@ func (c *SkuController) UpdateSkuNamesExPrefix() {
|
||||
// @Title 合并饿鲜达商品库
|
||||
// @Description 合并饿鲜达商品库
|
||||
// @Param token header string true "认证token"
|
||||
// @Param isAsync formData bool false "是否异步"
|
||||
// @Param isContinueWhenError formData bool false "单个同步失败是否继续,缺省false"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /SumExianDaDepot [put]
|
||||
func (c *SkuController) SumExianDaDepot() {
|
||||
c.callSumExianDaDepot(func(params *tSkuSumExianDaDepotParams) (retVal interface{}, errCode string, err error) {
|
||||
err = cms.SumExianDaDepot(params.Ctx)
|
||||
retVal, err = cms.SumExianDaDepot(params.Ctx, params.IsAsync, params.IsContinueWhenError)
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
@@ -461,20 +463,3 @@ func (c *SkuController) CopyEbaiStoreSkusToJx() {
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
// @Title 通过Excel创建饿鲜达商品(必须先要在饿鲜达系统中创建)
|
||||
// @Description 通过Excel创建饿鲜达商品(必须先要在饿鲜达系统中创建)
|
||||
// @Param token header string true "认证token"
|
||||
// @Param isAsync formData bool false "是否异步"
|
||||
// @Param isContinueWhenError formData bool false "单个同步失败是否继续,缺省false"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /AddExdSkuByExcel [post]
|
||||
func (c *SkuController) AddExdSkuByExcel() {
|
||||
c.callAddExdSkuByExcel(func(params *tSkuAddExdSkuByExcelParams) (retVal interface{}, errCode string, err error) {
|
||||
// r := c.Ctx.Request
|
||||
// files := r.MultipartForm.File["userfiles"]
|
||||
retVal, err = cms.AddExdSkuByExcel(params.Ctx, params.IsAsync, params.IsContinueWhenError)
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user