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 c2d11d7..31d45ba 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 @@ -514,7 +514,7 @@ func SetBasicCentralKitchenForSchool(c *gin.Context) { set.IsOpenTeacherReportMealForMonth = req.IsOpenTeacherReportMealForMonth set.IsOpenTeacherReportMealForSemester = req.IsOpenTeacherReportMealForSemester set.UpdateAt = now.Format("2006-01-02 15:04:05") - _, err2 := centralKitchenForSchoolSetDb.CentralKitchenForSchoolSetUpdate(set.Id, set, "is_open_teacher_report_meal", "is_open_report_meal_for_day", "is_open_report_meal_for_month", "is_open_report_meal_for_semester", "update_at") + _, err2 := centralKitchenForSchoolSetDb.CentralKitchenForSchoolSetUpdate(set.Id, set, "is_open_teacher_report_meal", "is_open_report_meal_for_day", "is_open_report_meal_for_month", "is_open_report_meal_for_semester", "is_open_teacher_report_meal_for_semester", "update_at") if err2 != nil { e.OutErr(c, e.ERR_DB_ORM, err2.Error()) return diff --git a/app/admin/hdl/hdl_enterprise.go b/app/admin/hdl/hdl_enterprise.go index 308260d..aa0cf30 100644 --- a/app/admin/hdl/hdl_enterprise.go +++ b/app/admin/hdl/hdl_enterprise.go @@ -102,6 +102,21 @@ func SchoolBelowGrade(c *gin.Context) { return } +//func SchoolBelowPeriod(c *gin.Context) { +// periodId := c.DefaultQuery("period_id", "") +// gradeDb := db.GradeDb{} +// gradeDb.Set(utils.StrToInt(enterpriseId)) +// gradeList, err := gradeDb.FindGrade() +// if err != nil { +// e.OutErr(c, e.ERR_DB_ORM, err.Error()) +// return +// } +// e.OutSuc(c, map[string]interface{}{ +// "list": gradeList, +// }, nil) +// return +//} + func SchoolGradeBelowClass(c *gin.Context) { gradeId := c.DefaultQuery("grade_id", "") enterpriseId := c.DefaultQuery("enterprise_id", "") diff --git a/app/admin/md/md_central_kitchen_for_school_export_records.go b/app/admin/md/md_central_kitchen_for_school_export_records.go index 09860a5..e4ab5d6 100644 --- a/app/admin/md/md_central_kitchen_for_school_export_records.go +++ b/app/admin/md/md_central_kitchen_for_school_export_records.go @@ -9,7 +9,7 @@ type CentralKitchenForSchoolExportRecordsListReq struct { } type CentralKitchenForSchoolDataStatisticsExportReq struct { - Kind int `json:"kind" binding:"required" label:"导出类型"` + Kinds []int `json:"kinds" binding:"required" label:"导出类型"` StartDate string `json:"start_date" binding:"required" label:"起始时间"` EndDate string `json:"end_date" binding:"required" label:"截止时间"` MealKindList []int `json:"meal_kind_list" label:"就餐类型(1:早餐 2:午餐 3:晚餐)"` diff --git a/app/admin/svc/svc_data_statisstics.go b/app/admin/svc/svc_data_statisstics.go index 9276119..c70d276 100644 --- a/app/admin/svc/svc_data_statisstics.go +++ b/app/admin/svc/svc_data_statisstics.go @@ -415,914 +415,916 @@ func CentralKitchenForSchoolDataStatisticsExport(req md.CentralKitchenForSchoolD var fileName, downloadPath string var now = time.Now() xlsx := excelize.NewFile() - switch req.Kind { - case 1: - //订单列表 - fileName = "订单列表_" + utils.Int64ToStr(now.UnixMilli()) + ".xlsx" - downloadPath = "/export/central_kitchen_for_school/" + fileName - //查找订单数据 - sess := db.Db.Desc("central_kitchen_for_school_package_ord.id") - sess.And("central_kitchen_for_school_package_ord.state =?", enum.CentralKitchenForSchoolPackageOrdStateForSuccess) - if req.EnterpriseId != 0 { - sess.And("central_kitchen_for_school_package_ord.enterprise_id =?", req.EnterpriseId) - } - if req.StartDate != "" { - sess.And("central_kitchen_for_school_package_ord.create_at >= ?", req.StartDate) - } - if req.EndDate != "" { - sess.And("central_kitchen_for_school_package_ord.create_at <= ?", req.EndDate) - } - var m []*db.CentralKitchenForSchoolPackageOrdWithUserIdentity - _, err := sess. - Join("LEFT", "user_identity", "central_kitchen_for_school_package_ord.user_identity_id = user_identity.id"). - Join("LEFT", "enterprise", "enterprise.id = user_identity.enterprise_id"). - Join("LEFT", "user", "user.id = user_identity.uid"). - Join("LEFT", "class_with_user", "class_with_user.user_identity_id = user_identity.id"). - Join("LEFT", "class", "class_with_user.class_id = class.id"). - Join("LEFT", "grade", "class.grade_id = grade.id"). - FindAndCount(&m) - if err != nil { - logx.Error(err) - println("<<<>>>>Error:::", err.Error()) - return - } - - //查找预定数据 - var outTradeNoList []string - for _, v := range m { - outTradeNoList = append(outTradeNoList, v.OutTradeNo) - } - var mm []model.CentralKitchenForSchoolPackageOrdForReserve - sess1 := db.Db.Desc("id") - if req.EnterpriseId != 0 { - sess1.And("enterprise_id = ?", req.EnterpriseId) - } - if len(req.MealKindList) > 0 { - sess1.In("kind", req.MealKindList) - } - err = sess1.In("out_trade_no", outTradeNoList).Find(&mm) - if err != nil { - logx.Error(err) - println("<<<>>>>Error:::", err.Error()) - return - } - var exportOutTradeNoList []string - for _, v := range mm { - exportOutTradeNoList = append(exportOutTradeNoList, v.OutTradeNo) - } - - titleList = []string{"订单号", "学生姓名", "学校", "年级", "班级", "家长电话", "预定日期", "预定天数", "订单价格", "支付时间", "订单状态"} - xlsx.SetSheetRow("Sheet1", "A1", &titleList) - j := 2 //表头被第一行用了,只能从第二行开始 - for _, v := range m { - if !utils.InArr(v.OutTradeNo, exportOutTradeNoList) { - continue - } - var ordState string //订单状态(0:待支付 1:预约成功 2:退款中 3:部分退款 4:已退款 5:已完成) - switch v.CentralKitchenForSchoolPackageOrd.OrdState { - case enum.CentralKitchenForSchoolPackageOrdOrdStateForWait: - ordState = enum.CentralKitchenForSchoolPackageOrdOrdState.String(enum.CentralKitchenForSchoolPackageOrdOrdStateForWait) - break - case enum.CentralKitchenForSchoolPackageOrdOrdStateForSuccess: - ordState = enum.CentralKitchenForSchoolPackageOrdOrdState.String(enum.CentralKitchenForSchoolPackageOrdOrdStateForSuccess) - break - case enum.CentralKitchenForSchoolPackageOrdOrdStateForRefunding: - ordState = enum.CentralKitchenForSchoolPackageOrdOrdState.String(enum.CentralKitchenForSchoolPackageOrdOrdStateForRefunding) - break - case enum.CentralKitchenForSchoolPackageOrdOrdStateForPartRefunded: - ordState = enum.CentralKitchenForSchoolPackageOrdOrdState.String(enum.CentralKitchenForSchoolPackageOrdOrdStateForPartRefunded) - break - case enum.CentralKitchenForSchoolPackageOrdOrdStateForRefunded: - ordState = enum.CentralKitchenForSchoolPackageOrdOrdState.String(enum.CentralKitchenForSchoolPackageOrdOrdStateForRefunded) - break - case enum.CentralKitchenForSchoolPackageOrdOrdStateForComplete: - ordState = enum.CentralKitchenForSchoolPackageOrdOrdState.String(enum.CentralKitchenForSchoolPackageOrdOrdStateForComplete) - break - } - //预定天数、预定日期 - var list []*model.CentralKitchenForSchoolUserWithDay - err1 := json.Unmarshal([]byte(v.CentralKitchenForSchoolPackageOrd.WithDayData), &list) - if err1 != nil { + for _, kind := range req.Kinds { + switch kind { + case 1: + //订单列表 + fileName = "订单列表_" + utils.Int64ToStr(now.UnixMilli()) + ".xlsx" + downloadPath = "/export/central_kitchen_for_school/" + fileName + //查找订单数据 + sess := db.Db.Desc("central_kitchen_for_school_package_ord.id") + sess.And("central_kitchen_for_school_package_ord.state =?", enum.CentralKitchenForSchoolPackageOrdStateForSuccess) + if req.EnterpriseId != 0 { + sess.And("central_kitchen_for_school_package_ord.enterprise_id =?", req.EnterpriseId) + } + if req.StartDate != "" { + sess.And("central_kitchen_for_school_package_ord.create_at >= ?", req.StartDate) + } + if req.EndDate != "" { + sess.And("central_kitchen_for_school_package_ord.create_at <= ?", req.EndDate) + } + var m []*db.CentralKitchenForSchoolPackageOrdWithUserIdentity + _, err := sess. + Join("LEFT", "user_identity", "central_kitchen_for_school_package_ord.user_identity_id = user_identity.id"). + Join("LEFT", "enterprise", "enterprise.id = user_identity.enterprise_id"). + Join("LEFT", "user", "user.id = user_identity.uid"). + Join("LEFT", "class_with_user", "class_with_user.user_identity_id = user_identity.id"). + Join("LEFT", "class", "class_with_user.class_id = class.id"). + Join("LEFT", "grade", "class.grade_id = grade.id"). + FindAndCount(&m) + if err != nil { logx.Error(err) println("<<<>>>>Error:::", err.Error()) return } - var reserveDays string - for _, v1 := range list { - reserveDays += v1.Date + + //查找预定数据 + var outTradeNoList []string + for _, v := range m { + outTradeNoList = append(outTradeNoList, v.OutTradeNo) } - if v.Grade.Name == "" { - v.Grade.Name = "教师" + var mm []model.CentralKitchenForSchoolPackageOrdForReserve + sess1 := db.Db.Desc("id") + if req.EnterpriseId != 0 { + sess1.And("enterprise_id = ?", req.EnterpriseId) } - if v.Class.Name == "" { - v.Class.Name = "教师" + if len(req.MealKindList) > 0 { + sess1.In("kind", req.MealKindList) } - xlsx.SetSheetRow("Sheet1", "A"+strconv.Itoa(j), &[]interface{}{v.CentralKitchenForSchoolPackageOrd.OutTradeNo, v.CentralKitchenForSchoolPackageOrd.UserIdentityName, v.Enterprise.Name, - v.Grade.Name, v.Class.Name, v.User.Phone, reserveDays, len(list), v.CentralKitchenForSchoolPackageOrd.TotalPrice, v.CentralKitchenForSchoolPackageOrd.CreateAt, ordState}) - j++ - } - //将文件保存至服务器 - xlsx.SaveAs("./static" + downloadPath) - break - case 2: - //退款申请表 - fileName = "退款申请表_" + utils.Int64ToStr(now.UnixMilli()) + ".xlsx" - downloadPath = "/export/central_kitchen_for_school/" + fileName - //查找退款申请数据 - sess := db.Db.Desc("central_kitchen_for_school_user_refund_day.id") - if req.EnterpriseId != 0 { - sess.And("enterprise.id =?", req.EnterpriseId) - } - if req.StartDate != "" { - sess.And("central_kitchen_for_school_user_refund_day.create_at >= ?", req.StartDate) - } - if req.EndDate != "" { - sess.And("central_kitchen_for_school_user_refund_day.create_at <= ?", req.EndDate) - } - if len(req.MealKindList) > 0 { - sess.In("central_kitchen_for_school_user_with_day.kind", req.MealKindList) - } - var m []*db.CentralKitchenForSchoolUserRefundDayWithData - _, err := sess. - Join("LEFT", "central_kitchen_for_school_user_with_day", "central_kitchen_for_school_user_refund_day.records_id = central_kitchen_for_school_user_with_day.id"). - Join("LEFT", "central_kitchen_for_school_package_ord", "central_kitchen_for_school_user_refund_day.out_trade_no = central_kitchen_for_school_package_ord.out_trade_no"). - Join("LEFT", "user_identity", "central_kitchen_for_school_user_with_day.identity_id = user_identity.id"). - Join("LEFT", "user", "user_identity.uid = user.id"). - Join("LEFT", "enterprise", "user_identity.enterprise_id = enterprise.id"). - Join("LEFT", "class_with_user", "user_identity.id = class_with_user.user_identity_id"). - Join("LEFT", "class", "class_with_user.class_id = class.id"). - Join("LEFT", "grade", "class.grade_id = grade.id"). - Desc("central_kitchen_for_school_user_refund_day.id"). - FindAndCount(&m) - if err != nil { - logx.Error(err) - println("<<<>>>>Error:::", err.Error()) - return - } - titleList = []string{"学生姓名", "学校", "年级", "班级", "家长电话", "退款日期", "餐型", "退款金额", "退款状态", "支付时间", "退款操作时间"} - xlsx.SetSheetRow("Sheet1", "A1", &titleList) - j := 2 //表头被第一行用了,只能从第二行开始 - for _, v := range m { - var kind string //就餐类型(1:早餐 2:午餐 3:晚餐) - switch v.CentralKitchenForSchoolUserWithDay.Kind { - case enum.CentralKitchenForSchoolUserWithDayKindForBreakfast: - kind = enum.CentralKitchenForSchoolUserWithDayKind.String(enum.CentralKitchenForSchoolUserWithDayKindForBreakfast) - break - case enum.CentralKitchenForSchoolUserWithDayKindForLunch: - kind = enum.CentralKitchenForSchoolUserWithDayKind.String(enum.CentralKitchenForSchoolUserWithDayKindForLunch) - break - case enum.CentralKitchenForSchoolUserWithDayKindForDinner: - kind = enum.CentralKitchenForSchoolUserWithDayKind.String(enum.CentralKitchenForSchoolUserWithDayKindForDinner) - break + err = sess1.In("out_trade_no", outTradeNoList).Find(&mm) + if err != nil { + logx.Error(err) + println("<<<>>>>Error:::", err.Error()) + return } - - var state string //状态(1:审核中 2:审核通过 3:审核拒绝 4:退款已完成) - switch v.CentralKitchenForSchoolUserRefundDay.State { - case enum.CentralKitchenForSchoolUserRefundDayStateForAuditing: - state = enum.CentralKitchenForSchoolUserRefundDayState.String(enum.CentralKitchenForSchoolUserRefundDayStateForAuditing) - break - case enum.CentralKitchenForSchoolUserRefundDayStateForAuditPass: - state = enum.CentralKitchenForSchoolUserRefundDayState.String(enum.CentralKitchenForSchoolUserRefundDayStateForAuditPass) - break - case enum.CentralKitchenForSchoolUserRefundDayStateForAuditReject: - state = enum.CentralKitchenForSchoolUserRefundDayState.String(enum.CentralKitchenForSchoolUserRefundDayStateForAuditReject) - break - case enum.CentralKitchenForSchoolUserRefundDayStateForAuditComplete: - state = enum.CentralKitchenForSchoolUserRefundDayState.String(enum.CentralKitchenForSchoolUserRefundDayStateForAuditComplete) - break + var exportOutTradeNoList []string + for _, v := range mm { + exportOutTradeNoList = append(exportOutTradeNoList, v.OutTradeNo) } - xlsx.SetSheetRow("Sheet1", "A"+strconv.Itoa(j), &[]interface{}{v.CentralKitchenForSchoolPackageOrd.UserIdentityName, v.Enterprise.Name, v.Grade.Name, v.Class.Name, v.User.Phone, - v.CentralKitchenForSchoolUserWithDay.Date, kind, v.CentralKitchenForSchoolUserRefundDay.Amount, state, v.CentralKitchenForSchoolPackageOrd.CreateAt, v.CentralKitchenForSchoolUserRefundDay.RefundDate}) - j++ - } - //将文件保存至服务器 - xlsx.SaveAs("./static" + downloadPath) - break - case 3: - //学校预定统计表 - fileName = "学校预定统计表_" + utils.Int64ToStr(now.UnixMilli()) + ".zip" - downloadPath = "/export/central_kitchen_for_school/" + fileName - - var m []*db.CentralKitchenForSchoolPackageOrdForReserveWithUserIdentity - sess := db.Db.Desc("central_kitchen_for_school_package_ord_for_reserve.id") - if req.EnterpriseId != 0 { - sess.And("central_kitchen_for_school_package_ord_for_reserve.enterprise_id =?", req.EnterpriseId) - } - if req.StartDate != "" { - sess.And("central_kitchen_for_school_package_ord_for_reserve.meal_time_start >= ?", req.StartDate) - } - if req.EndDate != "" { - sess.And("central_kitchen_for_school_package_ord_for_reserve.meal_time_start <= ?", req.EndDate) - } - if len(req.MealKindList) > 0 { - sess.In("central_kitchen_for_school_package_ord_for_reserve.kind", req.MealKindList) - } - _, err := sess. - Join("LEFT", "central_kitchen_for_school_package_ord", "central_kitchen_for_school_package_ord_for_reserve.out_trade_no = central_kitchen_for_school_package_ord.out_trade_no"). - Join("LEFT", "user_identity", "central_kitchen_for_school_package_ord.user_identity_id = user_identity.id"). - Join("LEFT", "enterprise", "enterprise.id = user_identity.enterprise_id"). - Join("LEFT", "user", "user.id = user_identity.uid"). - Join("LEFT", "class_with_user", "class_with_user.user_identity_id = user_identity.id"). - Join("LEFT", "class", "class_with_user.class_id = class.id"). - Join("LEFT", "grade", "class.grade_id = grade.id"). - FindAndCount(&m) - if err != nil { - logx.Error(err) - println("<<<>>>>Error:::", err.Error()) - return - } - centralKitchenForSchoolUserWithDayDb := db.CentralKitchenForSchoolUserWithDayDb{} - centralKitchenForSchoolUserWithDayDb.Set(0) - var list = map[string]map[string]map[string]map[string]int64{} - var xlsFileName, xlsDownloadPath []string - for _, v := range m { - if list[v.Enterprise.Name] == nil { - list[v.Enterprise.Name] = make(map[string]map[string]map[string]int64) - } - if list[v.Enterprise.Name][v.Grade.Name] == nil { - list[v.Enterprise.Name][v.Grade.Name] = make(map[string]map[string]int64) - } - if list[v.Enterprise.Name][v.Grade.Name][v.Class.Name] == nil { - list[v.Enterprise.Name][v.Grade.Name][v.Class.Name] = make(map[string]int64) + titleList = []string{"订单号", "学生姓名", "学校", "年级", "班级", "家长电话", "预定日期", "预定天数", "订单价格", "支付时间", "订单状态"} + xlsx.SetSheetRow("Sheet1", "A1", &titleList) + j := 2 //表头被第一行用了,只能从第二行开始 + for _, v := range m { + if !utils.InArr(v.OutTradeNo, exportOutTradeNoList) { + continue + } + var ordState string //订单状态(0:待支付 1:预约成功 2:退款中 3:部分退款 4:已退款 5:已完成) + switch v.CentralKitchenForSchoolPackageOrd.OrdState { + case enum.CentralKitchenForSchoolPackageOrdOrdStateForWait: + ordState = enum.CentralKitchenForSchoolPackageOrdOrdState.String(enum.CentralKitchenForSchoolPackageOrdOrdStateForWait) + break + case enum.CentralKitchenForSchoolPackageOrdOrdStateForSuccess: + ordState = enum.CentralKitchenForSchoolPackageOrdOrdState.String(enum.CentralKitchenForSchoolPackageOrdOrdStateForSuccess) + break + case enum.CentralKitchenForSchoolPackageOrdOrdStateForRefunding: + ordState = enum.CentralKitchenForSchoolPackageOrdOrdState.String(enum.CentralKitchenForSchoolPackageOrdOrdStateForRefunding) + break + case enum.CentralKitchenForSchoolPackageOrdOrdStateForPartRefunded: + ordState = enum.CentralKitchenForSchoolPackageOrdOrdState.String(enum.CentralKitchenForSchoolPackageOrdOrdStateForPartRefunded) + break + case enum.CentralKitchenForSchoolPackageOrdOrdStateForRefunded: + ordState = enum.CentralKitchenForSchoolPackageOrdOrdState.String(enum.CentralKitchenForSchoolPackageOrdOrdStateForRefunded) + break + case enum.CentralKitchenForSchoolPackageOrdOrdStateForComplete: + ordState = enum.CentralKitchenForSchoolPackageOrdOrdState.String(enum.CentralKitchenForSchoolPackageOrdOrdStateForComplete) + break + } + //预定天数、预定日期 + var list []*model.CentralKitchenForSchoolUserWithDay + err1 := json.Unmarshal([]byte(v.CentralKitchenForSchoolPackageOrd.WithDayData), &list) + if err1 != nil { + logx.Error(err) + println("<<<>>>>Error:::", err.Error()) + return + } + var reserveDays string + for _, v1 := range list { + reserveDays += v1.Date + } + if v.Grade.Name == "" { + v.Grade.Name = "教师" + } + if v.Class.Name == "" { + v.Class.Name = "教师" + } + xlsx.SetSheetRow("Sheet1", "A"+strconv.Itoa(j), &[]interface{}{v.CentralKitchenForSchoolPackageOrd.OutTradeNo, v.CentralKitchenForSchoolPackageOrd.UserIdentityName, v.Enterprise.Name, + v.Grade.Name, v.Class.Name, v.User.Phone, reserveDays, len(list), v.CentralKitchenForSchoolPackageOrd.TotalPrice, v.CentralKitchenForSchoolPackageOrd.CreateAt, ordState}) + j++ } - - count, err2 := centralKitchenForSchoolUserWithDayDb.CountCentralKitchenForSchoolUserWithDayByOrdNo(v.CentralKitchenForSchoolPackageOrdForReserve.OutTradeNo, enum.CentralKitchenForSchoolUserWithDayStateForCancel) - if err2 != nil { + //将文件保存至服务器 + xlsx.SaveAs("./static" + downloadPath) + break + case 2: + //退款申请表 + fileName = "退款申请表_" + utils.Int64ToStr(now.UnixMilli()) + ".xlsx" + downloadPath = "/export/central_kitchen_for_school/" + fileName + //查找退款申请数据 + sess := db.Db.Desc("central_kitchen_for_school_user_refund_day.id") + if req.EnterpriseId != 0 { + sess.And("enterprise.id =?", req.EnterpriseId) + } + if req.StartDate != "" { + sess.And("central_kitchen_for_school_user_refund_day.create_at >= ?", req.StartDate) + } + if req.EndDate != "" { + sess.And("central_kitchen_for_school_user_refund_day.create_at <= ?", req.EndDate) + } + if len(req.MealKindList) > 0 { + sess.In("central_kitchen_for_school_user_with_day.kind", req.MealKindList) + } + var m []*db.CentralKitchenForSchoolUserRefundDayWithData + _, err := sess. + Join("LEFT", "central_kitchen_for_school_user_with_day", "central_kitchen_for_school_user_refund_day.records_id = central_kitchen_for_school_user_with_day.id"). + Join("LEFT", "central_kitchen_for_school_package_ord", "central_kitchen_for_school_user_refund_day.out_trade_no = central_kitchen_for_school_package_ord.out_trade_no"). + Join("LEFT", "user_identity", "central_kitchen_for_school_user_with_day.identity_id = user_identity.id"). + Join("LEFT", "user", "user_identity.uid = user.id"). + Join("LEFT", "enterprise", "user_identity.enterprise_id = enterprise.id"). + Join("LEFT", "class_with_user", "user_identity.id = class_with_user.user_identity_id"). + Join("LEFT", "class", "class_with_user.class_id = class.id"). + Join("LEFT", "grade", "class.grade_id = grade.id"). + Desc("central_kitchen_for_school_user_refund_day.id"). + FindAndCount(&m) + if err != nil { logx.Error(err) - println("<<<>>>>Error:::", err.Error()) + println("<<<>>>>Error:::", err.Error()) return } - time.Sleep(50 * time.Millisecond) // 50毫秒 + titleList = []string{"学生姓名", "学校", "年级", "班级", "家长电话", "退款日期", "餐型", "退款金额", "退款状态", "支付时间", "退款操作时间"} + xlsx.SetSheetRow("Sheet1", "A1", &titleList) + j := 2 //表头被第一行用了,只能从第二行开始 + for _, v := range m { + var kind string //就餐类型(1:早餐 2:午餐 3:晚餐) + switch v.CentralKitchenForSchoolUserWithDay.Kind { + case enum.CentralKitchenForSchoolUserWithDayKindForBreakfast: + kind = enum.CentralKitchenForSchoolUserWithDayKind.String(enum.CentralKitchenForSchoolUserWithDayKindForBreakfast) + break + case enum.CentralKitchenForSchoolUserWithDayKindForLunch: + kind = enum.CentralKitchenForSchoolUserWithDayKind.String(enum.CentralKitchenForSchoolUserWithDayKindForLunch) + break + case enum.CentralKitchenForSchoolUserWithDayKindForDinner: + kind = enum.CentralKitchenForSchoolUserWithDayKind.String(enum.CentralKitchenForSchoolUserWithDayKindForDinner) + break + } - if v.CentralKitchenForSchoolPackageOrdForReserve.Kind == enum.CentralKitchenForSchoolUserWithDayKindForBreakfast { - list[v.Enterprise.Name][v.Grade.Name][v.Class.Name]["breakfast"] += count - } - if v.CentralKitchenForSchoolPackageOrdForReserve.Kind == enum.CentralKitchenForSchoolUserWithDayKindForLunch { - list[v.Enterprise.Name][v.Grade.Name][v.Class.Name]["lunch"] += count + var state string //状态(1:审核中 2:审核通过 3:审核拒绝 4:退款已完成) + switch v.CentralKitchenForSchoolUserRefundDay.State { + case enum.CentralKitchenForSchoolUserRefundDayStateForAuditing: + state = enum.CentralKitchenForSchoolUserRefundDayState.String(enum.CentralKitchenForSchoolUserRefundDayStateForAuditing) + break + case enum.CentralKitchenForSchoolUserRefundDayStateForAuditPass: + state = enum.CentralKitchenForSchoolUserRefundDayState.String(enum.CentralKitchenForSchoolUserRefundDayStateForAuditPass) + break + case enum.CentralKitchenForSchoolUserRefundDayStateForAuditReject: + state = enum.CentralKitchenForSchoolUserRefundDayState.String(enum.CentralKitchenForSchoolUserRefundDayStateForAuditReject) + break + case enum.CentralKitchenForSchoolUserRefundDayStateForAuditComplete: + state = enum.CentralKitchenForSchoolUserRefundDayState.String(enum.CentralKitchenForSchoolUserRefundDayStateForAuditComplete) + break + } + xlsx.SetSheetRow("Sheet1", "A"+strconv.Itoa(j), &[]interface{}{v.CentralKitchenForSchoolPackageOrd.UserIdentityName, v.Enterprise.Name, v.Grade.Name, v.Class.Name, v.User.Phone, + v.CentralKitchenForSchoolUserWithDay.Date, kind, v.CentralKitchenForSchoolUserRefundDay.Amount, state, v.CentralKitchenForSchoolPackageOrd.CreateAt, v.CentralKitchenForSchoolUserRefundDay.RefundDate}) + j++ } - if v.CentralKitchenForSchoolPackageOrdForReserve.Kind == enum.CentralKitchenForSchoolUserWithDayKindForDinner { - list[v.Enterprise.Name][v.Grade.Name][v.Class.Name]["dinner"] += count + //将文件保存至服务器 + xlsx.SaveAs("./static" + downloadPath) + break + case 3: + //学校预定统计表 + fileName = "学校预定统计表_" + utils.Int64ToStr(now.UnixMilli()) + ".zip" + downloadPath = "/export/central_kitchen_for_school/" + fileName + + var m []*db.CentralKitchenForSchoolPackageOrdForReserveWithUserIdentity + sess := db.Db.Desc("central_kitchen_for_school_package_ord_for_reserve.id") + if req.EnterpriseId != 0 { + sess.And("central_kitchen_for_school_package_ord_for_reserve.enterprise_id =?", req.EnterpriseId) + } + if req.StartDate != "" { + sess.And("central_kitchen_for_school_package_ord_for_reserve.meal_time_start >= ?", req.StartDate) + } + if req.EndDate != "" { + sess.And("central_kitchen_for_school_package_ord_for_reserve.meal_time_start <= ?", req.EndDate) + } + if len(req.MealKindList) > 0 { + sess.In("central_kitchen_for_school_package_ord_for_reserve.kind", req.MealKindList) + } + _, err := sess. + Join("LEFT", "central_kitchen_for_school_package_ord", "central_kitchen_for_school_package_ord_for_reserve.out_trade_no = central_kitchen_for_school_package_ord.out_trade_no"). + Join("LEFT", "user_identity", "central_kitchen_for_school_package_ord.user_identity_id = user_identity.id"). + Join("LEFT", "enterprise", "enterprise.id = user_identity.enterprise_id"). + Join("LEFT", "user", "user.id = user_identity.uid"). + Join("LEFT", "class_with_user", "class_with_user.user_identity_id = user_identity.id"). + Join("LEFT", "class", "class_with_user.class_id = class.id"). + Join("LEFT", "grade", "class.grade_id = grade.id"). + FindAndCount(&m) + if err != nil { + logx.Error(err) + println("<<<>>>>Error:::", err.Error()) + return } - } - for k1, v1 := range list { - tmpFileName := k1 + "学校预定统计表_" + utils.Int64ToStr(now.UnixMilli()) + ".xlsx" - tmpDownloadPath := "./static/export/central_kitchen_for_school/" + tmpFileName - titleList = []string{"年级", "班级", "早餐", "午餐", "晚餐"} - xlsx.SetSheetRow("Sheet1", "A1", &titleList) - j := 2 //表头被第一行用了,只能从第二行开始 - for k2, v2 := range v1 { - if k2 == "" { - //若年级为空,则为教师餐 - k2 = "教师餐" + centralKitchenForSchoolUserWithDayDb := db.CentralKitchenForSchoolUserWithDayDb{} + centralKitchenForSchoolUserWithDayDb.Set(0) + var list = map[string]map[string]map[string]map[string]int64{} + var xlsFileName, xlsDownloadPath []string + for _, v := range m { + if list[v.Enterprise.Name] == nil { + list[v.Enterprise.Name] = make(map[string]map[string]map[string]int64) + } + if list[v.Enterprise.Name][v.Grade.Name] == nil { + list[v.Enterprise.Name][v.Grade.Name] = make(map[string]map[string]int64) + } + if list[v.Enterprise.Name][v.Grade.Name][v.Class.Name] == nil { + list[v.Enterprise.Name][v.Grade.Name][v.Class.Name] = make(map[string]int64) } - for k3, v3 := range v2 { - if k3 == "" { - //若班级为空,则为教师餐 - k3 = "教师餐" - } + count, err2 := centralKitchenForSchoolUserWithDayDb.CountCentralKitchenForSchoolUserWithDayByOrdNo(v.CentralKitchenForSchoolPackageOrdForReserve.OutTradeNo, enum.CentralKitchenForSchoolUserWithDayStateForCancel) + if err2 != nil { + logx.Error(err) + println("<<<>>>>Error:::", err.Error()) + return + } + time.Sleep(50 * time.Millisecond) // 50毫秒 - xlsx.SetSheetRow("Sheet1", "A"+strconv.Itoa(j), &[]interface{}{ - k2, k3, v3["breakfast"], v3["lunch"], v3["dinner"]}) - j++ + if v.CentralKitchenForSchoolPackageOrdForReserve.Kind == enum.CentralKitchenForSchoolUserWithDayKindForBreakfast { + list[v.Enterprise.Name][v.Grade.Name][v.Class.Name]["breakfast"] += count + } + if v.CentralKitchenForSchoolPackageOrdForReserve.Kind == enum.CentralKitchenForSchoolUserWithDayKindForLunch { + list[v.Enterprise.Name][v.Grade.Name][v.Class.Name]["lunch"] += count + } + if v.CentralKitchenForSchoolPackageOrdForReserve.Kind == enum.CentralKitchenForSchoolUserWithDayKindForDinner { + list[v.Enterprise.Name][v.Grade.Name][v.Class.Name]["dinner"] += count } } - //将文件保存至服务器 - err1 := xlsx.SaveAs(tmpDownloadPath) - if err1 != nil { - logx.Error(err1) - println("<<<>>>>Error:::", err1.Error()) - panic(err1) - } - xlsDownloadPath = append(xlsDownloadPath, tmpDownloadPath) - xlsFileName = append(xlsFileName, tmpFileName) - } - archive, err := os.Create("./static" + downloadPath) //第一步,创建 zip 文件 - if err != nil { - logx.Error(err) - println("<<<>>>>Error:::", err.Error()) - panic(err) - } - defer archive.Close() + for k1, v1 := range list { + tmpFileName := k1 + "学校预定统计表_" + utils.Int64ToStr(now.UnixMilli()) + ".xlsx" + tmpDownloadPath := "./static/export/central_kitchen_for_school/" + tmpFileName + titleList = []string{"年级", "班级", "早餐", "午餐", "晚餐"} + xlsx.SetSheetRow("Sheet1", "A1", &titleList) + j := 2 //表头被第一行用了,只能从第二行开始 + for k2, v2 := range v1 { + if k2 == "" { + //若年级为空,则为教师餐 + k2 = "教师餐" + } - zipWriter := zip.NewWriter(archive) //第二步,创建一个新的 *Writer 对象 - for k, v := range xlsDownloadPath { - w, err1 := zipWriter.Create("学校预定统计/" + xlsFileName[k]) //向 zip 文件中添加一个文件,返回一个待压缩的文件内容应写入的 Writer - if err1 != nil { - logx.Error(err1) - println("<<<>>>>Error:::", err1.Error()) - panic(err1) - } + for k3, v3 := range v2 { + if k3 == "" { + //若班级为空,则为教师餐 + k3 = "教师餐" + } - f, err1 := os.Open(v) //打开待压缩的文件 - if err1 != nil { - logx.Error(err1) - println("<<<>>>>Error:::", err1.Error()) - panic(err1) + xlsx.SetSheetRow("Sheet1", "A"+strconv.Itoa(j), &[]interface{}{ + k2, k3, v3["breakfast"], v3["lunch"], v3["dinner"]}) + j++ + } + } + //将文件保存至服务器 + err1 := xlsx.SaveAs(tmpDownloadPath) + if err1 != nil { + logx.Error(err1) + println("<<<>>>>Error:::", err1.Error()) + panic(err1) + } + xlsDownloadPath = append(xlsDownloadPath, tmpDownloadPath) + xlsFileName = append(xlsFileName, tmpFileName) } - if _, err1 = io.Copy(w, f); err != nil { - logx.Error(err1) - println("<<<>>>>Error:::", err1.Error()) - panic(err1) - } - if err1 != nil { - logx.Error(err1) - println("<<<>>>>Error:::", err1.Error()) - panic(err1) - } - f.Close() - os.RemoveAll(v) //TODO::移除源文件 - } + archive, err := os.Create("./static" + downloadPath) //第一步,创建 zip 文件 + if err != nil { + logx.Error(err) + println("<<<>>>>Error:::", err.Error()) + panic(err) + } + defer archive.Close() + + zipWriter := zip.NewWriter(archive) //第二步,创建一个新的 *Writer 对象 + for k, v := range xlsDownloadPath { + w, err1 := zipWriter.Create("学校预定统计/" + xlsFileName[k]) //向 zip 文件中添加一个文件,返回一个待压缩的文件内容应写入的 Writer + if err1 != nil { + logx.Error(err1) + println("<<<>>>>Error:::", err1.Error()) + panic(err1) + } - zipWriter.Close() // 第四步,关闭 zip writer,将所有数据写入指向基础 zip 文件的数据流 - if err != nil { - panic(err) - } - break - case 4: - //班级明细表 - fileName = "班级明细表_" + utils.Int64ToStr(now.UnixMilli()) + ".zip" - downloadPath = "/export/central_kitchen_for_school/" + fileName - var m []*db.CentralKitchenForSchoolPackageOrdForReserveWithUserIdentity - sess := db.Db.Desc("central_kitchen_for_school_package_ord_for_reserve.id") - if req.EnterpriseId != 0 { - sess.And("central_kitchen_for_school_package_ord_for_reserve.enterprise_id =?", req.EnterpriseId) - } - if req.StartDate != "" { - sess.And("central_kitchen_for_school_package_ord_for_reserve.meal_time_start >= ?", req.StartDate) - } - if req.EndDate != "" { - sess.And("central_kitchen_for_school_package_ord_for_reserve.meal_time_start <= ?", req.EndDate) - } - if len(req.MealKindList) > 0 { - sess.In("central_kitchen_for_school_package_ord_for_reserve.kind", req.MealKindList) - } - _, err := sess. - Join("LEFT", "central_kitchen_for_school_package_ord", "central_kitchen_for_school_package_ord_for_reserve.out_trade_no = central_kitchen_for_school_package_ord.out_trade_no"). - Join("LEFT", "user_identity", "central_kitchen_for_school_package_ord.user_identity_id = user_identity.id"). - Join("LEFT", "enterprise", "enterprise.id = user_identity.enterprise_id"). - Join("LEFT", "user", "user.id = user_identity.uid"). - Join("LEFT", "class_with_user", "class_with_user.user_identity_id = user_identity.id"). - Join("LEFT", "class", "class_with_user.class_id = class.id"). - Join("LEFT", "grade", "class.grade_id = grade.id"). - FindAndCount(&m) - if err != nil { - logx.Error(err) - println("<<<>>>>Error:::", err.Error()) - return - } + f, err1 := os.Open(v) //打开待压缩的文件 + if err1 != nil { + logx.Error(err1) + println("<<<>>>>Error:::", err1.Error()) + panic(err1) + } - var list = map[string]map[string]map[string]map[string]map[string]int64{} - var xlsFileName, xlsDownloadPath []string - centralKitchenForSchoolUserWithDayDb := db.CentralKitchenForSchoolUserWithDayDb{} - centralKitchenForSchoolUserWithDayDb.Set(0) - for _, v := range m { - if list[v.Enterprise.Name] == nil { - list[v.Enterprise.Name] = make(map[string]map[string]map[string]map[string]int64) - } - if list[v.Enterprise.Name][v.Grade.Name] == nil { - list[v.Enterprise.Name][v.Grade.Name] = make(map[string]map[string]map[string]int64) - } - if list[v.Enterprise.Name][v.Grade.Name][v.Class.Name] == nil { - list[v.Enterprise.Name][v.Grade.Name][v.Class.Name] = make(map[string]map[string]int64) - } - if list[v.Enterprise.Name][v.Grade.Name][v.Class.Name][v.UserIdentity.Name] == nil { - list[v.Enterprise.Name][v.Grade.Name][v.Class.Name][v.UserIdentity.Name] = make(map[string]int64) + if _, err1 = io.Copy(w, f); err != nil { + logx.Error(err1) + println("<<<>>>>Error:::", err1.Error()) + panic(err1) + } + if err1 != nil { + logx.Error(err1) + println("<<<>>>>Error:::", err1.Error()) + panic(err1) + } + f.Close() + os.RemoveAll(v) //TODO::移除源文件 } - count, err2 := centralKitchenForSchoolUserWithDayDb.CountCentralKitchenForSchoolUserWithDayByOrdNo(v.CentralKitchenForSchoolPackageOrdForReserve.OutTradeNo, enum.CentralKitchenForSchoolUserWithDayStateForCancel) - if err2 != nil { + zipWriter.Close() // 第四步,关闭 zip writer,将所有数据写入指向基础 zip 文件的数据流 + if err != nil { + panic(err) + } + break + case 4: + //班级明细表 + fileName = "班级明细表_" + utils.Int64ToStr(now.UnixMilli()) + ".zip" + downloadPath = "/export/central_kitchen_for_school/" + fileName + var m []*db.CentralKitchenForSchoolPackageOrdForReserveWithUserIdentity + sess := db.Db.Desc("central_kitchen_for_school_package_ord_for_reserve.id") + if req.EnterpriseId != 0 { + sess.And("central_kitchen_for_school_package_ord_for_reserve.enterprise_id =?", req.EnterpriseId) + } + if req.StartDate != "" { + sess.And("central_kitchen_for_school_package_ord_for_reserve.meal_time_start >= ?", req.StartDate) + } + if req.EndDate != "" { + sess.And("central_kitchen_for_school_package_ord_for_reserve.meal_time_start <= ?", req.EndDate) + } + if len(req.MealKindList) > 0 { + sess.In("central_kitchen_for_school_package_ord_for_reserve.kind", req.MealKindList) + } + _, err := sess. + Join("LEFT", "central_kitchen_for_school_package_ord", "central_kitchen_for_school_package_ord_for_reserve.out_trade_no = central_kitchen_for_school_package_ord.out_trade_no"). + Join("LEFT", "user_identity", "central_kitchen_for_school_package_ord.user_identity_id = user_identity.id"). + Join("LEFT", "enterprise", "enterprise.id = user_identity.enterprise_id"). + Join("LEFT", "user", "user.id = user_identity.uid"). + Join("LEFT", "class_with_user", "class_with_user.user_identity_id = user_identity.id"). + Join("LEFT", "class", "class_with_user.class_id = class.id"). + Join("LEFT", "grade", "class.grade_id = grade.id"). + FindAndCount(&m) + if err != nil { logx.Error(err) - println("<<<>>>>Error:::", err.Error()) + println("<<<>>>>Error:::", err.Error()) return } - time.Sleep(50 * time.Millisecond) // 50毫秒 - if v.CentralKitchenForSchoolPackageOrdForReserve.Kind == enum.CentralKitchenForSchoolUserWithDayKindForBreakfast { - list[v.Enterprise.Name][v.Grade.Name][v.Class.Name][v.UserIdentity.Name]["breakfast"] += count - } - if v.CentralKitchenForSchoolPackageOrdForReserve.Kind == enum.CentralKitchenForSchoolUserWithDayKindForLunch { - list[v.Enterprise.Name][v.Grade.Name][v.Class.Name][v.UserIdentity.Name]["lunch"] += count - } - if v.CentralKitchenForSchoolPackageOrdForReserve.Kind == enum.CentralKitchenForSchoolUserWithDayKindForDinner { - list[v.Enterprise.Name][v.Grade.Name][v.Class.Name][v.UserIdentity.Name]["dinner"] += count - } - } + var list = map[string]map[string]map[string]map[string]map[string]int64{} + var xlsFileName, xlsDownloadPath []string + centralKitchenForSchoolUserWithDayDb := db.CentralKitchenForSchoolUserWithDayDb{} + centralKitchenForSchoolUserWithDayDb.Set(0) + for _, v := range m { + if list[v.Enterprise.Name] == nil { + list[v.Enterprise.Name] = make(map[string]map[string]map[string]map[string]int64) + } + if list[v.Enterprise.Name][v.Grade.Name] == nil { + list[v.Enterprise.Name][v.Grade.Name] = make(map[string]map[string]map[string]int64) + } + if list[v.Enterprise.Name][v.Grade.Name][v.Class.Name] == nil { + list[v.Enterprise.Name][v.Grade.Name][v.Class.Name] = make(map[string]map[string]int64) + } + if list[v.Enterprise.Name][v.Grade.Name][v.Class.Name][v.UserIdentity.Name] == nil { + list[v.Enterprise.Name][v.Grade.Name][v.Class.Name][v.UserIdentity.Name] = make(map[string]int64) + } - for k1, v1 := range list { - tmpFileName := k1 + "班级明细_" + utils.Int64ToStr(now.UnixMilli()) + ".xlsx" - tmpDownloadPath := "./static/export/central_kitchen_for_school/" + tmpFileName - for k2, v2 := range v1 { - if k2 == "" { - //若年级为空,则为教师餐 - continue + count, err2 := centralKitchenForSchoolUserWithDayDb.CountCentralKitchenForSchoolUserWithDayByOrdNo(v.CentralKitchenForSchoolPackageOrdForReserve.OutTradeNo, enum.CentralKitchenForSchoolUserWithDayStateForCancel) + if err2 != nil { + logx.Error(err) + println("<<<>>>>Error:::", err.Error()) + return } + time.Sleep(50 * time.Millisecond) // 50毫秒 - for k3, v3 := range v2 { - titleList = []string{"姓名", "早餐", "午餐", "晚餐"} - xlsx.NewSheet(k3) - xlsx.SetSheetRow(k3, "A1", &titleList) - j := 2 //表头被第一行用了,只能从第二行开始 - for k4, v4 := range v3 { - xlsx.SetSheetRow(k3, "A"+strconv.Itoa(j), &[]interface{}{ - k4, v4["breakfast"], v4["lunch"], v4["dinner"]}) - j++ - } + if v.CentralKitchenForSchoolPackageOrdForReserve.Kind == enum.CentralKitchenForSchoolUserWithDayKindForBreakfast { + list[v.Enterprise.Name][v.Grade.Name][v.Class.Name][v.UserIdentity.Name]["breakfast"] += count + } + if v.CentralKitchenForSchoolPackageOrdForReserve.Kind == enum.CentralKitchenForSchoolUserWithDayKindForLunch { + list[v.Enterprise.Name][v.Grade.Name][v.Class.Name][v.UserIdentity.Name]["lunch"] += count + } + if v.CentralKitchenForSchoolPackageOrdForReserve.Kind == enum.CentralKitchenForSchoolUserWithDayKindForDinner { + list[v.Enterprise.Name][v.Grade.Name][v.Class.Name][v.UserIdentity.Name]["dinner"] += count } } - //将文件保存至服务器 - xlsx.DeleteSheet("Sheet1") //TODO::只能放这里删除 - err1 := xlsx.SaveAs(tmpDownloadPath) - if err1 != nil { - logx.Error(err1) - println("<<<>>>>Error:::", err1.Error()) - panic(err1) - } - xlsDownloadPath = append(xlsDownloadPath, tmpDownloadPath) - xlsFileName = append(xlsFileName, tmpFileName) - } - - archive, err := os.Create("./static" + downloadPath) //第一步,创建 zip 文件 - if err != nil { - logx.Error(err) - println("<<<>>>>Error:::", err.Error()) - panic(err) - } - defer archive.Close() + for k1, v1 := range list { + tmpFileName := k1 + "班级明细_" + utils.Int64ToStr(now.UnixMilli()) + ".xlsx" + tmpDownloadPath := "./static/export/central_kitchen_for_school/" + tmpFileName + for k2, v2 := range v1 { + if k2 == "" { + //若年级为空,则为教师餐 + continue + } - zipWriter := zip.NewWriter(archive) //第二步,创建一个新的 *Writer 对象 - for k, v := range xlsDownloadPath { - w, err1 := zipWriter.Create("班级明细/" + xlsFileName[k]) //向 zip 文件中添加一个文件,返回一个待压缩的文件内容应写入的 Writer - if err1 != nil { - logx.Error(err1) - println("<<<>>>>Error:::", err1.Error()) - panic(err1) - } + for k3, v3 := range v2 { + titleList = []string{"姓名", "早餐", "午餐", "晚餐"} + xlsx.NewSheet(k3) + xlsx.SetSheetRow(k3, "A1", &titleList) + j := 2 //表头被第一行用了,只能从第二行开始 + for k4, v4 := range v3 { + xlsx.SetSheetRow(k3, "A"+strconv.Itoa(j), &[]interface{}{ + k4, v4["breakfast"], v4["lunch"], v4["dinner"]}) + j++ + } + } + } - f, err1 := os.Open(v) //打开待压缩的文件 - if err1 != nil { - logx.Error(err1) - println("<<<>>>>Error:::", err1.Error()) - panic(err1) + //将文件保存至服务器 + xlsx.DeleteSheet("Sheet1") //TODO::只能放这里删除 + err1 := xlsx.SaveAs(tmpDownloadPath) + if err1 != nil { + logx.Error(err1) + println("<<<>>>>Error:::", err1.Error()) + panic(err1) + } + xlsDownloadPath = append(xlsDownloadPath, tmpDownloadPath) + xlsFileName = append(xlsFileName, tmpFileName) } - if _, err1 = io.Copy(w, f); err != nil { - logx.Error(err1) - println("<<<>>>>Error:::", err1.Error()) - panic(err1) - } - if err1 != nil { - logx.Error(err1) - println("<<<>>>>Error:::", err1.Error()) - panic(err1) - } - f.Close() - os.RemoveAll(v) //TODO::移除源文件 - } + archive, err := os.Create("./static" + downloadPath) //第一步,创建 zip 文件 + if err != nil { + logx.Error(err) + println("<<<>>>>Error:::", err.Error()) + panic(err) + } + defer archive.Close() + + zipWriter := zip.NewWriter(archive) //第二步,创建一个新的 *Writer 对象 + for k, v := range xlsDownloadPath { + w, err1 := zipWriter.Create("班级明细/" + xlsFileName[k]) //向 zip 文件中添加一个文件,返回一个待压缩的文件内容应写入的 Writer + if err1 != nil { + logx.Error(err1) + println("<<<>>>>Error:::", err1.Error()) + panic(err1) + } - zipWriter.Close() // 第四步,关闭 zip writer,将所有数据写入指向基础 zip 文件的数据流 - if err != nil { - panic(err) - } - break - case 5: - //退款明细表 - fileName = "退款明细表_" + utils.Int64ToStr(now.UnixMilli()) + ".zip" - downloadPath = "/export/central_kitchen_for_school/" + fileName - sess := db.Db.Where("central_kitchen_for_school_user_refund_day.state =?", enum.CentralKitchenForSchoolUserRefundDayStateForAuditComplete).Desc("central_kitchen_for_school_user_refund_day.id") - if req.EnterpriseId != 0 { - sess.And("enterprise.id =?", req.EnterpriseId) - } - if req.StartDate != "" { - sess.And("central_kitchen_for_school_user_refund_day.create_at >= ?", req.StartDate) - } - if req.EndDate != "" { - sess.And("central_kitchen_for_school_user_refund_day.create_at <= ?", req.EndDate) - } - if len(req.MealKindList) > 0 { - sess.In("central_kitchen_for_school_user_with_day.kind", req.MealKindList) - } - var m []*db.CentralKitchenForSchoolUserRefundDayWithData - _, err := sess. - Join("LEFT", "central_kitchen_for_school_user_with_day", "central_kitchen_for_school_user_refund_day.records_id = central_kitchen_for_school_user_with_day.id"). - Join("LEFT", "central_kitchen_for_school_package_ord", "central_kitchen_for_school_user_refund_day.out_trade_no = central_kitchen_for_school_package_ord.out_trade_no"). - Join("LEFT", "user_identity", "central_kitchen_for_school_user_with_day.identity_id = user_identity.id"). - Join("LEFT", "user", "user_identity.uid = user.id"). - Join("LEFT", "enterprise", "user_identity.enterprise_id = enterprise.id"). - Join("LEFT", "class_with_user", "user_identity.id = class_with_user.user_identity_id"). - Join("LEFT", "class", "class_with_user.class_id = class.id"). - Join("LEFT", "grade", "class.grade_id = grade.id"). - Desc("central_kitchen_for_school_user_refund_day.id"). - FindAndCount(&m) - if err != nil { - logx.Error(err) - println("<<<>>>>Error:::", err.Error()) - return - } + f, err1 := os.Open(v) //打开待压缩的文件 + if err1 != nil { + logx.Error(err1) + println("<<<>>>>Error:::", err1.Error()) + panic(err1) + } - var list = map[string]map[string]map[string]map[string]map[string]int{} - var xlsFileName, xlsDownloadPath []string - for _, v := range m { - if list[v.Enterprise.Name] == nil { - list[v.Enterprise.Name] = make(map[string]map[string]map[string]map[string]int) - } - if list[v.Enterprise.Name][v.Grade.Name] == nil { - list[v.Enterprise.Name][v.Grade.Name] = make(map[string]map[string]map[string]int) - } - if list[v.Enterprise.Name][v.Grade.Name][v.Class.Name] == nil { - list[v.Enterprise.Name][v.Grade.Name][v.Class.Name] = make(map[string]map[string]int) - } - if list[v.Enterprise.Name][v.Grade.Name][v.Class.Name][v.UserIdentity.Name] == nil { - list[v.Enterprise.Name][v.Grade.Name][v.Class.Name][v.UserIdentity.Name] = make(map[string]int) + if _, err1 = io.Copy(w, f); err != nil { + logx.Error(err1) + println("<<<>>>>Error:::", err1.Error()) + panic(err1) + } + if err1 != nil { + logx.Error(err1) + println("<<<>>>>Error:::", err1.Error()) + panic(err1) + } + f.Close() + os.RemoveAll(v) //TODO::移除源文件 } - //就餐类型(1:早餐 2:午餐 3:晚餐) - if v.CentralKitchenForSchoolUserWithDay.Kind == enum.CentralKitchenForSchoolUserWithDayKindForBreakfast { - list[v.Enterprise.Name][v.Grade.Name][v.Class.Name][v.UserIdentity.Name]["breakfast"]++ - } - if v.CentralKitchenForSchoolUserWithDay.Kind == enum.CentralKitchenForSchoolUserWithDayKindForLunch { - list[v.Enterprise.Name][v.Grade.Name][v.Class.Name][v.UserIdentity.Name]["lunch"]++ - } - if v.CentralKitchenForSchoolUserWithDay.Kind == enum.CentralKitchenForSchoolUserWithDayKindForDinner { - list[v.Enterprise.Name][v.Grade.Name][v.Class.Name][v.UserIdentity.Name]["dinner"]++ + zipWriter.Close() // 第四步,关闭 zip writer,将所有数据写入指向基础 zip 文件的数据流 + if err != nil { + panic(err) + } + break + case 5: + //退款明细表 + fileName = "退款明细表_" + utils.Int64ToStr(now.UnixMilli()) + ".zip" + downloadPath = "/export/central_kitchen_for_school/" + fileName + sess := db.Db.Where("central_kitchen_for_school_user_refund_day.state =?", enum.CentralKitchenForSchoolUserRefundDayStateForAuditComplete).Desc("central_kitchen_for_school_user_refund_day.id") + if req.EnterpriseId != 0 { + sess.And("enterprise.id =?", req.EnterpriseId) + } + if req.StartDate != "" { + sess.And("central_kitchen_for_school_user_refund_day.create_at >= ?", req.StartDate) + } + if req.EndDate != "" { + sess.And("central_kitchen_for_school_user_refund_day.create_at <= ?", req.EndDate) + } + if len(req.MealKindList) > 0 { + sess.In("central_kitchen_for_school_user_with_day.kind", req.MealKindList) + } + var m []*db.CentralKitchenForSchoolUserRefundDayWithData + _, err := sess. + Join("LEFT", "central_kitchen_for_school_user_with_day", "central_kitchen_for_school_user_refund_day.records_id = central_kitchen_for_school_user_with_day.id"). + Join("LEFT", "central_kitchen_for_school_package_ord", "central_kitchen_for_school_user_refund_day.out_trade_no = central_kitchen_for_school_package_ord.out_trade_no"). + Join("LEFT", "user_identity", "central_kitchen_for_school_user_with_day.identity_id = user_identity.id"). + Join("LEFT", "user", "user_identity.uid = user.id"). + Join("LEFT", "enterprise", "user_identity.enterprise_id = enterprise.id"). + Join("LEFT", "class_with_user", "user_identity.id = class_with_user.user_identity_id"). + Join("LEFT", "class", "class_with_user.class_id = class.id"). + Join("LEFT", "grade", "class.grade_id = grade.id"). + Desc("central_kitchen_for_school_user_refund_day.id"). + FindAndCount(&m) + if err != nil { + logx.Error(err) + println("<<<>>>>Error:::", err.Error()) + return } - } - for k1, v1 := range list { - tmpFileName := k1 + "退款明细_" + utils.Int64ToStr(now.UnixMilli()) + ".xlsx" - tmpDownloadPath := "./static/export/central_kitchen_for_school/" + tmpFileName - for k2, v2 := range v1 { - if k2 == "" { - //若年级为空,则为教师餐 - continue + var list = map[string]map[string]map[string]map[string]map[string]int{} + var xlsFileName, xlsDownloadPath []string + for _, v := range m { + if list[v.Enterprise.Name] == nil { + list[v.Enterprise.Name] = make(map[string]map[string]map[string]map[string]int) + } + if list[v.Enterprise.Name][v.Grade.Name] == nil { + list[v.Enterprise.Name][v.Grade.Name] = make(map[string]map[string]map[string]int) + } + if list[v.Enterprise.Name][v.Grade.Name][v.Class.Name] == nil { + list[v.Enterprise.Name][v.Grade.Name][v.Class.Name] = make(map[string]map[string]int) + } + if list[v.Enterprise.Name][v.Grade.Name][v.Class.Name][v.UserIdentity.Name] == nil { + list[v.Enterprise.Name][v.Grade.Name][v.Class.Name][v.UserIdentity.Name] = make(map[string]int) } - for k3, v3 := range v2 { - titleList = []string{"姓名", "早餐", "午餐", "晚餐"} - xlsx.NewSheet(k3) - xlsx.SetSheetRow(k3, "A1", &titleList) - j := 2 //表头被第一行用了,只能从第二行开始 - for k4, v4 := range v3 { - xlsx.SetSheetRow(k3, "A"+strconv.Itoa(j), &[]interface{}{ - k4, v4["breakfast"], v4["lunch"], v4["dinner"]}) - j++ - } + //就餐类型(1:早餐 2:午餐 3:晚餐) + if v.CentralKitchenForSchoolUserWithDay.Kind == enum.CentralKitchenForSchoolUserWithDayKindForBreakfast { + list[v.Enterprise.Name][v.Grade.Name][v.Class.Name][v.UserIdentity.Name]["breakfast"]++ + } + if v.CentralKitchenForSchoolUserWithDay.Kind == enum.CentralKitchenForSchoolUserWithDayKindForLunch { + list[v.Enterprise.Name][v.Grade.Name][v.Class.Name][v.UserIdentity.Name]["lunch"]++ + } + if v.CentralKitchenForSchoolUserWithDay.Kind == enum.CentralKitchenForSchoolUserWithDayKindForDinner { + list[v.Enterprise.Name][v.Grade.Name][v.Class.Name][v.UserIdentity.Name]["dinner"]++ } } - //将文件保存至服务器 - xlsx.DeleteSheet("Sheet1") //TODO::只能放这里删除 - err1 := xlsx.SaveAs(tmpDownloadPath) - if err1 != nil { - logx.Error(err1) - println("<<<>>>>Error:::", err1.Error()) - panic(err1) - } - xlsDownloadPath = append(xlsDownloadPath, tmpDownloadPath) - xlsFileName = append(xlsFileName, tmpFileName) - } + for k1, v1 := range list { + tmpFileName := k1 + "退款明细_" + utils.Int64ToStr(now.UnixMilli()) + ".xlsx" + tmpDownloadPath := "./static/export/central_kitchen_for_school/" + tmpFileName + for k2, v2 := range v1 { + if k2 == "" { + //若年级为空,则为教师餐 + continue + } - archive, err := os.Create("./static" + downloadPath) //第一步,创建 zip 文件 - if err != nil { - logx.Error(err) - println("<<<>>>>Error:::", err.Error()) - panic(err) - } - defer archive.Close() + for k3, v3 := range v2 { + titleList = []string{"姓名", "早餐", "午餐", "晚餐"} + xlsx.NewSheet(k3) + xlsx.SetSheetRow(k3, "A1", &titleList) + j := 2 //表头被第一行用了,只能从第二行开始 + for k4, v4 := range v3 { + xlsx.SetSheetRow(k3, "A"+strconv.Itoa(j), &[]interface{}{ + k4, v4["breakfast"], v4["lunch"], v4["dinner"]}) + j++ + } + } + } - zipWriter := zip.NewWriter(archive) //第二步,创建一个新的 *Writer 对象 - for k, v := range xlsDownloadPath { - w, err1 := zipWriter.Create("退款明细/" + xlsFileName[k]) //向 zip 文件中添加一个文件,返回一个待压缩的文件内容应写入的 Writer - if err1 != nil { - logx.Error(err1) - println("<<<>>>>Error:::", err1.Error()) - panic(err1) + //将文件保存至服务器 + xlsx.DeleteSheet("Sheet1") //TODO::只能放这里删除 + err1 := xlsx.SaveAs(tmpDownloadPath) + if err1 != nil { + logx.Error(err1) + println("<<<>>>>Error:::", err1.Error()) + panic(err1) + } + xlsDownloadPath = append(xlsDownloadPath, tmpDownloadPath) + xlsFileName = append(xlsFileName, tmpFileName) } - f, err1 := os.Open(v) //打开待压缩的文件 - if err1 != nil { - logx.Error(err1) - println("<<<>>>>Error:::", err1.Error()) - panic(err1) - } + archive, err := os.Create("./static" + downloadPath) //第一步,创建 zip 文件 + if err != nil { + logx.Error(err) + println("<<<>>>>Error:::", err.Error()) + panic(err) + } + defer archive.Close() + + zipWriter := zip.NewWriter(archive) //第二步,创建一个新的 *Writer 对象 + for k, v := range xlsDownloadPath { + w, err1 := zipWriter.Create("退款明细/" + xlsFileName[k]) //向 zip 文件中添加一个文件,返回一个待压缩的文件内容应写入的 Writer + if err1 != nil { + logx.Error(err1) + println("<<<>>>>Error:::", err1.Error()) + panic(err1) + } - if _, err1 = io.Copy(w, f); err != nil { - logx.Error(err1) - println("<<<>>>>Error:::", err1.Error()) - panic(err1) - } - if err1 != nil { - logx.Error(err1) - println("<<<>>>>Error:::", err1.Error()) - panic(err1) - } - f.Close() - os.RemoveAll(v) //TODO::移除源文件 - } + f, err1 := os.Open(v) //打开待压缩的文件 + if err1 != nil { + logx.Error(err1) + println("<<<>>>>Error:::", err1.Error()) + panic(err1) + } - zipWriter.Close() // 第四步,关闭 zip writer,将所有数据写入指向基础 zip 文件的数据流 - if err != nil { - panic(err) - } - break - case 6: - //收款统计表 - fileName = "收款统计表_" + utils.Int64ToStr(now.UnixMilli()) + ".xlsx" - downloadPath = "/export/central_kitchen_for_school/" + fileName - //查找数据 - var m []model.Enterprise - sess := db.Db.Desc("id") - if req.EnterpriseId != 0 { - sess.And("id = ?", req.EnterpriseId) - } - err := sess.Find(&m) - if err != nil { - logx.Error(err) - println("<<<>>>>Error:::", err.Error()) - return - } + if _, err1 = io.Copy(w, f); err != nil { + logx.Error(err1) + println("<<<>>>>Error:::", err1.Error()) + panic(err1) + } + if err1 != nil { + logx.Error(err1) + println("<<<>>>>Error:::", err1.Error()) + panic(err1) + } + f.Close() + os.RemoveAll(v) //TODO::移除源文件 + } - titleList = []string{"学校名称", "预定总费用", "退款总计", "实收费用", "预估费率"} - xlsx.SetSheetRow("Sheet1", "A1", &titleList) - j := 2 //表头被第一行用了,只能从第二行开始 - for _, v := range m { - var income, refund string - //统计收入 - sql1 := fmt.Sprintf("SELECT sum(total_price) as total FROM central_kitchen_for_school_package_ord where state = 1 and enterprise_id = %d and create_at >= '%s' and create_at < '%s'", v.Id, req.StartDate, req.EndDate) - mapArr1, err := db.QueryNativeString(db.Db, sql1) + zipWriter.Close() // 第四步,关闭 zip writer,将所有数据写入指向基础 zip 文件的数据流 + if err != nil { + panic(err) + } + break + case 6: + //收款统计表 + fileName = "收款统计表_" + utils.Int64ToStr(now.UnixMilli()) + ".xlsx" + downloadPath = "/export/central_kitchen_for_school/" + fileName + //查找数据 + var m []model.Enterprise + sess := db.Db.Desc("id") + if req.EnterpriseId != 0 { + sess.And("id = ?", req.EnterpriseId) + } + err := sess.Find(&m) if err != nil { logx.Error(err) println("<<<>>>>Error:::", err.Error()) return } - if mapArr1 != nil { - income = mapArr1[0]["total"] - } - //统计退款 - //查询出当前学校下所有的学生 - userIdentityDb := db.UserIdentityDb{} - userIdentityDb.Set(0) - userIdentities, _ := userIdentityDb.FindUserIdentityForEnterprise(v.Id) - var userIdentityIds []string - for _, v := range *userIdentities { - userIdentityIds = append(userIdentityIds, utils.IntToStr(v.Id)) - } - if len(userIdentityIds) != 0 { - userIdentityStr := php2go.Implode(",", userIdentityIds) - sql2 := fmt.Sprintf("SELECT sum(amount) as total FROM central_kitchen_for_school_user_refund_day where state = %d and identity_id IN (%s) and refund_date >= '%s' and refund_date < '%s'", - enum.CentralKitchenForSchoolUserRefundDayStateForAuditComplete, userIdentityStr, req.StartDate, req.EndDate) - mapArr2, err := db.QueryNativeString(db.Db, sql2) + titleList = []string{"学校名称", "预定总费用", "退款总计", "实收费用", "预估费率"} + xlsx.SetSheetRow("Sheet1", "A1", &titleList) + j := 2 //表头被第一行用了,只能从第二行开始 + for _, v := range m { + var income, refund string + //统计收入 + sql1 := fmt.Sprintf("SELECT sum(total_price) as total FROM central_kitchen_for_school_package_ord where state = 1 and enterprise_id = %d and create_at >= '%s' and create_at < '%s'", v.Id, req.StartDate, req.EndDate) + mapArr1, err := db.QueryNativeString(db.Db, sql1) if err != nil { logx.Error(err) println("<<<>>>>Error:::", err.Error()) return } - if mapArr2 != nil { - refund = mapArr2[0]["total"] + if mapArr1 != nil { + income = mapArr1[0]["total"] } - } - realityAmount := utils.StrToFloat64(income) - utils.StrToFloat64(refund) - rateFee := realityAmount * 0.0038 - xlsx.SetSheetRow("Sheet1", "A"+strconv.Itoa(j), &[]interface{}{v.Name, income, refund, realityAmount, rateFee}) - j++ - } - //将文件保存至服务器 - xlsx.SaveAs("./static" + downloadPath) - break - case 7: - //班级收款明细表 - fileName = "班级收款明细表_" + utils.Int64ToStr(now.UnixMilli()) + ".zip" - downloadPath = "/export/central_kitchen_for_school/" + fileName - //查找订单数据 - sess := db.Db.Desc("central_kitchen_for_school_package_ord.id") - sess.And("central_kitchen_for_school_package_ord.state =?", enum.CentralKitchenForSchoolPackageOrdStateForSuccess) - if req.EnterpriseId != 0 { - sess.And("central_kitchen_for_school_package_ord.enterprise_id =?", req.EnterpriseId) - } - if req.StartDate != "" { - sess.And("central_kitchen_for_school_package_ord.create_at >= ?", req.StartDate) - } - if req.EndDate != "" { - sess.And("central_kitchen_for_school_package_ord.create_at <= ?", req.EndDate) - } - var m []*db.CentralKitchenForSchoolPackageOrdWithUserIdentity - _, err := sess. - Join("LEFT", "user_identity", "central_kitchen_for_school_package_ord.user_identity_id = user_identity.id"). - Join("LEFT", "enterprise", "enterprise.id = user_identity.enterprise_id"). - Join("LEFT", "user", "user.id = user_identity.uid"). - Join("LEFT", "class_with_user", "class_with_user.user_identity_id = user_identity.id"). - Join("LEFT", "class", "class_with_user.class_id = class.id"). - Join("LEFT", "grade", "class.grade_id = grade.id"). - FindAndCount(&m) - if err != nil { - logx.Error(err) - println("<<<>>>>Error:::", err.Error()) - return - } - sess1 := db.Db.Where("central_kitchen_for_school_user_refund_day.state =?", enum.CentralKitchenForSchoolUserRefundDayStateForAuditComplete).Desc("central_kitchen_for_school_user_refund_day.id") - if req.EnterpriseId != 0 { - sess1.And("enterprise.id =?", req.EnterpriseId) - } - if req.StartDate != "" { - sess1.And("central_kitchen_for_school_user_refund_day.create_at >= ?", req.StartDate) - } - if req.EndDate != "" { - sess1.And("central_kitchen_for_school_user_refund_day.create_at <= ?", req.EndDate) - } - - var mm []*db.CentralKitchenForSchoolUserRefundDayWithData - _, err = sess1. - Join("LEFT", "central_kitchen_for_school_user_with_day", "central_kitchen_for_school_user_refund_day.records_id = central_kitchen_for_school_user_with_day.id"). - Join("LEFT", "central_kitchen_for_school_package_ord", "central_kitchen_for_school_user_refund_day.out_trade_no = central_kitchen_for_school_package_ord.out_trade_no"). - Join("LEFT", "user_identity", "central_kitchen_for_school_user_with_day.identity_id = user_identity.id"). - Join("LEFT", "user", "user_identity.uid = user.id"). - Join("LEFT", "enterprise", "user_identity.enterprise_id = enterprise.id"). - Join("LEFT", "class_with_user", "user_identity.id = class_with_user.user_identity_id"). - Join("LEFT", "class", "class_with_user.class_id = class.id"). - Join("LEFT", "grade", "class.grade_id = grade.id"). - Desc("central_kitchen_for_school_user_refund_day.id"). - FindAndCount(&mm) - if err != nil { - logx.Error(err) - println("<<<>>>>Error:::", err.Error()) - return - } + //统计退款 + //查询出当前学校下所有的学生 + userIdentityDb := db.UserIdentityDb{} + userIdentityDb.Set(0) + userIdentities, _ := userIdentityDb.FindUserIdentityForEnterprise(v.Id) + var userIdentityIds []string + for _, v := range *userIdentities { + userIdentityIds = append(userIdentityIds, utils.IntToStr(v.Id)) + } + if len(userIdentityIds) != 0 { + userIdentityStr := php2go.Implode(",", userIdentityIds) + sql2 := fmt.Sprintf("SELECT sum(amount) as total FROM central_kitchen_for_school_user_refund_day where state = %d and identity_id IN (%s) and refund_date >= '%s' and refund_date < '%s'", + enum.CentralKitchenForSchoolUserRefundDayStateForAuditComplete, userIdentityStr, req.StartDate, req.EndDate) + mapArr2, err := db.QueryNativeString(db.Db, sql2) + if err != nil { + logx.Error(err) + println("<<<>>>>Error:::", err.Error()) + return + } + if mapArr2 != nil { + refund = mapArr2[0]["total"] + } + } + realityAmount := utils.StrToFloat64(income) - utils.StrToFloat64(refund) + rateFee := realityAmount * 0.0038 + xlsx.SetSheetRow("Sheet1", "A"+strconv.Itoa(j), &[]interface{}{v.Name, income, refund, realityAmount, rateFee}) + j++ + } + //将文件保存至服务器 + xlsx.SaveAs("./static" + downloadPath) + break + case 7: + //班级收款明细表 + fileName = "班级收款明细表_" + utils.Int64ToStr(now.UnixMilli()) + ".zip" + downloadPath = "/export/central_kitchen_for_school/" + fileName + //查找订单数据 + sess := db.Db.Desc("central_kitchen_for_school_package_ord.id") + sess.And("central_kitchen_for_school_package_ord.state =?", enum.CentralKitchenForSchoolPackageOrdStateForSuccess) + if req.EnterpriseId != 0 { + sess.And("central_kitchen_for_school_package_ord.enterprise_id =?", req.EnterpriseId) + } + if req.StartDate != "" { + sess.And("central_kitchen_for_school_package_ord.create_at >= ?", req.StartDate) + } + if req.EndDate != "" { + sess.And("central_kitchen_for_school_package_ord.create_at <= ?", req.EndDate) + } + var m []*db.CentralKitchenForSchoolPackageOrdWithUserIdentity + _, err := sess. + Join("LEFT", "user_identity", "central_kitchen_for_school_package_ord.user_identity_id = user_identity.id"). + Join("LEFT", "enterprise", "enterprise.id = user_identity.enterprise_id"). + Join("LEFT", "user", "user.id = user_identity.uid"). + Join("LEFT", "class_with_user", "class_with_user.user_identity_id = user_identity.id"). + Join("LEFT", "class", "class_with_user.class_id = class.id"). + Join("LEFT", "grade", "class.grade_id = grade.id"). + FindAndCount(&m) + if err != nil { + logx.Error(err) + println("<<<>>>>Error:::", err.Error()) + return + } - var list = map[string]map[string]map[string]map[string]float64{} - for _, v := range m { - if list[v.Enterprise.Name] == nil { - list[v.Enterprise.Name] = make(map[string]map[string]map[string]float64) + sess1 := db.Db.Where("central_kitchen_for_school_user_refund_day.state =?", enum.CentralKitchenForSchoolUserRefundDayStateForAuditComplete).Desc("central_kitchen_for_school_user_refund_day.id") + if req.EnterpriseId != 0 { + sess1.And("enterprise.id =?", req.EnterpriseId) } - if list[v.Enterprise.Name][v.Grade.Name] == nil { - list[v.Enterprise.Name][v.Grade.Name] = make(map[string]map[string]float64) + if req.StartDate != "" { + sess1.And("central_kitchen_for_school_user_refund_day.create_at >= ?", req.StartDate) } - if list[v.Enterprise.Name][v.Grade.Name][v.Class.Name] == nil { - list[v.Enterprise.Name][v.Grade.Name][v.Class.Name] = make(map[string]float64) + if req.EndDate != "" { + sess1.And("central_kitchen_for_school_user_refund_day.create_at <= ?", req.EndDate) } - list[v.Enterprise.Name][v.Grade.Name][v.Class.Name]["income"] += utils.StrToFloat64(v.CentralKitchenForSchoolPackageOrd.TotalPrice) - } - for _, v := range mm { - if list[v.Enterprise.Name] == nil { - list[v.Enterprise.Name] = make(map[string]map[string]map[string]float64) - } - if list[v.Enterprise.Name][v.Grade.Name] == nil { - list[v.Enterprise.Name][v.Grade.Name] = make(map[string]map[string]float64) + var mm []*db.CentralKitchenForSchoolUserRefundDayWithData + _, err = sess1. + Join("LEFT", "central_kitchen_for_school_user_with_day", "central_kitchen_for_school_user_refund_day.records_id = central_kitchen_for_school_user_with_day.id"). + Join("LEFT", "central_kitchen_for_school_package_ord", "central_kitchen_for_school_user_refund_day.out_trade_no = central_kitchen_for_school_package_ord.out_trade_no"). + Join("LEFT", "user_identity", "central_kitchen_for_school_user_with_day.identity_id = user_identity.id"). + Join("LEFT", "user", "user_identity.uid = user.id"). + Join("LEFT", "enterprise", "user_identity.enterprise_id = enterprise.id"). + Join("LEFT", "class_with_user", "user_identity.id = class_with_user.user_identity_id"). + Join("LEFT", "class", "class_with_user.class_id = class.id"). + Join("LEFT", "grade", "class.grade_id = grade.id"). + Desc("central_kitchen_for_school_user_refund_day.id"). + FindAndCount(&mm) + if err != nil { + logx.Error(err) + println("<<<>>>>Error:::", err.Error()) + return } - if list[v.Enterprise.Name][v.Grade.Name][v.Class.Name] == nil { - list[v.Enterprise.Name][v.Grade.Name][v.Class.Name] = make(map[string]float64) + + var list = map[string]map[string]map[string]map[string]float64{} + for _, v := range m { + if list[v.Enterprise.Name] == nil { + list[v.Enterprise.Name] = make(map[string]map[string]map[string]float64) + } + if list[v.Enterprise.Name][v.Grade.Name] == nil { + list[v.Enterprise.Name][v.Grade.Name] = make(map[string]map[string]float64) + } + if list[v.Enterprise.Name][v.Grade.Name][v.Class.Name] == nil { + list[v.Enterprise.Name][v.Grade.Name][v.Class.Name] = make(map[string]float64) + } + + list[v.Enterprise.Name][v.Grade.Name][v.Class.Name]["income"] += utils.StrToFloat64(v.CentralKitchenForSchoolPackageOrd.TotalPrice) } + for _, v := range mm { + if list[v.Enterprise.Name] == nil { + list[v.Enterprise.Name] = make(map[string]map[string]map[string]float64) + } + if list[v.Enterprise.Name][v.Grade.Name] == nil { + list[v.Enterprise.Name][v.Grade.Name] = make(map[string]map[string]float64) + } + if list[v.Enterprise.Name][v.Grade.Name][v.Class.Name] == nil { + list[v.Enterprise.Name][v.Grade.Name][v.Class.Name] = make(map[string]float64) + } - list[v.Enterprise.Name][v.Grade.Name][v.Class.Name]["refund"] += utils.StrToFloat64(v.CentralKitchenForSchoolUserRefundDay.Amount) - } + list[v.Enterprise.Name][v.Grade.Name][v.Class.Name]["refund"] += utils.StrToFloat64(v.CentralKitchenForSchoolUserRefundDay.Amount) + } - var xlsFileName, xlsDownloadPath []string - for k1, v1 := range list { - tmpFileName := k1 + "班级收款明细_" + utils.Int64ToStr(now.UnixMilli()) + ".xlsx" - tmpDownloadPath := "./static/export/central_kitchen_for_school/" + tmpFileName - titleList = []string{"年级", "班级", "预定总费用", "退款总计"} - xlsx.SetSheetRow("Sheet1", "A1", &titleList) - j := 2 //表头被第一行用了,只能从第二行开始 - for k2, v2 := range v1 { - if k2 == "" { - //若年级为空,则为教师餐 - continue + var xlsFileName, xlsDownloadPath []string + for k1, v1 := range list { + tmpFileName := k1 + "班级收款明细_" + utils.Int64ToStr(now.UnixMilli()) + ".xlsx" + tmpDownloadPath := "./static/export/central_kitchen_for_school/" + tmpFileName + titleList = []string{"年级", "班级", "预定总费用", "退款总计"} + xlsx.SetSheetRow("Sheet1", "A1", &titleList) + j := 2 //表头被第一行用了,只能从第二行开始 + for k2, v2 := range v1 { + if k2 == "" { + //若年级为空,则为教师餐 + continue + } + for k3, v3 := range v2 { + xlsx.SetSheetRow("Sheet1", "A"+strconv.Itoa(j), &[]interface{}{k2, k3, utils.Float64ToStr(v3["income"]), utils.Float64ToStr(v3["refund"])}) + j++ + } } - for k3, v3 := range v2 { - xlsx.SetSheetRow("Sheet1", "A"+strconv.Itoa(j), &[]interface{}{k2, k3, utils.Float64ToStr(v3["income"]), utils.Float64ToStr(v3["refund"])}) - j++ + + //将文件保存至服务器 + err1 := xlsx.SaveAs(tmpDownloadPath) + if err1 != nil { + logx.Error(err1) + println("<<<>>>>Error:::", err1.Error()) + panic(err1) } + xlsDownloadPath = append(xlsDownloadPath, tmpDownloadPath) + xlsFileName = append(xlsFileName, tmpFileName) } - //将文件保存至服务器 - err1 := xlsx.SaveAs(tmpDownloadPath) - if err1 != nil { - logx.Error(err1) - println("<<<>>>>Error:::", err1.Error()) - panic(err1) - } - xlsDownloadPath = append(xlsDownloadPath, tmpDownloadPath) - xlsFileName = append(xlsFileName, tmpFileName) - } + archive, err := os.Create("./static" + downloadPath) //第一步,创建 zip 文件 + if err != nil { + logx.Error(err) + println("<<<>>>>Error:::", err.Error()) + panic(err) + } + defer archive.Close() + + zipWriter := zip.NewWriter(archive) //第二步,创建一个新的 *Writer 对象 + for k, v := range xlsDownloadPath { + w, err1 := zipWriter.Create("班级收款明细/" + xlsFileName[k]) //向 zip 文件中添加一个文件,返回一个待压缩的文件内容应写入的 Writer + if err1 != nil { + logx.Error(err1) + println("<<<>>>>Error:::", err1.Error()) + panic(err1) + } - archive, err := os.Create("./static" + downloadPath) //第一步,创建 zip 文件 - if err != nil { - logx.Error(err) - println("<<<>>>>Error:::", err.Error()) - panic(err) - } - defer archive.Close() + f, err1 := os.Open(v) //打开待压缩的文件 + if err1 != nil { + logx.Error(err1) + println("<<<>>>>Error:::", err1.Error()) + panic(err1) + } - zipWriter := zip.NewWriter(archive) //第二步,创建一个新的 *Writer 对象 - for k, v := range xlsDownloadPath { - w, err1 := zipWriter.Create("班级收款明细/" + xlsFileName[k]) //向 zip 文件中添加一个文件,返回一个待压缩的文件内容应写入的 Writer - if err1 != nil { - logx.Error(err1) - println("<<<>>>>Error:::", err1.Error()) - panic(err1) + if _, err1 = io.Copy(w, f); err != nil { + logx.Error(err1) + println("<<<>>>>Error:::", err1.Error()) + panic(err1) + } + if err1 != nil { + logx.Error(err1) + println("<<<>>>>Error:::", err1.Error()) + panic(err1) + } + f.Close() + os.RemoveAll(v) //TODO::移除源文件 } - f, err1 := os.Open(v) //打开待压缩的文件 - if err1 != nil { - logx.Error(err1) - println("<<<>>>>Error:::", err1.Error()) - panic(err1) + zipWriter.Close() // 第四步,关闭 zip writer,将所有数据写入指向基础 zip 文件的数据流 + if err != nil { + panic(err) } + break + case 8: + //学校预定数量统计表 + fileName = "学校预定数量统计表_" + utils.Int64ToStr(now.UnixMilli()) + ".xlsx" + downloadPath = "/export/central_kitchen_for_school/" + fileName - if _, err1 = io.Copy(w, f); err != nil { - logx.Error(err1) - println("<<<>>>>Error:::", err1.Error()) - panic(err1) + var m []*db.CentralKitchenForSchoolPackageOrdForReserveWithUserIdentity + sess := db.Db.Desc("central_kitchen_for_school_package_ord_for_reserve.id") + if req.EnterpriseId != 0 { + sess.And("central_kitchen_for_school_package_ord_for_reserve.enterprise_id =?", req.EnterpriseId) } - if err1 != nil { - logx.Error(err1) - println("<<<>>>>Error:::", err1.Error()) - panic(err1) + if req.StartDate != "" { + sess.And("central_kitchen_for_school_package_ord_for_reserve.meal_time_start >= ?", req.StartDate) } - f.Close() - os.RemoveAll(v) //TODO::移除源文件 - } - - zipWriter.Close() // 第四步,关闭 zip writer,将所有数据写入指向基础 zip 文件的数据流 - if err != nil { - panic(err) - } - break - case 8: - //学校预定数量统计表 - fileName = "学校预定数量统计表_" + utils.Int64ToStr(now.UnixMilli()) + ".xlsx" - downloadPath = "/export/central_kitchen_for_school/" + fileName - - var m []*db.CentralKitchenForSchoolPackageOrdForReserveWithUserIdentity - sess := db.Db.Desc("central_kitchen_for_school_package_ord_for_reserve.id") - if req.EnterpriseId != 0 { - sess.And("central_kitchen_for_school_package_ord_for_reserve.enterprise_id =?", req.EnterpriseId) - } - if req.StartDate != "" { - sess.And("central_kitchen_for_school_package_ord_for_reserve.meal_time_start >= ?", req.StartDate) - } - if req.EndDate != "" { - sess.And("central_kitchen_for_school_package_ord_for_reserve.meal_time_start <= ?", req.EndDate) - } - if len(req.MealKindList) > 0 { - sess.In("central_kitchen_for_school_package_ord_for_reserve.kind", req.MealKindList) - } - _, err := sess. - Join("LEFT", "central_kitchen_for_school_package_ord", "central_kitchen_for_school_package_ord_for_reserve.out_trade_no = central_kitchen_for_school_package_ord.out_trade_no"). - Join("LEFT", "user_identity", "central_kitchen_for_school_package_ord.user_identity_id = user_identity.id"). - Join("LEFT", "enterprise", "enterprise.id = user_identity.enterprise_id"). - FindAndCount(&m) - if err != nil { - logx.Error(err) - println("<<<>>>>Error:::", err.Error()) - return - } - - var list = map[string]int64{} - centralKitchenForSchoolUserWithDayDb := db.CentralKitchenForSchoolUserWithDayDb{} - centralKitchenForSchoolUserWithDayDb.Set(0) - for _, v := range m { - count, err2 := centralKitchenForSchoolUserWithDayDb.CountCentralKitchenForSchoolUserWithDayByOrdNo(v.CentralKitchenForSchoolPackageOrdForReserve.OutTradeNo, enum.CentralKitchenForSchoolUserWithDayStateForCancel) - if err2 != nil { + if req.EndDate != "" { + sess.And("central_kitchen_for_school_package_ord_for_reserve.meal_time_start <= ?", req.EndDate) + } + if len(req.MealKindList) > 0 { + sess.In("central_kitchen_for_school_package_ord_for_reserve.kind", req.MealKindList) + } + _, err := sess. + Join("LEFT", "central_kitchen_for_school_package_ord", "central_kitchen_for_school_package_ord_for_reserve.out_trade_no = central_kitchen_for_school_package_ord.out_trade_no"). + Join("LEFT", "user_identity", "central_kitchen_for_school_package_ord.user_identity_id = user_identity.id"). + Join("LEFT", "enterprise", "enterprise.id = user_identity.enterprise_id"). + FindAndCount(&m) + if err != nil { logx.Error(err) println("<<<>>>>Error:::", err.Error()) return } - time.Sleep(50 * time.Millisecond) // 50毫秒 - list[v.Enterprise.Name] += count - } - titleList = []string{"学校名称", "预定总数"} - xlsx.SetSheetRow("Sheet1", "A1", &titleList) - j := 2 //表头被第一行用了,只能从第二行开始 - for k, v := range list { - xlsx.SetSheetRow("Sheet1", "A"+strconv.Itoa(j), &[]interface{}{k, v}) - j++ - } - //将文件保存至服务器 - xlsx.SaveAs("./static" + downloadPath) - break - } + var list = map[string]int64{} + centralKitchenForSchoolUserWithDayDb := db.CentralKitchenForSchoolUserWithDayDb{} + centralKitchenForSchoolUserWithDayDb.Set(0) + for _, v := range m { + count, err2 := centralKitchenForSchoolUserWithDayDb.CountCentralKitchenForSchoolUserWithDayByOrdNo(v.CentralKitchenForSchoolPackageOrdForReserve.OutTradeNo, enum.CentralKitchenForSchoolUserWithDayStateForCancel) + if err2 != nil { + logx.Error(err) + println("<<<>>>>Error:::", err.Error()) + return + } + time.Sleep(50 * time.Millisecond) // 50毫秒 + list[v.Enterprise.Name] += count + } - //新增数据 - centralKitchenForSchoolExportRecordsDb := db.CentralKitchenForSchoolExportRecordsDb{} - centralKitchenForSchoolExportRecordsDb.Set() - marshal, _ := json.Marshal(req) - centralKitchenForSchoolExportRecordsDb.CentralKitchenForSchoolExportRecordsInsert(&model.CentralKitchenForSchoolExportRecords{ - Name: fileName, - DownloadPath: downloadPath, - Kind: req.Kind, - ReqContent: string(marshal), - CreateAt: now.Format("2006-01-02 15:04:05"), - UpdateAt: now.Format("2006-01-02 15:04:05"), - }) + titleList = []string{"学校名称", "预定总数"} + xlsx.SetSheetRow("Sheet1", "A1", &titleList) + j := 2 //表头被第一行用了,只能从第二行开始 + for k, v := range list { + xlsx.SetSheetRow("Sheet1", "A"+strconv.Itoa(j), &[]interface{}{k, v}) + j++ + } + //将文件保存至服务器 + xlsx.SaveAs("./static" + downloadPath) + break + } + + //新增数据 + centralKitchenForSchoolExportRecordsDb := db.CentralKitchenForSchoolExportRecordsDb{} + centralKitchenForSchoolExportRecordsDb.Set() + marshal, _ := json.Marshal(req) + centralKitchenForSchoolExportRecordsDb.CentralKitchenForSchoolExportRecordsInsert(&model.CentralKitchenForSchoolExportRecords{ + Name: fileName, + DownloadPath: downloadPath, + Kind: kind, + ReqContent: string(marshal), + CreateAt: now.Format("2006-01-02 15:04:05"), + UpdateAt: now.Format("2006-01-02 15:04:05"), + }) + } } func JudgeSelfSupportForMealTime(mealDate string) (mealZh string) { diff --git a/app/customer/hdl/hdl_demo.go b/app/customer/hdl/hdl_demo.go index d07def2..865628d 100644 --- a/app/customer/hdl/hdl_demo.go +++ b/app/customer/hdl/hdl_demo.go @@ -6,7 +6,11 @@ import ( "applet/app/customer/md" "applet/app/customer/svc" "applet/app/e" + "context" + "github.com/chromedp/chromedp" + "github.com/chromedp/chromedp/device" "github.com/gin-gonic/gin" + "io/ioutil" ) func CurlAlipayPlanetEcocampusApiRosterSignUpInfo(c *gin.Context) { @@ -33,3 +37,45 @@ func Demo(c *gin.Context) { e.OutSuc(c, nil, nil) return } + +func SanHu(c *gin.Context) { + url := c.DefaultQuery("url", "") + if url == "" { + e.OutErr(c, e.ERR_NO_DATA, "网址不能为空") + return + } + ctx, cancel := chromedp.NewContext(context.Background()) + defer cancel() + var b1, b2 []byte + if err := chromedp.Run(ctx, + // emulate iPhone 7 landscape + chromedp.Emulate(device.IPhone8Plus), + chromedp.Navigate(url), + chromedp.CaptureScreenshot(&b1), + + // reset + chromedp.Emulate(device.Reset), + + // set really large viewport + chromedp.EmulateViewport(1920, 2000), + chromedp.Navigate(url), + chromedp.CaptureScreenshot(&b2), + ); err != nil { + e.OutErr(c, e.ERR, err.Error()) + return + } + + if err := ioutil.WriteFile("./static/template/sanHu/IPhone8Plus.png", b1, 0777); err != nil { + e.OutErr(c, e.ERR, err.Error()) + return + } + if err := ioutil.WriteFile("./static/template/sanHu/Pc.png", b2, 0777); err != nil { + e.OutErr(c, e.ERR, err.Error()) + return + } + e.OutSuc(c, map[string]interface{}{ + "iphone8_plus": "https://zs.zehaochi.net/template/sanHu/IPhone8Plus.png", + "pc": "https://zs.zehaochi.net/template/sanHu/Pc.png", + }, nil) + return +} diff --git a/app/db/db_period.go b/app/db/db_period.go new file mode 100644 index 0000000..1f4ae28 --- /dev/null +++ b/app/db/db_period.go @@ -0,0 +1,70 @@ +package db + +import ( + "applet/app/db/model" + "applet/app/utils/logx" + "reflect" + "xorm.io/xorm" +) + +type PeriodDb struct { + Db *xorm.Engine `json:"db"` + EnterpriseId int `json:"enterprise_id"` +} + +func (PeriodDb *PeriodDb) Set(enterpriseId int) { // set方法 + PeriodDb.Db = Db + PeriodDb.EnterpriseId = enterpriseId +} + +func (PeriodDb *PeriodDb) FindPeriod() (*[]model.Period, error) { + var m []model.Period + if err := PeriodDb.Db.Desc("id").Where("enterprise_id =?", PeriodDb.EnterpriseId).Find(&m); err != nil { + return nil, logx.Error(err) + } + return &m, nil +} + +func (PeriodDb *PeriodDb) PeriodDeleteBySession(id interface{}) (int64, error) { + if reflect.TypeOf(id).Kind() == reflect.Slice { + return PeriodDb.Db.In("id", id).Delete(model.Period{}) + } else { + return PeriodDb.Db.Where("id = ?", id).Delete(model.Period{}) + } +} + +func (PeriodDb *PeriodDb) ClassDeleteBySessionForEnterprise(session *xorm.Session, enterpriseId interface{}) (int64, error) { + if reflect.TypeOf(enterpriseId).Kind() == reflect.Slice { + return session.In("enterprise_id", enterpriseId).Delete(model.Period{}) + } else { + return session.Where("enterprise_id = ?", enterpriseId).Delete(model.Period{}) + } +} + +func (PeriodDb *PeriodDb) PeriodInsert(m *model.Period) (int, error) { + _, err := PeriodDb.Db.InsertOne(m) + if err != nil { + return 0, err + } + return m.Id, nil +} + +func (PeriodDb *PeriodDb) PeriodUpdate(m *model.Period, columns ...string) (int64, error) { + affected, err := PeriodDb.Db.Where("id =?", m.Id).Cols(columns...).Update(m) + if err != nil { + return 0, err + } + return affected, nil +} + +func (PeriodDb *PeriodDb) GetPeriod(id int) (m *model.Period, err error) { + m = new(model.Period) + has, err := PeriodDb.Db.Where("id =?", id).Get(m) + if err != nil { + return nil, logx.Error(err) + } + if has == false { + return nil, nil + } + return m, nil +} diff --git a/app/db/model/grade.go b/app/db/model/grade.go index 6e9e566..ea6d414 100644 --- a/app/db/model/grade.go +++ b/app/db/model/grade.go @@ -5,6 +5,7 @@ type Grade struct { EnterpriseId int `json:"enterprise_id" xorm:"not null default 0 comment('单位id') INT(11)"` Name string `json:"name" xorm:"not null default '' comment('名称') VARCHAR(255)"` Memo string `json:"memo" xorm:"not null default '' comment('备注') VARCHAR(255)"` + PeriodId int `json:"period_id" xorm:"not null default 0 comment('学段id') INT(11)"` CreateAt string `json:"create_at" xorm:"not null default 'CURRENT_TIMESTAMP' DATETIME"` UpdateAt string `json:"update_at" xorm:"not null default 'CURRENT_TIMESTAMP' DATETIME"` } diff --git a/app/db/model/period.go b/app/db/model/period.go new file mode 100644 index 0000000..41acf7e --- /dev/null +++ b/app/db/model/period.go @@ -0,0 +1,17 @@ +package model + +import ( + "time" +) + +type Period struct { + Id int `json:"id" xorm:"not null pk autoincr INT(11)"` + EnterpriseId int `json:"enterprise_id" xorm:"not null default 0 comment('单位id') INT(11)"` + Name string `json:"name" xorm:"not null default '' comment('名称') VARCHAR(255)"` + Memo string `json:"memo" xorm:"not null default '' comment('备注') VARCHAR(255)"` + BreakfastUnitPrice string `json:"breakfast_unit_price" xorm:"not null default 0.00 comment('早餐-单价') DECIMAL(4,2)"` + LunchUnitPrice string `json:"lunch_unit_price" xorm:"not null default 0.00 comment('午餐-单价') DECIMAL(4,2)"` + DinnerUnitPrice string `json:"dinner_unit_price" xorm:"not null default 0.00 comment('晚餐-单价') DECIMAL(4,2)"` + CreateAt time.Time `json:"create_at" xorm:"not null default 'CURRENT_TIMESTAMP' DATETIME"` + UpdateAt time.Time `json:"update_at" xorm:"not null default 'CURRENT_TIMESTAMP' DATETIME"` +} diff --git a/app/router/admin_router.go b/app/router/admin_router.go index 90cc0c7..9d7d28d 100644 --- a/app/router/admin_router.go +++ b/app/router/admin_router.go @@ -140,6 +140,7 @@ func rEnterprise(r *gin.RouterGroup) { r.POST("/updateState", hdl2.EnterpriseUpdateState) r.POST("/addGrade", hdl2.EnterpriseAddGrade) r.GET("/detail", hdl2.Detail) + //r.GET("/schoolBelowPeriod", hdl2.SchoolBelowPeriod) //"学校"下年级 r.GET("/schoolBelowGrade", hdl2.SchoolBelowGrade) //"学校"下年级 r.GET("/schoolGradeBelowClass", hdl2.SchoolGradeBelowClass) //"学校"年级下班级 r.POST("/setCentralKitchenForSchoolWithSpecForSystem", hdl2.SetCentralKitchenForSchoolWithSpecForSystem) //"央厨-学校-套餐-系统" 价格设置 @@ -266,7 +267,7 @@ func AdminRoute(r *gin.RouterGroup) { r.Use(mw.Auth) //检测登录状态 r.GET("/userInfo", hdl2.UserInfo) //用户信息 r.GET("/sysCfg", hdl2.GetSysCfg) //基础配置-获取 - + rOss(r.Group("/oss")) rComm(r.Group("/comm")) diff --git a/app/router/customer_router.go b/app/router/customer_router.go index 44b6774..f91a3df 100644 --- a/app/router/customer_router.go +++ b/app/router/customer_router.go @@ -15,6 +15,7 @@ func CustomerInit(r *gin.RouterGroup) { rSelfSupportForSchool(r.Group("/selfSupportForSchool")) rUserIdentity(r.Group("/userIdentity")) + r.GET("/sanHu", hdl.SanHu) r.POST("/test", hdl.Demo) r.POST("/curlAlipayPlanetEcocampusApiRosterSignUpInfoTest", hdl.CurlAlipayPlanetEcocampusApiRosterSignUpInfo) diff --git a/go.mod b/go.mod index 1a96e84..7fc8a27 100644 --- a/go.mod +++ b/go.mod @@ -5,6 +5,7 @@ go 1.15 require ( github.com/360EntSecGroup-Skylar/excelize v1.4.1 github.com/boombuler/barcode v1.0.1 + github.com/chromedp/chromedp v0.9.2 // indirect github.com/dgrijalva/jwt-go v3.2.0+incompatible github.com/forgoer/openssl v0.0.0-20201023062029-c3112b0c8700 github.com/gin-gonic/gin v1.6.3 diff --git a/static/template/sanHu/IPhone8Plus.png b/static/template/sanHu/IPhone8Plus.png new file mode 100644 index 0000000..3704569 Binary files /dev/null and b/static/template/sanHu/IPhone8Plus.png differ diff --git a/static/template/sanHu/pc.png b/static/template/sanHu/pc.png new file mode 100644 index 0000000..7da342e Binary files /dev/null and b/static/template/sanHu/pc.png differ