面包店
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.
 
 
 
 
 

405 lines
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. var orders []model.Order
  214. 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)
  215. if err != nil {
  216. return
  217. }
  218. var oIds []int64
  219. for _, v := range orders {
  220. v1 := order.JudgePackageOrdOrdState(&v)
  221. if v1.State == 4 || v1.State == 5 {
  222. continue
  223. }
  224. oIds = append(oIds, v.Oid)
  225. }
  226. //2、查找对应的订单产品记录
  227. var orderGoods []model.OrderGoods
  228. err = engine.In("oid", oIds).Find(&orderGoods)
  229. if err != nil {
  230. return
  231. }
  232. var orderGoodsMap = map[int64][]model.OrderGoods{}
  233. var records []int
  234. for _, v := range orderGoods {
  235. if orderGoodsMap[v.Oid] == nil {
  236. orderGoodsMap[v.Oid] = []model.OrderGoods{}
  237. }
  238. orderGoodsMap[v.Oid] = append(orderGoodsMap[v.Oid], v)
  239. records = append(records, v.Id)
  240. }
  241. //4、整合数据
  242. orderStateArr := []string{"待分拣", "待分拣", "待分拣", "待分拣", "已完成", "已取消"}
  243. for _, v := range orders {
  244. var list []md.LeftDataForMakeList
  245. if len(orderGoodsMap[v.Oid]) > 0 {
  246. orderGoodsStateArr := []string{"待分拣", "待分拣", "待分拣", "待分拣", "已完成"}
  247. for _, vv := range orderGoodsMap[v.Oid] {
  248. skuData := make([]md2.Sku, 0)
  249. json.Unmarshal([]byte(vv.Sku), &skuData)
  250. skuStr := ""
  251. for _, v1 := range skuData {
  252. if skuStr != "" {
  253. skuStr += ";"
  254. }
  255. skuStr += v1.Value
  256. }
  257. var stateZh = orderGoodsStateArr[vv.State]
  258. list = append(list, md.LeftDataForMakeList{
  259. GoodsName: vv.GoodsTitle,
  260. Sku: skuStr,
  261. Num: vv.Num,
  262. SuccessNum: vv.SuccessNum,
  263. StateZh: stateZh,
  264. State: vv.State,
  265. })
  266. }
  267. resp = append(resp, md.LeftDataForMakeResp{
  268. EnterpriseName: enterpriseMap[v.EnterpriseId].Name,
  269. EnterpriseId: v.EnterpriseId,
  270. StateZh: orderStateArr[v.State],
  271. State: v.State,
  272. List: list,
  273. })
  274. }
  275. }
  276. return
  277. }
  278. func RightDataForMake(req md.RightDataForMakeReq) (resp []md.RightDataForMakeResp, total int64, err error) {
  279. now := time.Now()
  280. startDate := now.Format("2006-01-02") + " 00:00:00"
  281. endDate := now.AddDate(0, 0, 1).Format("2006-01-02") + " 00:00:00"
  282. engine := db.Db
  283. var enterprise []model.Enterprise
  284. err = engine.Where("1=1").Find(&enterprise)
  285. if err != nil {
  286. return
  287. }
  288. var enterpriseMap = map[int]model.Enterprise{}
  289. for _, v := range enterprise {
  290. enterpriseMap[v.Id] = v
  291. }
  292. //1、查找当天的 order 数据(大于 待制作)
  293. var orders []model.Order
  294. total, err = engine.Where("create_at >= ?", startDate).And("create_at < ?", endDate).And("state > ? and state != 5", 0).
  295. Limit(req.Limit, (req.Page-1)*req.Limit).FindAndCount(&orders)
  296. if err != nil {
  297. return
  298. }
  299. var oIds []int64
  300. for _, v := range orders {
  301. oIds = append(oIds, v.Oid)
  302. }
  303. //2、整合数据
  304. orderStateArr := []string{"待制作", "制作中", "制作完成", "烘焙完成", "分拣完成", "已取消"}
  305. for _, v := range orders {
  306. resp = append(resp, md.RightDataForMakeResp{
  307. EnterpriseName: enterpriseMap[v.EnterpriseId].Name,
  308. EnterpriseId: v.EnterpriseId,
  309. StateZh: orderStateArr[v.State],
  310. State: v.State,
  311. })
  312. }
  313. return
  314. }
  315. func RightDataForBaking(req md.RightDataForMakeReq) (resp []md.RightDataForMakeResp, total int64, err error) {
  316. now := time.Now()
  317. startDate := now.Format("2006-01-02") + " 00:00:00"
  318. endDate := now.AddDate(0, 0, 1).Format("2006-01-02") + " 00:00:00"
  319. engine := db.Db
  320. var enterprise []model.Enterprise
  321. err = engine.Where("1=1").Find(&enterprise)
  322. if err != nil {
  323. return
  324. }
  325. var enterpriseMap = map[int]model.Enterprise{}
  326. for _, v := range enterprise {
  327. enterpriseMap[v.Id] = v
  328. }
  329. //1、查找当天的 order 数据(大于 待制作)
  330. var orders []model.Order
  331. total, err = engine.Where("create_at >= ?", startDate).And("create_at < ?", endDate).And("state > ? and state != 5", 1).
  332. Limit(req.Limit, (req.Page-1)*req.Limit).FindAndCount(&orders)
  333. if err != nil {
  334. return
  335. }
  336. var oIds []int64
  337. for _, v := range orders {
  338. oIds = append(oIds, v.Oid)
  339. }
  340. //2、整合数据
  341. orderStateArr := []string{"待制作", "制作中", "制作完成", "烘焙完成", "分拣完成", "已取消"}
  342. for _, v := range orders {
  343. resp = append(resp, md.RightDataForMakeResp{
  344. EnterpriseName: enterpriseMap[v.EnterpriseId].Name,
  345. EnterpriseId: v.EnterpriseId,
  346. StateZh: orderStateArr[v.State],
  347. State: v.State,
  348. })
  349. }
  350. return
  351. }
  352. func RightDataForSorting(req md.RightDataForMakeReq) (resp []md.RightDataForMakeResp, total int64, err error) {
  353. now := time.Now()
  354. startDate := now.Format("2006-01-02") + " 00:00:00"
  355. endDate := now.AddDate(0, 0, 1).Format("2006-01-02") + " 00:00:00"
  356. engine := db.Db
  357. var enterprise []model.Enterprise
  358. err = engine.Where("1=1").Find(&enterprise)
  359. if err != nil {
  360. return
  361. }
  362. var enterpriseMap = map[int]model.Enterprise{}
  363. for _, v := range enterprise {
  364. enterpriseMap[v.Id] = v
  365. }
  366. //1、查找当天的 order 数据(大于 待制作)
  367. var orders []model.Order
  368. total, err = engine.Where("create_at >= ?", startDate).And("create_at < ?", endDate).And("state > ? and state != 5", 2).
  369. Limit(req.Limit, (req.Page-1)*req.Limit).FindAndCount(&orders)
  370. if err != nil {
  371. return
  372. }
  373. var oIds []int64
  374. for _, v := range orders {
  375. oIds = append(oIds, v.Oid)
  376. }
  377. //2、整合数据
  378. orderStateArr := []string{"待制作", "制作中", "制作完成", "烘焙完成", "分拣完成", "已取消"}
  379. for _, v := range orders {
  380. resp = append(resp, md.RightDataForMakeResp{
  381. EnterpriseName: enterpriseMap[v.EnterpriseId].Name,
  382. EnterpriseId: v.EnterpriseId,
  383. StateZh: orderStateArr[v.State],
  384. State: v.State,
  385. })
  386. }
  387. return
  388. }