方法移动到check文件
This commit is contained in:
@@ -96,6 +96,7 @@ type tStoreSkuBindAndSpec struct {
|
||||
ExdSkuID string `orm:"column(exd_sku_id)"`
|
||||
StoreName string
|
||||
ChangePriceType int8 `json:"changePriceType"` // 修改价格类型,即是否需要审核
|
||||
NameID int `orm:"column(name_id)" json:"nameID"`
|
||||
}
|
||||
|
||||
type SkuSaleInfo struct {
|
||||
@@ -128,6 +129,7 @@ type tGetStoresSkusInfo struct {
|
||||
dao.StoreSkuExt
|
||||
RealMidUnitPrice int `json:"realMidUnitPrice"` //真实的该商品的全国中位价
|
||||
YbSkuName string
|
||||
AuditUnitPrice int
|
||||
}
|
||||
|
||||
type SheetParam struct {
|
||||
@@ -312,11 +314,13 @@ func getGetStoresSkusBaseSQL(db *dao.DaoDB, storeIDs, skuIDs []int, isFocus bool
|
||||
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 = ? AND t6.sku_id = t2.id AND t6.snapshot_at = ?
|
||||
LEFT JOIN store_sku_audit t7 ON t7.store_id = t3.id AND t7.name_id = t1.id AND t7.status = ? AND t7.deleted_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,
|
||||
0, utils.Time2Date(time.Now().AddDate(0, 0, -1)),
|
||||
model.StoreAuditStatusOnline, utils.DefaultTimeValue,
|
||||
utils.DefaultTimeValue,
|
||||
utils.Bool2Int(isFocus),
|
||||
})
|
||||
@@ -544,7 +548,8 @@ func GetStoresSkusNew(ctx *jxcontext.Context, storeIDs, skuIDs []int, isFocus, i
|
||||
t4.jd_price, t4.ebai_price, t4.mtwm_price, t4.jx_price, t4.yb_price, t4.jds_price,
|
||||
t4.jd_lock_time, t4.ebai_lock_time, t4.mtwm_lock_time, t4.jx_lock_time, t4.yb_lock_time, t4.jds_lock_time,
|
||||
t4.status_sale_begin, t4.status_sale_end,
|
||||
t6.mid_unit_price real_mid_unit_price
|
||||
t6.mid_unit_price real_mid_unit_price,
|
||||
t7.unit_price audit_unit_price
|
||||
` + sql
|
||||
if isHighPrice || priceType != 0 {
|
||||
sql += " , t4.unit_price DESC LIMIT 99"
|
||||
@@ -573,6 +578,7 @@ func GetStoresSkusNew(ctx *jxcontext.Context, storeIDs, skuIDs []int, isFocus, i
|
||||
PayPercentage: v.PayPercentage,
|
||||
RealMidUnitPrice: v.RealMidUnitPrice,
|
||||
YbSkuName: v.YbSkuName,
|
||||
AuditUnitPrice: v.AuditUnitPrice,
|
||||
}
|
||||
if !isBySku {
|
||||
storeNameMap[index] = storeName
|
||||
@@ -702,7 +708,7 @@ func updateSaleInfo4StoreSkuName(ctx *jxcontext.Context, db *dao.DaoDB, storeIDs
|
||||
}
|
||||
|
||||
func getValidStoreVendorMap(db *dao.DaoDB, storeIDs []int) (realVendorMap map[int]int, err error) {
|
||||
storeMapList, err := dao.GetStoresMapList(db, nil, storeIDs, nil, model.StoreStatusAll, model.StoreIsSyncYes, "")
|
||||
storeMapList, err := dao.GetStoresMapList(db, nil, storeIDs, nil, model.StoreStatusAll, model.StoreIsSyncYes, "", "")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -832,29 +838,43 @@ func UpdateStoreSku(ctx *jxcontext.Context, causeFlag, storeID int, skuBindInfo
|
||||
}
|
||||
|
||||
func UpdateStoreSkus(ctx *jxcontext.Context, causeFlag, storeID int, skuBindInfos []*StoreSkuBindInfo, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||
return UpdateStoresSkus(ctx, causeFlag, []int{storeID}, skuBindInfos, false, isAsync, isContinueWhenError)
|
||||
return UpdateStoresSkus(ctx, causeFlag, []int{storeID}, skuBindInfos, false, false, isAsync, isContinueWhenError)
|
||||
}
|
||||
|
||||
func UpdateStoresSkus(ctx *jxcontext.Context, causeFlag int, storeIDs []int, skuBindInfos []*StoreSkuBindInfo, isScale, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||
func UpdateStoresSkus(ctx *jxcontext.Context, causeFlag int, storeIDs []int, skuBindInfos []*StoreSkuBindInfo, isScale, isRefreshHigh, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||
globals.SugarLogger.Debugf("UpdateStoresSkus:%s, storeIDs:%v, skuBindInfos:%s", ctx.GetTrackInfo(), storeIDs, utils.Format4Output(skuBindInfos, true))
|
||||
|
||||
var num int64
|
||||
db := dao.GetDB()
|
||||
skuIDs, err := updateStoresSkusWithoutSync(ctx, db, storeIDs, skuBindInfos, isScale)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
isAsync = asyncStoreSkuOpFilter(ctx, isAsync)
|
||||
num = int64(len(skuIDs))
|
||||
if num > 0 {
|
||||
hint, err = CurVendorSync.SyncStoresSkus(ctx, nil, causeFlag, db, nil, storeIDs, skuIDs, false, isAsync, isContinueWhenError)
|
||||
}
|
||||
if num == 0 || !isAsync || hint == "" {
|
||||
hint = utils.Int64ToStr(num)
|
||||
flag, err := doStoreSkuAudit(ctx, storeIDs, skuBindInfos)
|
||||
if !flag {
|
||||
var num int64
|
||||
db := dao.GetDB()
|
||||
skuIDs, err := updateStoresSkusWithoutSync(ctx, db, storeIDs, skuBindInfos, isScale, isRefreshHigh)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
isAsync = asyncStoreSkuOpFilter(ctx, isAsync)
|
||||
num = int64(len(skuIDs))
|
||||
if num > 0 {
|
||||
hint, err = CurVendorSync.SyncStoresSkus(ctx, nil, causeFlag, db, nil, storeIDs, skuIDs, false, isAsync, isContinueWhenError)
|
||||
}
|
||||
if num == 0 || !isAsync || hint == "" {
|
||||
hint = utils.Int64ToStr(num)
|
||||
}
|
||||
}
|
||||
return hint, err
|
||||
}
|
||||
|
||||
func UpdateStoresSkusWithoutSync(ctx *jxcontext.Context, storeIDs []int, skuBindInfos []*StoreSkuBindInfo, isRefreshHigh bool) (err error) {
|
||||
db := dao.GetDB()
|
||||
if len(storeIDs) == 0 {
|
||||
stores, _ := dao.GetStoreList(db, nil, nil, nil, nil, "")
|
||||
for _, v := range stores {
|
||||
storeIDs = append(storeIDs, v.ID)
|
||||
}
|
||||
}
|
||||
updateStoresSkusWithoutSync(ctx, db, storeIDs, skuBindInfos, false, isRefreshHigh)
|
||||
return err
|
||||
}
|
||||
|
||||
func UpdateStoresSkusByBind(ctx *jxcontext.Context, parentTask tasksch.ITask, skuBindInfos []*StoreSkuBindInfo, isAsync, isContinueWhenError, isFos bool) (hint string, err error) {
|
||||
// if len(skuBindInfos) > maxStoreNameBind {
|
||||
// return "", fmt.Errorf("门店商品信息大于%d", maxStoreNameBind)
|
||||
@@ -880,7 +900,7 @@ func UpdateStoresSkusByBind(ctx *jxcontext.Context, parentTask tasksch.ITask, sk
|
||||
// }
|
||||
// }()
|
||||
for _, storeID := range storeIDs {
|
||||
skuIDs, err2 := updateStoresSkusWithoutSync(ctx, db, []int{storeID}, skuBindInfosMap[storeID], false)
|
||||
skuIDs, err2 := updateStoresSkusWithoutSync(ctx, db, []int{storeID}, skuBindInfosMap[storeID], false, false)
|
||||
if err = err2; err != nil {
|
||||
// dao.Rollback(db)
|
||||
return "", err
|
||||
@@ -960,7 +980,7 @@ func uniqueStoreNameBind(skuBindInfos []*StoreSkuBindInfo) (outSkuBindInfos []*S
|
||||
return outSkuBindInfos
|
||||
}
|
||||
|
||||
func updateStoresSkusWithoutSync(ctx *jxcontext.Context, db *dao.DaoDB, storeIDs []int, skuBindInfos []*StoreSkuBindInfo, isScale bool) (needSyncSkus []int, err error) {
|
||||
func updateStoresSkusWithoutSync(ctx *jxcontext.Context, db *dao.DaoDB, storeIDs []int, skuBindInfos []*StoreSkuBindInfo, isScale, isRefreshHigh bool) (needSyncSkus []int, err error) {
|
||||
// if len(storeIDs)*len(skuBindInfos) > maxStoreNameBind2 {
|
||||
// return nil, fmt.Errorf("门店商品信息大于%d", maxStoreNameBind2)
|
||||
// }
|
||||
@@ -976,9 +996,6 @@ func updateStoresSkusWithoutSync(ctx *jxcontext.Context, db *dao.DaoDB, storeIDs
|
||||
// if err = checkStoresSkusSaleCity(ctx, db, storeIDs, skuBindInfos); err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
// if storeIDs, skuBindInfos, err = filterStorePriceChange(ctx, storeIDs, skuBindInfos); err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
// globals.SugarLogger.Debugf("updateStoresSkusWithoutSync2, storeIDs:%v, skuBindInfos:%s", storeIDs, utils.Format4Output(skuBindInfos, false))
|
||||
isUserCanDirectChangePrice := true
|
||||
if user := ctx.GetFullUser(); user != nil {
|
||||
@@ -1018,7 +1035,7 @@ func updateStoresSkusWithoutSync(ctx *jxcontext.Context, db *dao.DaoDB, storeIDs
|
||||
sql += " IF(t5.unit_price > 0, t5.unit_price, t3.price) sku_name_price,"
|
||||
}
|
||||
sql += `
|
||||
t3.unit sku_name_unit, t3.name, t3.status sku_name_status,
|
||||
t3.unit sku_name_unit, t3.name, t3.status sku_name_status, t3.id name_id,
|
||||
ts.change_price_type, ts.name store_name
|
||||
FROM sku t1
|
||||
JOIN store ts ON ts.id = ? AND ts.deleted_at = ?
|
||||
@@ -1139,6 +1156,15 @@ func updateStoresSkusWithoutSync(ctx *jxcontext.Context, db *dao.DaoDB, storeIDs
|
||||
dao.Rollback(db)
|
||||
return nil, err
|
||||
}
|
||||
//删除待审核商品信息
|
||||
storeAudits, err := dao.GetStoreSkuAuditLight(db, []int{storeID}, []int{v.NameID}, model.StoreAuditStatusOnline)
|
||||
if len(storeAudits) > 0 {
|
||||
storeAudits[0].DeletedAt = time.Now()
|
||||
if _, err = dao.UpdateEntity(db, storeAudits[0], "DeletedAt"); err != nil {
|
||||
dao.Rollback(db)
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 用了SELECT FOR UPDATE后,只更新修改字段是没有必要的,暂时保留
|
||||
updateFieldMap := make(map[string]interface{})
|
||||
@@ -1168,11 +1194,21 @@ func updateStoresSkusWithoutSync(ctx *jxcontext.Context, db *dao.DaoDB, storeIDs
|
||||
setStoreSkuBindStatus(skuBind, model.SyncFlagPriceMask)
|
||||
updateFieldMap["Price"] = 1
|
||||
}
|
||||
skuBind.UnitPrice = unitPrice
|
||||
skuBind.Price = price
|
||||
skuBind.JxPrice = jxPrice
|
||||
updateFieldMap["UnitPrice"] = 1
|
||||
updateFieldMap["JxPrice"] = 1
|
||||
if isRefreshHigh {
|
||||
if beforeMsg.UnitPrice > skuBindInfo.UnitPrice {
|
||||
skuBind.UnitPrice = unitPrice
|
||||
skuBind.Price = price
|
||||
skuBind.JxPrice = jxPrice
|
||||
updateFieldMap["UnitPrice"] = 1
|
||||
updateFieldMap["JxPrice"] = 1
|
||||
}
|
||||
} else {
|
||||
skuBind.UnitPrice = unitPrice
|
||||
skuBind.Price = price
|
||||
skuBind.JxPrice = jxPrice
|
||||
updateFieldMap["UnitPrice"] = 1
|
||||
updateFieldMap["JxPrice"] = 1
|
||||
}
|
||||
}
|
||||
}
|
||||
if skuBindInfo.StatusSaleBegin != 0 && skuBindInfo.StatusSaleEnd != 0 {
|
||||
@@ -1851,7 +1887,7 @@ func AcceptStoreOpRequests(ctx *jxcontext.Context, reqIDs []int) (err error) {
|
||||
}
|
||||
}
|
||||
if err2 == nil {
|
||||
_, err2 := UpdateStoresSkus(ctx, 0, []int{op.StoreID}, []*StoreSkuBindInfo{skuBindInfo}, false, false, false)
|
||||
_, err2 := UpdateStoresSkus(ctx, 0, []int{op.StoreID}, []*StoreSkuBindInfo{skuBindInfo}, false, false, false, false)
|
||||
isLocalSucess := true
|
||||
if err2 != nil {
|
||||
subErrors[reqID] = err2
|
||||
@@ -2067,7 +2103,7 @@ func RefreshStoresSkuByVendor(ctx *jxcontext.Context, storeIDs []int, vendorID i
|
||||
return "", fmt.Errorf("此功能当前只支持京东到家平台")
|
||||
}
|
||||
db := dao.GetDB()
|
||||
storeMapList, err := dao.GetStoresMapList(db, []int{vendorID}, storeIDs, nil, model.StoreStatusAll, model.StoreIsSyncAll, "")
|
||||
storeMapList, err := dao.GetStoresMapList(db, []int{vendorID}, storeIDs, nil, model.StoreStatusAll, model.StoreIsSyncAll, "", "")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -2570,7 +2606,7 @@ func RefershStoreSkusMidPrice(ctx *jxcontext.Context, storeIDs []int, isCountry
|
||||
}
|
||||
}
|
||||
}
|
||||
updateStoresSkusWithoutSync(ctx, db, []int{v}, skuBindInfos, false)
|
||||
updateStoresSkusWithoutSync(ctx, db, []int{v}, skuBindInfos, false, false)
|
||||
}
|
||||
if err == nil {
|
||||
CreateStorePriceScore(ctx)
|
||||
@@ -2712,7 +2748,7 @@ func RefreshJxPriceByExcelBin(ctx *jxcontext.Context, storeIDs []int, reader io.
|
||||
skuBindInfoList = append(skuBindInfoList, v.(*StoreSkuBindInfo))
|
||||
}
|
||||
if isErr {
|
||||
UpdateStoresSkus(ctx, 0, storeIDs, skuBindInfoList, false, isAsync, isContinueWhenError)
|
||||
UpdateStoresSkus(ctx, 0, storeIDs, skuBindInfoList, false, false, isAsync, isContinueWhenError)
|
||||
}
|
||||
case 3:
|
||||
//写Excel
|
||||
@@ -3372,7 +3408,7 @@ func AutoFocusStoreSkusWithoutFocus(ctx *jxcontext.Context, skuIDs []int, isSync
|
||||
if isSync {
|
||||
UpdateStoreSkus(ctx, 0, v.StoreID, skuBindInfoList, true, true)
|
||||
} else {
|
||||
updateStoresSkusWithoutSync(ctx, db, []int{v.StoreID}, skuBindInfoList, false)
|
||||
updateStoresSkusWithoutSync(ctx, db, []int{v.StoreID}, skuBindInfoList, false, false)
|
||||
}
|
||||
}
|
||||
return err
|
||||
@@ -3479,7 +3515,7 @@ func SendSeckillSkusCountMsg(ctx *jxcontext.Context, vendorIDs []int, isAsync, i
|
||||
ddMsgresult []interface{}
|
||||
)
|
||||
db := dao.GetDB()
|
||||
storeList, err := dao.GetStoresMapList(db, vendorIDs, nil, []int{model.StoreStatusClosed, model.StoreStatusHaveRest, model.StoreStatusOpened}, model.StoreStatusOpened, model.StoreIsSyncAll, "")
|
||||
storeList, err := dao.GetStoresMapList(db, vendorIDs, nil, []int{model.StoreStatusClosed, model.StoreStatusHaveRest, model.StoreStatusOpened}, model.StoreStatusOpened, model.StoreIsSyncAll, "", "")
|
||||
taskSeqFunc := func(task *tasksch.SeqTask, step int, params ...interface{}) (result interface{}, err error) {
|
||||
switch step {
|
||||
case 0:
|
||||
@@ -4076,7 +4112,7 @@ func RefreshMatterStock(ctx *jxcontext.Context, skuID int) (err error) {
|
||||
}
|
||||
}
|
||||
//物料店666666
|
||||
updateStoresSkusWithoutSync(ctx, db, []int{666666}, skuBindInfos, false)
|
||||
updateStoresSkusWithoutSync(ctx, db, []int{666666}, skuBindInfos, false, false)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -4424,7 +4460,7 @@ func focusC4Matters(ctx *jxcontext.Context, db *dao.DaoDB, v *model.Sku) (err er
|
||||
}
|
||||
skuBindInfos = append(skuBindInfos, skuBindInfo)
|
||||
}
|
||||
updateStoresSkusWithoutSync(ctx, db, []int{model.MatterStoreID}, skuBindInfos, false)
|
||||
updateStoresSkusWithoutSync(ctx, db, []int{model.MatterStoreID}, skuBindInfos, false, false)
|
||||
}
|
||||
return err
|
||||
}
|
||||
@@ -4443,24 +4479,190 @@ func RefreshJdsSkusStatus(ctx *jxcontext.Context) (err error) {
|
||||
return err
|
||||
}
|
||||
|
||||
func GetStoreSkuAudit(ctx *jxcontext.Context, storeIDs, nameIDs, skuIDs []int, status int, name, remark string, applyTimeStart, applyTimeEnd, auditTimeStart, auditTimeEnd time.Time, pageSize, offset int) (pagedInfo *model.PagedInfo, err error) {
|
||||
pagedInfo, err = dao.GetStoreSkuAudit(dao.GetDB(), storeIDs, nameIDs, skuIDs, status, name, remark, applyTimeStart, applyTimeEnd, auditTimeStart, auditTimeEnd, pageSize, offset)
|
||||
func GetStoreSkuAudit(ctx *jxcontext.Context, storeIDs, nameIDs, skuIDs, statuss, types []int, name, remark, keyword, cityName, marketManPhone, applyTimeStart, applyTimeEnd, auditTimeStart, auditTimeEnd string, pageSize, offset int) (pagedInfo *model.PagedInfo, err error) {
|
||||
var (
|
||||
applyTimeStartp, applyTimeEndp, auditTimeStartp, auditTimeEndp time.Time
|
||||
)
|
||||
if applyTimeStart != "" {
|
||||
applyTimeStartp = utils.Str2Time(applyTimeStart)
|
||||
}
|
||||
if applyTimeEnd != "" {
|
||||
applyTimeEndp = utils.Str2Time(applyTimeEnd)
|
||||
}
|
||||
if auditTimeStart != "" {
|
||||
auditTimeStartp = utils.Str2Time(auditTimeStart)
|
||||
}
|
||||
if auditTimeEnd != "" {
|
||||
auditTimeEndp = utils.Str2Time(auditTimeEnd)
|
||||
}
|
||||
pagedInfo, err = dao.GetStoreSkuAudit(dao.GetDB(), storeIDs, nameIDs, skuIDs, statuss, types, name, remark, keyword, marketManPhone, cityName, applyTimeStartp, applyTimeEndp, auditTimeStartp, auditTimeEndp, pageSize, offset)
|
||||
return pagedInfo, err
|
||||
}
|
||||
|
||||
func SetJxPrice(jxSkuInfoDataMulti *dao.StoreSkuNamesInfo,storeId int) (err error){
|
||||
func doStoreSkuAudit(ctx *jxcontext.Context, storeIDs []int, skuBindInfos []*StoreSkuBindInfo) (isAudit bool, err error) {
|
||||
globals.SugarLogger.Debugf("doStoreSkuAudit storeIDs: %v", storeIDs)
|
||||
time.Sleep(time.Second / 5)
|
||||
db := dao.GetDB()
|
||||
storeDetail, err := dao.GetStoreDetail(dao.GetDB(), storeId, model.VendorIDJX)
|
||||
if err != nil {
|
||||
dao.Rollback(db)
|
||||
return err
|
||||
}
|
||||
/*重新计算京西价格*/
|
||||
for _,values := range jxSkuInfoDataMulti.SkuNames{
|
||||
for _,value := range values.Skus{
|
||||
value.JxPrice = jxutils.CaculatePriceByPricePack(storeDetail.PricePercentagePackObj, int(storeDetail.PricePercentage), value.JxPrice)
|
||||
for _, storeID := range storeIDs {
|
||||
for _, skuBindInfo := range skuBindInfos {
|
||||
globals.SugarLogger.Debugf("doStoreSkuAudit storeID: %v , nameID: %v", storeID, skuBindInfo.NameID)
|
||||
storeAudits, err := dao.GetStoreSkuAuditLight(db, []int{storeID}, []int{skuBindInfo.NameID}, model.StoreAuditStatusOnline)
|
||||
//取消关注,可售排除
|
||||
if skuBindInfo.IsFocus == -1 || skuBindInfo.IsSale != 0 || skuBindInfo.UnitPrice == 0 {
|
||||
globals.SugarLogger.Debugf("doStoreSkuAudit return1 storeID : %v nameID: %v", storeID, skuBindInfo.NameID)
|
||||
return false, err
|
||||
}
|
||||
//运营排除
|
||||
// if (ctx.GetFullUser().Type & model.UserTypeOperator) != 0 {
|
||||
// if len(storeAudits) > 0 {
|
||||
// storeAudits[0].DeletedAt = time.Now()
|
||||
// dao.UpdateEntity(db, storeAudits[0], "DeletedAt")
|
||||
// }
|
||||
// globals.SugarLogger.Debugf("doStoreSkuAudit return2 storeID : %v nameID: %v", storeID, skuBindInfo.NameID)
|
||||
// return false, err
|
||||
// }
|
||||
if ctx.GetLoginType() != weixin.AuthTypeMP && ctx.GetLoginType() != weixin.AuthTypeMini {
|
||||
if len(storeAudits) > 0 {
|
||||
storeAudits[0].DeletedAt = time.Now()
|
||||
dao.UpdateEntity(db, storeAudits[0], "DeletedAt")
|
||||
if globals.IsProductEnv() {
|
||||
skuAndNames, err := dao.GetSkus(db, nil, []int{skuBindInfo.NameID}, nil, nil, nil)
|
||||
if len(skuAndNames) > 0 && err == nil {
|
||||
weixinmsg.NotifyStoreOpRequestStatus(true, storeID, skuBindInfo.NameID, jxutils.ComposeSpuName(skuAndNames[0].Prefix, skuAndNames[0].Name, 0), storeAudits[0].OriginUnitPrice, skuBindInfo.UnitPrice, "")
|
||||
}
|
||||
}
|
||||
}
|
||||
globals.SugarLogger.Debugf("doStoreSkuAudit return3 storeID : %v nameID: %v", storeID, skuBindInfo.NameID)
|
||||
return false, err
|
||||
}
|
||||
storeSkuAudit := &model.StoreSkuAudit{
|
||||
StoreID: storeID,
|
||||
NameID: skuBindInfo.NameID,
|
||||
Status: model.StoreAuditStatusOnline,
|
||||
UnitPrice: skuBindInfo.UnitPrice,
|
||||
}
|
||||
//如果是关注改价
|
||||
if skuBindInfo.IsFocus == 1 {
|
||||
if len(storeAudits) > 0 {
|
||||
storeAudits[0].DeletedAt = time.Now()
|
||||
dao.UpdateEntity(db, storeAudits[0], "DeletedAt")
|
||||
}
|
||||
storeSkuAudit.Type = model.StoreSkuAuditTypeFocus
|
||||
} else {
|
||||
storeSkus, err := dao.GetStoreSkusByNameIDs(db, []int{storeID}, skuBindInfo.NameID)
|
||||
if len(storeSkus) > 0 {
|
||||
//如果改的价比原价低排除
|
||||
if skuBindInfo.UnitPrice <= int(storeSkus[0].UnitPrice) {
|
||||
if len(storeAudits) > 0 {
|
||||
storeAudits[0].DeletedAt = time.Now()
|
||||
dao.UpdateEntity(db, storeAudits[0], "DeletedAt")
|
||||
}
|
||||
globals.SugarLogger.Debugf("doStoreSkuAudit return4 storeID : %v nameID: %v", storeID, skuBindInfo.NameID)
|
||||
return false, err
|
||||
} else {
|
||||
if len(storeAudits) > 0 {
|
||||
storeAudits[0].DeletedAt = time.Now()
|
||||
dao.UpdateEntity(db, storeAudits[0], "DeletedAt")
|
||||
}
|
||||
globals.SugarLogger.Debugf("doStoreSkuAudit cover storeID : %v nameID: %v", storeID, skuBindInfo.NameID)
|
||||
}
|
||||
} else {
|
||||
return false, fmt.Errorf("未查询到该门店商品价,storeID: %v, nameID: %V", storeID, skuBindInfo.NameID)
|
||||
}
|
||||
storeSkuAudit.Type = model.StoreSkuAuditTypePrice
|
||||
storeSkuAudit.OriginUnitPrice = int(storeSkus[0].UnitPrice)
|
||||
}
|
||||
dao.WrapAddIDCULDEntity(storeSkuAudit, ctx.GetUserName())
|
||||
err = dao.CreateEntity(db, storeSkuAudit)
|
||||
}
|
||||
}
|
||||
/*重新计算京西价格*/
|
||||
return nil
|
||||
}
|
||||
return true, err
|
||||
}
|
||||
|
||||
func StoreSkuPriceAudit(ctx *jxcontext.Context, storeSkuAudits []*model.StoreSkuAudit, status int, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||||
db := dao.GetDB()
|
||||
if status == model.StoreAuditStatusOnline {
|
||||
return "", fmt.Errorf("审核标志不正确!")
|
||||
}
|
||||
task := tasksch.NewParallelTask("StoreSkuPriceAudit", tasksch.NewParallelConfig().SetParallelCount(1).SetIsContinueWhenError(isContinueWhenError), ctx,
|
||||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||||
storeAudit := batchItemList[0].(*model.StoreSkuAudit)
|
||||
storeAudits, err := dao.GetStoreSkuAuditLight(db, []int{storeAudit.StoreID}, []int{storeAudit.NameID}, model.StoreAuditStatusOnline)
|
||||
if len(storeAudits) == 0 || err != nil {
|
||||
return retVal, fmt.Errorf("未查询到该门店该商品的待审核信息!storeID: %v, nameID: %v", storeAudit.StoreID, storeAudit.NameID)
|
||||
}
|
||||
if len(storeAudits) > 1 {
|
||||
return retVal, fmt.Errorf("查询到该门店该商品的待审核信息大于1条!storeID: %v, nameID: %v", storeAudit.StoreID, storeAudit.NameID)
|
||||
}
|
||||
flag := false
|
||||
//审核通过
|
||||
if status == model.StoreAuditStatusCreated {
|
||||
flag = true
|
||||
storeAudits[0].UserID = ctx.GetUserID()
|
||||
storeAudits[0].Status = model.StoreAuditStatusCreated
|
||||
storeAudits[0].Remark = storeAudit.Remark
|
||||
storeAudits[0].AuditPrice = storeAudit.AuditPrice
|
||||
_, err = dao.UpdateEntity(db, storeAudits[0], "UserID", "Status", "Remark", "AuditPrice")
|
||||
var skuBindInfos = []*StoreSkuBindInfo{
|
||||
&StoreSkuBindInfo{
|
||||
NameID: storeAudit.NameID,
|
||||
UnitPrice: storeAudits[0].UnitPrice,
|
||||
},
|
||||
}
|
||||
//证明填了额外的审核价格
|
||||
if storeAudit.AuditPrice != 0 {
|
||||
skuBindInfos[0].UnitPrice = storeAudit.AuditPrice
|
||||
}
|
||||
//如果是关注改价
|
||||
if storeAudits[0].Type == model.StoreSkuAuditTypeFocus {
|
||||
skuBindInfos[0].IsFocus = 1
|
||||
}
|
||||
var num int64
|
||||
db := dao.GetDB()
|
||||
skuIDs, err := updateStoresSkusWithoutSync(ctx, db, []int{storeAudit.StoreID}, skuBindInfos, false, false)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
isAsync = asyncStoreSkuOpFilter(ctx, isAsync)
|
||||
num = int64(len(skuIDs))
|
||||
if num > 0 {
|
||||
hint, err = CurVendorSync.SyncStoresSkus(ctx, nil, 0, db, nil, []int{storeAudit.StoreID}, skuIDs, false, isAsync, isContinueWhenError)
|
||||
}
|
||||
if num == 0 || !isAsync || hint == "" {
|
||||
hint = utils.Int64ToStr(num)
|
||||
}
|
||||
// _, err = UpdateStoresSkus(ctx, 0, []int{storeID}, skuBindInfos, false, isAsync, isContinueWhenError)
|
||||
} else if status == model.StoreAuditStatusRejected {
|
||||
storeAudits[0].UserID = ctx.GetUserID()
|
||||
storeAudits[0].Status = model.StoreAuditStatusRejected
|
||||
storeAudits[0].Remark = storeAudit.Remark
|
||||
_, err = dao.UpdateEntity(db, storeAudits[0], "UserID", "Status", "Remark")
|
||||
} else {
|
||||
return retVal, fmt.Errorf("审核标志不正确!")
|
||||
}
|
||||
if err == nil {
|
||||
if globals.IsProductEnv() {
|
||||
skuAndNames, err := dao.GetSkus(db, nil, []int{storeAudit.NameID}, nil, nil, nil)
|
||||
if len(skuAndNames) > 0 && err == nil {
|
||||
price := 0
|
||||
if storeAudit.AuditPrice != 0 {
|
||||
price = storeAudit.AuditPrice
|
||||
} else {
|
||||
price = storeAudits[0].UnitPrice
|
||||
}
|
||||
weixinmsg.NotifyStoreOpRequestStatus(flag, storeAudit.StoreID, storeAudit.NameID, jxutils.ComposeSpuName(skuAndNames[0].Prefix, skuAndNames[0].Name, 0), storeAudits[0].OriginUnitPrice, price, storeAudit.Remark)
|
||||
}
|
||||
}
|
||||
}
|
||||
return retVal, err
|
||||
}, storeSkuAudits)
|
||||
tasksch.HandleTask(task, nil, true).Run()
|
||||
if isAsync {
|
||||
hint = task.GetID()
|
||||
} else {
|
||||
_, err = task.GetResult(0)
|
||||
hint = "1"
|
||||
}
|
||||
return hint, err
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user