diff --git a/app/admin/hdl/enterprise_manage/hdl_central_kitchen_for_school.go b/app/admin/hdl/enterprise_manage/hdl_central_kitchen_for_school.go index 928a365..fe05486 100644 --- a/app/admin/hdl/enterprise_manage/hdl_central_kitchen_for_school.go +++ b/app/admin/hdl/enterprise_manage/hdl_central_kitchen_for_school.go @@ -912,30 +912,58 @@ func CentralKitchenForSchoolOrdRefund(c *gin.Context) { } func CentralKitchenForSchoolBatchAskForLeave(c *gin.Context) { - var req md.CentralKitchenForSchoolBatchAskForLeaveReq - 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.CentralKitchenForSchoolBatchAskForLeave(req) - if err != nil { - e.OutErr(c, e.ERR, err.Error()) - return + Kind := c.DefaultQuery("kind", "1") + switch Kind { + case "1": + var req md.CentralKitchenForSchoolBatchAskForLeaveReqBySchool + err := c.ShouldBindJSON(&req) + if err != nil { + err = validate.HandleValidateErr(err) + err1 := err.(e.E) + e.OutErr(c, err1.Code, err1.Error()) + return + } + err = svc2.CentralKitchenForSchoolBatchAskForLeaveBySchool(req) + if err != nil { + e.OutErr(c, e.ERR, err.Error()) + return + } + //按学校 + break + case "2": + //按年级 + var req md.CentralKitchenForSchoolBatchAskForLeaveReqByGrade + err := c.ShouldBindJSON(&req) + if err != nil { + err = validate.HandleValidateErr(err) + err1 := err.(e.E) + e.OutErr(c, err1.Code, err1.Error()) + return + } + err = svc2.CentralKitchenForSchoolBatchAskForLeaveByGrade(req) + if err != nil { + e.OutErr(c, e.ERR, err.Error()) + return + } + break + case "3": + //按班级 + var req md.CentralKitchenForSchoolBatchAskForLeaveReqByClass + err := c.ShouldBindJSON(&req) + if err != nil { + err = validate.HandleValidateErr(err) + err1 := err.(e.E) + e.OutErr(c, err1.Code, err1.Error()) + return + } + err = svc2.CentralKitchenForSchoolBatchAskForLeaveByClass(req) + if err != nil { + e.OutErr(c, e.ERR, err.Error()) + return + } + break } + e.OutSuc(c, "success", nil) return } diff --git a/app/admin/md/md_enterprise_manage.go b/app/admin/md/md_enterprise_manage.go index c75b9a6..0409e8c 100644 --- a/app/admin/md/md_enterprise_manage.go +++ b/app/admin/md/md_enterprise_manage.go @@ -494,14 +494,34 @@ type SelfSupportForSchoolOrdListResp struct { CpMerchantId string `json:"cp_merchant_id" label:"商户编码"` } -type CentralKitchenForSchoolBatchAskForLeaveReq struct { - EnterpriseId int `json:"enterprise_id" binding:"required" label:"企业id"` - GradeId int `json:"grade_id" binding:"required" label:"年级id"` - ClassId int `json:"class_id" label:"班级id"` - IsBreakfast int `json:"is_breakfast" label:"是否退早餐(1:退 0:不退)"` - IsLunch int `json:"is_lunch" label:"是否退午餐(1:退 0:不退)"` - IsDinner int `json:"is_dinner" label:"是否退晚餐(1:退 0:不退)"` - Date string `json:"date"` +type CentralKitchenForSchoolBatchAskForLeaveReqBySchool struct { + EnterpriseIds []int `json:"enterprise_id" binding:"required" label:"企业id"` + GradeId int `json:"grade_id" binding:"required" label:"年级id"` + ClassId int `json:"class_id" label:"班级id"` + IsBreakfast int `json:"is_breakfast" label:"是否退早餐(1:退 0:不退)"` + IsLunch int `json:"is_lunch" label:"是否退午餐(1:退 0:不退)"` + IsDinner int `json:"is_dinner" label:"是否退晚餐(1:退 0:不退)"` + Dates []string `json:"dates"` +} + +type CentralKitchenForSchoolBatchAskForLeaveReqByGrade struct { + EnterpriseId int `json:"enterprise_id" binding:"required" label:"企业id"` + GradeIds []int `json:"grade_ids" binding:"required" label:"年级id"` + ClassId int `json:"class_id" label:"班级id"` + IsBreakfast int `json:"is_breakfast" label:"是否退早餐(1:退 0:不退)"` + IsLunch int `json:"is_lunch" label:"是否退午餐(1:退 0:不退)"` + IsDinner int `json:"is_dinner" label:"是否退晚餐(1:退 0:不退)"` + Dates []string `json:"dates"` +} + +type CentralKitchenForSchoolBatchAskForLeaveReqByClass struct { + EnterpriseId int `json:"enterprise_id" binding:"required" label:"企业id"` + GradeId int `json:"grade_id" binding:"required" label:"年级id"` + ClassIds []int `json:"class_ids" label:"班级id"` + IsBreakfast int `json:"is_breakfast" label:"是否退早餐(1:退 0:不退)"` + IsLunch int `json:"is_lunch" label:"是否退午餐(1:退 0:不退)"` + IsDinner int `json:"is_dinner" label:"是否退晚餐(1:退 0:不退)"` + Dates []string `json:"dates"` } type ListNursingHomePackageReq struct { diff --git a/app/admin/svc/enterprise_manage/svc_central_kitchen_for_school.go b/app/admin/svc/enterprise_manage/svc_central_kitchen_for_school.go index 6e59e57..64f1387 100644 --- a/app/admin/svc/enterprise_manage/svc_central_kitchen_for_school.go +++ b/app/admin/svc/enterprise_manage/svc_central_kitchen_for_school.go @@ -808,210 +808,628 @@ func CentralKitchenForSchoolOrdRefund(req md.CentralKitchenForSchoolOrdRefundReq return } -func CentralKitchenForSchoolBatchAskForLeave(req md.CentralKitchenForSchoolBatchAskForLeaveReq) (err error) { - classWithUserDb := db.ClassWithUserDb{} - classWithUserDb.Set() - - //1、判断 "按年级" / "按班级" - var classWithUser *[]model.ClassWithUser - if req.ClassId != 0 { - classWithUser, err = classWithUserDb.FindUserIdentity(req.ClassId) - if err != nil { - return err - } - } else { - classDb := db.ClassDb{} - classDb.Set(req.GradeId) - classes, err1 := classDb.FindClass() +func CentralKitchenForSchoolBatchAskForLeaveBySchool(req md.CentralKitchenForSchoolBatchAskForLeaveReqBySchool) (err error) { + enterpriseDb := db.EnterpriseDb{} + enterpriseDb.Set() + for _, v := range req.EnterpriseIds { + //1、查询学校 + enterprise, err1 := enterpriseDb.GetEnterprise(v) if err1 != nil { - return err1 - } - var classIds []int - for _, v := range *classes { - classIds = append(classIds, v.Id) - } - classWithUser, err = classWithUserDb.FindUserIdentity(classIds) - if err != nil { - return err + return } - } - var identityIds []string - for _, v := range *classWithUser { - identityIds = append(identityIds, utils.IntToStr(v.UserIdentityId)) - } - - if len(identityIds) <= 0 { - return errors.New("【" + req.Date + "】,无需请假学生") - } - - //2、查询出所有 `central_kitchen_for_school_user_with_day` 记录 - var m []model.CentralKitchenForSchoolUserWithDay - centralKitchenForSchoolUserWithDayDb := db.CentralKitchenForSchoolUserWithDayDb{} - centralKitchenForSchoolUserWithDayDb.Set(0) - if req.IsBreakfast == 1 { - err = centralKitchenForSchoolUserWithDayDb.Db.In("identity_id", identityIds).And("date =?", req.Date). - And("kind =?", enum2.CentralKitchenForSchoolUserWithDayKindForBreakfast).Find(&m) - if err != nil { - return err + if enterprise == nil { + return errors.New("未查询到id:【" + utils.IntToStr(v) + "】公司对应记录") } - if len(m) > 0 { - //2、更改 `central_kitchen_for_school_user_with_day` 的 state 为 退款中 - sql := "update central_kitchen_for_school_user_with_day set state = %d where identity_id In (%s) and date = '%s' and kind = %d" - idsStr := strings.Join(identityIds, ",") - sql = fmt.Sprintf(sql, enum2.CentralKitchenForSchoolUserWithDayStateForCanceling, idsStr, req.Date, enum2.CentralKitchenForSchoolUserWithDayKindForBreakfast) - fmt.Println(sql) - _, err = db.ExecuteOriginalSql(db.Db, sql) - if err != nil { - return err + for _, date := range req.Dates { + //2、查询出所有 `central_kitchen_for_school_user_with_day` 记录 + var mm []model.CentralKitchenForSchoolUserWithDay + centralKitchenForSchoolUserWithDayDb := db.CentralKitchenForSchoolUserWithDayDb{} + centralKitchenForSchoolUserWithDayDb.Set(0) + if req.IsBreakfast == 1 { + err = centralKitchenForSchoolUserWithDayDb.Db.Where("enterprise_id =?", v).And("date =?", date). + And("kind =?", enum2.CentralKitchenForSchoolUserWithDayKindForBreakfast).Find(&mm) + if err != nil { + return err + } + if len(mm) > 0 { + var identityIds []string + for _, m := range mm { + identityIds = append(identityIds, utils.IntToStr(m.Id)) + } + if len(identityIds) <= 0 { + //无请假学生 + continue + } + //2、更改 `central_kitchen_for_school_user_with_day` 的 state 为 退款中 + sql := "update central_kitchen_for_school_user_with_day set state = %d where identity_id In (%s) and date = '%s' and kind = %d" + idsStr := strings.Join(identityIds, ",") + sql = fmt.Sprintf(sql, enum2.CentralKitchenForSchoolUserWithDayStateForCanceling, idsStr, date, enum2.CentralKitchenForSchoolUserWithDayKindForBreakfast) + fmt.Println(sql) + _, err = db.ExecuteOriginalSql(db.Db, sql) + if err != nil { + return err + } + + //3、循环处理数据 + var dealOutTradeNo = map[string]string{} + var centralKitchenForSchoolUserRefundDays []*model.CentralKitchenForSchoolUserRefundDay + now := time.Now() + for _, m := range mm { + dealOutTradeNo[m.OrdNo] = m.OrdNo + outRequestNo := utils.OrderUUID(m.Uid) + centralKitchenForSchoolUserRefundDays = append(centralKitchenForSchoolUserRefundDays, &model.CentralKitchenForSchoolUserRefundDay{ + OutTradeNo: m.OrdNo, + OutRequestNo: outRequestNo, + Uid: m.Uid, + IdentityId: m.IdentityId, + RecordsId: m.Id, + State: enum2.CentralKitchenForSchoolUserRefundDayStateForAuditing, + Amount: m.Amount, + Memo: "", + CreateAt: now.Format("2006-01-02 15:04:05"), + UpdateAt: now.Format("2006-01-02 15:04:05"), + }) + } + + //4、处理 `central_kitchen_for_school_package_ord` 的 订单状态 (ord_state) + for _, vv := range dealOutTradeNo { + err2 := JudgePackageOrdOrdState(vv) + if err2 != nil { + return err2 + } + } + + //5、新增 `central_kitchen_for_school_user_refund_day` 数据 + centralKitchenForSchoolUserRefundDayDb := db.CentralKitchenForSchoolUserRefundDayDb{} + centralKitchenForSchoolUserRefundDayDb.Set(0) + _, err = centralKitchenForSchoolUserRefundDayDb.BatchAddCentralKitchenForSchoolUserRefundDays(centralKitchenForSchoolUserRefundDays) + if err != nil { + return err + } + } } - //3、循环处理数据 - var dealOutTradeNo = map[string]string{} - var centralKitchenForSchoolUserRefundDays []*model.CentralKitchenForSchoolUserRefundDay - now := time.Now() - for _, v := range m { - dealOutTradeNo[v.OrdNo] = v.OrdNo - outRequestNo := utils.OrderUUID(v.Uid) - centralKitchenForSchoolUserRefundDays = append(centralKitchenForSchoolUserRefundDays, &model.CentralKitchenForSchoolUserRefundDay{ - OutTradeNo: v.OrdNo, - OutRequestNo: outRequestNo, - Uid: v.Uid, - IdentityId: v.IdentityId, - RecordsId: v.Id, - State: enum2.CentralKitchenForSchoolUserRefundDayStateForAuditing, - Amount: v.Amount, - Memo: "", - CreateAt: now.Format("2006-01-02 15:04:05"), - UpdateAt: now.Format("2006-01-02 15:04:05"), - }) - } + if req.IsLunch == 1 { + err = centralKitchenForSchoolUserWithDayDb.Db.Where("enterprise_id =?", v).And("date =?", date). + And("kind =?", enum2.CentralKitchenForSchoolUserWithDayKindForLunch).Find(&mm) + if err != nil { + return err + } - //4、处理 `central_kitchen_for_school_package_ord` 的 订单状态(ord_state) - for _, v := range dealOutTradeNo { - err1 := JudgePackageOrdOrdState(v) - if err1 != nil { - return err1 + if len(mm) > 0 { + var identityIds []string + for _, m := range mm { + identityIds = append(identityIds, utils.IntToStr(m.Id)) + } + //2、更改 `central_kitchen_for_school_user_with_day` 的 state 为 退款中 + sql := "update central_kitchen_for_school_user_with_day set state = %d where identity_id In (%s) and date = '%s' and kind = %d" + idsStr := strings.Join(identityIds, ",") + sql = fmt.Sprintf(sql, enum2.CentralKitchenForSchoolUserWithDayStateForCanceling, idsStr, date, enum2.CentralKitchenForSchoolUserWithDayKindForLunch) + fmt.Println(sql) + _, err = db.ExecuteOriginalSql(db.Db, sql) + if err != nil { + return err + } + + //3、循环处理数据 + var dealOutTradeNo = map[string]string{} + var centralKitchenForSchoolUserRefundDays []*model.CentralKitchenForSchoolUserRefundDay + now := time.Now() + for _, m := range mm { + dealOutTradeNo[m.OrdNo] = m.OrdNo + outRequestNo := utils.OrderUUID(m.Uid) + centralKitchenForSchoolUserRefundDays = append(centralKitchenForSchoolUserRefundDays, &model.CentralKitchenForSchoolUserRefundDay{ + OutTradeNo: m.OrdNo, + OutRequestNo: outRequestNo, + Uid: m.Uid, + IdentityId: m.IdentityId, + RecordsId: m.Id, + State: enum2.CentralKitchenForSchoolUserRefundDayStateForAuditing, + Amount: m.Amount, + Memo: "", + CreateAt: now.Format("2006-01-02 15:04:05"), + UpdateAt: now.Format("2006-01-02 15:04:05"), + }) + } + + //4、处理 `central_kitchen_for_school_package_ord` 的 订单状态 (ord_state) + for _, vv := range dealOutTradeNo { + err1 := JudgePackageOrdOrdState(vv) + if err1 != nil { + return err1 + } + } + + //5、新增 `central_kitchen_for_school_user_refund_day` 数据 + centralKitchenForSchoolUserRefundDayDb := db.CentralKitchenForSchoolUserRefundDayDb{} + centralKitchenForSchoolUserRefundDayDb.Set(0) + _, err = centralKitchenForSchoolUserRefundDayDb.BatchAddCentralKitchenForSchoolUserRefundDays(centralKitchenForSchoolUserRefundDays) + if err != nil { + return err + } } } - //5、新增 `central_kitchen_for_school_user_refund_day` 数据 - centralKitchenForSchoolUserRefundDayDb := db.CentralKitchenForSchoolUserRefundDayDb{} - centralKitchenForSchoolUserRefundDayDb.Set(0) - _, err = centralKitchenForSchoolUserRefundDayDb.BatchAddCentralKitchenForSchoolUserRefundDays(centralKitchenForSchoolUserRefundDays) - if err != nil { - return err + if req.IsDinner == 1 { + err = centralKitchenForSchoolUserWithDayDb.Db.Where("enterprise_id =?", v).And("date =?", date). + And("kind =?", enum2.CentralKitchenForSchoolUserWithDayKindForDinner).Find(&mm) + if err != nil { + return err + } + + if len(mm) > 0 { + var identityIds []string + for _, m := range mm { + identityIds = append(identityIds, utils.IntToStr(m.Id)) + } + //2、更改 `central_kitchen_for_school_user_with_day` 的 state 为 退款中 + sql := "update central_kitchen_for_school_user_with_day set state = %d where identity_id In (%s) and date = '%s' and kind = %d" + idsStr := strings.Join(identityIds, ",") + sql = fmt.Sprintf(sql, enum2.CentralKitchenForSchoolUserWithDayStateForCanceling, idsStr, date, enum2.CentralKitchenForSchoolUserWithDayKindForDinner) + fmt.Println(sql) + _, err = db.ExecuteOriginalSql(db.Db, sql) + if err != nil { + return err + } + + //3、循环处理数据 + var dealOutTradeNo = map[string]string{} + var centralKitchenForSchoolUserRefundDays []*model.CentralKitchenForSchoolUserRefundDay + now := time.Now() + for _, m := range mm { + dealOutTradeNo[m.OrdNo] = m.OrdNo + outRequestNo := utils.OrderUUID(m.Uid) + centralKitchenForSchoolUserRefundDays = append(centralKitchenForSchoolUserRefundDays, &model.CentralKitchenForSchoolUserRefundDay{ + OutTradeNo: m.OrdNo, + OutRequestNo: outRequestNo, + Uid: m.Uid, + IdentityId: m.IdentityId, + RecordsId: m.Id, + State: enum2.CentralKitchenForSchoolUserRefundDayStateForAuditing, + Amount: m.Amount, + Memo: "", + CreateAt: now.Format("2006-01-02 15:04:05"), + UpdateAt: now.Format("2006-01-02 15:04:05"), + }) + } + + //4、处理 `central_kitchen_for_school_package_ord` 的 订单状态 (ord_state) + for _, vv := range dealOutTradeNo { + err1 := JudgePackageOrdOrdState(vv) + if err1 != nil { + return err1 + } + } + + //5、新增 `central_kitchen_for_school_user_refund_day` 数据 + centralKitchenForSchoolUserRefundDayDb := db.CentralKitchenForSchoolUserRefundDayDb{} + centralKitchenForSchoolUserRefundDayDb.Set(0) + _, err = centralKitchenForSchoolUserRefundDayDb.BatchAddCentralKitchenForSchoolUserRefundDays(centralKitchenForSchoolUserRefundDays) + if err != nil { + return err + } + } } } } - if req.IsLunch == 1 { - err = centralKitchenForSchoolUserWithDayDb.Db.In("identity_id", identityIds).And("date =?", req.Date). - And("kind =?", enum2.CentralKitchenForSchoolUserWithDayKindForLunch).Find(&m) + return +} + +func CentralKitchenForSchoolBatchAskForLeaveByGrade(req md.CentralKitchenForSchoolBatchAskForLeaveReqByGrade) (err error) { + enterpriseDb := db.EnterpriseDb{} + enterpriseDb.Set() + classWithUserDb := db.ClassWithUserDb{} + classWithUserDb.Set() + //1、查询学校 + enterprise, err1 := enterpriseDb.GetEnterprise(req.EnterpriseId) + if err1 != nil { + return + } + if enterprise == nil { + return errors.New("未查询到id:【" + utils.IntToStr(req.EnterpriseId) + "】公司对应记录") + } + + classDb := db.ClassDb{} + var classWithUser *[]model.ClassWithUser + for _, v := range req.GradeIds { + classDb.Set(v) + classes, err2 := classDb.FindClass() + if err2 != nil { + return err2 + } + var classIds []int + for _, vv := range *classes { + classIds = append(classIds, vv.Id) + } + classWithUser, err = classWithUserDb.FindUserIdentity(classIds) if err != nil { return err } - - if len(m) > 0 { - //2、更改 `central_kitchen_for_school_user_with_day` 的 state 为 退款中 - sql := "update central_kitchen_for_school_user_with_day set state = %d where identity_id In (%s) and date = '%s' and kind = %d" - idsStr := strings.Join(identityIds, ",") - sql = fmt.Sprintf(sql, enum2.CentralKitchenForSchoolUserWithDayStateForCanceling, idsStr, req.Date, enum2.CentralKitchenForSchoolUserWithDayKindForLunch) - fmt.Println(sql) - _, err = db.ExecuteOriginalSql(db.Db, sql) - if err != nil { - return err - } - - //3、循环处理数据 - var dealOutTradeNo = map[string]string{} - var centralKitchenForSchoolUserRefundDays []*model.CentralKitchenForSchoolUserRefundDay - now := time.Now() - for _, v := range m { - dealOutTradeNo[v.OrdNo] = v.OrdNo - outRequestNo := utils.OrderUUID(v.Uid) - centralKitchenForSchoolUserRefundDays = append(centralKitchenForSchoolUserRefundDays, &model.CentralKitchenForSchoolUserRefundDay{ - OutTradeNo: v.OrdNo, - OutRequestNo: outRequestNo, - Uid: v.Uid, - IdentityId: v.IdentityId, - RecordsId: v.Id, - State: enum2.CentralKitchenForSchoolUserRefundDayStateForAuditing, - Amount: v.Amount, - Memo: "", - CreateAt: now.Format("2006-01-02 15:04:05"), - UpdateAt: now.Format("2006-01-02 15:04:05"), - }) + var identityIds []string + for _, vv := range *classWithUser { + identityIds = append(identityIds, utils.IntToStr(vv.UserIdentityId)) + } + if len(identityIds) <= 0 { + //无请假学生 + continue + } + for _, date := range req.Dates { + //2、查询出所有 `central_kitchen_for_school_user_with_day` 记录 + var mm []model.CentralKitchenForSchoolUserWithDay + centralKitchenForSchoolUserWithDayDb := db.CentralKitchenForSchoolUserWithDayDb{} + centralKitchenForSchoolUserWithDayDb.Set(0) + if req.IsBreakfast == 1 { + err = centralKitchenForSchoolUserWithDayDb.Db.In("identity_id", identityIds).And("date =?", date). + And("kind =?", enum2.CentralKitchenForSchoolUserWithDayKindForBreakfast).Find(&mm) + if err != nil { + return err + } + if len(mm) > 0 { + //2、更改 `central_kitchen_for_school_user_with_day` 的 state 为 退款中 + sql := "update central_kitchen_for_school_user_with_day set state = %d where identity_id In (%s) and date = '%s' and kind = %d" + idsStr := strings.Join(identityIds, ",") + sql = fmt.Sprintf(sql, enum2.CentralKitchenForSchoolUserWithDayStateForCanceling, idsStr, date, enum2.CentralKitchenForSchoolUserWithDayKindForBreakfast) + fmt.Println(sql) + _, err = db.ExecuteOriginalSql(db.Db, sql) + if err != nil { + return err + } + + //3、循环处理数据 + var dealOutTradeNo = map[string]string{} + var centralKitchenForSchoolUserRefundDays []*model.CentralKitchenForSchoolUserRefundDay + now := time.Now() + for _, m := range mm { + dealOutTradeNo[m.OrdNo] = m.OrdNo + outRequestNo := utils.OrderUUID(m.Uid) + centralKitchenForSchoolUserRefundDays = append(centralKitchenForSchoolUserRefundDays, &model.CentralKitchenForSchoolUserRefundDay{ + OutTradeNo: m.OrdNo, + OutRequestNo: outRequestNo, + Uid: m.Uid, + IdentityId: m.IdentityId, + RecordsId: m.Id, + State: enum2.CentralKitchenForSchoolUserRefundDayStateForAuditing, + Amount: m.Amount, + Memo: "", + CreateAt: now.Format("2006-01-02 15:04:05"), + UpdateAt: now.Format("2006-01-02 15:04:05"), + }) + } + + //4、处理 `central_kitchen_for_school_package_ord` 的 订单状态 (ord_state) + for _, vv := range dealOutTradeNo { + err2 := JudgePackageOrdOrdState(vv) + if err2 != nil { + return err2 + } + } + + //5、新增 `central_kitchen_for_school_user_refund_day` 数据 + centralKitchenForSchoolUserRefundDayDb := db.CentralKitchenForSchoolUserRefundDayDb{} + centralKitchenForSchoolUserRefundDayDb.Set(0) + _, err = centralKitchenForSchoolUserRefundDayDb.BatchAddCentralKitchenForSchoolUserRefundDays(centralKitchenForSchoolUserRefundDays) + if err != nil { + return err + } + } } - //4、处理 `central_kitchen_for_school_package_ord` 的 订单状态 (ord_state) - for _, v := range dealOutTradeNo { - err1 := JudgePackageOrdOrdState(v) - if err1 != nil { - return err1 + if req.IsLunch == 1 { + err = centralKitchenForSchoolUserWithDayDb.Db.In("identity_id", identityIds).And("date =?", date). + And("kind =?", enum2.CentralKitchenForSchoolUserWithDayKindForLunch).Find(&mm) + if err != nil { + return err + } + if len(mm) > 0 { + //2、更改 `central_kitchen_for_school_user_with_day` 的 state 为 退款中 + sql := "update central_kitchen_for_school_user_with_day set state = %d where identity_id In (%s) and date = '%s' and kind = %d" + idsStr := strings.Join(identityIds, ",") + sql = fmt.Sprintf(sql, enum2.CentralKitchenForSchoolUserWithDayStateForCanceling, idsStr, date, enum2.CentralKitchenForSchoolUserWithDayKindForLunch) + fmt.Println(sql) + _, err = db.ExecuteOriginalSql(db.Db, sql) + if err != nil { + return err + } + + //3、循环处理数据 + var dealOutTradeNo = map[string]string{} + var centralKitchenForSchoolUserRefundDays []*model.CentralKitchenForSchoolUserRefundDay + now := time.Now() + for _, m := range mm { + dealOutTradeNo[m.OrdNo] = m.OrdNo + outRequestNo := utils.OrderUUID(m.Uid) + centralKitchenForSchoolUserRefundDays = append(centralKitchenForSchoolUserRefundDays, &model.CentralKitchenForSchoolUserRefundDay{ + OutTradeNo: m.OrdNo, + OutRequestNo: outRequestNo, + Uid: m.Uid, + IdentityId: m.IdentityId, + RecordsId: m.Id, + State: enum2.CentralKitchenForSchoolUserRefundDayStateForAuditing, + Amount: m.Amount, + Memo: "", + CreateAt: now.Format("2006-01-02 15:04:05"), + UpdateAt: now.Format("2006-01-02 15:04:05"), + }) + } + + //4、处理 `central_kitchen_for_school_package_ord` 的 订单状态 (ord_state) + for _, vv := range dealOutTradeNo { + err2 := JudgePackageOrdOrdState(vv) + if err2 != nil { + return err2 + } + } + + //5、新增 `central_kitchen_for_school_user_refund_day` 数据 + centralKitchenForSchoolUserRefundDayDb := db.CentralKitchenForSchoolUserRefundDayDb{} + centralKitchenForSchoolUserRefundDayDb.Set(0) + _, err = centralKitchenForSchoolUserRefundDayDb.BatchAddCentralKitchenForSchoolUserRefundDays(centralKitchenForSchoolUserRefundDays) + if err != nil { + return err + } } } - //5、新增 `central_kitchen_for_school_user_refund_day` 数据 - centralKitchenForSchoolUserRefundDayDb := db.CentralKitchenForSchoolUserRefundDayDb{} - centralKitchenForSchoolUserRefundDayDb.Set(0) - _, err = centralKitchenForSchoolUserRefundDayDb.BatchAddCentralKitchenForSchoolUserRefundDays(centralKitchenForSchoolUserRefundDays) - if err != nil { - return err + if req.IsDinner == 1 { + err = centralKitchenForSchoolUserWithDayDb.Db.In("identity_id", identityIds).And("date =?", date). + And("kind =?", enum2.CentralKitchenForSchoolUserWithDayKindForDinner).Find(&mm) + if err != nil { + return err + } + if len(mm) > 0 { + //2、更改 `central_kitchen_for_school_user_with_day` 的 state 为 退款中 + sql := "update central_kitchen_for_school_user_with_day set state = %d where identity_id In (%s) and date = '%s' and kind = %d" + idsStr := strings.Join(identityIds, ",") + sql = fmt.Sprintf(sql, enum2.CentralKitchenForSchoolUserWithDayStateForCanceling, idsStr, date, enum2.CentralKitchenForSchoolUserWithDayKindForDinner) + fmt.Println(sql) + _, err = db.ExecuteOriginalSql(db.Db, sql) + if err != nil { + return err + } + + //3、循环处理数据 + var dealOutTradeNo = map[string]string{} + var centralKitchenForSchoolUserRefundDays []*model.CentralKitchenForSchoolUserRefundDay + now := time.Now() + for _, m := range mm { + dealOutTradeNo[m.OrdNo] = m.OrdNo + outRequestNo := utils.OrderUUID(m.Uid) + centralKitchenForSchoolUserRefundDays = append(centralKitchenForSchoolUserRefundDays, &model.CentralKitchenForSchoolUserRefundDay{ + OutTradeNo: m.OrdNo, + OutRequestNo: outRequestNo, + Uid: m.Uid, + IdentityId: m.IdentityId, + RecordsId: m.Id, + State: enum2.CentralKitchenForSchoolUserRefundDayStateForAuditing, + Amount: m.Amount, + Memo: "", + CreateAt: now.Format("2006-01-02 15:04:05"), + UpdateAt: now.Format("2006-01-02 15:04:05"), + }) + } + + //4、处理 `central_kitchen_for_school_package_ord` 的 订单状态 (ord_state) + for _, vv := range dealOutTradeNo { + err2 := JudgePackageOrdOrdState(vv) + if err2 != nil { + return err2 + } + } + + //5、新增 `central_kitchen_for_school_user_refund_day` 数据 + centralKitchenForSchoolUserRefundDayDb := db.CentralKitchenForSchoolUserRefundDayDb{} + centralKitchenForSchoolUserRefundDayDb.Set(0) + _, err = centralKitchenForSchoolUserRefundDayDb.BatchAddCentralKitchenForSchoolUserRefundDays(centralKitchenForSchoolUserRefundDays) + if err != nil { + return err + } + } } } } + return +} + +func CentralKitchenForSchoolBatchAskForLeaveByClass(req md.CentralKitchenForSchoolBatchAskForLeaveReqByClass) (err error) { + enterpriseDb := db.EnterpriseDb{} + enterpriseDb.Set() + classWithUserDb := db.ClassWithUserDb{} + classWithUserDb.Set() + //1、查询学校 + enterprise, err1 := enterpriseDb.GetEnterprise(req.EnterpriseId) + if err1 != nil { + return + } + if enterprise == nil { + return errors.New("未查询到id:【" + utils.IntToStr(req.EnterpriseId) + "】公司对应记录") + } - if req.IsDinner == 1 { - err = centralKitchenForSchoolUserWithDayDb.Db.In("identity_id", identityIds).And("date =?", req.Date). - And("kind =?", enum2.CentralKitchenForSchoolUserWithDayKindForDinner).Find(&m) + var classWithUser *[]model.ClassWithUser + for _, v := range req.ClassIds { + classWithUser, err = classWithUserDb.FindUserIdentity(v) if err != nil { return err } - if len(m) < 0 { - //2、更改 `central_kitchen_for_school_user_with_day` 的 state 为 退款中 - sql := "update central_kitchen_for_school_user_with_day set state = %d where identity_id In (%s) and date = '%s' and kind = %d" - idsStr := strings.Join(identityIds, ",") - sql = fmt.Sprintf(sql, enum2.CentralKitchenForSchoolUserWithDayStateForCanceling, idsStr, req.Date, enum2.CentralKitchenForSchoolUserWithDayKindForDinner) - fmt.Println(sql) - _, err = db.ExecuteOriginalSql(db.Db, sql) - if err != nil { - return err - } + var identityIds []string + for _, vv := range *classWithUser { + identityIds = append(identityIds, utils.IntToStr(vv.UserIdentityId)) + } + if len(identityIds) <= 0 { + //无请假学生 + continue + } - //3、循环处理数据 - var dealOutTradeNo = map[string]string{} - var centralKitchenForSchoolUserRefundDays []*model.CentralKitchenForSchoolUserRefundDay - now := time.Now() - for _, v := range m { - dealOutTradeNo[v.OrdNo] = v.OrdNo - outRequestNo := utils.OrderUUID(v.Uid) - centralKitchenForSchoolUserRefundDays = append(centralKitchenForSchoolUserRefundDays, &model.CentralKitchenForSchoolUserRefundDay{ - OutTradeNo: v.OrdNo, - OutRequestNo: outRequestNo, - Uid: v.Uid, - IdentityId: v.IdentityId, - RecordsId: v.Id, - State: enum2.CentralKitchenForSchoolUserRefundDayStateForAuditing, - Amount: v.Amount, - Memo: "", - CreateAt: now.Format("2006-01-02 15:04:05"), - UpdateAt: now.Format("2006-01-02 15:04:05"), - }) + for _, date := range req.Dates { + //2、查询出所有 `central_kitchen_for_school_user_with_day` 记录 + var mm []model.CentralKitchenForSchoolUserWithDay + centralKitchenForSchoolUserWithDayDb := db.CentralKitchenForSchoolUserWithDayDb{} + centralKitchenForSchoolUserWithDayDb.Set(0) + if req.IsBreakfast == 1 { + err = centralKitchenForSchoolUserWithDayDb.Db.In("identity_id", identityIds).And("date =?", date). + And("kind =?", enum2.CentralKitchenForSchoolUserWithDayKindForBreakfast).Find(&mm) + if err != nil { + return err + } + if len(mm) > 0 { + //2、更改 `central_kitchen_for_school_user_with_day` 的 state 为 退款中 + sql := "update central_kitchen_for_school_user_with_day set state = %d where identity_id In (%s) and date = '%s' and kind = %d" + idsStr := strings.Join(identityIds, ",") + sql = fmt.Sprintf(sql, enum2.CentralKitchenForSchoolUserWithDayStateForCanceling, idsStr, date, enum2.CentralKitchenForSchoolUserWithDayKindForBreakfast) + fmt.Println(sql) + _, err = db.ExecuteOriginalSql(db.Db, sql) + if err != nil { + return err + } + + //3、循环处理数据 + var dealOutTradeNo = map[string]string{} + var centralKitchenForSchoolUserRefundDays []*model.CentralKitchenForSchoolUserRefundDay + now := time.Now() + for _, m := range mm { + dealOutTradeNo[m.OrdNo] = m.OrdNo + outRequestNo := utils.OrderUUID(m.Uid) + centralKitchenForSchoolUserRefundDays = append(centralKitchenForSchoolUserRefundDays, &model.CentralKitchenForSchoolUserRefundDay{ + OutTradeNo: m.OrdNo, + OutRequestNo: outRequestNo, + Uid: m.Uid, + IdentityId: m.IdentityId, + RecordsId: m.Id, + State: enum2.CentralKitchenForSchoolUserRefundDayStateForAuditing, + Amount: m.Amount, + Memo: "", + CreateAt: now.Format("2006-01-02 15:04:05"), + UpdateAt: now.Format("2006-01-02 15:04:05"), + }) + } + + //4、处理 `central_kitchen_for_school_package_ord` 的 订单状态 (ord_state) + for _, vv := range dealOutTradeNo { + err2 := JudgePackageOrdOrdState(vv) + if err2 != nil { + return err2 + } + } + + //5、新增 `central_kitchen_for_school_user_refund_day` 数据 + centralKitchenForSchoolUserRefundDayDb := db.CentralKitchenForSchoolUserRefundDayDb{} + centralKitchenForSchoolUserRefundDayDb.Set(0) + _, err = centralKitchenForSchoolUserRefundDayDb.BatchAddCentralKitchenForSchoolUserRefundDays(centralKitchenForSchoolUserRefundDays) + if err != nil { + return err + } + } } - //4、处理 `central_kitchen_for_school_package_ord` 的 订单状态(ord_state) - for _, v := range dealOutTradeNo { - err1 := JudgePackageOrdOrdState(v) - if err1 != nil { - return err1 + if req.IsLunch == 1 { + err = centralKitchenForSchoolUserWithDayDb.Db.In("identity_id", identityIds).And("date =?", date). + And("kind =?", enum2.CentralKitchenForSchoolUserWithDayKindForLunch).Find(&mm) + if err != nil { + return err + } + if len(mm) > 0 { + //2、更改 `central_kitchen_for_school_user_with_day` 的 state 为 退款中 + sql := "update central_kitchen_for_school_user_with_day set state = %d where identity_id In (%s) and date = '%s' and kind = %d" + idsStr := strings.Join(identityIds, ",") + sql = fmt.Sprintf(sql, enum2.CentralKitchenForSchoolUserWithDayStateForCanceling, idsStr, date, enum2.CentralKitchenForSchoolUserWithDayKindForLunch) + fmt.Println(sql) + _, err = db.ExecuteOriginalSql(db.Db, sql) + if err != nil { + return err + } + + //3、循环处理数据 + var dealOutTradeNo = map[string]string{} + var centralKitchenForSchoolUserRefundDays []*model.CentralKitchenForSchoolUserRefundDay + now := time.Now() + for _, m := range mm { + dealOutTradeNo[m.OrdNo] = m.OrdNo + outRequestNo := utils.OrderUUID(m.Uid) + centralKitchenForSchoolUserRefundDays = append(centralKitchenForSchoolUserRefundDays, &model.CentralKitchenForSchoolUserRefundDay{ + OutTradeNo: m.OrdNo, + OutRequestNo: outRequestNo, + Uid: m.Uid, + IdentityId: m.IdentityId, + RecordsId: m.Id, + State: enum2.CentralKitchenForSchoolUserRefundDayStateForAuditing, + Amount: m.Amount, + Memo: "", + CreateAt: now.Format("2006-01-02 15:04:05"), + UpdateAt: now.Format("2006-01-02 15:04:05"), + }) + } + + //4、处理 `central_kitchen_for_school_package_ord` 的 订单状态 (ord_state) + for _, vv := range dealOutTradeNo { + err2 := JudgePackageOrdOrdState(vv) + if err2 != nil { + return err2 + } + } + + //5、新增 `central_kitchen_for_school_user_refund_day` 数据 + centralKitchenForSchoolUserRefundDayDb := db.CentralKitchenForSchoolUserRefundDayDb{} + centralKitchenForSchoolUserRefundDayDb.Set(0) + _, err = centralKitchenForSchoolUserRefundDayDb.BatchAddCentralKitchenForSchoolUserRefundDays(centralKitchenForSchoolUserRefundDays) + if err != nil { + return err + } } } - //5、新增 `central_kitchen_for_school_user_refund_day` 数据 - centralKitchenForSchoolUserRefundDayDb := db.CentralKitchenForSchoolUserRefundDayDb{} - centralKitchenForSchoolUserRefundDayDb.Set(0) - _, err = centralKitchenForSchoolUserRefundDayDb.BatchAddCentralKitchenForSchoolUserRefundDays(centralKitchenForSchoolUserRefundDays) - if err != nil { - return err + if req.IsDinner == 1 { + err = centralKitchenForSchoolUserWithDayDb.Db.In("identity_id", identityIds).And("date =?", date). + And("kind =?", enum2.CentralKitchenForSchoolUserWithDayKindForDinner).Find(&mm) + if err != nil { + return err + } + if len(mm) > 0 { + //2、更改 `central_kitchen_for_school_user_with_day` 的 state 为 退款中 + sql := "update central_kitchen_for_school_user_with_day set state = %d where identity_id In (%s) and date = '%s' and kind = %d" + idsStr := strings.Join(identityIds, ",") + sql = fmt.Sprintf(sql, enum2.CentralKitchenForSchoolUserWithDayStateForCanceling, idsStr, date, enum2.CentralKitchenForSchoolUserWithDayKindForDinner) + fmt.Println(sql) + _, err = db.ExecuteOriginalSql(db.Db, sql) + if err != nil { + return err + } + + //3、循环处理数据 + var dealOutTradeNo = map[string]string{} + var centralKitchenForSchoolUserRefundDays []*model.CentralKitchenForSchoolUserRefundDay + now := time.Now() + for _, m := range mm { + dealOutTradeNo[m.OrdNo] = m.OrdNo + outRequestNo := utils.OrderUUID(m.Uid) + centralKitchenForSchoolUserRefundDays = append(centralKitchenForSchoolUserRefundDays, &model.CentralKitchenForSchoolUserRefundDay{ + OutTradeNo: m.OrdNo, + OutRequestNo: outRequestNo, + Uid: m.Uid, + IdentityId: m.IdentityId, + RecordsId: m.Id, + State: enum2.CentralKitchenForSchoolUserRefundDayStateForAuditing, + Amount: m.Amount, + Memo: "", + CreateAt: now.Format("2006-01-02 15:04:05"), + UpdateAt: now.Format("2006-01-02 15:04:05"), + }) + } + + //4、处理 `central_kitchen_for_school_package_ord` 的 订单状态 (ord_state) + for _, vv := range dealOutTradeNo { + err2 := JudgePackageOrdOrdState(vv) + if err2 != nil { + return err2 + } + } + + //5、新增 `central_kitchen_for_school_user_refund_day` 数据 + centralKitchenForSchoolUserRefundDayDb := db.CentralKitchenForSchoolUserRefundDayDb{} + centralKitchenForSchoolUserRefundDayDb.Set(0) + _, err = centralKitchenForSchoolUserRefundDayDb.BatchAddCentralKitchenForSchoolUserRefundDays(centralKitchenForSchoolUserRefundDays) + if err != nil { + return err + } + } } } }