package hdl import ( "applet/app/customer/md" "applet/app/db" "applet/app/db/model" "applet/app/e" "applet/app/utils" "github.com/gin-gonic/gin" "time" ) func NursingHomePackage(c *gin.Context) { enterpriseId := utils.StrToInt(c.DefaultQuery("enterprise_id", "")) //1、查询出当前合适的package var m []model.NursingHomePackage now := time.Now().Format("2006-01-02 15:04:05") err := db.Db.Where("enterprise_id =?", enterpriseId).Where("end_date > ?", now).And("is_delete = 0").And("state = 1").Desc("end_date").Find(&m) if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } //2、循环拼接数据 var resp []md.FindNursingHomePackageReq for _, v := range m { NursingHomePackageWithDayDb := db.NursingHomePackageWithDayDb{} NursingHomePackageWithDayDb.Set(v.Id) NursingHomePackageWithDay, err1 := NursingHomePackageWithDayDb.FindNursingHomePackageWithDay() if err1 != nil { e.OutErr(c, e.ERR_DB_ORM, err1.Error()) return } var tempResp = md.FindNursingHomePackageReq{ PackageId: v.Id, EnterpriseId: v.EnterpriseId, Year: v.Year, Month: v.Month, StartDate: v.StartDate, EndDate: v.EndDate, DateList: nil, } for _, v1 := range *NursingHomePackageWithDay { tempResp.DateList = append(tempResp.DateList, struct { Date string `json:"date"` IsOpenBreakfast int32 `json:"is_open_breakfast"` IsOpenLunch int32 `json:"is_open_lunch"` IsOpenDinner int32 `json:"is_open_dinner"` IsOpenReplenish int32 `json:"is_open_replenish"` }{Date: v1.Date, IsOpenBreakfast: int32(v1.IsOpenBreakfast), IsOpenLunch: int32(v1.IsOpenLunch), IsOpenDinner: int32(v1.IsOpenDinner), IsOpenReplenish: int32(v1.IsOpenReplenish)}) } resp = append(resp, tempResp) } e.OutSuc(c, map[string]interface{}{ "list": resp, }, nil) return }