导入Excel更新京西价,推荐商品
This commit is contained in:
@@ -112,7 +112,60 @@ type StoreSkuNameInfo struct {
|
||||
type SkuAndNameExt struct {
|
||||
SkuID int `orm:"column(sku_id)" json:"skuID"`
|
||||
model.SkuName
|
||||
Skus []*model.Sku `orm:"-" json:"skus,omitempty"`
|
||||
Skus []*StoreSkuExt `orm:"-" json:"skus,omitempty"`
|
||||
}
|
||||
|
||||
type StoreSkuExt struct {
|
||||
NameID int `orm:"column(name_id)" json:"nameID"`
|
||||
SkuID int `orm:"column(sku_id)" json:"id"`
|
||||
Comment string `orm:"size(255)" json:"comment"`
|
||||
SkuCategoryID int `orm:"column(sku_category_id)" json:"categoryID"`
|
||||
SkuSpecQuality float32 `json:"specQuality"`
|
||||
SkuSpecUnit string `orm:"size(8)" json:"specUnit"` // 质量或容量
|
||||
Weight int `json:"weight"` // 重量/质量,单位为克,当相应的SkuName的SpecUnit为g或kg时,必须等于SpecQuality
|
||||
JdID string `orm:"column(sku_jd_id);null;index" json:"jdID"`
|
||||
SkuStatus int `json:"status"`
|
||||
|
||||
BindCreatedAt time.Time `orm:"auto_now_add;type(datetime)" json:"createdAt"`
|
||||
BindUpdatedAt time.Time `orm:"auto_now;type(datetime)" json:"updatedAt"`
|
||||
BindLastOperator string `orm:"size(32)" json:"lastOperator"` // 最后操作员
|
||||
BindDeletedAt time.Time `orm:"type(datetime)" json:"deletedAt"`
|
||||
SubStoreID int `orm:"column(sub_store_id)" json:"subStoreID"`
|
||||
BindPrice int `json:"price"` // 单位为分,不用int64的原因是这里不需要累加
|
||||
UnitPrice int `json:"unitPrice"` // 这个是一斤的门店商品价,放在这里的原因是避免额外增加一张store sku_name表,逻辑上要保证同一SKU NAME中的所有SKU这个字段的数据一致
|
||||
StoreSkuStatus int `json:"storeSkuStatus"`
|
||||
|
||||
EbaiID string `orm:"column(ebai_id);index" json:"ebaiID"`
|
||||
MtwmID string `orm:"column(mtwm_id)" json:"mtwmID"` // 这个也不是必须的,只是为了DAO取数据语句一致
|
||||
// WscID string `orm:"column(wsc_id);index" json:"wscID"` // 表示微盟skuId
|
||||
// WscID2 string `orm:"column(wsc_id2);index" json:"wscID2"` // 表示微盟goodsId
|
||||
|
||||
JdSyncStatus int8 `orm:"default(2)" json:"jdSyncStatus"`
|
||||
EbaiSyncStatus int8 `orm:"default(2)" json:"ebaiSyncStatus"`
|
||||
MtwmSyncStatus int8 `orm:"default(2)" json:"mtwmSyncStatus"`
|
||||
// WscSyncStatus int8 `orm:"default(2)" json:"wscSyncStatus"`
|
||||
|
||||
JdPrice int `json:"jdPrice"`
|
||||
EbaiPrice int `json:"ebaiPrice"`
|
||||
MtwmPrice int `json:"mtwmPrice"`
|
||||
JxPrice int `json:"jxPrice"`
|
||||
|
||||
AutoSaleAt time.Time `orm:"type(datetime);null" json:"autoSaleAt"`
|
||||
|
||||
ActPrice int `json:"actPrice"`
|
||||
ActID int `orm:"column(act_id)" json:"actID"`
|
||||
ActType int `orm:"column(act_type)" json:"actType"`
|
||||
|
||||
EarningPrice int `json:"earningPrice"`
|
||||
EarningActID int `orm:"column(earning_act_id)" json:"earningActID"`
|
||||
|
||||
RealEarningPrice int `json:"realEarningPrice"`
|
||||
|
||||
StatusSaleBegin int16 `json:"statusSaleBegin"` //商品可售时间范围
|
||||
StatusSaleEnd int16 `json:"statusSaleEnd"`
|
||||
|
||||
Count int `json:"count"`
|
||||
Times int `json:"times"`
|
||||
}
|
||||
|
||||
// todo 应该通过需要同步的skuid来驱动同步分类,而不是当前这种分开的逻辑
|
||||
@@ -670,14 +723,19 @@ func GetTopSkusByStoreIDs(db *DaoDB, storeIDs []int) (skuAndNameExt []*SkuAndNam
|
||||
sql := `
|
||||
SELECT t2.id sku_id,t3.*
|
||||
FROM(
|
||||
SELECT SUM(b.count) count,c.id
|
||||
SELECT SUM(b.count) count,c.id
|
||||
FROM goods_order a
|
||||
JOIN order_sku b ON a.vendor_order_id = b.vendor_order_id
|
||||
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 = ?
|
||||
WHERE 1=1
|
||||
AND a.order_created_at BETWEEN ? and NOW()
|
||||
`
|
||||
sqlParams := []interface{}{
|
||||
utils.DefaultTimeValue,
|
||||
utils.DefaultTimeValue,
|
||||
model.SkuStatusNormal,
|
||||
utils.DefaultTimeValue,
|
||||
time.Now().AddDate(0, -1, 0),
|
||||
}
|
||||
@@ -687,7 +745,7 @@ func GetTopSkusByStoreIDs(db *DaoDB, storeIDs []int) (skuAndNameExt []*SkuAndNam
|
||||
}
|
||||
sql += `
|
||||
AND b.sale_price > ?
|
||||
GROUP BY c.id)t1
|
||||
GROUP BY 2)t1
|
||||
JOIN sku t2 ON t2.id = t1.id
|
||||
JOIN sku_name t3 ON t3.id = t2.name_id
|
||||
ORDER BY t1.count DESC
|
||||
@@ -696,17 +754,28 @@ func GetTopSkusByStoreIDs(db *DaoDB, storeIDs []int) (skuAndNameExt []*SkuAndNam
|
||||
sqlParams = append(sqlParams, 100, 30)
|
||||
err = GetRows(db, &skuAndNameExt, sql, sqlParams...)
|
||||
for _, v := range skuAndNameExt {
|
||||
var skus []*model.Sku
|
||||
var skus []*StoreSkuExt
|
||||
sql2 := `
|
||||
SELECT *
|
||||
FROM sku
|
||||
WHERE id = ?
|
||||
AND deleted_at = ?
|
||||
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,
|
||||
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,
|
||||
t4.jd_price, t4.ebai_price, t4.mtwm_price, t4.jx_price
|
||||
FROM sku a
|
||||
JOIN sku_name b ON a.name_id = b.id AND b.delete_at = ?
|
||||
JOIN store_sku_bind t4 ON t4.sku_id = a.id AND t4.deleted_at = ?
|
||||
WHERE a.id = ?
|
||||
AND a.deleted_at = ?
|
||||
`
|
||||
sqlParams2 := []interface{}{
|
||||
utils.DefaultTimeValue,
|
||||
v.SkuID,
|
||||
utils.DefaultTimeValue,
|
||||
}
|
||||
if len(storeIDs) > 0 {
|
||||
sql2 += " AND t4.store_id IN(" + GenQuestionMarks(len(storeIDs)) + ")"
|
||||
sqlParams2 = append(sqlParams2, storeIDs)
|
||||
}
|
||||
err = GetRows(db, &skus, sql2, sqlParams2...)
|
||||
v.Skus = skus
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user