diff --git a/business/jxstore/cms/store_sku.go b/business/jxstore/cms/store_sku.go index 47fd32118..e0ece3dd6 100644 --- a/business/jxstore/cms/store_sku.go +++ b/business/jxstore/cms/store_sku.go @@ -4,6 +4,7 @@ import ( "errors" "fmt" "math" + "sort" "strconv" "time" @@ -29,6 +30,9 @@ type StoreSkuNameExt struct { UnitPrice int `json:"unitPrice"` Skus []map[string]interface{} `orm:"-" json:"skus"` SkusStr string `json:"-"` + + PendingOpType int8 `json:"pendingOpType"` // 取值同 StoreOpRequest.Type + PendingUnitPrice int `json:"pendingUnitPrice"` // 这个是待审核的价格申请 } // GetStoreSkus用 @@ -74,9 +78,9 @@ type SkuSaleInfo struct { type StoreOpRequestInfo struct { model.StoreOpRequest - StoreName string - SkuNamePrefix string - SkuNameName string + StoreName string `json:"storeName"` + SkuNamePrefix string `json:"skuNamePrefix"` + SkuNameName string `json:"skuNameName"` } // 商品不可售,直接排除 @@ -339,6 +343,28 @@ func GetStoreSkus(ctx *jxcontext.Context, storeID int, isFocus bool, keyword str skuNamesInfo.SkuNames = newSkuNames[offset:endIndex] } } + if globals.EnablePendingChange { + if isGetOpRequest, ok := params["isGetOpRequest"].(bool); ok && isGetOpRequest { + nameIDs := make([]int, len(skuNamesInfo.SkuNames)) + for k, skuName := range skuNamesInfo.SkuNames { + nameIDs[k] = skuName.ID + } + requestList, err2 := GetStoreOpRequests(ctx, utils.DefaultTimeValue, utils.DefaultTimeValue, "", []int{storeID}, nameIDs, nil, []int{model.RequestStatusNew}, 0, -1) + if err = err2; err != nil { + return nil, err + } + requestMap := make(map[int]*StoreOpRequestInfo) + for _, requestOp := range requestList { + requestMap[requestOp.ItemID] = requestOp + } + for _, skuName := range skuNamesInfo.SkuNames { + if requestOp := requestMap[skuName.ID]; requestOp != nil { + skuName.PendingUnitPrice = requestOp.IntParam1 + skuName.PendingOpType = requestOp.Type + } + } + } + } } } dao.Commit(db) @@ -454,6 +480,7 @@ func checkStoresSkusSaleCity(ctx *jxcontext.Context, db *dao.DaoDB, storeIDs []i } func updateStoresSkusWithoutSync(ctx *jxcontext.Context, storeIDs []int, skuBindInfos []*StoreSkuBindInfo) (needSyncSkus []int, err error) { + sort.Ints(storeIDs) globals.SugarLogger.Debugf("updateStoresSkusWithoutSync, storeIDs:%v, skuBindInfos:%s", storeIDs, utils.Format4Output(skuBindInfos, false)) db := dao.GetDB() if err = checkStoresSkusSaleCity(ctx, db, storeIDs, skuBindInfos); err != nil { @@ -973,23 +1000,20 @@ func RejectStoreOpRequests(ctx *jxcontext.Context, reqIDs []int, rejectReason st } // 当前些函数只针对type为: RequestTypeChangePrice与RequestTypeFocusSkuName的查询才有效 -func GetStoreOpRequests(ctx *jxcontext.Context, fromTime, toTime time.Time, keyword string, params map[string]interface{}, offset, pageSize int) (requestList []*StoreOpRequestInfo, err error) { +func GetStoreOpRequests(ctx *jxcontext.Context, fromTime, toTime time.Time, keyword string, storeIDs, itemIDs, typeList, statusList []int, offset, pageSize int) (requestList []*StoreOpRequestInfo, err error) { if globals.EnablePendingChange { sql := ` - SELECT t1.id, t1.created_at, t1.updated_at, t1.last_operator, t1.deleted_at, - t1.type, t1.store_id, t1.item_id, t1.status, t1.user_id, t1.int_param1, t1.int_param2, - t2.name store_name, t3.prefix sku_name_prefix, t3.name sku_name_name, AVG(t5.unit_price) unit_price - FROM store_op_request t1 - JOIN store t2 ON t1.store_id = t2.id - JOIN sku_name t3 ON t1.item_id = t3.id - JOIN sku t4 ON t3.id = t4.name_id - LEFT JOIN store_sku_bind t5 ON t1.store_id = t5.store_id AND t4.id = t5.sku_id AND t5.deleted_at = ? - WHERE t1.created_at >= ? AND t1.created_at <= ? - ` + SELECT t1.id, t1.created_at, t1.updated_at, t1.last_operator, t1.deleted_at, + t1.type, t1.store_id, t1.item_id, t1.status, t1.user_id, t1.int_param1, t1.int_param2, + t2.name store_name, t3.prefix sku_name_prefix, t3.name sku_name_name, AVG(t5.unit_price) unit_price + FROM store_op_request t1 + JOIN store t2 ON t1.store_id = t2.id + JOIN sku_name t3 ON t1.item_id = t3.id + JOIN sku t4 ON t3.id = t4.name_id + LEFT JOIN store_sku_bind t5 ON t1.store_id = t5.store_id AND t4.id = t5.sku_id AND t5.deleted_at = ? + WHERE 1 = 1` sqlParams := []interface{}{ utils.DefaultTimeValue, - fromTime, - toTime, } if keyword != "" { keywordLike := "%" + keyword + "%" @@ -1001,36 +1025,31 @@ func GetStoreOpRequests(ctx *jxcontext.Context, fromTime, toTime time.Time, keyw } sql += ")" } - if params["storeIDs"] != nil { - var storeIDs []int - if err = utils.UnmarshalUseNumber([]byte(params["storeIDs"].(string)), &storeIDs); err != nil { - return nil, err - } - if len(storeIDs) > 0 { - sql += " AND t1.store_id IN (" + dao.GenQuestionMarks(len(storeIDs)) + ")" - sqlParams = append(sqlParams, storeIDs) - } + if fromTime != utils.DefaultTimeValue { + sql += " AND t1.created_at >= ?" + sqlParams = append(sqlParams, fromTime) } - if params["types"] != nil { - var typeList []int - if err = utils.UnmarshalUseNumber([]byte(params["types"].(string)), &typeList); err != nil { - return nil, err - } - if len(typeList) > 0 { - sql += " AND t1.type IN (" + dao.GenQuestionMarks(len(typeList)) + ")" - sqlParams = append(sqlParams, typeList) - } + if toTime != utils.DefaultTimeValue { + sql += " AND t1.created_at <= ?" + sqlParams = append(sqlParams, toTime) } - if params["statuss"] != nil { - var statusList []int - if err = utils.UnmarshalUseNumber([]byte(params["statuss"].(string)), &statusList); err != nil { - return nil, err - } - if len(statusList) > 0 { - sql += " AND t1.status IN (" + dao.GenQuestionMarks(len(statusList)) + ")" - sqlParams = append(sqlParams, statusList) - } + if len(storeIDs) > 0 { + sql += " AND t1.store_id IN (" + dao.GenQuestionMarks(len(storeIDs)) + ")" + sqlParams = append(sqlParams, storeIDs) } + if len(itemIDs) > 0 { + sql += " AND t1.item_id IN (" + dao.GenQuestionMarks(len(itemIDs)) + ")" + sqlParams = append(sqlParams, itemIDs) + } + if len(typeList) > 0 { + sql += " AND t1.type IN (" + dao.GenQuestionMarks(len(typeList)) + ")" + sqlParams = append(sqlParams, typeList) + } + if len(statusList) > 0 { + sql += " AND t1.status IN (" + dao.GenQuestionMarks(len(statusList)) + ")" + sqlParams = append(sqlParams, statusList) + } + sql += ` GROUP BY 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 LIMIT ? OFFSET ?` diff --git a/business/jxutils/jxutils.go b/business/jxutils/jxutils.go index 93d8e6f2e..62b8c28fe 100644 --- a/business/jxutils/jxutils.go +++ b/business/jxutils/jxutils.go @@ -394,3 +394,18 @@ func BatchStr2Time(strTime ...string) (timeList []time.Time, err error) { func IsTimeEmpty(timeValue time.Time) bool { return (timeValue == utils.DefaultTimeValue || timeValue == utils.ZeroTimeValue) } + +// strAndObjAddPairs必须按字符串1,转换地址1,字符串2,转换地址2这样的格式传递 +func Strings2Objs(strAndObjAddPairs ...interface{}) (err error) { + str := "" + for k, v := range strAndObjAddPairs { + if k%2 == 0 { + str, _ = v.(string) + } else if str != "" { + if err = utils.UnmarshalUseNumber([]byte(str), v); err != nil { + return err + } + } + } + return nil +} diff --git a/business/model/store_sku.go b/business/model/store_sku.go index 03f986967..806e7915b 100644 --- a/business/model/store_sku.go +++ b/business/model/store_sku.go @@ -84,19 +84,19 @@ func (*StoreSkuBind) TableUnique() [][]string { type StoreOpRequest struct { ModelIDCULD // DeletedAt用于表示请求操作结束,而并不一定是删除 - Type int8 - StoreID int `orm:"column(store_id)"` - ItemID int `orm:"column(item_id)"` // 这个根据type不同,可能是SKUNAME ID或SKU ID - Status int8 - UserID string `orm:"size(48);column(user_id)"` - IntParam1 int - IntParam2 int - JsonParam string `orm:"size(3000)"` - Remark string `orm:"size(255)"` + Type int8 `json:"type"` + StoreID int `orm:"column(store_id)" json:"storeID"` + ItemID int `orm:"column(item_id)" json:"itemID"` // 这个根据type不同,可能是SKUNAME ID或SKU ID + Status int8 `json:"status"` + UserID string `orm:"size(48);column(user_id)" json:"userID"` + IntParam1 int `json:"intParam1"` + IntParam2 int `json:"intParam2"` + JsonParam string `orm:"size(3000)" json:"jsonParam"` + Remark string `orm:"size(255)" json:"remark"` } func (*StoreOpRequest) TableUnique() [][]string { return [][]string{ - []string{"StoreID", "Type", "ItemID", "DeletedAt"}, + []string{"DeletedAt", "StoreID", "Type", "ItemID"}, } } diff --git a/controllers/cms_store_sku.go b/controllers/cms_store_sku.go index fb8cf3969..4698e3c5c 100644 --- a/controllers/cms_store_sku.go +++ b/controllers/cms_store_sku.go @@ -37,6 +37,7 @@ type StoreSkuController struct { // @Param stToTime query string false "统计SKU结束时间" // @Param stFromCount query int false "统计SKU,结果集起始数量(包括)" // @Param stToCount query int false "统计SKU,结果集结束数量(包括)" +// @Param isGetOpRequest query bool false "是否返回相应的待审核变动请求,缺省为false不返回" // @Param offset query int false "门店列表起始序号(以0开始,缺省为0)" // @Param pageSize query int false "门店列表页大小(缺省为50,-1表示全部)" // @Success 200 {object} controllers.CallResult @@ -220,11 +221,11 @@ func (c *StoreSkuController) GetStoresSkusSaleInfo() { // @Title 得到商家商品修改价格请求信息 // @Description 得到商家商品修改价格请求信息 // @Param token header string true "认证token" -// @Param fromTime query string true "申请开始时间" +// @Param fromTime query string false "申请开始时间" // @Param toTime query string false "申请结束时间" // @Param keyword query string false "查询关键字(可以为空,为空表示不限制)" // @Param storeIDs query string false "门店ID列表" -// @Param itemIDs query string false "id列表对象" +// @Param itemIDs query string false "id列表对象,当前指skuname id" // @Param types query string false "类型列表对象" // @Param statuss query string false "状态列表对象" // @Param offset query int false "门店列表起始序号(以0开始,缺省为0)" @@ -235,12 +236,19 @@ func (c *StoreSkuController) GetStoresSkusSaleInfo() { func (c *StoreSkuController) GetStoreOpRequests() { c.callGetStoreOpRequests(func(params *tStoreSkuGetStoreOpRequestsParams) (retVal interface{}, errCode string, err error) { var ( - timeList []time.Time + timeList []time.Time + storeIDs []int + typeList []int + statusList []int + itemIDs []int ) if timeList, err = jxutils.BatchStr2Time(params.FromTime, params.ToTime); err != nil { return retVal, "", err } - retVal, err = cms.GetStoreOpRequests(params.Ctx, timeList[0], timeList[1], params.Keyword, params.MapData, params.Offset, params.PageSize) + if err = jxutils.Strings2Objs(params.StoreIDs, &storeIDs, params.Types, &typeList, params.Statuss, &statusList, params.ItemIDs, &itemIDs); err != nil { + return retVal, "", err + } + retVal, err = cms.GetStoreOpRequests(params.Ctx, timeList[0], timeList[1], params.Keyword, storeIDs, itemIDs, typeList, statusList, params.Offset, params.PageSize) return retVal, "", err }) }