diff --git a/app/admin/hdl/hdl_data_statistics.go b/app/admin/hdl/hdl_data_statistics.go index 6b780d4..2d0028e 100644 --- a/app/admin/hdl/hdl_data_statistics.go +++ b/app/admin/hdl/hdl_data_statistics.go @@ -117,6 +117,8 @@ func CentralKitchenForSchoolDataStatisticsExport(c *gin.Context) { req.EnterpriseName = enterprise.Name } + go svc.CentralKitchenForSchoolDataStatisticsExport(req) + e.OutSuc(c, map[string]interface{}{ "msg": "导出成功,请稍后刷新数据列表", }, nil) diff --git a/app/admin/svc/svc_data_statisstics.go b/app/admin/svc/svc_data_statisstics.go index 37c83b1..4207719 100644 --- a/app/admin/svc/svc_data_statisstics.go +++ b/app/admin/svc/svc_data_statisstics.go @@ -7,8 +7,13 @@ import ( "applet/app/enum" "applet/app/utils" "applet/app/utils/logx" + "archive/zip" "encoding/json" + "fmt" "github.com/360EntSecGroup-Skylar/excelize" + "github.com/syyongx/php2go" + "io" + "os" "strconv" "time" ) @@ -47,6 +52,7 @@ func NursingHomeDataStatisticsExport(req md.NursingHomeDataStatisticsExportReq) return } titleList = []string{"单位名称", "用户身份名称", "用户手机号", "购买类型", "总价", "商户订单号", "支付状态", "购买时间"} + xlsx.SetSheetRow("Sheet1", "A1", &titleList) j := 2 //表头被第一行用了,只能从第二行开始 for _, v := range m { var kind string //1:按年购买 2:按月购买 3:按天购买 4:补餐 @@ -111,6 +117,7 @@ func NursingHomeDataStatisticsExport(req md.NursingHomeDataStatisticsExportReq) } titleList = []string{"退款单号", "所属订单号", "单位名称", "用户身份名称", "用户手机号", "就餐类型", "就餐时间", "金额", "状态", "退款时间"} + xlsx.SetSheetRow("Sheet1", "A1", &titleList) j := 2 //表头被第一行用了,只能从第二行开始 for _, v := range m { var kind string //就餐类型(1:早餐 2:午餐 3:晚餐) @@ -173,6 +180,7 @@ func NursingHomeDataStatisticsExport(req md.NursingHomeDataStatisticsExportReq) } titleList = []string{"所属订单号", "单位名称", "用户身份名称", "用户手机号", "预定类型", "预定月份", "就餐时间-开始", "就餐时间-截止"} + xlsx.SetSheetRow("Sheet1", "A1", &titleList) j := 2 //表头被第一行用了,只能从第二行开始 for _, v := range m { var kind string //预定类型(1:早餐 2:午餐 3:晚餐) @@ -211,18 +219,19 @@ func NursingHomeDataStatisticsExport(req md.NursingHomeDataStatisticsExportReq) func SelfSupportForSchoolDataStatisticsExport(req md.SelfSupportForSchoolDataStatisticsExportReq) { var titleList []string - var fileName string + var fileName, downloadPath string var now = time.Now() xlsx := excelize.NewFile() xlsx.SetSheetRow("Sheet1", "A1", &titleList) switch req.Kind { case 1: //学生列表 - fileName = "/export/self_support_for_school/学生列表_" + utils.Int64ToStr(now.UnixMilli()) + ".xlsx" + fileName = "学生列表_" + utils.Int64ToStr(now.UnixMilli()) + ".xlsx" + downloadPath = "/export/self_support_for_school/" + fileName //查找订单数据 sess := db.Db.Desc("user_identity.id") - sess.And("identity =?", enum.UserIdentityForSelfSupportForStudent) + sess.And("user_identity.identity =?", enum.UserIdentityForSelfSupportForStudent) if req.EnterpriseId != 0 { sess.And("user_identity.enterprise_id =?", req.EnterpriseId) } @@ -247,6 +256,7 @@ func SelfSupportForSchoolDataStatisticsExport(req md.SelfSupportForSchoolDataSta return } titleList = []string{"单位名称", "姓名", "身份证号", "家长电话", "采脸方式", "支付状态", "刷脸状态", "年级", "班级", "注册时间"} + xlsx.SetSheetRow("Sheet1", "A1", &titleList) j := 2 //表头被第一行用了,只能从第二行开始 for _, v := range m { var kind string //采集人脸方式(1:个采 2:集采) @@ -266,11 +276,12 @@ func SelfSupportForSchoolDataStatisticsExport(req md.SelfSupportForSchoolDataSta break case 2: //教师列表 - fileName = "/export/self_support_for_school/教师列表_" + utils.Int64ToStr(now.UnixMilli()) + ".xlsx" + fileName = "教师列表_" + utils.Int64ToStr(now.UnixMilli()) + ".xlsx" + downloadPath = "/export/self_support_for_school/" + fileName //查找订单数据 sess := db.Db.Desc("user_identity.id") - sess.And("identity =?", enum.UserIdentityForSelfSupportForTeacher) + sess.And("user_identity.identity =?", enum.UserIdentityForSelfSupportForTeacher) if req.EnterpriseId != 0 { sess.And("user_identity.enterprise_id =?", req.EnterpriseId) } @@ -292,6 +303,7 @@ func SelfSupportForSchoolDataStatisticsExport(req md.SelfSupportForSchoolDataSta return } titleList = []string{"单位名称", "姓名", "身份证号", "电话", "采脸方式", "支付状态", "刷脸状态", "注册时间"} + xlsx.SetSheetRow("Sheet1", "A1", &titleList) j := 2 //表头被第一行用了,只能从第二行开始 for _, v := range m { var kind string //采集人脸方式(1:个采 2:集采) @@ -311,7 +323,9 @@ func SelfSupportForSchoolDataStatisticsExport(req md.SelfSupportForSchoolDataSta break case 3: //消费明细表 - fileName = "/export/self_support_for_school/消费明细表_" + utils.Int64ToStr(now.UnixMilli()) + ".xlsx" + fileName = "消费明细表_" + utils.Int64ToStr(now.UnixMilli()) + ".xlsx" + downloadPath = "/export/self_support_for_school/" + fileName + var m []*db.SelfSupportForSchoolOrdWithUserIdentity sess := db.Db.Desc("self_support_for_school_ord.id") if req.EnterpriseId != 0 { @@ -338,20 +352,21 @@ func SelfSupportForSchoolDataStatisticsExport(req md.SelfSupportForSchoolDataSta } titleList = []string{"订单编号", "支付交易号", "用户手机号", "就餐人姓名", "学校名称", "年级", "班级", "金额", "支付状态", "就餐时间", "设备编号", "身份"} + xlsx.SetSheetRow("Sheet1", "A1", &titleList) j := 2 //表头被第一行用了,只能从第二行开始 for _, v := range m { var state string //支付状态(0:待支付 1:支付成功) switch v.SelfSupportForSchoolOrd.OrderStatus { - case 0: + case 1: state = "待支付" break - case 1: + case 2: state = "支付成功" break } var identity string - switch enum.UserIdentityForSelfSupportForTeacher { + switch v.UserIdentity.Identity { case enum.UserIdentityForSelfSupportForTeacher: identity = enum.UserIdentity.String(enum.UserIdentityForSelfSupportForTeacher) break @@ -362,7 +377,7 @@ func SelfSupportForSchoolDataStatisticsExport(req md.SelfSupportForSchoolDataSta identity = "未知" } - xlsx.SetSheetRow("Sheet1", "A"+strconv.Itoa(j), &[]interface{}{v.SelfSupportForSchoolOrd.OutOrderNo, v.SelfSupportForSchoolOrd.TradeNo, v.UserIdentity.Name, v.Enterprise.Name, + xlsx.SetSheetRow("Sheet1", "A"+strconv.Itoa(j), &[]interface{}{v.SelfSupportForSchoolOrd.OutOrderNo, v.SelfSupportForSchoolOrd.TradeNo, v.User.Phone, v.UserIdentity.Name, v.Enterprise.Name, v.Grade.Name, v.Class.Name, v.SelfSupportForSchoolOrd.TradeAmount, state, v.SelfSupportForSchoolOrd.FaceTime, v.SelfSupportForSchoolOrd.DeviceSn, identity}) j++ } @@ -370,7 +385,7 @@ func SelfSupportForSchoolDataStatisticsExport(req md.SelfSupportForSchoolDataSta } //将文件保存至服务器 - xlsx.SaveAs("./static" + fileName) + xlsx.SaveAs("./static" + downloadPath) //新增数据 selfSupportForSchoolExportRecordsDb := db.SelfSupportForSchoolExportRecordsDb{} @@ -378,7 +393,875 @@ func SelfSupportForSchoolDataStatisticsExport(req md.SelfSupportForSchoolDataSta marshal, _ := json.Marshal(req) selfSupportForSchoolExportRecordsDb.SelfSupportForSchoolExportRecordsInsert(&model.SelfSupportForSchoolExportRecords{ Name: fileName, - DownloadPath: 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"), + }) +} + +func CentralKitchenForSchoolDataStatisticsExport(req md.CentralKitchenForSchoolDataStatisticsExportReq) { + var titleList []string + 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 + } + titleList = []string{"订单号", "学生姓名", "学校", "年级", "班级", "家长电话", "预定日期", "预定天数", "订单价格", "支付时间", "订单状态"} + xlsx.SetSheetRow("Sheet1", "A1", &titleList) + j := 2 //表头被第一行用了,只能从第二行开始 + for _, v := range m { + 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++ + } + //将文件保存至服务器 + 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) + } + 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 + } + + 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++ + } + //将文件保存至服务器 + 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("self_support_for_school_ord.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) + } + _, 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) + } + + 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毫秒 + + 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 + } + } + + 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 = "教师餐" + } + + for k3, v3 := range v2 { + if k3 == "" { + //若班级为空,则为教师餐 + k3 = "教师餐" + } + + 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) + } + + 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) + } + + f, err1 := os.Open(v) //打开待压缩的文件 + 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::移除源文件 + } + + 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("self_support_for_school_ord.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) + } + _, 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 + } + + 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) + } + + 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毫秒 + + 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 + } + } + + 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 + } + + 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++ + } + } + } + + //将文件保存至服务器 + 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() + + 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) + } + + f, err1 := os.Open(v) //打开待压缩的文件 + 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::移除源文件 + } + + 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) + } + 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 + } + + 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) + } + + //就餐类型(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"]++ + } + } + + 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 + } + + 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++ + } + } + } + + //将文件保存至服务器 + 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() + + 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) + } + + f, err1 := os.Open(v) //打开待压缩的文件 + 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::移除源文件 + } + + 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 + } + + titleList = []string{"学校名称", "预定总费用", "退款总计"} + xlsx.SetSheetRow("Sheet1", "A1", &titleList) + 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 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)) + } + 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"] + } + j := 2 //表头被第一行用了,只能从第二行开始 + xlsx.SetSheetRow("Sheet1", "A"+strconv.Itoa(j), &[]interface{}{v.Name, income, refund}) + 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 + } + + 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) + } + + 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++ + } + } + + //将文件保存至服务器 + 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) + } + + f, err1 := os.Open(v) //打开待压缩的文件 + 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::移除源文件 + } + + 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("self_support_for_school_ord.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) + } + _, 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 { + 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 + } + + //新增数据 + 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"), diff --git a/app/db/db_central_kitchen_for_school_user_with_day.go b/app/db/db_central_kitchen_for_school_user_with_day.go index 7087147..600c8c9 100644 --- a/app/db/db_central_kitchen_for_school_user_with_day.go +++ b/app/db/db_central_kitchen_for_school_user_with_day.go @@ -46,6 +46,12 @@ func (centralKitchenForSchoolUserWithDayDb *CentralKitchenForSchoolUserWithDayDb return &m, nil } +func (centralKitchenForSchoolUserWithDayDb *CentralKitchenForSchoolUserWithDayDb) CountCentralKitchenForSchoolUserWithDayByOrdNo(ordNo string, state int) (count int64, err error) { + var m model.CentralKitchenForSchoolUserWithDay + count, err = centralKitchenForSchoolUserWithDayDb.Db.Where("ord_no =?", ordNo).And("state !=?", state).Count(&m) + return count, nil +} + func (centralKitchenForSchoolUserWithDayDb *CentralKitchenForSchoolUserWithDayDb) FindCentralKitchenForSchoolUserWithDayByOrdNoAndState(ordNo string, state int) (*[]model.CentralKitchenForSchoolUserWithDay, error) { var m []model.CentralKitchenForSchoolUserWithDay if err := centralKitchenForSchoolUserWithDayDb.Db.Where("ord_no =?", ordNo).And("state =?", state).Desc("id").Find(&m); err != nil { diff --git a/app/db/db_enterprise.go b/app/db/db_enterprise.go index bcb82b4..0ae3d9b 100644 --- a/app/db/db_enterprise.go +++ b/app/db/db_enterprise.go @@ -49,6 +49,14 @@ func (enterpriseDb *EnterpriseDb) FindEnterprise(limit, start int) (*[]model.Ent return &m, nil } +func (enterpriseDb *EnterpriseDb) FindEnterpriseByKind(kind int) (*[]model.Enterprise, error) { + var m []model.Enterprise + if err := enterpriseDb.Db.Where("kind =?", kind).Desc("id").Find(&m); err != nil { + return nil, logx.Error(err) + } + return &m, nil +} + func (enterpriseDb *EnterpriseDb) GetEnterpriseByName(name string) (m *model.Enterprise, err error) { m = new(model.Enterprise) has, err := enterpriseDb.Db.Where("name =?", name).Get(m) diff --git a/app/db/model/self_support_for_school_ord.go b/app/db/model/self_support_for_school_ord.go index 6a15106..a0e7469 100644 --- a/app/db/model/self_support_for_school_ord.go +++ b/app/db/model/self_support_for_school_ord.go @@ -24,7 +24,7 @@ type SelfSupportForSchoolOrd struct { CpMerchantId string `json:"cp_merchant_id" xorm:"not null default '' comment('商户编码') CHAR(100)"` TradeAmount string `json:"trade_amount" xorm:"not null default 0.00 comment('交易总金额') DECIMAL(8,2)"` FaceTime string `json:"face_time" xorm:"not null default '' comment('刷脸时间') CHAR(100)"` - OrderStatus int `json:"order_status" xorm:"not null default 0 comment('支付状态 (0:待支付 1:支付成功)') TINYINT(1)"` + OrderStatus int `json:"order_status" xorm:"not null default 0 comment('支付状态 (1:待支付 2:支付成功)') TINYINT(1)"` DebtBusinessCode string `json:"debt_business_code" xorm:"not null default '' comment('欠费订单异常渠道异常码(欠费返回)') CHAR(100)"` DebtBusinessMsg string `json:"debt_business_msg" xorm:"not null default '' comment('欠费订单欠费原因(欠费返回)') VARCHAR(255)"` CreateAt time.Time `json:"create_at" xorm:"not null pk default 'CURRENT_TIMESTAMP' DATETIME"` diff --git a/static/export/nursing_home/订单列表_2023-09-01-2023-09-301694086532916.xlsx b/static/export/nursing_home/订单列表_2023-09-01-2023-09-301694086532916.xlsx deleted file mode 100644 index 028d778..0000000 Binary files a/static/export/nursing_home/订单列表_2023-09-01-2023-09-301694086532916.xlsx and /dev/null differ diff --git a/static/export/收款统计表-2023-09-01-2023-09-30_2023083011221655.xls b/static/export/收款统计表-2023-09-01-2023-09-30_2023083011221655.xls deleted file mode 100644 index 31c0764..0000000 Binary files a/static/export/收款统计表-2023-09-01-2023-09-30_2023083011221655.xls and /dev/null differ diff --git a/static消费明细表_1694180739026.xlsx b/static消费明细表_1694180739026.xlsx new file mode 100644 index 0000000..8674966 Binary files /dev/null and b/static消费明细表_1694180739026.xlsx differ