- fix GetStores bug.
- isFocus on sku name.
This commit is contained in:
@@ -48,7 +48,7 @@ func GetStores(keyword string, params map[string]interface{}, offset, pageSize i
|
||||
sqlParams := make([]interface{}, 0)
|
||||
if keyword != "" {
|
||||
keywordLike := "%" + keyword + "%"
|
||||
sqlWhere += " (t1.name LIKE ? OR t1.address LIKE ? OR t1.tel1 LIKE ? OR t1.tel2 LIKE ? OR t1.last_operator LIKE ? OR city.name LIKE ?"
|
||||
sqlWhere += " AND (t1.name LIKE ? OR t1.address LIKE ? OR t1.tel1 LIKE ? OR t1.tel2 LIKE ? OR t1.last_operator LIKE ? OR city.name LIKE ?"
|
||||
sqlParams = append(sqlParams, keywordLike, keywordLike, keywordLike, keywordLike, keywordLike, keywordLike)
|
||||
|
||||
if keywordInt64, err2 := strconv.ParseInt(keyword, 10, 64); err2 == nil {
|
||||
@@ -56,8 +56,6 @@ func GetStores(keyword string, params map[string]interface{}, offset, pageSize i
|
||||
sqlParams = append(sqlParams, keywordInt64, keywordInt64, keywordInt64, keywordInt64, keywordInt64)
|
||||
}
|
||||
sqlWhere += ")"
|
||||
} else {
|
||||
sqlWhere += " 1 = 1"
|
||||
}
|
||||
|
||||
if params["storeID"] != nil {
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
)
|
||||
|
||||
// GetStoreSkus用
|
||||
@@ -29,8 +30,7 @@ type StoreSkuNamesInfo struct {
|
||||
type StoreSkuBindSkuInfo struct {
|
||||
SubStoreID int `json:"subStoreID"`
|
||||
SkuID int `json:"skuID"`
|
||||
IsFocus int `json:"isFocus"` // -1:不关注,0:忽略,1:关注
|
||||
IsSale int `json:"isSale"` // -1:不可售,0:忽略,1:可售
|
||||
IsSale int `json:"isSale"` // -1:不可售,0:忽略,1:可售
|
||||
|
||||
ElmID int64 `json:"elmID"`
|
||||
EbaiID int64 `json:"ebaiID"`
|
||||
@@ -40,6 +40,7 @@ type StoreSkuBindSkuInfo struct {
|
||||
type StoreSkuBindInfo struct {
|
||||
NameID int `json:"nameID"`
|
||||
UnitPrice int `json:"unitPrice"`
|
||||
IsFocus int `json:"isFocus"` // -1:不关注,0:忽略,1:关注
|
||||
Skus []*StoreSkuBindSkuInfo `json:"skus"`
|
||||
}
|
||||
|
||||
@@ -248,22 +249,43 @@ func UpdateStoreSkus(storeID int, skuBindInfos []*StoreSkuBindInfo, userName str
|
||||
if skuBindInfo.UnitPrice != 0 {
|
||||
v.UnitPrice = unitPrice
|
||||
v.Price = calStoreSkuPrice(unitPrice, v.SpecQuality, v.SpecUnit)
|
||||
v.JdSyncStatus |= model.SyncFlagPriceMask
|
||||
v.ElmSyncStatus |= model.SyncFlagPriceMask
|
||||
v.EbaiSyncStatus |= model.SyncFlagPriceMask
|
||||
setStoreSkuBindStatus(&v.StoreSkuBind, model.SyncFlagPriceMask)
|
||||
dao.WrapUpdateULEntity(v, userName)
|
||||
if _, err2 := dao.UpdateEntity(db, &v.StoreSkuBind); err2 != nil {
|
||||
if num, err = dao.UpdateEntity(db, &v.StoreSkuBind); err != nil {
|
||||
dao.Rollback(db)
|
||||
return 0, err2
|
||||
return 0, err
|
||||
}
|
||||
if num == 1 {
|
||||
needSyncIDMap[v.ID] = 1
|
||||
}
|
||||
}
|
||||
if skuBindInfo.IsFocus != 0 {
|
||||
if skuBindInfo.IsFocus == -1 {
|
||||
globals.SugarLogger.Debug(utils.Format4Output(v, false))
|
||||
num, err = dao.DeleteEntityLogically(db, &v.StoreSkuBind, map[string]interface{}{
|
||||
model.FieldStatus: model.StoreSkuBindStatusDeleted,
|
||||
model.FieldJdSyncStatus: model.SyncFlagDeletedMask,
|
||||
model.FieldElmSyncStatus: model.SyncFlagDeletedMask,
|
||||
model.FieldEbaiSyncStatus: model.SyncFlagDeletedMask,
|
||||
}, userName, nil)
|
||||
globals.SugarLogger.Debug(num)
|
||||
} else {
|
||||
// todo 如果修改ebai与elm ID怎么处理呢?
|
||||
v.DeletedAt = utils.DefaultTimeValue
|
||||
setStoreSkuBindStatus(&v.StoreSkuBind, model.SyncFlagModifiedMask)
|
||||
num, err = dao.UpdateEntity(db, &v.StoreSkuBind)
|
||||
globals.SugarLogger.Debug(num)
|
||||
}
|
||||
if num == 1 {
|
||||
needSyncIDMap[v.ID] = 1
|
||||
}
|
||||
needSyncIDMap[v.ID] = 1
|
||||
}
|
||||
existBindsMap[v.SkuID] = &v.StoreSkuBind
|
||||
}
|
||||
for _, v := range skuBinds {
|
||||
skuBind, ok := existBindsMap[v.SkuID]
|
||||
if !ok {
|
||||
if v.IsFocus == 1 {
|
||||
if skuBindInfo.IsFocus == 1 {
|
||||
sku := &model.Sku{}
|
||||
sku.ID = v.SkuID
|
||||
if err2 := dao.GetEntity(db, sku); err2 != nil {
|
||||
@@ -280,10 +302,6 @@ func UpdateStoreSkus(storeID int, skuBindInfos []*StoreSkuBindInfo, userName str
|
||||
}
|
||||
dao.WrapAddIDCULDEntity(skuBind, userName)
|
||||
}
|
||||
} else {
|
||||
if v.IsFocus != -1 {
|
||||
dao.WrapUpdateULEntity(skuBind, userName)
|
||||
}
|
||||
}
|
||||
if skuBind != nil {
|
||||
if v.IsSale != 0 {
|
||||
@@ -292,42 +310,19 @@ func UpdateStoreSkus(storeID int, skuBindInfos []*StoreSkuBindInfo, userName str
|
||||
} else {
|
||||
skuBind.Status = model.StoreSkuBindStatusDontSale
|
||||
}
|
||||
skuBind.JdSyncStatus |= model.SyncFlagSaleMask
|
||||
skuBind.ElmSyncStatus |= model.SyncFlagSaleMask
|
||||
skuBind.EbaiSyncStatus |= model.SyncFlagSaleMask
|
||||
setStoreSkuBindStatus(skuBind, model.SyncFlagSaleMask)
|
||||
}
|
||||
if ok {
|
||||
if v.IsFocus == -1 {
|
||||
_, err = dao.DeleteEntityLogically(db, skuBind, map[string]interface{}{
|
||||
model.FieldStatus: model.StoreSkuBindStatusDeleted,
|
||||
model.FieldJdSyncStatus: model.SyncFlagDeletedMask,
|
||||
model.FieldElmSyncStatus: model.SyncFlagDeletedMask,
|
||||
model.FieldEbaiSyncStatus: model.SyncFlagDeletedMask,
|
||||
}, userName, nil)
|
||||
needSyncIDMap[skuBind.ID] = 1
|
||||
} else {
|
||||
// todo 如果修改ebai与elm ID怎么处理呢?
|
||||
if v.IsFocus == 1 {
|
||||
skuBind.DeletedAt = utils.DefaultTimeValue
|
||||
}
|
||||
skuBind.JdSyncStatus |= model.SyncFlagModifiedMask
|
||||
skuBind.ElmSyncStatus |= model.SyncFlagModifiedMask
|
||||
skuBind.EbaiSyncStatus |= model.SyncFlagModifiedMask
|
||||
_, err = dao.UpdateEntity(db, skuBind)
|
||||
needSyncIDMap[skuBind.ID] = 1
|
||||
}
|
||||
} else {
|
||||
if !ok {
|
||||
if v.EbaiID != 0 {
|
||||
skuBind.EbaiID = v.EbaiID
|
||||
}
|
||||
if v.ElmID != 0 {
|
||||
skuBind.ElmID = v.ElmID
|
||||
}
|
||||
skuBind.JdSyncStatus = model.SyncFlagNewMask
|
||||
skuBind.ElmSyncStatus = model.SyncFlagNewMask
|
||||
skuBind.EbaiSyncStatus = model.SyncFlagNewMask
|
||||
err = dao.CreateEntity(db, skuBind)
|
||||
needSyncIDMap[skuBind.ID] = 1
|
||||
setStoreSkuBindStatus(skuBind, model.SyncFlagNewMask)
|
||||
if err = dao.CreateEntity(db, skuBind); err == nil {
|
||||
needSyncIDMap[skuBind.ID] = 1
|
||||
}
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
@@ -353,3 +348,9 @@ func calStoreSkuPrice(unitPrice int, specQuality float32, specUnit string) int {
|
||||
}
|
||||
return int(math.Round(float64(float32(unitPrice) * specQuality / 500)))
|
||||
}
|
||||
|
||||
func setStoreSkuBindStatus(skuBind *model.StoreSkuBind, status int8) {
|
||||
skuBind.JdSyncStatus |= status
|
||||
skuBind.ElmSyncStatus |= status
|
||||
skuBind.EbaiSyncStatus |= status
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ type StoreSkuController struct {
|
||||
// @Description 得到商家商品信息,如下条件之间是与的关系
|
||||
// @Param token header string true "认证token"
|
||||
// @Param storeID query int true "门店ID"
|
||||
// @Param isFocused query bool true "是否已关注(认领)"
|
||||
// @Param isFocus query bool true "是否已关注(认领)"
|
||||
// @Param keyword query string false "查询关键字(可以为空,为空表示不限制)"
|
||||
// @Param nameID query int false "SkuName ID"
|
||||
// @Param skuID query int false "Sku ID"
|
||||
@@ -32,7 +32,7 @@ type StoreSkuController struct {
|
||||
// @router /GetStoreSkus [get]
|
||||
func (c *StoreSkuController) GetStoreSkus() {
|
||||
c.callGetStoreSkus(func(params *tStoreSkuGetStoreSkusParams) (retVal interface{}, errCode string, err error) {
|
||||
retVal, err = cms.GetStoreSkus(params.StoreID, params.IsFocused, params.Keyword, params.MapData, params.Offset, params.PageSize)
|
||||
retVal, err = cms.GetStoreSkus(params.StoreID, params.IsFocus, params.Keyword, params.MapData, params.Offset, params.PageSize)
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
@@ -41,7 +41,7 @@ func (c *StoreSkuController) GetStoreSkus() {
|
||||
// @Description 修改商家商品绑定
|
||||
// @Param token header string true "认证token"
|
||||
// @Param storeID formData int true "需要修改的商品名ID,payload中的相应数据会被忽略"
|
||||
// @Param payload formData string true "json数据,StoreSkuBindInfo对象数组
|
||||
// @Param payload formData string true "json数据,StoreSkuBindInfo对象
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /UpdateStoreSku [put]
|
||||
@@ -54,3 +54,21 @@ func (c *StoreSkuController) UpdateStoreSku() {
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
// @Title 批量修改商家商品绑定
|
||||
// @Description 批量修改商家商品绑定
|
||||
// @Param token header string true "认证token"
|
||||
// @Param storeID formData int true "需要修改的商品名ID,payload中的相应数据会被忽略"
|
||||
// @Param payload formData string true "json数据,StoreSkuBindInfo对象数组
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /UpdateStoreSkus [put]
|
||||
func (c *StoreSkuController) UpdateStoreSkus() {
|
||||
c.callUpdateStoreSkus(func(params *tStoreSkuUpdateStoreSkusParams) (retVal interface{}, errCode string, err error) {
|
||||
var skuBindInfos []*cms.StoreSkuBindInfo
|
||||
if err = utils.UnmarshalUseNumber([]byte(params.Payload), &skuBindInfos); err == nil {
|
||||
retVal, err = cms.UpdateStoreSkus(params.StoreID, skuBindInfos, GetUserNameFromToken(params.Token))
|
||||
}
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
@@ -383,6 +383,14 @@ func init() {
|
||||
MethodParams: param.Make(),
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreSkuController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreSkuController"],
|
||||
beego.ControllerComments{
|
||||
Method: "UpdateStoreSkus",
|
||||
Router: `/UpdateStoreSkus`,
|
||||
AllowHTTPMethods: []string{"put"},
|
||||
MethodParams: param.Make(),
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:UserController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:UserController"],
|
||||
beego.ControllerComments{
|
||||
Method: "TmpAddMobile2Mobile",
|
||||
|
||||
Reference in New Issue
Block a user