This commit is contained in:
yan.y 2024-12-28 19:10:40 +08:00
parent 346412fef8
commit e0d302c5f5
4 changed files with 61 additions and 33 deletions

View File

@ -62,6 +62,7 @@ func (p DefParty) RegisterList() []web_iris.Party {
//系统 //系统
p.systemConfigInfo(), p.systemConfigInfo(),
p.systemBanners(), p.systemBanners(),
p.getPayoff(),
} }
return ps return ps
} }

View File

@ -95,9 +95,9 @@ func (p DefParty) orderCreatePreCheck() web_iris.Party {
} }
} }
var systemConfigPay models.SystemConfig var systemConfigPay models.SystemConfig
database.Instance().Model(&models.SystemConfig{}).Where("config_type = 3").Order(clause.OrderByColumn{Column: clause.Column{Name: "sort"}, Desc: true}).Limit(1).Find(&systemConfigPay) database.Instance().Model(&models.SystemConfig{}).Where("config_type = 4").Order(clause.OrderByColumn{Column: clause.Column{Name: "sort"}, Desc: true}).Limit(1).Find(&systemConfigPay)
if systemConfigPay.Name == "payOff" { if systemConfigPay.Name == "payOff" {
orderCreatePreCheckResponse.PayType = 0 orderCreatePreCheckResponse.PayType = 1
} }
Success(ctx, orderCreateRequest, orderCreatePreCheckResponse) Success(ctx, orderCreateRequest, orderCreatePreCheckResponse)
@ -478,14 +478,15 @@ func GetOrderDetail(orderId string) OrderDetail {
} }
orderSubR1 := SubOrder{ orderSubR1 := SubOrder{
OrderId: orderSub.OrderId, OrderId: orderSub.OrderId,
Status: orderSub.OrderStatus, Status: orderSub.OrderStatus,
UserPetInfo: GetUserPet(orderMain.Uid, orderSub.PetId), UserPetInfo: GetUserPet(orderMain.Uid, orderSub.PetId),
TotalAmount: orderSub.TotalAmount, TotalAmount: orderSub.TotalAmount,
PayAmount: strconv.Itoa(orderSub.PayAmount), PayAmount: strconv.Itoa(orderSub.PayAmount),
Discount: float64(orderSub.Discount), Discount: float64(orderSub.Discount),
Goods: goods, Goods: goods,
Coupons: nil, Coupons: nil,
CouponsAmount: "0",
} }
if coupons.Id > 0 { if coupons.Id > 0 {
orderSubR1.Coupons = &models.Coupons{ orderSubR1.Coupons = &models.Coupons{
@ -545,7 +546,7 @@ func GetOrderDetail(orderId string) OrderDetail {
} }
func checkOrderServiceTime(serviceTime string, projectionServiceTime int) bool { func checkOrderServiceTime(serviceTime string, projectionServiceTime int) bool {
type orderMainTmp struct { /*type orderMainTmp struct {
ServiceTime string ServiceTime string
ProjectionServiceTime int ProjectionServiceTime int
} }
@ -564,7 +565,7 @@ func checkOrderServiceTime(serviceTime string, projectionServiceTime int) bool {
//时间点订单数量<服务车辆*车辆单次服务数量 才可接受预约 //时间点订单数量<服务车辆*车辆单次服务数量 才可接受预约
if len(orderMainTmpList) > 0 { if len(orderMainTmpList) > 0 {
return len(orderMainTmpList) >= len(CarMap)*CarServiceNum return len(orderMainTmpList) >= len(CarMap)*CarServiceNum
} }*/
return false return false
} }
@ -804,11 +805,12 @@ func (p DefParty) orderServiceTime() web_iris.Party {
database.Instance().Model(&models.OrderMain{}).Where("service_time >= DATE_SUB(NOW(), INTERVAL 7 DAY) and order_status != 3 and order_status != 4 and status = 1").Find(&orderMainTmpList) database.Instance().Model(&models.OrderMain{}).Where("service_time >= DATE_SUB(NOW(), INTERVAL 7 DAY) and order_status != 3 and order_status != 4 and status = 1").Find(&orderMainTmpList)
// 执行查询 // 执行查询
var orderMainTmp1 []struct { var orderMainTmp1 []struct {
ServiceTime string ServiceTime string
Count int Count int
ProjectionServiceTime int
} }
err := database.Instance().Raw(` err := database.Instance().Raw(`
SELECT service_time, COUNT(1) AS count SELECT service_time, COUNT(1) AS count, projection_service_time
FROM order_mains FROM order_mains
WHERE service_time >= DATE_SUB(NOW(), INTERVAL 7 DAY) WHERE service_time >= DATE_SUB(NOW(), INTERVAL 7 DAY)
AND order_status != 3 AND order_status != 3
@ -825,8 +827,10 @@ func (p DefParty) orderServiceTime() web_iris.Party {
var orderTimeMap = make(map[string]string) var orderTimeMap = make(map[string]string)
var orderTimeNum = make(map[string]int) var orderTimeNum = make(map[string]int)
var orderTimeCount = make(map[string]int) var orderTimeCount = make(map[string]int)
var orderProjectionTime = make(map[string]int)
for _, val := range orderMainTmp1 { for _, val := range orderMainTmp1 {
orderTimeCount[val.ServiceTime] = val.Count orderTimeCount[val.ServiceTime] = val.Count
orderProjectionTime[val.ServiceTime] = val.ProjectionServiceTime
} }
for _, value := range orderMainTmpList { for _, value := range orderMainTmpList {
@ -838,15 +842,18 @@ func (p DefParty) orderServiceTime() web_iris.Party {
lastDate := date.Add(time.Minute * time.Duration(value.ProjectionServiceTime)) lastDate := date.Add(time.Minute * time.Duration(value.ProjectionServiceTime))
for t := date; t.Before(lastDate); t = t.Add(time.Hour) { for t := date; t.Before(lastDate); t = t.Add(time.Hour) {
timeStr := t.Format("2006-01-02 15:04") timeStr := t.Format("2006-01-02 15:04")
orderTimeMap[timeStr] = timeStr if timeStr != value.ServiceTime {
orderTimeNum[timeStr] = orderTimeNum[timeStr] + 1 orderTimeMap[timeStr] = timeStr
orderTimeNum[timeStr] = orderTimeNum[timeStr] + 1
orderTimeCount[timeStr] = orderTimeCount[timeStr] + 1
}
} }
} }
} }
serviceTime := AddrServiceMap[orderServiceTimeRequest.ServiceAddrId] serviceTime := AddrServiceMap[orderServiceTimeRequest.ServiceAddrId]
times := strings.Split(serviceTime.Times, ",") times := strings.Split(serviceTime.Times, ",")
carNum := len(CarMap) carNum := len(CarMap)
daysMap := utils.GetStrDays(7, 60, ReserveMap, orderTimeMap, carNum, orderTimeNum, CarServiceNum, times, orderTimeCount) daysMap := utils.GetStrDays(7, 60, ReserveMap, orderTimeMap, carNum, orderTimeNum, CarServiceNum, times, orderTimeCount, orderProjectionTime)
var dayHoursMap = make(map[string][]TimeObject) var dayHoursMap = make(map[string][]TimeObject)
for day, values := range daysMap { for day, values := range daysMap {
key := day key := day

View File

@ -42,3 +42,18 @@ func (p DefParty) systemBanners() web_iris.Party {
}) })
}} }}
} }
type PayoffResponse struct {
Payoff bool `json:"payoff"`
}
// 获取支付开关
func (p DefParty) getPayoff() web_iris.Party {
return web_iris.Party{Prefix: p.Prefix, PartyFunc: func(index iris.Party) {
index.Post(System+"/getPayoff", func(ctx *context.Context) {
var systemConfigPayOnOff models.SystemConfig
database.Instance().Model(&models.SystemConfig{}).Where("config_type = 4").Order(clause.OrderByColumn{Column: clause.Column{Name: "sort"}, Desc: true}).Limit(1).Find(&systemConfigPayOnOff)
Success(ctx, nil, PayoffResponse{systemConfigPayOnOff.Name == "payOff"})
})
}}
}

View File

@ -21,7 +21,7 @@ type TimeObject struct {
Y bool `json:"y"` Y bool `json:"y"`
} }
func GetStrDays(day int, minute int, reserveMap map[string]models.ReserveTimeFilter, orderTimeMap map[string]string, carNum int, orderNumMap map[string]int, carServiceNum int, times []string, orderTimeCount map[string]int) map[string][]TimeObject { func GetStrDays(day int, minute int, reserveMap map[string]models.ReserveTimeFilter, orderTimeMap map[string]string, carNum int, orderNumMap map[string]int, carServiceNum int, times []string, orderTimeCount map[string]int, projectionTime map[string]int) map[string][]TimeObject {
// 获取当前时间 // 获取当前时间
currentTime := time.Now() currentTime := time.Now()
// 计算半小时后的时间 // 计算半小时后的时间
@ -51,23 +51,27 @@ func GetStrDays(day int, minute int, reserveMap map[string]models.ReserveTimeFil
serviceDaysMap[dayTime] = dayTime serviceDaysMap[dayTime] = dayTime
} }
for nextHour.Before(oneWeekLater) { for nextHour.Before(oneWeekLater) {
key := nextHour.Format("2006-01-02")
key1 := nextHour.Format("2006-01-02 15:04")
if nextHour.Hour() < workStart || nextHour.Hour() > workEnd {
nextHour = nextHour.Add(time.Duration(minute) * time.Minute)
continue
}
if _, ok := serviceDaysMap[key1]; len(serviceDaysMap) > 0 && !ok {
//不存在服务配置中返回false
dayHoursMap[key] = append(dayHoursMap[key], TimeObject{
Time: nextHour.Format("15:04"),
Y: false,
})
nextHour = nextHour.Add(time.Duration(minute) * time.Minute)
continue
}
//且不存在过滤时间中 //且不存在过滤时间中
_, existsDay := reserveMap[nextHour.Format("2006-01-02")] _, existsDay := reserveMap[nextHour.Format("2006-01-02")]
_, existsHour := reserveMap[nextHour.Format("15")] _, existsHour := reserveMap[nextHour.Format("15")]
_, existOrderTime := orderTimeMap[nextHour.Format("2006-01-02 15:04")] _, existOrderTime := orderTimeMap[nextHour.Format("2006-01-02 15:04")]
orderNum, existOrderNum := orderNumMap[nextHour.Format("2006-01-02 15:04")] orderNum, existOrderNum := orderNumMap[nextHour.Format("2006-01-02 15:04")]
if (nextHour.Hour() >= workStart && nextHour.Hour() < workEnd) && (!existsDay && !existsHour) && !existOrderTime { if (!existsDay && !existsHour) && !existOrderTime {
key := nextHour.Format("2006-01-02")
key1 := nextHour.Format("2006-01-02 15:04")
if _, ok := serviceDaysMap[key1]; len(serviceDaysMap) > 0 && !ok {
//不存在服务配置中返回false
dayHoursMap[key] = append(dayHoursMap[key], TimeObject{
Time: nextHour.Format("15:04"),
Y: false,
})
nextHour = nextHour.Add(time.Duration(minute) * time.Minute)
continue
}
if _, ok := dayHoursMap[key]; ok { if _, ok := dayHoursMap[key]; ok {
dayHoursMap[key] = append(dayHoursMap[key], TimeObject{ dayHoursMap[key] = append(dayHoursMap[key], TimeObject{
Time: nextHour.Format("15:04"), Time: nextHour.Format("15:04"),
@ -98,8 +102,9 @@ func GetStrDays(day int, minute int, reserveMap map[string]models.ReserveTimeFil
} else if nextHour.Hour() >= workStart && nextHour.Hour() < workEnd { } else if nextHour.Hour() >= workStart && nextHour.Hour() < workEnd {
//查看当前时间对应的订单数量 //查看当前时间对应的订单数量
orderCount := orderTimeCount[key1] orderCount := orderTimeCount[key1]
//预约时间对应的订单数<车辆数量 当前时间可以预约 time := projectionTime[key1]
if orderCount < carNum*carServiceNum { //预约时间对应的订单数<车辆数量 当前时间可以预约 且是1笔订单
if orderCount < carNum*carServiceNum && time > 60 {
dayHoursMap[key] = append(dayHoursMap[key], TimeObject{ dayHoursMap[key] = append(dayHoursMap[key], TimeObject{
Time: nextHour.Format("15:04"), Time: nextHour.Format("15:04"),
Y: true, Y: true,