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

svc_goods_list.go 5.3 KiB

9 months ago
8 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
9 months ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. package goods
  2. import (
  3. "applet/app/admin/md"
  4. "applet/app/db"
  5. "applet/app/svc"
  6. "applet/app/utils"
  7. "github.com/gin-gonic/gin"
  8. )
  9. // 获取列表数据
  10. func GetMallGoodsList(c *gin.Context, req *md.MallGoodsListReq) (interface{}, int64, error) {
  11. var goodsListResp []md.MallGoodListResp
  12. // 获取分库链接
  13. engine := db.Db
  14. // 查询goods数据表获取数据
  15. mallGoodsList, skus, total, err := db.GetMallGoodsListLeftOnMallSku(engine, req)
  16. if err != nil {
  17. return nil, 0, err
  18. }
  19. var tmpMap interface{}
  20. scheme, host, subDomain, moreSubDomain := svc.ImageBucketNew(c)
  21. if err != nil {
  22. return nil, 0, err
  23. }
  24. //判断是不是学校下单时的商品列表 计算对应的价格
  25. gids := make([]string, 0)
  26. for _, item := range mallGoodsList {
  27. gids = append(gids, item["goods_id"])
  28. }
  29. for _, item := range mallGoodsList {
  30. var goods md.MallGoodListResp
  31. goods.GoodsId = item["goods_id"]
  32. goods.SaleState = utils.StrToInt(item["sale_state"])
  33. goods.Sales = utils.StrToInt(item["sales"])
  34. goods.CreateAt = item["create_at"]
  35. // 商品主图
  36. if item["image_list"] != "" {
  37. utils.Unserialize([]byte(item["image_list"]), &tmpMap)
  38. var imageListUrlTmp []string
  39. for _, v := range tmpMap.([]interface{}) {
  40. imageListUrlTmp = append(imageListUrlTmp, svc.ImageFormatWithBucketNew(scheme, host, subDomain, moreSubDomain, v.(string)))
  41. }
  42. if imageListUrlTmp != nil {
  43. goods.Image = imageListUrlTmp[0]
  44. }
  45. }
  46. goods.UpdateAt = item["update_at"]
  47. goods.Title = item["title"]
  48. // 状态
  49. switch utils.StrToInt64(item["sale_state"]) {
  50. case 1.00:
  51. goods.SaleStateText = "銷售中"
  52. break
  53. case 2.00:
  54. goods.SaleStateText = "下架"
  55. break
  56. }
  57. // sku
  58. for _, skuItem := range skus {
  59. if skuItem.GoodsId == utils.StrToInt64(item["goods_id"]) {
  60. goods.SkuList = append(goods.SkuList, skuItem)
  61. }
  62. }
  63. // 获取价格、库存、重量范围、利润空间
  64. goods.Price = item["price"]
  65. // spe
  66. var spe []map[string]interface{}
  67. var speTmp []map[string]interface{}
  68. utils.Unserialize([]byte(item["spe"]), &spe)
  69. for _, itemSpe := range spe {
  70. tmp := make(map[string]interface{})
  71. tmp["type"] = "text"
  72. tmp["name"] = itemSpe["name"]
  73. subTmp := make([]map[string]interface{}, 0)
  74. for i, v := range itemSpe["values"].([]interface{}) {
  75. subTmp = append(subTmp, map[string]interface{}{
  76. "key": i,
  77. "name": v,
  78. })
  79. }
  80. tmp["values"] = subTmp
  81. speTmp = append(speTmp, tmp)
  82. }
  83. goods.Spe = speTmp
  84. goodsListResp = append(goodsListResp, goods)
  85. }
  86. return goodsListResp, total, err
  87. }
  88. // 获取列表数据(给方案用)
  89. //func GetMallGoodsListForScheme(c *gin.Context, req *md.MallGoodsListReq, schemeId int) (interface{}, int64, error) {
  90. // schemeDb := db.SchemeDb{}
  91. // schemeDb.Set()
  92. // schemeInfo, err := schemeDb.GetScheme(schemeId)
  93. // if err != nil {
  94. // return nil, 0, err
  95. // }
  96. // if schemeInfo == nil {
  97. // return nil, 0, errors.New("未查询到相应方案记录")
  98. // }
  99. //
  100. // var goodsListResp []md.MallGoodListResp
  101. // // 获取分库链接
  102. // engine := db.Db
  103. // // 查询goods数据表获取数据
  104. // mallGoodsList, skus, total, err := db.GetMallGoodsListLeftOnMallSku(engine, req)
  105. // if err != nil {
  106. // return nil, 0, err
  107. // }
  108. // var tmpMap interface{}
  109. // scheme, host, subDomain, moreSubDomain := svc.ImageBucketNew(c)
  110. // if err != nil {
  111. // return nil, 0, err
  112. // }
  113. //
  114. // //获取方案中sku的价格
  115. // var skuIds []string
  116. // for _, v := range skus {
  117. // skuIds = append(skuIds, utils.Int64ToStr(v.SkuId))
  118. // }
  119. //
  120. // var schemeWithSkusMap = map[int]*model.SchemeWithSku{}
  121. // if len(skuIds) > 0 {
  122. // var schemeWithSkus []*model.SchemeWithSku
  123. // err = engine.Where("1 = 1").And(fmt.Sprintf("sku_id In (%s)", strings.Join(skuIds, ","))).Find(&schemeWithSkus)
  124. // if err != nil {
  125. // return nil, 0, err
  126. // }
  127. // for _, v := range schemeWithSkus {
  128. // schemeWithSkusMap[v.SkuId] = v
  129. // }
  130. // }
  131. //
  132. // for _, item := range mallGoodsList {
  133. // var goods md.MallGoodListResp
  134. // goods.GoodsId = item["goods_id"]
  135. // goods.SaleState = utils.StrToInt(item["sale_state"])
  136. // goods.Sales = utils.StrToInt(item["sales"])
  137. // goods.CreateAt = item["create_at"]
  138. //
  139. // // 商品主图
  140. // if item["image_list"] != "" {
  141. // utils.Unserialize([]byte(item["image_list"]), &tmpMap)
  142. // var imageListUrlTmp []string
  143. // for _, v := range tmpMap.([]interface{}) {
  144. // imageListUrlTmp = append(imageListUrlTmp, svc.ImageFormatWithBucketNew(scheme, host, subDomain, moreSubDomain, v.(string)))
  145. // }
  146. // if imageListUrlTmp != nil {
  147. // goods.Image = imageListUrlTmp[0]
  148. // }
  149. // }
  150. //
  151. // goods.UpdateAt = item["update_at"]
  152. // goods.Title = item["title"]
  153. //
  154. // // 状态
  155. // switch utils.StrToInt64(item["sale_state"]) {
  156. // case 1.00:
  157. // goods.SaleStateText = "銷售中"
  158. // break
  159. // case 2.00:
  160. // goods.SaleStateText = "下架"
  161. // break
  162. // }
  163. //
  164. // // sku
  165. // for _, skuItem := range skus {
  166. // if skuItem.GoodsId == utils.StrToInt64(item["goods_id"]) {
  167. // goods.SkuList = append(goods.SkuList, skuItem)
  168. // }
  169. // }
  170. // // 获取价格、库存、重量范围、利润空间
  171. // goods.Price = item["price"]
  172. // goodsListResp = append(goodsListResp, goods)
  173. // }
  174. //
  175. // return goodsListResp, total, err
  176. //}
  177. func CheckSkuCode(c *gin.Context, skuCode, goodsId string) (bool, error) {
  178. engine := db.Db
  179. isHas, _, err := db.GetMallSkuBySkuCode(engine, skuCode, goodsId)
  180. if err != nil {
  181. return false, err
  182. }
  183. return isHas, nil
  184. }