Files
baseapi/platformapi/dadaapi/shop.go
2025-11-20 14:27:08 +08:00

114 lines
3.6 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package dadaapi
import "gitrosy.jxc4.com/baseapi/utils"
const (
BusinessTypeSnack = 1
BusinessTypeDrink = 2
BusinessTypeFlower = 3
BusinessTypePrintTicket = 8
BusinessTypeConvStore = 9
BusinessTypeFruitVegetable = 13
BusinessTypeCityEComm = 19
BusinessTypeMedicine = 20
BusinessTypeCake = 21
BusinessTypeWine = 24
BusinessTypeSmallware = 25
BusinessTypeClothing = 26
BusinessTypeCarPart = 27
BusinessTypeDigital = 28
BusinessTypeCray = 29
BusinessTypeOther = -5
)
const (
ShopStatusOffline = 0 // -门店下线
ShopStatusOnline = 1 // -门店激活
)
type ShopInfo struct {
StationName string `json:"station_name,omitempty"`
Business int `json:"business,omitempty"`
CityName string `json:"city_name,omitempty"`
AreaName string `json:"area_name,omitempty"`
StationAddress string `json:"station_address,omitempty"`
Lng float64 `json:"lng,omitempty"`
Lat float64 `json:"lat,omitempty"`
ContactName string `json:"contact_name,omitempty"`
Phone string `json:"phone,omitempty"`
OriginShopID string `json:"origin_shop_id,omitempty"`
IDCard string `json:"id_card,omitempty"`
UserName string `json:"username,omitempty"`
Password string `json:"password,omitempty"`
NewShopID string `json:"new_shop_id,omitempty"` // 修改用
Status int `json:"status"` // 修改用0是有效值
}
type AddShopFailedInfo struct {
Code int `json:"code"`
ShopNo string `json:"shopNo"`
Msg string `json:"msg"`
ShopName string `json:"shopName"`
}
type AddShopSuccessInfo struct {
AreaName string `json:"areaName"`
Business int `json:"business"`
CityName string `json:"cityName"`
ContactName string `json:"contactName"`
Lat float64 `json:"lat"`
Lng float64 `json:"lng"`
OriginShopID string `json:"originShopId"`
Phone string `json:"phone"`
StationAddress string `json:"stationAddress"`
StationName string `json:"stationName"`
}
type AddShopResult struct {
Success int `json:"success"`
SuccessList []*AddShopSuccessInfo `json:"successList"`
FailedList []*AddShopFailedInfo `json:"failedList"`
}
func (a *API) ShopDetail(originShopID string) (shopDetail *ShopInfo, err error) {
params := map[string]interface{}{
"origin_shop_id": originShopID,
}
result, err := a.AccessAPI("api/shop/detail", params)
if err == nil {
err = utils.Map2StructByJson(result.Result, &shopDetail, false)
}
return shopDetail, err
}
func (a *API) ShopAdd(shopInfo *ShopInfo) (outOriginShopID string, err error) {
addResult, err := a.BatchShopAdd([]*ShopInfo{shopInfo})
if addResult != nil && len(addResult.FailedList) == 1 {
return "", utils.NewErrorIntCode(addResult.FailedList[0].Msg, int(utils.MustInterface2Int64(addResult.FailedList[0].Code)))
} else if err != nil {
return "", err
}
return addResult.SuccessList[0].OriginShopID, nil
}
func (a *API) BatchShopAdd(shopInfoList []*ShopInfo) (addResult *AddShopResult, err error) {
mapList := make([]map[string]interface{}, len(shopInfoList))
for k, v := range shopInfoList {
mapList[k] = utils.Struct2MapByJson(v)
delete(mapList[k], "status") // 创建时没有status参数
}
result, err := a.AccessAPI("api/shop/add", mapList)
err2 := utils.Map2StructByJson(result.Result, &addResult, false)
if err == nil {
err = err2
}
return addResult, err
}
func (a *API) ShopUpdate(shopInfo *ShopInfo) (err error) {
_, err = a.AccessAPI("api/shop/update", shopInfo)
return err
}