智慧食堂
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

1343 Zeilen
56 KiB

  1. package svc
  2. import (
  3. "applet/app/admin/md"
  4. "applet/app/db"
  5. "applet/app/db/model"
  6. "applet/app/enum"
  7. "applet/app/utils"
  8. "applet/app/utils/logx"
  9. "archive/zip"
  10. "encoding/json"
  11. "fmt"
  12. "github.com/360EntSecGroup-Skylar/excelize"
  13. "github.com/syyongx/php2go"
  14. "io"
  15. "os"
  16. "strconv"
  17. "time"
  18. )
  19. func NursingHomeDataStatisticsExport(req md.NursingHomeDataStatisticsExportReq) {
  20. var titleList []string
  21. var fileName string
  22. var now = time.Now()
  23. xlsx := excelize.NewFile()
  24. xlsx.SetSheetRow("Sheet1", "A1", &titleList)
  25. switch req.Kind {
  26. case 1:
  27. //订单列表
  28. fileName = "/export/nursing_home/订单列表_" + utils.Int64ToStr(now.UnixMilli()) + ".xlsx"
  29. //查找订单数据
  30. sess := db.Db.Desc("nursing_home_package_ord.id")
  31. if req.EnterpriseId != 0 {
  32. sess.And("nursing_home_package_ord.enterprise_id =?", req.EnterpriseId)
  33. }
  34. if req.StartDate != "" {
  35. sess.And("nursing_home_package_ord.create_at >= ?", req.StartDate)
  36. }
  37. if req.EndDate != "" {
  38. sess.And("nursing_home_package_ord.create_at <= ?", req.EndDate)
  39. }
  40. var m []*db.NursingHomePackageOrdWithUserIdentity
  41. _, err := sess.
  42. Join("LEFT", "user_identity", "nursing_home_package_ord.user_identity_id = user_identity.id").
  43. Join("LEFT", "enterprise", "enterprise.id = nursing_home_package_ord.enterprise_id").
  44. Join("LEFT", "user", "user.id = nursing_home_package_ord.uid").
  45. FindAndCount(&m)
  46. if err != nil {
  47. logx.Error(err)
  48. println("<<<<NursingHomeDataStatisticsExport1>>>>>Error:::", err.Error())
  49. return
  50. }
  51. titleList = []string{"单位名称", "用户身份名称", "用户手机号", "购买类型", "总价", "商户订单号", "支付状态", "购买时间"}
  52. xlsx.SetSheetRow("Sheet1", "A1", &titleList)
  53. j := 2 //表头被第一行用了,只能从第二行开始
  54. for _, v := range m {
  55. var kind string //1:按年购买 2:按月购买 3:按天购买 4:补餐
  56. switch v.NursingHomePackageOrd.Kind {
  57. case 1:
  58. kind = "按年购买"
  59. break
  60. case 2:
  61. kind = "按月购买"
  62. break
  63. case 3:
  64. kind = "按天购买"
  65. break
  66. case 4:
  67. kind = "补餐"
  68. break
  69. }
  70. var state string //0:待支付 1:支付成功 2:支付失败
  71. switch v.NursingHomePackageOrd.State {
  72. case enum.NursingHomePackageOrdStateForWait:
  73. state = enum.NursingHomePackageOrdState.String(enum.NursingHomePackageOrdStateForWait)
  74. break
  75. case enum.NursingHomePackageOrdStateForSuccess:
  76. state = enum.NursingHomePackageOrdState.String(enum.NursingHomePackageOrdStateForWait)
  77. break
  78. case enum.NursingHomePackageOrdStateForFail:
  79. state = enum.NursingHomePackageOrdState.String(enum.NursingHomePackageOrdStateForFail)
  80. break
  81. }
  82. xlsx.SetSheetRow("Sheet1", "A"+strconv.Itoa(j), &[]interface{}{v.Enterprise.Name, v.NursingHomePackageOrd.UserIdentityName, v.User.Phone, kind, v.NursingHomePackageOrd.TotalPrice,
  83. v.NursingHomePackageOrd.OutTradeNo, state, v.NursingHomePackageOrd.CreateAt})
  84. j++
  85. }
  86. break
  87. case 2:
  88. //退款申请表
  89. fileName = "/export/nursing_home/退款申请表_" + utils.Int64ToStr(now.UnixMilli()) + ".xlsx"
  90. var m []*db.NursingHomeUserRefundDayWithData
  91. sess := db.Db.Desc("nursing_home_user_refund_day.id")
  92. if req.EnterpriseId != 0 {
  93. sess.And("enterprise.enterprise_id =?", req.EnterpriseId)
  94. }
  95. if req.StartDate != "" {
  96. sess.And("nursing_home_user_refund_day.create_at >= ?", req.StartDate)
  97. }
  98. if req.EndDate != "" {
  99. sess.And("nursing_home_user_refund_day.create_at <= ?", req.EndDate)
  100. }
  101. _, err := sess.
  102. Join("LEFT", "nursing_home_user_with_day", "nursing_home_user_refund_day.records_id = nursing_home_user_with_day.id").
  103. Join("LEFT", "nursing_home_package_ord", "nursing_home_user_refund_day.out_trade_no = nursing_home_package_ord.out_trade_no").
  104. Join("LEFT", "user_identity", "nursing_home_user_with_day.identity_id = user_identity.id").
  105. Join("LEFT", "user", "user_identity.uid = user.id").
  106. Join("LEFT", "enterprise", "user_identity.enterprise_id = enterprise.id").
  107. Desc("nursing_home_user_refund_day.id").
  108. FindAndCount(&m)
  109. if err != nil {
  110. logx.Error(err)
  111. println("<<<<NursingHomeDataStatisticsExport2>>>>>Error:::", err.Error())
  112. return
  113. }
  114. titleList = []string{"退款单号", "所属订单号", "单位名称", "用户身份名称", "用户手机号", "就餐类型", "就餐时间", "金额", "状态", "退款时间"}
  115. xlsx.SetSheetRow("Sheet1", "A1", &titleList)
  116. j := 2 //表头被第一行用了,只能从第二行开始
  117. for _, v := range m {
  118. var kind string //就餐类型(1:早餐 2:午餐 3:晚餐)
  119. switch v.NursingHomeUserWithDay.Kind {
  120. case enum.NursingHomeUserWithDayKindForBreakfast:
  121. kind = enum.NursingHomeUserWithDayKind.String(enum.NursingHomeUserWithDayKindForBreakfast)
  122. break
  123. case enum.NursingHomeUserWithDayKindForLunch:
  124. kind = enum.NursingHomeUserWithDayKind.String(enum.NursingHomeUserWithDayKindForLunch)
  125. break
  126. case enum.NursingHomeUserWithDayKindForDinner:
  127. kind = enum.NursingHomeUserWithDayKind.String(enum.NursingHomeUserWithDayKindForDinner)
  128. break
  129. }
  130. var state string //状态(1:审核中 2:审核通过 3:审核拒绝 4:退款已完成)
  131. switch v.NursingHomeUserRefundDay.State {
  132. case enum.NursingHomeUserRefundDayStateForAuditing:
  133. state = enum.NursingHomeUserRefundDayState.String(enum.NursingHomeUserRefundDayStateForAuditing)
  134. break
  135. case enum.NursingHomeUserRefundDayStateForAuditPass:
  136. state = enum.NursingHomeUserRefundDayState.String(enum.NursingHomeUserRefundDayStateForAuditPass)
  137. break
  138. case enum.NursingHomeUserRefundDayStateForAuditReject:
  139. state = enum.NursingHomeUserRefundDayState.String(enum.NursingHomeUserRefundDayStateForAuditReject)
  140. break
  141. case enum.NursingHomeUserRefundDayStateForAuditComplete:
  142. state = enum.NursingHomeUserRefundDayState.String(enum.NursingHomeUserRefundDayStateForAuditComplete)
  143. break
  144. }
  145. xlsx.SetSheetRow("Sheet1", "A"+strconv.Itoa(j), &[]interface{}{v.NursingHomeUserRefundDay.OutRequestNo, v.NursingHomeUserRefundDay.OutTradeNo, v.Enterprise.Name,
  146. v.NursingHomePackageOrd.UserIdentityName, v.User.Phone, kind, v.NursingHomeUserWithDay.Date, v.NursingHomeUserRefundDay.Amount, state, v.NursingHomeUserRefundDay.RefundDate})
  147. j++
  148. }
  149. xlsx.SaveAs("./static" + fileName + ".xlsx")
  150. break
  151. case 3:
  152. //预定统计表
  153. fileName = "/export/nursing_home/预定统计表_" + utils.Int64ToStr(now.UnixMilli()) + ".xlsx"
  154. var m []*db.NursingHomePackageOrdForReserveWithUserIdentity
  155. sess := db.Db.Desc("nursing_home_package_ord_for_reserve.id")
  156. if req.EnterpriseId != 0 {
  157. sess.And("enterprise.enterprise_id =?", req.EnterpriseId)
  158. }
  159. if req.StartDate != "" {
  160. sess.And("nursing_home_package_ord_for_reserve.meal_time_start >= ?", req.StartDate)
  161. }
  162. if req.EndDate != "" {
  163. sess.And("nursing_home_package_ord_for_reserve.meal_time_start <= ?", req.EndDate)
  164. }
  165. _, err := sess.
  166. Join("LEFT", "nursing_home_package_ord", "nursing_home_package_ord_for_reserve.out_trade_no = nursing_home_package_ord.out_trade_no").
  167. Join("LEFT", "user_identity", "nursing_home_package_ord.user_identity_id = user_identity.id").
  168. Join("LEFT", "enterprise", "enterprise.id = user_identity.enterprise_id").
  169. Join("LEFT", "user", "user.id = user_identity.uid").FindAndCount(&m)
  170. if err != nil {
  171. logx.Error(err)
  172. println("<<<<NursingHomeDataStatisticsExport2>>>>>Error:::", err.Error())
  173. return
  174. }
  175. titleList = []string{"所属订单号", "单位名称", "用户身份名称", "用户手机号", "预定类型", "预定月份", "就餐时间-开始", "就餐时间-截止"}
  176. xlsx.SetSheetRow("Sheet1", "A1", &titleList)
  177. j := 2 //表头被第一行用了,只能从第二行开始
  178. for _, v := range m {
  179. var kind string //预定类型(1:早餐 2:午餐 3:晚餐)
  180. switch v.NursingHomePackageOrdForReserve.Kind {
  181. case enum.NursingHomeUserWithDayKindForBreakfast:
  182. kind = enum.NursingHomeUserWithDayKind.String(enum.NursingHomeUserWithDayKindForBreakfast)
  183. break
  184. case enum.NursingHomeUserWithDayKindForLunch:
  185. kind = enum.NursingHomeUserWithDayKind.String(enum.NursingHomeUserWithDayKindForLunch)
  186. break
  187. case enum.NursingHomeUserWithDayKindForDinner:
  188. kind = enum.NursingHomeUserWithDayKind.String(enum.NursingHomeUserWithDayKindForDinner)
  189. break
  190. }
  191. xlsx.SetSheetRow("Sheet1", "A"+strconv.Itoa(j), &[]interface{}{v.NursingHomePackageOrdForReserve.OutTradeNo, v.Enterprise.Name, v.NursingHomePackageOrd.UserIdentityName,
  192. v.User.Phone, kind, v.NursingHomePackageOrdForReserve.ReserveMonth, v.NursingHomePackageOrdForReserve.MealTimeStart, v.NursingHomePackageOrdForReserve.MealTimeEnd})
  193. j++
  194. }
  195. xlsx.SaveAs("./static" + fileName + ".xlsx")
  196. break
  197. }
  198. //新增数据
  199. nursingHomeExportRecordsDb := db.NursingHomeExportRecordsDb{}
  200. nursingHomeExportRecordsDb.Set()
  201. marshal, _ := json.Marshal(req)
  202. nursingHomeExportRecordsDb.NursingHomeExportRecordsInsert(&model.NursingHomeExportRecords{
  203. Name: fileName,
  204. DownloadPath: fileName,
  205. Kind: req.Kind,
  206. ReqContent: string(marshal),
  207. CreateAt: now.Format("2006-01-02 15:04:05"),
  208. UpdateAt: now.Format("2006-01-02 15:04:05"),
  209. })
  210. }
  211. func SelfSupportForSchoolDataStatisticsExport(req md.SelfSupportForSchoolDataStatisticsExportReq) {
  212. var titleList []string
  213. var fileName, downloadPath string
  214. var now = time.Now()
  215. switch req.Kind {
  216. case 1:
  217. //教师消费统计表
  218. xlsx, _ := excelize.OpenFile("./static/template/自营学校(教师消费统计表).xlsx")
  219. fileName = "教师消费统计表_" + utils.Int64ToStr(now.UnixMilli()) + ".xlsx"
  220. downloadPath = "/export/self_support_for_school/" + fileName
  221. //查询数据
  222. var m []*db.SelfSupportForSchoolOrdWithUserIdentity
  223. sess := db.Db.Desc("self_support_for_school_ord.id")
  224. if req.EnterpriseId != 0 {
  225. sess.And("self_support_for_school_ord.enterprise_id =?", req.EnterpriseId)
  226. }
  227. if req.StartDate != "" {
  228. sess.And("self_support_for_school_ord.face_time >= ?", req.StartDate)
  229. }
  230. if req.EndDate != "" {
  231. sess.And("self_support_for_school_ord.face_time <= ?", req.EndDate)
  232. }
  233. sess.And("user_identity.identity = ?", enum.UserIdentityForSelfSupportForTeacher) //只查询老师
  234. _, err := sess.
  235. Join("LEFT", "user_identity", "self_support_for_school_ord.user_identity_id = user_identity.id").
  236. Join("LEFT", "enterprise", "enterprise.id = user_identity.enterprise_id").
  237. Join("LEFT", "user", "user.id = user_identity.uid").
  238. Join("LEFT", "class_with_user", "class_with_user.user_identity_id = user_identity.id").
  239. Join("LEFT", "class", "class_with_user.class_id = class.id").
  240. Join("LEFT", "grade", "class.grade_id = grade.id").
  241. FindAndCount(&m)
  242. if err != nil {
  243. logx.Error(err)
  244. println("<<<<SelfSupportForSchoolDataStatisticsExport2>>>>>Error:::", err.Error())
  245. return
  246. }
  247. //整合数据
  248. var data map[string]map[string]map[string]map[string]float64
  249. for _, vv := range m {
  250. if data[vv.Enterprise.Name] == nil {
  251. data[vv.Enterprise.Name] = make(map[string]map[string]map[string]float64)
  252. }
  253. if data[vv.Enterprise.Name][vv.UserIdentity.Name] == nil {
  254. data[vv.Enterprise.Name][vv.UserIdentity.Name] = make(map[string]map[string]float64)
  255. }
  256. mealZh := JudgeSelfSupportForMealTime(vv.SelfSupportForSchoolOrd.FaceTime)
  257. if data[vv.Enterprise.Name][vv.UserIdentity.Name][mealZh] == nil {
  258. data[vv.Enterprise.Name][vv.UserIdentity.Name][mealZh] = make(map[string]float64)
  259. }
  260. data[vv.Enterprise.Name][vv.UserIdentity.Name]["编号"] = map[string]float64{
  261. "id": float64(vv.UserIdentity.Id),
  262. }
  263. if data[vv.Enterprise.Name][vv.UserIdentity.Name]["合计"] == nil {
  264. data[vv.Enterprise.Name][vv.UserIdentity.Name]["合计"] = make(map[string]float64)
  265. }
  266. data[vv.Enterprise.Name][vv.UserIdentity.Name][mealZh]["num"]++
  267. data[vv.Enterprise.Name][vv.UserIdentity.Name][mealZh]["amount"] += utils.StrToFloat64(vv.SelfSupportForSchoolOrd.TradeAmount)
  268. data[vv.Enterprise.Name][vv.UserIdentity.Name]["合计"]["num"]++
  269. data[vv.Enterprise.Name][vv.UserIdentity.Name]["合计"]["amount"] += utils.StrToFloat64(vv.SelfSupportForSchoolOrd.TradeAmount)
  270. }
  271. xlsx.SetSheetRow("", "A1", &titleList)
  272. sheetIndex := 2 //第一个表是模板表
  273. j := 3 //表头前两行被占用了,只能从第三行开始
  274. for k, v := range data {
  275. xlsx.NewSheet(k) //1、新建表格
  276. xlsx.CopySheet(1, sheetIndex)
  277. for kk, vv := range v {
  278. xlsx.SetSheetRow(k, "A"+strconv.Itoa(j), &[]interface{}{utils.Float64ToStr(vv["编号"]["id"]), kk,
  279. vv["早餐"]["num"], vv["早餐"]["amount"],
  280. vv["午餐"]["num"], vv["午餐"]["amount"],
  281. vv["晚餐"]["num"], vv["晚餐"]["amount"],
  282. vv["夜宵"]["num"], vv["夜宵"]["amount"],
  283. vv["合计"]["num"], vv["合计"]["amount"],
  284. })
  285. j++
  286. }
  287. sheetIndex++
  288. }
  289. xlsx.DeleteSheet("template") //删除模板表
  290. //将文件保存至服务器
  291. xlsx.SaveAs("./static" + downloadPath)
  292. break
  293. case 2:
  294. //商家分餐数据统计表
  295. xlsx, _ := excelize.OpenFile("./static/template/自营学校(商家分餐数据统计表).xlsx")
  296. fileName = "商家分餐数据统计表_" + utils.Int64ToStr(now.UnixMilli()) + ".xlsx"
  297. downloadPath = "/export/self_support_for_school/" + fileName
  298. //查询出所有的设备
  299. var deviceList []*model.Device
  300. err := db.Db.Where("enterprise_id != 0").Find(&deviceList)
  301. if err != nil {
  302. logx.Error(err)
  303. println("<<<<SelfSupportForSchoolDataStatisticsExport2>>>>>1111Error:::", err.Error())
  304. return
  305. }
  306. var deviceListMapping = map[string]model.Device{}
  307. for _, v := range deviceList {
  308. deviceListMapping[v.DeviceSn] = *v
  309. }
  310. var m []*db.SelfSupportForSchoolOrdWithUserIdentity
  311. sess := db.Db.Desc("self_support_for_school_ord.id")
  312. if req.EnterpriseId != 0 {
  313. sess.And("self_support_for_school_ord.enterprise_id =?", req.EnterpriseId)
  314. }
  315. if req.StartDate != "" {
  316. sess.And("self_support_for_school_ord.face_time >= ?", req.StartDate)
  317. }
  318. if req.EndDate != "" {
  319. sess.And("self_support_for_school_ord.face_time <= ?", req.EndDate)
  320. }
  321. _, err = sess.
  322. Join("LEFT", "user_identity", "self_support_for_school_ord.user_identity_id = user_identity.id").
  323. Join("LEFT", "enterprise", "enterprise.id = user_identity.enterprise_id").
  324. Join("LEFT", "user", "user.id = user_identity.uid").
  325. Join("LEFT", "class_with_user", "class_with_user.user_identity_id = user_identity.id").
  326. Join("LEFT", "class", "class_with_user.class_id = class.id").
  327. Join("LEFT", "grade", "class.grade_id = grade.id").
  328. FindAndCount(&m)
  329. if err != nil {
  330. logx.Error(err)
  331. println("<<<<SelfSupportForSchoolDataStatisticsExport2>>>>>Error:::", err.Error())
  332. return
  333. }
  334. //整合数据
  335. var data = map[string]map[string]map[string]map[string]float64{}
  336. for _, vv := range m {
  337. shopName := deviceListMapping[vv.SelfSupportForSchoolOrd.DeviceSn].Name
  338. if data[vv.Enterprise.Name] == nil {
  339. data[vv.Enterprise.Name] = make(map[string]map[string]map[string]float64)
  340. }
  341. if data[vv.Enterprise.Name][shopName] == nil {
  342. data[vv.Enterprise.Name][shopName] = make(map[string]map[string]float64)
  343. }
  344. mealZh := JudgeSelfSupportForMealTime(vv.SelfSupportForSchoolOrd.FaceTime)
  345. if data[vv.Enterprise.Name][shopName][mealZh] == nil {
  346. data[vv.Enterprise.Name][shopName][mealZh] = make(map[string]float64)
  347. }
  348. if data[vv.Enterprise.Name][shopName]["合计"] == nil {
  349. data[vv.Enterprise.Name][shopName]["合计"] = make(map[string]float64)
  350. }
  351. data[vv.Enterprise.Name][shopName][mealZh]["num"]++
  352. data[vv.Enterprise.Name][shopName][mealZh]["amount"] += utils.StrToFloat64(vv.SelfSupportForSchoolOrd.TradeAmount)
  353. data[vv.Enterprise.Name][shopName]["合计"]["num"]++
  354. data[vv.Enterprise.Name][shopName]["合计"]["amount"] += utils.StrToFloat64(vv.SelfSupportForSchoolOrd.TradeAmount)
  355. }
  356. xlsx.SetSheetRow("", "A1", &titleList)
  357. sheetIndex := 2 //第一个表是模板表
  358. for k, v := range data {
  359. if k == "" {
  360. k = "未知"
  361. }
  362. xlsx.NewSheet(k) //1、新建表格
  363. xlsx.CopySheet(1, sheetIndex)
  364. j := 4 //表头前三行被占用了,只能从第四行开始
  365. for kk, vv := range v {
  366. xlsx.SetSheetRow(k, "A"+strconv.Itoa(j), &[]interface{}{kk,
  367. vv["早餐"]["num"], vv["早餐"]["amount"],
  368. vv["午餐"]["num"], vv["午餐"]["amount"],
  369. vv["晚餐"]["num"], vv["晚餐"]["amount"],
  370. vv["夜宵"]["num"], vv["夜宵"]["amount"],
  371. vv["合计"]["num"], vv["合计"]["amount"],
  372. })
  373. j++
  374. }
  375. sheetIndex++
  376. }
  377. xlsx.DeleteSheet("template") //删除模板表
  378. //将文件保存至服务器
  379. xlsx.SaveAs("./static" + downloadPath)
  380. break
  381. }
  382. //新增数据
  383. selfSupportForSchoolExportRecordsDb := db.SelfSupportForSchoolExportRecordsDb{}
  384. selfSupportForSchoolExportRecordsDb.Set()
  385. marshal, _ := json.Marshal(req)
  386. selfSupportForSchoolExportRecordsDb.SelfSupportForSchoolExportRecordsInsert(&model.SelfSupportForSchoolExportRecords{
  387. Name: fileName,
  388. DownloadPath: downloadPath,
  389. Kind: req.Kind,
  390. ReqContent: string(marshal),
  391. CreateAt: now.Format("2006-01-02 15:04:05"),
  392. UpdateAt: now.Format("2006-01-02 15:04:05"),
  393. })
  394. }
  395. func CentralKitchenForSchoolDataStatisticsExport(req md.CentralKitchenForSchoolDataStatisticsExportReq) {
  396. var titleList []string
  397. var fileName, downloadPath string
  398. var now = time.Now()
  399. xlsx := excelize.NewFile()
  400. switch req.Kind {
  401. case 1:
  402. //订单列表
  403. fileName = "订单列表_" + utils.Int64ToStr(now.UnixMilli()) + ".xlsx"
  404. downloadPath = "/export/central_kitchen_for_school/" + fileName
  405. //查找订单数据
  406. sess := db.Db.Desc("central_kitchen_for_school_package_ord.id")
  407. sess.And("central_kitchen_for_school_package_ord.state =?", enum.CentralKitchenForSchoolPackageOrdStateForSuccess)
  408. if req.EnterpriseId != 0 {
  409. sess.And("central_kitchen_for_school_package_ord.enterprise_id =?", req.EnterpriseId)
  410. }
  411. if req.StartDate != "" {
  412. sess.And("central_kitchen_for_school_package_ord.create_at >= ?", req.StartDate)
  413. }
  414. if req.EndDate != "" {
  415. sess.And("central_kitchen_for_school_package_ord.create_at <= ?", req.EndDate)
  416. }
  417. var m []*db.CentralKitchenForSchoolPackageOrdWithUserIdentity
  418. _, err := sess.
  419. Join("LEFT", "user_identity", "central_kitchen_for_school_package_ord.user_identity_id = user_identity.id").
  420. Join("LEFT", "enterprise", "enterprise.id = user_identity.enterprise_id").
  421. Join("LEFT", "user", "user.id = user_identity.uid").
  422. Join("LEFT", "class_with_user", "class_with_user.user_identity_id = user_identity.id").
  423. Join("LEFT", "class", "class_with_user.class_id = class.id").
  424. Join("LEFT", "grade", "class.grade_id = grade.id").
  425. FindAndCount(&m)
  426. if err != nil {
  427. logx.Error(err)
  428. println("<<<<CentralKitchenForSchoolDataStatisticsExport1>>>>>Error:::", err.Error())
  429. return
  430. }
  431. //查找预定数据
  432. var outTradeNoList []string
  433. for _, v := range m {
  434. outTradeNoList = append(outTradeNoList, v.OutTradeNo)
  435. }
  436. var mm []model.CentralKitchenForSchoolPackageOrdForReserve
  437. sess1 := db.Db.Desc("id")
  438. if req.EnterpriseId != 0 {
  439. sess1.And("enterprise_id = ?", req.EnterpriseId)
  440. }
  441. if len(req.MealKindList) > 0 {
  442. sess1.In("kind", req.MealKindList)
  443. }
  444. err = sess1.In("out_trade_no", outTradeNoList).Find(&mm)
  445. if err != nil {
  446. logx.Error(err)
  447. println("<<<<CentralKitchenForSchoolDataStatisticsExport1>>>>>Error:::", err.Error())
  448. return
  449. }
  450. var exportOutTradeNoList []string
  451. for _, v := range mm {
  452. exportOutTradeNoList = append(exportOutTradeNoList, v.OutTradeNo)
  453. }
  454. titleList = []string{"订单号", "学生姓名", "学校", "年级", "班级", "家长电话", "预定日期", "预定天数", "订单价格", "支付时间", "订单状态"}
  455. xlsx.SetSheetRow("Sheet1", "A1", &titleList)
  456. j := 2 //表头被第一行用了,只能从第二行开始
  457. for _, v := range m {
  458. if !utils.InArr(v.OutTradeNo, exportOutTradeNoList) {
  459. continue
  460. }
  461. var ordState string //订单状态(0:待支付 1:预约成功 2:退款中 3:部分退款 4:已退款 5:已完成)
  462. switch v.CentralKitchenForSchoolPackageOrd.OrdState {
  463. case enum.CentralKitchenForSchoolPackageOrdOrdStateForWait:
  464. ordState = enum.CentralKitchenForSchoolPackageOrdOrdState.String(enum.CentralKitchenForSchoolPackageOrdOrdStateForWait)
  465. break
  466. case enum.CentralKitchenForSchoolPackageOrdOrdStateForSuccess:
  467. ordState = enum.CentralKitchenForSchoolPackageOrdOrdState.String(enum.CentralKitchenForSchoolPackageOrdOrdStateForSuccess)
  468. break
  469. case enum.CentralKitchenForSchoolPackageOrdOrdStateForRefunding:
  470. ordState = enum.CentralKitchenForSchoolPackageOrdOrdState.String(enum.CentralKitchenForSchoolPackageOrdOrdStateForRefunding)
  471. break
  472. case enum.CentralKitchenForSchoolPackageOrdOrdStateForPartRefunded:
  473. ordState = enum.CentralKitchenForSchoolPackageOrdOrdState.String(enum.CentralKitchenForSchoolPackageOrdOrdStateForPartRefunded)
  474. break
  475. case enum.CentralKitchenForSchoolPackageOrdOrdStateForRefunded:
  476. ordState = enum.CentralKitchenForSchoolPackageOrdOrdState.String(enum.CentralKitchenForSchoolPackageOrdOrdStateForRefunded)
  477. break
  478. case enum.CentralKitchenForSchoolPackageOrdOrdStateForComplete:
  479. ordState = enum.CentralKitchenForSchoolPackageOrdOrdState.String(enum.CentralKitchenForSchoolPackageOrdOrdStateForComplete)
  480. break
  481. }
  482. //预定天数、预定日期
  483. var list []*model.CentralKitchenForSchoolUserWithDay
  484. err1 := json.Unmarshal([]byte(v.CentralKitchenForSchoolPackageOrd.WithDayData), &list)
  485. if err1 != nil {
  486. logx.Error(err)
  487. println("<<<<CentralKitchenForSchoolDataStatisticsExport1>>>>>Error:::", err.Error())
  488. return
  489. }
  490. var reserveDays string
  491. for _, v1 := range list {
  492. reserveDays += v1.Date
  493. }
  494. if v.Grade.Name == "" {
  495. v.Grade.Name = "教师"
  496. }
  497. if v.Class.Name == "" {
  498. v.Class.Name = "教师"
  499. }
  500. xlsx.SetSheetRow("Sheet1", "A"+strconv.Itoa(j), &[]interface{}{v.CentralKitchenForSchoolPackageOrd.OutTradeNo, v.CentralKitchenForSchoolPackageOrd.UserIdentityName, v.Enterprise.Name,
  501. v.Grade.Name, v.Class.Name, v.User.Phone, reserveDays, len(list), v.CentralKitchenForSchoolPackageOrd.TotalPrice, v.CentralKitchenForSchoolPackageOrd.CreateAt, ordState})
  502. j++
  503. }
  504. //将文件保存至服务器
  505. xlsx.SaveAs("./static" + downloadPath)
  506. break
  507. case 2:
  508. //退款申请表
  509. fileName = "退款申请表_" + utils.Int64ToStr(now.UnixMilli()) + ".xlsx"
  510. downloadPath = "/export/central_kitchen_for_school/" + fileName
  511. //查找退款申请数据
  512. sess := db.Db.Desc("central_kitchen_for_school_user_refund_day.id")
  513. if req.EnterpriseId != 0 {
  514. sess.And("enterprise.id =?", req.EnterpriseId)
  515. }
  516. if req.StartDate != "" {
  517. sess.And("central_kitchen_for_school_user_refund_day.create_at >= ?", req.StartDate)
  518. }
  519. if req.EndDate != "" {
  520. sess.And("central_kitchen_for_school_user_refund_day.create_at <= ?", req.EndDate)
  521. }
  522. if len(req.MealKindList) > 0 {
  523. sess.In("central_kitchen_for_school_user_with_day.kind", req.MealKindList)
  524. }
  525. var m []*db.CentralKitchenForSchoolUserRefundDayWithData
  526. _, err := sess.
  527. 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").
  528. 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").
  529. Join("LEFT", "user_identity", "central_kitchen_for_school_user_with_day.identity_id = user_identity.id").
  530. Join("LEFT", "user", "user_identity.uid = user.id").
  531. Join("LEFT", "enterprise", "user_identity.enterprise_id = enterprise.id").
  532. Join("LEFT", "class_with_user", "user_identity.id = class_with_user.user_identity_id").
  533. Join("LEFT", "class", "class_with_user.class_id = class.id").
  534. Join("LEFT", "grade", "class.grade_id = grade.id").
  535. Desc("central_kitchen_for_school_user_refund_day.id").
  536. FindAndCount(&m)
  537. if err != nil {
  538. logx.Error(err)
  539. println("<<<<CentralKitchenForSchoolDataStatisticsExport2>>>>>Error:::", err.Error())
  540. return
  541. }
  542. titleList = []string{"学生姓名", "学校", "年级", "班级", "家长电话", "退款日期", "餐型", "退款金额", "退款状态", "支付时间", "退款操作时间"}
  543. xlsx.SetSheetRow("Sheet1", "A1", &titleList)
  544. j := 2 //表头被第一行用了,只能从第二行开始
  545. for _, v := range m {
  546. var kind string //就餐类型(1:早餐 2:午餐 3:晚餐)
  547. switch v.CentralKitchenForSchoolUserWithDay.Kind {
  548. case enum.CentralKitchenForSchoolUserWithDayKindForBreakfast:
  549. kind = enum.CentralKitchenForSchoolUserWithDayKind.String(enum.CentralKitchenForSchoolUserWithDayKindForBreakfast)
  550. break
  551. case enum.CentralKitchenForSchoolUserWithDayKindForLunch:
  552. kind = enum.CentralKitchenForSchoolUserWithDayKind.String(enum.CentralKitchenForSchoolUserWithDayKindForLunch)
  553. break
  554. case enum.CentralKitchenForSchoolUserWithDayKindForDinner:
  555. kind = enum.CentralKitchenForSchoolUserWithDayKind.String(enum.CentralKitchenForSchoolUserWithDayKindForDinner)
  556. break
  557. }
  558. var state string //状态(1:审核中 2:审核通过 3:审核拒绝 4:退款已完成)
  559. switch v.CentralKitchenForSchoolUserRefundDay.State {
  560. case enum.CentralKitchenForSchoolUserRefundDayStateForAuditing:
  561. state = enum.CentralKitchenForSchoolUserRefundDayState.String(enum.CentralKitchenForSchoolUserRefundDayStateForAuditing)
  562. break
  563. case enum.CentralKitchenForSchoolUserRefundDayStateForAuditPass:
  564. state = enum.CentralKitchenForSchoolUserRefundDayState.String(enum.CentralKitchenForSchoolUserRefundDayStateForAuditPass)
  565. break
  566. case enum.CentralKitchenForSchoolUserRefundDayStateForAuditReject:
  567. state = enum.CentralKitchenForSchoolUserRefundDayState.String(enum.CentralKitchenForSchoolUserRefundDayStateForAuditReject)
  568. break
  569. case enum.CentralKitchenForSchoolUserRefundDayStateForAuditComplete:
  570. state = enum.CentralKitchenForSchoolUserRefundDayState.String(enum.CentralKitchenForSchoolUserRefundDayStateForAuditComplete)
  571. break
  572. }
  573. xlsx.SetSheetRow("Sheet1", "A"+strconv.Itoa(j), &[]interface{}{v.CentralKitchenForSchoolPackageOrd.UserIdentityName, v.Enterprise.Name, v.Grade.Name, v.Class.Name, v.User.Phone,
  574. v.CentralKitchenForSchoolUserWithDay.Date, kind, v.CentralKitchenForSchoolUserRefundDay.Amount, state, v.CentralKitchenForSchoolPackageOrd.CreateAt, v.CentralKitchenForSchoolUserRefundDay.RefundDate})
  575. j++
  576. }
  577. //将文件保存至服务器
  578. xlsx.SaveAs("./static" + downloadPath)
  579. break
  580. case 3:
  581. //学校预定统计表
  582. fileName = "学校预定统计表_" + utils.Int64ToStr(now.UnixMilli()) + ".zip"
  583. downloadPath = "/export/central_kitchen_for_school/" + fileName
  584. var m []*db.CentralKitchenForSchoolPackageOrdForReserveWithUserIdentity
  585. sess := db.Db.Desc("central_kitchen_for_school_package_ord_for_reserve.id")
  586. if req.EnterpriseId != 0 {
  587. sess.And("central_kitchen_for_school_package_ord_for_reserve.enterprise_id =?", req.EnterpriseId)
  588. }
  589. if req.StartDate != "" {
  590. sess.And("central_kitchen_for_school_package_ord_for_reserve.meal_time_start >= ?", req.StartDate)
  591. }
  592. if req.EndDate != "" {
  593. sess.And("central_kitchen_for_school_package_ord_for_reserve.meal_time_start <= ?", req.EndDate)
  594. }
  595. if len(req.MealKindList) > 0 {
  596. sess.In("central_kitchen_for_school_package_ord_for_reserve.kind", req.MealKindList)
  597. }
  598. _, err := sess.
  599. 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").
  600. Join("LEFT", "user_identity", "central_kitchen_for_school_package_ord.user_identity_id = user_identity.id").
  601. Join("LEFT", "enterprise", "enterprise.id = user_identity.enterprise_id").
  602. Join("LEFT", "user", "user.id = user_identity.uid").
  603. Join("LEFT", "class_with_user", "class_with_user.user_identity_id = user_identity.id").
  604. Join("LEFT", "class", "class_with_user.class_id = class.id").
  605. Join("LEFT", "grade", "class.grade_id = grade.id").
  606. FindAndCount(&m)
  607. if err != nil {
  608. logx.Error(err)
  609. println("<<<<SelfSupportForSchoolDataStatisticsExport3>>>>>Error:::", err.Error())
  610. return
  611. }
  612. centralKitchenForSchoolUserWithDayDb := db.CentralKitchenForSchoolUserWithDayDb{}
  613. centralKitchenForSchoolUserWithDayDb.Set(0)
  614. var list = map[string]map[string]map[string]map[string]int64{}
  615. var xlsFileName, xlsDownloadPath []string
  616. for _, v := range m {
  617. if list[v.Enterprise.Name] == nil {
  618. list[v.Enterprise.Name] = make(map[string]map[string]map[string]int64)
  619. }
  620. if list[v.Enterprise.Name][v.Grade.Name] == nil {
  621. list[v.Enterprise.Name][v.Grade.Name] = make(map[string]map[string]int64)
  622. }
  623. if list[v.Enterprise.Name][v.Grade.Name][v.Class.Name] == nil {
  624. list[v.Enterprise.Name][v.Grade.Name][v.Class.Name] = make(map[string]int64)
  625. }
  626. count, err2 := centralKitchenForSchoolUserWithDayDb.CountCentralKitchenForSchoolUserWithDayByOrdNo(v.CentralKitchenForSchoolPackageOrdForReserve.OutTradeNo, enum.CentralKitchenForSchoolUserWithDayStateForCancel)
  627. if err2 != nil {
  628. logx.Error(err)
  629. println("<<<<SelfSupportForSchoolDataStatisticsExport3>>>>>Error:::", err.Error())
  630. return
  631. }
  632. time.Sleep(50 * time.Millisecond) // 50毫秒
  633. if v.CentralKitchenForSchoolPackageOrdForReserve.Kind == enum.CentralKitchenForSchoolUserWithDayKindForBreakfast {
  634. list[v.Enterprise.Name][v.Grade.Name][v.Class.Name]["breakfast"] += count
  635. }
  636. if v.CentralKitchenForSchoolPackageOrdForReserve.Kind == enum.CentralKitchenForSchoolUserWithDayKindForLunch {
  637. list[v.Enterprise.Name][v.Grade.Name][v.Class.Name]["lunch"] += count
  638. }
  639. if v.CentralKitchenForSchoolPackageOrdForReserve.Kind == enum.CentralKitchenForSchoolUserWithDayKindForDinner {
  640. list[v.Enterprise.Name][v.Grade.Name][v.Class.Name]["dinner"] += count
  641. }
  642. }
  643. for k1, v1 := range list {
  644. tmpFileName := k1 + "学校预定统计表_" + utils.Int64ToStr(now.UnixMilli()) + ".xlsx"
  645. tmpDownloadPath := "./static/export/central_kitchen_for_school/" + tmpFileName
  646. titleList = []string{"年级", "班级", "早餐", "午餐", "晚餐"}
  647. xlsx.SetSheetRow("Sheet1", "A1", &titleList)
  648. j := 2 //表头被第一行用了,只能从第二行开始
  649. for k2, v2 := range v1 {
  650. if k2 == "" {
  651. //若年级为空,则为教师餐
  652. k2 = "教师餐"
  653. }
  654. for k3, v3 := range v2 {
  655. if k3 == "" {
  656. //若班级为空,则为教师餐
  657. k3 = "教师餐"
  658. }
  659. xlsx.SetSheetRow("Sheet1", "A"+strconv.Itoa(j), &[]interface{}{
  660. k2, k3, v3["breakfast"], v3["lunch"], v3["dinner"]})
  661. j++
  662. }
  663. }
  664. //将文件保存至服务器
  665. err1 := xlsx.SaveAs(tmpDownloadPath)
  666. if err1 != nil {
  667. logx.Error(err1)
  668. println("<<<<CentralKitchenForSchoolDataStatisticsExport3>>>>>Error:::", err1.Error())
  669. panic(err1)
  670. }
  671. xlsDownloadPath = append(xlsDownloadPath, tmpDownloadPath)
  672. xlsFileName = append(xlsFileName, tmpFileName)
  673. }
  674. archive, err := os.Create("./static" + downloadPath) //第一步,创建 zip 文件
  675. if err != nil {
  676. logx.Error(err)
  677. println("<<<<CentralKitchenForSchoolDataStatisticsExport3>>>>>Error:::", err.Error())
  678. panic(err)
  679. }
  680. defer archive.Close()
  681. zipWriter := zip.NewWriter(archive) //第二步,创建一个新的 *Writer 对象
  682. for k, v := range xlsDownloadPath {
  683. w, err1 := zipWriter.Create("学校预定统计/" + xlsFileName[k]) //向 zip 文件中添加一个文件,返回一个待压缩的文件内容应写入的 Writer
  684. if err1 != nil {
  685. logx.Error(err1)
  686. println("<<<<CentralKitchenForSchoolDataStatisticsExport3>>>>>Error:::", err1.Error())
  687. panic(err1)
  688. }
  689. f, err1 := os.Open(v) //打开待压缩的文件
  690. if err1 != nil {
  691. logx.Error(err1)
  692. println("<<<<CentralKitchenForSchoolDataStatisticsExport3>>>>>Error:::", err1.Error())
  693. panic(err1)
  694. }
  695. if _, err1 = io.Copy(w, f); err != nil {
  696. logx.Error(err1)
  697. println("<<<<CentralKitchenForSchoolDataStatisticsExport3>>>>>Error:::", err1.Error())
  698. panic(err1)
  699. }
  700. if err1 != nil {
  701. logx.Error(err1)
  702. println("<<<<CentralKitchenForSchoolDataStatisticsExport3>>>>>Error:::", err1.Error())
  703. panic(err1)
  704. }
  705. f.Close()
  706. os.RemoveAll(v) //TODO::移除源文件
  707. }
  708. zipWriter.Close() // 第四步,关闭 zip writer,将所有数据写入指向基础 zip 文件的数据流
  709. if err != nil {
  710. panic(err)
  711. }
  712. break
  713. case 4:
  714. //班级明细表
  715. fileName = "班级明细表_" + utils.Int64ToStr(now.UnixMilli()) + ".zip"
  716. downloadPath = "/export/central_kitchen_for_school/" + fileName
  717. var m []*db.CentralKitchenForSchoolPackageOrdForReserveWithUserIdentity
  718. sess := db.Db.Desc("central_kitchen_for_school_package_ord_for_reserve.id")
  719. if req.EnterpriseId != 0 {
  720. sess.And("central_kitchen_for_school_package_ord_for_reserve.enterprise_id =?", req.EnterpriseId)
  721. }
  722. if req.StartDate != "" {
  723. sess.And("central_kitchen_for_school_package_ord_for_reserve.meal_time_start >= ?", req.StartDate)
  724. }
  725. if req.EndDate != "" {
  726. sess.And("central_kitchen_for_school_package_ord_for_reserve.meal_time_start <= ?", req.EndDate)
  727. }
  728. if len(req.MealKindList) > 0 {
  729. sess.In("central_kitchen_for_school_package_ord_for_reserve.kind", req.MealKindList)
  730. }
  731. _, err := sess.
  732. 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").
  733. Join("LEFT", "user_identity", "central_kitchen_for_school_package_ord.user_identity_id = user_identity.id").
  734. Join("LEFT", "enterprise", "enterprise.id = user_identity.enterprise_id").
  735. Join("LEFT", "user", "user.id = user_identity.uid").
  736. Join("LEFT", "class_with_user", "class_with_user.user_identity_id = user_identity.id").
  737. Join("LEFT", "class", "class_with_user.class_id = class.id").
  738. Join("LEFT", "grade", "class.grade_id = grade.id").
  739. FindAndCount(&m)
  740. if err != nil {
  741. logx.Error(err)
  742. println("<<<<CentralKitchenForSchoolDataStatisticsExport4>>>>>Error:::", err.Error())
  743. return
  744. }
  745. var list = map[string]map[string]map[string]map[string]map[string]int64{}
  746. var xlsFileName, xlsDownloadPath []string
  747. centralKitchenForSchoolUserWithDayDb := db.CentralKitchenForSchoolUserWithDayDb{}
  748. centralKitchenForSchoolUserWithDayDb.Set(0)
  749. for _, v := range m {
  750. if list[v.Enterprise.Name] == nil {
  751. list[v.Enterprise.Name] = make(map[string]map[string]map[string]map[string]int64)
  752. }
  753. if list[v.Enterprise.Name][v.Grade.Name] == nil {
  754. list[v.Enterprise.Name][v.Grade.Name] = make(map[string]map[string]map[string]int64)
  755. }
  756. if list[v.Enterprise.Name][v.Grade.Name][v.Class.Name] == nil {
  757. list[v.Enterprise.Name][v.Grade.Name][v.Class.Name] = make(map[string]map[string]int64)
  758. }
  759. if list[v.Enterprise.Name][v.Grade.Name][v.Class.Name][v.UserIdentity.Name] == nil {
  760. list[v.Enterprise.Name][v.Grade.Name][v.Class.Name][v.UserIdentity.Name] = make(map[string]int64)
  761. }
  762. count, err2 := centralKitchenForSchoolUserWithDayDb.CountCentralKitchenForSchoolUserWithDayByOrdNo(v.CentralKitchenForSchoolPackageOrdForReserve.OutTradeNo, enum.CentralKitchenForSchoolUserWithDayStateForCancel)
  763. if err2 != nil {
  764. logx.Error(err)
  765. println("<<<<SelfSupportForSchoolDataStatisticsExport3>>>>>Error:::", err.Error())
  766. return
  767. }
  768. time.Sleep(50 * time.Millisecond) // 50毫秒
  769. if v.CentralKitchenForSchoolPackageOrdForReserve.Kind == enum.CentralKitchenForSchoolUserWithDayKindForBreakfast {
  770. list[v.Enterprise.Name][v.Grade.Name][v.Class.Name][v.UserIdentity.Name]["breakfast"] += count
  771. }
  772. if v.CentralKitchenForSchoolPackageOrdForReserve.Kind == enum.CentralKitchenForSchoolUserWithDayKindForLunch {
  773. list[v.Enterprise.Name][v.Grade.Name][v.Class.Name][v.UserIdentity.Name]["lunch"] += count
  774. }
  775. if v.CentralKitchenForSchoolPackageOrdForReserve.Kind == enum.CentralKitchenForSchoolUserWithDayKindForDinner {
  776. list[v.Enterprise.Name][v.Grade.Name][v.Class.Name][v.UserIdentity.Name]["dinner"] += count
  777. }
  778. }
  779. for k1, v1 := range list {
  780. tmpFileName := k1 + "班级明细_" + utils.Int64ToStr(now.UnixMilli()) + ".xlsx"
  781. tmpDownloadPath := "./static/export/central_kitchen_for_school/" + tmpFileName
  782. for k2, v2 := range v1 {
  783. if k2 == "" {
  784. //若年级为空,则为教师餐
  785. continue
  786. }
  787. for k3, v3 := range v2 {
  788. titleList = []string{"姓名", "早餐", "午餐", "晚餐"}
  789. xlsx.NewSheet(k3)
  790. xlsx.SetSheetRow(k3, "A1", &titleList)
  791. j := 2 //表头被第一行用了,只能从第二行开始
  792. for k4, v4 := range v3 {
  793. xlsx.SetSheetRow(k3, "A"+strconv.Itoa(j), &[]interface{}{
  794. k4, v4["breakfast"], v4["lunch"], v4["dinner"]})
  795. j++
  796. }
  797. }
  798. }
  799. //将文件保存至服务器
  800. xlsx.DeleteSheet("Sheet1") //TODO::只能放这里删除
  801. err1 := xlsx.SaveAs(tmpDownloadPath)
  802. if err1 != nil {
  803. logx.Error(err1)
  804. println("<<<<CentralKitchenForSchoolDataStatisticsExport4>>>>>Error:::", err1.Error())
  805. panic(err1)
  806. }
  807. xlsDownloadPath = append(xlsDownloadPath, tmpDownloadPath)
  808. xlsFileName = append(xlsFileName, tmpFileName)
  809. }
  810. archive, err := os.Create("./static" + downloadPath) //第一步,创建 zip 文件
  811. if err != nil {
  812. logx.Error(err)
  813. println("<<<<CentralKitchenForSchoolDataStatisticsExport4>>>>>Error:::", err.Error())
  814. panic(err)
  815. }
  816. defer archive.Close()
  817. zipWriter := zip.NewWriter(archive) //第二步,创建一个新的 *Writer 对象
  818. for k, v := range xlsDownloadPath {
  819. w, err1 := zipWriter.Create("班级明细/" + xlsFileName[k]) //向 zip 文件中添加一个文件,返回一个待压缩的文件内容应写入的 Writer
  820. if err1 != nil {
  821. logx.Error(err1)
  822. println("<<<<CentralKitchenForSchoolDataStatisticsExport4>>>>>Error:::", err1.Error())
  823. panic(err1)
  824. }
  825. f, err1 := os.Open(v) //打开待压缩的文件
  826. if err1 != nil {
  827. logx.Error(err1)
  828. println("<<<<CentralKitchenForSchoolDataStatisticsExport4>>>>>Error:::", err1.Error())
  829. panic(err1)
  830. }
  831. if _, err1 = io.Copy(w, f); err != nil {
  832. logx.Error(err1)
  833. println("<<<<CentralKitchenForSchoolDataStatisticsExport4>>>>>Error:::", err1.Error())
  834. panic(err1)
  835. }
  836. if err1 != nil {
  837. logx.Error(err1)
  838. println("<<<<CentralKitchenForSchoolDataStatisticsExport4>>>>>Error:::", err1.Error())
  839. panic(err1)
  840. }
  841. f.Close()
  842. os.RemoveAll(v) //TODO::移除源文件
  843. }
  844. zipWriter.Close() // 第四步,关闭 zip writer,将所有数据写入指向基础 zip 文件的数据流
  845. if err != nil {
  846. panic(err)
  847. }
  848. break
  849. case 5:
  850. //退款明细表
  851. fileName = "退款明细表_" + utils.Int64ToStr(now.UnixMilli()) + ".zip"
  852. downloadPath = "/export/central_kitchen_for_school/" + fileName
  853. sess := db.Db.Where("central_kitchen_for_school_user_refund_day.state =?", enum.CentralKitchenForSchoolUserRefundDayStateForAuditComplete).Desc("central_kitchen_for_school_user_refund_day.id")
  854. if req.EnterpriseId != 0 {
  855. sess.And("enterprise.id =?", req.EnterpriseId)
  856. }
  857. if req.StartDate != "" {
  858. sess.And("central_kitchen_for_school_user_refund_day.create_at >= ?", req.StartDate)
  859. }
  860. if req.EndDate != "" {
  861. sess.And("central_kitchen_for_school_user_refund_day.create_at <= ?", req.EndDate)
  862. }
  863. if len(req.MealKindList) > 0 {
  864. sess.In("central_kitchen_for_school_user_with_day.kind", req.MealKindList)
  865. }
  866. var m []*db.CentralKitchenForSchoolUserRefundDayWithData
  867. _, err := sess.
  868. 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").
  869. 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").
  870. Join("LEFT", "user_identity", "central_kitchen_for_school_user_with_day.identity_id = user_identity.id").
  871. Join("LEFT", "user", "user_identity.uid = user.id").
  872. Join("LEFT", "enterprise", "user_identity.enterprise_id = enterprise.id").
  873. Join("LEFT", "class_with_user", "user_identity.id = class_with_user.user_identity_id").
  874. Join("LEFT", "class", "class_with_user.class_id = class.id").
  875. Join("LEFT", "grade", "class.grade_id = grade.id").
  876. Desc("central_kitchen_for_school_user_refund_day.id").
  877. FindAndCount(&m)
  878. if err != nil {
  879. logx.Error(err)
  880. println("<<<<CentralKitchenForSchoolDataStatisticsExport5>>>>>Error:::", err.Error())
  881. return
  882. }
  883. var list = map[string]map[string]map[string]map[string]map[string]int{}
  884. var xlsFileName, xlsDownloadPath []string
  885. for _, v := range m {
  886. if list[v.Enterprise.Name] == nil {
  887. list[v.Enterprise.Name] = make(map[string]map[string]map[string]map[string]int)
  888. }
  889. if list[v.Enterprise.Name][v.Grade.Name] == nil {
  890. list[v.Enterprise.Name][v.Grade.Name] = make(map[string]map[string]map[string]int)
  891. }
  892. if list[v.Enterprise.Name][v.Grade.Name][v.Class.Name] == nil {
  893. list[v.Enterprise.Name][v.Grade.Name][v.Class.Name] = make(map[string]map[string]int)
  894. }
  895. if list[v.Enterprise.Name][v.Grade.Name][v.Class.Name][v.UserIdentity.Name] == nil {
  896. list[v.Enterprise.Name][v.Grade.Name][v.Class.Name][v.UserIdentity.Name] = make(map[string]int)
  897. }
  898. //就餐类型(1:早餐 2:午餐 3:晚餐)
  899. if v.CentralKitchenForSchoolUserWithDay.Kind == enum.CentralKitchenForSchoolUserWithDayKindForBreakfast {
  900. list[v.Enterprise.Name][v.Grade.Name][v.Class.Name][v.UserIdentity.Name]["breakfast"]++
  901. }
  902. if v.CentralKitchenForSchoolUserWithDay.Kind == enum.CentralKitchenForSchoolUserWithDayKindForLunch {
  903. list[v.Enterprise.Name][v.Grade.Name][v.Class.Name][v.UserIdentity.Name]["lunch"]++
  904. }
  905. if v.CentralKitchenForSchoolUserWithDay.Kind == enum.CentralKitchenForSchoolUserWithDayKindForDinner {
  906. list[v.Enterprise.Name][v.Grade.Name][v.Class.Name][v.UserIdentity.Name]["dinner"]++
  907. }
  908. }
  909. for k1, v1 := range list {
  910. tmpFileName := k1 + "退款明细_" + utils.Int64ToStr(now.UnixMilli()) + ".xlsx"
  911. tmpDownloadPath := "./static/export/central_kitchen_for_school/" + tmpFileName
  912. for k2, v2 := range v1 {
  913. if k2 == "" {
  914. //若年级为空,则为教师餐
  915. continue
  916. }
  917. for k3, v3 := range v2 {
  918. titleList = []string{"姓名", "早餐", "午餐", "晚餐"}
  919. xlsx.NewSheet(k3)
  920. xlsx.SetSheetRow(k3, "A1", &titleList)
  921. j := 2 //表头被第一行用了,只能从第二行开始
  922. for k4, v4 := range v3 {
  923. xlsx.SetSheetRow(k3, "A"+strconv.Itoa(j), &[]interface{}{
  924. k4, v4["breakfast"], v4["lunch"], v4["dinner"]})
  925. j++
  926. }
  927. }
  928. }
  929. //将文件保存至服务器
  930. xlsx.DeleteSheet("Sheet1") //TODO::只能放这里删除
  931. err1 := xlsx.SaveAs(tmpDownloadPath)
  932. if err1 != nil {
  933. logx.Error(err1)
  934. println("<<<<CentralKitchenForSchoolDataStatisticsExport5>>>>>Error:::", err1.Error())
  935. panic(err1)
  936. }
  937. xlsDownloadPath = append(xlsDownloadPath, tmpDownloadPath)
  938. xlsFileName = append(xlsFileName, tmpFileName)
  939. }
  940. archive, err := os.Create("./static" + downloadPath) //第一步,创建 zip 文件
  941. if err != nil {
  942. logx.Error(err)
  943. println("<<<<CentralKitchenForSchoolDataStatisticsExport5>>>>>Error:::", err.Error())
  944. panic(err)
  945. }
  946. defer archive.Close()
  947. zipWriter := zip.NewWriter(archive) //第二步,创建一个新的 *Writer 对象
  948. for k, v := range xlsDownloadPath {
  949. w, err1 := zipWriter.Create("退款明细/" + xlsFileName[k]) //向 zip 文件中添加一个文件,返回一个待压缩的文件内容应写入的 Writer
  950. if err1 != nil {
  951. logx.Error(err1)
  952. println("<<<<CentralKitchenForSchoolDataStatisticsExport5>>>>>Error:::", err1.Error())
  953. panic(err1)
  954. }
  955. f, err1 := os.Open(v) //打开待压缩的文件
  956. if err1 != nil {
  957. logx.Error(err1)
  958. println("<<<<CentralKitchenForSchoolDataStatisticsExport5>>>>>Error:::", err1.Error())
  959. panic(err1)
  960. }
  961. if _, err1 = io.Copy(w, f); err != nil {
  962. logx.Error(err1)
  963. println("<<<<CentralKitchenForSchoolDataStatisticsExport5>>>>>Error:::", err1.Error())
  964. panic(err1)
  965. }
  966. if err1 != nil {
  967. logx.Error(err1)
  968. println("<<<<CentralKitchenForSchoolDataStatisticsExport5>>>>>Error:::", err1.Error())
  969. panic(err1)
  970. }
  971. f.Close()
  972. os.RemoveAll(v) //TODO::移除源文件
  973. }
  974. zipWriter.Close() // 第四步,关闭 zip writer,将所有数据写入指向基础 zip 文件的数据流
  975. if err != nil {
  976. panic(err)
  977. }
  978. break
  979. case 6:
  980. //收款统计表
  981. fileName = "收款统计表_" + utils.Int64ToStr(now.UnixMilli()) + ".xlsx"
  982. downloadPath = "/export/central_kitchen_for_school/" + fileName
  983. //查找数据
  984. var m []model.Enterprise
  985. sess := db.Db.Desc("id")
  986. if req.EnterpriseId != 0 {
  987. sess.And("id = ?", req.EnterpriseId)
  988. }
  989. err := sess.Find(&m)
  990. if err != nil {
  991. logx.Error(err)
  992. println("<<<<CentralKitchenForSchoolDataStatisticsExport6>>>>>Error:::", err.Error())
  993. return
  994. }
  995. titleList = []string{"学校名称", "预定总费用", "退款总计", "实收费用", "预估费率"}
  996. xlsx.SetSheetRow("Sheet1", "A1", &titleList)
  997. j := 2 //表头被第一行用了,只能从第二行开始
  998. for _, v := range m {
  999. var income, refund string
  1000. //统计收入
  1001. 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)
  1002. mapArr1, err := db.QueryNativeString(db.Db, sql1)
  1003. if err != nil {
  1004. logx.Error(err)
  1005. println("<<<<CentralKitchenForSchoolDataStatisticsExport6>>>>>Error:::", err.Error())
  1006. return
  1007. }
  1008. if mapArr1 != nil {
  1009. income = mapArr1[0]["total"]
  1010. }
  1011. //统计退款
  1012. //查询出当前学校下所有的学生
  1013. userIdentityDb := db.UserIdentityDb{}
  1014. userIdentityDb.Set(0)
  1015. userIdentities, _ := userIdentityDb.FindUserIdentityForEnterprise(v.Id)
  1016. var userIdentityIds []string
  1017. for _, v := range *userIdentities {
  1018. userIdentityIds = append(userIdentityIds, utils.IntToStr(v.Id))
  1019. }
  1020. if len(userIdentityIds) != 0 {
  1021. userIdentityStr := php2go.Implode(",", userIdentityIds)
  1022. 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'",
  1023. enum.CentralKitchenForSchoolUserRefundDayStateForAuditComplete, userIdentityStr, req.StartDate, req.EndDate)
  1024. mapArr2, err := db.QueryNativeString(db.Db, sql2)
  1025. if err != nil {
  1026. logx.Error(err)
  1027. println("<<<<CentralKitchenForSchoolDataStatisticsExport6>>>>>Error:::", err.Error())
  1028. return
  1029. }
  1030. if mapArr2 != nil {
  1031. refund = mapArr2[0]["total"]
  1032. }
  1033. }
  1034. realityAmount := utils.StrToFloat64(income) - utils.StrToFloat64(refund)
  1035. rateFee := realityAmount * 0.0038
  1036. xlsx.SetSheetRow("Sheet1", "A"+strconv.Itoa(j), &[]interface{}{v.Name, income, refund, realityAmount, rateFee})
  1037. j++
  1038. }
  1039. //将文件保存至服务器
  1040. xlsx.SaveAs("./static" + downloadPath)
  1041. break
  1042. case 7:
  1043. //班级收款明细表
  1044. fileName = "班级收款明细表_" + utils.Int64ToStr(now.UnixMilli()) + ".zip"
  1045. downloadPath = "/export/central_kitchen_for_school/" + fileName
  1046. //查找订单数据
  1047. sess := db.Db.Desc("central_kitchen_for_school_package_ord.id")
  1048. sess.And("central_kitchen_for_school_package_ord.state =?", enum.CentralKitchenForSchoolPackageOrdStateForSuccess)
  1049. if req.EnterpriseId != 0 {
  1050. sess.And("central_kitchen_for_school_package_ord.enterprise_id =?", req.EnterpriseId)
  1051. }
  1052. if req.StartDate != "" {
  1053. sess.And("central_kitchen_for_school_package_ord.create_at >= ?", req.StartDate)
  1054. }
  1055. if req.EndDate != "" {
  1056. sess.And("central_kitchen_for_school_package_ord.create_at <= ?", req.EndDate)
  1057. }
  1058. var m []*db.CentralKitchenForSchoolPackageOrdWithUserIdentity
  1059. _, err := sess.
  1060. Join("LEFT", "user_identity", "central_kitchen_for_school_package_ord.user_identity_id = user_identity.id").
  1061. Join("LEFT", "enterprise", "enterprise.id = user_identity.enterprise_id").
  1062. Join("LEFT", "user", "user.id = user_identity.uid").
  1063. Join("LEFT", "class_with_user", "class_with_user.user_identity_id = user_identity.id").
  1064. Join("LEFT", "class", "class_with_user.class_id = class.id").
  1065. Join("LEFT", "grade", "class.grade_id = grade.id").
  1066. FindAndCount(&m)
  1067. if err != nil {
  1068. logx.Error(err)
  1069. println("<<<<CentralKitchenForSchoolDataStatisticsExport7>>>>>Error:::", err.Error())
  1070. return
  1071. }
  1072. sess1 := db.Db.Where("central_kitchen_for_school_user_refund_day.state =?", enum.CentralKitchenForSchoolUserRefundDayStateForAuditComplete).Desc("central_kitchen_for_school_user_refund_day.id")
  1073. if req.EnterpriseId != 0 {
  1074. sess1.And("enterprise.id =?", req.EnterpriseId)
  1075. }
  1076. if req.StartDate != "" {
  1077. sess1.And("central_kitchen_for_school_user_refund_day.create_at >= ?", req.StartDate)
  1078. }
  1079. if req.EndDate != "" {
  1080. sess1.And("central_kitchen_for_school_user_refund_day.create_at <= ?", req.EndDate)
  1081. }
  1082. var mm []*db.CentralKitchenForSchoolUserRefundDayWithData
  1083. _, err = sess1.
  1084. 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").
  1085. 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").
  1086. Join("LEFT", "user_identity", "central_kitchen_for_school_user_with_day.identity_id = user_identity.id").
  1087. Join("LEFT", "user", "user_identity.uid = user.id").
  1088. Join("LEFT", "enterprise", "user_identity.enterprise_id = enterprise.id").
  1089. Join("LEFT", "class_with_user", "user_identity.id = class_with_user.user_identity_id").
  1090. Join("LEFT", "class", "class_with_user.class_id = class.id").
  1091. Join("LEFT", "grade", "class.grade_id = grade.id").
  1092. Desc("central_kitchen_for_school_user_refund_day.id").
  1093. FindAndCount(&mm)
  1094. if err != nil {
  1095. logx.Error(err)
  1096. println("<<<<CentralKitchenForSchoolDataStatisticsExport7>>>>>Error:::", err.Error())
  1097. return
  1098. }
  1099. var list = map[string]map[string]map[string]map[string]float64{}
  1100. for _, v := range m {
  1101. if list[v.Enterprise.Name] == nil {
  1102. list[v.Enterprise.Name] = make(map[string]map[string]map[string]float64)
  1103. }
  1104. if list[v.Enterprise.Name][v.Grade.Name] == nil {
  1105. list[v.Enterprise.Name][v.Grade.Name] = make(map[string]map[string]float64)
  1106. }
  1107. if list[v.Enterprise.Name][v.Grade.Name][v.Class.Name] == nil {
  1108. list[v.Enterprise.Name][v.Grade.Name][v.Class.Name] = make(map[string]float64)
  1109. }
  1110. list[v.Enterprise.Name][v.Grade.Name][v.Class.Name]["income"] += utils.StrToFloat64(v.CentralKitchenForSchoolPackageOrd.TotalPrice)
  1111. }
  1112. for _, v := range mm {
  1113. if list[v.Enterprise.Name] == nil {
  1114. list[v.Enterprise.Name] = make(map[string]map[string]map[string]float64)
  1115. }
  1116. if list[v.Enterprise.Name][v.Grade.Name] == nil {
  1117. list[v.Enterprise.Name][v.Grade.Name] = make(map[string]map[string]float64)
  1118. }
  1119. if list[v.Enterprise.Name][v.Grade.Name][v.Class.Name] == nil {
  1120. list[v.Enterprise.Name][v.Grade.Name][v.Class.Name] = make(map[string]float64)
  1121. }
  1122. list[v.Enterprise.Name][v.Grade.Name][v.Class.Name]["refund"] += utils.StrToFloat64(v.CentralKitchenForSchoolUserRefundDay.Amount)
  1123. }
  1124. var xlsFileName, xlsDownloadPath []string
  1125. for k1, v1 := range list {
  1126. tmpFileName := k1 + "班级收款明细_" + utils.Int64ToStr(now.UnixMilli()) + ".xlsx"
  1127. tmpDownloadPath := "./static/export/central_kitchen_for_school/" + tmpFileName
  1128. titleList = []string{"年级", "班级", "预定总费用", "退款总计"}
  1129. xlsx.SetSheetRow("Sheet1", "A1", &titleList)
  1130. j := 2 //表头被第一行用了,只能从第二行开始
  1131. for k2, v2 := range v1 {
  1132. if k2 == "" {
  1133. //若年级为空,则为教师餐
  1134. continue
  1135. }
  1136. for k3, v3 := range v2 {
  1137. xlsx.SetSheetRow("Sheet1", "A"+strconv.Itoa(j), &[]interface{}{k2, k3, utils.Float64ToStr(v3["income"]), utils.Float64ToStr(v3["refund"])})
  1138. j++
  1139. }
  1140. }
  1141. //将文件保存至服务器
  1142. err1 := xlsx.SaveAs(tmpDownloadPath)
  1143. if err1 != nil {
  1144. logx.Error(err1)
  1145. println("<<<<CentralKitchenForSchoolDataStatisticsExport7>>>>>Error:::", err1.Error())
  1146. panic(err1)
  1147. }
  1148. xlsDownloadPath = append(xlsDownloadPath, tmpDownloadPath)
  1149. xlsFileName = append(xlsFileName, tmpFileName)
  1150. }
  1151. archive, err := os.Create("./static" + downloadPath) //第一步,创建 zip 文件
  1152. if err != nil {
  1153. logx.Error(err)
  1154. println("<<<<CentralKitchenForSchoolDataStatisticsExport7>>>>>Error:::", err.Error())
  1155. panic(err)
  1156. }
  1157. defer archive.Close()
  1158. zipWriter := zip.NewWriter(archive) //第二步,创建一个新的 *Writer 对象
  1159. for k, v := range xlsDownloadPath {
  1160. w, err1 := zipWriter.Create("班级收款明细/" + xlsFileName[k]) //向 zip 文件中添加一个文件,返回一个待压缩的文件内容应写入的 Writer
  1161. if err1 != nil {
  1162. logx.Error(err1)
  1163. println("<<<<CentralKitchenForSchoolDataStatisticsExport7>>>>>Error:::", err1.Error())
  1164. panic(err1)
  1165. }
  1166. f, err1 := os.Open(v) //打开待压缩的文件
  1167. if err1 != nil {
  1168. logx.Error(err1)
  1169. println("<<<<CentralKitchenForSchoolDataStatisticsExport7>>>>>Error:::", err1.Error())
  1170. panic(err1)
  1171. }
  1172. if _, err1 = io.Copy(w, f); err != nil {
  1173. logx.Error(err1)
  1174. println("<<<<CentralKitchenForSchoolDataStatisticsExport7>>>>>Error:::", err1.Error())
  1175. panic(err1)
  1176. }
  1177. if err1 != nil {
  1178. logx.Error(err1)
  1179. println("<<<<CentralKitchenForSchoolDataStatisticsExport7>>>>>Error:::", err1.Error())
  1180. panic(err1)
  1181. }
  1182. f.Close()
  1183. os.RemoveAll(v) //TODO::移除源文件
  1184. }
  1185. zipWriter.Close() // 第四步,关闭 zip writer,将所有数据写入指向基础 zip 文件的数据流
  1186. if err != nil {
  1187. panic(err)
  1188. }
  1189. break
  1190. case 8:
  1191. //学校预定数量统计表
  1192. fileName = "学校预定数量统计表_" + utils.Int64ToStr(now.UnixMilli()) + ".xlsx"
  1193. downloadPath = "/export/central_kitchen_for_school/" + fileName
  1194. var m []*db.CentralKitchenForSchoolPackageOrdForReserveWithUserIdentity
  1195. sess := db.Db.Desc("central_kitchen_for_school_package_ord_for_reserve.id")
  1196. if req.EnterpriseId != 0 {
  1197. sess.And("central_kitchen_for_school_package_ord_for_reserve.enterprise_id =?", req.EnterpriseId)
  1198. }
  1199. if req.StartDate != "" {
  1200. sess.And("central_kitchen_for_school_package_ord_for_reserve.meal_time_start >= ?", req.StartDate)
  1201. }
  1202. if req.EndDate != "" {
  1203. sess.And("central_kitchen_for_school_package_ord_for_reserve.meal_time_start <= ?", req.EndDate)
  1204. }
  1205. if len(req.MealKindList) > 0 {
  1206. sess.In("central_kitchen_for_school_package_ord_for_reserve.kind", req.MealKindList)
  1207. }
  1208. _, err := sess.
  1209. 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").
  1210. Join("LEFT", "user_identity", "central_kitchen_for_school_package_ord.user_identity_id = user_identity.id").
  1211. Join("LEFT", "enterprise", "enterprise.id = user_identity.enterprise_id").
  1212. FindAndCount(&m)
  1213. if err != nil {
  1214. logx.Error(err)
  1215. println("<<<<SelfSupportForSchoolDataStatisticsExport3>>>>>Error:::", err.Error())
  1216. return
  1217. }
  1218. var list = map[string]int64{}
  1219. centralKitchenForSchoolUserWithDayDb := db.CentralKitchenForSchoolUserWithDayDb{}
  1220. centralKitchenForSchoolUserWithDayDb.Set(0)
  1221. for _, v := range m {
  1222. count, err2 := centralKitchenForSchoolUserWithDayDb.CountCentralKitchenForSchoolUserWithDayByOrdNo(v.CentralKitchenForSchoolPackageOrdForReserve.OutTradeNo, enum.CentralKitchenForSchoolUserWithDayStateForCancel)
  1223. if err2 != nil {
  1224. logx.Error(err)
  1225. println("<<<<SelfSupportForSchoolDataStatisticsExport3>>>>>Error:::", err.Error())
  1226. return
  1227. }
  1228. time.Sleep(50 * time.Millisecond) // 50毫秒
  1229. list[v.Enterprise.Name] += count
  1230. }
  1231. titleList = []string{"学校名称", "预定总数"}
  1232. xlsx.SetSheetRow("Sheet1", "A1", &titleList)
  1233. j := 2 //表头被第一行用了,只能从第二行开始
  1234. for k, v := range list {
  1235. xlsx.SetSheetRow("Sheet1", "A"+strconv.Itoa(j), &[]interface{}{k, v})
  1236. j++
  1237. }
  1238. //将文件保存至服务器
  1239. xlsx.SaveAs("./static" + downloadPath)
  1240. break
  1241. }
  1242. //新增数据
  1243. centralKitchenForSchoolExportRecordsDb := db.CentralKitchenForSchoolExportRecordsDb{}
  1244. centralKitchenForSchoolExportRecordsDb.Set()
  1245. marshal, _ := json.Marshal(req)
  1246. centralKitchenForSchoolExportRecordsDb.CentralKitchenForSchoolExportRecordsInsert(&model.CentralKitchenForSchoolExportRecords{
  1247. Name: fileName,
  1248. DownloadPath: downloadPath,
  1249. Kind: req.Kind,
  1250. ReqContent: string(marshal),
  1251. CreateAt: now.Format("2006-01-02 15:04:05"),
  1252. UpdateAt: now.Format("2006-01-02 15:04:05"),
  1253. })
  1254. }
  1255. func JudgeSelfSupportForMealTime(mealDate string) (mealZh string) {
  1256. mealZh = "未知"
  1257. mealTime, _ := time.ParseInLocation("2006-01-02 15:04:05", mealDate, time.Local)
  1258. for _, v := range md.SelfSupportForMealTimeMapping {
  1259. //判断时间大小
  1260. tmpFromTime, _ := time.ParseInLocation("2006-01-02 15:04:05", mealTime.Format("2006-01-02")+" "+v["from"]+":00", time.Local)
  1261. tmpToTime, _ := time.ParseInLocation("2006-01-02 15:04:05", mealTime.Format("2006-01-02")+" "+v["to"]+":00", time.Local)
  1262. fmt.Println(">>>>>>>>>>>>>", mealTime.After(tmpFromTime))
  1263. fmt.Println("<<<<<<<<<<<<<", mealTime.Before(tmpToTime))
  1264. if mealTime.After(tmpFromTime) && mealTime.Before(tmpToTime) {
  1265. mealZh = v["name"]
  1266. }
  1267. }
  1268. return
  1269. }