This commit is contained in:
richboo111
2023-06-29 09:19:05 +08:00
parent cf51eda4d5
commit 7373f78fd7
10 changed files with 150 additions and 26 deletions

View File

@@ -4,6 +4,16 @@ import (
"encoding/json"
"errors"
"fmt"
"math"
"regexp"
"strings"
"git.rosy.net.cn/baseapi/platformapi/tao_vegetable"
"git.rosy.net.cn/baseapi/utils/errlist"
"git.rosy.net.cn/jx-callback/globals/api"
"git.rosy.net.cn/baseapi/platformapi/mtwmapi"
"git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/business/jxstore/event"
@@ -13,9 +23,6 @@ import (
"git.rosy.net.cn/jx-callback/business/model"
"git.rosy.net.cn/jx-callback/business/model/dao"
"git.rosy.net.cn/jx-callback/business/partner"
"math"
"regexp"
"strings"
)
var (
@@ -45,6 +52,12 @@ var (
}
)
const (
FlagStatus = 1 //1-营业状态
FlagBusinessTime = 2 //2-营业时间
FlagRange = 3 //3-营业范围
)
type tEbaiStoreInfo struct {
model.Store
VendorStoreID string `orm:"column(vendor_store_id)"`
@@ -57,6 +70,84 @@ type tEbaiStoreInfo struct {
DistrictID int `orm:"column(district_id)"`
}
type TxdStore struct {
Flag []int `json:"flag"` //更新字段标识 1-营业状态 2-营业时间 3-营业范围
TxdStoreID string `json:"txdStoreID"` //淘鲜达平台id
Status int64 `json:"status"` //营业状态
StartTime string `json:"startTime"` //营业开始时间(HH:mm)
EndTime string `json:"endTime"` //营业结束时间(HH:mm)
Points string `json:"points"` //营业范围坐标
}
type Point struct {
Lat string `json:"lat"`
Lng string `json:"lng"`
}
// UpdateTxdStore 单独更新淘鲜达门店营业时间/状态 销售范围
func UpdateTxdStore(store TxdStore) (err error) {
errList := errlist.New()
for _, v := range store.Flag {
switch v {
case FlagStatus:
if err = api.TaoVegetableApi.ShopUpdateStatus(store.TxdStoreID, store.Status); err != nil {
errList.AddErr(fmt.Errorf("营业状态:%v", err))
}
case FlagBusinessTime:
if CheckBusinessTime(store.StartTime, store.EndTime) {
if err = api.TaoVegetableApi.ShopUpdateInfo(store.TxdStoreID, store.StartTime, store.EndTime); err != nil {
errList.AddErr(fmt.Errorf("营业时间:%v", err))
}
}
case FlagRange:
point := GetPoints(store.Points)
if err = api.TaoVegetableApi.ShopUpdateRange(store.TxdStoreID, point); err != nil {
errList.AddErr(fmt.Errorf("营业范围:%v", err))
}
default:
return nil
}
}
if errList.GetErrListAsOne() != nil {
return errList.GetErrListAsOne()
}
return nil
}
// CheckBusinessTime 检验营业时间格式是否合法
func CheckBusinessTime(start, end string) bool {
s1 := strings.Split(start, ":")
t1 := utils.Str2Int64(s1[0])
t11 := utils.Str2Int64(s1[1])
s2 := strings.Split(end, ":")
t2 := utils.Str2Int64(s2[0])
t22 := utils.Str2Int64(s2[1])
if (0 <= t1 && t1 <= 23) && (0 <= t11 && t11 <= 59) && (0 <= t2 && t2 <= 23) && (0 <= t22 && t22 <= 59) && t1 < t2 {
return true
}
return false
}
// GetPoints 解析范围坐标
func GetPoints(data string) []tao_vegetable.Points {
if len(data) == 0 {
return nil
}
temp := strings.Split(data, ";")
points := make([]tao_vegetable.Points, 0)
for _, v := range temp {
s := strings.Split(v, ",")
point := tao_vegetable.Points{
Lng: s[0],
Lat: s[1],
}
points = append(points, point)
}
return points
}
func (p *PurchaseHandler) ReadStore(ctx *jxcontext.Context, vendorOrgCode, vendorStoreID, vendorStoreName string) (retVal *dao.StoreDetail, err error) {
//result, err := getAPIWithoutToken(vendorOrgCode).PoiGet(vendorStoreID)
//if err == nil {