推荐商品
This commit is contained in:
@@ -6,8 +6,10 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
)
|
||||
|
||||
@@ -109,10 +111,25 @@ type StoreSkuNameInfo struct {
|
||||
UnitPrice int64
|
||||
}
|
||||
|
||||
type SkuAndNameExt struct {
|
||||
SkuID int `orm:"column(sku_id)" json:"skuID"`
|
||||
// GetStoreSkus用
|
||||
type StoreSkuNameExt struct {
|
||||
StoreID int `orm:"column(store_id)" json:"storeID"`
|
||||
StoreName string `json:"storeName"`
|
||||
|
||||
model.SkuName
|
||||
Skus []*StoreSkuExt `orm:"-" json:"skus,omitempty"`
|
||||
PayPercentage int `json:"-"`
|
||||
UnitPrice int `json:"unitPrice"`
|
||||
Skus []*StoreSkuExt `orm:"-" json:"skus,omitempty"`
|
||||
SkusStr string `json:"-"`
|
||||
|
||||
PendingOpType int8 `json:"pendingOpType"` // 取值同 StoreOpRequest.Type
|
||||
PendingUnitPrice int `json:"pendingUnitPrice"` // 这个是待审核的价格申请
|
||||
}
|
||||
|
||||
// GetStoreSkus用
|
||||
type StoreSkuNamesInfo struct {
|
||||
TotalCount int `json:"totalCount"`
|
||||
SkuNames []*StoreSkuNameExt `json:"skuNames"`
|
||||
}
|
||||
|
||||
type StoreSkuExt struct {
|
||||
@@ -896,16 +913,17 @@ func GetStoreSkusByNameIDs(db *DaoDB, storeIDs []int, nameID int) (skuList []*St
|
||||
return skuList, err
|
||||
}
|
||||
|
||||
func GetTopSkusByStoreIDs(db *DaoDB, storeIDs []int) (skuAndNameExt []*SkuAndNameExt, err error) {
|
||||
func GetTopSkusByStoreIDs(db *DaoDB, storeIDs []int) (storeSkuNameExt []*StoreSkuNameExt, err error) {
|
||||
sql := `
|
||||
SELECT t2.id sku_id,t3.*
|
||||
FROM(
|
||||
SELECT SUM(b.count) count,c.id
|
||||
SELECT SUM(b.count) count,c.id,a.store_id,d.name store_name
|
||||
FROM goods_order a
|
||||
JOIN order_sku b ON a.vendor_order_id = b.vendor_order_id AND a.vendor_id = b.vendor_id
|
||||
JOIN sku c ON b.sku_id = c.id AND c.deleted_at = ?
|
||||
JOIN sku_name t1 ON t1.id = c.name_id AND t1.deleted_at = ?
|
||||
STRAIGHT_JOIN store_sku_bind t4 ON t4.store_id = IF(a.store_id = 0,a.jx_store_id,a.store_id) AND t4.sku_id = b.sku_id AND t4.status = ? AND t4.deleted_at = ?
|
||||
JOIN store d ON d.id = a.store_id
|
||||
WHERE 1=1
|
||||
AND a.order_created_at BETWEEN ? and NOW()
|
||||
`
|
||||
@@ -922,18 +940,21 @@ func GetTopSkusByStoreIDs(db *DaoDB, storeIDs []int) (skuAndNameExt []*SkuAndNam
|
||||
}
|
||||
sql += `
|
||||
AND b.sale_price > ?
|
||||
GROUP BY 2)t1
|
||||
GROUP BY 2,3,4)t1
|
||||
JOIN sku t2 ON t2.id = t1.id
|
||||
JOIN sku_name t3 ON t3.id = t2.name_id
|
||||
ORDER BY t1.count DESC
|
||||
LIMIT ?
|
||||
`
|
||||
sqlParams = append(sqlParams, 100, 30)
|
||||
err = GetRows(db, &skuAndNameExt, sql, sqlParams...)
|
||||
for _, v := range skuAndNameExt {
|
||||
err = GetRows(db, &storeSkuNameExt, sql, sqlParams...)
|
||||
var skuNamesInfo = &StoreSkuNamesInfo{
|
||||
SkuNames: storeSkuNameExt,
|
||||
}
|
||||
for _, v := range storeSkuNameExt {
|
||||
var skus []*StoreSkuExt
|
||||
sql2 := `
|
||||
SELECT a.*,t4.created_at bind_created_at, t4.updated_at bind_updated_at, t4.last_operator bind_last_operator, t4.deleted_at bind_deleted_at,
|
||||
SELECT a.id sku_id,a.*,t4.created_at bind_created_at, t4.updated_at bind_updated_at, t4.last_operator bind_last_operator, t4.deleted_at bind_deleted_at,
|
||||
t4.sub_store_id, t4.price bind_price, IF(t4.unit_price IS NOT NULL, t4.unit_price, t1.price) unit_price, t4.status store_sku_status, t4.auto_sale_at,
|
||||
t4.ebai_id, t4.mtwm_id,
|
||||
t4.ebai_sync_status, t4.mtwm_sync_status,
|
||||
@@ -947,7 +968,7 @@ func GetTopSkusByStoreIDs(db *DaoDB, storeIDs []int) (skuAndNameExt []*SkuAndNam
|
||||
sqlParams2 := []interface{}{
|
||||
utils.DefaultTimeValue,
|
||||
utils.DefaultTimeValue,
|
||||
v.SkuID,
|
||||
v.Skus[0].SkuID,
|
||||
utils.DefaultTimeValue,
|
||||
}
|
||||
if len(storeIDs) > 0 {
|
||||
@@ -956,8 +977,9 @@ func GetTopSkusByStoreIDs(db *DaoDB, storeIDs []int) (skuAndNameExt []*SkuAndNam
|
||||
}
|
||||
err = GetRows(db, &skus, sql2, sqlParams2...)
|
||||
v.Skus = skus
|
||||
err = UpdateActPrice4StoreSkuNameNew(db, storeIDs, []int{v.Skus[0].SkuID}, skuNamesInfo, -1)
|
||||
}
|
||||
return skuAndNameExt, err
|
||||
return storeSkuNameExt, err
|
||||
}
|
||||
|
||||
func GetTopCategorysByStoreIDs(db *DaoDB, storeIDs []int) (skuCategory []*model.SkuCategory, err error) {
|
||||
@@ -1086,3 +1108,45 @@ func SetStoreCatMapSyncStatus(storeCatMap *model.StoreSkuCategoryMap, vendorID i
|
||||
storeCatMap.EbaiSyncStatus = syncStatus
|
||||
}
|
||||
}
|
||||
|
||||
// skuIDs为空,会导致性能极低,所以要skuIDs必须有值
|
||||
func UpdateActPrice4StoreSkuNameNew(db *DaoDB, storeIDs, skuIDs []int, skuNamesInfo *StoreSkuNamesInfo, actVendorID int) (err error) {
|
||||
if len(skuIDs) == 0 {
|
||||
return nil
|
||||
}
|
||||
var vendorIDs []int
|
||||
if actVendorID >= 0 {
|
||||
vendorIDs = []int{actVendorID}
|
||||
}
|
||||
actStoreSkuList, err := GetEffectiveActStoreSkuInfo(db, 0, vendorIDs, storeIDs, skuIDs, time.Now(), time.Now())
|
||||
if err != nil {
|
||||
globals.SugarLogger.Errorf("updateActPrice4StoreSkuNameNew can not get sku promotion info for error:%v", err)
|
||||
return err
|
||||
}
|
||||
actStoreSkuMap4Act := jxutils.NewActStoreSkuMap(actStoreSkuList, true)
|
||||
actStoreSkuMap4EarningPrice := jxutils.NewActStoreSkuMap(actStoreSkuList, false)
|
||||
|
||||
for _, skuName := range skuNamesInfo.SkuNames {
|
||||
if len(skuName.Skus) > 0 {
|
||||
for _, v := range skuName.Skus {
|
||||
if actStoreSku := actStoreSkuMap4Act.GetActStoreSku(skuName.StoreID, v.SkuID, -1); actStoreSku != nil {
|
||||
v.ActPrice = int(actStoreSku.ActualActPrice)
|
||||
v.ActID = actStoreSku.ActID
|
||||
v.ActType = actStoreSku.Type
|
||||
}
|
||||
if actStoreSku := actStoreSkuMap4EarningPrice.GetActStoreSku(skuName.StoreID, v.SkuID, -1); actStoreSku != nil {
|
||||
v.EarningPrice = int(actStoreSku.EarningPrice)
|
||||
v.EarningActID = actStoreSku.ActID
|
||||
}
|
||||
|
||||
v.RealEarningPrice = v.EarningPrice
|
||||
if v.RealEarningPrice == 0 {
|
||||
v.RealEarningPrice = int(jxutils.CaculateSkuEarningPrice(int64(v.BindPrice), int64(v.BindPrice), skuName.PayPercentage))
|
||||
}
|
||||
}
|
||||
} else {
|
||||
skuName.UnitPrice = skuName.Price
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user