package hdl import ( "applet/app/admin/lib/validate" "applet/app/admin/md" "applet/app/admin/svc" svc2 "applet/app/admin/svc/enterprise_manage" "applet/app/db" "applet/app/db/model" "applet/app/e" "applet/app/enum" "applet/app/utils" "github.com/gin-gonic/gin" "time" ) func NursingHomeUserUpdate(c *gin.Context) { var req md.NursingHomeUserUpdateReq err := c.ShouldBindJSON(&req) if err != nil { err = validate.HandleValidateErr(err) err1 := err.(e.E) e.OutErr(c, err1.Code, err1.Error()) return } enterpriseDb := db.EnterpriseDb{} enterpriseDb.Set() enterprise, err := enterpriseDb.GetEnterprise(req.EnterpriseId) if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } if enterprise == nil { e.OutErr(c, e.ERR_NO_DATA, "未查询到对应记录") return } err = svc2.NursingHomeUserUpdate(req) if err != nil { e.OutErr(c, e.ERR, err.Error()) return } e.OutSuc(c, "success", nil) return } func NursingHomeUserDelete(c *gin.Context) { var req md.NursingHomeUserDeleteReq err := c.ShouldBindJSON(&req) if err != nil { err = validate.HandleValidateErr(err) err1 := err.(e.E) e.OutErr(c, err1.Code, err1.Error()) return } enterpriseDb := db.EnterpriseDb{} enterpriseDb.Set() enterprise, err := enterpriseDb.GetEnterprise(req.EnterpriseId) if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } if enterprise == nil { e.OutErr(c, e.ERR_NO_DATA, "未查询到对应记录") return } err = svc2.NursingHomeUserDelete(req) if err != nil { e.OutErr(c, e.ERR, err.Error()) return } e.OutSuc(c, "success", nil) return } func GetNursingHomeWithSpec(c *gin.Context) { enterpriseId := utils.StrToInt(c.DefaultQuery("enterprise_id", "0")) nursingHomeWithSpec := db.NursingHomeWithSpec{} nursingHomeWithSpec.Set(enterpriseId) data, err := nursingHomeWithSpec.GetNursingHomeWithSpec() if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } e.OutSuc(c, map[string]interface{}{ "data": data, }, nil) return } func SetNursingHomeWithSpec(c *gin.Context) { var req md.SetNursingHomeWithSpecReq err := c.ShouldBindJSON(&req) if err != nil { err = validate.HandleValidateErr(err) err1 := err.(e.E) e.OutErr(c, err1.Code, err1.Error()) return } nursingHomeWithSpec := db.NursingHomeWithSpec{} nursingHomeWithSpec.Set(req.EnterpriseId) spec, err := nursingHomeWithSpec.GetNursingHomeWithSpec() if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } _, err = nursingHomeWithSpec.NursingHomeWithSpecDelete() if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } now := time.Now() if spec != nil { insertConfirm, err1 := nursingHomeWithSpec.NursingHomeWithSpecInsert(&model.NursingHomeWithSpec{ IsOpenBreakfast: spec.IsOpenBreakfast, IsOpenLunch: spec.IsOpenLunch, IsOpenDinner: spec.IsOpenDinner, EnterpriseId: req.EnterpriseId, BreakfastUnitPrice: req.BreakfastUnitPrice, LunchUnitPrice: req.LunchUnitPrice, DinnerUnitPrice: req.DinnerUnitPrice, CreateAt: now.Format("2006-01-02 15:04:05"), UpdateAt: now.Format("2006-01-02 15:04:05"), }) if err1 != nil { e.OutErr(c, e.ERR_DB_ORM, err1.Error()) return } if insertConfirm <= 0 { e.OutErr(c, e.ERR_DB_ORM, "新增数据失败") return } } else { insertConfirm, err1 := nursingHomeWithSpec.NursingHomeWithSpecInsert(&model.NursingHomeWithSpec{ EnterpriseId: req.EnterpriseId, BreakfastUnitPrice: req.BreakfastUnitPrice, LunchUnitPrice: req.LunchUnitPrice, DinnerUnitPrice: req.DinnerUnitPrice, CreateAt: now.Format("2006-01-02 15:04:05"), UpdateAt: now.Format("2006-01-02 15:04:05"), }) if err1 != nil { e.OutErr(c, e.ERR_DB_ORM, err1.Error()) return } if insertConfirm <= 0 { e.OutErr(c, e.ERR_DB_ORM, "新增数据失败") return } } e.OutSuc(c, "success", nil) return } func ListNursingHomePackage(c *gin.Context) { var req md.ListNursingHomePackageReq err := c.ShouldBindJSON(&req) if err != nil { err = validate.HandleValidateErr(err) err1 := err.(e.E) e.OutErr(c, err1.Code, err1.Error()) return } nursingHomePackageDb := db.NursingHomePackageDb{} nursingHomePackageDb.Set() list, total, err := nursingHomePackageDb.NursingHomePackageList(req) if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } e.OutSuc(c, map[string]interface{}{ "list": list, "total": total, "state_list": []map[string]interface{}{ { "name": "可用", "value": 1, }, { "name": "不可用", "value": 2, }, }, }, nil) return } func DetailNursingHomePackage(c *gin.Context) { packageId := utils.StrToInt(c.DefaultQuery("package_id", "")) nursingHomePackageDb := db.NursingHomePackageDb{} nursingHomePackageDb.Set() NursingHomePackage, err := nursingHomePackageDb.GetNursingHomePackage(packageId) if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } if NursingHomePackage == nil { e.OutErr(c, e.ERR_NO_DATA, "未查询到对应记录") return } nursingHomePackageWithDayDb := db.NursingHomePackageWithDayDb{} nursingHomePackageWithDayDb.Set(packageId) nursingHomePackageWithDay, err := nursingHomePackageWithDayDb.FindNursingHomePackageWithDay() if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } var resp = md.SaveNursingHomePackageReq{ PackageId: NursingHomePackage.Id, EnterpriseId: NursingHomePackage.EnterpriseId, Year: NursingHomePackage.Year, Month: NursingHomePackage.Month, StartDate: NursingHomePackage.StartDate, EndDate: NursingHomePackage.EndDate, DateList: nil, } for _, v := range *nursingHomePackageWithDay { resp.DateList = append(resp.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: v.Date, IsOpenBreakfast: int32(v.IsOpenBreakfast), IsOpenLunch: int32(v.IsOpenLunch), IsOpenDinner: int32(v.IsOpenDinner), IsOpenReplenish: int32(v.IsOpenReplenish)}) } e.OutSuc(c, resp, nil) return } func SaveNursingHomePackage(c *gin.Context) { var req md.SaveNursingHomePackageReq err := c.ShouldBindJSON(&req) if err != nil { err = validate.HandleValidateErr(err) err1 := err.(e.E) e.OutErr(c, err1.Code, err1.Error()) return } //判断是新增 / 编辑 if req.PackageId > 0 { err = svc.UpdateNursingHomePackage(req) if err != nil { e.OutErr(c, e.ERR, err.Error()) return } } else { err = svc.AddNursingHomePackage(req) if err != nil { e.OutErr(c, e.ERR, err.Error()) return } } e.OutSuc(c, "success", nil) return } func SetBasicNursingHome(c *gin.Context) { var req md.SetBasicNursingHomeReq err := c.ShouldBindJSON(&req) if err != nil { err = validate.HandleValidateErr(err) err1 := err.(e.E) e.OutErr(c, err1.Code, err1.Error()) return } now := time.Now() //1、更新 nursing_home_set nursingHomeSetDb := db.NursingHomeSetDb{} nursingHomeSetDb.Set(req.EnterpriseId) set, err := nursingHomeSetDb.GetNursingHomeSet() if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } if set != nil { set.IsOpenReportMealForYear = req.IsOpenReportMealForYear set.IsOpenReportMealForDay = req.IsOpenReportMealForDay set.IsOpenReportMealForMonth = req.IsOpenReportMealForMonth set.UpdateAt = now.Format("2006-01-02 15:04:05") _, err2 := nursingHomeSetDb.NursingHomeSetUpdate(set.Id, set, "is_open_report_meal_for_day", "is_open_report_meal_for_month", "is_open_report_meal_for_year", "update_at") if err2 != nil { e.OutErr(c, e.ERR_DB_ORM, err2.Error()) return } } else { _, err2 := nursingHomeSetDb.NursingHomeSetInsert(&model.NursingHomeSet{ EnterpriseId: req.EnterpriseId, IsOpenReportMealForYear: req.IsOpenReportMealForYear, IsOpenReportMealForDay: req.IsOpenReportMealForDay, IsOpenReportMealForMonth: req.IsOpenReportMealForMonth, CreateAt: now.Format("2006-01-02 15:04:05"), UpdateAt: now.Format("2006-01-02 15:04:05"), }) if err2 != nil { e.OutErr(c, e.ERR_DB_ORM, err2.Error()) return } } //2、更新 nursing_home_with_spec nursingHomeWithSpec := db.NursingHomeWithSpec{} nursingHomeWithSpec.Set(req.EnterpriseId) spec, err := nursingHomeWithSpec.GetNursingHomeWithSpec() if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } if spec != nil { spec.IsOpenBreakfast = req.IsOpenBreakfast spec.IsOpenLunch = req.IsOpenLunch spec.IsOpenDinner = req.IsOpenDinner spec.UpdateAt = now.Format("2006-01-02 15:04:05") _, err2 := nursingHomeWithSpec.NursingHomeWithSpecUpdate(spec.Id, spec, "is_open_breakfast", "is_open_lunch", "is_open_dinner", "update_at") if err2 != nil { e.OutErr(c, e.ERR_DB_ORM, err2.Error()) return } } else { _, err2 := nursingHomeWithSpec.NursingHomeWithSpecInsert(&model.NursingHomeWithSpec{ EnterpriseId: req.EnterpriseId, IsOpenBreakfast: req.IsOpenBreakfast, IsOpenLunch: req.IsOpenLunch, IsOpenDinner: req.IsOpenDinner, CreateAt: now.Format("2006-01-02 15:04:05"), UpdateAt: now.Format("2006-01-02 15:04:05"), }) if err2 != nil { e.OutErr(c, e.ERR_DB_ORM, err2.Error()) return } } //3、更新 `enterprise` enterpriseDb := db.EnterpriseDb{} enterpriseDb.Set() enterprise, err := enterpriseDb.GetEnterprise(req.EnterpriseId) if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } if enterprise == nil { e.OutErr(c, e.ERR_NO_DATA, "未查询到对应记录") return } enterprise.Name = req.Name enterprise.State = req.State enterprise.UpdateAt = now.Format("2006-01-02 15:04:05") _, err = enterpriseDb.EnterpriseUpdate(enterprise, "name", "state", "update_at") if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } e.OutSuc(c, "success", nil) return } func GetBasicNursingHome(c *gin.Context) { enterpriseId := utils.StrToInt(c.DefaultQuery("enterprise_id", "0")) //1、获取 nursing_home_set nursingHomeSetDb := db.NursingHomeSetDb{} nursingHomeSetDb.Set(enterpriseId) set, err := nursingHomeSetDb.GetNursingHomeSet() if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } if set == nil { set = &model.NursingHomeSet{ EnterpriseId: enterpriseId, IsOpenReportMealForDay: 0, IsOpenReportMealForMonth: 0, IsOpenReportMealForYear: 0, CreateAt: time.Now().Format("2006-01-02 15:04:05"), UpdateAt: time.Now().Format("2006-01-02 15:04:05"), } _, err2 := nursingHomeSetDb.NursingHomeSetInsert(set) if err2 != nil { e.OutErr(c, e.ERR_DB_ORM, err2.Error()) return } } //2、获取 nursing_home_with_spec nursingHomeWithSpec := db.NursingHomeWithSpec{} nursingHomeWithSpec.Set(enterpriseId) spec, err := nursingHomeWithSpec.GetNursingHomeWithSpec() if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } if spec == nil { spec = &model.NursingHomeWithSpec{ EnterpriseId: enterpriseId, IsOpenBreakfast: 0, IsOpenLunch: 0, IsOpenDinner: 0, BreakfastUnitPrice: "0", LunchUnitPrice: "0", DinnerUnitPrice: "0", CreateAt: time.Now().Format("2006-01-02 15:04:05"), UpdateAt: time.Now().Format("2006-01-02 15:04:05"), } _, err2 := nursingHomeWithSpec.NursingHomeWithSpecInsert(spec) if err2 != nil { e.OutErr(c, e.ERR_DB_ORM, err2.Error()) return } } //3、更新 `enterprise` enterpriseDb := db.EnterpriseDb{} enterpriseDb.Set() enterprise, err := enterpriseDb.GetEnterprise(enterpriseId) if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } if enterprise == nil { e.OutErr(c, e.ERR_NO_DATA, "未查询到对应记录") return } e.OutSuc(c, map[string]interface{}{ "central_kitchen_for_school_set": set, "central_kitchen_for_school_with_spec": spec, "enterprise": enterprise, }, nil) return } func NursingHomeOrdList(c *gin.Context) { var req md.NursingHomeOrdListReq err := c.ShouldBindJSON(&req) if err != nil { err = validate.HandleValidateErr(err) err1 := err.(e.E) e.OutErr(c, err1.Code, err1.Error()) return } resp, total, err := svc2.NursingHomeOrdList(req) if err != nil { e.OutErr(c, e.ERR, err.Error()) return } e.OutSuc(c, map[string]interface{}{ "list": resp, "total": total, "kind_list": []map[string]string{ { "name": "按年购买", "value": "1", }, { "name": "按月购买", "value": "2", }, { "name": "按天购买", "value": "3", }, { "name": "补餐", "value": "4", }, }, "state_list": []map[string]interface{}{ { "name": enum.NursingHomePackageOrdState.String(enum.NursingHomePackageOrdStateForWait), "value": enum.NursingHomePackageOrdStateForWait, }, { "name": enum.NursingHomePackageOrdState.String(enum.NursingHomePackageOrdStateForSuccess), "value": enum.NursingHomePackageOrdStateForSuccess, }, { "name": enum.NursingHomePackageOrdState.String(enum.NursingHomePackageOrdStateForFail), "value": enum.NursingHomePackageOrdStateForFail, }, }, "ord_state_list": []map[string]interface{}{ { "name": enum.NursingHomePackageOrdOrdState.String(enum.NursingHomePackageOrdOrdStateForWait), "value": enum.NursingHomePackageOrdOrdStateForWait, }, { "name": enum.NursingHomePackageOrdOrdState.String(enum.NursingHomePackageOrdOrdStateForSuccess), "value": enum.NursingHomePackageOrdOrdStateForSuccess, }, { "name": enum.NursingHomePackageOrdOrdState.String(enum.NursingHomePackageOrdOrdStateForRefunding), "value": enum.NursingHomePackageOrdOrdStateForRefunding, }, { "name": enum.NursingHomePackageOrdOrdState.String(enum.NursingHomePackageOrdOrdStateForPartRefunded), "value": enum.NursingHomePackageOrdOrdStateForPartRefunded, }, { "name": enum.NursingHomePackageOrdOrdState.String(enum.NursingHomePackageOrdOrdStateForRefunded), "value": enum.NursingHomePackageOrdOrdStateForRefunded, }, { "name": enum.NursingHomePackageOrdOrdState.String(enum.NursingHomePackageOrdOrdStateForComplete), "value": enum.NursingHomePackageOrdOrdStateForComplete, }, }, "user_identity_kind_list": []map[string]interface{}{ { "name": enum.UserIdentity.String(enum.UserIdentityForCentralKitchenForStudent), "value": enum.UserIdentityForCentralKitchenForStudent, }, { "name": enum.UserIdentity.String(enum.UserIdentityForCentralKitchenForTeacher), "value": enum.UserIdentityForCentralKitchenForTeacher, }, { "name": enum.UserIdentity.String(enum.UserIdentityForCentralKitchenForWorker), "value": enum.UserIdentityForCentralKitchenForWorker, }, { "name": enum.UserIdentity.String(enum.UserIdentityForSelfSupportForStudent), "value": enum.UserIdentityForSelfSupportForStudent, }, { "name": enum.UserIdentity.String(enum.UserIdentityForSelfSupportForTeacher), "value": enum.UserIdentityForSelfSupportForTeacher, }, { "name": enum.UserIdentity.String(enum.UserIdentityForSelfSupportForWorker), "value": enum.UserIdentityForSelfSupportForWorker, }, }, }, nil) return } func NursingHomeReserveList(c *gin.Context) { var req md.NursingHomeReserveListReq err := c.ShouldBindJSON(&req) if err != nil { err = validate.HandleValidateErr(err) err1 := err.(e.E) e.OutErr(c, err1.Code, err1.Error()) return } resp, total, err := svc2.NursingHomeReserveList(req) if err != nil { e.OutErr(c, e.ERR, err.Error()) return } e.OutSuc(c, map[string]interface{}{ "list": resp, "total": total, "kind_list": []map[string]interface{}{ { "name": enum.NursingHomeUserWithDayKind.String(enum.NursingHomeUserWithDayKindForBreakfast), "value": enum.NursingHomeUserWithDayKindForBreakfast, }, { "name": enum.NursingHomeUserWithDayKind.String(enum.NursingHomeUserWithDayKindForLunch), "value": enum.NursingHomeUserWithDayKindForLunch, }, { "name": enum.NursingHomeUserWithDayKind.String(enum.NursingHomeUserWithDayKindForDinner), "value": enum.NursingHomeUserWithDayKindForDinner, }, }, }, nil) return } func NursingHomeReserveDetail(c *gin.Context) { id := c.DefaultQuery("id", "") NursingHomePackageOrdForReserveDb := db.NursingHomePackageOrdForReserve{} NursingHomePackageOrdForReserveDb.Set("") NursingHomePackageOrdForReserve, err := NursingHomePackageOrdForReserveDb.GetNursingHomePackageOrdForReserveById(utils.StrToInt(id)) if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } if NursingHomePackageOrdForReserve == nil { e.OutErr(c, e.ERR_NO_DATA, "未查询到相应记录") return } var m []model.NursingHomeUserWithDay err = db.Db.Where("ord_no =?", NursingHomePackageOrdForReserve.OutTradeNo). And("date >=? and date <=?", NursingHomePackageOrdForReserve.MealTimeStart, NursingHomePackageOrdForReserve.MealTimeEnd). Find(&m) if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } e.OutSuc(c, map[string]interface{}{ "list": m, "kind_list": []map[string]interface{}{ { "name": enum.NursingHomeUserWithDayKind.String(enum.NursingHomeUserWithDayKindForBreakfast), "value": enum.NursingHomeUserWithDayKindForBreakfast, }, { "name": enum.NursingHomeUserWithDayKind.String(enum.NursingHomeUserWithDayKindForLunch), "value": enum.NursingHomeUserWithDayKindForLunch, }, { "name": enum.NursingHomeUserWithDayKind.String(enum.NursingHomeUserWithDayKindForDinner), "value": enum.NursingHomeUserWithDayKindForDinner, }, }, "state_list": []map[string]interface{}{ { "name": enum.NursingHomeUserWithDayState.String(enum.NursingHomeUserWithDayStateForWait), "value": enum.NursingHomeUserWithDayStateForWait, }, { "name": enum.NursingHomeUserWithDayState.String(enum.NursingHomeUserWithDayStateForAlready), "value": enum.NursingHomeUserWithDayStateForAlready, }, { "name": enum.NursingHomeUserWithDayState.String(enum.NursingHomeUserWithDayStateForCanceling), "value": enum.NursingHomeUserWithDayStateForCanceling, }, { "name": enum.NursingHomeUserWithDayState.String(enum.NursingHomeUserWithDayStateForCancel), "value": enum.NursingHomeUserWithDayStateForCancel, }, }, }, nil) return } func NursingHomeOrdRefund(c *gin.Context) { var req md.NursingHomeOrdRefundReq err := c.ShouldBindJSON(&req) if err != nil { err = validate.HandleValidateErr(err) err1 := err.(e.E) e.OutErr(c, err1.Code, err1.Error()) return } enterpriseDb := db.EnterpriseDb{} enterpriseDb.Set() enterprise, err := enterpriseDb.GetEnterprise(req.EnterpriseId) if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } if enterprise == nil { e.OutErr(c, e.ERR_NO_DATA, "未查询到对应记录") return } err = svc2.NursingHomeOrdRefund(req) if err != nil { e.OutErr(c, e.ERR, err.Error()) return } e.OutSuc(c, "success", nil) return } func NursingHomeOrdDetail(c *gin.Context) { outTradeNo := c.DefaultQuery("out_trade_no", "") nursingHomePackageOrd := db.NursingHomePackageOrd{} nursingHomePackageOrd.Set(outTradeNo) ord, err := nursingHomePackageOrd.GetNursingHomePackageOrd() if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } if ord == nil { e.OutErr(c, e.ERR_NO_DATA, "未查询到对应订单记录") return } nursingHomeUserWithDayDb := db.NursingHomeUserWithDayDb{} nursingHomeUserWithDayDb.Set(0) list, err := nursingHomeUserWithDayDb.FindNursingHomeUserWithDayByOrdNo(ord.OutTradeNo) if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } e.OutSuc(c, map[string]interface{}{ "list": list, "kind_list": []map[string]interface{}{ { "name": enum.NursingHomeUserWithDayKind.String(enum.NursingHomeUserWithDayKindForBreakfast), "value": enum.NursingHomeUserWithDayKindForBreakfast, }, { "name": enum.NursingHomeUserWithDayKind.String(enum.NursingHomeUserWithDayKindForLunch), "value": enum.NursingHomeUserWithDayKindForLunch, }, { "name": enum.NursingHomeUserWithDayKind.String(enum.NursingHomeUserWithDayKindForDinner), "value": enum.NursingHomeUserWithDayKindForDinner, }, }, "state_list": []map[string]interface{}{ { "name": enum.NursingHomeUserWithDayState.String(enum.NursingHomeUserWithDayStateForWait), "value": enum.NursingHomeUserWithDayStateForWait, }, { "name": enum.NursingHomeUserWithDayState.String(enum.NursingHomeUserWithDayStateForAlready), "value": enum.NursingHomeUserWithDayStateForAlready, }, { "name": enum.NursingHomeUserWithDayState.String(enum.NursingHomeUserWithDayStateForCanceling), "value": enum.NursingHomeUserWithDayStateForCanceling, }, { "name": enum.NursingHomeUserWithDayState.String(enum.NursingHomeUserWithDayStateForCancel), "value": enum.NursingHomeUserWithDayStateForCancel, }, }, }, nil) return } func DeleteNursingHomePackage(c *gin.Context) { packageId := c.Param("id") err := svc.DeleteNursingHomePackage(utils.StrToInt(packageId)) if err != nil { e.OutErr(c, e.ERR, err.Error()) return } e.OutSuc(c, "success", nil) return }