- GetMissingStoreSkuFromOrder
This commit is contained in:
@@ -56,10 +56,10 @@ type StoreSkuNamesInfo struct {
|
|||||||
// UpdateStoreSku用,API调用时
|
// UpdateStoreSku用,API调用时
|
||||||
type StoreSkuBindSkuInfo struct {
|
type StoreSkuBindSkuInfo struct {
|
||||||
SkuID int `json:"skuID"`
|
SkuID int `json:"skuID"`
|
||||||
IsSale int `json:"isSale"` // -1:不可售,0:忽略,1:可售
|
IsSale int `json:"isSale,omitempty"` // -1:不可售,0:忽略,1:可售
|
||||||
|
|
||||||
ElmID int64 `json:"elmID"`
|
ElmID int64 `json:"elmID,omitempty"`
|
||||||
EbaiID int64 `json:"ebaiID"`
|
EbaiID int64 `json:"ebaiID,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateStoreSku用,API调用时
|
// UpdateStoreSku用,API调用时
|
||||||
@@ -69,8 +69,8 @@ type StoreSkuBindInfo struct {
|
|||||||
UnitPrice int `json:"unitPrice"` // 对于是份的SKU就是单价(每斤价格),其它则为总价
|
UnitPrice int `json:"unitPrice"` // 对于是份的SKU就是单价(每斤价格),其它则为总价
|
||||||
IsFocus int `json:"isFocus"` // -1:不关注,0:忽略,1:关注
|
IsFocus int `json:"isFocus"` // -1:不关注,0:忽略,1:关注
|
||||||
IsSale int `json:"isSale"` // -1:不可售,0:忽略,1:可售
|
IsSale int `json:"isSale"` // -1:不可售,0:忽略,1:可售
|
||||||
SubStoreID int `json:"subStoreID"`
|
SubStoreID int `json:"subStoreID,omitempty"`
|
||||||
Skus []*StoreSkuBindSkuInfo `json:"skus"`
|
Skus []*StoreSkuBindSkuInfo `json:"skus,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type tStoreSkuBindAndSpec struct {
|
type tStoreSkuBindAndSpec struct {
|
||||||
@@ -1704,3 +1704,28 @@ func SyncJdStoreProducts(ctx *jxcontext.Context, storeIDs, skuIDs []int, isAsync
|
|||||||
}, isContinueWhenError)
|
}, isContinueWhenError)
|
||||||
return hint, err
|
return hint, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetMissingStoreSkuFromOrder(ctx *jxcontext.Context, fromTime time.Time) (missingList []*StoreSkuBindInfo, err error) {
|
||||||
|
storeSkuList, err := dao.GetMissingStoreSkuFromOrder(dao.GetDB(), nil, fromTime)
|
||||||
|
if err == nil {
|
||||||
|
storeSkuNameMap := make(map[int64]*StoreSkuBindInfo)
|
||||||
|
for _, v := range storeSkuList {
|
||||||
|
skuName := storeSkuNameMap[jxutils.Combine2Int(v.StoreID, v.NameID)]
|
||||||
|
if skuName == nil {
|
||||||
|
skuName = &StoreSkuBindInfo{
|
||||||
|
StoreID: v.StoreID,
|
||||||
|
NameID: v.NameID,
|
||||||
|
IsFocus: 1,
|
||||||
|
IsSale: 1,
|
||||||
|
// 这里没有考虑平台价格比例
|
||||||
|
UnitPrice: jxutils.CaculateUnitPrice(v.RefPrice, v.SpecQuality, v.SpecUnit, v.Unit),
|
||||||
|
}
|
||||||
|
missingList = append(missingList, skuName)
|
||||||
|
}
|
||||||
|
skuName.Skus = append(skuName.Skus, &StoreSkuBindSkuInfo{
|
||||||
|
SkuID: v.SkuID,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return missingList, err
|
||||||
|
}
|
||||||
|
|||||||
@@ -576,3 +576,8 @@ func TaskResult2Hint(resultList []interface{}) (hint string) {
|
|||||||
hint = strings.Join(strList, ",")
|
hint = strings.Join(strList, ",")
|
||||||
return hint
|
return hint
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 这个函数用于将两个整数合并为一单一int64,不要用于持久化的场景
|
||||||
|
func Combine2Int(int1, int2 int) (outInt int64) {
|
||||||
|
return int64(int1)*100000 + int64(int2)
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package dao
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
"git.rosy.net.cn/baseapi/utils"
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
"git.rosy.net.cn/jx-callback/business/model"
|
"git.rosy.net.cn/jx-callback/business/model"
|
||||||
@@ -72,6 +73,16 @@ type StoreSkuSyncInfo struct {
|
|||||||
CatPricePercentage int
|
CatPricePercentage int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type MissingStoreSkuInfo struct {
|
||||||
|
StoreID int `orm:"column(store_id)"`
|
||||||
|
NameID int `orm:"column(name_id)"`
|
||||||
|
SkuID int `orm:"column(sku_id)"`
|
||||||
|
SpecQuality float32
|
||||||
|
SpecUnit string
|
||||||
|
Unit string
|
||||||
|
RefPrice int
|
||||||
|
}
|
||||||
|
|
||||||
// 单门店模式厂商适用
|
// 单门店模式厂商适用
|
||||||
// 从store_sku_bind中,得到所有依赖的商家分类信息
|
// 从store_sku_bind中,得到所有依赖的商家分类信息
|
||||||
func GetSkusCategories(db *DaoDB, vendorID, storeID int, skuIDs []int, level int) (cats []*SkuStoreCatInfo, err error) {
|
func GetSkusCategories(db *DaoDB, vendorID, storeID int, skuIDs []int, level int) (cats []*SkuStoreCatInfo, err error) {
|
||||||
@@ -381,3 +392,37 @@ func GetStoresSkusInfo(db *DaoDB, storeIDs, skuIDs []int) (storeSkuList []*model
|
|||||||
err = GetRows(db, &storeSkuList, sql, sqlParams...)
|
err = GetRows(db, &storeSkuList, sql, sqlParams...)
|
||||||
return storeSkuList, err
|
return storeSkuList, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetMissingStoreSkuFromOrder(db *DaoDB, storeIDs []int, fromTime time.Time) (storeSkuList []*MissingStoreSkuInfo, err error) {
|
||||||
|
// if time.Now().Sub(fromTime) > 24*time.Hour*60 {
|
||||||
|
// return nil, fmt.Errorf("GetMissingStoreSkuFromOrder,时间超过60天")
|
||||||
|
// }
|
||||||
|
sql := `
|
||||||
|
SELECT IF(t2.jx_store_id <> 0, t2.jx_store_id, t2.store_id) store_id, t4.name_id, t1.sku_id,
|
||||||
|
t4.spec_quality, t4.spec_unit, t5.unit,
|
||||||
|
COUNT(*) ct, CAST(AVG(IF(t1.vendor_price <> 0, t1.vendor_price, t1.sale_price)) AS SIGNED) ref_price
|
||||||
|
FROM order_sku t1
|
||||||
|
JOIN goods_order t2 ON t2.vendor_order_id = t1.vendor_order_id
|
||||||
|
LEFT JOIN store_sku_bind t3 ON t3.store_id = IF(t2.jx_store_id <> 0, t2.jx_store_id, t2.store_id) AND
|
||||||
|
t3.sku_id = t1.sku_id AND t3.deleted_at = ?
|
||||||
|
JOIN sku t4 ON t4.id = t1.sku_id
|
||||||
|
JOIN sku_name t5 ON t5.id = t4.name_id
|
||||||
|
WHERE t2.status = ? AND IF(t2.jx_store_id <> 0, t2.jx_store_id, t2.store_id) > 0 AND t1.sku_id > 0 AND t1.shop_price = 0 AND
|
||||||
|
t1.order_created_at > ? AND t3.id IS NULL
|
||||||
|
`
|
||||||
|
sqlParams := []interface{}{
|
||||||
|
utils.DefaultTimeValue,
|
||||||
|
model.OrderStatusFinished,
|
||||||
|
fromTime,
|
||||||
|
}
|
||||||
|
if len(storeIDs) > 0 {
|
||||||
|
sql += " AND IF(t2.jx_store_id <> 0, t2.jx_store_id, t2.store_id) IN (" + GenQuestionMarks(len(storeIDs)) + ")"
|
||||||
|
sqlParams = append(sqlParams, storeIDs)
|
||||||
|
}
|
||||||
|
sql += `
|
||||||
|
GROUP BY 1,2,3,4,5,6
|
||||||
|
ORDER BY 1,2,3,4,5,6
|
||||||
|
`
|
||||||
|
err = GetRows(db, &storeSkuList, sql, sqlParams...)
|
||||||
|
return storeSkuList, err
|
||||||
|
}
|
||||||
|
|||||||
@@ -409,3 +409,20 @@ func (c *StoreSkuController) SyncJdStoreProducts() {
|
|||||||
return retVal, "", err
|
return retVal, "", err
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @Title 从订单得到本地没有关注的商品信息
|
||||||
|
// @Description 从订单得到本地没有关注的商品信息
|
||||||
|
// @Param token header string true "认证token"
|
||||||
|
// @Param fromTime query string false "扫描的订单开始时间"
|
||||||
|
// @Success 200 {object} controllers.CallResult
|
||||||
|
// @Failure 200 {object} controllers.CallResult
|
||||||
|
// @router /GetMissingStoreSkuFromOrder [get]
|
||||||
|
func (c *StoreSkuController) GetMissingStoreSkuFromOrder() {
|
||||||
|
c.callGetMissingStoreSkuFromOrder(func(params *tStoreSkuGetMissingStoreSkuFromOrderParams) (retVal interface{}, errCode string, err error) {
|
||||||
|
timeList, err := jxutils.BatchStr2Time(params.FromTime)
|
||||||
|
if err == nil {
|
||||||
|
retVal, err = cms.GetMissingStoreSkuFromOrder(params.Ctx, timeList[0])
|
||||||
|
}
|
||||||
|
return retVal, "", err
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|||||||
@@ -1222,6 +1222,15 @@ func init() {
|
|||||||
Filters: nil,
|
Filters: nil,
|
||||||
Params: nil})
|
Params: nil})
|
||||||
|
|
||||||
|
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreSkuController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreSkuController"],
|
||||||
|
beego.ControllerComments{
|
||||||
|
Method: "GetMissingStoreSkuFromOrder",
|
||||||
|
Router: `/GetMissingStoreSkuFromOrder`,
|
||||||
|
AllowHTTPMethods: []string{"get"},
|
||||||
|
MethodParams: param.Make(),
|
||||||
|
Filters: nil,
|
||||||
|
Params: nil})
|
||||||
|
|
||||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreSkuController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreSkuController"],
|
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreSkuController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreSkuController"],
|
||||||
beego.ControllerComments{
|
beego.ControllerComments{
|
||||||
Method: "GetStoreAbnormalSkuCount",
|
Method: "GetStoreAbnormalSkuCount",
|
||||||
|
|||||||
Reference in New Issue
Block a user