面包店
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

8 місяці тому
6 місяці тому
8 місяці тому
6 місяці тому
8 місяці тому
6 місяці тому
8 місяці тому
7 місяці тому
8 місяці тому
7 місяці тому
8 місяці тому
6 місяці тому
6 місяці тому
8 місяці тому
6 місяці тому
8 місяці тому
6 місяці тому
8 місяці тому
8 місяці тому
8 місяці тому
8 місяці тому
6 місяці тому
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515
  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. "fmt"
  11. "github.com/gin-gonic/gin"
  12. "strings"
  13. "time"
  14. )
  15. func LeftDataForMake() (resp []md.LeftDataForMakeResp, err error) {
  16. //now := time.Now()
  17. //startDate := now.Format("2006-01-02") + " 00:00:00"
  18. //endDate := now.AddDate(0, 0, 1).Format("2006-01-02") + " 00:00:00"
  19. //engine := db.Db
  20. //var enterprise []model.Enterprise
  21. //err = engine.Where("1=1").Find(&enterprise)
  22. //if err != nil {
  23. // return
  24. //}
  25. //var enterpriseMap = map[int]model.Enterprise{}
  26. //for _, v := range enterprise {
  27. // enterpriseMap[v.Id] = v
  28. //}
  29. //
  30. ////1、查找当天的 order 数据(大于 待制作)
  31. //var orders []model.Order
  32. //err = engine.Where("create_at >= ?", startDate).And("create_at < ?", endDate).And("state > ? and state != 5", 0).Find(&orders)
  33. //if err != nil {
  34. // return
  35. //}
  36. //var oIds []int64
  37. //for _, v := range orders {
  38. // oIds = append(oIds, v.Oid)
  39. //}
  40. //
  41. ////2、查找对应的订单产品记录
  42. //var orderGoods []model.OrderGoods
  43. //err = engine.In("oid", oIds).Find(&orderGoods)
  44. //if err != nil {
  45. // return
  46. //}
  47. //var orderGoodsMap = map[int64][]model.OrderGoods{}
  48. //var records []int
  49. //for _, v := range orderGoods {
  50. // if orderGoodsMap[v.Oid] == nil {
  51. // orderGoodsMap[v.Oid] = []model.OrderGoods{}
  52. // }
  53. // orderGoodsMap[v.Oid] = append(orderGoodsMap[v.Oid], v)
  54. // records = append(records, v.Id)
  55. //}
  56. //
  57. ////3、用户订单商品操作流程
  58. //var orderGoodsDoingFlows []model.OrderGoodsDoingFlow
  59. //err = engine.Where("state = 2").In("record_id", records).Find(&orderGoodsDoingFlows)
  60. //if err != nil {
  61. // return
  62. //}
  63. //var orderGoodsDoingFlowsMap = map[int]model.OrderGoodsDoingFlow{}
  64. //for _, v := range orderGoodsDoingFlows {
  65. // orderGoodsDoingFlowsMap[v.RecordId] = v
  66. //}
  67. //
  68. ////4、整合数据
  69. //orderStateArr := []string{"待制作", "制作中", "烘焙完成", "分拣完成", "已取消"}
  70. //for _, v := range orders {
  71. // var list []md.LeftDataForMakeList
  72. // if len(orderGoodsMap[v.Oid]) > 0 {
  73. // orderGoodsStateArr := []string{"待制作", "制作中"}
  74. // for _, vv := range orderGoodsMap[v.Oid] {
  75. // skuData := make([]md2.Sku, 0)
  76. // json.Unmarshal([]byte(vv.Sku), &skuData)
  77. // skuStr := ""
  78. // for _, v1 := range skuData {
  79. // if skuStr != "" {
  80. // skuStr += ";"
  81. // }
  82. // skuStr += v1.Value
  83. // }
  84. // var stateZh = "已完成"
  85. // if vv.State <= 1 {
  86. // stateZh = orderGoodsStateArr[vv.State]
  87. // }
  88. // list = append(list, md.LeftDataForMakeList{
  89. // GoodsName: vv.GoodsTitle,
  90. // Sku: skuStr,
  91. // Num: vv.Num,
  92. // SuccessNum: orderGoodsDoingFlowsMap[vv.Id].SuccessNum,
  93. // StateZh: stateZh,
  94. // State: vv.State,
  95. // })
  96. // }
  97. //
  98. // resp = append(resp, md.LeftDataForMakeResp{
  99. // EnterpriseName: enterpriseMap[v.EnterpriseId].Name,
  100. // EnterpriseId: v.EnterpriseId,
  101. // StateZh: orderStateArr[v.State],
  102. // State: v.State,
  103. // List: list,
  104. // })
  105. // }
  106. //}
  107. return
  108. }
  109. func LeftDataForBaking() (resp []md.LeftDataForMakeResp, err error) {
  110. //now := time.Now()
  111. //startDate := now.Format("2006-01-02") + " 00:00:00"
  112. //endDate := now.AddDate(0, 0, 1).Format("2006-01-02") + " 00:00:00"
  113. //engine := db.Db
  114. //var enterprise []model.Enterprise
  115. //err = engine.Where("1=1").Find(&enterprise)
  116. //if err != nil {
  117. // return
  118. //}
  119. //var enterpriseMap = map[int]model.Enterprise{}
  120. //for _, v := range enterprise {
  121. // enterpriseMap[v.Id] = v
  122. //}
  123. //
  124. ////1、查找当天的 order 数据(大于 待制作)
  125. //var orders []model.Order
  126. //err = engine.Where("create_at >= ?", startDate).And("create_at < ?", endDate).And("state > ? and state != 5", 1).Find(&orders)
  127. //if err != nil {
  128. // return
  129. //}
  130. //var oIds []int64
  131. //for _, v := range orders {
  132. // oIds = append(oIds, v.Oid)
  133. //}
  134. //
  135. ////2、查找对应的订单产品记录
  136. //var orderGoods []model.OrderGoods
  137. //err = engine.In("oid", oIds).Find(&orderGoods)
  138. //if err != nil {
  139. // return
  140. //}
  141. //var orderGoodsMap = map[int64][]model.OrderGoods{}
  142. //var records []int
  143. //for _, v := range orderGoods {
  144. // if orderGoodsMap[v.Oid] == nil {
  145. // orderGoodsMap[v.Oid] = []model.OrderGoods{}
  146. // }
  147. // orderGoodsMap[v.Oid] = append(orderGoodsMap[v.Oid], v)
  148. // records = append(records, v.Id)
  149. //}
  150. //
  151. ////3、用户订单商品操作流程
  152. //var orderGoodsDoingFlows []model.OrderGoodsDoingFlow
  153. //err = engine.Where("state = 2").In("record_id", records).Find(&orderGoodsDoingFlows)
  154. //if err != nil {
  155. // return
  156. //}
  157. //var orderGoodsDoingFlowsMap = map[int]model.OrderGoodsDoingFlow{}
  158. //for _, v := range orderGoodsDoingFlows {
  159. // orderGoodsDoingFlowsMap[v.RecordId] = v
  160. //}
  161. //
  162. ////4、整合数据
  163. //orderStateArr := []string{"待制作", "制作中", "制作完成", "烘焙完成", "分拣完成", "已取消"}
  164. //for _, v := range orders {
  165. // var list []md.LeftDataForMakeList
  166. // if len(orderGoodsMap[v.Oid]) > 0 {
  167. // for _, vv := range orderGoodsMap[v.Oid] {
  168. // skuData := make([]md2.Sku, 0)
  169. // json.Unmarshal([]byte(vv.Sku), &skuData)
  170. // skuStr := ""
  171. // for _, v1 := range skuData {
  172. // if skuStr != "" {
  173. // skuStr += ";"
  174. // }
  175. // skuStr += v1.Value
  176. // }
  177. // var stateZh = "已完成"
  178. // if vv.State == 2 {
  179. // stateZh = "烘焙中"
  180. // }
  181. //
  182. // list = append(list, md.LeftDataForMakeList{
  183. // GoodsName: vv.GoodsTitle,
  184. // Sku: skuStr,
  185. // Num: vv.Num,
  186. // SuccessNum: orderGoodsDoingFlowsMap[vv.Id].SuccessNum,
  187. // StateZh: stateZh,
  188. // State: vv.State,
  189. // })
  190. // }
  191. //
  192. // resp = append(resp, md.LeftDataForMakeResp{
  193. // EnterpriseName: enterpriseMap[v.EnterpriseId].Name,
  194. // EnterpriseId: v.EnterpriseId,
  195. // StateZh: orderStateArr[v.State],
  196. // State: v.State,
  197. // List: list,
  198. // })
  199. // }
  200. //}
  201. return
  202. }
  203. func LeftDataForSorting() (resp []md.LeftDataForMakeResp, err error) {
  204. engine := db.Db
  205. var enterprise []model.Enterprise
  206. err = engine.Where("1=1").Find(&enterprise)
  207. if err != nil {
  208. return
  209. }
  210. var enterpriseMap = map[int]model.Enterprise{}
  211. for _, v := range enterprise {
  212. enterpriseMap[v.Id] = v
  213. }
  214. //1、查找不等于4 5
  215. today := utils.GetTimeRange("today")
  216. if time.Now().Hour() < 2 {
  217. today = utils.GetTimeRange("yesterday")
  218. }
  219. var orders []model.Order
  220. 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)
  221. if err != nil {
  222. return
  223. }
  224. var oIds []int64
  225. for _, v := range orders {
  226. v1 := order.JudgePackageOrdOrdState(&v)
  227. if v1.State == 4 || v1.State == 5 {
  228. continue
  229. }
  230. oIds = append(oIds, v.Oid)
  231. }
  232. //2、查找对应的订单产品记录
  233. var orderGoods []model.OrderGoods
  234. err = engine.In("oid", oIds).Find(&orderGoods)
  235. if err != nil {
  236. return
  237. }
  238. var orderGoodsMap = map[int64][]model.OrderGoods{}
  239. var records []int
  240. for _, v := range orderGoods {
  241. if orderGoodsMap[v.Oid] == nil {
  242. orderGoodsMap[v.Oid] = []model.OrderGoods{}
  243. }
  244. orderGoodsMap[v.Oid] = append(orderGoodsMap[v.Oid], v)
  245. records = append(records, v.Id)
  246. }
  247. //4、整合数据
  248. orderStateArr := []string{"待分拣", "待分拣", "待分拣", "待分拣", "已完成", "已取消"}
  249. for _, v := range orders {
  250. var list []md.LeftDataForMakeList
  251. if len(orderGoodsMap[v.Oid]) > 0 {
  252. orderGoodsStateArr := []string{"待分拣", "待分拣", "待分拣", "待分拣", "已完成"}
  253. for _, vv := range orderGoodsMap[v.Oid] {
  254. skuData := make([]md2.Sku, 0)
  255. json.Unmarshal([]byte(vv.Sku), &skuData)
  256. skuStr := ""
  257. for _, v1 := range skuData {
  258. if skuStr != "" {
  259. skuStr += ";"
  260. }
  261. skuStr += v1.Value
  262. }
  263. var stateZh = orderGoodsStateArr[vv.State]
  264. list = append(list, md.LeftDataForMakeList{
  265. GoodsName: vv.GoodsTitle,
  266. Sku: skuStr,
  267. Num: vv.Num,
  268. SuccessNum: vv.SuccessNum,
  269. StateZh: stateZh,
  270. State: vv.State,
  271. })
  272. }
  273. resp = append(resp, md.LeftDataForMakeResp{
  274. EnterpriseName: enterpriseMap[v.EnterpriseId].Name,
  275. EnterpriseId: v.EnterpriseId,
  276. StateZh: orderStateArr[v.State],
  277. State: v.State,
  278. List: list,
  279. })
  280. }
  281. }
  282. return
  283. }
  284. func RightDataForMake(req md.RightDataForMakeReq) (resp []md.RightDataForMakeResp, total int64, err error) {
  285. now := time.Now()
  286. startDate := now.Format("2006-01-02") + " 00:00:00"
  287. endDate := now.AddDate(0, 0, 1).Format("2006-01-02") + " 00:00:00"
  288. engine := db.Db
  289. var enterprise []model.Enterprise
  290. err = engine.Where("1=1").Find(&enterprise)
  291. if err != nil {
  292. return
  293. }
  294. var enterpriseMap = map[int]model.Enterprise{}
  295. for _, v := range enterprise {
  296. enterpriseMap[v.Id] = v
  297. }
  298. //1、查找当天的 order 数据(大于 待制作)
  299. var orders []model.Order
  300. total, err = engine.Where("create_at >= ?", startDate).And("create_at < ?", endDate).And("state > ? and state != 5", 0).
  301. Limit(req.Limit, (req.Page-1)*req.Limit).FindAndCount(&orders)
  302. if err != nil {
  303. return
  304. }
  305. var oIds []int64
  306. for _, v := range orders {
  307. oIds = append(oIds, v.Oid)
  308. }
  309. //2、整合数据
  310. orderStateArr := []string{"待制作", "制作中", "制作完成", "烘焙完成", "分拣完成", "已取消"}
  311. for _, v := range orders {
  312. resp = append(resp, md.RightDataForMakeResp{
  313. EnterpriseName: enterpriseMap[v.EnterpriseId].Name,
  314. EnterpriseId: v.EnterpriseId,
  315. StateZh: orderStateArr[v.State],
  316. State: v.State,
  317. })
  318. }
  319. return
  320. }
  321. func RightDataForBaking(req md.RightDataForMakeReq) (resp []md.RightDataForMakeResp, total int64, err error) {
  322. now := time.Now()
  323. startDate := now.Format("2006-01-02") + " 00:00:00"
  324. endDate := now.AddDate(0, 0, 1).Format("2006-01-02") + " 00:00:00"
  325. engine := db.Db
  326. var enterprise []model.Enterprise
  327. err = engine.Where("1=1").Find(&enterprise)
  328. if err != nil {
  329. return
  330. }
  331. var enterpriseMap = map[int]model.Enterprise{}
  332. for _, v := range enterprise {
  333. enterpriseMap[v.Id] = v
  334. }
  335. //1、查找当天的 order 数据(大于 待制作)
  336. var orders []model.Order
  337. total, err = engine.Where("create_at >= ?", startDate).And("create_at < ?", endDate).And("state > ? and state != 5", 1).
  338. Limit(req.Limit, (req.Page-1)*req.Limit).FindAndCount(&orders)
  339. if err != nil {
  340. return
  341. }
  342. var oIds []int64
  343. for _, v := range orders {
  344. oIds = append(oIds, v.Oid)
  345. }
  346. //2、整合数据
  347. orderStateArr := []string{"待制作", "制作中", "制作完成", "烘焙完成", "分拣完成", "已取消"}
  348. for _, v := range orders {
  349. resp = append(resp, md.RightDataForMakeResp{
  350. EnterpriseName: enterpriseMap[v.EnterpriseId].Name,
  351. EnterpriseId: v.EnterpriseId,
  352. StateZh: orderStateArr[v.State],
  353. State: v.State,
  354. })
  355. }
  356. return
  357. }
  358. func RightDataForSorting(req md.RightDataForMakeReq) (resp []md.RightDataForMakeResp, total int64, err error) {
  359. now := time.Now()
  360. startDate := now.Format("2006-01-02") + " 00:00:00"
  361. endDate := now.AddDate(0, 0, 1).Format("2006-01-02") + " 00:00:00"
  362. engine := db.Db
  363. var enterprise []model.Enterprise
  364. err = engine.Where("1=1").Find(&enterprise)
  365. if err != nil {
  366. return
  367. }
  368. var enterpriseMap = map[int]model.Enterprise{}
  369. for _, v := range enterprise {
  370. enterpriseMap[v.Id] = v
  371. }
  372. //1、查找当天的 order 数据(大于 待制作)
  373. var orders []model.Order
  374. total, err = engine.Where("create_at >= ?", startDate).And("create_at < ?", endDate).And("state > ? and state != 5", 2).
  375. Limit(req.Limit, (req.Page-1)*req.Limit).FindAndCount(&orders)
  376. if err != nil {
  377. return
  378. }
  379. var oIds []int64
  380. for _, v := range orders {
  381. oIds = append(oIds, v.Oid)
  382. }
  383. //2、整合数据
  384. orderStateArr := []string{"待制作", "制作中", "制作完成", "烘焙完成", "分拣完成", "已取消"}
  385. for _, v := range orders {
  386. resp = append(resp, md.RightDataForMakeResp{
  387. EnterpriseName: enterpriseMap[v.EnterpriseId].Name,
  388. EnterpriseId: v.EnterpriseId,
  389. StateZh: orderStateArr[v.State],
  390. State: v.State,
  391. })
  392. }
  393. return
  394. }
  395. func NewSortingCate() []map[string]string {
  396. engine := db.Db
  397. res := make([]map[string]string, 0)
  398. var enterprise []model.Enterprise
  399. err := engine.Where("1=1").Find(&enterprise)
  400. if err != nil {
  401. return res
  402. }
  403. var enterpriseMap = map[int]model.Enterprise{}
  404. for _, v := range enterprise {
  405. enterpriseMap[v.Id] = v
  406. }
  407. //1、查找不等于4 5
  408. today := utils.GetTimeRange("today")
  409. if time.Now().Hour() < 2 {
  410. today = utils.GetTimeRange("yesterday")
  411. }
  412. var orders []model.Order
  413. 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)
  414. if err != nil {
  415. return res
  416. }
  417. ids := make([]string, 0)
  418. orderStateArr := []string{"待分拣", "待分拣", "待分拣", "待分拣", "已完成", "已取消"}
  419. for _, v := range orders {
  420. if utils.InArr(utils.IntToStr(v.EnterpriseId), ids) {
  421. continue
  422. }
  423. tmp := map[string]string{
  424. "id": utils.IntToStr(v.EnterpriseId),
  425. "name": enterpriseMap[v.EnterpriseId].Name,
  426. "state": utils.IntToStr(v.State),
  427. "state_str": orderStateArr[v.State],
  428. }
  429. ids = append(ids, utils.IntToStr(v.EnterpriseId))
  430. res = append(res, tmp)
  431. }
  432. return res
  433. }
  434. func NewSortingData(c *gin.Context) []map[string]string {
  435. res := make([]map[string]string, 0)
  436. var args map[string]string
  437. if err := c.ShouldBindJSON(&args); err != nil {
  438. return res
  439. }
  440. engine := db.Db
  441. var enterprise []model.Enterprise
  442. err := engine.Where("1=1").Find(&enterprise)
  443. if err != nil {
  444. return res
  445. }
  446. var enterpriseMap = map[int]model.Enterprise{}
  447. for _, v := range enterprise {
  448. enterpriseMap[v.Id] = v
  449. }
  450. //1、查找不等于4 5
  451. today := utils.GetTimeRange("today")
  452. if time.Now().Hour() < 2 {
  453. today = utils.GetTimeRange("yesterday")
  454. }
  455. var orders []model.Order
  456. err = engine.Where(" state != 4 and state != 5 and create_at>=? and enterprise_id=?", time.Unix(today["start"], 0).Format("2006-01-02 15:04:05"), args["id"]).Find(&orders)
  457. if err != nil {
  458. return res
  459. }
  460. var oIds []string
  461. for _, v := range orders {
  462. v1 := order.JudgePackageOrdOrdState(&v)
  463. if v1.State == 4 || v1.State == 5 {
  464. continue
  465. }
  466. oIds = append(oIds, utils.Int64ToStr(v.Oid))
  467. }
  468. sql := `SELECT SUM(num) as num,SUM(success_num) as success_num,goods_title,sku FROM order_goods WHERE oid in (%s) GROUP BY enterprise_id,goods_id,sku_id`
  469. sql = fmt.Sprintf(sql, strings.Join(oIds, ","))
  470. nativeString, err := db.QueryNativeString(engine, sql)
  471. for _, v := range nativeString {
  472. skuData := make([]md2.Sku, 0)
  473. json.Unmarshal([]byte(v["sku"]), &skuData)
  474. skuStr := ""
  475. for _, v1 := range skuData {
  476. if skuStr != "" {
  477. skuStr += ";"
  478. }
  479. skuStr += v1.Value
  480. }
  481. tmp := map[string]string{
  482. "goods_name": v["goods_title"],
  483. "sku": skuStr,
  484. "num": v["num"],
  485. "success_num": v["success_num"],
  486. "state": "1",
  487. "state_str": "待分拣",
  488. }
  489. if utils.StrToInt(v["num"]) <= utils.StrToInt(v["success_num"]) {
  490. tmp["state"] = "4"
  491. tmp["stare_str"] = "分拣完成"
  492. }
  493. res = append(res, tmp)
  494. }
  495. return res
  496. }