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

126 regels
3.4 KiB

  1. package svc
  2. import (
  3. "applet/app/admin/md"
  4. "applet/app/db"
  5. "applet/app/e"
  6. "applet/app/svc"
  7. "applet/app/utils"
  8. "encoding/json"
  9. "github.com/gin-gonic/gin"
  10. )
  11. func Order(c *gin.Context) {
  12. var args map[string]string
  13. if err := c.ShouldBindJSON(&args); err != nil {
  14. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  15. return
  16. }
  17. eg := db.Db
  18. data, _ := db.GetOrderListByIpad(eg, args)
  19. list := make([]map[string]string, 0)
  20. if data != nil {
  21. enterpriseIds := make([]int, 0)
  22. for _, v := range *data {
  23. enterpriseIds = append(enterpriseIds, v.EnterpriseId)
  24. }
  25. enterpriseMap := db.GetEnterpriseMore(eg, enterpriseIds)
  26. stateArr := []string{"待制作", "制作中", "烘焙中", "分拣中", "已完成", "已取消"}
  27. btnArr := []string{"进入制作", "进入制作", "进入制作", "分拣完成", "查看详情", "已取消"}
  28. for _, v := range *data {
  29. enterpriseName := ""
  30. _, ok := enterpriseMap[v.EnterpriseId]
  31. if ok {
  32. enterpriseName = enterpriseMap[v.EnterpriseId].Name
  33. }
  34. var tmp = map[string]string{
  35. "oid": utils.Int64ToStr(v.Oid),
  36. "id": utils.IntToStr(v.Id),
  37. "state_str": stateArr[v.State],
  38. "btn_str": btnArr[v.State],
  39. "state": utils.IntToStr(v.State),
  40. "enterprise_name": enterpriseName,
  41. }
  42. list = append(list, tmp)
  43. }
  44. }
  45. e.OutSuc(c, list, nil)
  46. return
  47. }
  48. func StateOrder(c *gin.Context) {
  49. var args map[string]string
  50. if err := c.ShouldBindJSON(&args); err != nil {
  51. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  52. return
  53. }
  54. eg := db.Db
  55. data, _ := db.GetOrderGoodsMakeStockByIpad(eg, args)
  56. list := make([]map[string]string, 0)
  57. if data != nil {
  58. gids := make([]int64, 0)
  59. for _, v := range *data {
  60. gids = append(gids, v.Gid)
  61. }
  62. goodsMap := db.GetGoodsMore(eg, gids)
  63. scheme, host, subDomain, moreSubDomain := svc.ImageBucketNew(c)
  64. var tmpMap interface{}
  65. for _, v := range *data {
  66. var tmp = map[string]string{
  67. "id": utils.IntToStr(v.Id),
  68. "gid": utils.Int64ToStr(v.Gid),
  69. "sku_id": utils.Int64ToStr(v.SkuId),
  70. "num": "",
  71. "state_str": "",
  72. "btn_str": "",
  73. "goods_title": v.GoodsTitle,
  74. "goods_img": "",
  75. "state": "",
  76. }
  77. if args["state"] == "1" {
  78. tmp["num"] = utils.IntToStr(v.WaitMakeNum)
  79. tmp["state_str"] = "制作中"
  80. tmp["btn_str"] = "制作完成"
  81. tmp["state"] = "1"
  82. }
  83. if args["state"] == "2" {
  84. tmp["num"] = utils.IntToStr(v.WaitBakingNum)
  85. tmp["state_str"] = "烘焙中"
  86. tmp["btn_str"] = "烘焙完成"
  87. tmp["state"] = "2"
  88. }
  89. if args["state"] == "3" {
  90. tmp["num"] = utils.IntToStr(v.WaitSortingNum)
  91. tmp["state_str"] = "分拣中"
  92. tmp["btn_str"] = "分拣完成"
  93. tmp["state"] = "3"
  94. }
  95. // 商品主图
  96. if goodsMap[v.Gid].ImageList != "" {
  97. utils.Unserialize([]byte(goodsMap[v.Gid].ImageList), &tmpMap)
  98. var imageListUrlTmp []string
  99. for _, v := range tmpMap.([]interface{}) {
  100. imageListUrlTmp = append(imageListUrlTmp, svc.ImageFormatWithBucketNew(scheme, host, subDomain, moreSubDomain, v.(string)))
  101. }
  102. if imageListUrlTmp != nil {
  103. tmp["goods_img"] = imageListUrlTmp[0]
  104. }
  105. }
  106. skuData := make([]md.Sku, 0)
  107. json.Unmarshal([]byte(v.Sku), &skuData)
  108. skuStr := ""
  109. for _, v1 := range skuData {
  110. if skuStr != "" {
  111. skuStr += ";"
  112. }
  113. skuStr += v1.Value
  114. }
  115. tmp["sku_str"] = skuStr
  116. list = append(list, tmp)
  117. }
  118. }
  119. e.OutSuc(c, list, nil)
  120. return
  121. }