面包店
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 

408 行
12 KiB

  1. package svc
  2. import (
  3. md2 "applet/app/admin/md"
  4. "applet/app/admin/svc/order"
  5. "applet/app/bigData/md"
  6. "applet/app/db"
  7. "applet/app/db/model"
  8. "applet/app/utils"
  9. "encoding/json"
  10. "time"
  11. )
  12. func LeftDataForMake() (resp []md.LeftDataForMakeResp, err error) {
  13. //now := time.Now()
  14. //startDate := now.Format("2006-01-02") + " 00:00:00"
  15. //endDate := now.AddDate(0, 0, 1).Format("2006-01-02") + " 00:00:00"
  16. //engine := db.Db
  17. //var enterprise []model.Enterprise
  18. //err = engine.Where("1=1").Find(&enterprise)
  19. //if err != nil {
  20. // return
  21. //}
  22. //var enterpriseMap = map[int]model.Enterprise{}
  23. //for _, v := range enterprise {
  24. // enterpriseMap[v.Id] = v
  25. //}
  26. //
  27. ////1、查找当天的 order 数据(大于 待制作)
  28. //var orders []model.Order
  29. //err = engine.Where("create_at >= ?", startDate).And("create_at < ?", endDate).And("state > ? and state != 5", 0).Find(&orders)
  30. //if err != nil {
  31. // return
  32. //}
  33. //var oIds []int64
  34. //for _, v := range orders {
  35. // oIds = append(oIds, v.Oid)
  36. //}
  37. //
  38. ////2、查找对应的订单产品记录
  39. //var orderGoods []model.OrderGoods
  40. //err = engine.In("oid", oIds).Find(&orderGoods)
  41. //if err != nil {
  42. // return
  43. //}
  44. //var orderGoodsMap = map[int64][]model.OrderGoods{}
  45. //var records []int
  46. //for _, v := range orderGoods {
  47. // if orderGoodsMap[v.Oid] == nil {
  48. // orderGoodsMap[v.Oid] = []model.OrderGoods{}
  49. // }
  50. // orderGoodsMap[v.Oid] = append(orderGoodsMap[v.Oid], v)
  51. // records = append(records, v.Id)
  52. //}
  53. //
  54. ////3、用户订单商品操作流程
  55. //var orderGoodsDoingFlows []model.OrderGoodsDoingFlow
  56. //err = engine.Where("state = 2").In("record_id", records).Find(&orderGoodsDoingFlows)
  57. //if err != nil {
  58. // return
  59. //}
  60. //var orderGoodsDoingFlowsMap = map[int]model.OrderGoodsDoingFlow{}
  61. //for _, v := range orderGoodsDoingFlows {
  62. // orderGoodsDoingFlowsMap[v.RecordId] = v
  63. //}
  64. //
  65. ////4、整合数据
  66. //orderStateArr := []string{"待制作", "制作中", "烘焙完成", "分拣完成", "已取消"}
  67. //for _, v := range orders {
  68. // var list []md.LeftDataForMakeList
  69. // if len(orderGoodsMap[v.Oid]) > 0 {
  70. // orderGoodsStateArr := []string{"待制作", "制作中"}
  71. // for _, vv := range orderGoodsMap[v.Oid] {
  72. // skuData := make([]md2.Sku, 0)
  73. // json.Unmarshal([]byte(vv.Sku), &skuData)
  74. // skuStr := ""
  75. // for _, v1 := range skuData {
  76. // if skuStr != "" {
  77. // skuStr += ";"
  78. // }
  79. // skuStr += v1.Value
  80. // }
  81. // var stateZh = "已完成"
  82. // if vv.State <= 1 {
  83. // stateZh = orderGoodsStateArr[vv.State]
  84. // }
  85. // list = append(list, md.LeftDataForMakeList{
  86. // GoodsName: vv.GoodsTitle,
  87. // Sku: skuStr,
  88. // Num: vv.Num,
  89. // SuccessNum: orderGoodsDoingFlowsMap[vv.Id].SuccessNum,
  90. // StateZh: stateZh,
  91. // State: vv.State,
  92. // })
  93. // }
  94. //
  95. // resp = append(resp, md.LeftDataForMakeResp{
  96. // EnterpriseName: enterpriseMap[v.EnterpriseId].Name,
  97. // EnterpriseId: v.EnterpriseId,
  98. // StateZh: orderStateArr[v.State],
  99. // State: v.State,
  100. // List: list,
  101. // })
  102. // }
  103. //}
  104. return
  105. }
  106. func LeftDataForBaking() (resp []md.LeftDataForMakeResp, err error) {
  107. //now := time.Now()
  108. //startDate := now.Format("2006-01-02") + " 00:00:00"
  109. //endDate := now.AddDate(0, 0, 1).Format("2006-01-02") + " 00:00:00"
  110. //engine := db.Db
  111. //var enterprise []model.Enterprise
  112. //err = engine.Where("1=1").Find(&enterprise)
  113. //if err != nil {
  114. // return
  115. //}
  116. //var enterpriseMap = map[int]model.Enterprise{}
  117. //for _, v := range enterprise {
  118. // enterpriseMap[v.Id] = v
  119. //}
  120. //
  121. ////1、查找当天的 order 数据(大于 待制作)
  122. //var orders []model.Order
  123. //err = engine.Where("create_at >= ?", startDate).And("create_at < ?", endDate).And("state > ? and state != 5", 1).Find(&orders)
  124. //if err != nil {
  125. // return
  126. //}
  127. //var oIds []int64
  128. //for _, v := range orders {
  129. // oIds = append(oIds, v.Oid)
  130. //}
  131. //
  132. ////2、查找对应的订单产品记录
  133. //var orderGoods []model.OrderGoods
  134. //err = engine.In("oid", oIds).Find(&orderGoods)
  135. //if err != nil {
  136. // return
  137. //}
  138. //var orderGoodsMap = map[int64][]model.OrderGoods{}
  139. //var records []int
  140. //for _, v := range orderGoods {
  141. // if orderGoodsMap[v.Oid] == nil {
  142. // orderGoodsMap[v.Oid] = []model.OrderGoods{}
  143. // }
  144. // orderGoodsMap[v.Oid] = append(orderGoodsMap[v.Oid], v)
  145. // records = append(records, v.Id)
  146. //}
  147. //
  148. ////3、用户订单商品操作流程
  149. //var orderGoodsDoingFlows []model.OrderGoodsDoingFlow
  150. //err = engine.Where("state = 2").In("record_id", records).Find(&orderGoodsDoingFlows)
  151. //if err != nil {
  152. // return
  153. //}
  154. //var orderGoodsDoingFlowsMap = map[int]model.OrderGoodsDoingFlow{}
  155. //for _, v := range orderGoodsDoingFlows {
  156. // orderGoodsDoingFlowsMap[v.RecordId] = v
  157. //}
  158. //
  159. ////4、整合数据
  160. //orderStateArr := []string{"待制作", "制作中", "制作完成", "烘焙完成", "分拣完成", "已取消"}
  161. //for _, v := range orders {
  162. // var list []md.LeftDataForMakeList
  163. // if len(orderGoodsMap[v.Oid]) > 0 {
  164. // for _, vv := range orderGoodsMap[v.Oid] {
  165. // skuData := make([]md2.Sku, 0)
  166. // json.Unmarshal([]byte(vv.Sku), &skuData)
  167. // skuStr := ""
  168. // for _, v1 := range skuData {
  169. // if skuStr != "" {
  170. // skuStr += ";"
  171. // }
  172. // skuStr += v1.Value
  173. // }
  174. // var stateZh = "已完成"
  175. // if vv.State == 2 {
  176. // stateZh = "烘焙中"
  177. // }
  178. //
  179. // list = append(list, md.LeftDataForMakeList{
  180. // GoodsName: vv.GoodsTitle,
  181. // Sku: skuStr,
  182. // Num: vv.Num,
  183. // SuccessNum: orderGoodsDoingFlowsMap[vv.Id].SuccessNum,
  184. // StateZh: stateZh,
  185. // State: vv.State,
  186. // })
  187. // }
  188. //
  189. // resp = append(resp, md.LeftDataForMakeResp{
  190. // EnterpriseName: enterpriseMap[v.EnterpriseId].Name,
  191. // EnterpriseId: v.EnterpriseId,
  192. // StateZh: orderStateArr[v.State],
  193. // State: v.State,
  194. // List: list,
  195. // })
  196. // }
  197. //}
  198. return
  199. }
  200. func LeftDataForSorting() (resp []md.LeftDataForMakeResp, err error) {
  201. engine := db.Db
  202. var enterprise []model.Enterprise
  203. err = engine.Where("1=1").Find(&enterprise)
  204. if err != nil {
  205. return
  206. }
  207. var enterpriseMap = map[int]model.Enterprise{}
  208. for _, v := range enterprise {
  209. enterpriseMap[v.Id] = v
  210. }
  211. //1、查找不等于4 5
  212. today := utils.GetTimeRange("today")
  213. if time.Now().Hour() < 2 {
  214. today = utils.GetTimeRange("yesterday")
  215. }
  216. var orders []model.Order
  217. err = engine.Where(" state != 4 and state != 5 and create_at>=?", time.Unix(today["start"], 0).Format("2006-01-02 15:04:05")).Find(&orders)
  218. if err != nil {
  219. return
  220. }
  221. var oIds []int64
  222. for _, v := range orders {
  223. v1 := order.JudgePackageOrdOrdState(&v)
  224. if v1.State == 4 || v1.State == 5 {
  225. continue
  226. }
  227. oIds = append(oIds, v.Oid)
  228. }
  229. //2、查找对应的订单产品记录
  230. var orderGoods []model.OrderGoods
  231. err = engine.In("oid", oIds).Find(&orderGoods)
  232. if err != nil {
  233. return
  234. }
  235. var orderGoodsMap = map[int64][]model.OrderGoods{}
  236. var records []int
  237. for _, v := range orderGoods {
  238. if orderGoodsMap[v.Oid] == nil {
  239. orderGoodsMap[v.Oid] = []model.OrderGoods{}
  240. }
  241. orderGoodsMap[v.Oid] = append(orderGoodsMap[v.Oid], v)
  242. records = append(records, v.Id)
  243. }
  244. //4、整合数据
  245. orderStateArr := []string{"待分拣", "待分拣", "待分拣", "待分拣", "已完成", "已取消"}
  246. for _, v := range orders {
  247. var list []md.LeftDataForMakeList
  248. if len(orderGoodsMap[v.Oid]) > 0 {
  249. orderGoodsStateArr := []string{"待分拣", "待分拣", "待分拣", "待分拣", "已完成"}
  250. for _, vv := range orderGoodsMap[v.Oid] {
  251. skuData := make([]md2.Sku, 0)
  252. json.Unmarshal([]byte(vv.Sku), &skuData)
  253. skuStr := ""
  254. for _, v1 := range skuData {
  255. if skuStr != "" {
  256. skuStr += ";"
  257. }
  258. skuStr += v1.Value
  259. }
  260. var stateZh = orderGoodsStateArr[vv.State]
  261. list = append(list, md.LeftDataForMakeList{
  262. GoodsName: vv.GoodsTitle,
  263. Sku: skuStr,
  264. Num: vv.Num,
  265. SuccessNum: vv.SuccessNum,
  266. StateZh: stateZh,
  267. State: vv.State,
  268. })
  269. }
  270. resp = append(resp, md.LeftDataForMakeResp{
  271. EnterpriseName: enterpriseMap[v.EnterpriseId].Name,
  272. EnterpriseId: v.EnterpriseId,
  273. StateZh: orderStateArr[v.State],
  274. State: v.State,
  275. List: list,
  276. })
  277. }
  278. }
  279. return
  280. }
  281. func RightDataForMake(req md.RightDataForMakeReq) (resp []md.RightDataForMakeResp, total int64, err error) {
  282. now := time.Now()
  283. startDate := now.Format("2006-01-02") + " 00:00:00"
  284. endDate := now.AddDate(0, 0, 1).Format("2006-01-02") + " 00:00:00"
  285. engine := db.Db
  286. var enterprise []model.Enterprise
  287. err = engine.Where("1=1").Find(&enterprise)
  288. if err != nil {
  289. return
  290. }
  291. var enterpriseMap = map[int]model.Enterprise{}
  292. for _, v := range enterprise {
  293. enterpriseMap[v.Id] = v
  294. }
  295. //1、查找当天的 order 数据(大于 待制作)
  296. var orders []model.Order
  297. total, err = engine.Where("create_at >= ?", startDate).And("create_at < ?", endDate).And("state > ? and state != 5", 0).
  298. Limit(req.Limit, (req.Page-1)*req.Limit).FindAndCount(&orders)
  299. if err != nil {
  300. return
  301. }
  302. var oIds []int64
  303. for _, v := range orders {
  304. oIds = append(oIds, v.Oid)
  305. }
  306. //2、整合数据
  307. orderStateArr := []string{"待制作", "制作中", "制作完成", "烘焙完成", "分拣完成", "已取消"}
  308. for _, v := range orders {
  309. resp = append(resp, md.RightDataForMakeResp{
  310. EnterpriseName: enterpriseMap[v.EnterpriseId].Name,
  311. EnterpriseId: v.EnterpriseId,
  312. StateZh: orderStateArr[v.State],
  313. State: v.State,
  314. })
  315. }
  316. return
  317. }
  318. func RightDataForBaking(req md.RightDataForMakeReq) (resp []md.RightDataForMakeResp, total int64, err error) {
  319. now := time.Now()
  320. startDate := now.Format("2006-01-02") + " 00:00:00"
  321. endDate := now.AddDate(0, 0, 1).Format("2006-01-02") + " 00:00:00"
  322. engine := db.Db
  323. var enterprise []model.Enterprise
  324. err = engine.Where("1=1").Find(&enterprise)
  325. if err != nil {
  326. return
  327. }
  328. var enterpriseMap = map[int]model.Enterprise{}
  329. for _, v := range enterprise {
  330. enterpriseMap[v.Id] = v
  331. }
  332. //1、查找当天的 order 数据(大于 待制作)
  333. var orders []model.Order
  334. total, err = engine.Where("create_at >= ?", startDate).And("create_at < ?", endDate).And("state > ? and state != 5", 1).
  335. Limit(req.Limit, (req.Page-1)*req.Limit).FindAndCount(&orders)
  336. if err != nil {
  337. return
  338. }
  339. var oIds []int64
  340. for _, v := range orders {
  341. oIds = append(oIds, v.Oid)
  342. }
  343. //2、整合数据
  344. orderStateArr := []string{"待制作", "制作中", "制作完成", "烘焙完成", "分拣完成", "已取消"}
  345. for _, v := range orders {
  346. resp = append(resp, md.RightDataForMakeResp{
  347. EnterpriseName: enterpriseMap[v.EnterpriseId].Name,
  348. EnterpriseId: v.EnterpriseId,
  349. StateZh: orderStateArr[v.State],
  350. State: v.State,
  351. })
  352. }
  353. return
  354. }
  355. func RightDataForSorting(req md.RightDataForMakeReq) (resp []md.RightDataForMakeResp, total int64, err error) {
  356. now := time.Now()
  357. startDate := now.Format("2006-01-02") + " 00:00:00"
  358. endDate := now.AddDate(0, 0, 1).Format("2006-01-02") + " 00:00:00"
  359. engine := db.Db
  360. var enterprise []model.Enterprise
  361. err = engine.Where("1=1").Find(&enterprise)
  362. if err != nil {
  363. return
  364. }
  365. var enterpriseMap = map[int]model.Enterprise{}
  366. for _, v := range enterprise {
  367. enterpriseMap[v.Id] = v
  368. }
  369. //1、查找当天的 order 数据(大于 待制作)
  370. var orders []model.Order
  371. total, err = engine.Where("create_at >= ?", startDate).And("create_at < ?", endDate).And("state > ? and state != 5", 2).
  372. Limit(req.Limit, (req.Page-1)*req.Limit).FindAndCount(&orders)
  373. if err != nil {
  374. return
  375. }
  376. var oIds []int64
  377. for _, v := range orders {
  378. oIds = append(oIds, v.Oid)
  379. }
  380. //2、整合数据
  381. orderStateArr := []string{"待制作", "制作中", "制作完成", "烘焙完成", "分拣完成", "已取消"}
  382. for _, v := range orders {
  383. resp = append(resp, md.RightDataForMakeResp{
  384. EnterpriseName: enterpriseMap[v.EnterpriseId].Name,
  385. EnterpriseId: v.EnterpriseId,
  386. StateZh: orderStateArr[v.State],
  387. State: v.State,
  388. })
  389. }
  390. return
  391. }