智慧食堂
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

86 Zeilen
2.4 KiB

  1. package hdl
  2. import (
  3. "applet/app/customer/lib/validate"
  4. "applet/app/customer/md"
  5. "applet/app/db"
  6. "applet/app/e"
  7. "fmt"
  8. "github.com/gin-gonic/gin"
  9. "time"
  10. )
  11. func WeekFoodMenu(c *gin.Context) {
  12. var req md.WeekFoodMenuReq
  13. err := c.ShouldBindJSON(&req)
  14. if err != nil {
  15. err = validate.HandleValidateErr(err)
  16. err1 := err.(e.E)
  17. e.OutErr(c, err1.Code, err1.Error())
  18. return
  19. }
  20. centralKitchenForSchoolMenuDb := db.CentralKitchenForSchoolMenuDb{}
  21. centralKitchenForSchoolMenuDb.Set(req.EnterpriseId)
  22. var sDate, eDate, date string
  23. now := time.Now()
  24. switch req.Kind {
  25. case "this_week":
  26. date = now.Format("2006-01-02")
  27. // 获取本周第一天(周一)
  28. sDate = now.AddDate(0, 0, -int(time.Monday-now.Weekday())).Format("2006-01-02")
  29. // 获取本周最后一天(周日)
  30. eDate = now.AddDate(0, 0, int(time.Sunday-now.Weekday())).Format("2006-01-02")
  31. break
  32. case "last_week":
  33. // 获取上周的同一时间
  34. lastWeek := now.AddDate(0, 0, -7)
  35. date = lastWeek.Format("2006-01-02")
  36. // 获取上周的周一
  37. sDate = lastWeek.AddDate(0, 0, -int(time.Monday-now.Weekday())).Format("2006-01-02")
  38. // 获取本周最后一天(周日)
  39. eDate = lastWeek.AddDate(0, 0, int(time.Sunday-now.Weekday())).Format("2006-01-02")
  40. break
  41. case "next_week":
  42. // 获取下周的同一时间
  43. nextWeek := now.AddDate(0, 0, +7)
  44. date = nextWeek.Format("2006-01-02")
  45. // 获取上周的周一
  46. sDate = nextWeek.AddDate(0, 0, -int(time.Monday-now.Weekday())).Format("2006-01-02")
  47. // 获取本周最后一天(周日)
  48. eDate = nextWeek.AddDate(0, 0, int(time.Sunday-now.Weekday())).Format("2006-01-02")
  49. break
  50. default:
  51. date = now.Format("2006-01-02")
  52. // 获取本周第一天(周一)
  53. sDate = now.AddDate(0, 0, -int(time.Monday-now.Weekday())).Format("2006-01-02")
  54. // 获取本周最后一天(周日)
  55. eDate = now.AddDate(0, 0, int(time.Sunday-now.Weekday())).Format("2006-01-02")
  56. break
  57. }
  58. fmt.Println("sDate:::::::::::::::", sDate)
  59. fmt.Println("eDate:::::::::::::::", eDate)
  60. menu, err := centralKitchenForSchoolMenuDb.GetCentralKitchenForSchoolMenu(date)
  61. if err != nil {
  62. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  63. return
  64. }
  65. e.OutSuc(c, map[string]interface{}{
  66. "info": menu,
  67. "kind_list": []map[string]interface{}{
  68. {
  69. "name": "本周",
  70. "value": "this_week",
  71. },
  72. {
  73. "name": "下周",
  74. "value": "next_week",
  75. },
  76. {
  77. "name": "上周",
  78. "value": "last_week",
  79. },
  80. },
  81. }, nil)
  82. return
  83. }