aa
This commit is contained in:
@@ -1094,6 +1094,88 @@ func GetStoresSkusSaleInfo(ctx *jxcontext.Context, storeIDs []int, skuIDs []int,
|
||||
return nil, err
|
||||
}
|
||||
|
||||
type GetStoresSkusSaleInfoNewResult struct {
|
||||
VendorID int `orm:"column(vendor_id)" json:"vendorID"`
|
||||
StoreID int `orm:"column(store_id)" json:"storeID"`
|
||||
StoreName string `json:"storeName"`
|
||||
SkuID int `orm:"column(sku_id)" json:"skuID"`
|
||||
SkuName string `json:"skuName"`
|
||||
SaleCount int `json:"saleCount"` //销量
|
||||
}
|
||||
|
||||
func GetStoresSkusSaleInfoNew(ctx *jxcontext.Context, vendorIDs, storeIDs, skuIDs, skuNameIDs []int, fromTime, toTime string, saleCountBegin, saleCountEnd, sortType int, keyword string, offset, pageSize int) (pageInfo *model.PagedInfo, err error) {
|
||||
var (
|
||||
db = dao.GetDB()
|
||||
list []*GetStoresSkusSaleInfoNewResult
|
||||
)
|
||||
if len(storeIDs) == 0 && len(skuIDs) == 0 && keyword == "" {
|
||||
return nil, fmt.Errorf("请至少输入一个条件查询!")
|
||||
}
|
||||
if fromTime == "" && toTime == "" {
|
||||
return nil, fmt.Errorf("必须选择一段时间!")
|
||||
}
|
||||
sql := `
|
||||
SELECT SQL_CALC_FOUND_ROWS t1.* FROM (
|
||||
SELECT d.id, d.name, c.id, e.name, a.vendor_id, SUM(a.count) sale_count
|
||||
FROM order_sku a
|
||||
LEFT JOIN goods_order b ON a.vendor_id = b.vendor_id AND a.vendor_order_id = b.vendor_order_id
|
||||
LEFT JOIN sku c ON IF(a.jx_sku_id = 0, a.sku_id, a.jx_sku_id) = c.id
|
||||
LEFT JOIN sku_name e ON e.id = c.name_id
|
||||
LEFT JOIN store d ON IF(b.jx_store_id = 0, b.store_id, b.jx_store_id) = d.id
|
||||
WHERE a.order_created_at > ? AND a.order_created_at < ?
|
||||
`
|
||||
sqlParams := []interface{}{utils.Str2Time(fromTime), utils.Str2Time(toTime)}
|
||||
if len(vendorIDs) > 0 {
|
||||
sql += " AND a.vendor_id IN (" + dao.GenQuestionMarks(len(vendorIDs)) + ")"
|
||||
sqlParams = append(sqlParams, vendorIDs)
|
||||
}
|
||||
if len(storeIDs) > 0 {
|
||||
sql += " AND d.id IN (" + dao.GenQuestionMarks(len(storeIDs)) + ")"
|
||||
sqlParams = append(sqlParams, storeIDs)
|
||||
}
|
||||
if len(skuIDs) > 0 {
|
||||
sql += " AND c.id IN (" + dao.GenQuestionMarks(len(skuIDs)) + ")"
|
||||
sqlParams = append(sqlParams, skuIDs)
|
||||
}
|
||||
if len(skuNameIDs) > 0 {
|
||||
sql += " AND e.id IN (" + dao.GenQuestionMarks(len(skuNameIDs)) + ")"
|
||||
sqlParams = append(sqlParams, skuNameIDs)
|
||||
}
|
||||
if keyword != "" {
|
||||
sql += " AND (e.name LIKE ? OR d.name LIKE ? OR d.id = ? OR a.vendor_order_id = ?)"
|
||||
sqlParams = append(sqlParams, "%"+keyword+"%", "%"+keyword+"%", keyword, keyword)
|
||||
}
|
||||
sql += " GROUP BY 1, 2, 3, 4, 5)t1 WHERE 1 = 1"
|
||||
if saleCountBegin != 0 {
|
||||
sql += " AND t1.sale_count >= ?"
|
||||
sqlParams = append(sqlParams, saleCountBegin)
|
||||
}
|
||||
if saleCountEnd != 0 {
|
||||
sql += " AND t1.sale_count <= ?"
|
||||
sqlParams = append(sqlParams, saleCountEnd)
|
||||
}
|
||||
if sortType != 0 {
|
||||
if sortType > 0 {
|
||||
sql += " ORDER BY t1.sale_count"
|
||||
} else {
|
||||
sql += " ORDER BY t1.sale_count DESC"
|
||||
}
|
||||
}
|
||||
sql += " LIMIT ? OFFSET ?"
|
||||
pageSize = jxutils.FormalizePageSize(pageSize)
|
||||
offset = jxutils.FormalizePageOffset(offset)
|
||||
sqlParams = append(sqlParams, pageSize, offset)
|
||||
txDB, _ := dao.Begin(db)
|
||||
defer dao.Commit(db, txDB)
|
||||
if err = dao.GetRowsTx(txDB, &list, sql, sqlParams...); err == nil {
|
||||
pageInfo = &model.PagedInfo{
|
||||
TotalCount: dao.GetLastTotalRowCount2(db, txDB),
|
||||
Data: list,
|
||||
}
|
||||
}
|
||||
return pageInfo, err
|
||||
}
|
||||
|
||||
func asyncStoreSkuOpFilter(ctx *jxcontext.Context, isAsync bool) bool {
|
||||
if !isAsync {
|
||||
authType := ctx.GetLoginInfo().GetAuthType()
|
||||
|
||||
@@ -336,12 +336,14 @@ func (c *StoreSkuController) UpdateStoresSkusSale() {
|
||||
// @Param token header string true "认证token"
|
||||
// @Param storeIDs query string false "门店ID列表"
|
||||
// @Param skuIDs query string false "Sku ID列表"
|
||||
// @Param vendorIDs query string false "平台 ID列表"
|
||||
// @Param skuNameIDs query string false "Skuname ID列表"
|
||||
// @Param fromTime query string false "开始时间"
|
||||
// @Param toTime query string false "结束时间"
|
||||
// @Param saleCountBegin query string false "销量begin"
|
||||
// @Param saleCountEnd query string false "销量end"
|
||||
// @Param sortType query int false ""
|
||||
// @Param saleCountBegin query int false "销量begin"
|
||||
// @Param saleCountEnd query int false "销量end"
|
||||
// @Param sortType query int false "排序类型,1为按销量排,正为升序,负为倒序"
|
||||
// @Param keyword query string false "关键字"
|
||||
// @Param offset query int false "门店列表起始序号(以0开始,缺省为0)"
|
||||
// @Param pageSize query int false "门店列表页大小(缺省为50,-1表示全部)"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
@@ -350,11 +352,12 @@ func (c *StoreSkuController) UpdateStoresSkusSale() {
|
||||
func (c *StoreSkuController) GetStoresSkusSaleInfo() {
|
||||
c.callGetStoresSkusSaleInfo(func(params *tStoreSkuGetStoresSkusSaleInfoParams) (retVal interface{}, errCode string, err error) {
|
||||
var (
|
||||
storeIDs, skuIDs []int
|
||||
storeIDs, skuIDs, skuNameIDs, vendorIDs []int
|
||||
)
|
||||
if err = jxutils.Strings2Objs(params.StoreIDs, &storeIDs, params.SkuIDs, &skuIDs); err != nil {
|
||||
if err = jxutils.Strings2Objs(params.StoreIDs, &storeIDs, params.SkuIDs, &skuIDs, params.SkuNameIDs, &skuNameIDs, params.VendorIDs, &vendorIDs); err != nil {
|
||||
return retVal, "", err
|
||||
}
|
||||
retVal, err = cms.GetStoresSkusSaleInfoNew(params.Ctx, vendorIDs, storeIDs, skuIDs, skuNameIDs, params.FromTime, params.ToTime, params.SaleCountBegin, params.SaleCountEnd, params.SortType, params.Keyword, params.Offset, params.PageSize)
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user