面包店
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 
 

618 wiersze
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. tmp := map[string]string{
  420. "id": utils.IntToStr(v.EnterpriseId),
  421. "name": enterpriseMap[v.EnterpriseId].Name,
  422. "state": utils.IntToStr(v.State),
  423. "state_str": orderStateArr[v.State],
  424. }
  425. ids = append(ids, utils.IntToStr(v.EnterpriseId))
  426. res = append(res, tmp)
  427. }
  428. return res
  429. }
  430. func NewSortingData(c *gin.Context) []map[string]string {
  431. res := make([]map[string]string, 0)
  432. var args map[string]string
  433. if err := c.ShouldBindJSON(&args); err != nil {
  434. return res
  435. }
  436. engine := db.Db
  437. var enterprise []model.Enterprise
  438. err := engine.Where("1=1").Find(&enterprise)
  439. if err != nil {
  440. return res
  441. }
  442. var enterpriseMap = map[int]model.Enterprise{}
  443. for _, v := range enterprise {
  444. enterpriseMap[v.Id] = v
  445. }
  446. //1、查找不等于4 5
  447. now := CommDate()
  448. var orders []model.Order
  449. err = engine.Where(" state != 4 and state != 5 and make_date=? and enterprise_id=?", now, args["id"]).Find(&orders)
  450. if err != nil {
  451. return res
  452. }
  453. var oIds []string
  454. for _, v := range orders {
  455. v1 := order.JudgePackageOrdOrdState(&v)
  456. if v1.State == 4 || v1.State == 5 {
  457. continue
  458. }
  459. oIds = append(oIds, utils.Int64ToStr(v.Oid))
  460. }
  461. sql := `SELECT SUM(num) as num,SUM(success_num) as success_num,goods_title,sku FROM order_goods WHERE oid in (%s) and goods_type=0 GROUP BY enterprise_id,goods_id,sku_id`
  462. sql = fmt.Sprintf(sql, strings.Join(oIds, ","))
  463. nativeString, err := db.QueryNativeString(engine, sql)
  464. for _, v := range nativeString {
  465. skuData := make([]md2.Sku, 0)
  466. json.Unmarshal([]byte(v["sku"]), &skuData)
  467. skuStr := ""
  468. for _, v1 := range skuData {
  469. if skuStr != "" {
  470. skuStr += ";"
  471. }
  472. skuStr += v1.Value
  473. }
  474. tmp := map[string]string{
  475. "goods_name": v["goods_title"],
  476. "sku": skuStr,
  477. "num": v["num"],
  478. "success_num": v["success_num"],
  479. "state": "1",
  480. "state_str": "待分拣",
  481. }
  482. if utils.StrToInt(v["num"]) <= utils.StrToInt(v["success_num"]) {
  483. tmp["state"] = "4"
  484. tmp["stare_str"] = "分拣完成"
  485. }
  486. res = append(res, tmp)
  487. }
  488. return res
  489. }
  490. func NewSortingGoodsCate() []map[string]string {
  491. res := make([]map[string]string, 0)
  492. engine := db.Db
  493. //1、查找不等于4 5
  494. now := CommDate()
  495. var orders []model.Order
  496. err := engine.Where(" state != 4 and state != 5 and make_date=? ", now).Find(&orders)
  497. if err != nil {
  498. return res
  499. }
  500. var oIds []string
  501. for _, v := range orders {
  502. v1 := order.JudgePackageOrdOrdState(&v)
  503. if v1.State == 4 || v1.State == 5 {
  504. continue
  505. }
  506. oIds = append(oIds, utils.Int64ToStr(v.Oid))
  507. }
  508. 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`
  509. sql = fmt.Sprintf(sql, strings.Join(oIds, ","), now)
  510. nativeString, err := db.QueryNativeString(engine, sql)
  511. for _, v := range nativeString {
  512. skuData := make([]md2.Sku, 0)
  513. json.Unmarshal([]byte(v["sku"]), &skuData)
  514. skuStr := ""
  515. for _, v1 := range skuData {
  516. if skuStr != "" {
  517. skuStr += ";"
  518. }
  519. skuStr += v1.Value
  520. }
  521. tmp := map[string]string{
  522. "goods_id": v["goods_id"],
  523. "sku_id": v["sku_id"],
  524. "goods_name": v["goods_title"],
  525. "sku": skuStr,
  526. "num": v["num"],
  527. "success_num": v["success_num"],
  528. "state": "1",
  529. "state_str": "待分拣",
  530. }
  531. if utils.StrToInt(v["num"]) <= utils.StrToInt(v["success_num"]) {
  532. tmp["state"] = "4"
  533. tmp["stare_str"] = "分拣完成"
  534. }
  535. res = append(res, tmp)
  536. }
  537. return res
  538. }
  539. func NewSortingGoodsData(arg map[string]string) []map[string]string {
  540. engine := db.Db
  541. res := make([]map[string]string, 0)
  542. var enterprise []model.Enterprise
  543. err := engine.Where("1=1").Find(&enterprise)
  544. if err != nil {
  545. return res
  546. }
  547. var enterpriseMap = map[int]model.Enterprise{}
  548. for _, v := range enterprise {
  549. enterpriseMap[v.Id] = v
  550. }
  551. //1、查找不等于4 5
  552. now := CommDate()
  553. var orders []model.Order
  554. err = engine.Where(" state != 4 and state != 5 and make_date=? ", now).Find(&orders)
  555. if err != nil {
  556. return res
  557. }
  558. var oIds []string
  559. for _, v := range orders {
  560. v1 := order.JudgePackageOrdOrdState(&v)
  561. if v1.State == 4 || v1.State == 5 {
  562. continue
  563. }
  564. oIds = append(oIds, utils.Int64ToStr(v.Oid))
  565. }
  566. 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`
  567. sql = fmt.Sprintf(sql, strings.Join(oIds, ","), arg["goods_id"], arg["sku_id"], now)
  568. nativeString, err := db.QueryNativeString(engine, sql)
  569. for _, v := range nativeString {
  570. skuData := make([]md2.Sku, 0)
  571. json.Unmarshal([]byte(v["sku"]), &skuData)
  572. skuStr := ""
  573. for _, v1 := range skuData {
  574. if skuStr != "" {
  575. skuStr += ";"
  576. }
  577. skuStr += v1.Value
  578. }
  579. tmp := map[string]string{
  580. "enterprise_name": enterpriseMap[utils.StrToInt(v["enterprise_id"])].Name,
  581. "num": v["num"],
  582. "success_num": v["success_num"],
  583. "state": "1",
  584. "state_str": "待分拣",
  585. }
  586. if utils.StrToInt(v["num"]) <= utils.StrToInt(v["success_num"]) {
  587. tmp["state"] = "4"
  588. tmp["stare_str"] = "分拣完成"
  589. }
  590. res = append(res, tmp)
  591. }
  592. return res
  593. }