package svc import ( "applet/app/admin/md" md2 "applet/app/customer/md" "applet/app/db" "applet/app/db/model" "applet/app/enum" "applet/app/utils" "time" ) func CalcByYearForNursingHome(uid int, buyPackageReq md2.NursingHomeBuyPackageReq) (totalPrice float64, data []*model.NursingHomeUserWithDay, err error) { sysCfgDb := db.SysCfgDb{} sysCfgDb.Set() cfg, err := sysCfgDb.SysCfgGetOne(enum.NursingHomeReserveMealTime) if err != nil { return } //1、查询出套餐基础设置 NursingHomeWithSpec := db.NursingHomeWithSpec{} NursingHomeWithSpec.Set(buyPackageReq.EnterpriseId) NursingHomeWithSpecData, err := NursingHomeWithSpec.GetNursingHomeWithSpec() if err != nil { return } //2、查询出当前合适的package var m []model.NursingHomePackage now := time.Now() today, _ := time.ParseInLocation("2006-01-02", time.Now().Format("2006-01-02"), time.Local) err = db.Db.Where("enterprise_id =?", buyPackageReq.EnterpriseId).In("id", buyPackageReq.PackageIds).And("is_delete = 0").And("state = 1").Desc("end_date").Find(&m) if err != nil { return } NursingHomeReserveMealTime, _ := time.ParseInLocation("2006-01-02 15:04:05", now.Format("2006-01-02")+" "+cfg.Val+":00", time.Local) //3、循环拼接数据 for _, v := range m { NursingHomePackageWithDayDb := db.NursingHomePackageWithDayDb{} NursingHomePackageWithDayDb.Set(v.Id) NursingHomePackageWithDay, err1 := NursingHomePackageWithDayDb.FindNursingHomePackageWithDay() if err1 != nil { return } for _, v1 := range *NursingHomePackageWithDay { //3.1、判断是否小于今天 date, _ := time.ParseInLocation("2006-01-02", v1.Date, time.Local) if today.After(date) { continue } if today.Equal(date) { //2.2、判断是否过了今日可订餐时间 if now.After(NursingHomeReserveMealTime) { continue } } //3.3、计算价格 && 组装数据 if v1.IsOpenBreakfast == md.OpenBreakfast && buyPackageReq.IsBuyBreakfast == 1 { //早餐 var amount = NursingHomeWithSpecData.BreakfastUnitPrice totalPrice += utils.StrToFloat64(amount) data = append(data, &model.NursingHomeUserWithDay{ Uid: uid, IdentityId: buyPackageReq.UserIdentityId, Amount: amount, Kind: enum.NursingHomeUserWithDayKindForBreakfast, Date: v1.Date, State: enum.NursingHomeUserWithDayStateForWait, }) } if v1.IsOpenLunch == md.OpenLunch && buyPackageReq.IsBuyLunch == 1 { var amount = NursingHomeWithSpecData.LunchUnitPrice totalPrice += utils.StrToFloat64(amount) data = append(data, &model.NursingHomeUserWithDay{ Uid: uid, IdentityId: buyPackageReq.UserIdentityId, Amount: amount, Kind: enum.NursingHomeUserWithDayKindForLunch, Date: v1.Date, State: enum.NursingHomeUserWithDayStateForWait, }) } if v1.IsOpenDinner == md.OpenDinner && buyPackageReq.IsBuyDinner == 1 { var amount = NursingHomeWithSpecData.DinnerUnitPrice totalPrice += utils.StrToFloat64(amount) data = append(data, &model.NursingHomeUserWithDay{ Uid: uid, IdentityId: buyPackageReq.UserIdentityId, Kind: enum.NursingHomeUserWithDayKindForDinner, Date: v1.Date, Amount: amount, State: enum.NursingHomeUserWithDayStateForWait, }) } } } return } func CalcByMonthForNursingHome(uid int, buyPackageReq md2.NursingHomeBuyPackageReq) (totalPrice float64, data []*model.NursingHomeUserWithDay, err error) { sysCfgDb := db.SysCfgDb{} sysCfgDb.Set() cfg, err := sysCfgDb.SysCfgGetOne(enum.NursingHomeReserveMealTime) if err != nil { return } //1、查询出套餐基础设置 NursingHomeWithSpec := db.NursingHomeWithSpec{} NursingHomeWithSpec.Set(buyPackageReq.EnterpriseId) NursingHomeWithSpecData, err := NursingHomeWithSpec.GetNursingHomeWithSpec() if err != nil { return } //2、查询出当前合适的package var m []model.NursingHomePackage now := time.Now() today, _ := time.ParseInLocation("2006-01-02", time.Now().Format("2006-01-02"), time.Local) err = db.Db.Where("enterprise_id =?", buyPackageReq.EnterpriseId).And("id =?", buyPackageReq.PackageId).And("is_delete = 0").And("state = 1").Find(&m) if err != nil { return } NursingHomeReserveMealTime, _ := time.ParseInLocation("2006-01-02 15:04:05", now.Format("2006-01-02")+" "+cfg.Val+":00", time.Local) //3、循环拼接数据 for _, v := range m { NursingHomePackageWithDayDb := db.NursingHomePackageWithDayDb{} NursingHomePackageWithDayDb.Set(v.Id) NursingHomePackageWithDay, err1 := NursingHomePackageWithDayDb.FindNursingHomePackageWithDay() if err1 != nil { return } for _, v1 := range *NursingHomePackageWithDay { //3.1、判断是否小于今天 date, _ := time.ParseInLocation("2006-01-02", v1.Date, time.Local) if today.After(date) { continue } if today.Equal(date) { //2.2、判断是否过了今日可订餐时间 if now.After(NursingHomeReserveMealTime) { continue } } //3.3、计算价格 && 组装数据 if v1.IsOpenBreakfast == md.OpenBreakfast && buyPackageReq.IsBuyBreakfast == 1 { //早餐 var amount = NursingHomeWithSpecData.BreakfastUnitPrice totalPrice += utils.StrToFloat64(amount) data = append(data, &model.NursingHomeUserWithDay{ Uid: uid, IdentityId: buyPackageReq.UserIdentityId, Amount: amount, Kind: enum.NursingHomeUserWithDayKindForBreakfast, Date: v1.Date, State: enum.NursingHomeUserWithDayStateForWait, }) } if v1.IsOpenLunch == md.OpenLunch && buyPackageReq.IsBuyLunch == 1 { var amount = NursingHomeWithSpecData.LunchUnitPrice totalPrice += utils.StrToFloat64(amount) data = append(data, &model.NursingHomeUserWithDay{ Uid: uid, IdentityId: buyPackageReq.UserIdentityId, Amount: amount, Kind: enum.NursingHomeUserWithDayKindForLunch, Date: v1.Date, State: enum.NursingHomeUserWithDayStateForWait, }) } if v1.IsOpenDinner == md.OpenDinner && buyPackageReq.IsBuyDinner == 1 { var amount = NursingHomeWithSpecData.DinnerUnitPrice totalPrice += utils.StrToFloat64(amount) data = append(data, &model.NursingHomeUserWithDay{ Uid: uid, IdentityId: buyPackageReq.UserIdentityId, Kind: enum.NursingHomeUserWithDayKindForDinner, Amount: amount, Date: v1.Date, State: enum.NursingHomeUserWithDayStateForWait, }) } } } return } func CalcByDayForNursingHome(uid int, buyPackageReq md2.NursingHomeBuyPackageReq) (totalPrice float64, data []*model.NursingHomeUserWithDay, err error) { sysCfgDb := db.SysCfgDb{} sysCfgDb.Set() cfg, err := sysCfgDb.SysCfgGetOne(enum.NursingHomeReserveMealTime) if err != nil { return } //1、查询出套餐基础设置 NursingHomeWithSpec := db.NursingHomeWithSpec{} NursingHomeWithSpec.Set(buyPackageReq.EnterpriseId) NursingHomeWithSpecData, err := NursingHomeWithSpec.GetNursingHomeWithSpec() if err != nil { return } now := time.Now() today, _ := time.ParseInLocation("2006-01-02", time.Now().Format("2006-01-02"), time.Local) NursingHomeReserveMealTime, _ := time.ParseInLocation("2006-01-02 15:04:05", now.Format("2006-01-02")+" "+cfg.Val+":00", time.Local) //2、循环拼接数据 for _, v1 := range buyPackageReq.WithDays { //2.1、判断是否小于今天 date, _ := time.ParseInLocation("2006-01-02", v1.Date, time.Local) if today.After(date) { continue } if today.Equal(date) { //2.2、判断是否过了今日可订餐时间 if now.After(NursingHomeReserveMealTime) { continue } } //2.3、计算价格 && 组装数据 if v1.IsBuyBreakfast == 1 && buyPackageReq.IsBuyBreakfast == 1 { //早餐 var amount = NursingHomeWithSpecData.BreakfastUnitPrice totalPrice += utils.StrToFloat64(amount) data = append(data, &model.NursingHomeUserWithDay{ Uid: uid, IdentityId: buyPackageReq.UserIdentityId, Kind: enum.NursingHomeUserWithDayKindForBreakfast, Date: v1.Date, Amount: amount, State: enum.NursingHomeUserWithDayStateForWait, }) } if v1.IsBuyLunch == 1 && buyPackageReq.IsBuyLunch == 1 { var amount = NursingHomeWithSpecData.LunchUnitPrice totalPrice += utils.StrToFloat64(amount) data = append(data, &model.NursingHomeUserWithDay{ Uid: uid, IdentityId: buyPackageReq.UserIdentityId, Kind: enum.NursingHomeUserWithDayKindForLunch, Date: v1.Date, State: enum.NursingHomeUserWithDayStateForWait, Amount: amount, }) } if v1.IsBuyDinner == 1 && buyPackageReq.IsBuyDinner == 1 { var amount = NursingHomeWithSpecData.DinnerUnitPrice totalPrice += utils.StrToFloat64(amount) data = append(data, &model.NursingHomeUserWithDay{ Uid: uid, IdentityId: buyPackageReq.UserIdentityId, Kind: enum.NursingHomeUserWithDayKindForDinner, Amount: amount, Date: v1.Date, State: enum.NursingHomeUserWithDayStateForWait, }) } } return }