面包店
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

svc_data.go 12 KiB

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