hotime/example/app/ctg_order_date.go

101 lines
2.8 KiB
Go
Raw Normal View History

package app
import (
. "../../../hotime"
. "../../../hotime/common"
"fmt"
"time"
)
var ctg_order_dateCtr = Ctr{
"info": func(that *Context) {
//today:=time.Now().Weekday()
category := that.Db.Get("category", "*", Map{"id": that.RouterString[2]})
if category == nil {
that.Display(4, "找不到该类别!")
return
}
todayPMTime, _ := time.Parse("2006-01-02 15:04", time.Now().Format("2006-01-02")+" 14:00")
todayAMTime, _ := time.Parse("2006-01-02 15:04", time.Now().Format("2006-01-02"+" 09:00"))
weekDay := 1
switch time.Now().Weekday().String() {
case "Monday":
weekDay = 1
case "Tuesday":
weekDay = 2
case "Wednesday":
weekDay = 3
case "Thursday":
weekDay = 4
case "Friday":
weekDay = 5
case "Saturday":
weekDay = 6
case "Sunday":
weekDay = 7
}
////future:=that.Db.Select("ctg_order_date","*",Map{"category_id":that.RouterString[2],"date[>]":time})
date := Slice{}
for i := 0; i < 7; i++ {
day := weekDay + i + 1
if day > 7 {
day = day - 7
}
if day == 6 || day == 7 {
continue
}
fmt.Println(todayAMTime.Unix() + int64(24*60*60*(i+1)))
dayAM := that.Db.Get("ctg_order_date", "*", Map{"AND": Map{"category_id": that.RouterString[2], "date": todayAMTime.Unix() + int64(24*60*60*(i+1))}})
if dayAM == nil {
dayAM = Map{"name": "9:00-12:00",
"date": todayAMTime.Unix() + int64(24*60*60*(i+1)),
"create_time": time.Now().Unix(),
"modify_time": time.Now().Unix(),
"start_sn": category.GetCeilInt("start_sn"),
"max_sn": category.GetCeilInt("start_sn") + category.GetCeilInt("am"+ObjToStr(day)),
"now_sn": category.GetCeilInt("start_sn"),
"category_id": category.GetCeilInt("id"),
}
dayAM["id"] = that.Db.Insert("ctg_order_date", dayAM)
if dayAM.GetCeilInt64("id") == 0 {
that.Display(4, "内部错误!")
return
}
}
dayPM := that.Db.Get("ctg_order_date", "*", Map{"AND": Map{"category_id": that.RouterString[2], "date": todayPMTime.Unix() + int64(24*60*60*(i+1))}})
if dayPM == nil {
dayPM = Map{"name": "14:00-16:00",
"date": todayPMTime.Unix() + int64(24*60*60*(i+1)),
"create_time": time.Now().Unix(),
"modify_time": time.Now().Unix(),
"start_sn": category.GetCeilInt("start_sn"),
"max_sn": category.GetCeilInt("start_sn") + category.GetCeilInt("pm"+ObjToStr(day)),
"now_sn": category.GetCeilInt("start_sn"),
"category_id": category.GetCeilInt("id"),
}
dayPM["id"] = that.Db.Insert("ctg_order_date", dayPM)
if dayPM.GetCeilInt64("id") == 0 {
that.Display(4, "内部错误!")
return
}
}
date = append(date, Map{"name": "星期" + ObjToStr(day) + "(" + time.Unix(todayPMTime.Unix()+int64(24*60*60*(i+1)), 0).Format("01-02") + ")",
"am": dayAM,
"pm": dayPM,
})
}
that.Display(0, date)
},
}