新增逻辑 根据车辆数量及单次服务数量来决定时间点是否可预约
This commit is contained in:
parent
5421ae8a87
commit
74ae25bcd0
|
|
@ -1 +1,9 @@
|
||||||
package api
|
package api
|
||||||
|
|
||||||
|
import "pet-house.com/business/models"
|
||||||
|
|
||||||
|
var CarServiceNum = 2
|
||||||
|
|
||||||
|
func GetCarInfo(carId int) models.ServiceCar {
|
||||||
|
return CarMap[carId]
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -112,6 +112,8 @@ var PetBaseInfoMap map[int]models.PetBaseInfo
|
||||||
var ServiceAddrMap map[int64]models.ServiceAddr
|
var ServiceAddrMap map[int64]models.ServiceAddr
|
||||||
var PetGoodsMap map[string][]models.PetGoods
|
var PetGoodsMap map[string][]models.PetGoods
|
||||||
var GoodsMap map[int64]models.Goods
|
var GoodsMap map[int64]models.Goods
|
||||||
|
var CarMap map[int]models.ServiceCar
|
||||||
|
var ReserveMap map[string]models.ReserveTimeFilter
|
||||||
|
|
||||||
func DataInit() {
|
func DataInit() {
|
||||||
//--------------------------------------------------宠物基础信息数据---------------------------------------------------------
|
//--------------------------------------------------宠物基础信息数据---------------------------------------------------------
|
||||||
|
|
@ -150,6 +152,20 @@ func DataInit() {
|
||||||
GoodsMap[value.Id] = value
|
GoodsMap[value.Id] = value
|
||||||
}
|
}
|
||||||
zap_server.ZAPLOG.Info("dataInit GoodsMap : ", zap.Any("GoodsMap", GoodsMap))
|
zap_server.ZAPLOG.Info("dataInit GoodsMap : ", zap.Any("GoodsMap", GoodsMap))
|
||||||
|
var carList []models.ServiceCar
|
||||||
|
database.Instance().Model(&models.ServiceCar{}).Find(&carList)
|
||||||
|
CarMap = make(map[int]models.ServiceCar)
|
||||||
|
for _, value := range carList {
|
||||||
|
CarMap[value.Id] = value
|
||||||
|
}
|
||||||
|
zap_server.ZAPLOG.Info("dataInit CarMap : ", zap.Any("CarMap", CarMap))
|
||||||
|
var timesList []models.ReserveTimeFilter
|
||||||
|
database.Instance().Model(&models.ReserveTimeFilter{}).Find(×List)
|
||||||
|
ReserveMap = make(map[string]models.ReserveTimeFilter)
|
||||||
|
for _, value := range timesList {
|
||||||
|
ReserveMap[value.Content] = value
|
||||||
|
}
|
||||||
|
zap_server.ZAPLOG.Info("dataInit ReserveMap : ", zap.Any("ReserveMap", CarMap))
|
||||||
}
|
}
|
||||||
|
|
||||||
func DataCacheJob() {
|
func DataCacheJob() {
|
||||||
|
|
|
||||||
|
|
@ -41,6 +41,7 @@ func ModuleInit() {
|
||||||
&models.ServiceCarUser{},
|
&models.ServiceCarUser{},
|
||||||
&models.ServiceUserMark{},
|
&models.ServiceUserMark{},
|
||||||
&models.ServiceUserMarkRecord{},
|
&models.ServiceUserMarkRecord{},
|
||||||
|
&models.ReserveTimeFilter{},
|
||||||
)
|
)
|
||||||
DataInit()
|
DataInit()
|
||||||
DataCacheJob()
|
DataCacheJob()
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
"io"
|
"io"
|
||||||
"pet-house.com/business/models"
|
"pet-house.com/business/models"
|
||||||
|
"pet-house.com/business/utils"
|
||||||
"pet-house.com/core/server/database"
|
"pet-house.com/core/server/database"
|
||||||
"pet-house.com/core/server/web/web_iris"
|
"pet-house.com/core/server/web/web_iris"
|
||||||
"pet-house.com/core/server/zap_server"
|
"pet-house.com/core/server/zap_server"
|
||||||
|
|
@ -221,11 +222,52 @@ func (p DefParty) orderList() web_iris.Party {
|
||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type TimeObject struct {
|
||||||
|
Time string `json:"time"`
|
||||||
|
Y bool `json:"y"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type OrderServiceTimeResponse struct {
|
||||||
|
Times map[string][]TimeObject `json:"times"`
|
||||||
|
}
|
||||||
|
|
||||||
// 获取订单可预约时间
|
// 获取订单可预约时间
|
||||||
func (p DefParty) orderServiceTime() web_iris.Party {
|
func (p DefParty) orderServiceTime() web_iris.Party {
|
||||||
return web_iris.Party{Prefix: p.Prefix, PartyFunc: func(index iris.Party) {
|
return web_iris.Party{Prefix: p.Prefix, PartyFunc: func(index iris.Party) {
|
||||||
index.Post(OrderBase+"/orderServiceTime", func(ctx *context.Context) {
|
index.Post(OrderBase+"/orderServiceTime", func(ctx *context.Context) {
|
||||||
|
headerBaseInfo := GetHeaderBaseInfo(ctx)
|
||||||
|
type orderMainTmp struct {
|
||||||
|
ServiceTime string
|
||||||
|
}
|
||||||
|
var orderMainTmpList []orderMainTmp
|
||||||
|
database.Instance().Model(&models.OrderMain{}).Where("service_time >= DATE_SUB(NOW(), INTERVAL 7 DAY) and status != 3 and status != 5").Find(&orderMainTmpList)
|
||||||
|
var orderTimeMap = make(map[string]string)
|
||||||
|
var orderTimeNum = make(map[string]int)
|
||||||
|
for _, value := range orderMainTmpList {
|
||||||
|
orderTimeMap[value.ServiceTime] = value.ServiceTime
|
||||||
|
orderTimeNum[value.ServiceTime] = orderTimeNum[value.ServiceTime] + 1
|
||||||
|
}
|
||||||
|
carNum := len(CarMap)
|
||||||
|
daysMap := utils.GetStrDays(7, 30, ReserveMap, orderTimeMap, carNum, orderTimeNum, 2)
|
||||||
|
var dayHoursMap = make(map[string][]TimeObject)
|
||||||
|
for day, values := range daysMap {
|
||||||
|
key := day
|
||||||
|
for _, value := range values {
|
||||||
|
if _, ok := dayHoursMap[key]; ok {
|
||||||
|
dayHoursMap[key] = append(dayHoursMap[key], TimeObject{
|
||||||
|
Time: value.Time,
|
||||||
|
Y: value.Y,
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
dayHoursMap[key] = []TimeObject{{
|
||||||
|
Time: value.Time,
|
||||||
|
Y: value.Y,
|
||||||
|
}}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
Success(ctx, headerBaseInfo, OrderServiceTimeResponse{dayHoursMap})
|
||||||
})
|
})
|
||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -193,3 +193,10 @@ type ServiceUserMarkRecord struct {
|
||||||
CreateTime time.Time `gorm:"type:timestamp;default:CURRENT_TIMESTAMP" json:"-"` //创建时间
|
CreateTime time.Time `gorm:"type:timestamp;default:CURRENT_TIMESTAMP" json:"-"` //创建时间
|
||||||
UpdateTime time.Time `gorm:"type:timestamp;default:CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP" json:"-"` //更新时间
|
UpdateTime time.Time `gorm:"type:timestamp;default:CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP" json:"-"` //更新时间
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ReserveTimeFilter 服务过滤时间
|
||||||
|
type ReserveTimeFilter struct {
|
||||||
|
Id int `gorm:"primaryKey;autoIncrement" json:"id"` //id
|
||||||
|
Type int `gorm:"not null" json:"type"` //类型 1日期 2小时
|
||||||
|
Content string `gorm:"not null" json:"content"` //类型 具体内容 比如:2024-04-08 12
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,8 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"github.com/kataras/iris/v12/context"
|
"github.com/kataras/iris/v12/context"
|
||||||
"io"
|
"io"
|
||||||
|
"pet-house.com/business/models"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func CtxBodyJSONParse(ctx *context.Context) any {
|
func CtxBodyJSONParse(ctx *context.Context) any {
|
||||||
|
|
@ -12,3 +14,86 @@ func CtxBodyJSONParse(ctx *context.Context) any {
|
||||||
_ = json.Unmarshal(body, _i)
|
_ = json.Unmarshal(body, _i)
|
||||||
return _i
|
return _i
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type TimeObject struct {
|
||||||
|
Time string `json:"time"`
|
||||||
|
Y bool `json:"y"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetStrDays(day int, hour int, reserveMap map[string]models.ReserveTimeFilter, orderTimeMap map[string]string, carNum int, orderNumMap map[string]int, carServiceNum int) map[string][]TimeObject {
|
||||||
|
// 获取当前时间
|
||||||
|
currentTime := time.Now()
|
||||||
|
// 计算半小时后的时间
|
||||||
|
halfHourLater := currentTime.Add(time.Duration(hour) * time.Minute)
|
||||||
|
|
||||||
|
// 计算下一个整点时间
|
||||||
|
nextHour := time.Date(
|
||||||
|
halfHourLater.Year(),
|
||||||
|
halfHourLater.Month(),
|
||||||
|
halfHourLater.Day(),
|
||||||
|
halfHourLater.Hour()+1, // 下一个整点小时
|
||||||
|
0, // 下一个整点分钟数为0
|
||||||
|
0, // 下一个整点秒数为0
|
||||||
|
0, // 下一个整点纳秒数为0
|
||||||
|
time.Local, // 下一个整点时区
|
||||||
|
)
|
||||||
|
|
||||||
|
// 工作时间范围
|
||||||
|
workStart := 9
|
||||||
|
workEnd := 19
|
||||||
|
var dayHoursMap = make(map[string][]TimeObject)
|
||||||
|
// 循环生成每半个小时的整点时间列表,直到一周后
|
||||||
|
oneWeekLater := currentTime.Add(time.Duration(day) * 24 * time.Hour)
|
||||||
|
for nextHour.Before(oneWeekLater) {
|
||||||
|
//且不存在过滤时间中
|
||||||
|
_, existsDay := reserveMap[nextHour.Format("2006-01-02")]
|
||||||
|
_, existsHour := reserveMap[nextHour.Format("15")]
|
||||||
|
_, existOrderTime := orderTimeMap[nextHour.Format("2006-01-02 15:04:00")]
|
||||||
|
orderNum, existOrderNum := orderNumMap[nextHour.Format("2006-01-02 15:04:00")]
|
||||||
|
if (nextHour.Hour() >= workStart && nextHour.Hour() < workEnd) && (!existsDay && !existsHour) && !existOrderTime {
|
||||||
|
key := nextHour.Format("2006-01-02")
|
||||||
|
if _, ok := dayHoursMap[key]; ok {
|
||||||
|
dayHoursMap[key] = append(dayHoursMap[key], TimeObject{
|
||||||
|
Time: nextHour.Format("15:04"),
|
||||||
|
Y: true,
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
dayHoursMap[key] = []TimeObject{{
|
||||||
|
Time: nextHour.Format("15:04"),
|
||||||
|
Y: true,
|
||||||
|
}}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
key := nextHour.Format("2006-01-02")
|
||||||
|
//当前订单数小于车辆数 可接单
|
||||||
|
if existOrderNum && orderNum < carNum*carServiceNum {
|
||||||
|
if _, ok := dayHoursMap[key]; ok {
|
||||||
|
dayHoursMap[key] = append(dayHoursMap[key], TimeObject{
|
||||||
|
Time: nextHour.Format("15:04"),
|
||||||
|
Y: true,
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
dayHoursMap[key] = []TimeObject{{
|
||||||
|
Time: nextHour.Format("15:04"),
|
||||||
|
Y: true,
|
||||||
|
}}
|
||||||
|
}
|
||||||
|
} else if nextHour.Hour() >= workStart && nextHour.Hour() < workEnd {
|
||||||
|
if _, ok := dayHoursMap[key]; ok {
|
||||||
|
dayHoursMap[key] = append(dayHoursMap[key], TimeObject{
|
||||||
|
Time: nextHour.Format("15:04"),
|
||||||
|
Y: false,
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
dayHoursMap[key] = []TimeObject{{
|
||||||
|
Time: nextHour.Format("15:04"),
|
||||||
|
Y: false,
|
||||||
|
}}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
nextHour = nextHour.Add(30 * time.Minute) // 下一个整点半时间
|
||||||
|
}
|
||||||
|
return dayHoursMap
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,22 @@
|
||||||
|
package utils
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"pet-house.com/business/models"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestGetStrDays(t *testing.T) {
|
||||||
|
var ReserveMap map[string]models.ReserveTimeFilter
|
||||||
|
ReserveMap = make(map[string]models.ReserveTimeFilter)
|
||||||
|
ReserveMap["2024-04-10"] = models.ReserveTimeFilter{
|
||||||
|
Type: 1,
|
||||||
|
Content: "2024-04-10",
|
||||||
|
}
|
||||||
|
ReserveMap["12"] = models.ReserveTimeFilter{
|
||||||
|
Type: 2,
|
||||||
|
Content: "12",
|
||||||
|
}
|
||||||
|
days := GetStrDays(7, 30, ReserveMap, nil, 1, nil, 2)
|
||||||
|
fmt.Println(days)
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue