package hdl import ( "applet/app/customer/lib/validate" "applet/app/customer/md" "applet/app/db" "applet/app/e" "fmt" "github.com/gin-gonic/gin" "time" ) func WeekFoodMenu(c *gin.Context) { var req md.WeekFoodMenuReq err := c.ShouldBindJSON(&req) if err != nil { err = validate.HandleValidateErr(err) err1 := err.(e.E) e.OutErr(c, err1.Code, err1.Error()) return } centralKitchenForSchoolMenuDb := db.CentralKitchenForSchoolMenuDb{} centralKitchenForSchoolMenuDb.Set(req.EnterpriseId) var sDate, eDate, date string now := time.Now() switch req.Kind { case "this_week": date = now.Format("2006-01-02") // 获取本周第一天(周一) sDate = now.AddDate(0, 0, -int(time.Monday-now.Weekday())).Format("2006-01-02") // 获取本周最后一天(周日) eDate = now.AddDate(0, 0, int(time.Sunday-now.Weekday())).Format("2006-01-02") break case "last_week": // 获取上周的同一时间 lastWeek := now.AddDate(0, 0, -7) date = lastWeek.Format("2006-01-02") // 获取上周的周一 sDate = lastWeek.AddDate(0, 0, -int(time.Monday-now.Weekday())).Format("2006-01-02") // 获取本周最后一天(周日) eDate = lastWeek.AddDate(0, 0, int(time.Sunday-now.Weekday())).Format("2006-01-02") break case "next_week": // 获取下周的同一时间 nextWeek := now.AddDate(0, 0, +7) date = nextWeek.Format("2006-01-02") // 获取上周的周一 sDate = nextWeek.AddDate(0, 0, -int(time.Monday-now.Weekday())).Format("2006-01-02") // 获取本周最后一天(周日) eDate = nextWeek.AddDate(0, 0, int(time.Sunday-now.Weekday())).Format("2006-01-02") break default: date = now.Format("2006-01-02") // 获取本周第一天(周一) sDate = now.AddDate(0, 0, -int(time.Monday-now.Weekday())).Format("2006-01-02") // 获取本周最后一天(周日) eDate = now.AddDate(0, 0, int(time.Sunday-now.Weekday())).Format("2006-01-02") break } fmt.Println("sDate:::::::::::::::", sDate) fmt.Println("eDate:::::::::::::::", eDate) menu, err := centralKitchenForSchoolMenuDb.GetCentralKitchenForSchoolMenu(date) if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } e.OutSuc(c, map[string]interface{}{ "info": menu, "kind_list": []map[string]interface{}{ { "name": "本周", "value": "this_week", }, { "name": "下周", "value": "next_week", }, { "name": "上周", "value": "last_week", }, }, }, nil) return }