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()
|
||||
|
||||
Reference in New Issue
Block a user