- store man almost ok.
This commit is contained in:
@@ -89,7 +89,7 @@ func BindMobile(token, mobileNum, code string) (err error) {
|
||||
user := &model.WeiXins{
|
||||
OpenID: loginInfo.ID,
|
||||
}
|
||||
err = dao.UpdateEntityByKV(nil, user, utils.Params2Map("Tel", mobileNum), utils.Params2Map("OpenID", loginInfo.ID))
|
||||
_, err = dao.UpdateEntityByKV(nil, user, utils.Params2Map("Tel", mobileNum), utils.Params2Map("OpenID", loginInfo.ID))
|
||||
}
|
||||
err = errors.New("验证码错")
|
||||
}
|
||||
|
||||
@@ -2,8 +2,15 @@ package cms
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/business/jxcallback/scheduler/basesch"
|
||||
"git.rosy.net.cn/jx-callback/business/partner"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrHaveNotImplementedYet = errors.New("还没有实现")
|
||||
)
|
||||
|
||||
func GetPurchaseHandler(vendorID int) partner.IPurchasePlatformHandler {
|
||||
return basesch.FixedBaseScheduler.GetPurchasePlatformFromVendorID(vendorID)
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package cms
|
||||
import (
|
||||
"errors"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
@@ -17,6 +18,9 @@ type StoreExt struct {
|
||||
model.Store
|
||||
CityName string `json:"cityName"`
|
||||
DistrictName string `json:"districtName"`
|
||||
JdID string `orm:"column(jd_id)" json:"jdID"`
|
||||
ElmID string `orm:"column(elm_id)" json:"elmID"`
|
||||
EbaiID string `orm:"column(ebai_id)" json:"ebaiID"`
|
||||
}
|
||||
|
||||
type StoresInfo struct {
|
||||
@@ -45,13 +49,13 @@ func GetPlaces(parentCode int, vendorID int, includeDisabled bool) ([]*model.Pla
|
||||
return places, dao.GetRows(db, &places, sql+"AND parent_code = ?", parentCode)
|
||||
}
|
||||
|
||||
func UpdatePlaces(places []map[string]interface{}, userName string) (err error) {
|
||||
func UpdatePlaces(places []map[string]interface{}, userName string) (num int64, err error) {
|
||||
if len(places) == 0 {
|
||||
return ErrMissingInput
|
||||
return 0, ErrMissingInput
|
||||
}
|
||||
for _, place := range places {
|
||||
if place["code"] == nil {
|
||||
return ErrMissingInput
|
||||
return 0, ErrMissingInput
|
||||
}
|
||||
placeid := &model.Place{}
|
||||
globals.SugarLogger.Debug(utils.Format4Output(place, false))
|
||||
@@ -59,11 +63,16 @@ func UpdatePlaces(places []map[string]interface{}, userName string) (err error)
|
||||
valid["updatedAt"] = time.Now()
|
||||
valid["lastOperator"] = userName
|
||||
globals.SugarLogger.Debug(valid)
|
||||
if err = dao.UpdateEntityByKV(nil, placeid, valid, utils.Params2Map("Code", place["code"])); err != nil {
|
||||
return err
|
||||
if num, err = dao.UpdateEntityByKV(nil, placeid, valid, utils.Params2Map("Code", place["code"])); err != nil {
|
||||
return num, err
|
||||
}
|
||||
}
|
||||
return err
|
||||
return num, err
|
||||
}
|
||||
|
||||
func UpdatePlace(placeCode int, payload map[string]interface{}, userName string) (num int64, err error) {
|
||||
payload["code"] = placeCode
|
||||
return UpdatePlaces([]map[string]interface{}{payload}, userName)
|
||||
}
|
||||
|
||||
func GetStores(keyword string, params map[string]interface{}, offset, pageSize int) (retVal *StoresInfo, err error) {
|
||||
@@ -71,17 +80,19 @@ func GetStores(keyword string, params map[string]interface{}, offset, pageSize i
|
||||
FROM store t1
|
||||
LEFT JOIN place city ON t1.city_code = city.code AND city.level = 2
|
||||
LEFT JOIN place district ON t1.district_code = district.code AND district.level = 3
|
||||
LEFT JOIN store_map jdm ON t1.id = jdm.store_id AND jdm.vendor_id = 0
|
||||
LEFT JOIN store_map elmm ON t1.id = elmm.store_id AND elmm.vendor_id = 2
|
||||
LEFT JOIN store_map ebaim ON t1.id = ebaim.store_id AND ebaim.vendor_id = 3
|
||||
WHERE`
|
||||
|
||||
params2 := make([]interface{}, 0)
|
||||
sqlParams := make([]interface{}, 0)
|
||||
if keyword != "" {
|
||||
keywordLike := "%" + keyword + "%"
|
||||
sql += " (t1.name LIKE ? OR t1.address LIKE ? OR t1.tel1 LIKE ? OR t1.tel2 LIKE ? OR t1.last_operator LIKE ? OR city.name LIKE ?"
|
||||
params2 = append(params2, keywordLike, keywordLike, keywordLike, keywordLike, keywordLike, keywordLike)
|
||||
sqlParams = append(sqlParams, keywordLike, keywordLike, keywordLike, keywordLike, keywordLike, keywordLike)
|
||||
|
||||
if keywordInt64, err2 := strconv.ParseInt(keyword, 10, 64); err2 == nil {
|
||||
sql += " OR t1.id = ? OR t1.city_code = ? OR t1.district_code = ? OR t1.lng = ? OR t1.lat = ?"
|
||||
params2 = append(params2, keywordInt64, keywordInt64, keywordInt64, keywordInt64, keywordInt64)
|
||||
sqlParams = append(sqlParams, keywordInt64, keywordInt64, keywordInt64, keywordInt64, keywordInt64)
|
||||
}
|
||||
sql += ")"
|
||||
} else {
|
||||
@@ -90,11 +101,11 @@ func GetStores(keyword string, params map[string]interface{}, offset, pageSize i
|
||||
|
||||
if params["id"] != nil {
|
||||
sql += " AND t1.id = ?"
|
||||
params2 = append(params2, params["id"].(int))
|
||||
sqlParams = append(sqlParams, params["id"].(int))
|
||||
}
|
||||
if params["name"] != nil {
|
||||
sql += " AND t1.name LIKE ?"
|
||||
params2 = append(params2, "%"+params["name"].(string)+"%")
|
||||
sqlParams = append(sqlParams, "%"+params["name"].(string)+"%")
|
||||
}
|
||||
if params["placeID"] != nil {
|
||||
level := 2
|
||||
@@ -106,16 +117,16 @@ func GetStores(keyword string, params map[string]interface{}, offset, pageSize i
|
||||
} else {
|
||||
sql += " AND t1.district_code = ?"
|
||||
}
|
||||
params2 = append(params2, params["placeID"].(int))
|
||||
sqlParams = append(sqlParams, params["placeID"].(int))
|
||||
}
|
||||
if params["address"] != nil {
|
||||
sql += " AND t1.address LIKE ?"
|
||||
params2 = append(params2, "%"+params["address"].(string)+"%")
|
||||
sqlParams = append(sqlParams, "%"+params["address"].(string)+"%")
|
||||
}
|
||||
if params["tel"] != nil {
|
||||
sql += " AND (t1.tel1 LIKE ? OR t1.tel2 LIKE ?)"
|
||||
params2 = append(params2, "%"+params["tel"].(string)+"%")
|
||||
params2 = append(params2, "%"+params["tel"].(string)+"%")
|
||||
sqlParams = append(sqlParams, "%"+params["tel"].(string)+"%")
|
||||
sqlParams = append(sqlParams, "%"+params["tel"].(string)+"%")
|
||||
}
|
||||
if params["fromStatus"] != nil {
|
||||
fromStatus := params["fromStatus"].(int)
|
||||
@@ -124,7 +135,30 @@ func GetStores(keyword string, params map[string]interface{}, offset, pageSize i
|
||||
toStatus = params["toStatus"].(int)
|
||||
}
|
||||
sql += " AND t1.status >= ? AND t1.status <= ?"
|
||||
params2 = append(params2, fromStatus, toStatus)
|
||||
sqlParams = append(sqlParams, fromStatus, toStatus)
|
||||
}
|
||||
if vendorStoreCond := strings.ToUpper(utils.Interface2String(params["vendorStoreCond"])); vendorStoreCond == "AND" || vendorStoreCond == "OR" {
|
||||
if vendorStoreCond == "AND" {
|
||||
sql += " AND ( 1 = 1"
|
||||
} else {
|
||||
sql += " AND ( 1 = 0"
|
||||
}
|
||||
condMap := map[string]int{
|
||||
"jdm": utils.Interface2DirectIntWithDefault(params["jdCond"], 0),
|
||||
"elmm": utils.Interface2DirectIntWithDefault(params["elmCond"], 0),
|
||||
"ebaim": utils.Interface2DirectIntWithDefault(params["ebaiCond"], 0),
|
||||
}
|
||||
for tableName, cond := range condMap {
|
||||
if cond != 0 {
|
||||
sql += " " + vendorStoreCond + " " + tableName
|
||||
}
|
||||
if cond == -1 {
|
||||
sql += ".vendor_store_id IS NULL"
|
||||
} else if cond == 1 {
|
||||
sql += ".vendor_store_id IS NOT NULL"
|
||||
}
|
||||
}
|
||||
sql += ")"
|
||||
}
|
||||
sqlCount := "SELECT COUNT(*) ct\n" + sql
|
||||
type tcount struct {
|
||||
@@ -132,8 +166,8 @@ func GetStores(keyword string, params map[string]interface{}, offset, pageSize i
|
||||
}
|
||||
countInfo := []tcount{}
|
||||
db := dao.GetDB()
|
||||
if err = dao.GetRows(db, &countInfo, sqlCount, params2...); err == nil {
|
||||
sqlData := "SELECT t1.*, city.name city_name, district.name district_name\n" + sql + `
|
||||
if err = dao.GetRows(db, &countInfo, sqlCount, sqlParams...); err == nil {
|
||||
sqlData := "SELECT t1.*, city.name city_name, district.name district_name, jdm.vendor_store_id jd_id, elmm.vendor_store_id elm_id, ebaim.vendor_store_id ebai_id\n" + sql + `
|
||||
ORDER BY id
|
||||
LIMIT ? OFFSET ?`
|
||||
if pageSize == 0 {
|
||||
@@ -142,11 +176,11 @@ func GetStores(keyword string, params map[string]interface{}, offset, pageSize i
|
||||
if offset < 0 {
|
||||
offset = 0
|
||||
}
|
||||
params2 = append(params2, pageSize, offset)
|
||||
sqlParams = append(sqlParams, pageSize, offset)
|
||||
retVal := &StoresInfo{
|
||||
TotalCount: countInfo[0].Ct,
|
||||
}
|
||||
err = dao.GetRows(db, &retVal.Stores, sqlData, params2...)
|
||||
err = dao.GetRows(db, &retVal.Stores, sqlData, sqlParams...)
|
||||
return retVal, err
|
||||
}
|
||||
return nil, err
|
||||
@@ -174,18 +208,23 @@ func GetVendorStore(vendorStoreID string, vendorID int) (retVal *StoreExt, err e
|
||||
return nil, ErrCanNotVendor
|
||||
}
|
||||
|
||||
func UpdateStore(params map[string]interface{}, userName string) (err error) {
|
||||
func UpdateStore(storeID int, payload map[string]interface{}, userName string) (num int64, err error) {
|
||||
store := &model.Store{}
|
||||
if params["id"] == nil {
|
||||
return ErrMissingInput
|
||||
store.ID = storeID
|
||||
valid := jxutils.NormalMakeMapByStructObject(payload, &model.Store{}, userName)
|
||||
db := dao.GetDB()
|
||||
globals.SugarLogger.Debug("1")
|
||||
if num, err = dao.UpdateEntityByKV(db, store, valid, nil); err == nil {
|
||||
globals.SugarLogger.Debug("2")
|
||||
dummy := &model.StoreMap{}
|
||||
_, err2 := dao.UpdateEntityByKV(db, dummy, utils.Params2Map("SyncStatus", 2), utils.Params2Map("StoreID", store.ID))
|
||||
if err = err2; err == nil {
|
||||
if err = dao.GetEntity(db, store); err == nil {
|
||||
err = SyncStore2Vendor(db, -1, store, false, userName)
|
||||
}
|
||||
}
|
||||
}
|
||||
params["lastOperator"] = userName
|
||||
params["updatedAt"] = time.Now()
|
||||
|
||||
store.ID = int(utils.MustInterface2Int64(params["id"]))
|
||||
valid, _ := jxutils.NormalFilterMapByStructObject(params, &model.Store{})
|
||||
err = dao.UpdateEntityByKV(nil, store, valid, nil)
|
||||
return err
|
||||
return num, err
|
||||
}
|
||||
|
||||
func CreateStore(store *model.Store, userName string) (id int, err error) {
|
||||
@@ -198,3 +237,57 @@ func CreateStore(store *model.Store, userName string) (id int, err error) {
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
|
||||
func SyncStore2Vendor(db *dao.DaoDB, vendorID int, store *model.Store, isForce bool, userName string) (err error) {
|
||||
storeMaps, err := GetStoreVendorMaps(db, store.ID)
|
||||
if err == nil {
|
||||
// globals.SugarLogger.Debug(utils.Format4Output(store, false))
|
||||
for _, storeMap := range storeMaps {
|
||||
if (vendorID == -1 || storeMap.VendorID == vendorID) && (isForce || storeMap.SyncStatus != 0) {
|
||||
if err = GetPurchaseHandler(storeMap.VendorID).UpdateStore(storeMap.VendorStoreID, store, userName); err == nil {
|
||||
storeMap.SyncStatus = 0
|
||||
dao.UpdateEntity(db, storeMap, "SyncStatus")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func GetStoreVendorMaps(db *dao.DaoDB, storeID int) (storeMaps []*model.StoreMap, err error) {
|
||||
err = dao.GetRows(db, &storeMaps, "SELECT * FROM store_map WHERE store_id = ?", storeID)
|
||||
return storeMaps, err
|
||||
}
|
||||
|
||||
func AddStoreVendorMap(db *dao.DaoDB, storeMap *model.StoreMap, userName string) (outStoreMap *model.StoreMap, err error) {
|
||||
store, err := GetPurchaseHandler(storeMap.VendorID).ReadStore(storeMap.VendorStoreID)
|
||||
if err == nil {
|
||||
storeMap.DeliveryType = store.DeliveryType
|
||||
outStoreMap = storeMap
|
||||
if err = dao.CreateEntity(db, storeMap); err == nil {
|
||||
|
||||
}
|
||||
}
|
||||
return outStoreMap, err
|
||||
}
|
||||
|
||||
func DeleteStoreVendorMap(db *dao.DaoDB, storeID, vendorID int, userName string) (num int64, err error) {
|
||||
storeMap := &model.StoreMap{}
|
||||
return dao.DeleteEntity(db, storeMap, utils.Params2Map("StoreID", storeID, "VendorID", vendorID))
|
||||
}
|
||||
|
||||
func UpdateStoreVendorMap(db *dao.DaoDB, storeID, vendorID int, payload map[string]interface{}, userName string) (num int64, err error) {
|
||||
if vendorStoreID := utils.Interface2String(payload["vendorStoreID"]); vendorStoreID != "" {
|
||||
store, err2 := GetPurchaseHandler(vendorID).ReadStore(vendorStoreID)
|
||||
if err = err2; err == nil {
|
||||
payload["deliveryType"] = store.DeliveryType
|
||||
}
|
||||
}
|
||||
if err == nil {
|
||||
dummy := &model.StoreMap{}
|
||||
valid := jxutils.NormalMakeMapByStructObject(payload, dummy, userName)
|
||||
globals.SugarLogger.Debug(utils.Format4Output(valid, false))
|
||||
num, err = dao.UpdateEntityByKV(db, dummy, valid, utils.Params2Map("StoreID", storeID, "VendorID", vendorID))
|
||||
}
|
||||
return num, err
|
||||
}
|
||||
|
||||
@@ -316,7 +316,7 @@ func FilterMapByStructObject(mapData map[string]interface{}, obj interface{}, ex
|
||||
}
|
||||
|
||||
func NormalFilterMapByStructObject(mapData map[string]interface{}, obj interface{}) (valid map[string]interface{}, invalid map[string]interface{}) {
|
||||
return FilterMapByStructObject(mapData, obj, []string{"id", "createdAt"})
|
||||
return FilterMapByStructObject(mapData, obj, []string{"id", "createdAt", "syncStatus", "lastOperator", "updatedAt", "finishedAt"})
|
||||
}
|
||||
|
||||
func FilterMapByFieldList(mapData map[string]interface{}, fields []string) (valid map[string]interface{}, invalid map[string]interface{}) {
|
||||
@@ -335,3 +335,10 @@ func FilterMapByFieldList(mapData map[string]interface{}, fields []string) (vali
|
||||
func GetObjFieldByName(obj interface{}, fieldName string) interface{} {
|
||||
return reflect.Indirect(reflect.ValueOf(obj)).FieldByName(fieldName).Interface()
|
||||
}
|
||||
|
||||
func NormalMakeMapByStructObject(mapData map[string]interface{}, obj interface{}, userName string) (retVal map[string]interface{}) {
|
||||
retVal, _ = NormalFilterMapByStructObject(mapData, obj)
|
||||
retVal["lastOperator"] = userName
|
||||
retVal["updatedAt"] = time.Now()
|
||||
return retVal
|
||||
}
|
||||
|
||||
@@ -7,7 +7,8 @@ const (
|
||||
VendorIDJD = 0
|
||||
VendorIDMTWM = 1
|
||||
VendorIDELM = 2
|
||||
VendorIDPurchaseEnd = 2
|
||||
VendorIDEBAI = 3
|
||||
VendorIDPurchaseEnd = 3
|
||||
|
||||
VendorIDDeliveryBegin = 101
|
||||
VendorIDDada = 101
|
||||
|
||||
@@ -77,22 +77,22 @@ func GetEntity(db *DaoDB, item interface{}, cols ...string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func UpdateEntity(db *DaoDB, item interface{}, cols ...string) error {
|
||||
func UpdateEntity(db *DaoDB, item interface{}, cols ...string) (num int64, err error) {
|
||||
if db == nil {
|
||||
db = GetDB()
|
||||
}
|
||||
err := utils.CallFuncLogError(func() error {
|
||||
_, err2 := db.db.Update(item, cols...)
|
||||
return err2
|
||||
err = utils.CallFuncLogError(func() error {
|
||||
num, err = db.db.Update(item, cols...)
|
||||
return err
|
||||
}, reflect.TypeOf(item).Name())
|
||||
return err
|
||||
return num, err
|
||||
}
|
||||
|
||||
func UpdateEntityByKV(db *DaoDB, item interface{}, kvs map[string]interface{}, conditions map[string]interface{}) error {
|
||||
func UpdateEntityByKV(db *DaoDB, item interface{}, kvs map[string]interface{}, conditions map[string]interface{}) (num int64, err error) {
|
||||
if db == nil {
|
||||
db = GetDB()
|
||||
}
|
||||
err := utils.CallFuncLogError(func() error {
|
||||
err = utils.CallFuncLogError(func() error {
|
||||
qs := db.db.QueryTable(item)
|
||||
if conditions == nil {
|
||||
qs = qs.Filter("id", jxutils.GetObjFieldByName(item, "ID"))
|
||||
@@ -101,10 +101,10 @@ func UpdateEntityByKV(db *DaoDB, item interface{}, kvs map[string]interface{}, c
|
||||
qs = qs.Filter(k, v)
|
||||
}
|
||||
}
|
||||
_, err2 := qs.Update(kvs)
|
||||
return err2
|
||||
num, err = qs.Update(kvs)
|
||||
return err
|
||||
}, reflect.TypeOf(item).Name())
|
||||
return err
|
||||
return num, err
|
||||
}
|
||||
|
||||
func CreateEntity(db *DaoDB, item interface{}) error {
|
||||
@@ -117,3 +117,22 @@ func CreateEntity(db *DaoDB, item interface{}) error {
|
||||
}, reflect.TypeOf(item).Name())
|
||||
return err
|
||||
}
|
||||
|
||||
func DeleteEntity(db *DaoDB, item interface{}, conditions map[string]interface{}) (num int64, err error) {
|
||||
if db == nil {
|
||||
db = GetDB()
|
||||
}
|
||||
err = utils.CallFuncLogError(func() error {
|
||||
if len(conditions) == 0 {
|
||||
num, err = db.db.Delete(item)
|
||||
} else {
|
||||
qs := db.db.QueryTable(item)
|
||||
for k, v := range conditions {
|
||||
qs = qs.Filter(k, v)
|
||||
}
|
||||
num, err = qs.Delete()
|
||||
}
|
||||
return err
|
||||
}, reflect.TypeOf(item).Name())
|
||||
return 0, err
|
||||
}
|
||||
|
||||
@@ -10,3 +10,28 @@ type ModelIDCUL struct {
|
||||
UpdatedAt time.Time `orm:"auto_now;type(datetime)" json:"updatedAt"`
|
||||
LastOperator string `orm:"size(32)" json:"lastOperator"` // 最后操作员
|
||||
}
|
||||
|
||||
// flag按位表示,第一位表示修改,第二位表示新增,第三位表示删除
|
||||
const (
|
||||
SyncFlagModifiedMask = 1
|
||||
SyncFlagNewMask = 2
|
||||
SyncFlagDeletedMask = 4
|
||||
)
|
||||
|
||||
// const (
|
||||
// KeyJdFlag = "jdFlag"
|
||||
// KeyJdSyncedAt = "jdSyncedAt"
|
||||
// KeyElmFlag = "elmFlag"
|
||||
// KeyElmSyncedAt = "elmSyncedAt"
|
||||
// KeyEbaiFlag = "ebaiFlag"
|
||||
// KeyEbaiSyncedAt = "ebaiSyncedAt"
|
||||
// )
|
||||
|
||||
// type ModelSyncFlag struct {
|
||||
// JdFlag int8 `orm:"column(jd_flag);default(2)" json:"jdFlag"` // 京东同步状态
|
||||
// JdSyncedAt time.Time `orm:"column(jd_synced_at);null" json:"jdSyncedAt"` // 京东最新成功同步时间
|
||||
// ElmFlag int8 `orm:"column(elm_flag);default(2)" json:"elmFlag"` // 饿了么同步状态
|
||||
// ElmSyncedAt time.Time `orm:"column(elm_synced_at);null" json:"elmSyncedAt"` // 京东最新成功同步时间
|
||||
// EbaiFlag int8 `orm:"column(ebai_flag);default(2)" json:"ebaiFlag"` // 饿百同步状态
|
||||
// EbaiSyncedAt time.Time `orm:"column(ebai_synced_at);null" json:"ebaiSyncedAt"` // 京东最新成功同步时间
|
||||
// }
|
||||
|
||||
@@ -35,6 +35,8 @@ type Store struct {
|
||||
DeliveryRangeType int8 `json:"deliveryRangeType"` // 参见相关常量定义
|
||||
DeliveryRange string `orm:"size(2048)" json:"deliveryRange"` // 如果DeliveryRangeType为DeliveryRangeTypePolygon,则为逗号分隔坐标,分号分隔的坐标点(坐标与Lng和Lat一样,都是整数),比如 121361504,31189308;121420555,31150238。否则为半径,单位为米
|
||||
Status int `json:"status"`
|
||||
|
||||
DeliveryType int8 `orm:"-" json:"-"`
|
||||
}
|
||||
|
||||
type StoreSub struct {
|
||||
@@ -59,14 +61,16 @@ func (*StoreSub) TableUnique() [][]string {
|
||||
type StoreMap struct {
|
||||
ModelIDCUL
|
||||
|
||||
StoreID int `orm:"column(store_id)"`
|
||||
VendorID int `orm:"column(vendor_id)"`
|
||||
VendorStoreID string `orm:"column(vendor_store_id);size(48)"`
|
||||
Status int // 取值同Store.Status
|
||||
StoreID int `orm:"column(store_id)" json:"storeID"`
|
||||
VendorID int `orm:"column(vendor_id)" json:"vendorID"`
|
||||
VendorStoreID string `orm:"column(vendor_store_id);size(48)" json:"vendorStoreID"`
|
||||
Status int `json:"status"` // 取值同Store.Status
|
||||
|
||||
AutoPickup int8 // 是否自动拣货
|
||||
DeliveryType int8 // 配送类型
|
||||
DeliveryCompetition int8 // 是否支持配送竞争
|
||||
SyncStatus int8 `orm:"default(2)" json:"syncStatus"`
|
||||
|
||||
AutoPickup int8 `json:"autoPickup"` // 是否自动拣货
|
||||
DeliveryType int8 `json:"deliveryType"` // 配送类型
|
||||
DeliveryCompetition int8 `json:"deliveryCompetition"` // 是否支持配送竞争
|
||||
}
|
||||
|
||||
func (*StoreMap) TableUnique() [][]string {
|
||||
|
||||
@@ -59,9 +59,9 @@ type IPurchasePlatformHandler interface {
|
||||
// Store
|
||||
ReadStore(vendorStoreID string) (store *model.Store, err error)
|
||||
UpdateStore(vendorStoreID string, store *model.Store, userName string) error
|
||||
EnableAutoAcceptOrder(vendorStoreID string, isEnabled bool) error
|
||||
OpenStore(vendorStoreID string, userName string) error
|
||||
CloseStore(vendorStoreID, closeNotice, userName string) error
|
||||
// EnableAutoAcceptOrder(vendorStoreID string, isEnabled bool) error
|
||||
// OpenStore(vendorStoreID string, userName string) error
|
||||
// CloseStore(vendorStoreID, closeNotice, userName string) error
|
||||
|
||||
// Sku
|
||||
CreateCategory(cat *model.SkuCategory, userName string) (err error)
|
||||
|
||||
@@ -10,14 +10,14 @@ func (p *PurchaseHandler) UpdateStore(vendorStoreID string, store *model.Store,
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *PurchaseHandler) EnableAutoAcceptOrder(vendorStoreID string, isEnabled bool) error {
|
||||
return nil
|
||||
}
|
||||
// func (p *PurchaseHandler) EnableAutoAcceptOrder(vendorStoreID string, isEnabled bool) error {
|
||||
// return nil
|
||||
// }
|
||||
|
||||
func (p *PurchaseHandler) OpenStore(vendorStoreID string, userName string) error {
|
||||
return nil
|
||||
}
|
||||
// func (p *PurchaseHandler) OpenStore(vendorStoreID string, userName string) error {
|
||||
// return nil
|
||||
// }
|
||||
|
||||
func (p *PurchaseHandler) CloseStore(vendorStoreID, closeNotice, userName string) error {
|
||||
return nil
|
||||
}
|
||||
// func (p *PurchaseHandler) CloseStore(vendorStoreID, closeNotice, userName string) error {
|
||||
// return nil
|
||||
// }
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"git.rosy.net.cn/jx-callback/business/jxcallback/scheduler"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||||
|
||||
@@ -25,6 +26,8 @@ func (p *PurchaseHandler) ReadStore(vendorStoreID string) (*model.Store, error)
|
||||
Status: JdStoreStatus2JxStatus(result["yn"], result["closeStatus"]),
|
||||
Tel1: utils.Interface2String(result["phone"]),
|
||||
}
|
||||
retVal.DeliveryType = JdDeliveryType2Jx(int(utils.MustInterface2Int64(result["carrierNo"])))
|
||||
|
||||
tel2 := utils.Interface2String(result["mobile"])
|
||||
if tel2 != "" && tel2 != retVal.Tel1 {
|
||||
retVal.Tel2 = tel2
|
||||
@@ -92,26 +95,26 @@ func (p *PurchaseHandler) UpdateStore(vendorStoreID string, store *model.Store,
|
||||
// return api.JdAPI.UpdateStoreInfo4Open(vendorStoreID, userName, params)
|
||||
// }
|
||||
|
||||
func (p *PurchaseHandler) EnableAutoAcceptOrder(vendorStoreID string, isEnabled bool) error {
|
||||
_, err := api.JdAPI.UpdateStoreConfig4Open(vendorStoreID, isEnabled)
|
||||
return err
|
||||
}
|
||||
// func (p *PurchaseHandler) EnableAutoAcceptOrder(vendorStoreID string, isEnabled bool) error {
|
||||
// _, err := api.JdAPI.UpdateStoreConfig4Open(vendorStoreID, isEnabled)
|
||||
// return err
|
||||
// }
|
||||
|
||||
func (p *PurchaseHandler) OpenStore(vendorStoreID string, userName string) error {
|
||||
params := map[string]interface{}{
|
||||
"closeStatus": 0,
|
||||
"storeNotice": "",
|
||||
}
|
||||
return api.JdAPI.UpdateStoreInfo4Open(vendorStoreID, userName, params)
|
||||
}
|
||||
// func (p *PurchaseHandler) OpenStore(vendorStoreID string, userName string) error {
|
||||
// params := map[string]interface{}{
|
||||
// "closeStatus": 0,
|
||||
// "storeNotice": "",
|
||||
// }
|
||||
// return api.JdAPI.UpdateStoreInfo4Open(vendorStoreID, userName, params)
|
||||
// }
|
||||
|
||||
func (p *PurchaseHandler) CloseStore(vendorStoreID, closeNotice, userName string) error {
|
||||
params := map[string]interface{}{
|
||||
"closeStatus": 1,
|
||||
"storeNotice": closeNotice,
|
||||
}
|
||||
return api.JdAPI.UpdateStoreInfo4Open(vendorStoreID, userName, params)
|
||||
}
|
||||
// func (p *PurchaseHandler) CloseStore(vendorStoreID, closeNotice, userName string) error {
|
||||
// params := map[string]interface{}{
|
||||
// "closeStatus": 1,
|
||||
// "storeNotice": closeNotice,
|
||||
// }
|
||||
// return api.JdAPI.UpdateStoreInfo4Open(vendorStoreID, userName, params)
|
||||
// }
|
||||
|
||||
///////////////////////
|
||||
func (p *PurchaseHandler) GetAllStoreIDsFromRemote() ([]string, error) {
|
||||
@@ -163,3 +166,12 @@ func JxRange2JdRange(jxRanges string) (jdRanges string) {
|
||||
}
|
||||
return strings.Join(intCoords, ";")
|
||||
}
|
||||
|
||||
func JdDeliveryType2Jx(deliveryType int) int8 {
|
||||
if deliveryType == 2938 {
|
||||
return scheduler.StoreDeliveryTypeByStore
|
||||
} else if deliveryType == 9966 {
|
||||
return scheduler.StoreDeliveryTypeCrowdSourcing
|
||||
}
|
||||
return scheduler.StoreDeliveryTypeByPlatform
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ func (c *StoreController) GetPlaces() {
|
||||
})
|
||||
}
|
||||
|
||||
// @Title 修改地点信息
|
||||
// @Title 批量修改地点信息
|
||||
// @Description 只支持修改enabled, jd_code和mtps_price这三个属性
|
||||
// @Param token header string true "认证token"
|
||||
// @Param payload formData string true "json数据,place对象数组"
|
||||
@@ -44,11 +44,29 @@ func (c *StoreController) GetPlaces() {
|
||||
// @router /UpdatePlaces [put]
|
||||
func (c *StoreController) UpdatePlaces() {
|
||||
c.callUpdatePlaces(func(params *tStoreUpdatePlacesParams) (retVal interface{}, errCode string, err error) {
|
||||
// placeList := []*model.Place{}
|
||||
placeList := make([]map[string]interface{}, 0)
|
||||
utils.UnmarshalUseNumber([]byte(params.Payload), &placeList)
|
||||
err = cms.UpdatePlaces(placeList, GetUserNameFromToken(params.Token))
|
||||
return nil, "", err
|
||||
if err = utils.UnmarshalUseNumber([]byte(params.Payload), &placeList); err == nil {
|
||||
retVal, err = cms.UpdatePlaces(placeList, GetUserNameFromToken(params.Token))
|
||||
}
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
// @Title 修改地点信息
|
||||
// @Description 只支持修改enabled, jd_code和mtps_price这三个属性
|
||||
// @Param token header string true "认证token"
|
||||
// @Param code formData int true "地点编号,注意是code不是ID,payload中的code会被忽略"
|
||||
// @Param payload formData string true "json数据,place对象"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /UpdatePlace [put]
|
||||
func (c *StoreController) UpdatePlace() {
|
||||
c.callUpdatePlace(func(params *tStoreUpdatePlaceParams) (retVal interface{}, errCode string, err error) {
|
||||
place := make(map[string]interface{}, 0)
|
||||
if err = utils.UnmarshalUseNumber([]byte(params.Payload), &place); err == nil {
|
||||
retVal, err = cms.UpdatePlace(params.Code, place, GetUserNameFromToken(params.Token))
|
||||
}
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
@@ -62,8 +80,12 @@ func (c *StoreController) UpdatePlaces() {
|
||||
// @Param placeLevel query int false "所属地点级别"
|
||||
// @Param address query string false "门店地址"
|
||||
// @Param tel query string false "电话"
|
||||
// @Param fromStatus query int false "起始状态(-1:禁用;0:休息,关店;1:正常开店)"
|
||||
// @Param toStatus query int false "结束状态(-1:禁用;0:休息,关店;1:正常开店)"
|
||||
// @Param fromStatus query int false "查询起始状态(-1:禁用;0:休息,关店;1:正常开店)"
|
||||
// @Param toStatus query int false "查询结束状态(-1:禁用;0:休息,关店;1:正常开店)"
|
||||
// @Param vendorStoreCond query string false "查询关联门店的条件,and:与,or:或,指的是jdCond,elmCond,ebaiCod这三个条件间的关系,这组条件与其它条件都是与的关系"
|
||||
// @Param jdCond query int false "京东关联条件,-1:没有关联,0:不限定,1:有关联,缺省为0"
|
||||
// @Param elmCond query int false "饿了么关联条件,-1:没有关联,0:不限定,1:有关联,缺省为0"
|
||||
// @Param ebaiCond query int false "饿百关联条件,-1:没有关联,0:不限定,1:有关联,缺省为0"
|
||||
// @Param offset query int false "门店列表起始序号(以0开始,缺省为0)"
|
||||
// @Param pageSize query int false "门店列表页大小(缺省为50)"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
@@ -94,6 +116,7 @@ func (c *StoreController) GetVendorStore() {
|
||||
// @Title 修改门店信息
|
||||
// @Description 修改门店信息
|
||||
// @Param token header string true "认证token"
|
||||
// @Param storeID formData int true "京西门店编号,payload中的京西门店编号会被忽略"
|
||||
// @Param payload formData string true "json数据,store对象"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
@@ -101,9 +124,10 @@ func (c *StoreController) GetVendorStore() {
|
||||
func (c *StoreController) UpdateStore() {
|
||||
c.callUpdateStore(func(params *tStoreUpdateStoreParams) (retVal interface{}, errCode string, err error) {
|
||||
store := make(map[string]interface{})
|
||||
utils.UnmarshalUseNumber([]byte(params.Payload), &store)
|
||||
err = cms.UpdateStore(store, GetUserNameFromToken(params.Token))
|
||||
return nil, "", err
|
||||
if err = utils.UnmarshalUseNumber([]byte(params.Payload), &store); err == nil {
|
||||
retVal, err = cms.UpdateStore(params.StoreID, store, GetUserNameFromToken(params.Token))
|
||||
}
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
@@ -117,8 +141,9 @@ func (c *StoreController) UpdateStore() {
|
||||
func (c *StoreController) CreateStore() {
|
||||
c.callCreateStore(func(params *tStoreCreateStoreParams) (retVal interface{}, errCode string, err error) {
|
||||
store := &model.Store{}
|
||||
utils.UnmarshalUseNumber([]byte(params.Payload), store)
|
||||
retVal, err = cms.CreateStore(store, GetUserNameFromToken(params.Token))
|
||||
if err = utils.UnmarshalUseNumber([]byte(params.Payload), store); err == nil {
|
||||
retVal, err = cms.CreateStore(store, GetUserNameFromToken(params.Token))
|
||||
}
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
@@ -132,3 +157,69 @@ func (c *StoreController) CreateStore() {
|
||||
// @router /ZZZZZ [put]
|
||||
func (c *StoreController) ZZZZZ() {
|
||||
}
|
||||
|
||||
// @Title 得到门店映射信息
|
||||
// @Description 得到门店映射信息
|
||||
// @Param token header string true "认证token"
|
||||
// @Param storeID query int true "门店ID"
|
||||
// @Param vendorID query int false "厂商ID(缺省为全部)"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /GetStoreVendorMaps [get]
|
||||
func (c *StoreController) GetStoreVendorMaps() {
|
||||
c.callGetStoreVendorMaps(func(params *tStoreGetStoreVendorMapsParams) (retVal interface{}, errCode string, err error) {
|
||||
retVal, err = cms.GetStoreVendorMaps(nil, params.StoreID)
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
// @Title 修改门店映射信息
|
||||
// @Description 修改门店映射信息
|
||||
// @Param token header string true "认证token"
|
||||
// @Param storeID query int true "门店ID,payload中的相应字段会被忽略"
|
||||
// @Param vendorID query int true "厂商ID,payload中的相应字段会被忽略"
|
||||
// @Param payload formData string true "json数据,storeMap对象"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /UpdateStoreVendorMap [put]
|
||||
func (c *StoreController) UpdateStoreVendorMap() {
|
||||
c.callUpdateStoreVendorMap(func(params *tStoreUpdateStoreVendorMapParams) (retVal interface{}, errCode string, err error) {
|
||||
storeMap := make(map[string]interface{})
|
||||
if err = utils.UnmarshalUseNumber([]byte(params.Payload), &storeMap); err == nil {
|
||||
retVal, err = cms.UpdateStoreVendorMap(nil, params.StoreID, params.VendorID, storeMap, GetUserNameFromToken(params.Token))
|
||||
}
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
// @Title 新增门店映射信息
|
||||
// @Description 新增门店映射信息
|
||||
// @Param token header string true "认证token"
|
||||
// @Param payload formData string true "json数据,storeMap对象"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /AddStoreVendorMap [post]
|
||||
func (c *StoreController) AddStoreVendorMap() {
|
||||
c.callAddStoreVendorMap(func(params *tStoreAddStoreVendorMapParams) (retVal interface{}, errCode string, err error) {
|
||||
storeMap := &model.StoreMap{}
|
||||
if err = utils.UnmarshalUseNumber([]byte(params.Payload), storeMap); err == nil {
|
||||
retVal, err = cms.AddStoreVendorMap(nil, storeMap, GetUserNameFromToken(params.Token))
|
||||
}
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
// @Title 删除门店映射信息
|
||||
// @Description 删除门店映射信息
|
||||
// @Param token header string true "认证token"
|
||||
// @Param storeID query int true "门店ID"
|
||||
// @Param vendorID query int true "厂商ID"
|
||||
// @Success 200 {object} controllers.CallResult
|
||||
// @Failure 200 {object} controllers.CallResult
|
||||
// @router /DeleteStoreVendorMap [delete]
|
||||
func (c *StoreController) DeleteStoreVendorMap() {
|
||||
c.callDeleteStoreVendorMap(func(params *tStoreDeleteStoreVendorMapParams) (retVal interface{}, errCode string, err error) {
|
||||
retVal, err = cms.DeleteStoreVendorMap(nil, params.StoreID, params.VendorID, GetUserNameFromToken(params.Token))
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
@@ -143,6 +143,14 @@ func init() {
|
||||
MethodParams: param.Make(),
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreController"],
|
||||
beego.ControllerComments{
|
||||
Method: "AddStoreVendorMap",
|
||||
Router: `/AddStoreVendorMap`,
|
||||
AllowHTTPMethods: []string{"post"},
|
||||
MethodParams: param.Make(),
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreController"],
|
||||
beego.ControllerComments{
|
||||
Method: "CreateStore",
|
||||
@@ -151,6 +159,14 @@ func init() {
|
||||
MethodParams: param.Make(),
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreController"],
|
||||
beego.ControllerComments{
|
||||
Method: "DeleteStoreVendorMap",
|
||||
Router: `/DeleteStoreVendorMap`,
|
||||
AllowHTTPMethods: []string{"delete"},
|
||||
MethodParams: param.Make(),
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreController"],
|
||||
beego.ControllerComments{
|
||||
Method: "GetPlaces",
|
||||
@@ -159,6 +175,14 @@ func init() {
|
||||
MethodParams: param.Make(),
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreController"],
|
||||
beego.ControllerComments{
|
||||
Method: "GetStoreVendorMaps",
|
||||
Router: `/GetStoreVendorMaps`,
|
||||
AllowHTTPMethods: []string{"get"},
|
||||
MethodParams: param.Make(),
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreController"],
|
||||
beego.ControllerComments{
|
||||
Method: "GetStores",
|
||||
@@ -175,6 +199,14 @@ func init() {
|
||||
MethodParams: param.Make(),
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreController"],
|
||||
beego.ControllerComments{
|
||||
Method: "UpdatePlace",
|
||||
Router: `/UpdatePlace`,
|
||||
AllowHTTPMethods: []string{"put"},
|
||||
MethodParams: param.Make(),
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreController"],
|
||||
beego.ControllerComments{
|
||||
Method: "UpdatePlaces",
|
||||
@@ -191,6 +223,14 @@ func init() {
|
||||
MethodParams: param.Make(),
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreController"],
|
||||
beego.ControllerComments{
|
||||
Method: "UpdateStoreVendorMap",
|
||||
Router: `/UpdateStoreVendorMap`,
|
||||
AllowHTTPMethods: []string{"put"},
|
||||
MethodParams: param.Make(),
|
||||
Params: nil})
|
||||
|
||||
beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreController"] = append(beego.GlobalControllerRouter["git.rosy.net.cn/jx-callback/controllers:StoreController"],
|
||||
beego.ControllerComments{
|
||||
Method: "ZZZZZ",
|
||||
|
||||
Reference in New Issue
Block a user