Merge remote-tracking branch 'origin/mark' into jdshop
This commit is contained in:
@@ -484,16 +484,6 @@ func GetSkuNames(ctx *jxcontext.Context, keyword string, isBySku, isQueryMidPric
|
||||
sqlParams = append(sqlParams, nameIDs)
|
||||
}
|
||||
}
|
||||
if params["isExd"] != nil {
|
||||
var idExd = params["isExd"].(bool)
|
||||
if idExd {
|
||||
sql += " AND t2.exd_sku_id <> ''"
|
||||
} else {
|
||||
sql += " AND t2.exd_sku_id = ''"
|
||||
}
|
||||
} else {
|
||||
sql += " AND t2.exd_sku_id = ''"
|
||||
}
|
||||
if params["categoryID"] != nil {
|
||||
cat := &model.SkuCategory{}
|
||||
cat.ID = params["categoryID"].(int)
|
||||
@@ -508,6 +498,16 @@ func GetSkuNames(ctx *jxcontext.Context, keyword string, isBySku, isQueryMidPric
|
||||
}
|
||||
sql += ")"
|
||||
}
|
||||
if params["isExd"] != nil {
|
||||
var idExd = params["isExd"].(bool)
|
||||
if idExd {
|
||||
sql += " AND t2.exd_sku_id <> ''"
|
||||
} else {
|
||||
sql += " AND t2.exd_sku_id = ''"
|
||||
}
|
||||
} else {
|
||||
sql += " AND t2.exd_sku_id = ''"
|
||||
}
|
||||
if params["skuCategoryID"] != nil {
|
||||
cat := &model.SkuCategory{}
|
||||
cat.ID = params["skuCategoryID"].(int)
|
||||
@@ -589,49 +589,10 @@ func GetSkuNames(ctx *jxcontext.Context, keyword string, isBySku, isQueryMidPric
|
||||
sql += " AND t2.status >= ? AND t2.status <= ?"
|
||||
sqlParams = append(sqlParams, fromStatus, toStatus)
|
||||
}
|
||||
sql += `
|
||||
GROUP BY
|
||||
t1.id,
|
||||
t1.created_at,
|
||||
t1.updated_at,
|
||||
t1.last_operator,
|
||||
t1.deleted_at,
|
||||
t1.prefix,
|
||||
t1.name,
|
||||
t1.brand_id,
|
||||
t1.category_id,
|
||||
t1.jd_category_id,
|
||||
t1.is_global,
|
||||
t1.unit,
|
||||
t1.price,
|
||||
t1.img,
|
||||
t1.img2,
|
||||
t1.img3,
|
||||
t1.img_watermark,
|
||||
t1.img_mix,
|
||||
t1.status,
|
||||
t1.is_spu,
|
||||
t1.desc_img,
|
||||
t1.upc,
|
||||
t1.ex_prefix,
|
||||
t1.ex_prefix_begin,
|
||||
t1.ex_prefix_end,
|
||||
t1.yb_name_suffix,
|
||||
t1.jds_stock_switch,
|
||||
t1.preparation_time,
|
||||
t1.best_seller
|
||||
`
|
||||
if isQueryMidPrice {
|
||||
sql += `,
|
||||
t4.mid_unit_price`
|
||||
}
|
||||
if isBySku {
|
||||
sql += `,
|
||||
t2.id`
|
||||
}
|
||||
sqlData := `
|
||||
SELECT
|
||||
SQL_CALC_FOUND_ROWS
|
||||
DISTINCT
|
||||
t1.id,
|
||||
t1.created_at,
|
||||
t1.updated_at,
|
||||
@@ -654,41 +615,22 @@ func GetSkuNames(ctx *jxcontext.Context, keyword string, isBySku, isQueryMidPric
|
||||
t1.is_spu,
|
||||
t1.desc_img,
|
||||
t1.upc,
|
||||
/*
|
||||
t1.jd_id,
|
||||
t1.jd_sync_status,
|
||||
*/
|
||||
t1.ex_prefix,
|
||||
t1.ex_prefix_begin,
|
||||
t1.ex_prefix_end,
|
||||
t1.yb_name_suffix,
|
||||
t1.jds_stock_switch,
|
||||
t1.preparation_time,
|
||||
t1.best_seller,
|
||||
t1.best_seller
|
||||
`
|
||||
if isQueryMidPrice {
|
||||
sqlData += " t4.mid_unit_price,"
|
||||
sqlData += ",t4.mid_unit_price"
|
||||
}
|
||||
sqlData +=
|
||||
`
|
||||
CONCAT("[", GROUP_CONCAT(DISTINCT CONCAT('{"id":', t2.id, ',"comment":"', t2.comment, '","status":', t2.status,
|
||||
',"createdAt":"', CONCAT(REPLACE(t2.created_at," ","T"),"+08:00"), '","updatedAt":"', CONCAT(REPLACE(t2.updated_at," ","T"),"+08:00"),
|
||||
'","lastOperator":"', t2.last_operator, '","specQuality":', t2.spec_quality, ',"specUnit":"', t2.spec_unit,
|
||||
'","exdSkuID":"', t2.exd_sku_id,
|
||||
'","eclpID":"', t2.eclp_id,
|
||||
'","weight":', t2.weight, ',"categoryID":', t2.category_id, ',"nameID":', t2.name_id,
|
||||
', "seq":', t2.seq,
|
||||
', "minOrderCount":', t2.min_order_count,
|
||||
', "ladderBoxNum":', t2.ladder_box_num,
|
||||
', "ladderBoxPrice":', t2.ladder_box_price,
|
||||
"}")), "]") skus_str,
|
||||
CONCAT("[", GROUP_CONCAT(DISTINCT t3.place_code), "]") places_str
|
||||
` + sql + `
|
||||
ORDER BY MIN(t2.seq), t1.id DESC
|
||||
sqlData += sql + `
|
||||
ORDER BY t1.id DESC
|
||||
LIMIT ? OFFSET ?`
|
||||
pageSize = jxutils.FormalizePageSize(pageSize)
|
||||
offset = jxutils.FormalizePageOffset(offset)
|
||||
|
||||
sqlParams = append(sqlParams, pageSize, offset)
|
||||
skuNamesInfo = &SkuNamesInfo{}
|
||||
dao.Begin(db) // todo 这里用事务的原因是,SQL_CALC_FOUND_ROWS会出错
|
||||
@@ -698,30 +640,28 @@ func GetSkuNames(ctx *jxcontext.Context, keyword string, isBySku, isQueryMidPric
|
||||
panic(r)
|
||||
}
|
||||
}()
|
||||
// globals.SugarLogger.Debug(sqlData)
|
||||
// globals.SugarLogger.Debug(utils.Format4Output(sqlParams, false))
|
||||
if err = dao.GetRows(db, &skuNamesInfo.SkuNames, sqlData, sqlParams...); err == nil {
|
||||
skuNamesInfo.TotalCount = dao.GetLastTotalRowCount(db)
|
||||
dao.Commit(db)
|
||||
|
||||
var skuIDs []int
|
||||
// var skuIDs []int
|
||||
for _, skuName := range skuNamesInfo.SkuNames {
|
||||
skuName.FullName = jxutils.ComposeSkuName(skuName.Prefix, skuName.Name, "", "", 0, "", 0, skuName.ExPrefix, skuName.ExPrefixBegin, skuName.ExPrefixEnd)
|
||||
if skuName.SkusStr != "" {
|
||||
if err = utils.UnmarshalUseNumber([]byte(skuName.SkusStr), &skuName.Skus); err != nil {
|
||||
dao.Rollback(db)
|
||||
return nil, err
|
||||
}
|
||||
for _, v := range skuName.Skus {
|
||||
skuIDs = append(skuIDs, v.ID)
|
||||
}
|
||||
}
|
||||
if skuName.PlacesStr != "" {
|
||||
if err = utils.UnmarshalUseNumber([]byte(skuName.PlacesStr), &skuName.Places); err != nil {
|
||||
dao.Rollback(db)
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
// if skuName.SkusStr != "" {
|
||||
// if err = utils.UnmarshalUseNumber([]byte(skuName.SkusStr), &skuName.Skus); err != nil {
|
||||
// dao.Rollback(db)
|
||||
// return nil, err
|
||||
// }
|
||||
// for _, v := range skuName.Skus {
|
||||
// skuIDs = append(skuIDs, v.ID)
|
||||
// }
|
||||
// }
|
||||
// if skuName.PlacesStr != "" {
|
||||
// if err = utils.UnmarshalUseNumber([]byte(skuName.PlacesStr), &skuName.Places); err != nil {
|
||||
// dao.Rollback(db)
|
||||
// return nil, err
|
||||
// }
|
||||
// }
|
||||
skuVendorCats, _ := dao.GetSkuVendorCategoryMaps(db, []int{skuName.ID}, []int{model.VendorIDMTWM, model.VendorIDEBAI, model.VendorIDJDShop, model.VendorIDJD}, nil)
|
||||
if len(skuVendorCats) > 0 {
|
||||
for _, v := range skuVendorCats {
|
||||
@@ -739,15 +679,42 @@ func GetSkuNames(ctx *jxcontext.Context, keyword string, isBySku, isQueryMidPric
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(skuIDs) > 0 {
|
||||
thingMapMap, err2 := dao.GetThingMapMap(db, model.ThingTypeSku, nil, skuIDs)
|
||||
if err = err2; err == nil {
|
||||
for _, skuName := range skuNamesInfo.SkuNames {
|
||||
for _, v := range skuName.Skus {
|
||||
v.MapList = thingMapMap[int64(v.ID)]
|
||||
var skus []*model.Sku
|
||||
sql := `
|
||||
SELECT * FROM sku WHERE deleted_at = ? AND name_id = ?
|
||||
`
|
||||
sqlParams := []interface{}{utils.DefaultTimeValue, skuName.ID}
|
||||
if err = dao.GetRows(db, &skus, sql, sqlParams); err == nil {
|
||||
var skusVendors []*model.SkuWithVendor
|
||||
for _, v := range skus {
|
||||
skusVendor := &model.SkuWithVendor{
|
||||
Sku: v,
|
||||
}
|
||||
skusVendors = append(skusVendors, skusVendor)
|
||||
}
|
||||
skuName.Skus = skusVendors
|
||||
// thingMapMap, err2 := dao.GetThingMapMap(db, model.ThingTypeSku, nil, nil)
|
||||
// if err = err2; err == nil {
|
||||
// for _, skuName := range skuNamesInfo.SkuNames {
|
||||
// for _, v := range skuName.Skus {
|
||||
// v.MapList = thingMapMap[int64(v.ID)]
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
var (
|
||||
places []*model.SkuNamePlaceBind
|
||||
placeCodes []int
|
||||
)
|
||||
sql2 := `
|
||||
SELECT * FROM sku_name_place_bind WHERE name_id = ?
|
||||
`
|
||||
sqlParams2 := []interface{}{skuName.ID}
|
||||
if err = dao.GetRows(db, &places, sql2, sqlParams2); err == nil {
|
||||
for _, v := range places {
|
||||
placeCodes = append(placeCodes, v.PlaceCode)
|
||||
}
|
||||
skuName.Places = placeCodes
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -850,7 +817,7 @@ func AddSkuName(ctx *jxcontext.Context, skuNameExt *model.SkuNameExt, userName s
|
||||
}
|
||||
|
||||
picType := true
|
||||
for _, imgName := range []string{skuNameExt.Img, skuNameExt.Img2} {
|
||||
for _, imgName := range []string{skuNameExt.Img, skuNameExt.Img2, skuNameExt.Img3, skuNameExt.Img4, skuNameExt.Img5} {
|
||||
if imgName != "" {
|
||||
dataRes, err2 := datares.TryRegisterDataResource(ctx, skuNameExt.Name, imgName, model.ImgTypeMain, false)
|
||||
if err = err2; err != nil {
|
||||
@@ -973,7 +940,7 @@ func UpdateSkuName(ctx *jxcontext.Context, nameID int, payload map[string]interf
|
||||
}
|
||||
}
|
||||
globals.SugarLogger.Debugf("UpdateSkuName valid:%s", utils.Format4Output(valid, false))
|
||||
for _, imgName := range []string{"img", "img2", "img3"} {
|
||||
for _, imgName := range []string{"img", "img2", "img3", "img4", "img5"} {
|
||||
if valid[imgName] != nil {
|
||||
if imgStr := utils.Interface2String(valid[imgName]); imgStr != "" {
|
||||
_, err2 := datares.TryRegisterDataResource(ctx, skuName.Name, valid[imgName].(string), model.ImgTypeMain, true)
|
||||
@@ -1656,6 +1623,27 @@ func GetJdUpcCodeByName(ctx *jxcontext.Context, name, upcCode string) (productIn
|
||||
}
|
||||
} else {
|
||||
productInfos, err = GetJdUpcCodeByCode(ctx, upcCode)
|
||||
if len(productInfos) == 0 {
|
||||
if configs, err := dao.QueryConfigs(dao.GetDB(), "mtwmCookieStr", model.ConfigTypeCookie, ""); err == nil {
|
||||
api.MtwmAPI.SetCookieWithStr(configs[0].Value)
|
||||
}
|
||||
if result, err := api.MtwmAPI.GetStandardProductListWithCond(upcCode); err == nil && result != nil {
|
||||
productInfo := &jdapi.ProductInfo{
|
||||
OriginalName: result.Name,
|
||||
OriginalSpec: result.Spec,
|
||||
}
|
||||
// _, name, _, specUnit, unit, specQuality := jxutils.SplitSkuName(productInfo.OriginalName)
|
||||
productInfo.Name = name
|
||||
productInfo.SpecUnit = result.SpecUnit
|
||||
productInfo.Unit = result.Unit
|
||||
productInfo.SpecQuality = float32(result.SpecNew)
|
||||
productInfo.ImgList = strings.Split(result.Pic, ",")
|
||||
productInfo.Weight = float32(result.Weight)
|
||||
productInfo.Price = result.AvgPrice
|
||||
productInfo.BrandName = result.BrandNamePath
|
||||
productInfos = append(productInfos, productInfo)
|
||||
}
|
||||
}
|
||||
}
|
||||
return productInfos, err
|
||||
}
|
||||
@@ -2108,24 +2096,6 @@ func CreateUpcSkuByExcelBin(ctx *jxcontext.Context, reader io.Reader, categoryID
|
||||
return retVal, err
|
||||
}
|
||||
skuName.Img = downloadURL
|
||||
// if resBinary, _, err := jxutils.DownloadFileByURL(result.Img); err == nil {
|
||||
// if downloadURL, err := jxutils.UploadExportContent(resBinary, utils.Int64ToStr(time.Now().Unix())+"origin"+result.Img[strings.LastIndex(result.Img, "/")+1:len(result.Img)]); err == nil {
|
||||
// resBinary2, _, err := jxutils.DownloadFileByURL(downloadURL + model.SkuNameImgStandard)
|
||||
// downloadURL2, err := jxutils.UploadExportContent(resBinary2, utils.Int64ToStr(time.Now().Unix())+downloadURL[strings.LastIndex(downloadURL, "/")+1:len(downloadURL)])
|
||||
// if err == nil {
|
||||
// skuName.Img = downloadURL2
|
||||
// } else {
|
||||
// retVal = []*CreateUpcSkuByExcelErr{buildCreateUpcSkuByExcelErr(v, err.Error())}
|
||||
// return retVal, err
|
||||
// }
|
||||
// } else {
|
||||
// retVal = []*CreateUpcSkuByExcelErr{buildCreateUpcSkuByExcelErr(v, err.Error())}
|
||||
// return retVal, err
|
||||
// }
|
||||
// } else {
|
||||
// retVal = []*CreateUpcSkuByExcelErr{buildCreateUpcSkuByExcelErr(v, err.Error())}
|
||||
// return retVal, err
|
||||
// }
|
||||
} else {
|
||||
skuName.Img = model.NOSkuNameImg
|
||||
}
|
||||
@@ -2291,7 +2261,7 @@ func CreateUpcSkuByExcelBin(ctx *jxcontext.Context, reader io.Reader, categoryID
|
||||
}
|
||||
}
|
||||
if len(productInfo.ImgList) > 0 {
|
||||
skuName.Img = productInfo.ImgList[0]
|
||||
setImgs(skuName, productInfo.ImgList)
|
||||
} else {
|
||||
skuName.Img = model.NOSkuNameImg
|
||||
}
|
||||
@@ -2306,45 +2276,6 @@ func CreateUpcSkuByExcelBin(ctx *jxcontext.Context, reader io.Reader, categoryID
|
||||
retVal = []*CreateUpcSkuByExcelErr{buildCreateUpcSkuByExcelErr(v, fmt.Sprintf("暂不支持的图片格式:[%v]", skuName.Img))}
|
||||
return retVal, err
|
||||
}
|
||||
//需要把图片传到七牛云上
|
||||
if !strings.Contains(skuName.Img, "image.jxc4.com") {
|
||||
downloadURL, err := uploadImgStandard(skuName.Img)
|
||||
if err != nil {
|
||||
retVal = []*CreateUpcSkuByExcelErr{buildCreateUpcSkuByExcelErr(v, err.Error())}
|
||||
return retVal, err
|
||||
}
|
||||
skuName.Img = downloadURL
|
||||
// if resBinary, _, err := jxutils.DownloadFileByURL(skuName.Img); err == nil {
|
||||
// if downloadURL, err := jxutils.UploadExportContent(resBinary, utils.Int64ToStr(time.Now().Unix())+"origin"+skuName.Img[strings.LastIndex(skuName.Img, "/")+1:len(skuName.Img)]); err == nil {
|
||||
// if img, _, err := datares.Binary2Image(resBinary, http.DetectContentType(resBinary)); err == nil {
|
||||
// if img.Bounds().Dx() != datares.MainImgWidth || img.Bounds().Dy() != datares.MainImgHeight {
|
||||
// if resBinary2, _, err := jxutils.DownloadFileByURL(downloadURL + model.SkuNameImgStandard); err == nil {
|
||||
// if downloadURL2, err := jxutils.UploadExportContent(resBinary2, utils.Int64ToStr(time.Now().Unix())+skuName.Img[strings.LastIndex(skuName.Img, "/")+1:len(skuName.Img)]); err == nil {
|
||||
// skuName.Img = downloadURL2
|
||||
// } else {
|
||||
// retVal = []*CreateUpcSkuByExcelErr{buildCreateUpcSkuByExcelErr(v, err.Error())}
|
||||
// return retVal, err
|
||||
// }
|
||||
// } else {
|
||||
// retVal = []*CreateUpcSkuByExcelErr{buildCreateUpcSkuByExcelErr(v, err.Error())}
|
||||
// return retVal, err
|
||||
// }
|
||||
// } else {
|
||||
// skuName.Img = downloadURL
|
||||
// }
|
||||
// } else {
|
||||
// retVal = []*CreateUpcSkuByExcelErr{buildCreateUpcSkuByExcelErr(v, err.Error())}
|
||||
// return retVal, err
|
||||
// }
|
||||
// } else {
|
||||
// retVal = []*CreateUpcSkuByExcelErr{buildCreateUpcSkuByExcelErr(v, err.Error())}
|
||||
// return retVal, err
|
||||
// }
|
||||
// } else {
|
||||
// retVal = []*CreateUpcSkuByExcelErr{buildCreateUpcSkuByExcelErr(v, err.Error())}
|
||||
// return retVal, err
|
||||
// }
|
||||
}
|
||||
skuName.Status = model.SkuStatusNormal
|
||||
skuName.IsGlobal = model.YES
|
||||
if categoryID == 0 {
|
||||
@@ -2353,6 +2284,68 @@ func CreateUpcSkuByExcelBin(ctx *jxcontext.Context, reader io.Reader, categoryID
|
||||
skuName.CategoryID = categoryID
|
||||
}
|
||||
skuName.Skus[0].Status = model.SkuStatusNormal
|
||||
if skuName.Img == model.NOSkuNameImg {
|
||||
if configs, err := dao.QueryConfigs(dao.GetDB(), "mtwmCookieStr", model.ConfigTypeCookie, ""); err == nil {
|
||||
api.MtwmAPI.SetCookieWithStr(configs[0].Value)
|
||||
}
|
||||
result, _ := api.MtwmAPI.GetStandardProductListWithCond(*skuName.Upc)
|
||||
if result != nil {
|
||||
imgs := strings.Split(result.Pic, ",")
|
||||
setImgs(skuName, imgs)
|
||||
} else {
|
||||
retVal = []*CreateUpcSkuByExcelErr{buildCreateUpcSkuByExcelErr(v, "美团cookie过期了吧")}
|
||||
return retVal, err
|
||||
}
|
||||
}
|
||||
//需要把图片传到七牛云上, 很难受
|
||||
if !strings.Contains(skuName.Img, "image.jxc4.com") {
|
||||
downloadURL, err := uploadImgStandard(skuName.Img)
|
||||
if err != nil {
|
||||
retVal = []*CreateUpcSkuByExcelErr{buildCreateUpcSkuByExcelErr(v, err.Error())}
|
||||
return retVal, err
|
||||
}
|
||||
skuName.Img = downloadURL
|
||||
}
|
||||
if skuName.Img2 != "" {
|
||||
if !strings.Contains(skuName.Img2, "image.jxc4.com") {
|
||||
downloadURL, err := uploadImgStandard(skuName.Img2)
|
||||
if err != nil {
|
||||
retVal = []*CreateUpcSkuByExcelErr{buildCreateUpcSkuByExcelErr(v, err.Error())}
|
||||
return retVal, err
|
||||
}
|
||||
skuName.Img2 = downloadURL
|
||||
}
|
||||
}
|
||||
if skuName.Img3 != "" {
|
||||
if !strings.Contains(skuName.Img3, "image.jxc4.com") {
|
||||
downloadURL, err := uploadImgStandard(skuName.Img3)
|
||||
if err != nil {
|
||||
retVal = []*CreateUpcSkuByExcelErr{buildCreateUpcSkuByExcelErr(v, err.Error())}
|
||||
return retVal, err
|
||||
}
|
||||
skuName.Img3 = downloadURL
|
||||
}
|
||||
}
|
||||
if skuName.Img4 != "" {
|
||||
if !strings.Contains(skuName.Img4, "image.jxc4.com") {
|
||||
downloadURL, err := uploadImgStandard(skuName.Img4)
|
||||
if err != nil {
|
||||
retVal = []*CreateUpcSkuByExcelErr{buildCreateUpcSkuByExcelErr(v, err.Error())}
|
||||
return retVal, err
|
||||
}
|
||||
skuName.Img4 = downloadURL
|
||||
}
|
||||
}
|
||||
if skuName.Img5 != "" {
|
||||
if !strings.Contains(skuName.Img5, "image.jxc4.com") {
|
||||
downloadURL, err := uploadImgStandard(skuName.Img5)
|
||||
if err != nil {
|
||||
retVal = []*CreateUpcSkuByExcelErr{buildCreateUpcSkuByExcelErr(v, err.Error())}
|
||||
return retVal, err
|
||||
}
|
||||
skuName.Img5 = downloadURL
|
||||
}
|
||||
}
|
||||
_, err = AddSkuName(ctx, skuName, ctx.GetUserName())
|
||||
if err != nil {
|
||||
retVal = []*CreateUpcSkuByExcelErr{buildCreateUpcSkuByExcelErr(v, err.Error())}
|
||||
@@ -2863,6 +2856,29 @@ func UpdateVendorCategoryMap(ctx *jxcontext.Context, ID int, vendorCategoryMap *
|
||||
}
|
||||
}
|
||||
}
|
||||
var countInfos []*struct{ Ct int }
|
||||
db := dao.GetDB()
|
||||
if err = dao.GetRows(db, &countInfos, `
|
||||
SELECT COUNT(*) ct
|
||||
FROM sku t1
|
||||
WHERE t1.category_id = ? AND t1.deleted_at = ?
|
||||
UNION ALL
|
||||
SELECT COUNT(*) ct
|
||||
FROM sku_name t1
|
||||
WHERE t1.category_id = ? AND t1.deleted_at = ?
|
||||
UNION ALL
|
||||
SELECT COUNT(*) ct
|
||||
FROM sku_category t1
|
||||
WHERE t1.parent_id = ? AND t1.deleted_at = ?
|
||||
`, vendorCategoryMap2.CategoryID, utils.DefaultTimeValue, vendorCategoryMap2.CategoryID, utils.DefaultTimeValue, vendorCategoryMap2.CategoryID, utils.DefaultTimeValue, &countInfos); err == nil {
|
||||
if countInfos[0].Ct != 0 {
|
||||
return 0, errors.New("还有商品使用此类别,不能删除")
|
||||
} else if countInfos[1].Ct != 0 {
|
||||
return 0, errors.New("还有商品名使用此类别,不能删除")
|
||||
} else if countInfos[2].Ct != 0 {
|
||||
return 0, errors.New("还有商品类别使用此类别,不能删除")
|
||||
}
|
||||
}
|
||||
}
|
||||
vendorOrgCodes, err := dao.GetVendorOrgCode(db, vendorCategoryMap2.VendorID, vendorCategoryMap2.VendorOrgCode, model.VendorOrgTypePlatform)
|
||||
dao.Begin(db)
|
||||
@@ -2933,6 +2949,9 @@ func LoadStoreVendorCategories(ctx *jxcontext.Context, vendorOrgCode string, ven
|
||||
return fmt.Errorf("未查询到该门店有门店分类,请重新选择! [%v]", storeID)
|
||||
}
|
||||
vendorOrgCodes, _ := dao.GetVendorOrgCode(db, vendorID, vendorOrgCode, model.VendorOrgTypePlatform)
|
||||
if vendorCatMap, _ := dao.GetVendorCategoryMap(db, -1, 0, vendorID, vendorOrgCode, 0); len(vendorCatMap) > 0 {
|
||||
return fmt.Errorf("该账号下已有分类,请在这里修改!")
|
||||
}
|
||||
dao.Begin(db)
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
@@ -2977,5 +2996,136 @@ func LoadStoreVendorCategories(ctx *jxcontext.Context, vendorOrgCode string, ven
|
||||
OnCreateThing(ctx, db, vendorOrgCodes, int64(v.CategoryID), model.ThingTypeCategory, model.SyncFlagNewMask, true)
|
||||
}
|
||||
}
|
||||
if _, err = SyncCategories(ctx, nil, []int{vendorID}, []string{vendorOrgCode}, nil, false); err == nil {
|
||||
SyncReorderCategories2(ctx, 0, vendorID, vendorOrgCode)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func RefreshNoImgSku(ctx *jxcontext.Context) (err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
skuNames []*model.SkuName
|
||||
)
|
||||
sql := `
|
||||
SELECT * FROM sku_name WHERE deleted_at = ? AND upc <> '' AND img2 = ''
|
||||
`
|
||||
sqlParams := []interface{}{
|
||||
utils.DefaultTimeValue,
|
||||
}
|
||||
dao.GetRows(db, &skuNames, sql, sqlParams)
|
||||
task := tasksch.NewParallelTask("uuuuu", tasksch.NewParallelConfig().SetParallelCount(20).SetIsContinueWhenError(true), ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
v := batchItemList[0].(*model.SkuName)
|
||||
if v.Upc != nil {
|
||||
productInfos, _ := api.JdAPI.GetJdUpcCodeByName("", *v.Upc, 1, 30)
|
||||
if len(productInfos) > 0 {
|
||||
productInfo := productInfos[0]
|
||||
if len(productInfo.ImgList) >= 5 {
|
||||
v.Img = productInfo.ImgList[0]
|
||||
v.Img2 = productInfo.ImgList[1]
|
||||
v.Img3 = productInfo.ImgList[2]
|
||||
v.Img4 = productInfo.ImgList[3]
|
||||
v.Img5 = productInfo.ImgList[4]
|
||||
} else {
|
||||
result, _ := api.MtwmAPI.GetStandardProductListWithCond(*v.Upc)
|
||||
if result != nil {
|
||||
imgs := strings.Split(result.Pic, ",")
|
||||
if len(imgs) >= 5 {
|
||||
v.Img = imgs[0]
|
||||
v.Img2 = imgs[1]
|
||||
v.Img3 = imgs[2]
|
||||
v.Img4 = imgs[3]
|
||||
v.Img5 = imgs[4]
|
||||
} else {
|
||||
if len(imgs) > len(productInfo.ImgList) {
|
||||
setImgs2(v, imgs)
|
||||
} else {
|
||||
setImgs2(v, productInfo.ImgList)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
setImgs2(v, productInfo.ImgList)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
result, _ := api.MtwmAPI.GetStandardProductListWithCond(*v.Upc)
|
||||
if result != nil {
|
||||
imgs := strings.Split(result.Pic, ",")
|
||||
setImgs2(v, imgs)
|
||||
}
|
||||
}
|
||||
dao.UpdateEntity(db, v, "Img", "Img2", "Img3", "Img4", "Img5")
|
||||
}
|
||||
return retVal, err
|
||||
}, skuNames)
|
||||
tasksch.HandleTask(task, nil, true).Run()
|
||||
_, err = task.GetResult(0)
|
||||
return err
|
||||
}
|
||||
|
||||
func setImgs(v *model.SkuNameExt, imgs []string) (err error) {
|
||||
switch len(imgs) {
|
||||
case 0:
|
||||
case 1:
|
||||
v.Img = imgs[0]
|
||||
case 2:
|
||||
v.Img = imgs[0]
|
||||
v.Img2 = imgs[1]
|
||||
case 3:
|
||||
v.Img = imgs[0]
|
||||
v.Img2 = imgs[1]
|
||||
v.Img3 = imgs[2]
|
||||
case 4:
|
||||
v.Img = imgs[0]
|
||||
v.Img2 = imgs[1]
|
||||
v.Img3 = imgs[2]
|
||||
v.Img4 = imgs[3]
|
||||
case 5:
|
||||
v.Img = imgs[0]
|
||||
v.Img2 = imgs[1]
|
||||
v.Img3 = imgs[2]
|
||||
v.Img4 = imgs[3]
|
||||
v.Img5 = imgs[4]
|
||||
default:
|
||||
v.Img = imgs[0]
|
||||
v.Img2 = imgs[1]
|
||||
v.Img3 = imgs[2]
|
||||
v.Img4 = imgs[3]
|
||||
v.Img5 = imgs[4]
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func setImgs2(v *model.SkuName, imgs []string) (err error) {
|
||||
switch len(imgs) {
|
||||
case 0:
|
||||
case 1:
|
||||
v.Img = imgs[0]
|
||||
case 2:
|
||||
v.Img = imgs[0]
|
||||
v.Img2 = imgs[1]
|
||||
case 3:
|
||||
v.Img = imgs[0]
|
||||
v.Img2 = imgs[1]
|
||||
v.Img3 = imgs[2]
|
||||
case 4:
|
||||
v.Img = imgs[0]
|
||||
v.Img2 = imgs[1]
|
||||
v.Img3 = imgs[2]
|
||||
v.Img4 = imgs[3]
|
||||
case 5:
|
||||
v.Img = imgs[0]
|
||||
v.Img2 = imgs[1]
|
||||
v.Img3 = imgs[2]
|
||||
v.Img4 = imgs[3]
|
||||
v.Img5 = imgs[4]
|
||||
default:
|
||||
v.Img = imgs[0]
|
||||
v.Img2 = imgs[1]
|
||||
v.Img3 = imgs[2]
|
||||
v.Img4 = imgs[3]
|
||||
v.Img5 = imgs[4]
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -14,6 +14,8 @@ import (
|
||||
"time"
|
||||
"unicode/utf8"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/business/auth2"
|
||||
"git.rosy.net.cn/jx-callback/business/auth2/authprovider/weixin"
|
||||
"git.rosy.net.cn/jx-callback/business/jxstore/permission"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/business/authz"
|
||||
@@ -183,33 +185,33 @@ var (
|
||||
"payeeBankCode": "开户行代码",
|
||||
"payPercentage": "支付比例",
|
||||
}
|
||||
roleMoblieMap = map[string]string{
|
||||
"17380734342": "17380734342", //漆云的手机 ,用于判断updatestore的权限
|
||||
"18328080405": "18328080405", //肖娜娜的手机
|
||||
"13350726500": "13350726500", //谭翔心
|
||||
"15928865396": "15928865396", //何佳梦
|
||||
"18048531223": "18048531223", //石老板
|
||||
"18982250714": "18982250714", //赵敏夫
|
||||
"13708196093": "13708196093", //顾子航
|
||||
"15680070110": "15680070110", //李荣维
|
||||
"15208271238": "15208271238",
|
||||
}
|
||||
// roleMoblieMap = map[string]string{
|
||||
// "17380734342": "17380734342", //漆云的手机 ,用于判断updatestore的权限
|
||||
// "18328080405": "18328080405", //肖娜娜的手机
|
||||
// "13350726500": "13350726500", //谭翔心
|
||||
// "15928865396": "15928865396", //何佳梦
|
||||
// "18048531223": "18048531223", //石老板
|
||||
// "18982250714": "18982250714", //赵敏夫
|
||||
// "13708196093": "13708196093", //顾子航
|
||||
// "15680070110": "15680070110", //李荣维
|
||||
// "15208271238": "15208271238",
|
||||
// }
|
||||
|
||||
marketManPhoneRoleMap = map[string]string{
|
||||
"marketManPhone": "市场负责人电话",
|
||||
}
|
||||
|
||||
marketManPhoneRoleMoblieMap = map[string]string{
|
||||
"13684045763": "13684045763",
|
||||
"18160030913": "18160030913",
|
||||
"18048531223": "18048531223",
|
||||
"18328080405": "18328080405",
|
||||
"17380734342": "17380734342",
|
||||
"15208271238": "15208271238",
|
||||
"18583684218": "18583684218",
|
||||
"18982250714": "18982250714",
|
||||
"13708196093": "13708196093",
|
||||
}
|
||||
// marketManPhoneRoleMoblieMap = map[string]string{
|
||||
// "13684045763": "13684045763",
|
||||
// "18160030913": "18160030913",
|
||||
// "18048531223": "18048531223",
|
||||
// "18328080405": "18328080405",
|
||||
// "17380734342": "17380734342",
|
||||
// "15208271238": "15208271238",
|
||||
// "18583684218": "18583684218",
|
||||
// "18982250714": "18982250714",
|
||||
// "13708196093": "13708196093",
|
||||
// }
|
||||
)
|
||||
|
||||
func getStoresSql(ctx *jxcontext.Context, keyword string, params map[string]interface{}, orderTimeFrom, orderTimeTo time.Time) (sql string, sqlParams []interface{}, sqlFrom string, sqlFromParams []interface{}, err error) {
|
||||
@@ -921,20 +923,26 @@ func UpdateStore(ctx *jxcontext.Context, storeID int, payload map[string]interfa
|
||||
}
|
||||
|
||||
for k, _ := range valid {
|
||||
if roleMap[k] != "" {
|
||||
if authInfo, err := ctx.GetV2AuthInfo(); err == nil {
|
||||
if roleMoblieMap[authInfo.Mobile] == "" {
|
||||
return 0, errors.New(fmt.Sprintf("当前用户 [%v] 无权限修改 [%v] 字段!", authInfo.Name, roleMap[k]))
|
||||
}
|
||||
}
|
||||
}
|
||||
if marketManPhoneRoleMap[k] != "" {
|
||||
if authInfo, err := ctx.GetV2AuthInfo(); err == nil {
|
||||
if marketManPhoneRoleMoblieMap[authInfo.Mobile] == "" {
|
||||
return 0, errors.New(fmt.Sprintf("当前用户 [%v] 无权限修改 [%v] 字段!", authInfo.Name, roleMap[k]))
|
||||
}
|
||||
if roleMap[k] != "" || marketManPhoneRoleMap[k] != "" {
|
||||
menus, _ := dao.GetMenuWithUser(dao.GetDB(), "结算权限", 0, 1, ctx.GetUserID())
|
||||
if len(menus) == 0 {
|
||||
return 0, errors.New(fmt.Sprintf("当前用户 [%v] 无权限修改此字段!", ctx.GetUserName()))
|
||||
}
|
||||
}
|
||||
// if roleMap[k] != "" {
|
||||
// if authInfo, err := ctx.GetV2AuthInfo(); err == nil {
|
||||
// if roleMoblieMap[authInfo.Mobile] == "" {
|
||||
// return 0, errors.New(fmt.Sprintf("当前用户 [%v] 无权限修改 [%v] 字段!", authInfo.Name, roleMap[k]))
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// if marketManPhoneRoleMap[k] != "" {
|
||||
// if authInfo, err := ctx.GetV2AuthInfo(); err == nil {
|
||||
// if marketManPhoneRoleMoblieMap[authInfo.Mobile] == "" {
|
||||
// return 0, errors.New(fmt.Sprintf("当前用户 [%v] 无权限修改 [%v] 字段!", authInfo.Name, roleMap[k]))
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
// districtCode := 0
|
||||
@@ -1198,15 +1206,16 @@ func AddStoreVendorMap(ctx *jxcontext.Context, db *dao.DaoDB, vendorID int, vend
|
||||
if store != nil {
|
||||
storeMap.DeliveryType = store.DeliveryType
|
||||
storeMap.Status = store.Status
|
||||
storeMap.VendorStoreName = store.Name
|
||||
}
|
||||
err = nil
|
||||
}
|
||||
} else {
|
||||
//美团商超获取token
|
||||
mtapi := apimanager.CurAPIManager.GetAPI(model.VendorIDMTWM, outStoreMap.VendorOrgCode).(*mtwmapi.API)
|
||||
if token, err := mtapi.GetAccessToken2(outStoreMap.VendorStoreID); err == nil && token != nil {
|
||||
mtapi := apimanager.CurAPIManager.GetAPI(model.VendorIDMTWM, storeMap.VendorOrgCode).(*mtwmapi.API)
|
||||
if token, err := mtapi.GetAccessToken2(storeMap.VendorStoreID); err == nil && token != nil {
|
||||
storeMap.MtwmToken = token.AccessToken
|
||||
storeMap.MtwmToken = token.RefreshToken
|
||||
storeMap.MtwmRefreshToken = token.RefreshToken
|
||||
}
|
||||
}
|
||||
storeMap.SyncStatus = model.SyncFlagModifiedMask | model.SyncFlagStoreName | model.SyncFlagStoreAddress // 新增绑定门店是修改的概念
|
||||
@@ -1225,7 +1234,6 @@ func AddStoreVendorMap(ctx *jxcontext.Context, db *dao.DaoDB, vendorID int, vend
|
||||
return nil, err
|
||||
}
|
||||
} else if vendorID == model.VendorIDJDShop {
|
||||
storeMap.VendorOrgCode = "1"
|
||||
if storeMap.VendorStoreID == "" {
|
||||
storeMap.SyncStatus = model.SyncFlagNewMask //京东商城要去建店
|
||||
} else {
|
||||
@@ -1262,11 +1270,6 @@ func AddStoreVendorMap(ctx *jxcontext.Context, db *dao.DaoDB, vendorID int, vend
|
||||
}
|
||||
}()
|
||||
if err = dao.CreateEntity(db, storeMap); err == nil {
|
||||
if vendorID == model.VendorIDJDShop {
|
||||
storeMap2 := storeMap
|
||||
storeMap2.VendorOrgCode = "2"
|
||||
dao.CreateEntity(db, storeMap2)
|
||||
}
|
||||
dao.Commit(db)
|
||||
outStoreMap = storeMap
|
||||
} else {
|
||||
@@ -1539,6 +1542,9 @@ func TmpGetJxBadCommentsByStoreId(ctx *jxcontext.Context, keyword string, storeI
|
||||
storeIDs2 = append(storeIDs2, v)
|
||||
}
|
||||
}
|
||||
if len(storeIDs2) == 0 {
|
||||
storeIDs2 = append(storeIDs2, -1)
|
||||
}
|
||||
} else {
|
||||
for k, _ := range storeIDsMap {
|
||||
storeIDs2 = append(storeIDs2, k)
|
||||
@@ -2846,6 +2852,9 @@ func GetStorePriceScore(ctx *jxcontext.Context, storeIDs, vendorIDs []int, fromS
|
||||
storeIDs2 = append(storeIDs2, v)
|
||||
}
|
||||
}
|
||||
if len(storeIDs2) == 0 {
|
||||
storeIDs2 = append(storeIDs2, -1)
|
||||
}
|
||||
} else {
|
||||
for k, _ := range storeIDsMap {
|
||||
storeIDs2 = append(storeIDs2, k)
|
||||
@@ -3170,6 +3179,13 @@ func GetStoreCategoryMap(ctx *jxcontext.Context, parentID, level int, storeID in
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if ctx.GetLoginType() != weixin.AuthTypeMP && ctx.GetLoginType() != weixin.AuthTypeMini && ctx.GetLoginType() != weixin.AuthTypeWxApp && ctx.GetLoginType() != auth2.AuthTypeMobile {
|
||||
return storeCatMaps, err
|
||||
}
|
||||
//表示没有门店分类
|
||||
if len(storeCatMaps) == 0 {
|
||||
storeCatMaps, err = dao.GetCategoriesForStore(db, parentID, 0, nil)
|
||||
}
|
||||
return storeCatMaps, err
|
||||
}
|
||||
|
||||
@@ -3260,36 +3276,36 @@ func UpdateStoreCategoryMap(ctx *jxcontext.Context, ID int, storeCategoryMap *mo
|
||||
}
|
||||
}
|
||||
}
|
||||
// var storeSkus []*model.StoreSkuBind
|
||||
// sql := `
|
||||
// SELECT a.*
|
||||
// FROM store_sku_bind a
|
||||
// JOIN sku b ON a.sku_id = b.id
|
||||
// JOIN sku_name c ON c.id = b.name_id
|
||||
// WHERE a.deleted_at = ? AND b.deleted_at = ? AND c.deleted_at = ?
|
||||
// AND c.category_id = ? AND a.store_id = ?
|
||||
// UNION ALL
|
||||
// SELECT a.*
|
||||
// FROM store_sku_bind a
|
||||
// JOIN sku b ON a.sku_id = b.id
|
||||
// JOIN sku_name c ON c.id = b.name_id
|
||||
// JOIN sku_category d ON d.id = c.category_id
|
||||
// JOIN sku_category e ON e.id = d.parent_id
|
||||
// WHERE a.deleted_at = ? AND b.deleted_at = ? AND c.deleted_at = ?
|
||||
// AND e.id = ? AND a.store_id = ?
|
||||
// `
|
||||
// sqlParams := []interface{}{
|
||||
// utils.DefaultTimeValue, utils.DefaultTimeValue, utils.DefaultTimeValue,
|
||||
// storeCategoryMap2.CategoryID, storeCategoryMap2.StoreID,
|
||||
// utils.DefaultTimeValue, utils.DefaultTimeValue, utils.DefaultTimeValue,
|
||||
// storeCategoryMap2.CategoryID, storeCategoryMap2.StoreID,
|
||||
// }
|
||||
// if err = dao.GetRows(db, &storeSkus, sql, sqlParams); err != nil {
|
||||
// return 0, err
|
||||
// }
|
||||
// if len(storeSkus) > 0 {
|
||||
// return 0, fmt.Errorf("该分类下或该分类的子分类下有关注的商品,不可删除!分类名:[%v]", storeCategoryMap2.StoreCategoryName)
|
||||
// }
|
||||
var storeSkus []*model.StoreSkuBind
|
||||
sql := `
|
||||
SELECT a.*
|
||||
FROM store_sku_bind a
|
||||
JOIN sku b ON a.sku_id = b.id
|
||||
JOIN sku_name c ON c.id = b.name_id
|
||||
WHERE a.deleted_at = ? AND b.deleted_at = ? AND c.deleted_at = ?
|
||||
AND c.category_id = ? AND a.store_id = ?
|
||||
UNION ALL
|
||||
SELECT a.*
|
||||
FROM store_sku_bind a
|
||||
JOIN sku b ON a.sku_id = b.id
|
||||
JOIN sku_name c ON c.id = b.name_id
|
||||
JOIN sku_category d ON d.id = c.category_id
|
||||
JOIN sku_category e ON e.id = d.parent_id
|
||||
WHERE a.deleted_at = ? AND b.deleted_at = ? AND c.deleted_at = ?
|
||||
AND e.id = ? AND a.store_id = ?
|
||||
`
|
||||
sqlParams := []interface{}{
|
||||
utils.DefaultTimeValue, utils.DefaultTimeValue, utils.DefaultTimeValue,
|
||||
storeCategoryMap2.CategoryID, storeCategoryMap2.StoreID,
|
||||
utils.DefaultTimeValue, utils.DefaultTimeValue, utils.DefaultTimeValue,
|
||||
storeCategoryMap2.CategoryID, storeCategoryMap2.StoreID,
|
||||
}
|
||||
if err = dao.GetRows(db, &storeSkus, sql, sqlParams); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if len(storeSkus) > 0 {
|
||||
return 0, fmt.Errorf("该分类下或该分类的子分类下有关注的商品,不可删除!分类名:[%v]", storeCategoryMap2.StoreCategoryName)
|
||||
}
|
||||
catIDs = append(catIDs, storeCategoryMap.CategoryID)
|
||||
SetStoreCategorySyncStatus2(db, []int{storeCategoryMap2.StoreID}, catIDs, model.SyncFlagModifiedMask)
|
||||
} else {
|
||||
@@ -4002,10 +4018,10 @@ func RefreshMTWMToken(ctx *jxcontext.Context) (err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
)
|
||||
if time.Now().YearDay()%20 != 0 {
|
||||
if time.Now().YearDay()%10 != 0 {
|
||||
return
|
||||
}
|
||||
//token是1个月过期,每20天刷一次吧
|
||||
//token是1个月过期,每10天刷一次吧
|
||||
storeMaps, _ := dao.GetStoresMapList(db, []int{model.VendorIDMTWM}, nil, nil, model.StoreStatusAll, model.StoreIsSyncAll, "", "", globals.Mtwm2Code)
|
||||
for _, v := range storeMaps {
|
||||
if v.MtwmRefreshToken != "" {
|
||||
@@ -4064,3 +4080,32 @@ func GetStoreAcctBalance(ctx *jxcontext.Context, storeID int) (storeAcct *model.
|
||||
AccountBalance: totalIncome - totalExpend,
|
||||
}, err
|
||||
}
|
||||
|
||||
// func SendVendorStoreStatusChanged(ctx *jxcontext.Context) (err error) {
|
||||
// var (
|
||||
// db = dao.GetDB()
|
||||
// )
|
||||
// dao.GetStoresMapList(db, []int{model.VendorIDJD, model.VendorIDMTWM, model.VendorIDEBAI}, nil, nil, model.StoreStatusAll, model.StoreIsSyncAll, "", "", "")
|
||||
// return err
|
||||
// }
|
||||
|
||||
func RefreshStoreBind(ctx *jxcontext.Context) (err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
)
|
||||
stores, err := dao.GetStoreList(db, nil, nil, []int{model.StoreStatusClosed, model.StoreStatusHaveRest, model.StoreStatusOpened}, nil, nil, "")
|
||||
task := tasksch.NewParallelTask("RefreshStoreBind", tasksch.NewParallelConfig().SetParallelCount(5).SetIsContinueWhenError(true), ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
store := batchItemList[0].(*model.Store)
|
||||
var userIDs []string
|
||||
userList := getAllUsers4Store(ctx, db, store)
|
||||
for _, v := range userList {
|
||||
userIDs = append(userIDs, v.UserID)
|
||||
}
|
||||
err = AddUsers4Role(ctx, autils.NewRole(authz.StoreRoleBoss, store.ID), userIDs)
|
||||
return retVal, err
|
||||
}, stores)
|
||||
tasksch.HandleTask(task, nil, true).Run()
|
||||
task.GetID()
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -89,6 +89,7 @@ type StoreSkuBindInfo struct {
|
||||
SubStoreID int `json:"subStoreID,omitempty"`
|
||||
StatusSaleBegin int16 `json:"statusSaleBegin" validate:"max=2359,min=1,ltfield=StatusSaleEnd"` //商品可售时间范围
|
||||
StatusSaleEnd int16 `json:"statusSaleEnd" validate:"max=2359,min=1"`
|
||||
UPC string `json:"upc"`
|
||||
Skus []*StoreSkuBindSkuInfo `json:"skus,omitempty"`
|
||||
}
|
||||
|
||||
@@ -263,11 +264,163 @@ var (
|
||||
}
|
||||
)
|
||||
|
||||
func GetStoreSkus(ctx *jxcontext.Context, storeID int, skuIDs []int, isFocus bool, keyword string, isBySku, isAct bool, params map[string]interface{}, offset, pageSize int) (skuNamesInfo *dao.StoreSkuNamesInfo, err error) {
|
||||
return GetStoresSkus(ctx, []int{storeID}, skuIDs, isFocus, false, 0, keyword, isBySku, isAct, params, offset, pageSize)
|
||||
func GetStoresSkusForStore(ctx *jxcontext.Context, storeID int, isFocus, isAct bool, keyword string, categoryID, status, offset, pageSize int) (skuNamesInfo *dao.StoreSkuNamesInfo, err error) {
|
||||
//权限
|
||||
if permission.IsRoled(ctx) {
|
||||
if storeIDsMap, err := permission.GetUserStoresResultMap(ctx.GetUserID()); err == nil {
|
||||
if storeIDsMap[storeID] == 0 {
|
||||
return skuNamesInfo, err
|
||||
}
|
||||
}
|
||||
}
|
||||
var (
|
||||
sqlParams []interface{}
|
||||
db = dao.GetDB()
|
||||
SkuNames []*dao.StoreSkuNameExt
|
||||
)
|
||||
sql := `
|
||||
SELECT SQL_CALC_FOUND_ROWS DISTINCT a.*, e.id store_id, c.unit_price
|
||||
FROM sku_name a
|
||||
JOIN sku b ON b.name_id = a.id AND b.deleted_at = ?
|
||||
JOIN store e ON e.deleted_at = ?
|
||||
`
|
||||
sqlParams = append(sqlParams,
|
||||
utils.DefaultTimeValue,
|
||||
utils.DefaultTimeValue,
|
||||
)
|
||||
if !isFocus {
|
||||
sql += `
|
||||
LEFT
|
||||
`
|
||||
}
|
||||
sql += `
|
||||
JOIN store_sku_bind c ON c.sku_id = b.id AND c.deleted_at = ? AND c.store_id = e.id
|
||||
`
|
||||
sqlParams = append(sqlParams, utils.DefaultTimeValue)
|
||||
if status != -1 {
|
||||
sql += " AND c.status = ?"
|
||||
sqlParams = append(sqlParams, status)
|
||||
}
|
||||
sql += `
|
||||
LEFT JOIN sku_name_place_bind f ON a.id = f.name_id AND e.city_code = f.place_code
|
||||
`
|
||||
if isAct {
|
||||
sql += `
|
||||
JOIN (
|
||||
SELECT t2.store_id, t2.sku_id,
|
||||
MIN(IF(t3.actual_act_price <= 0, NULL, t3.actual_act_price)) actual_act_price, /*non-zero min value*/
|
||||
MIN(IF(t2.earning_price <= 0, NULL, t2.earning_price)) earning_price /*non-zero min value*/
|
||||
FROM act t1
|
||||
JOIN act_store_sku t2 ON t2.act_id = t1.id AND t2.deleted_at = ?
|
||||
JOIN act_store_sku_map t3 ON t3.bind_id = t2.id AND t3.act_id = t1.id AND (t3.sync_status & ? = 0 OR t1.type = ?)
|
||||
JOIN act_map t4 ON t4.act_id = t1.id AND t4.vendor_id = t3.vendor_id AND t4.deleted_at = ? AND (t4.sync_status & ? = 0 OR t1.type = ?)
|
||||
WHERE t1.deleted_at = ? AND t1.status = ? AND NOT (t1.begin_at > ? OR t1.end_at < ?)
|
||||
AND t2.store_id = ?
|
||||
GROUP BY 1,2
|
||||
) ta ON ta.store_id = e.id AND ta.sku_id = b.id
|
||||
`
|
||||
sqlParams = append(sqlParams,
|
||||
utils.DefaultTimeValue,
|
||||
model.SyncFlagNewMask,
|
||||
model.ActSkuFake,
|
||||
utils.DefaultTimeValue,
|
||||
model.SyncFlagNewMask,
|
||||
model.ActSkuFake,
|
||||
utils.DefaultTimeValue,
|
||||
model.ActStatusCreated,
|
||||
time.Now(),
|
||||
time.Now(),
|
||||
storeID,
|
||||
)
|
||||
}
|
||||
sql += `
|
||||
WHERE a.deleted_at = ?
|
||||
AND (a.is_global = 1 OR f.id IS NOT NULL OR 1 = ?)
|
||||
AND e.id = ?
|
||||
`
|
||||
sqlParams = append(sqlParams, utils.DefaultTimeValue, utils.Bool2Int(isFocus), storeID)
|
||||
if categoryID != 0 {
|
||||
cat := &model.SkuCategory{}
|
||||
cat.ID = categoryID
|
||||
if err = dao.GetEntity(db, cat); err == nil {
|
||||
sql += " AND (a.category_id = ?"
|
||||
sqlParams = append(sqlParams, cat.ID)
|
||||
if cat.Level == 1 {
|
||||
sql += " OR a.category_id IN (SELECT id FROM sku_category WHERE parent_id = ?)"
|
||||
sqlParams = append(sqlParams, cat.ID)
|
||||
}
|
||||
sql += ")"
|
||||
}
|
||||
}
|
||||
if isFocus {
|
||||
sql += " AND ((a.status = ? AND b.status = ?) OR c.status = ?)"
|
||||
sqlParams = append(sqlParams, model.SkuStatusNormal, model.SkuStatusNormal, model.SkuStatusNormal)
|
||||
} else {
|
||||
sql += " AND c.sku_id IS NULL AND (a.status = ? AND b.status = ?)"
|
||||
sqlParams = append(sqlParams, model.SkuStatusNormal, model.SkuStatusNormal)
|
||||
}
|
||||
if keyword != "" {
|
||||
sql += " AND a.name LIKE ?"
|
||||
sqlParams = append(sqlParams, "%"+keyword+"%")
|
||||
}
|
||||
sql += `
|
||||
LIMIT ? OFFSET ?
|
||||
`
|
||||
pageSize = jxutils.FormalizePageSize(pageSize)
|
||||
offset = jxutils.FormalizePageOffset(offset)
|
||||
sqlParams = append(sqlParams, pageSize, offset)
|
||||
fmt.Println(sql)
|
||||
fmt.Println(sqlParams)
|
||||
dao.Begin(db)
|
||||
defer dao.Commit(db)
|
||||
if err = dao.GetRows(db, &SkuNames, sql, sqlParams...); err == nil {
|
||||
skuNamesInfo = &dao.StoreSkuNamesInfo{
|
||||
TotalCount: dao.GetLastTotalRowCount(db),
|
||||
}
|
||||
// skuNamesInfo.TotalCount = dao.GetLastTotalRowCount(db)
|
||||
for _, v := range SkuNames {
|
||||
var skus []*dao.StoreSkuExt
|
||||
sql2 := `
|
||||
SELECT a.id sku_id, a.spec_quality sku_spec_quality, a.spec_unit sku_spec_unit, a.status sku_status,
|
||||
b.stock, b.price bind_price, b.unit_price,
|
||||
b.status store_sku_status
|
||||
FROM sku a
|
||||
JOIN store_sku_bind b ON a.id = b.sku_id AND b.deleted_at = ? AND b.store_id = ?
|
||||
JOIN sku_name c ON a.name_id = c.id AND c.deleted_at = ? AND c.status = ?
|
||||
WHERE a.deleted_at = ? AND a.name_id = ? AND a.status = ?
|
||||
`
|
||||
sqlParams2 := []interface{}{utils.DefaultTimeValue, storeID,
|
||||
utils.DefaultTimeValue, model.SkuStatusNormal,
|
||||
utils.DefaultTimeValue, v.ID, model.SkuStatusNormal,
|
||||
}
|
||||
if status != -1 {
|
||||
sql2 += " AND b.status = ?"
|
||||
sqlParams2 = append(sqlParams2, status)
|
||||
}
|
||||
if err = dao.GetRows(db, &skus, sql2, sqlParams2); err == nil {
|
||||
v.Skus = skus
|
||||
}
|
||||
}
|
||||
skuNamesInfo.SkuNames = SkuNames
|
||||
if err == nil {
|
||||
if isFocus {
|
||||
if err == nil {
|
||||
storeIDs, skuIDs := GetStoreAndSkuIDsFromInfo(skuNamesInfo)
|
||||
err = dao.UpdateActPrice4StoreSkuNameNew(db, storeIDs, skuIDs, skuNamesInfo, -1)
|
||||
}
|
||||
} else {
|
||||
err = updateUnitPrice4StoreSkuNameNew(db, skuNamesInfo)
|
||||
}
|
||||
}
|
||||
}
|
||||
return skuNamesInfo, err
|
||||
}
|
||||
|
||||
func getGetStoresSkusBaseSQL(db *dao.DaoDB, storeIDs, skuIDs []int, isFocus bool, keyword string, isBySku, isAct, isHighPrice bool, priceType int, actVendorID int, params map[string]interface{}) (sql string, sqlParams []interface{}, err error) {
|
||||
func GetStoreSkus(ctx *jxcontext.Context, storeID int, skuIDs []int, isFocus bool, keyword string, isBySku, isAct bool, params map[string]interface{}, offset, pageSize int) (skuNamesInfo *dao.StoreSkuNamesInfo, err error) {
|
||||
return GetStoresSkus(ctx, []int{storeID}, skuIDs, nil, isFocus, false, 0, keyword, isBySku, isAct, params, offset, pageSize)
|
||||
}
|
||||
|
||||
func getGetStoresSkusBaseSQL(db *dao.DaoDB, storeIDs, skuIDs []int, upcs []string, isFocus bool, keyword string, isBySku, isAct, isHighPrice bool, priceType int, actVendorID int, params map[string]interface{}) (sql string, sqlParams []interface{}, err error) {
|
||||
sql = `
|
||||
FROM sku_name t1
|
||||
JOIN sku t2 FORCE INDEX(PRIMARY) ON t1.id = t2.name_id AND t2.deleted_at = ?/* AND t2.status = ?*/
|
||||
@@ -422,6 +575,10 @@ func getGetStoresSkusBaseSQL(db *dao.DaoDB, storeIDs, skuIDs []int, isFocus bool
|
||||
sql += " AND IF(INSTR(t3.name,'" + model.ExdStoreName + "') > 0, t2.exd_sku_id <> '', t2.exd_sku_id = '')"
|
||||
}
|
||||
}
|
||||
if len(upcs) > 0 {
|
||||
sql += " AND t1.upc IN (" + dao.GenQuestionMarks(len(upcs)) + ")"
|
||||
sqlParams = append(sqlParams, upcs)
|
||||
}
|
||||
if len(skuIDs) > 0 {
|
||||
sql += " AND t2.id IN (" + dao.GenQuestionMarks(len(skuIDs)) + ")"
|
||||
sqlParams = append(sqlParams, skuIDs)
|
||||
@@ -486,7 +643,7 @@ func getGetStoresSkusBaseSQL(db *dao.DaoDB, storeIDs, skuIDs []int, isFocus bool
|
||||
return sql, sqlParams, err
|
||||
}
|
||||
|
||||
func GetStoresSkus(ctx *jxcontext.Context, storeIDs, skuIDs []int, isFocus, isHighPrice bool, priceType int, keyword string, isBySku, isAct bool, params map[string]interface{}, offset, pageSize int) (skuNamesInfo *dao.StoreSkuNamesInfo, err error) {
|
||||
func GetStoresSkus(ctx *jxcontext.Context, storeIDs, skuIDs []int, upcs []string, isFocus, isHighPrice bool, priceType int, keyword string, isBySku, isAct bool, params map[string]interface{}, offset, pageSize int) (skuNamesInfo *dao.StoreSkuNamesInfo, err error) {
|
||||
//权限
|
||||
if permission.IsRoled(ctx) {
|
||||
if storeIDsMap, err := permission.GetUserStoresResultMap(ctx.GetUserID()); err == nil {
|
||||
@@ -497,6 +654,9 @@ func GetStoresSkus(ctx *jxcontext.Context, storeIDs, skuIDs []int, isFocus, isHi
|
||||
storeIDs2 = append(storeIDs2, v)
|
||||
}
|
||||
}
|
||||
if len(storeIDs2) == 0 {
|
||||
storeIDs2 = append(storeIDs2, -1)
|
||||
}
|
||||
} else {
|
||||
for k, _ := range storeIDsMap {
|
||||
storeIDs2 = append(storeIDs2, k)
|
||||
@@ -506,10 +666,10 @@ func GetStoresSkus(ctx *jxcontext.Context, storeIDs, skuIDs []int, isFocus, isHi
|
||||
storeIDs = storeIDs2
|
||||
}
|
||||
}
|
||||
return GetStoresSkusNew(ctx, storeIDs, skuIDs, isFocus, isHighPrice, priceType, keyword, isBySku, isAct, params, offset, pageSize)
|
||||
return GetStoresSkusNew(ctx, storeIDs, skuIDs, upcs, isFocus, isHighPrice, priceType, keyword, isBySku, isAct, params, offset, pageSize)
|
||||
}
|
||||
|
||||
func GetStoresSkusNew(ctx *jxcontext.Context, storeIDs, skuIDs []int, isFocus, isHighPrice bool, priceType int, keyword string, isBySku, isAct bool, params map[string]interface{}, offset, pageSize int) (skuNamesInfo *dao.StoreSkuNamesInfo, err error) {
|
||||
func GetStoresSkusNew(ctx *jxcontext.Context, storeIDs, skuIDs []int, upcs []string, isFocus, isHighPrice bool, priceType int, keyword string, isBySku, isAct bool, params map[string]interface{}, offset, pageSize int) (skuNamesInfo *dao.StoreSkuNamesInfo, err error) {
|
||||
if !isFocus && !isBySku && (len(storeIDs) > 1 || len(storeIDs) == 0) {
|
||||
return nil, fmt.Errorf("未关注按SkuName只能查询单店")
|
||||
}
|
||||
@@ -542,7 +702,7 @@ func GetStoresSkusNew(ctx *jxcontext.Context, storeIDs, skuIDs []int, isFocus, i
|
||||
delete(params, "minimumPrice")
|
||||
}
|
||||
db := dao.GetDB()
|
||||
sql, sqlParams, err := getGetStoresSkusBaseSQL(db, storeIDs, skuIDs, isFocus, keyword, isBySku, isAct, isHighPrice, priceType, actVendorID, params)
|
||||
sql, sqlParams, err := getGetStoresSkusBaseSQL(db, storeIDs, skuIDs, upcs, isFocus, keyword, isBySku, isAct, isHighPrice, priceType, actVendorID, params)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -583,6 +743,8 @@ func GetStoresSkusNew(ctx *jxcontext.Context, storeIDs, skuIDs []int, isFocus, i
|
||||
sqlParams2 = append(sqlParams2, sqlParamsPage)
|
||||
var storeNameList []*tStoreNameBind
|
||||
beginTime := time.Now()
|
||||
fmt.Println(sql2)
|
||||
fmt.Println(sqlParams2)
|
||||
if err = dao.GetRows(db, &storeNameList, sql2, sqlParams2...); err != nil {
|
||||
dao.Rollback(db)
|
||||
return nil, err
|
||||
@@ -1058,10 +1220,18 @@ func uniqueStoreIDs(storeIDs []int) []int {
|
||||
|
||||
func uniqueStoreNameBind(skuBindInfos []*StoreSkuBindInfo) (outSkuBindInfos []*StoreSkuBindInfo) {
|
||||
nameIDMap := make(map[int]int)
|
||||
upcMap := make(map[string]int)
|
||||
for _, v := range skuBindInfos {
|
||||
if nameIDMap[v.NameID] != 1 {
|
||||
outSkuBindInfos = append(outSkuBindInfos, v)
|
||||
nameIDMap[v.NameID] = 1
|
||||
if v.NameID != 0 {
|
||||
if nameIDMap[v.NameID] != 1 {
|
||||
outSkuBindInfos = append(outSkuBindInfos, v)
|
||||
nameIDMap[v.NameID] = 1
|
||||
}
|
||||
} else if v.UPC != "" {
|
||||
if upcMap[v.UPC] != 1 {
|
||||
outSkuBindInfos = append(outSkuBindInfos, v)
|
||||
upcMap[v.UPC] = 1
|
||||
}
|
||||
}
|
||||
}
|
||||
return outSkuBindInfos
|
||||
@@ -1083,7 +1253,7 @@ func updateStoresSkusWithoutSync(ctx *jxcontext.Context, db *dao.DaoDB, storeIDs
|
||||
// if err = checkStoresSkusSaleCity(ctx, db, storeIDs, skuBindInfos); err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
// globals.SugarLogger.Debugf("updateStoresSkusWithoutSync2, storeIDs:%v, skuBindInfos:%s", storeIDs, utils.Format4Output(skuBindInfos, false))
|
||||
globals.SugarLogger.Debugf("updateStoresSkusWithoutSync2, storeIDs:%v, skuBindInfos:%s", storeIDs, utils.Format4Output(skuBindInfos, false))
|
||||
isUserCanDirectChangePrice := true
|
||||
if user := ctx.GetFullUser(); user != nil {
|
||||
isUserCanDirectChangePrice = user.Type&model.UserTypeOperator != 0
|
||||
@@ -1146,16 +1316,32 @@ func updateStoresSkusWithoutSync(ctx *jxcontext.Context, db *dao.DaoDB, storeIDs
|
||||
LEFT JOIN (
|
||||
SELECT t7.store_id, t8.name_id, CAST(AVG(t7.unit_price) AS SIGNED) unit_price
|
||||
FROM store_sku_bind t7
|
||||
JOIN sku t8 ON t8.id = t7.sku_id AND t8.name_id = ?
|
||||
JOIN sku t8 ON t8.id = t7.sku_id
|
||||
`
|
||||
if skuBindInfo.NameID != 0 {
|
||||
sql += " AND t8.name_id = ?"
|
||||
sqlParams = append(sqlParams, skuBindInfo.NameID)
|
||||
} else if skuBindInfo.UPC != "" {
|
||||
sql += " JOIN sku_name t9 ON t9.id = t8.name_id AND t9.upc = ?"
|
||||
sqlParams = append(sqlParams, skuBindInfo.UPC)
|
||||
}
|
||||
sql += `
|
||||
WHERE t7.deleted_at = ? AND t7.store_id = ?
|
||||
GROUP BY 1,2
|
||||
) t5 ON t5.store_id = ts.id AND t5.name_id = t1.name_id`
|
||||
sqlParams = append(sqlParams, skuBindInfo.NameID, utils.DefaultTimeValue, storeID)
|
||||
sqlParams = append(sqlParams, utils.DefaultTimeValue, storeID)
|
||||
}
|
||||
sql += `
|
||||
WHERE t1.name_id = ? AND t1.deleted_at = ?
|
||||
sql += " WHERE 1 = 1"
|
||||
if skuBindInfo.NameID != 0 {
|
||||
sql += " AND t1.name_id = ?"
|
||||
sqlParams = append(sqlParams, skuBindInfo.NameID)
|
||||
} else if skuBindInfo.UPC != "" {
|
||||
sql += " AND t3.upc = ?"
|
||||
sqlParams = append(sqlParams, skuBindInfo.UPC)
|
||||
}
|
||||
sql += ` AND t1.deleted_at = ?
|
||||
FOR UPDATE`
|
||||
sqlParams = append(sqlParams, skuBindInfo.NameID, utils.DefaultTimeValue)
|
||||
sqlParams = append(sqlParams, utils.DefaultTimeValue)
|
||||
// globals.SugarLogger.Debug(sql)
|
||||
if err = dao.GetRows(db, &allBinds, sql, sqlParams...); err == nil {
|
||||
if len(allBinds) > 0 {
|
||||
@@ -1187,7 +1373,6 @@ func updateStoresSkusWithoutSync(ctx *jxcontext.Context, db *dao.DaoDB, storeIDs
|
||||
var num int64
|
||||
inSkuBind := inSkuBinsMap[v.RealSkuID]
|
||||
isCanChangePrice := (isUserCanDirectChangePrice || jxutils.TranslateStorePriceType(v.ChangePriceType) != model.StoreChangePriceTypeBossDisabled)
|
||||
// globals.SugarLogger.Debug(utils.Format4Output(inSkuBind, false))
|
||||
var skuBind *model.StoreSkuBind
|
||||
if v.ID == 0 {
|
||||
// if v.ExdSkuID == "" {
|
||||
@@ -1227,7 +1412,6 @@ func updateStoresSkusWithoutSync(ctx *jxcontext.Context, db *dao.DaoDB, storeIDs
|
||||
}
|
||||
setStoreSkuBindStatus(skuBind, model.SyncFlagNewMask)
|
||||
dao.WrapAddIDCULDEntity(skuBind, userName)
|
||||
// globals.SugarLogger.Debug(utils.Format4Output(skuBind, false))
|
||||
if deletedSku := dao.GetDeletedStoreSkuBind(db, skuBind.StoreID, skuBind.SkuID); deletedSku == nil {
|
||||
if err = dao.CreateEntity(db, skuBind); err != nil {
|
||||
dao.Rollback(db)
|
||||
@@ -1260,10 +1444,10 @@ func updateStoresSkusWithoutSync(ctx *jxcontext.Context, db *dao.DaoDB, storeIDs
|
||||
if len(thingMaps) > 0 {
|
||||
//如果平台ID为空(未创建到京东)
|
||||
if thingMaps[0].VendorThingID == "" {
|
||||
isSyncSkus = true
|
||||
appCodeList = append(appCodeList, list1[0].VendorOrgCode)
|
||||
//并且同步标志还没有带待创建(因为addskuname现在建到thingmap上不会带待创建标志了)
|
||||
if !model.IsSyncStatusNew(thingMaps[0].SyncStatus) {
|
||||
isSyncSkus = true
|
||||
appCodeList = append(appCodeList, list1[0].VendorOrgCode)
|
||||
OnCreateThing(ctx, db, vendorOrgCodes, int64(v.RealSkuID), model.ThingTypeSku, model.SyncFlagNewMask, false)
|
||||
}
|
||||
}
|
||||
@@ -1334,6 +1518,33 @@ func updateStoresSkusWithoutSync(ctx *jxcontext.Context, db *dao.DaoDB, storeIDs
|
||||
setStoreSkuBindStatus(skuBind, model.SyncFlagStockMask)
|
||||
if tmpStatus == model.StoreSkuBindStatusNormal {
|
||||
skuBind.Stock = model.MaxStoreSkuStockQty
|
||||
//下面这段很难受
|
||||
{
|
||||
//如果是京东关注,要去建商品
|
||||
list1, _ := dao.GetStoresMapList(db, []int{model.VendorIDJD}, []int{storeID}, nil, model.StoreStatusAll, 1, "", "", "")
|
||||
//表示这个门店绑定了京东
|
||||
if len(list1) > 0 {
|
||||
vendorOrgCodes, _ := dao.GetVendorOrgCode(db, model.VendorIDJD, list1[0].VendorOrgCode, model.VendorOrgTypePlatform)
|
||||
//thingmap里肯定存在,再判断有没有同步上去
|
||||
thingMaps, _ := dao.GetThingMapList(db, model.ThingTypeSku, []int{model.VendorIDJD}, []int{v.RealSkuID}, []string{list1[0].VendorOrgCode})
|
||||
if len(thingMaps) > 0 {
|
||||
//如果平台ID为空(未创建到京东)
|
||||
if thingMaps[0].VendorThingID == "" {
|
||||
isSyncSkus = true
|
||||
appCodeList = append(appCodeList, list1[0].VendorOrgCode)
|
||||
//并且同步标志还没有带待创建(因为addskuname现在建到thingmap上不会带待创建标志了)
|
||||
if !model.IsSyncStatusNew(thingMaps[0].SyncStatus) {
|
||||
OnCreateThing(ctx, db, vendorOrgCodes, int64(v.RealSkuID), model.ThingTypeSku, model.SyncFlagNewMask, false)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
//万一不存在
|
||||
isSyncSkus = true
|
||||
appCodeList = append(appCodeList, list1[0].VendorOrgCode)
|
||||
OnCreateThing(ctx, db, vendorOrgCodes, int64(v.RealSkuID), model.ThingTypeSku, model.SyncFlagNewMask, false)
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
skuBind.Stock = 0
|
||||
}
|
||||
@@ -4419,9 +4630,11 @@ func buildStoreSkuBindInfosAndFocus(ctx *jxcontext.Context, db *dao.DaoDB, store
|
||||
|
||||
func CreateSkusAndFocusFromWx(ctx *jxcontext.Context, productInfo *jdapi.ProductInfo, price, storeID int) (err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
skuBindInfos []*StoreSkuBindInfo
|
||||
db = dao.GetDB()
|
||||
skuBindInfos []*StoreSkuBindInfo
|
||||
outSkuNameExt *model.SkuNameExt
|
||||
)
|
||||
|
||||
if productInfo == nil {
|
||||
return fmt.Errorf("未查询到相关商品!")
|
||||
}
|
||||
@@ -4461,56 +4674,60 @@ func CreateSkusAndFocusFromWx(ctx *jxcontext.Context, productInfo *jdapi.Product
|
||||
productInfo.Unit = unit
|
||||
productInfo.SpecUnit = specUnit
|
||||
}
|
||||
skuNames2, err := dao.GetSkuNames(db, nil, nil, productInfo.Name, false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if productInfo.Name == "" {
|
||||
return fmt.Errorf("暂时无法创建此商品,[%v]", productInfo.Name)
|
||||
}
|
||||
if len(skuNames2) > 1 {
|
||||
return fmt.Errorf("此商品名在京西库中查询出了大于1个商品,[%v]", productInfo.Name)
|
||||
}
|
||||
//表示查到了,需要把upc更新上去,没查到就要新建
|
||||
if len(skuNames2) == 1 && (productInfo.SpecQuality == skuNames2[0].SpecQuality && productInfo.SpecUnit == skuNames2[0].SpecUnit) {
|
||||
skuNames2[0].Upc = &productInfo.UpcCode
|
||||
dao.UpdateEntity(db, skuNames2[0], "Upc")
|
||||
focusSku(skuNames2[0].ID)
|
||||
} else {
|
||||
skuNameExt := &model.SkuNameExt{
|
||||
SkuName: model.SkuName{
|
||||
Name: productInfo.Name,
|
||||
Upc: &productInfo.UpcCode,
|
||||
Status: model.SkuStatusNormal,
|
||||
CategoryID: model.NoCatCatgoryID,
|
||||
IsGlobal: model.YES,
|
||||
Unit: productInfo.Unit,
|
||||
},
|
||||
Skus: []*model.SkuWithVendor{
|
||||
&model.SkuWithVendor{
|
||||
Sku: &model.Sku{},
|
||||
},
|
||||
},
|
||||
// Places: []int{510100}, //默认成都
|
||||
if result, err := api.MtwmAPI.GetStandardProductListWithCond(productInfo.UpcCode); err == nil && result != nil {
|
||||
productInfo.OriginalName = result.Name
|
||||
productInfo.OriginalSpec = result.Spec
|
||||
productInfo.Name = result.Name
|
||||
productInfo.SpecUnit = result.SpecUnit
|
||||
productInfo.Unit = result.Unit
|
||||
productInfo.SpecQuality = float32(result.SpecNew)
|
||||
productInfo.ImgList = strings.Split(result.Pic, ",")
|
||||
productInfo.Weight = float32(result.Weight)
|
||||
productInfo.BrandName = result.BrandNamePath
|
||||
}
|
||||
skuNameExt.Price = price
|
||||
skuNameExt.Skus[0].SpecQuality = productInfo.SpecQuality
|
||||
skuNameExt.Skus[0].SpecUnit = productInfo.SpecUnit
|
||||
skuNameExt.Skus[0].Weight = int(utils.Str2Int64(utils.Float64ToStr(float64(productInfo.Weight))))
|
||||
skuNameExt.Skus[0].Status = model.SkuStatusNormal
|
||||
if len(productInfo.ImgList) > 0 {
|
||||
skuNameExt.Img = productInfo.ImgList[0]
|
||||
}
|
||||
outSkuNameExt, err := AddSkuName(ctx, skuNameExt, ctx.GetUserName())
|
||||
if err != nil {
|
||||
if _, ok := err.(*SyncError); ok {
|
||||
err = nil
|
||||
} else {
|
||||
return err
|
||||
}
|
||||
}
|
||||
skuNameExt := &model.SkuNameExt{
|
||||
SkuName: model.SkuName{
|
||||
Name: productInfo.Name,
|
||||
Upc: &productInfo.UpcCode,
|
||||
Status: model.SkuStatusNormal,
|
||||
CategoryID: model.NoCatCatgoryID,
|
||||
IsGlobal: model.YES,
|
||||
Unit: productInfo.Unit,
|
||||
},
|
||||
Skus: []*model.SkuWithVendor{
|
||||
&model.SkuWithVendor{
|
||||
Sku: &model.Sku{},
|
||||
},
|
||||
},
|
||||
// Places: []int{510100}, //默认成都
|
||||
}
|
||||
skuNameExt.Price = price
|
||||
skuNameExt.Skus[0].SpecQuality = productInfo.SpecQuality
|
||||
skuNameExt.Skus[0].SpecUnit = productInfo.SpecUnit
|
||||
skuNameExt.Skus[0].Weight = int(utils.Str2Int64(utils.Float64ToStr(float64(productInfo.Weight))))
|
||||
skuNameExt.Skus[0].Status = model.SkuStatusNormal
|
||||
if len(productInfo.ImgList) > 0 {
|
||||
setImgs(skuNameExt, productInfo.ImgList)
|
||||
}
|
||||
//可能就是没查出来
|
||||
if skuNameExt.Name == "" {
|
||||
skuNameExt.Name = productInfo.OriginalName
|
||||
skuNameExt.Unit = model.UnitNames[5]
|
||||
skuNameExt.Skus[0].SpecQuality = 100
|
||||
skuNameExt.Skus[0].SpecUnit = model.SpecUnitNames[0]
|
||||
skuNameExt.Skus[0].Weight = 100
|
||||
}
|
||||
outSkuNameExt, err = AddSkuName(ctx, skuNameExt, ctx.GetUserName())
|
||||
if err != nil {
|
||||
if _, ok := err.(*SyncError); ok {
|
||||
err = nil
|
||||
} else {
|
||||
focusSku(outSkuNameExt.ID)
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
focusSku(outSkuNameExt.ID)
|
||||
}
|
||||
} else {
|
||||
focusSku(skuNames[0].ID)
|
||||
@@ -4784,6 +5001,9 @@ func GetStoreSkuAudit(ctx *jxcontext.Context, storeIDs, nameIDs, skuIDs, statuss
|
||||
storeIDs2 = append(storeIDs2, v)
|
||||
}
|
||||
}
|
||||
if len(storeIDs2) == 0 {
|
||||
storeIDs2 = append(storeIDs2, -1)
|
||||
}
|
||||
} else {
|
||||
for k, _ := range storeIDsMap {
|
||||
storeIDs2 = append(storeIDs2, k)
|
||||
@@ -5241,3 +5461,69 @@ func DeleteActStoreSkuBind(ctx *jxcontext.Context, db *dao.DaoDB, actID int, act
|
||||
dao.Commit(db)
|
||||
return originSyncStatus, err
|
||||
}
|
||||
|
||||
func GetVendorStoreSkus(ctx *jxcontext.Context, storeID, vendorID int) (err error) {
|
||||
type SpecialtyStoreSkus struct {
|
||||
Upc string `json:"商品upc码"`
|
||||
SkuName string `json:"商品名"`
|
||||
Unit string `json:"单位"`
|
||||
Weight int `json:"重量(g)"`
|
||||
Price int64 `json:"售价"`
|
||||
}
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
specialtyStoreSkus []*SpecialtyStoreSkus
|
||||
excelTitle = []string{
|
||||
"商品upc码",
|
||||
"商品名",
|
||||
"单位",
|
||||
"重量(g)",
|
||||
"售价",
|
||||
}
|
||||
sheetList []*excel.Obj2ExcelSheetConfig
|
||||
downloadURL, fileName string
|
||||
)
|
||||
storeDetail, err := dao.GetStoreDetail(db, storeID, vendorID, "")
|
||||
if err != nil || storeDetail == nil {
|
||||
return err
|
||||
}
|
||||
if partner.IsMultiStore(vendorID) {
|
||||
// handler := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.IPurchasePlatformStoreSkuHandler)
|
||||
// skuBareInfoList, _ := handler.GetStoreSkusBareInfo(ctx, storeDetail.VendorOrgCode, nil, storeID, storeDetail.VendorStoreID, nil)
|
||||
return fmt.Errorf("暂不支持京东!")
|
||||
} else {
|
||||
handler := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.ISingleStoreStoreSkuHandler)
|
||||
skuList, _ := handler.GetStoreSkusFullInfo(ctx, nil, storeID, storeDetail.VendorStoreID, nil)
|
||||
for _, sku := range skuList {
|
||||
if sku.UPC != "" {
|
||||
skus := &SpecialtyStoreSkus{
|
||||
Upc: sku.UPC,
|
||||
SkuName: sku.Name,
|
||||
Unit: sku.Unit,
|
||||
Weight: sku.SkuList[0].Weight,
|
||||
Price: sku.SkuList[0].VendorPrice,
|
||||
}
|
||||
specialtyStoreSkus = append(specialtyStoreSkus, skus)
|
||||
}
|
||||
}
|
||||
}
|
||||
excelConf := &excel.Obj2ExcelSheetConfig{
|
||||
Title: "sheet1",
|
||||
Data: specialtyStoreSkus,
|
||||
CaptionList: excelTitle,
|
||||
}
|
||||
sheetList = append(sheetList, excelConf)
|
||||
if excelConf != nil {
|
||||
downloadURL, fileName, err = jxutils.UploadExeclAndPushMsg(sheetList, "平台门店标品")
|
||||
} else {
|
||||
baseapi.SugarLogger.Debug("WriteToExcel: dataSuccess is nil!")
|
||||
}
|
||||
if err != nil {
|
||||
baseapi.SugarLogger.Errorf("WriteToExcel:upload %s , %s failed error:%v", fileName, err)
|
||||
} else {
|
||||
noticeMsg := fmt.Sprintf("[详情点我]%s/billshow/?normal=true&path=%s \n", globals.BackstageHost, downloadURL)
|
||||
ddmsg.SendUserMessage(dingdingapi.MsgTyeText, ctx.GetUserID(), "异步任务完成", noticeMsg)
|
||||
baseapi.SugarLogger.Debug("WriteToExcel: dataSuccess downloadURL: [%v]", downloadURL)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package cms
|
||||
|
||||
import (
|
||||
"git.rosy.net.cn/baseapi/platformapi/dingdingapi"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/ddmsg"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
@@ -22,7 +24,7 @@ func init() {
|
||||
}
|
||||
|
||||
func (s *StoreManager) OnStoreStatusChanged(vendorStoreID string, vendorID int, storeStatus int) (err error) {
|
||||
return err
|
||||
// return err
|
||||
globals.SugarLogger.Debugf("OnStoreStatusChanged venvendorStoreID:%s, storeStatus:%d", vendorStoreID, storeStatus)
|
||||
db := dao.GetDB()
|
||||
storeDetail, err := dao.GetStoreDetailByVendorStoreID(db, vendorStoreID, vendorID, "")
|
||||
@@ -33,6 +35,10 @@ func (s *StoreManager) OnStoreStatusChanged(vendorStoreID string, vendorID int,
|
||||
storeKV = map[string]interface{}{
|
||||
"Status": model.StoreStatusOpened,
|
||||
}
|
||||
content := "您的门店 [" + storeDetail.Name + "],ID:[" + utils.Int2Str(storeDetail.ID) + "],在[" + model.VendorChineseNames[vendorID] + "] 平台上营业状态和京西不一致!平台状态:【营业】,京西状态:【非营业】"
|
||||
if user, err := dao.GetUserByID(db, "mobile", storeDetail.MarketManPhone); err == nil {
|
||||
ddmsg.SendUserMessage(dingdingapi.MsgTyeText, user.UserID, "平台门店状态变化", content)
|
||||
}
|
||||
}
|
||||
if storeDetail.VendorStatus != model.StoreStatusOpened {
|
||||
storeMapKV = map[string]interface{}{
|
||||
@@ -46,6 +52,10 @@ func (s *StoreManager) OnStoreStatusChanged(vendorStoreID string, vendorID int,
|
||||
"Status": storeStatus,
|
||||
}
|
||||
}
|
||||
content := "您的门店 [" + storeDetail.Name + "],ID:[" + utils.Int2Str(storeDetail.ID) + "],在[" + model.VendorChineseNames[vendorID] + "] 平台上营业状态和京西不一致!平台状态:【非营业】,京西状态:【营业】"
|
||||
if user, err := dao.GetUserByID(db, "mobile", storeDetail.MarketManPhone); err == nil {
|
||||
ddmsg.SendUserMessage(dingdingapi.MsgTyeText, user.UserID, "平台门店状态变化", content)
|
||||
}
|
||||
} else if storeDetail.Status <= storeStatus {
|
||||
if storeDetail.VendorStatus != model.StoreStatusOpened {
|
||||
storeMapKV = map[string]interface{}{
|
||||
|
||||
@@ -532,6 +532,9 @@ func (v *VendorSync) SyncStoresSkus(ctx *jxcontext.Context, parentTask tasksch.I
|
||||
storeIDs2 = append(storeIDs2, v)
|
||||
}
|
||||
}
|
||||
if len(storeIDs2) == 0 {
|
||||
storeIDs2 = append(storeIDs2, -1)
|
||||
}
|
||||
} else {
|
||||
for k, _ := range storeIDsMap {
|
||||
storeIDs2 = append(storeIDs2, k)
|
||||
|
||||
@@ -604,7 +604,7 @@ func amendAndPruneVendorStuff(ctx *jxcontext.Context, parentTask tasksch.ITask,
|
||||
}
|
||||
}
|
||||
getSyncFlagCat := func(categoryID int) int8 {
|
||||
if vendorCatMap[categoryID] != nil {
|
||||
if vendorCatMap[categoryID] != nil || vendorOrgCodes[0].IsJxCat == model.NO {
|
||||
return model.SyncFlagNewMask
|
||||
}
|
||||
return 0
|
||||
@@ -613,7 +613,6 @@ func amendAndPruneVendorStuff(ctx *jxcontext.Context, parentTask tasksch.ITask,
|
||||
if err = err2; err == nil {
|
||||
remoteCatMap := make(map[string]int)
|
||||
cat2Delete = checkRemoteCatExist(remoteCatMap, localCatMap, remoteCatList)
|
||||
|
||||
for _, v := range localCatList {
|
||||
if v.IsExdSpec == model.NO {
|
||||
if v.MapID != 0 {
|
||||
|
||||
@@ -297,7 +297,7 @@ func formalizeStoreSkuList(inSkuList []*dao.StoreSkuSyncInfo) []*dao.StoreSkuSyn
|
||||
skuItem.VendorVendorCatID = utils.Str2Int64(skuItem.SkuVendorMapCatID)
|
||||
}
|
||||
skuItem.MergedStatus = jxutils.MergeSkuStatus(jxutils.MergeSkuStatus(skuItem.NameStatus, skuItem.Status), skuItem.StoreSkuStatus)
|
||||
//美团的商品名字非标品中间不能有 ‘约’
|
||||
//美团的商品名字都要有 ‘约’
|
||||
if skuItem.VendorID == model.VendorIDMTWM {
|
||||
skuItem.SkuName = jxutils.ComposeSkuNameSync2(skuItem.Prefix, skuItem.Name, skuItem.Comment, skuItem.Unit, skuItem.SpecQuality, skuItem.SpecUnit, 0, skuItem.ExPrefix, skuItem.ExPrefixBegin, skuItem.ExPrefixEnd, (skuItem.BrandID == skuItem.ExBrandID && skuItem.ExBrandID != 0) || skuItem.ExBrandID == 0)
|
||||
} else {
|
||||
@@ -373,7 +373,7 @@ func updateStoreSku(db *dao.DaoDB, vendorID int, storeSkuList []*dao.StoreSkuSyn
|
||||
// }
|
||||
// }()
|
||||
if vendorID == model.VendorIDJDShop {
|
||||
if syncStatus != model.SyncFlagPriceMask && syncStatus != model.SyncFlagSaleMask {
|
||||
if syncStatus != model.SyncFlagPriceMask && syncStatus != model.SyncFlagSaleMask && syncStatus != model.SyncFlagStockMask {
|
||||
for _, v := range storeSkuList {
|
||||
updateItemList := make([]*dao.KVUpdateItem, len(v.StoreSkuSyncInfoJds))
|
||||
for k, vv := range v.StoreSkuSyncInfoJds {
|
||||
@@ -469,7 +469,7 @@ func syncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, causeFlag
|
||||
now := jxutils.OperationTime2HourMinuteFormat(time.Now())
|
||||
var failedList []*partner.StoreSkuInfoWithErr
|
||||
for _, sku := range skus {
|
||||
globals.SugarLogger.Debugf("syncStoreSkuNew sku sync:%v", sku.SkuSyncStatus)
|
||||
globals.SugarLogger.Debugf("syncStoreSkuNew sku sync1:%v", sku.SkuSyncStatus)
|
||||
if !useVendorPriceDirectly &&
|
||||
!isSkuLockTimeValid(sku) {
|
||||
sku.VendorPrice = 0
|
||||
@@ -536,7 +536,7 @@ func syncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, causeFlag
|
||||
isAdded2Update := false
|
||||
// 修改商品信息时不改价(以免活动引起的失败),而用单独的改价来改
|
||||
if (model.IsSyncStatusUpdate(sku.SkuSyncStatus) || (model.IsSyncStatusSeq(sku.SkuSyncStatus) && reorderHandler == nil)) && singleStoreHandler != nil {
|
||||
if dao.IsVendorThingIDEmpty(sku.VendorCatID) && !strings.Contains(sku.StoreName, model.ExdStoreName) && vendorID != model.VendorIDYB && vendorID != model.VendorIDJDShop {
|
||||
if dao.IsVendorThingIDEmpty(sku.VendorCatID) && !strings.Contains(sku.StoreName, model.ExdStoreName) && vendorID != model.VendorIDYB {
|
||||
// globals.SugarLogger.Warnf("syncStoreSkuNew 修改门店:%d商品:%d,但没有平台分类ID", storeID, sku.SkuID)
|
||||
} else {
|
||||
isAdded2Update = true
|
||||
@@ -573,9 +573,7 @@ func syncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, causeFlag
|
||||
if bareSku == nil {
|
||||
bareSku = storeSkuSyncInfo2Bare(sku)
|
||||
}
|
||||
globals.SugarLogger.Debugf("syncStoreSkuNew sku stock sync:%v", sku.SkuSyncStatus)
|
||||
stockList = append(stockList, bareSku)
|
||||
globals.SugarLogger.Debugf("syncStoreSkuNew stock len:%v", len(stockList))
|
||||
}
|
||||
}
|
||||
isNeedReorder = model.IsSyncStatusSeq(sku.SkuSyncStatus)
|
||||
@@ -935,7 +933,13 @@ func amendAndPruneStoreStuff(ctx *jxcontext.Context, parentTask tasksch.ITask, v
|
||||
}
|
||||
localSkuMap := make(map[string]*dao.StoreSkuSyncInfo)
|
||||
for _, v := range localSkuList {
|
||||
localSkuMap[v.VendorSkuID] = v
|
||||
vendorSkuID := v.VendorSkuID
|
||||
if vendorID == model.VendorIDJDShop {
|
||||
if storeSkus, _ := dao.GetStoresSkusInfo(db, []int{model.JdShopMainStoreID2}, []int{v.SkuID}); len(storeSkus) > 0 {
|
||||
vendorSkuID = utils.Int64ToStr(storeSkus[0].JdsID)
|
||||
}
|
||||
}
|
||||
localSkuMap[vendorSkuID] = v
|
||||
}
|
||||
|
||||
remoteSkuList, err2 := handler.GetStoreSkusFullInfo(ctx, task, storeID, vendorStoreID, nil)
|
||||
|
||||
@@ -246,6 +246,14 @@ func TryAddStoreBossRole4StoreByMobile(ctx *jxcontext.Context, storeID int, mobi
|
||||
if v != "" {
|
||||
if userList, _, err := dao.GetUsers(dao.GetDB(), model.UserTypeStoreBoss, "", nil, nil, []string{v}, 0, -1); err == nil && len(userList) > 0 {
|
||||
userIDs = append(userIDs, userList[0].GetID())
|
||||
} else {
|
||||
if manTokenInfo, err := auth2.GetTokenInfo(ctx.GetToken()); err == nil {
|
||||
RegisterUserWithMobile(ctx, &model.User{
|
||||
Name: v,
|
||||
Mobile: &v,
|
||||
UserID2: v,
|
||||
}, "", nil, manTokenInfo)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -561,6 +569,14 @@ func AddUsers4Role(ctx *jxcontext.Context, r *authz.RoleInfo, userIDList []strin
|
||||
|
||||
errList := errlist.New()
|
||||
for _, v := range userIDList {
|
||||
// if permission.IsRoledByUserID(v) {
|
||||
// if storeIDsMap, err := permission.GetUserStoresResultMap(v); err == nil {
|
||||
// if storeIDsMap[r.StoreID] == 0 {
|
||||
// return fmt.Errorf("此用户没有该门店[%v]的权限,无法添加到分组", r.StoreID)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
if err = checkUserType(v, model.UserTypeNonConsumer); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user