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

398 lines
11 KiB

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