|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275 |
- 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
- }
|