面包店
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 

620 linhas
18 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. "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. sysCfgDb := db.SysCfgDb{}
  216. sysCfgDb.Set()
  217. now := CommDate()
  218. var orders []model.Order
  219. err = engine.Where(" state != 4 and state != 5 and make_date=?", now).Find(&orders)
  220. if err != nil {
  221. return
  222. }
  223. var oIds []int64
  224. for _, v := range orders {
  225. v1 := order.JudgePackageOrdOrdState(&v)
  226. if v1.State == 4 || v1.State == 5 {
  227. continue
  228. }
  229. oIds = append(oIds, v.Oid)
  230. }
  231. //2、查找对应的订单产品记录
  232. var orderGoods []model.OrderGoods
  233. err = engine.In("oid", oIds).Find(&orderGoods)
  234. if err != nil {
  235. return
  236. }
  237. var orderGoodsMap = map[int64][]model.OrderGoods{}
  238. var records []int
  239. for _, v := range orderGoods {
  240. if orderGoodsMap[v.Oid] == nil {
  241. orderGoodsMap[v.Oid] = []model.OrderGoods{}
  242. }
  243. orderGoodsMap[v.Oid] = append(orderGoodsMap[v.Oid], v)
  244. records = append(records, v.Id)
  245. }
  246. //4、整合数据
  247. orderStateArr := []string{"待分拣", "待分拣", "待分拣", "待分拣", "已完成", "已取消"}
  248. for _, v := range orders {
  249. var list []md.LeftDataForMakeList
  250. if len(orderGoodsMap[v.Oid]) > 0 {
  251. orderGoodsStateArr := []string{"待分拣", "待分拣", "待分拣", "待分拣", "已完成"}
  252. for _, vv := range orderGoodsMap[v.Oid] {
  253. skuData := make([]md2.Sku, 0)
  254. json.Unmarshal([]byte(vv.Sku), &skuData)
  255. skuStr := ""
  256. for _, v1 := range skuData {
  257. if skuStr != "" {
  258. skuStr += ";"
  259. }
  260. skuStr += v1.Value
  261. }
  262. var stateZh = orderGoodsStateArr[vv.State]
  263. list = append(list, md.LeftDataForMakeList{
  264. GoodsName: vv.GoodsTitle,
  265. Sku: skuStr,
  266. Num: vv.Num,
  267. SuccessNum: vv.SuccessNum,
  268. StateZh: stateZh,
  269. State: vv.State,
  270. })
  271. }
  272. resp = append(resp, md.LeftDataForMakeResp{
  273. EnterpriseName: enterpriseMap[v.EnterpriseId].Name,
  274. EnterpriseId: v.EnterpriseId,
  275. StateZh: orderStateArr[v.State],
  276. State: v.State,
  277. List: list,
  278. })
  279. }
  280. }
  281. return
  282. }
  283. func RightDataForMake(req md.RightDataForMakeReq) (resp []md.RightDataForMakeResp, total int64, err error) {
  284. now := time.Now()
  285. startDate := now.Format("2006-01-02") + " 00:00:00"
  286. endDate := now.AddDate(0, 0, 1).Format("2006-01-02") + " 00:00:00"
  287. engine := db.Db
  288. var enterprise []model.Enterprise
  289. err = engine.Where("1=1").Find(&enterprise)
  290. if err != nil {
  291. return
  292. }
  293. var enterpriseMap = map[int]model.Enterprise{}
  294. for _, v := range enterprise {
  295. enterpriseMap[v.Id] = v
  296. }
  297. //1、查找当天的 order 数据(大于 待制作)
  298. var orders []model.Order
  299. total, err = engine.Where("create_at >= ?", startDate).And("create_at < ?", endDate).And("state > ? and state != 5", 0).
  300. Limit(req.Limit, (req.Page-1)*req.Limit).FindAndCount(&orders)
  301. if err != nil {
  302. return
  303. }
  304. var oIds []int64
  305. for _, v := range orders {
  306. oIds = append(oIds, v.Oid)
  307. }
  308. //2、整合数据
  309. orderStateArr := []string{"待制作", "制作中", "制作完成", "烘焙完成", "分拣完成", "已取消"}
  310. for _, v := range orders {
  311. resp = append(resp, md.RightDataForMakeResp{
  312. EnterpriseName: enterpriseMap[v.EnterpriseId].Name,
  313. EnterpriseId: v.EnterpriseId,
  314. StateZh: orderStateArr[v.State],
  315. State: v.State,
  316. })
  317. }
  318. return
  319. }
  320. func RightDataForBaking(req md.RightDataForMakeReq) (resp []md.RightDataForMakeResp, total int64, err error) {
  321. now := time.Now()
  322. startDate := now.Format("2006-01-02") + " 00:00:00"
  323. endDate := now.AddDate(0, 0, 1).Format("2006-01-02") + " 00:00:00"
  324. engine := db.Db
  325. var enterprise []model.Enterprise
  326. err = engine.Where("1=1").Find(&enterprise)
  327. if err != nil {
  328. return
  329. }
  330. var enterpriseMap = map[int]model.Enterprise{}
  331. for _, v := range enterprise {
  332. enterpriseMap[v.Id] = v
  333. }
  334. //1、查找当天的 order 数据(大于 待制作)
  335. var orders []model.Order
  336. total, err = engine.Where("create_at >= ?", startDate).And("create_at < ?", endDate).And("state > ? and state != 5", 1).
  337. Limit(req.Limit, (req.Page-1)*req.Limit).FindAndCount(&orders)
  338. if err != nil {
  339. return
  340. }
  341. var oIds []int64
  342. for _, v := range orders {
  343. oIds = append(oIds, v.Oid)
  344. }
  345. //2、整合数据
  346. orderStateArr := []string{"待制作", "制作中", "制作完成", "烘焙完成", "分拣完成", "已取消"}
  347. for _, v := range orders {
  348. resp = append(resp, md.RightDataForMakeResp{
  349. EnterpriseName: enterpriseMap[v.EnterpriseId].Name,
  350. EnterpriseId: v.EnterpriseId,
  351. StateZh: orderStateArr[v.State],
  352. State: v.State,
  353. })
  354. }
  355. return
  356. }
  357. func RightDataForSorting(req md.RightDataForMakeReq) (resp []md.RightDataForMakeResp, total int64, err error) {
  358. now := time.Now()
  359. startDate := now.Format("2006-01-02") + " 00:00:00"
  360. endDate := now.AddDate(0, 0, 1).Format("2006-01-02") + " 00:00:00"
  361. engine := db.Db
  362. var enterprise []model.Enterprise
  363. err = engine.Where("1=1").Find(&enterprise)
  364. if err != nil {
  365. return
  366. }
  367. var enterpriseMap = map[int]model.Enterprise{}
  368. for _, v := range enterprise {
  369. enterpriseMap[v.Id] = v
  370. }
  371. //1、查找当天的 order 数据(大于 待制作)
  372. var orders []model.Order
  373. total, err = engine.Where("create_at >= ?", startDate).And("create_at < ?", endDate).And("state > ? and state != 5", 2).
  374. Limit(req.Limit, (req.Page-1)*req.Limit).FindAndCount(&orders)
  375. if err != nil {
  376. return
  377. }
  378. var oIds []int64
  379. for _, v := range orders {
  380. oIds = append(oIds, v.Oid)
  381. }
  382. //2、整合数据
  383. orderStateArr := []string{"待制作", "制作中", "制作完成", "烘焙完成", "分拣完成", "已取消"}
  384. for _, v := range orders {
  385. resp = append(resp, md.RightDataForMakeResp{
  386. EnterpriseName: enterpriseMap[v.EnterpriseId].Name,
  387. EnterpriseId: v.EnterpriseId,
  388. StateZh: orderStateArr[v.State],
  389. State: v.State,
  390. })
  391. }
  392. return
  393. }
  394. func NewSortingCate() []map[string]string {
  395. engine := db.Db
  396. res := make([]map[string]string, 0)
  397. var enterprise []model.Enterprise
  398. err := engine.Where("1=1").Find(&enterprise)
  399. if err != nil {
  400. return res
  401. }
  402. var enterpriseMap = map[int]model.Enterprise{}
  403. for _, v := range enterprise {
  404. enterpriseMap[v.Id] = v
  405. }
  406. //1、查找不等于4 5
  407. now := CommDate()
  408. var orders []model.Order
  409. err = engine.Where(" state != 4 and state != 5 and make_date=?", now).Find(&orders)
  410. if err != nil {
  411. return res
  412. }
  413. ids := make([]string, 0)
  414. orderStateArr := []string{"待分拣", "待分拣", "待分拣", "待分拣", "已完成", "已取消"}
  415. for _, v := range orders {
  416. if utils.InArr(utils.IntToStr(v.EnterpriseId), ids) {
  417. continue
  418. }
  419. v1 := order.JudgePackageOrdOrdState(&v)
  420. v = *v1
  421. tmp := map[string]string{
  422. "id": utils.IntToStr(v.EnterpriseId),
  423. "name": enterpriseMap[v.EnterpriseId].Name,
  424. "state": utils.IntToStr(v.State),
  425. "state_str": orderStateArr[v.State],
  426. }
  427. ids = append(ids, utils.IntToStr(v.EnterpriseId))
  428. res = append(res, tmp)
  429. }
  430. return res
  431. }
  432. func NewSortingData(c *gin.Context) []map[string]string {
  433. res := make([]map[string]string, 0)
  434. var args map[string]string
  435. if err := c.ShouldBindJSON(&args); err != nil {
  436. return res
  437. }
  438. engine := db.Db
  439. var enterprise []model.Enterprise
  440. err := engine.Where("1=1").Find(&enterprise)
  441. if err != nil {
  442. return res
  443. }
  444. var enterpriseMap = map[int]model.Enterprise{}
  445. for _, v := range enterprise {
  446. enterpriseMap[v.Id] = v
  447. }
  448. //1、查找不等于4 5
  449. now := CommDate()
  450. var orders []model.Order
  451. err = engine.Where(" state != 4 and state != 5 and make_date=? and enterprise_id=?", now, args["id"]).Find(&orders)
  452. if err != nil {
  453. return res
  454. }
  455. var oIds []string
  456. for _, v := range orders {
  457. v1 := order.JudgePackageOrdOrdState(&v)
  458. if v1.State == 4 || v1.State == 5 {
  459. continue
  460. }
  461. oIds = append(oIds, utils.Int64ToStr(v.Oid))
  462. }
  463. sql := `SELECT SUM(num) as num,SUM(success_num) as success_num,goods_title,sku FROM order_goods WHERE oid in (%s) and make_date=%s and goods_type=0 GROUP BY enterprise_id,goods_id,sku_id`
  464. sql = fmt.Sprintf(sql, strings.Join(oIds, ","), now)
  465. nativeString, err := db.QueryNativeString(engine, sql)
  466. for _, v := range nativeString {
  467. skuData := make([]md2.Sku, 0)
  468. json.Unmarshal([]byte(v["sku"]), &skuData)
  469. skuStr := ""
  470. for _, v1 := range skuData {
  471. if skuStr != "" {
  472. skuStr += ";"
  473. }
  474. skuStr += v1.Value
  475. }
  476. tmp := map[string]string{
  477. "goods_name": v["goods_title"],
  478. "sku": skuStr,
  479. "num": v["num"],
  480. "success_num": v["success_num"],
  481. "state": "1",
  482. "state_str": "待分拣",
  483. }
  484. if utils.StrToInt(v["num"]) <= utils.StrToInt(v["success_num"]) {
  485. tmp["state"] = "4"
  486. tmp["state_str"] = "分拣完成"
  487. }
  488. res = append(res, tmp)
  489. }
  490. return res
  491. }
  492. func NewSortingGoodsCate() []map[string]string {
  493. res := make([]map[string]string, 0)
  494. engine := db.Db
  495. //1、查找不等于4 5
  496. now := CommDate()
  497. var orders []model.Order
  498. err := engine.Where(" state != 4 and state != 5 and make_date=? ", now).Find(&orders)
  499. if err != nil {
  500. return res
  501. }
  502. var oIds []string
  503. for _, v := range orders {
  504. v1 := order.JudgePackageOrdOrdState(&v)
  505. if v1.State == 4 || v1.State == 5 {
  506. continue
  507. }
  508. oIds = append(oIds, utils.Int64ToStr(v.Oid))
  509. }
  510. sql := `SELECT SUM(num) as num,SUM(success_num) as success_num,goods_title,sku,goods_id,sku_id FROM order_goods WHERE oid in (%s) and goods_type=0 and make_date=%s GROUP BY goods_id,sku_id`
  511. sql = fmt.Sprintf(sql, strings.Join(oIds, ","), now)
  512. nativeString, err := db.QueryNativeString(engine, sql)
  513. for _, v := range nativeString {
  514. skuData := make([]md2.Sku, 0)
  515. json.Unmarshal([]byte(v["sku"]), &skuData)
  516. skuStr := ""
  517. for _, v1 := range skuData {
  518. if skuStr != "" {
  519. skuStr += ";"
  520. }
  521. skuStr += v1.Value
  522. }
  523. tmp := map[string]string{
  524. "goods_id": v["goods_id"],
  525. "sku_id": v["sku_id"],
  526. "goods_name": v["goods_title"],
  527. "sku": skuStr,
  528. "num": v["num"],
  529. "success_num": v["success_num"],
  530. "state": "1",
  531. "state_str": "待分拣",
  532. }
  533. if utils.StrToInt(v["num"]) <= utils.StrToInt(v["success_num"]) {
  534. tmp["state"] = "4"
  535. tmp["state_str"] = "分拣完成"
  536. }
  537. res = append(res, tmp)
  538. }
  539. return res
  540. }
  541. func NewSortingGoodsData(arg map[string]string) []map[string]string {
  542. engine := db.Db
  543. res := make([]map[string]string, 0)
  544. var enterprise []model.Enterprise
  545. err := engine.Where("1=1").Find(&enterprise)
  546. if err != nil {
  547. return res
  548. }
  549. var enterpriseMap = map[int]model.Enterprise{}
  550. for _, v := range enterprise {
  551. enterpriseMap[v.Id] = v
  552. }
  553. //1、查找不等于4 5
  554. now := CommDate()
  555. var orders []model.Order
  556. err = engine.Where(" state != 4 and state != 5 and make_date=? ", now).Find(&orders)
  557. if err != nil {
  558. return res
  559. }
  560. var oIds []string
  561. for _, v := range orders {
  562. v1 := order.JudgePackageOrdOrdState(&v)
  563. if v1.State == 4 || v1.State == 5 {
  564. continue
  565. }
  566. oIds = append(oIds, utils.Int64ToStr(v.Oid))
  567. }
  568. sql := `SELECT SUM(num) as num,SUM(success_num) as success_num,goods_title,sku,goods_id,sku_id,enterprise_id FROM order_goods WHERE oid in (%s) and goods_id=%s and goods_type=0 and sku_id=%s and make_date=%s GROUP BY enterprise_id`
  569. sql = fmt.Sprintf(sql, strings.Join(oIds, ","), arg["goods_id"], arg["sku_id"], now)
  570. nativeString, err := db.QueryNativeString(engine, sql)
  571. for _, v := range nativeString {
  572. skuData := make([]md2.Sku, 0)
  573. json.Unmarshal([]byte(v["sku"]), &skuData)
  574. skuStr := ""
  575. for _, v1 := range skuData {
  576. if skuStr != "" {
  577. skuStr += ";"
  578. }
  579. skuStr += v1.Value
  580. }
  581. tmp := map[string]string{
  582. "enterprise_name": enterpriseMap[utils.StrToInt(v["enterprise_id"])].Name,
  583. "num": v["num"],
  584. "success_num": v["success_num"],
  585. "state": "1",
  586. "state_str": "待分拣",
  587. }
  588. if utils.StrToInt(v["num"]) <= utils.StrToInt(v["success_num"]) {
  589. tmp["state"] = "4"
  590. tmp["state_str"] = "分拣完成"
  591. }
  592. res = append(res, tmp)
  593. }
  594. return res
  595. }