diff --git a/business/api/control.go b/business/api/control.go index bd3273e..439a39c 100644 --- a/business/api/control.go +++ b/business/api/control.go @@ -62,6 +62,7 @@ func (p DefParty) RegisterList() []web_iris.Party { //系统 p.systemConfigInfo(), p.systemBanners(), + p.getPayoff(), } return ps } diff --git a/business/api/order.go b/business/api/order.go index 98607a2..49a08a4 100644 --- a/business/api/order.go +++ b/business/api/order.go @@ -95,9 +95,9 @@ func (p DefParty) orderCreatePreCheck() web_iris.Party { } } 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" { - orderCreatePreCheckResponse.PayType = 0 + orderCreatePreCheckResponse.PayType = 1 } Success(ctx, orderCreateRequest, orderCreatePreCheckResponse) @@ -478,14 +478,15 @@ func GetOrderDetail(orderId string) OrderDetail { } orderSubR1 := SubOrder{ - OrderId: orderSub.OrderId, - Status: orderSub.OrderStatus, - UserPetInfo: GetUserPet(orderMain.Uid, orderSub.PetId), - TotalAmount: orderSub.TotalAmount, - PayAmount: strconv.Itoa(orderSub.PayAmount), - Discount: float64(orderSub.Discount), - Goods: goods, - Coupons: nil, + OrderId: orderSub.OrderId, + Status: orderSub.OrderStatus, + UserPetInfo: GetUserPet(orderMain.Uid, orderSub.PetId), + TotalAmount: orderSub.TotalAmount, + PayAmount: strconv.Itoa(orderSub.PayAmount), + Discount: float64(orderSub.Discount), + Goods: goods, + Coupons: nil, + CouponsAmount: "0", } if coupons.Id > 0 { orderSubR1.Coupons = &models.Coupons{ @@ -545,7 +546,7 @@ func GetOrderDetail(orderId string) OrderDetail { } func checkOrderServiceTime(serviceTime string, projectionServiceTime int) bool { - type orderMainTmp struct { + /*type orderMainTmp struct { ServiceTime string ProjectionServiceTime int } @@ -564,7 +565,7 @@ func checkOrderServiceTime(serviceTime string, projectionServiceTime int) bool { //时间点订单数量<服务车辆*车辆单次服务数量 才可接受预约 if len(orderMainTmpList) > 0 { return len(orderMainTmpList) >= len(CarMap)*CarServiceNum - } + }*/ 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) // 执行查询 var orderMainTmp1 []struct { - ServiceTime string - Count int + ServiceTime string + Count int + ProjectionServiceTime int } err := database.Instance().Raw(` - SELECT service_time, COUNT(1) AS count + SELECT service_time, COUNT(1) AS count, projection_service_time FROM order_mains WHERE service_time >= DATE_SUB(NOW(), INTERVAL 7 DAY) AND order_status != 3 @@ -825,8 +827,10 @@ func (p DefParty) orderServiceTime() web_iris.Party { var orderTimeMap = make(map[string]string) var orderTimeNum = make(map[string]int) var orderTimeCount = make(map[string]int) + var orderProjectionTime = make(map[string]int) for _, val := range orderMainTmp1 { orderTimeCount[val.ServiceTime] = val.Count + orderProjectionTime[val.ServiceTime] = val.ProjectionServiceTime } for _, value := range orderMainTmpList { @@ -838,15 +842,18 @@ func (p DefParty) orderServiceTime() web_iris.Party { lastDate := date.Add(time.Minute * time.Duration(value.ProjectionServiceTime)) for t := date; t.Before(lastDate); t = t.Add(time.Hour) { timeStr := t.Format("2006-01-02 15:04") - orderTimeMap[timeStr] = timeStr - orderTimeNum[timeStr] = orderTimeNum[timeStr] + 1 + if timeStr != value.ServiceTime { + orderTimeMap[timeStr] = timeStr + orderTimeNum[timeStr] = orderTimeNum[timeStr] + 1 + orderTimeCount[timeStr] = orderTimeCount[timeStr] + 1 + } } } } serviceTime := AddrServiceMap[orderServiceTimeRequest.ServiceAddrId] times := strings.Split(serviceTime.Times, ",") 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) for day, values := range daysMap { key := day diff --git a/business/api/system.go b/business/api/system.go index c772b67..f569d3f 100644 --- a/business/api/system.go +++ b/business/api/system.go @@ -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"}) + }) + }} +} diff --git a/business/utils/commonUtil.go b/business/utils/commonUtil.go index b85922d..8d357e5 100644 --- a/business/utils/commonUtil.go +++ b/business/utils/commonUtil.go @@ -21,7 +21,7 @@ type TimeObject struct { 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() // 计算半小时后的时间 @@ -51,23 +51,27 @@ func GetStrDays(day int, minute int, reserveMap map[string]models.ReserveTimeFil serviceDaysMap[dayTime] = dayTime } 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")] _, existsHour := reserveMap[nextHour.Format("15")] _, existOrderTime := orderTimeMap[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 { - 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 (!existsDay && !existsHour) && !existOrderTime { if _, ok := dayHoursMap[key]; ok { dayHoursMap[key] = append(dayHoursMap[key], TimeObject{ 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 { //查看当前时间对应的订单数量 orderCount := orderTimeCount[key1] - //预约时间对应的订单数<车辆数量 当前时间可以预约 - if orderCount < carNum*carServiceNum { + time := projectionTime[key1] + //预约时间对应的订单数<车辆数量 当前时间可以预约 且是1笔订单 + if orderCount < carNum*carServiceNum && time > 60 { dayHoursMap[key] = append(dayHoursMap[key], TimeObject{ Time: nextHour.Format("15:04"), Y: true,