新增一系列接口
This commit is contained in:
@@ -35,6 +35,10 @@ func (p DefParty) login() web_iris.Party {
|
||||
body, _ := io.ReadAll(ctx.Request().Body)
|
||||
var loginRequest LoginRequest
|
||||
json.Unmarshal(body, &loginRequest)
|
||||
if len(loginRequest.Code) == 0 {
|
||||
ParamError.Fail(ctx, nil)
|
||||
return
|
||||
}
|
||||
//获取code
|
||||
/*info, err := utils.GetWxUserInfo(loginRequest.Code)
|
||||
if err != nil {
|
||||
|
||||
+57
-16
@@ -8,6 +8,7 @@ import (
|
||||
"go.uber.org/zap"
|
||||
"pet-house.com/business/models"
|
||||
"pet-house.com/core/server/cache"
|
||||
"pet-house.com/core/server/cron_server"
|
||||
"pet-house.com/core/server/database"
|
||||
"pet-house.com/core/server/zap_server"
|
||||
"strconv"
|
||||
@@ -15,9 +16,9 @@ import (
|
||||
)
|
||||
|
||||
type Response struct {
|
||||
Code int `json:"code"` //code
|
||||
Msg string `json:"msg"` //msg
|
||||
Data any `json:"data"` //数据
|
||||
Code int `json:"code"` //code
|
||||
Msg string `json:"msg"` //msg
|
||||
Data any `json:"data,omitempty"` //数据
|
||||
}
|
||||
|
||||
type ResponseData struct {
|
||||
@@ -34,13 +35,17 @@ type DefParty struct {
|
||||
}
|
||||
|
||||
var (
|
||||
ParamError = Error{Code: 201, Msg: "参数错误"}
|
||||
IllegalError = Error{Code: 202, Msg: "非法请求"}
|
||||
UserError = Error{Code: 203, Msg: "用户错误"}
|
||||
TokenError = Error{Code: 204, Msg: "Token失效,请重新登录"}
|
||||
UserNotExistError = Error{Code: 205, Msg: "用户不存在"}
|
||||
PetNotExistError = Error{Code: 206, Msg: "用户宠物不存在"}
|
||||
PetBaseNotExistError = Error{Code: 207, Msg: "宠物基础信息不存在"}
|
||||
ParamError = Error{Code: 201, Msg: "参数错误"}
|
||||
IllegalError = Error{Code: 202, Msg: "非法请求"}
|
||||
UserError = Error{Code: 203, Msg: "用户错误"}
|
||||
TokenError = Error{Code: 204, Msg: "Token失效,请重新登录"}
|
||||
UserNotExistError = Error{Code: 205, Msg: "用户不存在"}
|
||||
PetNotExistError = Error{Code: 206, Msg: "用户宠物不存在"}
|
||||
PetBaseNotExistError = Error{Code: 207, Msg: "宠物基础信息不存在"}
|
||||
UserServiceAddrNotExistError = Error{Code: 207, Msg: "用户服务地址不存在"}
|
||||
ServiceAddrNotExistError = Error{Code: 208, Msg: "服务地址区域,请重新配置地址"}
|
||||
NotInServiceExistError = Error{Code: 209, Msg: "不在服务范围"}
|
||||
OrderCreateError = Error{Code: 210, Msg: "订单创建失败"}
|
||||
)
|
||||
|
||||
func Success(ctx *context.Context, request any, data any) {
|
||||
@@ -83,11 +88,6 @@ func GetTokenInfo(token string) string {
|
||||
return uId
|
||||
}
|
||||
|
||||
func checkToken(uid string, token string) bool {
|
||||
uToken, _ := cache.GetCacheString("u_uid_token:" + uid)
|
||||
return uToken == token
|
||||
}
|
||||
|
||||
type HeaderBaseInfo struct {
|
||||
Token string
|
||||
Uid int64
|
||||
@@ -107,13 +107,54 @@ type FrontExclude struct {
|
||||
}
|
||||
|
||||
var PetBaseInfoMap map[int]models.PetBaseInfo
|
||||
var ServiceAddrMap map[int64]models.ServiceAddr
|
||||
var PetGoodsMap map[string][]models.PetGoods
|
||||
var GoodsMap map[int64]models.Goods
|
||||
|
||||
func DataInit() {
|
||||
//--------------------------------------------------宠物基础信息数据---------------------------------------------------------
|
||||
var petBastInfoList []models.PetBaseInfo
|
||||
database.Instance().Model(&models.PetBaseInfo{}).Find(&petBastInfoList)
|
||||
PetBaseInfoMap = make(map[int]models.PetBaseInfo)
|
||||
for _, value := range petBastInfoList {
|
||||
PetBaseInfoMap[value.Id] = value
|
||||
}
|
||||
zap_server.ZAPLOG.Info("dataInit : ", zap.Any("petBastInfoMap", PetBaseInfoMap))
|
||||
zap_server.ZAPLOG.Info("dataInit petBastInfoMap : ", zap.Any("petBastInfoMap", PetBaseInfoMap))
|
||||
//--------------------------------------------------服务地址数据---------------------------------------------------------
|
||||
var serviceAddrList []models.ServiceAddr
|
||||
database.Instance().Model(&models.ServiceAddr{}).Find(&serviceAddrList)
|
||||
ServiceAddrMap = make(map[int64]models.ServiceAddr)
|
||||
for _, value := range serviceAddrList {
|
||||
ServiceAddrMap[value.Id] = value
|
||||
}
|
||||
zap_server.ZAPLOG.Info("dataInit ServiceAddrMap : ", zap.Any("ServiceAddrMap", ServiceAddrMap))
|
||||
//--------------------------------------------------宠物商品关联数据---------------------------------------------------------
|
||||
var petGoodsList []models.PetGoods
|
||||
database.Instance().Model(&models.PetGoods{}).Find(&petGoodsList)
|
||||
PetGoodsMap = make(map[string][]models.PetGoods)
|
||||
for _, value := range petGoodsList {
|
||||
key := strconv.Itoa(value.Assortment) + strconv.Itoa(value.PetType) + strconv.Itoa(value.Size)
|
||||
if _, ok := PetGoodsMap[key]; ok {
|
||||
PetGoodsMap[key] = append(PetGoodsMap[key], value)
|
||||
} else {
|
||||
PetGoodsMap[key] = []models.PetGoods{value}
|
||||
}
|
||||
}
|
||||
zap_server.ZAPLOG.Info("dataInit petGoodsMap : ", zap.Any("petGoodsMap", PetGoodsMap))
|
||||
var goodsList []models.Goods
|
||||
database.Instance().Model(&models.Goods{}).Find(&goodsList)
|
||||
GoodsMap = make(map[int64]models.Goods)
|
||||
for _, value := range goodsList {
|
||||
GoodsMap[value.Id] = value
|
||||
}
|
||||
zap_server.ZAPLOG.Info("dataInit GoodsMap : ", zap.Any("GoodsMap", GoodsMap))
|
||||
}
|
||||
|
||||
func DataCacheJob() {
|
||||
c, err := cron_server.CronInstance().AddFunc("@every 1m", DataInit)
|
||||
if err != nil {
|
||||
zap_server.ZAPLOG.Info("DataCacheJob err : ", zap.Any("err", err))
|
||||
}
|
||||
zap_server.ZAPLOG.Info("DataCacheJob c : ", zap.Any("c", c), zap.Any("err", err))
|
||||
cron_server.CronInstance().Start()
|
||||
}
|
||||
|
||||
@@ -15,13 +15,17 @@ func (p DefParty) RegisterList() []web_iris.Party {
|
||||
p.goodsList(),
|
||||
p.goodsDetail(),
|
||||
p.orderCreate(),
|
||||
p.orderServiceTime(),
|
||||
p.orderList(),
|
||||
p.orderPay(),
|
||||
p.petList(),
|
||||
p.petInfo(),
|
||||
p.petTypeList(),
|
||||
p.petAddOrEdit(),
|
||||
p.delPet(),
|
||||
p.serviceAddrList(),
|
||||
p.serviceAddOrEdit(),
|
||||
p.serviceAreaAddrList(),
|
||||
p.index(),
|
||||
}
|
||||
return ps
|
||||
|
||||
+76
-2
@@ -1,25 +1,99 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/kataras/iris/v12"
|
||||
"github.com/kataras/iris/v12/context"
|
||||
"io"
|
||||
"pet-house.com/core/server/web/web_iris"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type GoodsListRequest struct {
|
||||
Pid int64
|
||||
}
|
||||
|
||||
type GoodsDetail struct {
|
||||
Id int64 `json:"id"` //商品ID
|
||||
Name string `json:"name"` //商品名称
|
||||
GoodsType int `json:"goodsType"` //商品类型 1基础服务 2附加产品 3附加服务
|
||||
Time string `json:"time"` //时间
|
||||
Price int32 `json:"price"` //价格
|
||||
ParentId int64 `json:"parentId"` //商品父ID
|
||||
BuyMany int `json:"buyMany"` //同类型是否可购买多个 0否 1是
|
||||
GoodsDetail string `json:"goodsDetail"` //商品详情 图片URL
|
||||
GoodsIcon string `json:"goodsIcon"` //iconUrl
|
||||
GoodsSubList []GoodsDetail `json:"goodsSubList,omitempty"`
|
||||
}
|
||||
|
||||
type GoodsListResponse struct {
|
||||
GoodsList []GoodsDetail `json:"goodsList"`
|
||||
}
|
||||
|
||||
// 商品列表
|
||||
func (p DefParty) goodsList() web_iris.Party {
|
||||
return web_iris.Party{Perfix: p.Perfix, PartyFunc: func(index iris.Party) {
|
||||
index.Post(GoodsBase+"/goodsList", func(ctx *context.Context) {
|
||||
|
||||
headerBaseInfo := GetHeaderBaseInfo(ctx)
|
||||
body, _ := io.ReadAll(ctx.Request().Body)
|
||||
var goodsListRequest GoodsListRequest
|
||||
json.Unmarshal(body, &goodsListRequest)
|
||||
userPetInfo := GetUserPet(headerBaseInfo.Uid, goodsListRequest.Pid)
|
||||
if userPetInfo.PetInfo.Id == 0 {
|
||||
PetNotExistError.Fail(ctx, goodsListRequest)
|
||||
return
|
||||
}
|
||||
//先取默认的商品
|
||||
key := "0" + strconv.Itoa(userPetInfo.PetBaseInfo.PetType) + strconv.Itoa(userPetInfo.PetBaseInfo.Size)
|
||||
goodsList := getPetGoodsList(key)
|
||||
key1 := strconv.Itoa(userPetInfo.PetBaseInfo.Id) + strconv.Itoa(userPetInfo.PetBaseInfo.PetType) + strconv.Itoa(userPetInfo.PetBaseInfo.Size)
|
||||
goodsList = append(goodsList, getPetGoodsList(key1)...)
|
||||
Success(ctx, goodsListRequest, GoodsListResponse{goodsList})
|
||||
})
|
||||
}}
|
||||
}
|
||||
|
||||
func getPetGoodsList(key string) []GoodsDetail {
|
||||
var goodsList []GoodsDetail
|
||||
baseGoodsList := PetGoodsMap[key]
|
||||
for _, value := range baseGoodsList {
|
||||
goods := GoodsMap[value.GoodsId]
|
||||
goodsDetail := GoodsDetail{
|
||||
Id: goods.Id,
|
||||
Name: goods.Name,
|
||||
GoodsType: goods.GoodsType,
|
||||
Time: goods.Time,
|
||||
Price: goods.Price,
|
||||
BuyMany: goods.BuyMany,
|
||||
GoodsDetail: goods.GoodsDetail,
|
||||
GoodsIcon: goods.GoodsIcon,
|
||||
GoodsSubList: nil,
|
||||
}
|
||||
for _, goodsSub := range GoodsMap {
|
||||
if goodsSub.ParentId == goodsDetail.Id {
|
||||
goodsDetail.GoodsSubList = append(goodsDetail.GoodsSubList, GoodsDetail{
|
||||
Id: goodsSub.Id,
|
||||
Name: goodsSub.Name,
|
||||
GoodsType: goodsSub.GoodsType,
|
||||
Time: goodsSub.Time,
|
||||
Price: goodsSub.Price,
|
||||
BuyMany: goodsSub.BuyMany,
|
||||
GoodsDetail: goodsSub.GoodsDetail,
|
||||
GoodsIcon: goodsSub.GoodsIcon,
|
||||
})
|
||||
}
|
||||
}
|
||||
goodsList = append(goodsList, goodsDetail)
|
||||
}
|
||||
return goodsList
|
||||
}
|
||||
|
||||
// 商品详情
|
||||
func (p DefParty) goodsDetail() web_iris.Party {
|
||||
return web_iris.Party{Perfix: p.Perfix, PartyFunc: func(index iris.Party) {
|
||||
index.Post(GoodsBase+"/goodsDetail", func(ctx *context.Context) {
|
||||
|
||||
//暂留
|
||||
Success(ctx, nil, nil)
|
||||
})
|
||||
}}
|
||||
}
|
||||
|
||||
@@ -29,10 +29,13 @@ func ModuleInit() {
|
||||
&models.ServiceAddr{},
|
||||
&models.UserServiceAddr{},
|
||||
&models.Goods{},
|
||||
&models.PetGoods{},
|
||||
&models.SystemConfig{},
|
||||
&models.OrderMain{},
|
||||
&models.OrderSub{},
|
||||
&models.OrderDetail{})
|
||||
DataInit()
|
||||
DataCacheJob()
|
||||
}
|
||||
|
||||
func FrontAuth(ctx *context.Context) {
|
||||
|
||||
@@ -1,15 +1,116 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/kataras/iris/v12"
|
||||
"github.com/kataras/iris/v12/context"
|
||||
"go.uber.org/zap"
|
||||
"io"
|
||||
"pet-house.com/business/models"
|
||||
"pet-house.com/core/server/database"
|
||||
"pet-house.com/core/server/web/web_iris"
|
||||
"pet-house.com/core/server/zap_server"
|
||||
)
|
||||
|
||||
type PetGoodsInfo struct {
|
||||
PetId int64
|
||||
GoodsIds []int64
|
||||
}
|
||||
|
||||
type OrderCreateRequest struct {
|
||||
PetGoodsInfos []PetGoodsInfo //宠物商品信息列表
|
||||
ServiceTime string //预约时间 yyyy-MM-dd HH:mm
|
||||
ServiceAddrId int64 //预约服务地址
|
||||
}
|
||||
|
||||
// 创建
|
||||
func (p DefParty) orderCreate() web_iris.Party {
|
||||
return web_iris.Party{Perfix: p.Perfix, PartyFunc: func(index iris.Party) {
|
||||
index.Post(OrderBase+"/orderCreate", func(ctx *context.Context) {
|
||||
headerBaseInfo := GetHeaderBaseInfo(ctx)
|
||||
body, _ := io.ReadAll(ctx.Request().Body)
|
||||
var orderCreateRequest OrderCreateRequest
|
||||
json.Unmarshal(body, &orderCreateRequest)
|
||||
var userServiceAddr models.UserServiceAddr
|
||||
database.Instance().Model(&models.UserServiceAddr{}).Where("uid = ? and id = ?", headerBaseInfo.Uid, orderCreateRequest.ServiceAddrId).Find(&userServiceAddr)
|
||||
if userServiceAddr.Id == 0 {
|
||||
UserServiceAddrNotExistError.Fail(ctx, nil)
|
||||
return
|
||||
}
|
||||
serviceAddr := ServiceAddrMap[userServiceAddr.AreaId]
|
||||
if serviceAddr.Id == 0 {
|
||||
ServiceAddrNotExistError.Fail(ctx, nil)
|
||||
return
|
||||
}
|
||||
orderId := NextId.Generate().String()
|
||||
orderMain := models.OrderMain{
|
||||
OrderId: orderId,
|
||||
Uid: headerBaseInfo.Uid,
|
||||
Status: 1,
|
||||
ServiceTime: orderCreateRequest.ServiceTime,
|
||||
ServiceAddrId: orderCreateRequest.ServiceAddrId,
|
||||
ServiceRemark: "",
|
||||
}
|
||||
var orderSubList []models.OrderSub
|
||||
var orderSubDetailList []models.OrderDetail
|
||||
for _, value := range orderCreateRequest.PetGoodsInfos {
|
||||
subOrderId := NextId.Generate().String()
|
||||
var totalAmount int32 = 0
|
||||
for _, value := range value.GoodsIds {
|
||||
goods := GoodsMap[value]
|
||||
totalAmount = totalAmount + goods.Price
|
||||
orderSubDetailList = append(orderSubDetailList, models.OrderDetail{SubOrderId: subOrderId, GoodsId: value, Amount: goods.Price})
|
||||
}
|
||||
orderSub := models.OrderSub{
|
||||
OrderId: subOrderId,
|
||||
MainOrderId: orderMain.OrderId,
|
||||
Status: 1,
|
||||
PetId: value.PetId,
|
||||
PayType: 1,
|
||||
Discount: 100,
|
||||
TotalAmount: totalAmount,
|
||||
PayAmount: 0,
|
||||
}
|
||||
orderSubList = append(orderSubList, orderSub)
|
||||
}
|
||||
tx := database.Instance().Begin()
|
||||
db := tx.Model(&models.OrderDetail{}).CreateInBatches(&orderSubDetailList, len(orderSubDetailList))
|
||||
db1 := tx.Model(&models.OrderSub{}).CreateInBatches(&orderSubList, len(orderSubList))
|
||||
db2 := tx.Model(&models.OrderMain{}).Create(&orderMain)
|
||||
if db.Error != nil || db1.Error != nil || db2.Error != nil {
|
||||
tx.Callback()
|
||||
zap_server.ZAPLOG.Error("订单插入失败", zap.Any("db", db.Error), zap.Any("db1", db1.Error), zap.Any("db2", db2.Error))
|
||||
OrderCreateError.Fail(ctx, orderCreateRequest)
|
||||
return
|
||||
}
|
||||
tx.Commit()
|
||||
Success(ctx, orderCreateRequest, nil)
|
||||
})
|
||||
}}
|
||||
}
|
||||
|
||||
type OrderListRequest struct {
|
||||
Status int //订单状态
|
||||
PageNo int //页码
|
||||
PageSize int //数据数量
|
||||
}
|
||||
|
||||
type OrderListResponse struct {
|
||||
}
|
||||
|
||||
// 订单列表
|
||||
func (p DefParty) orderList() web_iris.Party {
|
||||
return web_iris.Party{Perfix: p.Perfix, PartyFunc: func(index iris.Party) {
|
||||
index.Post(OrderBase+"/orderList", func(ctx *context.Context) {
|
||||
|
||||
})
|
||||
}}
|
||||
}
|
||||
|
||||
// 获取订单可预约时间
|
||||
func (p DefParty) orderServiceTime() web_iris.Party {
|
||||
return web_iris.Party{Perfix: p.Perfix, PartyFunc: func(index iris.Party) {
|
||||
index.Post(OrderBase+"/orderServiceTime", func(ctx *context.Context) {
|
||||
|
||||
})
|
||||
}}
|
||||
|
||||
@@ -157,3 +157,26 @@ func (p DefParty) petTypeList() web_iris.Party {
|
||||
})
|
||||
}}
|
||||
}
|
||||
|
||||
type DelPetRequest struct {
|
||||
Id int64
|
||||
}
|
||||
|
||||
func (p DefParty) delPet() web_iris.Party {
|
||||
return web_iris.Party{Perfix: p.Perfix, PartyFunc: func(index iris.Party) {
|
||||
index.Post(PetBase+"/delPet", func(ctx *context.Context) {
|
||||
headerBaseInfo := GetHeaderBaseInfo(ctx)
|
||||
body, _ := io.ReadAll(ctx.Request().Body)
|
||||
var delPetRequest DelPetRequest
|
||||
json.Unmarshal(body, &delPetRequest)
|
||||
var userPetInfo models.Pet
|
||||
database.Instance().Model(&models.Pet{}).Where("id = ? and uid = ?", delPetRequest.Id, headerBaseInfo.Uid).Find(&userPetInfo)
|
||||
if userPetInfo.Id == 0 {
|
||||
PetNotExistError.Fail(ctx, delPetRequest)
|
||||
return
|
||||
}
|
||||
database.Instance().Where("id = ?", userPetInfo.PetId).Delete(&models.Pet{})
|
||||
Success(ctx, nil, nil)
|
||||
})
|
||||
}}
|
||||
}
|
||||
|
||||
+116
-2
@@ -1,25 +1,139 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/kataras/iris/v12"
|
||||
"github.com/kataras/iris/v12/context"
|
||||
geo "github.com/kellydunn/golang-geo"
|
||||
"go.uber.org/zap"
|
||||
"io"
|
||||
"pet-house.com/business/models"
|
||||
"pet-house.com/business/utils"
|
||||
"pet-house.com/core/server/database"
|
||||
"pet-house.com/core/server/web/web_iris"
|
||||
"pet-house.com/core/server/zap_server"
|
||||
strconv "strconv"
|
||||
)
|
||||
|
||||
// 服务地址列表
|
||||
type ServiceAddrListResponse struct {
|
||||
UserServiceAddrList []*models.UserServiceAddr `json:"userServiceAddrList"`
|
||||
}
|
||||
|
||||
// 我的服务地址列表
|
||||
func (p DefParty) serviceAddrList() web_iris.Party {
|
||||
return web_iris.Party{Perfix: p.Perfix, PartyFunc: func(index iris.Party) {
|
||||
index.Post(ServiceBase+"/serviceAddrList", func(ctx *context.Context) {
|
||||
|
||||
headerBaseInfo := GetHeaderBaseInfo(ctx)
|
||||
var userServiceAddrList []*models.UserServiceAddr
|
||||
database.Instance().Model(&models.UserServiceAddr{}).Where("uid = ?", headerBaseInfo.Uid).Find(&userServiceAddrList)
|
||||
for _, value := range userServiceAddrList {
|
||||
value.Area = ServiceAddrMap[value.AreaId].Addr
|
||||
}
|
||||
Success(ctx, headerBaseInfo, ServiceAddrListResponse{userServiceAddrList})
|
||||
})
|
||||
}}
|
||||
}
|
||||
|
||||
type ServiceAddOrEditRequest struct {
|
||||
Id int64
|
||||
Name string
|
||||
Mobile string
|
||||
AreaId int64
|
||||
Addr string
|
||||
Longitude string
|
||||
Latitude string
|
||||
}
|
||||
|
||||
type ServiceAddOrEditResponse struct {
|
||||
ServiceAddrList []*models.UserServiceAddr `json:"serviceAddrList"`
|
||||
}
|
||||
|
||||
// 服务地址添加或编辑
|
||||
func (p DefParty) serviceAddOrEdit() web_iris.Party {
|
||||
return web_iris.Party{Perfix: p.Perfix, PartyFunc: func(index iris.Party) {
|
||||
index.Post(ServiceBase+"/serviceAddOrEdit", func(ctx *context.Context) {
|
||||
headerBaseInfo := GetHeaderBaseInfo(ctx)
|
||||
body, _ := io.ReadAll(ctx.Request().Body)
|
||||
var serviceAddOrEditRequest ServiceAddOrEditRequest
|
||||
json.Unmarshal(body, &serviceAddOrEditRequest)
|
||||
var serviceAddr models.ServiceAddr
|
||||
serviceAddr = ServiceAddrMap[serviceAddOrEditRequest.AreaId]
|
||||
if serviceAddr.Id == 0 {
|
||||
ServiceAddrNotExistError.Fail(ctx, serviceAddOrEditRequest)
|
||||
return
|
||||
}
|
||||
database.Instance().Model(&models.ServiceAddr{}).Where("id = ?", serviceAddOrEditRequest.AreaId).Find(&serviceAddr)
|
||||
userServiceAddr := models.UserServiceAddr{
|
||||
Uid: headerBaseInfo.Uid,
|
||||
Name: serviceAddOrEditRequest.Name,
|
||||
Mobile: serviceAddOrEditRequest.Mobile,
|
||||
AreaId: serviceAddr.Id,
|
||||
Addr: serviceAddOrEditRequest.Addr,
|
||||
Longitude: serviceAddOrEditRequest.Longitude,
|
||||
Latitude: serviceAddOrEditRequest.Latitude,
|
||||
}
|
||||
if len(serviceAddOrEditRequest.Longitude) == 0 || len(serviceAddOrEditRequest.Latitude) == 0 {
|
||||
addrGeocoding := utils.GetAddrGeocoding(utils.BmapGeoCodingRequest{Address: serviceAddOrEditRequest.Addr})
|
||||
userServiceAddr.Longitude = addrGeocoding.Longitude
|
||||
userServiceAddr.Latitude = addrGeocoding.Latitude
|
||||
}
|
||||
serviceAddrLat, _ := strconv.ParseFloat(serviceAddr.Latitude, 64)
|
||||
serviceAddrLng, _ := strconv.ParseFloat(serviceAddr.Longitude, 64)
|
||||
servicePoint := geo.NewPoint(serviceAddrLat, serviceAddrLng)
|
||||
|
||||
userAddrLat, _ := strconv.ParseFloat(userServiceAddr.Latitude, 64)
|
||||
userAddrLng, _ := strconv.ParseFloat(userServiceAddr.Longitude, 64)
|
||||
userPoint := geo.NewPoint(userAddrLat, userAddrLng)
|
||||
// 计算两个点之间的距离(单位:米)
|
||||
distance := servicePoint.GreatCircleDistance(userPoint) * 1000
|
||||
zap_server.ZAPLOG.Info("服务距离", zap.Any("distance", distance), zap.Any("服务经纬度", servicePoint), zap.Any("用户经纬度", userPoint))
|
||||
//超出服务范围
|
||||
if distance >= serviceAddr.DistantGapMeters {
|
||||
NotInServiceExistError.Fail(ctx, serviceAddOrEditRequest)
|
||||
return
|
||||
}
|
||||
if serviceAddOrEditRequest.Id == 0 {
|
||||
database.Instance().Model(&models.UserServiceAddr{}).Create(&userServiceAddr)
|
||||
} else {
|
||||
userServiceAddr.Id = serviceAddOrEditRequest.Id
|
||||
var findUserServiceAddr models.UserServiceAddr
|
||||
database.Instance().Model(&models.UserServiceAddr{}).Where("id = ? and uid = ?", serviceAddOrEditRequest.Id, headerBaseInfo.Uid).Find(&findUserServiceAddr)
|
||||
if findUserServiceAddr.Id == 0 {
|
||||
UserServiceAddrNotExistError.Fail(ctx, serviceAddOrEditRequest)
|
||||
return
|
||||
}
|
||||
updateValues := map[string]interface{}{
|
||||
"Uid": headerBaseInfo.Uid,
|
||||
"Name": serviceAddOrEditRequest.Name,
|
||||
"Mobile": serviceAddOrEditRequest.Mobile,
|
||||
"AreaId": serviceAddr.Id,
|
||||
"Addr": serviceAddOrEditRequest.Addr,
|
||||
"Longitude": serviceAddOrEditRequest.Longitude,
|
||||
"Latitude": serviceAddOrEditRequest.Latitude,
|
||||
}
|
||||
database.Instance().Model(&userServiceAddr).Updates(&updateValues)
|
||||
}
|
||||
var userServiceAddrList []*models.UserServiceAddr
|
||||
database.Instance().Model(&models.UserServiceAddr{}).Where("uid = ?", headerBaseInfo.Uid).Find(&userServiceAddrList)
|
||||
for _, value := range userServiceAddrList {
|
||||
value.Area = ServiceAddrMap[value.AreaId].Addr
|
||||
}
|
||||
Success(ctx, serviceAddOrEditRequest, ServiceAddOrEditResponse{userServiceAddrList})
|
||||
})
|
||||
}}
|
||||
}
|
||||
|
||||
type ServiceAreaAddrListResponse struct {
|
||||
ServiceAddrList []models.ServiceAddr `json:"serviceAddrList"`
|
||||
}
|
||||
|
||||
// 服务区域列表
|
||||
func (p DefParty) serviceAreaAddrList() web_iris.Party {
|
||||
return web_iris.Party{Perfix: p.Perfix, PartyFunc: func(index iris.Party) {
|
||||
index.Post(ServiceBase+"/serviceAreaAddrList", func(ctx *context.Context) {
|
||||
var serviceAddrList []models.ServiceAddr
|
||||
database.Instance().Model(&models.ServiceAddr{}).Find(&serviceAddrList)
|
||||
Success(ctx, nil, ServiceAreaAddrListResponse{serviceAddrList})
|
||||
})
|
||||
}}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ require (
|
||||
github.com/bwmarrin/snowflake v0.3.0
|
||||
github.com/dgb8901/go-wechat-miniapp-sdk v1.0.1-release
|
||||
github.com/kataras/iris/v12 v12.2.10
|
||||
github.com/kellydunn/golang-geo v0.7.0
|
||||
github.com/spf13/viper v1.18.2
|
||||
go.uber.org/zap v1.27.0
|
||||
pet-house.com/core v0.0.0
|
||||
@@ -22,6 +23,7 @@ require (
|
||||
github.com/aymerick/douceur v0.2.0 // indirect
|
||||
github.com/cespare/xxhash/v2 v2.2.0 // indirect
|
||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
|
||||
github.com/erikstmartin/go-testdb v0.0.0-20160219214506-8d10e4a1bae5 // indirect
|
||||
github.com/fatih/structs v1.1.0 // indirect
|
||||
github.com/flosch/pongo2/v4 v4.0.2 // indirect
|
||||
github.com/fsnotify/fsnotify v1.7.0 // indirect
|
||||
@@ -48,9 +50,11 @@ require (
|
||||
github.com/kataras/sitemap v0.0.6 // indirect
|
||||
github.com/kataras/tunnel v0.0.4 // indirect
|
||||
github.com/klauspost/compress v1.17.4 // indirect
|
||||
github.com/kylelemons/go-gypsy v1.0.0 // indirect
|
||||
github.com/leodido/go-urn v1.4.0 // indirect
|
||||
github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible // indirect
|
||||
github.com/lestrrat-go/strftime v1.0.6 // indirect
|
||||
github.com/lib/pq v1.0.0 // indirect
|
||||
github.com/magiconair/properties v1.8.7 // indirect
|
||||
github.com/mailgun/raymond/v2 v2.0.48 // indirect
|
||||
github.com/mailru/easyjson v0.7.7 // indirect
|
||||
@@ -60,6 +64,7 @@ require (
|
||||
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
|
||||
github.com/pkg/errors v0.9.1 // indirect
|
||||
github.com/redis/go-redis/v9 v9.4.0 // indirect
|
||||
github.com/robfig/cron/v3 v3.0.1 // indirect
|
||||
github.com/rogpeppe/go-internal v1.11.0 // indirect
|
||||
github.com/russross/blackfriday/v2 v2.1.0 // indirect
|
||||
github.com/sagikazarmark/locafero v0.4.0 // indirect
|
||||
@@ -77,6 +82,7 @@ require (
|
||||
github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect
|
||||
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
|
||||
github.com/yosssi/ace v0.0.5 // indirect
|
||||
github.com/ziutek/mymysql v1.5.4 // indirect
|
||||
go.uber.org/multierr v1.10.0 // indirect
|
||||
golang.org/x/crypto v0.19.0 // indirect
|
||||
golang.org/x/exp v0.0.0-20240325151524-a685a6edb6d8 // indirect
|
||||
|
||||
@@ -47,6 +47,8 @@ github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/r
|
||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
|
||||
github.com/edsrzf/mmap-go v0.0.0-20170320065105-0bce6a688712/go.mod h1:YO35OhQPt3KJa3ryjFM5Bs14WD66h8eGKpfaBNrHW5M=
|
||||
github.com/elazarl/go-bindata-assetfs v1.0.0/go.mod h1:v+YaWX3bdea5J/mo8dSETolEo7R71Vk1u8bnjau5yw4=
|
||||
github.com/erikstmartin/go-testdb v0.0.0-20160219214506-8d10e4a1bae5 h1:Yzb9+7DPaBjB8zlTR87/ElzFsnQfuHnVUVqpZZIcV5Y=
|
||||
github.com/erikstmartin/go-testdb v0.0.0-20160219214506-8d10e4a1bae5/go.mod h1:a2zkGnVExMxdzMo3M0Hi/3sEU+cWnZpSni0O6/Yb/P0=
|
||||
github.com/fatih/color v1.15.0 h1:kOqh6YHBtK8aywxGerMG2Eq3H6Qgoqeo13Bk2Mv/nBs=
|
||||
github.com/fatih/color v1.15.0/go.mod h1:0h5ZqXfHYED7Bhv2ZJamyIOUej9KtShiJESRwBDUSsw=
|
||||
github.com/fatih/structs v1.1.0 h1:Q7juDM0QtcnhCpeyLGQKyg4TOIghuNXrkL32pHAUMxo=
|
||||
@@ -123,6 +125,8 @@ github.com/kataras/sitemap v0.0.6 h1:w71CRMMKYMJh6LR2wTgnk5hSgjVNB9KL60n5e2KHvLY
|
||||
github.com/kataras/sitemap v0.0.6/go.mod h1:dW4dOCNs896OR1HmG+dMLdT7JjDk7mYBzoIRwuj5jA4=
|
||||
github.com/kataras/tunnel v0.0.4 h1:sCAqWuJV7nPzGrlb0os3j49lk2JhILT0rID38NHNLpA=
|
||||
github.com/kataras/tunnel v0.0.4/go.mod h1:9FkU4LaeifdMWqZu7o20ojmW4B7hdhv2CMLwfnHGpYw=
|
||||
github.com/kellydunn/golang-geo v0.7.0 h1:A5j0/BvNgGwY6Yb6inXQxzYwlPHc6WVZR+MrarZYNNg=
|
||||
github.com/kellydunn/golang-geo v0.7.0/go.mod h1:YYlQPJ+DPEzrHx8kT3oPHC/NjyvCCXE+IuKGKdrjrcU=
|
||||
github.com/klauspost/compress v1.17.4 h1:Ej5ixsIri7BrIjBkRZLTo6ghwrEtHFk7ijlczPW4fZ4=
|
||||
github.com/klauspost/compress v1.17.4/go.mod h1:/dCuZOvVtNoHsyb+cuJD3itjs3NbnF6KH9zAO4BDxPM=
|
||||
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
||||
@@ -131,6 +135,8 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||
github.com/kylelemons/go-gypsy v1.0.0 h1:7/wQ7A3UL1bnqRMnZ6T8cwCOArfZCxFmb1iTxaOOo1s=
|
||||
github.com/kylelemons/go-gypsy v1.0.0/go.mod h1:chkXM0zjdpXOiqkCW1XcCHDfjfk14PH2KKkQWxfJUcU=
|
||||
github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
|
||||
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
|
||||
github.com/lestrrat-go/envload v0.0.0-20180220234015-a3eb8ddeffcc h1:RKf14vYWi2ttpEmkA4aQ3j4u9dStX2t4M8UM6qqNsG8=
|
||||
@@ -139,6 +145,7 @@ github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible h1:Y6sqxHMyB1D2YSzWkL
|
||||
github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible/go.mod h1:ZQnN8lSECaebrkQytbHj4xNgtg8CR7RYXnPok8e0EHA=
|
||||
github.com/lestrrat-go/strftime v1.0.6 h1:CFGsDEt1pOpFNU+TJB0nhz9jl+K0hZSLE205AhTIGQQ=
|
||||
github.com/lestrrat-go/strftime v1.0.6/go.mod h1:f7jQKgV5nnJpYgdEasS+/y7EsTb8ykN2z68n3TtcTaw=
|
||||
github.com/lib/pq v1.0.0 h1:X5PMW56eZitiTeO7tKzZxFCSpbFZJtkMMooicw2us9A=
|
||||
github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
|
||||
github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY=
|
||||
github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0=
|
||||
@@ -170,6 +177,8 @@ github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRI
|
||||
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/redis/go-redis/v9 v9.4.0 h1:Yzoz33UZw9I/mFhx4MNrB6Fk+XHO1VukNcCa1+lwyKk=
|
||||
github.com/redis/go-redis/v9 v9.4.0/go.mod h1:hdY0cQFCN4fnSYT6TkisLufl/4W5UIXyv0b/CLO2V2M=
|
||||
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
|
||||
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
|
||||
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
|
||||
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
|
||||
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
|
||||
@@ -243,6 +252,8 @@ github.com/yudai/gojsondiff v1.0.0/go.mod h1:AY32+k2cwILAkW1fbgxQ5mUmMiZFgLIV+FB
|
||||
github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 h1:BHyfKlQyqbsFN5p3IfnEUduWvb9is428/nNb5L3U01M=
|
||||
github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82/go.mod h1:lgjkn3NuSvDfVJdfcVVdX+jpBxNmX4rDAzaS45IcYoM=
|
||||
github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
|
||||
github.com/ziutek/mymysql v1.5.4 h1:GB0qdRGsTwQSBVYuVShFBKaXSnSnYYC2d9knnE1LHFs=
|
||||
github.com/ziutek/mymysql v1.5.4/go.mod h1:LMSpPZ6DbqWFxNCHW77HeMg9I646SAhApZ/wKdgO/C0=
|
||||
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
|
||||
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
|
||||
go.uber.org/multierr v1.10.0 h1:S0h4aNzvfcFsC3dRF1jLoaov7oRaKqRGC/pUEJ2yvPQ=
|
||||
|
||||
+1
-4
@@ -1,8 +1,6 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"go.uber.org/zap"
|
||||
"os"
|
||||
"pet-house.com/business/api"
|
||||
"pet-house.com/core/server/web"
|
||||
"pet-house.com/core/server/web/web_iris"
|
||||
@@ -15,7 +13,6 @@ func main() {
|
||||
wi.AddFrontFunc(api.FrontAuth)
|
||||
wi.AddWebStatic("./static", "/static")
|
||||
api.ModuleInit()
|
||||
api.DataInit()
|
||||
zap_server.ZAPLOG.Info("main start success", zap.Any("pid", os.Getegid()))
|
||||
zap_server.ZAPLOG.Info("main start success")
|
||||
web.Start(wi)
|
||||
}
|
||||
|
||||
@@ -49,10 +49,11 @@ type PetBaseInfo struct {
|
||||
|
||||
// ServiceAddr 服务地址
|
||||
type ServiceAddr struct {
|
||||
Id int64 `gorm:"primaryKey;autoIncrement" json:"id"` //ID
|
||||
Longitude string `json:"longitude"` //经度
|
||||
Latitude string `json:"latitude"` //纬度
|
||||
Addr string `gorm:"not null" json:"addr"` //详细地址
|
||||
Id int64 `gorm:"primaryKey;autoIncrement" json:"id"` //ID
|
||||
Longitude string `json:"longitude"` //经度
|
||||
Latitude string `json:"latitude"` //纬度
|
||||
Addr string `gorm:"not null" json:"addr"` //详细地址
|
||||
DistantGapMeters float64 `gorm:"not null" json:"distantGapMeters"` //服务最远距离 单位/米
|
||||
}
|
||||
|
||||
// UserServiceAddr 用户服务地址
|
||||
@@ -61,8 +62,11 @@ type UserServiceAddr struct {
|
||||
Uid int64 `gorm:"index;not null" json:"uid"` //用户ID
|
||||
Name string `gorm:"not null" json:"name"` //名称
|
||||
Mobile string `gorm:"not null" json:"mobile"` //手机号
|
||||
Area string `gorm:"not null" json:"area"` //服务区域 精确到区县级
|
||||
AreaId int64 `gorm:"not null" json:"areaId"` //服务区域ID
|
||||
Addr string `gorm:"not null" json:"addr"` //详细地址
|
||||
Longitude string `json:"longitude"` //经度
|
||||
Latitude string `json:"latitude"` //纬度
|
||||
Area string `gorm:"-" json:"area"` //服务区域
|
||||
CreateTime time.Time `gorm:"type:timestamp;default:CURRENT_TIMESTAMP;not null" json:"-"` //创建时间
|
||||
}
|
||||
|
||||
@@ -76,16 +80,18 @@ type Goods struct {
|
||||
ParentId int64 `gorm:"not null" json:"parentId"` //商品父ID
|
||||
BuyMany int `gorm:"not null" json:"buyMany"` //同类型是否可购买多个 0否 1是
|
||||
GoodsDetail string `gorm:"not null" json:"goodsDetail"` //商品详情 图片URL
|
||||
GoodsIcon string `json:"goodsIcon"` //iconUrl
|
||||
CreateTime time.Time `gorm:"type:timestamp;default:CURRENT_TIMESTAMP" json:"-"` //创建时间
|
||||
}
|
||||
|
||||
// PetGoods 宠物商品
|
||||
type PetGoods struct {
|
||||
Id int64 `gorm:"primaryKey;autoIncrement" json:"id"` //id
|
||||
Assortment int `gorm:"not null" json:"assortment"` //品种 优先用品种查询 如不存在 则用类型及大小查询
|
||||
Assortment int `gorm:"not null" json:"assortment"` //品种Id 优先用品种查询 如不存在 则用类型及大小查询
|
||||
PetType int `gorm:"not null" json:"petType"` //类型 1猫 2狗
|
||||
Size int `gorm:"not null" json:"size"` //大小 1大 2中 3小
|
||||
GoodsId int64 `gorm:"not null" json:"goodsId"` //商品ID
|
||||
Sort int `gorm:"not null" json:"sort"` //排序
|
||||
CreateTime time.Time `gorm:"type:timestamp;default:CURRENT_TIMESTAMP" json:"-"` //创建时间
|
||||
}
|
||||
|
||||
@@ -100,36 +106,36 @@ type SystemConfig struct {
|
||||
|
||||
// OrderMain 主订单
|
||||
type OrderMain struct {
|
||||
Id int64 `gorm:"primaryKey;autoIncrement" json:"id"` //id
|
||||
OrderId string `gorm:"index;unique;not null" json:"orderId"` //主订单号
|
||||
Uid int64 `gorm:"index;not null" json:"uid"` //用户id
|
||||
Status int `json:"status"` //主订单状态 1待服务 2服务中 3已完成
|
||||
CreateTime time.Time `gorm:"type:timestamp;default:CURRENT_TIMESTAMP" json:"createTime"` //创建时间
|
||||
Id int64 `gorm:"primaryKey;autoIncrement" json:"id"` //id
|
||||
OrderId string `gorm:"index;unique;not null" json:"orderId"` //主订单号
|
||||
Uid int64 `gorm:"index;not null" json:"uid"` //用户id
|
||||
Status int `json:"status"` //主订单状态 1待服务 2服务中 3已完成
|
||||
ServiceTime string `json:"serviceTime"` //服务时间
|
||||
ServiceAddrId int64 `json:"serviceAddrId"` //服务地址信息
|
||||
ServiceRemark string `json:"serviceRemark"` //服务备注
|
||||
CreateTime time.Time `gorm:"type:timestamp;default:CURRENT_TIMESTAMP" json:"createTime"` //创建时间
|
||||
}
|
||||
|
||||
// OrderSub 子订单
|
||||
type OrderSub struct {
|
||||
Id int64 `gorm:"primaryKey;autoIncrement" json:"id"` //id
|
||||
MainOrderId int64 `gorm:"index" json:"mainOrderId"` //主订单ID
|
||||
Status int `gorm:"not null" json:"status"` //子订单状态 1待服务 2服务中 3已完成 4已取消
|
||||
PetId int64 `gorm:"index" json:"petId"` //宠物ID
|
||||
PayType int `gorm:"not null" json:"payType"` //支付方式 1线下 2线上
|
||||
Discount int `json:"discount"` //折扣
|
||||
TotalAmount int32 `gorm:"not null" json:"totalAmount"` //总金额
|
||||
PayAmount int32 `json:"payAmount"` //实际支付金额
|
||||
PayTime string `json:"payTime"` //支付时间
|
||||
ReserveTime string `gorm:"not null" json:"reserveTime"` //预约时间
|
||||
ServiceTime string `json:"serviceTime"` //服务时间
|
||||
ServiceAddrId int64 `json:"serviceAddrId"` //服务地址信息
|
||||
ServiceRemark string `json:"serviceRemark"` //服务备注
|
||||
CreateTime time.Time `gorm:"type:timestamp;default:CURRENT_TIMESTAMP" json:"createTime"` //创建时间
|
||||
UpdateTime time.Time `gorm:"type:timestamp;default:CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP" json:"-"` //更新时间
|
||||
Id int64 `gorm:"primaryKey;autoIncrement" json:"id"` //id
|
||||
OrderId string `gorm:"index" json:"orderId"` //子订单ID
|
||||
MainOrderId string `gorm:"index" json:"mainOrderId"` //主订单ID
|
||||
Status int `gorm:"not null" json:"status"` //子订单状态 1待服务 2服务中 3已完成 4已取消
|
||||
PetId int64 `gorm:"index" json:"petId"` //宠物ID
|
||||
PayType int `gorm:"not null" json:"payType"` //支付方式 1线下 2线上
|
||||
Discount int `json:"discount"` //折扣
|
||||
TotalAmount int32 `gorm:"not null" json:"totalAmount"` //总金额
|
||||
PayAmount int32 `json:"payAmount"` //实际支付金额
|
||||
PayTime time.Time `gorm:"type:timestamp;" json:"payTime"` //支付时间
|
||||
CreateTime time.Time `gorm:"type:timestamp;default:CURRENT_TIMESTAMP" json:"createTime"` //创建时间
|
||||
UpdateTime time.Time `gorm:"type:timestamp;default:CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP" json:"-"` //更新时间
|
||||
}
|
||||
|
||||
// OrderDetail 订单明细
|
||||
type OrderDetail struct {
|
||||
Id int64 `gorm:"primaryKey;autoIncrement" json:"id"` //id
|
||||
SubOrderId int64 `gorm:"index;not null" json:"subOrderId"` //子订单ID
|
||||
GoodsId int64 `gorm:"index;not null" json:"goodsId"` //商品ID
|
||||
Amount int `gorm:"not null" json:"amount"` //价格
|
||||
Id int64 `gorm:"primaryKey;autoIncrement" json:"id"` //id
|
||||
SubOrderId string `gorm:"index;not null" json:"subOrderId"` //子订单ID
|
||||
GoodsId int64 `gorm:"index;not null" json:"goodsId"` //商品ID
|
||||
Amount int32 `gorm:"not null" json:"amount"` //价格
|
||||
}
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
var ak = "ji0v0JfOZDlXHmICe93NFMEN67AxMSxN"
|
||||
var host = "https://api.map.baidu.com"
|
||||
var uri = "/geocoding/v3"
|
||||
|
||||
type Location struct {
|
||||
Lng float64
|
||||
Lat float64
|
||||
}
|
||||
type GeocodingResponse struct {
|
||||
Status int
|
||||
Result struct {
|
||||
Location Location
|
||||
Precise int
|
||||
Confidence int
|
||||
Comprehension int
|
||||
Level string
|
||||
}
|
||||
}
|
||||
|
||||
type BmapGeoCodingRequest struct {
|
||||
Address string
|
||||
}
|
||||
|
||||
type BmapGeoCodingResponse struct {
|
||||
Longitude string
|
||||
Latitude string
|
||||
}
|
||||
|
||||
func GetAddrGeocoding(request BmapGeoCodingRequest) *BmapGeoCodingResponse {
|
||||
// 设置请求参数
|
||||
params := url.Values{
|
||||
"address": []string{request.Address},
|
||||
"output": []string{"json"},
|
||||
"ak": []string{ak},
|
||||
}
|
||||
|
||||
// 发起请求
|
||||
requestStr, _ := url.Parse(host + uri + "?" + params.Encode())
|
||||
resp, err := http.Get(requestStr.String())
|
||||
if err != nil || resp.StatusCode != 200 {
|
||||
return nil
|
||||
}
|
||||
r, _ := io.ReadAll(resp.Body)
|
||||
var response GeocodingResponse
|
||||
json.Unmarshal(r, &response)
|
||||
bmapGeoCodingResponse := BmapGeoCodingResponse{strconv.FormatFloat(response.Result.Location.Lng, 'f', -1, 64), strconv.FormatFloat(response.Result.Location.Lat, 'f', -1, 64)}
|
||||
return &bmapGeoCodingResponse
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestBmapGeocoding(t *testing.T) {
|
||||
var addr = "上海市浦东新区日月光集团员工生活区"
|
||||
addrGeocoding := GetAddrGeocoding(BmapGeoCodingRequest{addr})
|
||||
fmt.Println("addrGeocoding : " + addrGeocoding.Latitude + "_" + addrGeocoding.Longitude)
|
||||
}
|
||||
Reference in New Issue
Block a user