- add PendingUnitPrice and PendingOpType in GetStoreSkus result, when param isGetOpRequest is true
- fix some API result to lower camel case
This commit is contained in:
@@ -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 ?`
|
||||
|
||||
Reference in New Issue
Block a user