智慧食堂
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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