Merge remote-tracking branch 'origin/mark' into su
This commit is contained in:
@@ -2,6 +2,7 @@ package cms
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -31,6 +32,13 @@ const (
|
||||
SendMsgTypeSuggestRequest = "suggestRequest"
|
||||
)
|
||||
|
||||
type SysConfigLimit struct {
|
||||
ValueType reflect.Kind
|
||||
MinValue int64
|
||||
MaxValue int64
|
||||
AfterChanged func() error
|
||||
}
|
||||
|
||||
var (
|
||||
serviceInfo map[string]interface{}
|
||||
allowUpdatePlaceFieldsMap = map[string]bool{
|
||||
@@ -54,6 +62,36 @@ var (
|
||||
needConfirmRequestMap = map[string]int{
|
||||
SendMsgTypeOpenStoreRequest: 1,
|
||||
}
|
||||
|
||||
SysConfigLimitMap = map[string]*SysConfigLimit{
|
||||
model.ConfigSysEbaiBoxFee: &SysConfigLimit{
|
||||
ValueType: reflect.Int,
|
||||
MinValue: 0,
|
||||
MaxValue: 500,
|
||||
AfterChanged: func() (err error) {
|
||||
_, err = dao.SetStoreMapSyncStatus(dao.GetDB(), []int{model.VendorIDEBAI}, nil, model.SyncFlagModifiedMask)
|
||||
return err
|
||||
},
|
||||
},
|
||||
model.ConfigSysMtwmBoxFee: &SysConfigLimit{
|
||||
ValueType: reflect.Int,
|
||||
MinValue: 0,
|
||||
MaxValue: 500,
|
||||
AfterChanged: func() (err error) {
|
||||
_, err = dao.SetStoreMapSyncStatus(dao.GetDB(), []int{model.VendorIDMTWM}, nil, model.SyncFlagModifiedMask)
|
||||
return err
|
||||
},
|
||||
},
|
||||
model.ConfigSysMtwmSkuBoxFee: &SysConfigLimit{
|
||||
ValueType: reflect.Int,
|
||||
MinValue: 0,
|
||||
MaxValue: 50,
|
||||
AfterChanged: func() (err error) {
|
||||
_, err = dao.SetStoreSkuSyncStatus(dao.GetDB(), model.VendorIDMTWM, nil, nil, model.SyncFlagModifiedMask)
|
||||
return err
|
||||
},
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
func InitServiceInfo(version string, buildTime time.Time, gitCommit string) {
|
||||
@@ -102,6 +140,7 @@ func InitServiceInfo(version string, buildTime time.Time, gitCommit string) {
|
||||
"refundStatusName": model.RefundStatusName,
|
||||
"autoReplyTypeName": model.AutoReplyTypeName,
|
||||
"complaintReasons": model.ComplaintReasons,
|
||||
"supplementType": model.SupplementTypeName,
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -193,6 +232,27 @@ func SendMsg2Somebody(ctx *jxcontext.Context, mobileNum, verifyCode, msgType, ms
|
||||
return err
|
||||
}
|
||||
|
||||
func checkSysConfig(key, value string) (err error) {
|
||||
if limit := SysConfigLimitMap[key]; limit != nil {
|
||||
if limit.ValueType == reflect.Int {
|
||||
int64Value, err2 := strconv.ParseInt(value, 10, 64)
|
||||
if err = err2; err == nil {
|
||||
if int64Value < limit.MinValue || int64Value > limit.MaxValue {
|
||||
err = fmt.Errorf("配置%s,值%s超范围[%d,%d]", key, value, limit.MinValue, limit.MaxValue)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func onSysConfigChanged(key, value string) (err error) {
|
||||
if limit := SysConfigLimitMap[key]; limit != nil && limit.AfterChanged != nil {
|
||||
err = limit.AfterChanged()
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func checkConfig(opFlag int, configType, key, value string) (err error) {
|
||||
switch configType {
|
||||
case model.ConfigTypePricePack:
|
||||
@@ -228,8 +288,10 @@ func checkConfig(opFlag int, configType, key, value string) (err error) {
|
||||
}
|
||||
case model.ConfigTypeRole:
|
||||
case model.ConfigTypeSys:
|
||||
if opFlag&(model.SyncFlagNewMask|model.SyncFlagDeletedMask) != 0 {
|
||||
err = fmt.Errorf("系统参数只支持修改,不支持自由添加")
|
||||
if opFlag&( /*model.SyncFlagNewMask|*/ model.SyncFlagDeletedMask) != 0 {
|
||||
err = fmt.Errorf("系统参数只支持修改或添加,不支持删除")
|
||||
} else {
|
||||
err = checkSysConfig(key, value)
|
||||
}
|
||||
default:
|
||||
err = fmt.Errorf("当前只支持配置:%s, 传入的配置类型:%s", utils.Format4Output(model.ConfigTypeName, true), configType)
|
||||
@@ -249,7 +311,11 @@ func AddConfig(ctx *jxcontext.Context, key, configType, value string) (err error
|
||||
Value: value,
|
||||
}
|
||||
dao.WrapAddIDCULDEntity(conf, ctx.GetUserName())
|
||||
return dao.CreateEntity(db, conf)
|
||||
err = dao.CreateEntity(db, conf)
|
||||
if configType == model.ConfigTypeSys && err == nil {
|
||||
err = onSysConfigChanged(key, value)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func DeleteConfig(ctx *jxcontext.Context, key, configType string) (err error) {
|
||||
@@ -314,6 +380,9 @@ func DeleteConfig(ctx *jxcontext.Context, key, configType string) (err error) {
|
||||
"Type": configType,
|
||||
})
|
||||
}
|
||||
if configType == model.ConfigTypeSys && err == nil {
|
||||
err = onSysConfigChanged(key, "")
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -393,6 +462,9 @@ func UpdateConfig(ctx *jxcontext.Context, key, configType, value string) (hint s
|
||||
default:
|
||||
dao.Commit(db)
|
||||
}
|
||||
if configType == model.ConfigTypeSys && err == nil {
|
||||
err = onSysConfigChanged(key, value)
|
||||
}
|
||||
return hint, err
|
||||
}
|
||||
|
||||
|
||||
@@ -101,8 +101,8 @@ func AddCategory(ctx *jxcontext.Context, cat *model.SkuCategory, userName string
|
||||
}
|
||||
|
||||
dao.WrapAddIDCULDEntity(cat, userName)
|
||||
cat.JdSyncStatus = model.SyncFlagNewMask
|
||||
cat.JdID = 0
|
||||
// cat.JdSyncStatus = model.SyncFlagNewMask
|
||||
// cat.JdID = 0
|
||||
cat.Status = model.CategoryStatusEnable
|
||||
cat.Name = strings.Trim(cat.Name, " ")
|
||||
if cat.Img != "" {
|
||||
@@ -152,12 +152,12 @@ func UpdateCategory(ctx *jxcontext.Context, categoryID int, payload map[string]i
|
||||
}
|
||||
valid := dao.StrictMakeMapByStructObject(payload, cat, userName)
|
||||
if len(valid) > 0 {
|
||||
syncStatus := 0
|
||||
if valid["name"] != nil {
|
||||
valid["name"] = strings.Trim(valid["name"].(string), " ")
|
||||
syncStatus = model.SyncFlagModifiedMask
|
||||
valid[model.FieldJdSyncStatus] = int8(syncStatus) | cat.JdSyncStatus
|
||||
}
|
||||
// syncStatus := 0
|
||||
// if valid["name"] != nil {
|
||||
// valid["name"] = strings.Trim(valid["name"].(string), " ")
|
||||
// syncStatus = model.SyncFlagModifiedMask
|
||||
// valid[model.FieldJdSyncStatus] = int8(syncStatus) | cat.JdSyncStatus
|
||||
// }
|
||||
if valid["status"] != nil {
|
||||
if utils.Interface2Int64WithDefault(valid["status"], -1) == model.CategoryStatusDisabled {
|
||||
if skuList, err2 := dao.GetSkuByCats(db, []int{categoryID}); err2 == nil && len(skuList) > 0 {
|
||||
@@ -336,7 +336,10 @@ func DeleteCategory(ctx *jxcontext.Context, categoryID int, userName string) (nu
|
||||
dao.Rollback(db)
|
||||
return 0, err
|
||||
}
|
||||
if num, err = dao.DeleteEntityLogically(db, cat, utils.Params2Map(model.FieldJdSyncStatus, model.SyncFlagDeletedMask), userName, nil); err != nil {
|
||||
if num, err = dao.DeleteEntityLogically(db, cat, map[string]interface{}{
|
||||
// model.FieldJdSyncStatus: model.SyncFlagDeletedMask,
|
||||
model.FieldStatus: 0,
|
||||
}, userName, nil); err != nil {
|
||||
dao.Rollback(db)
|
||||
return 0, err
|
||||
}
|
||||
@@ -441,8 +444,13 @@ func GetSkuNames(ctx *jxcontext.Context, keyword string, isBySku bool, params ma
|
||||
return nil, err
|
||||
}
|
||||
if len(vendorSkuIDs) > 0 {
|
||||
sql += " AND t2.jd_id IN (" + dao.GenQuestionMarks(len(vendorSkuIDs)) + ")"
|
||||
sqlParams = append(sqlParams, vendorSkuIDs)
|
||||
if globals.IsUseThingMap {
|
||||
sql += " AND (SELECT COUNT(*) FROM thing_map tm WHERE tm.thing_type = ? AND tm.thing_id = t2.id AND tm.deleted_at = ? AND tm.vendor_thing_id IN (" + dao.GenQuestionMarks(len(vendorSkuIDs)) + ")) > 0"
|
||||
sqlParams = append(sqlParams, utils.DefaultTimeValue, vendorSkuIDs)
|
||||
} else {
|
||||
sql += " AND t2.jd_id IN (" + dao.GenQuestionMarks(len(vendorSkuIDs)) + ")"
|
||||
sqlParams = append(sqlParams, vendorSkuIDs)
|
||||
}
|
||||
}
|
||||
}
|
||||
if params["name"] != nil {
|
||||
@@ -552,16 +560,18 @@ func GetSkuNames(ctx *jxcontext.Context, keyword string, isBySku bool, params ma
|
||||
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,
|
||||
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,
|
||||
'","weight":', t2.weight, ',"jdID":', t2.jd_id, ',"categoryID":', t2.category_id, ',"nameID":', t2.name_id,
|
||||
',"jdID":', t2.jd_id, ',"jdSyncStatus":', t2.jd_sync_status, ', "seq":', t2.seq,
|
||||
'","weight":', t2.weight, ',"categoryID":', t2.category_id, ',"nameID":', t2.name_id,
|
||||
', "seq":', t2.seq,
|
||||
"}")), "]") skus_str,
|
||||
CONCAT("[", GROUP_CONCAT(DISTINCT t3.place_code), "]") places_str
|
||||
` + sql + `
|
||||
@@ -670,7 +680,7 @@ func AddSkuName(ctx *jxcontext.Context, skuNameExt *model.SkuNameExt, userName s
|
||||
skuNameExt.SkuName.Status = model.SkuStatusNormal
|
||||
if skuNameExt.IsSpu == 1 {
|
||||
return nil, fmt.Errorf("不允许创建多规格商品")
|
||||
skuNameExt.SkuName.JdSyncStatus = model.SyncFlagNewMask
|
||||
// skuNameExt.SkuName.JdSyncStatus = model.SyncFlagNewMask
|
||||
}
|
||||
if skuNameExt.Unit == model.SpecialUnit {
|
||||
skuNameExt.SpecQuality = float32(model.SpecialSpecQuality)
|
||||
@@ -727,8 +737,8 @@ func AddSkuName(ctx *jxcontext.Context, skuNameExt *model.SkuNameExt, userName s
|
||||
sku := v.Sku
|
||||
dao.WrapAddIDCULDEntity(sku, userName)
|
||||
sku.NameID = skuNameExt.ID
|
||||
sku.JdSyncStatus = model.SyncFlagNewMask
|
||||
sku.JdID = 0
|
||||
// sku.JdSyncStatus = model.SyncFlagNewMask
|
||||
// sku.JdID = 0
|
||||
if err = dao.CreateEntity(db, sku); err != nil {
|
||||
dao.Rollback(db)
|
||||
return nil, err
|
||||
@@ -822,7 +832,7 @@ func UpdateSkuName(ctx *jxcontext.Context, nameID int, payload map[string]interf
|
||||
panic(r)
|
||||
}
|
||||
}()
|
||||
valid[model.FieldJdSyncStatus] = model.SyncFlagModifiedMask | skuName.JdSyncStatus
|
||||
// valid[model.FieldJdSyncStatus] = model.SyncFlagModifiedMask | skuName.JdSyncStatus
|
||||
if num, err = dao.UpdateEntityLogically(db, skuName, valid, userName, nil); err != nil {
|
||||
dao.Rollback(db)
|
||||
return 0, err
|
||||
@@ -855,7 +865,7 @@ func UpdateSkuName(ctx *jxcontext.Context, nameID int, payload map[string]interf
|
||||
if err = err2; err == nil {
|
||||
for _, v := range skuList {
|
||||
sku := &v.Sku
|
||||
sku.JdSyncStatus |= model.SyncFlagModifiedMask
|
||||
// sku.JdSyncStatus |= model.SyncFlagModifiedMask
|
||||
sku.LastOperator = userName
|
||||
sku.UpdatedAt = time.Now()
|
||||
if _, err = dao.UpdateEntity(db, sku); err != nil {
|
||||
@@ -930,8 +940,8 @@ func DeleteSkuName(ctx *jxcontext.Context, nameID int, userName string) (num int
|
||||
return 0, err
|
||||
}
|
||||
if _, err = dao.DeleteEntityLogically(db, sku, map[string]interface{}{
|
||||
model.FieldJdSyncStatus: model.SyncFlagDeletedMask,
|
||||
model.FieldStatus: model.SkuStatusDeleted,
|
||||
// model.FieldJdSyncStatus: model.SyncFlagDeletedMask,
|
||||
model.FieldStatus: model.SkuStatusDeleted,
|
||||
}, userName, nil); err != nil {
|
||||
dao.Rollback(db)
|
||||
return 0, err
|
||||
@@ -947,8 +957,8 @@ func DeleteSkuName(ctx *jxcontext.Context, nameID int, userName string) (num int
|
||||
skuName := &model.SkuName{}
|
||||
skuName.ID = nameID
|
||||
if num, err = dao.DeleteEntityLogically(db, skuName, map[string]interface{}{
|
||||
model.FieldJdSyncStatus: model.SyncFlagDeletedMask,
|
||||
model.FieldStatus: model.SkuStatusDeleted,
|
||||
// model.FieldJdSyncStatus: model.SyncFlagDeletedMask,
|
||||
model.FieldStatus: model.SkuStatusDeleted,
|
||||
}, userName, nil); err != nil {
|
||||
dao.Rollback(db)
|
||||
return 0, err
|
||||
@@ -973,8 +983,8 @@ func AddSku(ctx *jxcontext.Context, nameID int, sku *model.Sku, userName string)
|
||||
}
|
||||
|
||||
dao.WrapAddIDCULDEntity(sku, userName)
|
||||
sku.JdSyncStatus = model.SyncFlagNewMask
|
||||
sku.JdID = 0
|
||||
// sku.JdSyncStatus = model.SyncFlagNewMask
|
||||
// sku.JdID = 0
|
||||
sku.NameID = nameID
|
||||
|
||||
dao.Begin(db)
|
||||
@@ -1028,7 +1038,7 @@ func UpdateSku(ctx *jxcontext.Context, skuID int, payload map[string]interface{}
|
||||
if valid["specQuality"] != nil || valid["specUnit"] != nil {
|
||||
maskValue |= model.SyncFlagSpecMask
|
||||
}
|
||||
valid[model.FieldJdSyncStatus] = maskValue | sku.JdSyncStatus
|
||||
// valid[model.FieldJdSyncStatus] = maskValue | sku.JdSyncStatus
|
||||
if num, err = dao.UpdateEntityLogically(db, sku, valid, userName, nil); err != nil || num == 0 {
|
||||
dao.Rollback(db)
|
||||
if err == nil {
|
||||
@@ -1121,8 +1131,8 @@ func DeleteSku(ctx *jxcontext.Context, skuID int, userName string) (num int64, e
|
||||
sku := &model.Sku{}
|
||||
sku.ID = skuID
|
||||
if num, err = dao.DeleteEntityLogically(db, sku, map[string]interface{}{
|
||||
model.FieldStatus: model.SkuStatusDeleted,
|
||||
model.FieldJdSyncStatus: model.SyncFlagDeletedMask,
|
||||
model.FieldStatus: model.SkuStatusDeleted,
|
||||
// model.FieldJdSyncStatus: model.SyncFlagDeletedMask,
|
||||
}, userName, nil); err != nil {
|
||||
dao.Rollback(db)
|
||||
return 0, err
|
||||
|
||||
@@ -176,6 +176,13 @@ var (
|
||||
"promoteInfo": 1,
|
||||
}
|
||||
|
||||
storeMapKeyPropertyMap = map[string]int{
|
||||
"status": 1,
|
||||
"freightDeductionPack": 1,
|
||||
"vendorStoreName": 1,
|
||||
"boxFee": 1,
|
||||
}
|
||||
|
||||
WatchVendorStoreTimeList = []string{
|
||||
"8:00:00",
|
||||
"10:00:00",
|
||||
@@ -1121,6 +1128,17 @@ func DeleteStoreVendorMap(ctx *jxcontext.Context, db *dao.DaoDB, storeID, vendor
|
||||
return num, err
|
||||
}
|
||||
|
||||
func isStoreMapNeedSync(vendorID int, valid map[string]interface{}) bool {
|
||||
if vendorID != model.VendorIDJX {
|
||||
for k := range valid {
|
||||
if storeMapKeyPropertyMap[k] == 1 {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func UpdateStoreVendorMap(ctx *jxcontext.Context, db *dao.DaoDB, storeID, vendorID int, payload map[string]interface{}, userName string) (num int64, err error) {
|
||||
if vendorID != model.VendorIDJD {
|
||||
if autoPickup, ok := payload["autoPickup"]; ok && autoPickup == 0 {
|
||||
@@ -1196,7 +1214,7 @@ func UpdateStoreVendorMap(ctx *jxcontext.Context, db *dao.DaoDB, storeID, vendor
|
||||
panic(r)
|
||||
}
|
||||
}()
|
||||
if valid["status"] != nil || valid["vendorStoreName"] != nil { // 对于store vendor map,只有Status改变才需要同步到厂商
|
||||
if isStoreMapNeedSync(vendorID, valid) { // 对于store vendor map,只有Status改变才需要同步到厂商
|
||||
num, err = dao.UpdateEntityLogicallyAndUpdateSyncStatus(db, storeMap, valid, userName, map[string]interface{}{
|
||||
model.FieldStoreID: storeID,
|
||||
model.FieldVendorID: vendorID,
|
||||
@@ -1229,7 +1247,7 @@ func UpdateStoreVendorMap(ctx *jxcontext.Context, db *dao.DaoDB, storeID, vendor
|
||||
}
|
||||
}
|
||||
dao.Commit(db)
|
||||
if vendorID != model.VendorIDJX && (valid["status"] != nil || valid["freightDeductionPack"] != nil || valid["vendorStoreName"] != nil) {
|
||||
if isStoreMapNeedSync(vendorID, valid) {
|
||||
_, err = CurVendorSync.SyncStore(ctx, db, vendorID, storeID, false, userName)
|
||||
}
|
||||
}
|
||||
@@ -2577,7 +2595,7 @@ func CreateStorePriceScore(ctx *jxcontext.Context) (err error) {
|
||||
}
|
||||
}
|
||||
}()
|
||||
priceReferSnapshotDeleteHis := &model.StorePriceScoreSnapshot{SnapshotAt: snapshotAt.AddDate(0, -1, 0)}
|
||||
priceReferSnapshotDeleteHis := &model.StorePriceScoreSnapshot{SnapshotAt: snapshotAt.AddDate(0, 0, -7)}
|
||||
priceReferSnapshotDelete := &model.StorePriceScoreSnapshot{SnapshotAt: snapshotAt}
|
||||
dao.DeleteEntity(db, priceReferSnapshotDeleteHis, "SnapshotAt")
|
||||
dao.DeleteEntity(db, priceReferSnapshotDelete, "SnapshotAt")
|
||||
|
||||
@@ -114,6 +114,7 @@ type tGetStoresSkusInfo struct {
|
||||
model.SkuName
|
||||
PayPercentage int `json:"-"`
|
||||
dao.StoreSkuExt
|
||||
RealMidUnitPrice int `json:"realMidUnitPrice"` //真实的该商品的全国中位价
|
||||
}
|
||||
|
||||
type SheetParam struct {
|
||||
@@ -154,6 +155,11 @@ type DataLock struct {
|
||||
locker sync.RWMutex
|
||||
}
|
||||
|
||||
type tUpdateStoresSkus struct {
|
||||
StoreID int
|
||||
SkuBindInfos []*StoreSkuBindInfo
|
||||
}
|
||||
|
||||
const (
|
||||
maxStoreNameBind = 10000 // 最大门店SkuName bind个数
|
||||
maxStoreNameBind2 = 10000 // 最大门店乘SkuName个数
|
||||
@@ -256,10 +262,12 @@ func getGetStoresSkusBaseSQL(db *dao.DaoDB, storeIDs, skuIDs []int, isFocus bool
|
||||
sql += `
|
||||
JOIN store_sku_bind t4 ON t4.store_id = t3.id AND t4.sku_id = t2.id AND t4.deleted_at = ?
|
||||
LEFT JOIN sku_name_place_bind t5 ON t1.id = t5.name_id AND t3.city_code = t5.place_code
|
||||
LEFT JOIN price_refer_snapshot t6 ON t6.city_code = 0 AND t6.sku_id = t2.id AND t6.snapshot_at = ?
|
||||
WHERE t1.deleted_at = ? AND (t1.is_global = 1 OR t5.id IS NOT NULL OR 1 = ?)/* AND t1.status = ?*/
|
||||
`
|
||||
sqlParams = append(sqlParams, []interface{}{
|
||||
utils.DefaultTimeValue,
|
||||
utils.Time2Date(time.Now().AddDate(0, 0, -1)),
|
||||
utils.DefaultTimeValue,
|
||||
utils.Bool2Int(isFocus),
|
||||
// model.SkuStatusNormal,
|
||||
@@ -277,8 +285,15 @@ func getGetStoresSkusBaseSQL(db *dao.DaoDB, storeIDs, skuIDs []int, isFocus bool
|
||||
sqlParams = append(sqlParams, keywordLike, keywordLike, keywordLike, keywordLike)
|
||||
|
||||
if keywordInt64, err2 := strconv.ParseInt(keyword, 10, 64); err2 == nil {
|
||||
sql += " OR t1.id = ? OR t2.id = ? OR t2.jd_id = ?"
|
||||
sqlParams = append(sqlParams, keywordInt64, keywordInt64, keywordInt64)
|
||||
sql += " OR t1.id = ? OR t2.id = ?"
|
||||
sqlParams = append(sqlParams, keywordInt64, keywordInt64)
|
||||
if !globals.IsUseThingMap {
|
||||
sql += " OR t2.jd_id = ?"
|
||||
sqlParams = append(sqlParams, keywordInt64)
|
||||
} else {
|
||||
sql += " OR (SELECT COUNT(*) FROM thing_map tm WHERE tm.vendor_org_code = sm.vendor_org_code AND tm.thing_type = ? AND tm.thing_id = t2.id AND tm.deleted_at = ? AND tm.vendor_thing_id = ?) > 0"
|
||||
sqlParams = append(sqlParams, model.ThingTypeSku, utils.DefaultTimeValue, keywordInt64)
|
||||
}
|
||||
if isFocus {
|
||||
sql += " OR t4.ebai_id = ? OR t4.mtwm_id = ?"
|
||||
sqlParams = append(sqlParams, keywordInt64, keywordInt64)
|
||||
@@ -481,7 +496,8 @@ func GetStoresSkusNew(ctx *jxcontext.Context, storeIDs, skuIDs []int, isFocus bo
|
||||
t4.jd_sync_status, t4.ebai_sync_status, t4.mtwm_sync_status,
|
||||
t4.jd_price, t4.ebai_price, t4.mtwm_price, t4.jx_price,
|
||||
t4.jd_lock_time, t4.ebai_lock_time, t4.mtwm_lock_time, t4.jx_lock_time,
|
||||
t4.status_sale_begin, t4.status_sale_end
|
||||
t4.status_sale_begin, t4.status_sale_end,
|
||||
t6.mid_unit_price real_mid_unit_price
|
||||
`, jdVendorIDField) + sql
|
||||
var tmpList []*tGetStoresSkusInfo
|
||||
beginTime := time.Now()
|
||||
@@ -500,11 +516,12 @@ func GetStoresSkusNew(ctx *jxcontext.Context, storeIDs, skuIDs []int, isFocus bo
|
||||
index := jxutils.Combine2Int(v.StoreID, v.ID)
|
||||
if isBySku || storeNameMap[index] == nil {
|
||||
storeName = &dao.StoreSkuNameExt{
|
||||
StoreID: v.StoreID,
|
||||
StoreName: v.StoreName,
|
||||
SkuName: v.SkuName,
|
||||
UnitPrice: v.UnitPrice,
|
||||
PayPercentage: v.PayPercentage,
|
||||
StoreID: v.StoreID,
|
||||
StoreName: v.StoreName,
|
||||
SkuName: v.SkuName,
|
||||
UnitPrice: v.UnitPrice,
|
||||
PayPercentage: v.PayPercentage,
|
||||
RealMidUnitPrice: v.RealMidUnitPrice,
|
||||
}
|
||||
if !isBySku {
|
||||
storeNameMap[index] = storeName
|
||||
@@ -1890,7 +1907,7 @@ func RefreshStoresSkuByVendor(ctx *jxcontext.Context, storeIDs []int, vendorID i
|
||||
return "", fmt.Errorf("此功能当前只支持京东到家平台")
|
||||
}
|
||||
db := dao.GetDB()
|
||||
storeMapList, err := dao.GetStoresMapList(db, nil, storeIDs, model.StoreStatusAll, model.StoreIsSyncAll, "")
|
||||
storeMapList, err := dao.GetStoresMapList(db, []int{vendorID}, storeIDs, model.StoreStatusAll, model.StoreIsSyncAll, "")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -1907,13 +1924,13 @@ func RefreshStoresSkuByVendor(ctx *jxcontext.Context, storeIDs []int, vendorID i
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
skuList, err := dao.GetSkus(db, nil, nil, nil, nil)
|
||||
skuList, err := dao.GetSkusWithVendor(db, []int{vendorID}, nil, nil, nil, false)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
skuNameMap := make(map[int]*model.SkuName)
|
||||
skuMap := make(map[int]*model.SkuAndName)
|
||||
var bareStoreSkuList []*partner.StoreSkuInfo
|
||||
skuMap := make(map[int]*dao.StoreSkuSyncInfo)
|
||||
bareStoreSkuMap := make(map[string][]*partner.StoreSkuInfo)
|
||||
for _, sku := range skuList {
|
||||
if skuNameMap[sku.NameID] == nil {
|
||||
skuNameMap[sku.NameID] = &model.SkuName{
|
||||
@@ -1922,9 +1939,9 @@ func RefreshStoresSkuByVendor(ctx *jxcontext.Context, storeIDs []int, vendorID i
|
||||
}
|
||||
skuMap[sku.ID] = sku
|
||||
|
||||
bareStoreSkuList = append(bareStoreSkuList, &partner.StoreSkuInfo{
|
||||
bareStoreSkuMap[sku.VendorOrgCode] = append(bareStoreSkuMap[sku.VendorOrgCode], &partner.StoreSkuInfo{
|
||||
SkuID: sku.ID,
|
||||
VendorSkuID: utils.Int64ToStr(sku.JdID),
|
||||
VendorSkuID: sku.VendorSkuID,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1937,7 +1954,7 @@ func RefreshStoresSkuByVendor(ctx *jxcontext.Context, storeIDs []int, vendorID i
|
||||
func(task *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) {
|
||||
switch step {
|
||||
case 0:
|
||||
bareStoreSkuList, err2 := handler.GetStoreSkusBareInfo(ctx, oneStoreMap.VendorOrgCode, task, oneStoreMap.StoreID, oneStoreMap.VendorStoreID, bareStoreSkuList)
|
||||
bareStoreSkuList, err2 := handler.GetStoreSkusBareInfo(ctx, oneStoreMap.VendorOrgCode, task, oneStoreMap.StoreID, oneStoreMap.VendorStoreID, bareStoreSkuMap[oneStoreMap.VendorOrgCode])
|
||||
// globals.SugarLogger.Debug(utils.Format4Output(bareStoreSkuList, false))
|
||||
if err = err2; err == nil || len(bareStoreSkuList) > 0 {
|
||||
err = nil // todo 如果部分失败,强制忽略错误
|
||||
@@ -2202,18 +2219,7 @@ func GetTopSkusByCityCode(ctx *jxcontext.Context, cityCode, storeID int) (skuNam
|
||||
JOIN sku b ON a.sku_id = b.id AND b.deleted_at = ?
|
||||
WHERE a.deleted_at = ?
|
||||
AND a.store_id = ?
|
||||
AND a.status = ?)
|
||||
UNION
|
||||
SELECT DISTINCT a.name_id id,0 brand_id
|
||||
FROM sku a
|
||||
LEFT JOIN (SELECT DISTINCT b.name_id
|
||||
FROM store_sku_bind a
|
||||
JOIN sku b ON a.sku_id = b.id
|
||||
WHERE a.deleted_at = ?
|
||||
AND store_id = ?)b ON a.name_id = b.name_id
|
||||
WHERE a.status = ?
|
||||
AND a.deleted_at = ?
|
||||
AND b.name_id IS NULL
|
||||
AND a.status = ?)
|
||||
`
|
||||
sqlParams := []interface{}{
|
||||
utils.DefaultTimeValue,
|
||||
@@ -2224,23 +2230,31 @@ func GetTopSkusByCityCode(ctx *jxcontext.Context, cityCode, storeID int) (skuNam
|
||||
utils.DefaultTimeValue,
|
||||
storeID,
|
||||
model.StoreSkuBindStatusNormal,
|
||||
utils.DefaultTimeValue,
|
||||
storeID,
|
||||
model.StoreSkuBindStatusNormal,
|
||||
utils.DefaultTimeValue,
|
||||
}
|
||||
err = dao.GetRows(db, &skuNameList, sql, sqlParams...)
|
||||
var skuNameMap = make(map[int]*model.SkuName)
|
||||
for _, v := range skuNameList {
|
||||
skuNameMap[v.ID] = v
|
||||
}
|
||||
store, err := dao.GetStoreDetail(db, storeID, -1)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var payPercentage int
|
||||
if store.PayPercentage < 50 {
|
||||
payPercentage = 70
|
||||
} else {
|
||||
payPercentage = store.PayPercentage
|
||||
}
|
||||
for _, v := range skuNameAndPlace {
|
||||
if skuNameMap[v.ID] != nil {
|
||||
midPrice, _ := dao.GetMidPriceByNameID(db, cityCode, v.ID, utils.Time2Date(time.Now().AddDate(0, 0, -1)))
|
||||
if midPrice != 0 {
|
||||
v.Price = midPrice
|
||||
priceReferList, _ := dao.GetPriceReferSnapshotNoPage(db, []int{cityCode}, nil, []int{v.ID}, utils.Time2Date(time.Now().AddDate(0, 0, -1)))
|
||||
if len(priceReferList) > 0 {
|
||||
v.Price = priceReferList[0].MidUnitPrice * payPercentage / 100
|
||||
}
|
||||
v.Type = skuNameMap[v.ID].BrandID
|
||||
skuList, _ := dao.GetSkus(db, nil, []int{v.ID}, nil, nil)
|
||||
v.Skus = skuList
|
||||
skuNameAndPlaceList = append(skuNameAndPlaceList, v)
|
||||
}
|
||||
}
|
||||
@@ -2303,7 +2317,39 @@ func GetTopCategoriesByStoreIDs(ctx *jxcontext.Context, storeIDs []int) (skuCate
|
||||
|
||||
func RefershStoreSkusMidPrice(ctx *jxcontext.Context, storeIDs []int) (err error) {
|
||||
db := dao.GetDB()
|
||||
_, err = dao.RefershStoreSkusMidPrice(db, storeIDs)
|
||||
if len(storeIDs) == 0 {
|
||||
return err
|
||||
}
|
||||
for _, v := range storeIDs {
|
||||
var skuBindInfos []*StoreSkuBindInfo
|
||||
store, err := dao.GetStoreDetail(db, v, -1)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var payPercentage int
|
||||
if store.PayPercentage < 50 {
|
||||
payPercentage = 70
|
||||
} else {
|
||||
payPercentage = store.PayPercentage
|
||||
}
|
||||
storeSkuList, err := dao.GetStoresSkusInfo(db, []int{v}, nil)
|
||||
for _, storeSku := range storeSkuList {
|
||||
priceReferList, err := dao.GetPriceReferSnapshotNoPage(db, []int{store.CityCode}, []int{storeSku.SkuID}, nil, utils.Time2Date(time.Now().AddDate(0, 0, -1)))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(priceReferList) > 0 {
|
||||
if storeSku.UnitPrice > priceReferList[0].MidUnitPrice*payPercentage/100 {
|
||||
skuBindInfo := &StoreSkuBindInfo{
|
||||
NameID: priceReferList[0].NameID,
|
||||
UnitPrice: priceReferList[0].MidUnitPrice * payPercentage / 100,
|
||||
}
|
||||
skuBindInfos = append(skuBindInfos, skuBindInfo)
|
||||
}
|
||||
}
|
||||
}
|
||||
updateStoresSkusWithoutSync(ctx, db, []int{v}, skuBindInfos, false)
|
||||
}
|
||||
if err == nil {
|
||||
CreateStorePriceScore(ctx)
|
||||
}
|
||||
@@ -2624,15 +2670,15 @@ func GetVendorStoreSkuPrice(ctx *jxcontext.Context, vendorIDs []int, skuID int,
|
||||
outStoreSkuList []*partner.StoreSkuInfo
|
||||
)
|
||||
db := dao.GetDB()
|
||||
skuNameList, err := dao.GetSkus(db, []int{skuID}, nil, nil, nil)
|
||||
skuList, err := dao.GetSkusWithVendor(db, []int{vendorID}, []string{v}, nil, []int{skuID}, false)
|
||||
if err != nil {
|
||||
return retVal, err
|
||||
}
|
||||
if partner.IsMultiStore(vendorID) {
|
||||
multiHandler, _ := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.IMultipleStoresHandler)
|
||||
storeDetail, err = multiHandler.ReadStore(ctx, v, vendorStoreID)
|
||||
if len(skuNameList) > 0 {
|
||||
inStoreSku.VendorSkuID = utils.Int64ToStr(skuNameList[0].JdID)
|
||||
if len(skuList) > 0 {
|
||||
inStoreSku.VendorSkuID = skuList[0].VendorSkuID
|
||||
}
|
||||
} else {
|
||||
singleHandler, _ := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.ISingleStoreHandler)
|
||||
@@ -2652,7 +2698,7 @@ func GetVendorStoreSkuPrice(ctx *jxcontext.Context, vendorIDs []int, skuID int,
|
||||
StoreID: vendorStoreID,
|
||||
StoreName: storeDetail.Name,
|
||||
SkuID: skuID,
|
||||
SkuName: skuNameList[0].Name,
|
||||
SkuName: skuList[0].Name,
|
||||
VendorPrice: "",
|
||||
}
|
||||
retVal = []DataVendorStoreSkuPrice{data}
|
||||
@@ -2661,7 +2707,7 @@ func GetVendorStoreSkuPrice(ctx *jxcontext.Context, vendorIDs []int, skuID int,
|
||||
StoreID: vendorStoreID,
|
||||
StoreName: storeDetail.Name,
|
||||
SkuID: skuID,
|
||||
SkuName: skuNameList[0].Name,
|
||||
SkuName: skuList[0].Name,
|
||||
VendorPrice: utils.Float64ToStr(utils.Str2Float64(utils.Int64ToStr(outStoreSkuList[0].VendorPrice)) / 100),
|
||||
}
|
||||
retVal = []DataVendorStoreSkuPrice{data}
|
||||
@@ -2753,22 +2799,20 @@ func FocusStoreSkusByExcel(ctx *jxcontext.Context, files []*multipart.FileHeader
|
||||
|
||||
func FocusStoreSkusByExcelBin(ctx *jxcontext.Context, reader io.Reader, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||
var (
|
||||
skuMap = make(map[int]int)
|
||||
skuNameMap = make(map[int]int)
|
||||
skuBindInfos []*StoreSkuBindInfo
|
||||
db = dao.GetDB()
|
||||
storeIDs []int
|
||||
skuIDs []int
|
||||
skuMap = make(map[int]int)
|
||||
db = dao.GetDB()
|
||||
skuIDs []int
|
||||
result1 []interface{}
|
||||
)
|
||||
sheetParam := &SheetParam{
|
||||
OutSkuIDCol: 1,
|
||||
SkuPriceCol: 3,
|
||||
SkuRow: 1,
|
||||
}
|
||||
// xlsx, err := excelize.OpenFile("111.xlsx")
|
||||
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)
|
||||
if err != nil {
|
||||
return result, err
|
||||
@@ -2785,43 +2829,72 @@ func FocusStoreSkusByExcelBin(ctx *jxcontext.Context, reader io.Reader, isAsync,
|
||||
skuIDs = append(skuIDs, k)
|
||||
}
|
||||
skuList, err := dao.GetSkus(db, skuIDs, nil, nil, nil)
|
||||
storeList, err := dao.GetStoreList(db, nil, nil, "")
|
||||
if err != nil && len(skuList) == 0 {
|
||||
return result, err
|
||||
}
|
||||
for _, v := range skuList {
|
||||
taskFunc := func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
store := batchItemList[0].(*model.Store)
|
||||
var (
|
||||
price int
|
||||
specQuality float64
|
||||
skuBindInfos []*StoreSkuBindInfo
|
||||
skuNameMap = make(map[int]int)
|
||||
skuInfoMap = make(map[int][]*StoreSkuBindSkuInfo)
|
||||
)
|
||||
if v.Unit == model.SpecialUnit {
|
||||
if v.SpecUnit == model.SpecUnitNames[1] || v.SpecUnit == model.SpecUnitNames[2] {
|
||||
specQuality = float64(v.SpecQuality) * 1000
|
||||
for _, v := range skuList {
|
||||
var (
|
||||
price int
|
||||
specQuality float64
|
||||
)
|
||||
focusList, _ := dao.GetStoreSkuBindByNameID(db, store.ID, v.NameID, model.StoreSkuBindStatusNormal)
|
||||
//有关注过
|
||||
if len(focusList) > 0 {
|
||||
price = focusList[0].UnitPrice
|
||||
skuInfoMap[v.NameID] = append(skuInfoMap[v.NameID], &StoreSkuBindSkuInfo{
|
||||
SkuID: v.ID,
|
||||
IsSale: 1,
|
||||
})
|
||||
skuNameMap[v.NameID] = price
|
||||
} else {
|
||||
specQuality = float64(v.SpecQuality)
|
||||
if v.Unit == model.SpecialUnit {
|
||||
if v.SpecUnit == model.SpecUnitNames[1] || v.SpecUnit == model.SpecUnitNames[2] {
|
||||
specQuality = float64(v.SpecQuality) * 1000
|
||||
} else {
|
||||
specQuality = float64(v.SpecQuality)
|
||||
}
|
||||
price = int(utils.Float64TwoInt64(utils.Int2Float64(model.SpecialSpecQuality) / specQuality * utils.Int2Float64(skuMap[v.ID])))
|
||||
} else {
|
||||
price = skuMap[v.ID]
|
||||
}
|
||||
if skuNameMap[v.NameID] < price {
|
||||
skuNameMap[v.NameID] = price
|
||||
}
|
||||
}
|
||||
price = int(utils.Float64TwoInt64(utils.Int2Float64(model.SpecialSpecQuality) / specQuality * utils.Int2Float64(skuMap[v.ID])))
|
||||
} else {
|
||||
price = skuMap[v.ID]
|
||||
}
|
||||
if skuNameMap[v.NameID] < price {
|
||||
skuNameMap[v.NameID] = price
|
||||
for k, v := range skuNameMap {
|
||||
skuBindInfo := &StoreSkuBindInfo{
|
||||
NameID: k,
|
||||
UnitPrice: v,
|
||||
IsFocus: 1,
|
||||
IsSale: 1,
|
||||
Skus: skuInfoMap[k],
|
||||
}
|
||||
skuBindInfos = append(skuBindInfos, skuBindInfo)
|
||||
}
|
||||
}
|
||||
for k, v := range skuNameMap {
|
||||
skuBindInfo := &StoreSkuBindInfo{
|
||||
NameID: k,
|
||||
UnitPrice: v,
|
||||
IsFocus: 1,
|
||||
IsSale: 1,
|
||||
tUpdate := &tUpdateStoresSkus{
|
||||
StoreID: store.ID,
|
||||
SkuBindInfos: skuBindInfos,
|
||||
}
|
||||
skuBindInfos = append(skuBindInfos, skuBindInfo)
|
||||
}
|
||||
storeList, err := dao.GetStoreList(db, nil, nil, "")
|
||||
for _, v := range storeList {
|
||||
storeIDs = append(storeIDs, v.ID)
|
||||
retVal = []*tUpdateStoresSkus{tUpdate}
|
||||
return retVal, err
|
||||
}
|
||||
taskParallel := tasksch.NewParallelTask("根据skuID关注商品", tasksch.NewParallelConfig().SetIsContinueWhenError(isContinueWhenError), ctx, taskFunc, storeList)
|
||||
tasksch.HandleTask(taskParallel, task, true).Run()
|
||||
result1, _ = taskParallel.GetResult(0)
|
||||
case 2:
|
||||
UpdateStoresSkus(ctx, storeIDs, skuBindInfos, false, isAsync, isContinueWhenError)
|
||||
for _, v := range result1 {
|
||||
tUpdate := v.(*tUpdateStoresSkus)
|
||||
UpdateStoresSkus(ctx, []int{tUpdate.StoreID}, tUpdate.SkuBindInfos, false, isAsync, isContinueWhenError)
|
||||
}
|
||||
}
|
||||
return result, err
|
||||
}
|
||||
@@ -2854,9 +2927,9 @@ func GetCellForFocusStoreSkus(db *dao.DaoDB, rowNum int, row []string, sheetPara
|
||||
|
||||
func FocusStoreSkusBySku(ctx *jxcontext.Context, skuIDs []int, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||
var (
|
||||
skuBindInfos []*StoreSkuBindInfo
|
||||
skuNameMap = make(map[int][]*StoreSkuBindSkuInfo)
|
||||
storeIDs []int
|
||||
skuNameMap = make(map[int][]*StoreSkuBindSkuInfo)
|
||||
storeIDs []int
|
||||
result1 []interface{}
|
||||
)
|
||||
db := dao.GetDB()
|
||||
skuList, err := dao.GetSkus(db, skuIDs, nil, nil, nil)
|
||||
@@ -2876,26 +2949,48 @@ func FocusStoreSkusBySku(ctx *jxcontext.Context, skuIDs []int, isAsync, isContin
|
||||
case 1:
|
||||
taskFunc := func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
store := batchItemList[0].(*model.Store)
|
||||
var skuBindInfos []*StoreSkuBindInfo
|
||||
for k, v := range skuNameMap {
|
||||
midPrice, _ := dao.GetMidPriceByNameID(db, store.CityCode, k, utils.Time2Date(time.Now().AddDate(0, 0, -1)))
|
||||
var price int
|
||||
focusList, _ := dao.GetStoreSkuBindByNameID(db, store.ID, k, model.StoreSkuBindStatusNormal)
|
||||
//有关注过
|
||||
if len(focusList) > 0 {
|
||||
price = focusList[0].UnitPrice
|
||||
} else {
|
||||
var payPercentage int
|
||||
if store.PayPercentage < 50 {
|
||||
payPercentage = 70
|
||||
} else {
|
||||
payPercentage = store.PayPercentage
|
||||
}
|
||||
priceReferList, _ := dao.GetPriceReferSnapshotNoPage(db, []int{store.CityCode}, nil, []int{k}, utils.Time2Date(time.Now().AddDate(0, 0, -1)))
|
||||
if len(priceReferList) > 0 {
|
||||
price = priceReferList[0].MidUnitPrice * payPercentage / 100
|
||||
}
|
||||
}
|
||||
skuBindInfo := &StoreSkuBindInfo{
|
||||
NameID: k,
|
||||
UnitPrice: midPrice,
|
||||
UnitPrice: price,
|
||||
IsFocus: 1,
|
||||
Skus: v,
|
||||
}
|
||||
retVal = []*StoreSkuBindInfo{skuBindInfo}
|
||||
skuBindInfos = append(skuBindInfos, skuBindInfo)
|
||||
}
|
||||
tUpdate := &tUpdateStoresSkus{
|
||||
StoreID: store.ID,
|
||||
SkuBindInfos: skuBindInfos,
|
||||
}
|
||||
retVal = []*tUpdateStoresSkus{tUpdate}
|
||||
return retVal, err
|
||||
}
|
||||
taskParallel := tasksch.NewParallelTask("根据skuID部分关注商品", tasksch.NewParallelConfig().SetIsContinueWhenError(isContinueWhenError), ctx, taskFunc, storeList)
|
||||
tasksch.HandleTask(taskParallel, task, true).Run()
|
||||
result1, _ := taskParallel.GetResult(0)
|
||||
for _, v := range result1 {
|
||||
skuBindInfos = append(skuBindInfos, v.(*StoreSkuBindInfo))
|
||||
}
|
||||
result1, _ = taskParallel.GetResult(0)
|
||||
case 2:
|
||||
UpdateStoresSkus(ctx, storeIDs, skuBindInfos, false, isAsync, isContinueWhenError)
|
||||
for _, v := range result1 {
|
||||
tUpdate := v.(*tUpdateStoresSkus)
|
||||
UpdateStoresSkus(ctx, []int{tUpdate.StoreID}, tUpdate.SkuBindInfos, false, isAsync, isContinueWhenError)
|
||||
}
|
||||
}
|
||||
return result, err
|
||||
}
|
||||
@@ -2909,3 +3004,136 @@ func FocusStoreSkusBySku(ctx *jxcontext.Context, skuIDs []int, isAsync, isContin
|
||||
}
|
||||
return hint, err
|
||||
}
|
||||
|
||||
func AutoFocusStoreSkusWithoutFocusForTopSkus(ctx *jxcontext.Context) (err error) {
|
||||
db := dao.GetDB()
|
||||
storeList, err := dao.GetStoreList(db, nil, nil, "")
|
||||
for _, v := range storeList {
|
||||
var (
|
||||
skuName []*model.SkuName
|
||||
skuNameMap = make(map[int]int)
|
||||
skuBindInfoList []*StoreSkuBindInfo
|
||||
)
|
||||
sql := `
|
||||
SELECT DISTINCT a.name_id id
|
||||
FROM sku a
|
||||
LEFT JOIN (SELECT DISTINCT b.name_id
|
||||
FROM store_sku_bind a
|
||||
JOIN sku b ON a.sku_id = b.id
|
||||
WHERE a.deleted_at = ?
|
||||
AND store_id = ?)b ON a.name_id = b.name_id
|
||||
WHERE a.status = ?
|
||||
AND a.deleted_at = ?
|
||||
AND b.name_id IS NULL
|
||||
`
|
||||
sqlParams := []interface{}{
|
||||
utils.DefaultTimeValue,
|
||||
v.ID,
|
||||
model.SkuStatusNormal,
|
||||
utils.DefaultTimeValue,
|
||||
}
|
||||
err = dao.GetRows(db, &skuName, sql, sqlParams...)
|
||||
for _, v := range skuName {
|
||||
skuNameMap[v.ID] = v.ID
|
||||
}
|
||||
skuNameAndPlaceList, err2 := GetTopSkusByCityCode(ctx, v.CityCode, v.ID)
|
||||
if err2 != nil {
|
||||
return err2
|
||||
}
|
||||
var payPercentage int
|
||||
if v.PayPercentage < 50 {
|
||||
payPercentage = 70
|
||||
} else {
|
||||
payPercentage = v.PayPercentage
|
||||
}
|
||||
if len(skuNameAndPlaceList) > 0 {
|
||||
for _, v := range skuNameAndPlaceList {
|
||||
if skuNameMap[v.ID] != 0 {
|
||||
priceReferList, err := dao.GetPriceReferSnapshotNoPage(db, []int{v.CityCode}, nil, []int{v.ID}, utils.Time2Date(time.Now().AddDate(0, 0, -1)))
|
||||
if err == nil && len(priceReferList) > 0 {
|
||||
storeSkuBindInfo := &StoreSkuBindInfo{
|
||||
NameID: v.ID,
|
||||
UnitPrice: priceReferList[0].MidUnitPrice * payPercentage / 100,
|
||||
IsFocus: 1,
|
||||
IsSale: 0,
|
||||
}
|
||||
skuBindInfoList = append(skuBindInfoList, storeSkuBindInfo)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
UpdateStoreSkus(ctx, v.ID, skuBindInfoList, true, true)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func AutoFocusStoreSkusWithoutFocus(ctx *jxcontext.Context, skuIDs []int, isSync bool) (err error) {
|
||||
var (
|
||||
nameMap = make(map[int]*StoreSkuBindInfo)
|
||||
)
|
||||
db := dao.GetDB()
|
||||
storeList, err := dao.GetStoreList(db, nil, nil, "")
|
||||
for _, v := range storeList {
|
||||
storeSkuList, _ := dao.GetStoreSkusAndSkuName(db, []int{v.ID}, skuIDs, nil)
|
||||
for _, vv := range storeSkuList {
|
||||
if nameMap[vv.ID] != nil {
|
||||
nameMap[vv.ID].Skus = append(nameMap[vv.ID].Skus, &StoreSkuBindSkuInfo{
|
||||
SkuID: vv.SkuID,
|
||||
})
|
||||
} else {
|
||||
skuBindInfo := &StoreSkuBindInfo{
|
||||
UnitPrice: vv.UnitPrice,
|
||||
NameID: vv.ID,
|
||||
StoreID: v.ID,
|
||||
Skus: []*StoreSkuBindSkuInfo{},
|
||||
}
|
||||
nameMap[vv.ID] = skuBindInfo
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, v := range nameMap {
|
||||
var skuBindInfoList []*StoreSkuBindInfo
|
||||
skuBindInfoResult := &StoreSkuBindInfo{
|
||||
NameID: v.NameID,
|
||||
UnitPrice: v.UnitPrice,
|
||||
IsFocus: 1,
|
||||
}
|
||||
var skuBindSkuList []*StoreSkuBindSkuInfo
|
||||
skuMap := make(map[int]int)
|
||||
skuList, _ := dao.GetSkus(db, nil, []int{v.NameID}, nil, nil)
|
||||
if len(v.Skus) != len(skuList) {
|
||||
for _, skus := range v.Skus {
|
||||
skuMap[skus.SkuID] = 1
|
||||
}
|
||||
for _, vv := range skuList {
|
||||
if skuMap[vv.ID] != 1 {
|
||||
continue
|
||||
}
|
||||
skuBindSkuList = append(skuBindSkuList, &StoreSkuBindSkuInfo{
|
||||
SkuID: vv.ID,
|
||||
IsSale: 0,
|
||||
})
|
||||
}
|
||||
}
|
||||
skuBindInfoList = append(skuBindInfoList, skuBindInfoResult)
|
||||
if isSync {
|
||||
UpdateStoreSkus(ctx, v.StoreID, skuBindInfoList, true, true)
|
||||
} else {
|
||||
updateStoresSkusWithoutSync(ctx, db, []int{v.StoreID}, skuBindInfoList, false)
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
func UpdateStoreSkuNamePrice(ctx *jxcontext.Context, storeID, nameID, unitPrice int, isAsync bool) (hint string, err error) {
|
||||
// db := dao.GetDB()
|
||||
// skuList, err := dao.GetSkus(db, nil, []int{nameID}, nil, nil)
|
||||
// if err != nil || len(skuList) == 0 {
|
||||
// return "", err
|
||||
// }
|
||||
// var skuIDs []int
|
||||
// for _, v := range skuList {
|
||||
// skuIDs = append(skuIDs, v.ID)
|
||||
// }
|
||||
// actStoreSkuList, err :=dao.GetEffectiveActStoreSkuInfo(db, 0, nil, model.ActSkuDirectDown, []int{storeID}, skuIDs, time.Now(),time.Now())
|
||||
return hint, err
|
||||
}
|
||||
|
||||
@@ -218,20 +218,16 @@ func (v *VendorSync) SyncReorderCategories(ctx *jxcontext.Context, db *dao.DaoDB
|
||||
// return "", err
|
||||
// }
|
||||
|
||||
func (v *VendorSync) SyncStore(ctx *jxcontext.Context, db *dao.DaoDB, vendorID, storeID int, isAsync bool, userName string) (hint string, err error) {
|
||||
globals.SugarLogger.Debugf("SyncStore, storeID:%d", storeID)
|
||||
var vendorIDs []int
|
||||
if vendorID != -1 {
|
||||
vendorIDs = []int{
|
||||
vendorID,
|
||||
}
|
||||
}
|
||||
hint, err = v.LoopStoresMap(ctx, db, fmt.Sprintf("同步门店信息:%d", storeID), isAsync, false, vendorIDs, []int{storeID}, func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (resultList interface{}, err error) {
|
||||
func (v *VendorSync) SyncStore2(ctx *jxcontext.Context, db *dao.DaoDB, vendorIDs, storeIDs []int, mustDirty, isAsync bool) (hint string, err error) {
|
||||
globals.SugarLogger.Debugf("SyncStore2, storeIDs:%d", storeIDs)
|
||||
userName := ctx.GetUserName()
|
||||
isManageIt := len(storeIDs) == 0 || len(storeIDs) > 5
|
||||
_, hint, err = v.LoopStoresMap2(ctx, db, fmt.Sprintf("同步门店信息:%v", storeIDs), isAsync, isManageIt, vendorIDs, storeIDs, mustDirty, func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (resultList interface{}, err error) {
|
||||
loopMapInfo := batchItemList[0].(*LoopStoreMapInfo)
|
||||
handler := v.GetStoreHandler(loopMapInfo.VendorID)
|
||||
if handler != nil {
|
||||
if len(loopMapInfo.StoreMapList) > 1 {
|
||||
loopStoreTask := tasksch.NewParallelTask(fmt.Sprintf("处理平台%s", model.VendorChineseNames[loopMapInfo.VendorID]), nil, ctx,
|
||||
loopStoreTask := tasksch.NewParallelTask(fmt.Sprintf("处理平台%s", model.VendorChineseNames[loopMapInfo.VendorID]), tasksch.NewParallelConfig().SetIsContinueWhenError(true), ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
var resultList []interface{}
|
||||
storeMap := batchItemList[0].(*model.StoreMap)
|
||||
@@ -265,6 +261,16 @@ func (v *VendorSync) SyncStore(ctx *jxcontext.Context, db *dao.DaoDB, vendorID,
|
||||
return hint, makeSyncError(err)
|
||||
}
|
||||
|
||||
func (v *VendorSync) SyncStore(ctx *jxcontext.Context, db *dao.DaoDB, vendorID, storeID int, isAsync bool, userName string) (hint string, err error) {
|
||||
var vendorIDs []int
|
||||
if vendorID != -1 {
|
||||
vendorIDs = []int{
|
||||
vendorID,
|
||||
}
|
||||
}
|
||||
return v.SyncStore2(ctx, db, vendorIDs, []int{storeID}, false, isAsync)
|
||||
}
|
||||
|
||||
func (v *VendorSync) SyncSku(ctx *jxcontext.Context, db *dao.DaoDB, nameID, skuID int, isAsync, isContinueWhenError bool, userName string) (hint string, err error) {
|
||||
var (
|
||||
nameIDs []int
|
||||
@@ -417,7 +423,7 @@ func (v *VendorSync) SyncStoresCategory(ctx *jxcontext.Context, db *dao.DaoDB, v
|
||||
func (v *VendorSync) SyncStoresSkus2(ctx *jxcontext.Context, db *dao.DaoDB, vendorIDs []int, storeIDs []int, syncDisabled bool, skuIDs, excludeSkuIDs []int, setSyncStatus int, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||
globals.SugarLogger.Debug("SyncStoresSkus2")
|
||||
isManageIt := len(storeIDs) != 1 || len(skuIDs) == 0 || len(skuIDs) > 8
|
||||
task, hint, err := v.LoopStoresMap2(ctx, db, fmt.Sprintf("同步门店商品信息:%v", storeIDs), isAsync, isManageIt, vendorIDs, storeIDs,
|
||||
task, hint, err := v.LoopStoresMap2(ctx, db, fmt.Sprintf("同步门店商品信息:%v", storeIDs), isAsync, isManageIt, vendorIDs, storeIDs, false,
|
||||
func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (interface{}, error) {
|
||||
loopMapInfo := batchItemList[0].(*LoopStoreMapInfo)
|
||||
if handler := v.GetStoreHandler(loopMapInfo.VendorID); handler != nil {
|
||||
@@ -594,9 +600,9 @@ func (v *VendorSync) AmendAndPruneStoreStuff(ctx *jxcontext.Context, vendorIDs [
|
||||
return hint, makeSyncError(err)
|
||||
}
|
||||
|
||||
func (v *VendorSync) LoopStoresMap2(ctx *jxcontext.Context, db *dao.DaoDB, taskName string, isAsync, isManageIt bool, vendorIDs []int, storeIDs []int, handler tasksch.WorkFunc, isContinueWhenError bool) (task tasksch.ITask, hint string, err error) {
|
||||
func (v *VendorSync) LoopStoresMap2(ctx *jxcontext.Context, db *dao.DaoDB, taskName string, isAsync, isManageIt bool, vendorIDs []int, storeIDs []int, mustDirty bool, handler tasksch.WorkFunc, isContinueWhenError bool) (task tasksch.ITask, hint string, err error) {
|
||||
var storeMapList []*model.StoreMap
|
||||
if storeMapList, err = dao.GetStoresMapList(db, vendorIDs, storeIDs, model.StoreStatusAll, model.StoreIsSyncYes, ""); err != nil {
|
||||
if storeMapList, err = dao.GetStoresMapList2(db, vendorIDs, storeIDs, model.StoreStatusAll, model.StoreIsSyncYes, "", mustDirty); err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
if len(storeMapList) == 0 {
|
||||
@@ -618,7 +624,6 @@ func (v *VendorSync) LoopStoresMap2(ctx *jxcontext.Context, db *dao.DaoDB, taskN
|
||||
if len(loopInfoList) == 1 {
|
||||
taskName = fmt.Sprintf("%s,处理平台%s", taskName, model.VendorChineseNames[loopInfoList[0].VendorID])
|
||||
}
|
||||
// globals.SugarLogger.Debugf("LoopStoresMap2 loopInfoList:%s", utils.Format4Output(loopInfoList, false))
|
||||
task = tasksch.NewParallelTask(taskName, tasksch.NewParallelConfig().SetIsContinueWhenError(true), ctx, handler, loopInfoList)
|
||||
task.SetFinishHook(func(task tasksch.ITask, ctx *jxcontext.Context) {
|
||||
err = WirteToExcelBySyncFailed(task, ctx)
|
||||
@@ -640,7 +645,7 @@ func (v *VendorSync) LoopStoresMap2(ctx *jxcontext.Context, db *dao.DaoDB, taskN
|
||||
}
|
||||
|
||||
func (v *VendorSync) LoopStoresMap(ctx *jxcontext.Context, db *dao.DaoDB, taskName string, isAsync, isManageIt bool, vendorIDs []int, storeIDs []int, handler tasksch.WorkFunc, isContinueWhenError bool) (hint string, err error) {
|
||||
_, hint, err = v.LoopStoresMap2(ctx, db, taskName, isAsync, isManageIt, vendorIDs, storeIDs, handler, isContinueWhenError)
|
||||
_, hint, err = v.LoopStoresMap2(ctx, db, taskName, isAsync, isManageIt, vendorIDs, storeIDs, false, handler, isContinueWhenError)
|
||||
return hint, err
|
||||
}
|
||||
|
||||
|
||||
@@ -379,23 +379,23 @@ func OnThingSync(ctx *jxcontext.Context, db *dao.DaoDB, thingMap *model.ThingMap
|
||||
}
|
||||
|
||||
func updateThingMapEntity(db *dao.DaoDB, thingMap *model.ThingMap) {
|
||||
if thingMap.VendorOrgCode == globals.JdOrgCode {
|
||||
if thingMap.ThingType == model.ThingTypeCategory {
|
||||
cat := &model.SkuCategory{
|
||||
JdID: utils.Str2Int64WithDefault(thingMap.VendorThingID, 0),
|
||||
JdSyncStatus: thingMap.SyncStatus,
|
||||
}
|
||||
cat.ID = int(thingMap.ThingID)
|
||||
dao.UpdateEntity(db, cat, "JdID", "JdSyncStatus")
|
||||
} else if thingMap.ThingType == model.ThingTypeSku {
|
||||
sku := &model.Sku{
|
||||
JdID: utils.Str2Int64WithDefault(thingMap.VendorThingID, 0),
|
||||
JdSyncStatus: thingMap.SyncStatus,
|
||||
}
|
||||
sku.ID = int(thingMap.ThingID)
|
||||
dao.UpdateEntity(db, sku, "JdID", "JdSyncStatus")
|
||||
}
|
||||
}
|
||||
// if thingMap.VendorOrgCode == globals.JdOrgCode {
|
||||
// if thingMap.ThingType == model.ThingTypeCategory {
|
||||
// cat := &model.SkuCategory{
|
||||
// JdID: utils.Str2Int64WithDefault(thingMap.VendorThingID, 0),
|
||||
// JdSyncStatus: thingMap.SyncStatus,
|
||||
// }
|
||||
// cat.ID = int(thingMap.ThingID)
|
||||
// dao.UpdateEntity(db, cat, "JdID", "JdSyncStatus")
|
||||
// } else if thingMap.ThingType == model.ThingTypeSku {
|
||||
// sku := &model.Sku{
|
||||
// JdID: utils.Str2Int64WithDefault(thingMap.VendorThingID, 0),
|
||||
// JdSyncStatus: thingMap.SyncStatus,
|
||||
// }
|
||||
// sku.ID = int(thingMap.ThingID)
|
||||
// dao.UpdateEntity(db, sku, "JdID", "JdSyncStatus")
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
func amendAndPruneVendorStuff(ctx *jxcontext.Context, parentTask tasksch.ITask, vendorID int, vendorOrgCode string, isAsync, isContinueWhenError bool, opType int, isForceUpdate bool) (hint string, err error) {
|
||||
|
||||
@@ -225,10 +225,23 @@ func calVendorPrice4StoreSku(inSku *dao.StoreSkuSyncInfo, pricePercentagePack mo
|
||||
return inSku
|
||||
}
|
||||
|
||||
func getSkuBoxFee(vendorID int) (boxFee int64) {
|
||||
if vendorID == model.VendorIDMTWM {
|
||||
boxFee, _ = dao.GetSysConfigAsInt64(dao.GetDB(), model.ConfigSysMtwmSkuBoxFee)
|
||||
}
|
||||
return boxFee
|
||||
}
|
||||
|
||||
func formalizeStoreSkuList(inSkuList []*dao.StoreSkuSyncInfo) []*dao.StoreSkuSyncInfo {
|
||||
for _, skuItem := range inSkuList {
|
||||
skuItem.MergedStatus = jxutils.MergeSkuStatus(skuItem.Status, skuItem.StoreSkuStatus)
|
||||
skuItem.SkuName = jxutils.ComposeSkuNameSync(skuItem.Prefix, skuItem.Name, skuItem.Comment, skuItem.Unit, skuItem.SpecQuality, skuItem.SpecUnit, 0, skuItem.ExPrefix, skuItem.ExPrefixBegin, skuItem.ExPrefixEnd)
|
||||
if len(inSkuList) > 0 {
|
||||
boxFee := getSkuBoxFee(inSkuList[0].VendorID)
|
||||
for _, skuItem := range inSkuList {
|
||||
if skuItem.VendorPrice > skuItem.BoxFee {
|
||||
skuItem.BoxFee = boxFee
|
||||
}
|
||||
skuItem.MergedStatus = jxutils.MergeSkuStatus(skuItem.Status, skuItem.StoreSkuStatus)
|
||||
skuItem.SkuName = jxutils.ComposeSkuNameSync(skuItem.Prefix, skuItem.Name, skuItem.Comment, skuItem.Unit, skuItem.SpecQuality, skuItem.SpecUnit, 0, skuItem.ExPrefix, skuItem.ExPrefixBegin, skuItem.ExPrefixEnd)
|
||||
}
|
||||
}
|
||||
return inSkuList
|
||||
}
|
||||
@@ -244,7 +257,7 @@ func sku2Update(vendorID int, sku *dao.StoreSkuSyncInfo, syncStatus int8) (item
|
||||
kvs[dao.GetVendorThingIDStructField(model.VendorNames[vendorID])] = utils.Str2Int64WithDefault(sku.VendorSkuID, 0)
|
||||
} else if model.IsSyncStatusDelete(syncStatus) {
|
||||
sku.SkuSyncStatus = 0
|
||||
if utils.IsTimeZero(sku.BindDeletedAt) && (sku.ID == 0 || sku.NameID == 0) {
|
||||
if utils.IsTimeZero(sku.BindDeletedAt) && (sku.NameID == 0) {
|
||||
kvs[model.FieldDeletedAt] = time.Now()
|
||||
}
|
||||
if !dao.IsVendorThingIDEmpty(sku.VendorSkuID) && !partner.IsMultiStore(vendorID) {
|
||||
|
||||
@@ -146,26 +146,48 @@ func init() {
|
||||
auth2.Init(userProvider)
|
||||
}
|
||||
|
||||
func RegisterUserWithMobile(ctx *jxcontext.Context, user *model.User, mobileVerifyCode string, inAuthInfo *auth2.AuthInfo) (outAuthInfo *auth2.AuthInfo, err error) {
|
||||
func RegisterUserWithMobile(ctx *jxcontext.Context, user *model.User, mobileVerifyCode string, inAuthInfo, manTokenInfo *auth2.AuthInfo) (outAuthInfo *auth2.AuthInfo, err error) {
|
||||
var mobileAuth *auth2.AuthInfo
|
||||
fakeMobile := false
|
||||
user.Type = model.UserTypeConsumer
|
||||
createName := ctx.GetRealRemoteIP()
|
||||
authType := auth2.AuthTypeMobile
|
||||
if manTokenInfo != nil && mobileVerifyCode == "" {
|
||||
manUser, err2 := dao.GetUserByID(dao.GetDB(), "user_id", manTokenInfo.GetID())
|
||||
if err = err2; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if manUser.Type&(model.UserTypeOperator|model.UserTypeBoss) == 0 {
|
||||
return nil, fmt.Errorf("管理员才能添加商户")
|
||||
}
|
||||
if utils.Pointer2String(user.Mobile) == "" {
|
||||
return nil, fmt.Errorf("管理员添加必须指定用户手机号")
|
||||
}
|
||||
mobileVerifyCode = auth2.InternalAuthSecret
|
||||
fakeMobile = true
|
||||
user.Type |= model.UserTypeStoreBoss
|
||||
createName = manTokenInfo.GetName()
|
||||
}
|
||||
|
||||
if mobileVerifyCode != "" {
|
||||
mobileAuth, err = auth2.Login(ctx.Context, auth2.AuthTypeMobile, user.GetMobile(), auth2.UserIDMobile, mobileVerifyCode)
|
||||
if fakeMobile {
|
||||
mobileAuth, err = auth2.LoginInternal(ctx.Context, auth2.AuthTypeMobile, user.GetMobile(), auth2.UserIDMobile, mobileVerifyCode)
|
||||
} else {
|
||||
mobileAuth, err = auth2.Login(ctx.Context, auth2.AuthTypeMobile, user.GetMobile(), auth2.UserIDMobile, mobileVerifyCode)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if mobileAuth != nil && !mobileAuth.IsUserEmpty() {
|
||||
return nil, jsonerr.New(mobileAuth, model.ErrCodeJsonUserAlreadyExist)
|
||||
}
|
||||
} else {
|
||||
if inAuthInfo == nil {
|
||||
return nil, fmt.Errorf("短信验证码与其它认证方式至少要指定一种")
|
||||
}
|
||||
} else if inAuthInfo != nil {
|
||||
user.Mobile = nil
|
||||
} else {
|
||||
return nil, fmt.Errorf("短信验证码与其它认证方式至少要指定一种")
|
||||
}
|
||||
createName := ctx.GetRealRemoteIP()
|
||||
authType := auth2.AuthTypeMobile
|
||||
|
||||
if inAuthInfo != nil {
|
||||
user.Type = model.UserTypeConsumer
|
||||
if inAuthInfo.AuthBindInfo.Type == dingding.AuthTypeStaff {
|
||||
user.Type |= model.UserTypeOperator
|
||||
} else if user.Mobile != nil {
|
||||
|
||||
Reference in New Issue
Block a user