- jd basic api(category, sku, store management) finished.
This commit is contained in:
@@ -2,7 +2,6 @@ package skuman
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"git.rosy.net.cn/jx-callback/business/model"
|
"git.rosy.net.cn/jx-callback/business/model"
|
||||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -18,16 +17,3 @@ func New(sku *model.Sku) *Sku {
|
|||||||
Sku: sku,
|
Sku: sku,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetJdCategoryID(sku *model.Sku) int {
|
|
||||||
cat, _ := dao.GetCategory(sku.CategoryID, nil)
|
|
||||||
jdCategoryID := defJdCategoryID
|
|
||||||
if cat != nil && cat.JdCategoryID != 0 {
|
|
||||||
jdCategoryID = cat.JdCategoryID
|
|
||||||
}
|
|
||||||
return jdCategoryID
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetCategories(sku *model.Sku) []int {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|||||||
48
business/model/dao/dao.go
Normal file
48
business/model/dao/dao.go
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
package dao
|
||||||
|
|
||||||
|
import (
|
||||||
|
"reflect"
|
||||||
|
|
||||||
|
"git.rosy.net.cn/jx-callback/business/model"
|
||||||
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
|
"git.rosy.net.cn/jx-callback/globals/gormdb"
|
||||||
|
"github.com/jinzhu/gorm"
|
||||||
|
)
|
||||||
|
|
||||||
|
func GetEntity(item interface{}, db *gorm.DB) error {
|
||||||
|
if db == nil {
|
||||||
|
db = gormdb.GetDB()
|
||||||
|
}
|
||||||
|
err := utils.CallFuncLogError(func() error {
|
||||||
|
return db.First(item).Error
|
||||||
|
}, reflect.TypeOf(item).Name())
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetSellCities(skuNameID int, vendorID int, db *gorm.DB) (cities []*model.Place, err error) {
|
||||||
|
if db == nil {
|
||||||
|
db = gormdb.GetDB()
|
||||||
|
}
|
||||||
|
sql := `
|
||||||
|
SELECT DISTINCT t3.*
|
||||||
|
FROM sku_name_place_bind t1
|
||||||
|
JOIN place t2 ON t1.place_code = t2.code
|
||||||
|
JOIN place t3 ON (t2.level = 2 AND t2.code = t3.code) OR (t2.level = 1 AND t2.code = t3.parent_code)
|
||||||
|
WHERE t1.sku_name_id = ?
|
||||||
|
`
|
||||||
|
if vendorID == model.VendorIDJD {
|
||||||
|
sql += "AND t3.jd_code <> 0\n"
|
||||||
|
}
|
||||||
|
rows, err := db.Raw(sql, skuNameID).Rows()
|
||||||
|
if err == nil {
|
||||||
|
defer rows.Close()
|
||||||
|
places := make([]*model.Place, 0)
|
||||||
|
for rows.Next() {
|
||||||
|
place := new(model.Place)
|
||||||
|
db.ScanRows(rows, place)
|
||||||
|
places = append(places, place)
|
||||||
|
}
|
||||||
|
return places, nil
|
||||||
|
}
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
package dao
|
|
||||||
|
|
||||||
import (
|
|
||||||
"git.rosy.net.cn/baseapi/utils"
|
|
||||||
"git.rosy.net.cn/jx-callback/business/model"
|
|
||||||
"git.rosy.net.cn/jx-callback/globals/gormdb"
|
|
||||||
"github.com/jinzhu/gorm"
|
|
||||||
)
|
|
||||||
|
|
||||||
func GetCategory(ID int, db *gorm.DB) (*model.SkuCategory, error) {
|
|
||||||
if db == nil {
|
|
||||||
db = gormdb.GetDB()
|
|
||||||
}
|
|
||||||
item := &model.SkuCategory{}
|
|
||||||
item.ID = ID
|
|
||||||
err := utils.CallFuncLogError(func() error {
|
|
||||||
return db.First(item).Error
|
|
||||||
}, "GetCategory")
|
|
||||||
return item, err
|
|
||||||
}
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
package dao
|
|
||||||
|
|
||||||
import (
|
|
||||||
"git.rosy.net.cn/baseapi/utils"
|
|
||||||
"git.rosy.net.cn/jx-callback/business/model"
|
|
||||||
"git.rosy.net.cn/jx-callback/globals/gormdb"
|
|
||||||
"github.com/jinzhu/gorm"
|
|
||||||
)
|
|
||||||
|
|
||||||
func GetStore(ID int, db *gorm.DB) (*model.Store, error) {
|
|
||||||
if db == nil {
|
|
||||||
db = gormdb.GetDB()
|
|
||||||
}
|
|
||||||
item := &model.Store{}
|
|
||||||
item.ID = ID
|
|
||||||
err := utils.CallFuncLogError(func() error {
|
|
||||||
return db.First(item).Error
|
|
||||||
}, "GetStore")
|
|
||||||
return item, err
|
|
||||||
}
|
|
||||||
@@ -63,9 +63,9 @@ type SkuCategory struct {
|
|||||||
Type int8 // 类别类型
|
Type int8 // 类别类型
|
||||||
Seq int
|
Seq int
|
||||||
|
|
||||||
JdID int `gorm:"index"` // 这个是指商家自己的商品类别在京东平台上的ID
|
JdID int64 `gorm:"index"` // 这个是指商家自己的商品类别在京东平台上的ID
|
||||||
JdCategoryID int // 这个是指对应的京东商品类别
|
JdCategoryID int // 这个是指对应的京东商品类别
|
||||||
ElmID string `gorm:"type:varchar(48);index"`
|
ElmID int64 `gorm:"index"`
|
||||||
MtID string `gorm:"type:varchar(48);index"`
|
MtID string `gorm:"type:varchar(48);index"`
|
||||||
DidiID string `gorm:"type:varchar(48);index"`
|
DidiID string `gorm:"type:varchar(48);index"`
|
||||||
}
|
}
|
||||||
@@ -84,6 +84,7 @@ type SkuName struct {
|
|||||||
Name string `gorm:"type:varchar(255)"`
|
Name string `gorm:"type:varchar(255)"`
|
||||||
Comment string `gorm:"type:varchar(255)"`
|
Comment string `gorm:"type:varchar(255)"`
|
||||||
|
|
||||||
|
BrandID int
|
||||||
CategoryID int // 标准类别
|
CategoryID int // 标准类别
|
||||||
Status int
|
Status int
|
||||||
|
|
||||||
@@ -99,17 +100,16 @@ type Sku struct {
|
|||||||
CategoryID int // 特殊类别,一般用于秒杀,特价之类的特殊类别
|
CategoryID int // 特殊类别,一般用于秒杀,特价之类的特殊类别
|
||||||
NameID int `gorm:"index:unique_index_name_Id_quality"` // todo 这个索引应该要求唯一
|
NameID int `gorm:"index:unique_index_name_Id_quality"` // todo 这个索引应该要求唯一
|
||||||
SpecQuality float32 `gorm:"index:unique_index_name_Id_quality"`
|
SpecQuality float32 `gorm:"index:unique_index_name_Id_quality"`
|
||||||
SpecUnit string `gorm:"type:varchar(8)"`
|
SpecUnit string `gorm:"type:varchar(8)"` // 质量或容量
|
||||||
|
Weight int // 重量/质量,单位为克,当相应的SkuName的SpecUnit为g或kg时,必须等于SpecQuality
|
||||||
|
|
||||||
Weight int // 单位为克,当相应的SkuName的SpecUnit为g或kg时,必须等于SpecQuality
|
JdID int64
|
||||||
|
|
||||||
JdID string `gorm:"type:varchar(48)"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type SkuNamePlaceBind struct {
|
type SkuNamePlaceBind struct {
|
||||||
ModelIDCUO
|
ModelIDCUO
|
||||||
SkuNameID int `gorm:"unique_index:unique_sku_name_id_sku_place_id"`
|
SkuNameID int `gorm:"unique_index:unique_sku_name_id_sku_place_id"`
|
||||||
PlaceID int `gorm:"unique_index:unique_sku_name_id_sku_place_id"`
|
PlaceCode int `gorm:"unique_index:unique_sku_name_id_sku_place_id"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type StoreSkuBind struct {
|
type StoreSkuBind struct {
|
||||||
@@ -119,5 +119,6 @@ type StoreSkuBind struct {
|
|||||||
SubStoreID int
|
SubStoreID int
|
||||||
Price int // 单位为分,不用int64的原因是这里不需要累加
|
Price int // 单位为分,不用int64的原因是这里不需要累加
|
||||||
Status int
|
Status int
|
||||||
ElmID string `gorm:"type:varchar(48)"`
|
|
||||||
|
ElmID int64
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,19 +11,29 @@ const (
|
|||||||
MainSubStoreAddress = "本店"
|
MainSubStoreAddress = "本店"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// 配送范围类型,此定义与京东到家相同,除非特殊说明,本系统中的坐标都是火星坐标
|
||||||
|
const (
|
||||||
|
DeliveryRangeTypePolygon = 2
|
||||||
|
DeliveryRangeTypeRadius = 3
|
||||||
|
)
|
||||||
|
|
||||||
type Store struct {
|
type Store struct {
|
||||||
ModelIDCUO
|
ModelIDCUO
|
||||||
Name string `gorm:"type:varchar(255);unique_index"`
|
Name string `gorm:"type:varchar(255);unique_index"`
|
||||||
CityCode int
|
CityCode int // todo ?
|
||||||
DistrictCode int
|
DistrictCode int // todo ?
|
||||||
Address string `gorm:"type:varchar(255)"`
|
Address string `gorm:"type:varchar(255)"`
|
||||||
OpenTime1 int // 930就表示9点半,用两个的原因是为了支持中午休息,1与2的时间段不能交叉,为0表示没有
|
Tel1 string `gorm:"type:varchar(32)"`
|
||||||
CloseTime1 int // 格式同上
|
Tel2 string `gorm:"type:varchar(32)"`
|
||||||
OpenTime2 int // 格式同上
|
OpenTime1 int16 // 930就表示9点半,用两个的原因是为了支持中午休息,1与2的时间段不能交叉,为0表示没有
|
||||||
CloseTime2 int // 格式同上
|
CloseTime1 int16 // 格式同上
|
||||||
Lng int // 乘了10的6次方
|
OpenTime2 int16 // 格式同上
|
||||||
Lat int // 乘了10的6次方
|
CloseTime2 int16 // 格式同上
|
||||||
Status int
|
Lng int // 乘了10的6次方
|
||||||
|
Lat int // 乘了10的6次方
|
||||||
|
DeliveryRangeType int8 // 参见相关常量定义
|
||||||
|
DeliveryRange string `gorm:"type:varchar(2048)"` // 如果DeliveryRangeType为DeliveryRangeTypePolygon,则为逗号分隔坐标,分号分隔的坐标点(坐标与Lng和Lat一样,都是整数),比如 121361504,31189308;121420555,31150238。否则为半径,单位为米
|
||||||
|
Status int
|
||||||
}
|
}
|
||||||
|
|
||||||
type StoreSub struct {
|
type StoreSub struct {
|
||||||
@@ -32,7 +42,7 @@ type StoreSub struct {
|
|||||||
Index int `gorm:"unique_index:unique_index1"` // 子店序号,为0表示主店
|
Index int `gorm:"unique_index:unique_index1"` // 子店序号,为0表示主店
|
||||||
Name string `gorm:"type:varchar(255)"`
|
Name string `gorm:"type:varchar(255)"`
|
||||||
Address string `gorm:"type:varchar(255)"`
|
Address string `gorm:"type:varchar(255)"`
|
||||||
Status int
|
Status int // 取值同Store.Status
|
||||||
Mobile1 string `gorm:"type:varchar(32)"`
|
Mobile1 string `gorm:"type:varchar(32)"`
|
||||||
Mobile2 string `gorm:"type:varchar(32)"`
|
Mobile2 string `gorm:"type:varchar(32)"`
|
||||||
Mobile3 string `gorm:"type:varchar(32)"`
|
Mobile3 string `gorm:"type:varchar(32)"`
|
||||||
@@ -43,7 +53,7 @@ type StoreMap struct {
|
|||||||
StoreID int `gorm:"unique_index:storemap1"`
|
StoreID int `gorm:"unique_index:storemap1"`
|
||||||
VendorID int `gorm:"unique_index:storemap1"`
|
VendorID int `gorm:"unique_index:storemap1"`
|
||||||
VendorStoreID string `gorm:"type:varchar(48);unique_index"`
|
VendorStoreID string `gorm:"type:varchar(48);unique_index"`
|
||||||
Status int
|
Status int // 取值同Store.Status
|
||||||
|
|
||||||
AutoPickup int8 // 是否自动拣货
|
AutoPickup int8 // 是否自动拣货
|
||||||
DeliveryType int8 // 配送类型
|
DeliveryType int8 // 配送类型
|
||||||
|
|||||||
@@ -28,13 +28,13 @@ func OnWaybillMsg(msg *jdapi.CallbackDeliveryStatusMsg) (retVal *jdapi.CallbackR
|
|||||||
return curPurchaseHandler.OnWaybillMsg(msg)
|
return curPurchaseHandler.OnWaybillMsg(msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
func JdOperationTime2JxOperationTime(value1 interface{}) int {
|
func JdOperationTime2JxOperationTime(value1 interface{}) int16 {
|
||||||
value := int(utils.Interface2Int64WithDefault(value1, 0))
|
value := int16(utils.Interface2Int64WithDefault(value1, 0))
|
||||||
return (value/2)*100 + (value%2)*30
|
return (value/2)*100 + (value%2)*30
|
||||||
}
|
}
|
||||||
|
|
||||||
func JxOperationTime2JdOperationTime(value int) int {
|
func JxOperationTime2JdOperationTime(value int16) int16 {
|
||||||
return (value/100)*2 + (value % 30)
|
return (value/100)*2 + (value%100)/30
|
||||||
}
|
}
|
||||||
|
|
||||||
func JdStoreStatus2JxStatus(yn, closeStatus interface{}) int {
|
func JdStoreStatus2JxStatus(yn, closeStatus interface{}) int {
|
||||||
@@ -51,7 +51,7 @@ func JdStoreStatus2JxStatus(yn, closeStatus interface{}) int {
|
|||||||
func JxStoreStatus2JdStatus(status int) (yn, closeStatus int) {
|
func JxStoreStatus2JdStatus(status int) (yn, closeStatus int) {
|
||||||
switch status {
|
switch status {
|
||||||
case model.StoreStatusDisabled:
|
case model.StoreStatusDisabled:
|
||||||
return 1, 0
|
return 1, 1
|
||||||
case model.StoreStatusClosed:
|
case model.StoreStatusClosed:
|
||||||
return 0, 1
|
return 0, 1
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -9,15 +9,17 @@ import (
|
|||||||
"git.rosy.net.cn/jx-callback/globals"
|
"git.rosy.net.cn/jx-callback/globals"
|
||||||
"git.rosy.net.cn/jx-callback/globals/api"
|
"git.rosy.net.cn/jx-callback/globals/api"
|
||||||
"git.rosy.net.cn/jx-callback/globals/beegodb"
|
"git.rosy.net.cn/jx-callback/globals/beegodb"
|
||||||
|
"git.rosy.net.cn/jx-callback/globals/gormdb"
|
||||||
"github.com/astaxie/beego"
|
"github.com/astaxie/beego"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
beego.InitBeegoBeforeTest("/Users/xujianhua/go/src/git.rosy.net.cn/jx-callback/conf/app.conf")
|
beego.InitBeegoBeforeTest("/Users/xujianhua/go/src/git.rosy.net.cn/jx-callback/conf/app.conf")
|
||||||
beego.BConfig.RunMode = "dev" // InitBeegoBeforeTest会将runmode设置为test
|
// beego.BConfig.RunMode = "dev" // InitBeegoBeforeTest会将runmode设置为test
|
||||||
|
|
||||||
globals.Init()
|
globals.Init()
|
||||||
beegodb.Init()
|
beegodb.Init()
|
||||||
|
gormdb.Init()
|
||||||
api.Init()
|
api.Init()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
206
business/partner/purchase/jd/product.go
Normal file
206
business/partner/purchase/jd/product.go
Normal file
@@ -0,0 +1,206 @@
|
|||||||
|
package jd
|
||||||
|
|
||||||
|
// 这里函数取得的信息,除了与自身实体相关的ID(比如PARENT ID),都已经转换成了本地ID了
|
||||||
|
|
||||||
|
import (
|
||||||
|
"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/jx-callback/business/model/dao"
|
||||||
|
"git.rosy.net.cn/jx-callback/globals"
|
||||||
|
"git.rosy.net.cn/jx-callback/globals/api"
|
||||||
|
"git.rosy.net.cn/jx-callback/globals/gormdb"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
DefBrandID = 35247
|
||||||
|
DefJdCategoryID = 20362
|
||||||
|
)
|
||||||
|
|
||||||
|
type skuInfoExt struct {
|
||||||
|
model.SkuName
|
||||||
|
Img string
|
||||||
|
JdID int64 // 商家类别
|
||||||
|
JdCategoryID int // 到家类别
|
||||||
|
SkuCatID int64 // 商家特殊类别
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *PurchaseHandler) CreateCategory(cat *model.SkuCategory, userName string) (err error) {
|
||||||
|
var jdPid int64
|
||||||
|
if cat.ParentID != 0 {
|
||||||
|
pCat := &model.SkuCategory{}
|
||||||
|
pCat.ID = cat.ParentID
|
||||||
|
if err = dao.GetEntity(pCat, nil); err == nil {
|
||||||
|
jdPid = pCat.JdID
|
||||||
|
} else {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
result, err := api.JdAPI.AddShopCategory(jdPid, cat.Name, int(cat.Level), cat.Seq, userName)
|
||||||
|
if err == nil {
|
||||||
|
cat.JdID = utils.Str2Int64(result)
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *PurchaseHandler) ReadCategory(vendorCatID string) (cat *model.SkuCategory, err error) {
|
||||||
|
result, err := p.ReadCategories()
|
||||||
|
if err == nil {
|
||||||
|
jdID := utils.Str2Int64(vendorCatID)
|
||||||
|
for _, v := range result {
|
||||||
|
if v.JdID == jdID {
|
||||||
|
return v, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *PurchaseHandler) ReadCategories() (cats []*model.SkuCategory, err error) {
|
||||||
|
result, err := api.JdAPI.QueryCategoriesByOrgCode()
|
||||||
|
if err == nil {
|
||||||
|
cats = make([]*model.SkuCategory, len(result))
|
||||||
|
for k, v := range result {
|
||||||
|
cats[k] = &model.SkuCategory{
|
||||||
|
ParentID: int(v.ParentId), // 这里是暂存,传递数据用,正确的值应该是本地的ID
|
||||||
|
Name: v.Name,
|
||||||
|
Level: int8(v.Level),
|
||||||
|
Seq: v.Sort,
|
||||||
|
JdID: v.Id,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return cats, nil
|
||||||
|
}
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *PurchaseHandler) UpdateCategory(cat *model.SkuCategory) error {
|
||||||
|
return api.JdAPI.UpdateShopCategory(cat.JdID, cat.Name)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *PurchaseHandler) DeleteCategory(cat *model.SkuCategory) error {
|
||||||
|
return api.JdAPI.DelShopCategory(cat.JdID)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *PurchaseHandler) cuSku(sku *model.Sku, handler func(skuExt *skuInfoExt, skuName string, shopCategories []int64, addParams map[string]interface{}) (string, error)) (err error) {
|
||||||
|
var otherInfo skuInfoExt
|
||||||
|
db := gormdb.GetDB()
|
||||||
|
err = db.Raw(`
|
||||||
|
SELECT t2.*, t3.jd_id, t3.jd_category_id, t4.jd_id sku_cat_id
|
||||||
|
FROM sku t1
|
||||||
|
JOIN sku_name t2 ON t1.name_id = t2.id
|
||||||
|
JOIN sku_category t3 ON t2.category_id = t3.id
|
||||||
|
LEFT JOIN sku_category t4 ON t1.category_id = t4.id
|
||||||
|
WHERE t1.id = ?
|
||||||
|
`, sku.ID).Scan(&otherInfo).Error
|
||||||
|
if err == nil {
|
||||||
|
shopCategories := []int64{otherInfo.JdID}
|
||||||
|
if otherInfo.SkuCatID != 0 {
|
||||||
|
shopCategories = append(shopCategories, otherInfo.SkuCatID)
|
||||||
|
}
|
||||||
|
if otherInfo.JdCategoryID == 0 {
|
||||||
|
otherInfo.JdCategoryID = DefJdCategoryID
|
||||||
|
}
|
||||||
|
if otherInfo.BrandID == 0 {
|
||||||
|
otherInfo.BrandID = DefBrandID
|
||||||
|
}
|
||||||
|
addParams := map[string]interface{}{}
|
||||||
|
|
||||||
|
if otherInfo.IsGlobal == 0 { //如果不是全国可售,要查可售区域
|
||||||
|
sellPlaces, err2 := dao.GetSellCities(otherInfo.ID, model.VendorIDJD, db)
|
||||||
|
if err = err2; err == nil && len(sellPlaces) > 0 {
|
||||||
|
sellCites := make([]int, len(sellPlaces))
|
||||||
|
for k, v := range sellPlaces {
|
||||||
|
sellCites[k] = v.JdCode
|
||||||
|
}
|
||||||
|
addParams["sellCities"] = sellCites
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err == nil {
|
||||||
|
skuName := jxutils.ComposeSkuName(otherInfo.Prefix, otherInfo.Name, otherInfo.Comment, otherInfo.Unit, sku.SpecQuality, sku.SpecUnit, 0)
|
||||||
|
globals.SugarLogger.Debug(skuName)
|
||||||
|
result, err2 := handler(&otherInfo, skuName, shopCategories, addParams)
|
||||||
|
if err = err2; err == nil {
|
||||||
|
sku.JdID = utils.Str2Int64(result)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *PurchaseHandler) CreateSku(sku *model.Sku) (err error) {
|
||||||
|
return p.cuSku(sku, func(skuExt *skuInfoExt, skuName string, shopCategories []int64, addParams map[string]interface{}) (string, error) {
|
||||||
|
return api.JdAPI.AddSku(utils.Int2Str(sku.ID), skuExt.JdCategoryID, shopCategories, skuExt.BrandID, skuName, skuExt.Price, jxutils.IntWeight2Float(sku.Weight), []string{skuExt.Img}, 1, true, addParams)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *PurchaseHandler) ReadSku(vendorSkuID string) (skuName *model.SkuName, sellPlaces []*model.Place, sku *model.Sku, err error) {
|
||||||
|
result, _, err := api.JdAPI.QuerySkuInfos("", int(utils.Str2Int64(vendorSkuID)), 0, 0, false)
|
||||||
|
if err == nil {
|
||||||
|
if len(result) == 1 {
|
||||||
|
mapData := result[0]
|
||||||
|
skuNameStr := utils.Interface2String(mapData["skuName"])
|
||||||
|
prefix, name, comment, specUnit, unit, specQuality := jxutils.SplitSkuName(skuNameStr)
|
||||||
|
if name == "" {
|
||||||
|
name = skuNameStr
|
||||||
|
unit = "份"
|
||||||
|
specUnit = "g"
|
||||||
|
}
|
||||||
|
skuName = &model.SkuName{
|
||||||
|
Prefix: prefix,
|
||||||
|
Name: name,
|
||||||
|
Comment: comment,
|
||||||
|
Unit: unit,
|
||||||
|
Price: int(utils.MustInterface2Int64(mapData["skuPrice"])),
|
||||||
|
}
|
||||||
|
sku = &model.Sku{
|
||||||
|
SpecQuality: specQuality,
|
||||||
|
SpecUnit: specUnit,
|
||||||
|
Weight: jxutils.FloatWeight2Int(float32(utils.MustInterface2Float64(mapData["weight"]))),
|
||||||
|
JdID: utils.MustInterface2Int64(mapData["skuId"]),
|
||||||
|
}
|
||||||
|
sku.ID = int(utils.Str2Int64(utils.Interface2String(mapData["outSkuId"])))
|
||||||
|
|
||||||
|
db := gormdb.GetDB()
|
||||||
|
shopCategories := utils.Interface2Int64List(mapData["shopCategories"])
|
||||||
|
if len(shopCategories) > 0 {
|
||||||
|
skuCat := &model.SkuCategory{}
|
||||||
|
if db.Where("jd_id = ?", shopCategories[0]).Find(skuCat).Error == nil {
|
||||||
|
skuName.CategoryID = skuCat.ID
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sellCities := utils.Interface2Int64List(mapData["sellCities"])
|
||||||
|
if len(sellCities) == 0 {
|
||||||
|
skuName.IsGlobal = 1
|
||||||
|
} else {
|
||||||
|
sellPlaces = make([]*model.Place, 0)
|
||||||
|
err2 := db.Where("jd_code IN (?) AND level = 2", sellCities).Find(&sellPlaces).Error
|
||||||
|
globals.SugarLogger.Debug("err2:%v", err2)
|
||||||
|
}
|
||||||
|
return skuName, sellPlaces, sku, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil, nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *PurchaseHandler) UpdateSku(sku *model.Sku) (err error) {
|
||||||
|
return p.cuSku(sku, func(skuExt *skuInfoExt, skuName string, shopCategories []int64, addParams map[string]interface{}) (string, error) {
|
||||||
|
params := utils.MergeMaps(addParams)
|
||||||
|
params["categoryId"] = skuExt.JdCategoryID
|
||||||
|
params["shopCategories"] = shopCategories
|
||||||
|
params["brandId"] = skuExt.BrandID
|
||||||
|
params["skuName"] = skuName
|
||||||
|
params["weight"] = jxutils.IntWeight2Float(sku.Weight)
|
||||||
|
params["images"] = []string{skuExt.Img}
|
||||||
|
|
||||||
|
return api.JdAPI.UpdateSku(utils.Int2Str(sku.ID), params)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *PurchaseHandler) DeleteSku(sku *model.Sku) (err error) {
|
||||||
|
params := map[string]interface{}{
|
||||||
|
"fixedStatus": 4,
|
||||||
|
}
|
||||||
|
_, err = api.JdAPI.UpdateSku(utils.Int2Str(sku.ID), params)
|
||||||
|
return err
|
||||||
|
}
|
||||||
56
business/partner/purchase/jd/product_test.go
Normal file
56
business/partner/purchase/jd/product_test.go
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
package jd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
|
"git.rosy.net.cn/jx-callback/business/model"
|
||||||
|
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestCreateSku(t *testing.T) {
|
||||||
|
// t.Log(beego.BConfig.RunMode)
|
||||||
|
skuID := 21741
|
||||||
|
sku := &model.Sku{}
|
||||||
|
sku.ID = skuID
|
||||||
|
dao.GetEntity(sku, nil)
|
||||||
|
t.Log(sku)
|
||||||
|
// err := new(PurchaseHandler).CreateSku(sku)
|
||||||
|
// if err != nil {
|
||||||
|
// t.Fatal(err.Error())
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestUpdateSku(t *testing.T) {
|
||||||
|
// t.Log(beego.BConfig.RunMode)
|
||||||
|
skuID := 21741
|
||||||
|
sku := &model.Sku{}
|
||||||
|
sku.ID = skuID
|
||||||
|
dao.GetEntity(sku, nil)
|
||||||
|
|
||||||
|
err := new(PurchaseHandler).UpdateSku(sku)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestReadCategories(t *testing.T) {
|
||||||
|
result, err := new(PurchaseHandler).ReadCategories()
|
||||||
|
if err != nil || len(result) == 0 {
|
||||||
|
t.Fatal(err.Error())
|
||||||
|
}
|
||||||
|
t.Log(result[0])
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestReadSku(t *testing.T) {
|
||||||
|
skuName, sellCites, sku, err := new(PurchaseHandler).ReadSku("2018544585")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err.Error())
|
||||||
|
}
|
||||||
|
if skuName.Name != "每日鲜*脊骨" || sellCites[0].Name != "武汉市" || sku.SpecUnit != "g" {
|
||||||
|
t.Fatal("ReadSku return data wrong")
|
||||||
|
t.Log(string(utils.MustMarshal(skuName)))
|
||||||
|
t.Log(string(utils.MustMarshal(sellCites)))
|
||||||
|
t.Log(string(utils.MustMarshal(sku)))
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,11 @@
|
|||||||
package jd
|
package jd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||||
|
|
||||||
"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"
|
||||||
"git.rosy.net.cn/jx-callback/globals/api"
|
"git.rosy.net.cn/jx-callback/globals/api"
|
||||||
@@ -18,8 +23,18 @@ func (p *PurchaseHandler) ReadStore(vendorStoreID string) (*model.Store, error)
|
|||||||
CloseTime2: JdOperationTime2JxOperationTime(result["serviceTimeEnd2"]),
|
CloseTime2: JdOperationTime2JxOperationTime(result["serviceTimeEnd2"]),
|
||||||
Status: JdStoreStatus2JxStatus(result["yn"], result["closeStatus"]),
|
Status: JdStoreStatus2JxStatus(result["yn"], result["closeStatus"]),
|
||||||
}
|
}
|
||||||
|
|
||||||
retVal.ID = int(utils.Str2Int64WithDefault(utils.Interface2String(result["outSystemId"]), 0))
|
retVal.ID = int(utils.Str2Int64WithDefault(utils.Interface2String(result["outSystemId"]), 0))
|
||||||
return retVal, nil
|
result, err2 := api.JdAPI.GetDeliveryRangeByStationNo(vendorStoreID)
|
||||||
|
if err = err2; err == nil {
|
||||||
|
retVal.DeliveryRangeType = int8(utils.MustInterface2Int64(result["deliveryRangeType"]))
|
||||||
|
if retVal.DeliveryRangeType == model.DeliveryRangeTypePolygon {
|
||||||
|
retVal.DeliveryRange = JdRange2JxRange(utils.Interface2String(result["deliveryRange"]))
|
||||||
|
} else {
|
||||||
|
retVal.DeliveryRange = utils.Int64ToStr(utils.MustInterface2Int64(result["deliveryRangeRadius"]))
|
||||||
|
}
|
||||||
|
return retVal, nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -31,8 +46,19 @@ func (p *PurchaseHandler) UpdateStore(vendorStoreID string, store *model.Store,
|
|||||||
"stationAddress": store.Address,
|
"stationAddress": store.Address,
|
||||||
"serviceTimeStart1": JxOperationTime2JdOperationTime(store.OpenTime1),
|
"serviceTimeStart1": JxOperationTime2JdOperationTime(store.OpenTime1),
|
||||||
"serviceTimeEnd1": JxOperationTime2JdOperationTime(store.CloseTime1),
|
"serviceTimeEnd1": JxOperationTime2JdOperationTime(store.CloseTime1),
|
||||||
"serviceTimeStart2": JxOperationTime2JdOperationTime(store.OpenTime2),
|
"deliveryRangeType": store.DeliveryRangeType,
|
||||||
"serviceTimeEnd2": JxOperationTime2JdOperationTime(store.CloseTime2),
|
"coordinateType": 3, // 一直用高德
|
||||||
|
}
|
||||||
|
if store.DeliveryRangeType == model.DeliveryRangeTypePolygon {
|
||||||
|
params["coordinatePoints"] = JxRange2JdRange(store.DeliveryRange)
|
||||||
|
} else {
|
||||||
|
params["deliveryRangeRadius"] = utils.Str2Int64(store.DeliveryRange)
|
||||||
|
}
|
||||||
|
|
||||||
|
openTime2 := JxOperationTime2JdOperationTime(store.OpenTime2)
|
||||||
|
if openTime2 != 0 {
|
||||||
|
params["serviceTimeStart2"] = openTime2
|
||||||
|
params["serviceTimeEnd2"] = JxOperationTime2JdOperationTime(store.CloseTime2)
|
||||||
}
|
}
|
||||||
_, params["closeStatus"] = JxStoreStatus2JdStatus(store.Status)
|
_, params["closeStatus"] = JxStoreStatus2JdStatus(store.Status)
|
||||||
// globals.SugarLogger.Debug(utils.Format4Output(params, false))
|
// globals.SugarLogger.Debug(utils.Format4Output(params, false))
|
||||||
@@ -44,8 +70,7 @@ func (p *PurchaseHandler) UpdateStore(vendorStoreID string, store *model.Store,
|
|||||||
// params := map[string]interface{}{
|
// params := map[string]interface{}{
|
||||||
// "yn": 1,
|
// "yn": 1,
|
||||||
// }
|
// }
|
||||||
// _, err := api.JdAPI.UpdateStoreInfo4Open(vendorStoreID, userName, params)
|
// return api.JdAPI.UpdateStoreInfo4Open(vendorStoreID, userName, params)
|
||||||
// return err
|
|
||||||
// }
|
// }
|
||||||
|
|
||||||
func (p *PurchaseHandler) EnableAutoAcceptOrder(vendorStoreID string, isEnabled bool) error {
|
func (p *PurchaseHandler) EnableAutoAcceptOrder(vendorStoreID string, isEnabled bool) error {
|
||||||
@@ -91,3 +116,31 @@ func (p *PurchaseHandler) GetAllStoresFromRemote() ([]*model.Store, error) {
|
|||||||
}
|
}
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func JdRange2JxRange(jdRanges string) (jxRanges string) {
|
||||||
|
coords := strings.Split(jdRanges, ";")
|
||||||
|
intCoords := []string{}
|
||||||
|
for _, coord := range coords {
|
||||||
|
items := strings.Split(coord, ",")
|
||||||
|
if len(items) == 2 {
|
||||||
|
lng := jxutils.StandardCoordinate2Int(utils.Str2Float64(items[0]))
|
||||||
|
lat := jxutils.StandardCoordinate2Int(utils.Str2Float64(items[1]))
|
||||||
|
intCoords = append(intCoords, fmt.Sprintf("%d,%d", lng, lat))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return strings.Join(intCoords, ";")
|
||||||
|
}
|
||||||
|
|
||||||
|
func JxRange2JdRange(jxRanges string) (jdRanges string) {
|
||||||
|
coords := strings.Split(jxRanges, ";")
|
||||||
|
intCoords := []string{}
|
||||||
|
for _, coord := range coords {
|
||||||
|
items := strings.Split(coord, ",")
|
||||||
|
if len(items) == 2 {
|
||||||
|
lng := jxutils.IntCoordinate2Standard(int(utils.Str2Int64(items[0])))
|
||||||
|
lat := jxutils.IntCoordinate2Standard(int(utils.Str2Int64(items[1])))
|
||||||
|
intCoords = append(intCoords, fmt.Sprintf("%f,%f", lng, lat))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return strings.Join(intCoords, ";")
|
||||||
|
}
|
||||||
|
|||||||
77
business/partner/purchase/jd/store_test.go
Normal file
77
business/partner/purchase/jd/store_test.go
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
package jd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
TestStoreNo = "11736989"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestReadStore(t *testing.T) {
|
||||||
|
result, err := new(PurchaseHandler).ReadStore(TestStoreNo)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err.Error())
|
||||||
|
}
|
||||||
|
t.Log(result)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCloseStore(t *testing.T) {
|
||||||
|
err := new(PurchaseHandler).CloseStore(TestStoreNo, "我就是想休息一下", "test")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestOpenStore(t *testing.T) {
|
||||||
|
err := new(PurchaseHandler).OpenStore(TestStoreNo, "test")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestUpdateStore(t *testing.T) {
|
||||||
|
handler := new(PurchaseHandler)
|
||||||
|
result, err := handler.ReadStore(TestStoreNo)
|
||||||
|
|
||||||
|
// result := &model.Store{}
|
||||||
|
// result.ID = 100164
|
||||||
|
// err := dao.GetEntity(result, nil)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err.Error())
|
||||||
|
}
|
||||||
|
result.Name += "h"
|
||||||
|
newName := result.Name
|
||||||
|
err = handler.UpdateStore(TestStoreNo, result, "ttt")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
// same
|
||||||
|
result, err = handler.ReadStore(TestStoreNo)
|
||||||
|
if result.Name != newName {
|
||||||
|
t.Fatalf("result is not same, desired newName:%s, newName:%s", newName, result.Name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// restore
|
||||||
|
result.Name = strings.Trim(result.Name, "h")
|
||||||
|
err = handler.UpdateStore(TestStoreNo, result, "ttt")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCoordRangeConversion(t *testing.T) {
|
||||||
|
jxRange := "108841759,34332892;108842271,34330820;108846013,34331422;108846110,34333189;108847722,34331853;108856703,34331729;108866149,34327507;108873423,34320980;108877737,34312856;108877727,34299624;108870105,34287988;108855137,34290911;108867884,34286298;108858260,34281316;108854162,34283490;108853803,34280145;108846110,34279291;108830587,34282539;108818806,34291500;108814493,34299624;108813596,34308465;108818797,34320980;108830582,34329941;108841759,34332892"
|
||||||
|
jdRange := "108.841759,34.332892;108.842271,34.330820;108.846013,34.331422;108.846110,34.333189;108.847722,34.331853;108.856703,34.331729;108.866149,34.327507;108.873423,34.320980;108.877737,34.312856;108.877727,34.299624;108.870105,34.287988;108.855137,34.290911;108.867884,34.286298;108.858260,34.281316;108.854162,34.283490;108.853803,34.280145;108.846110,34.279291;108.830587,34.282539;108.818806,34.291500;108.814493,34.299624;108.813596,34.308465;108.818797,34.320980;108.830582,34.329941;108.841759,34.332892"
|
||||||
|
|
||||||
|
if JdRange2JxRange(jdRange) != jxRange {
|
||||||
|
t.Fatal("result doesn't match")
|
||||||
|
}
|
||||||
|
|
||||||
|
if JxRange2JdRange(jxRange) != jdRange {
|
||||||
|
t.Fatal("result doesn't match")
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user