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

71 lines
1.8 KiB

  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. for _, item := range mallGoodsList {
  25. var goods md.MallGoodListResp
  26. goods.GoodsId = item["goods_id"]
  27. goods.SaleState = utils.StrToInt(item["sale_state"])
  28. goods.CreateAt = item["create_at"]
  29. // 商品主图
  30. if item["image_list"] != "" {
  31. utils.Unserialize([]byte(item["image_list"]), &tmpMap)
  32. var imageListUrlTmp []string
  33. for _, v := range tmpMap.([]interface{}) {
  34. imageListUrlTmp = append(imageListUrlTmp, svc.ImageFormatWithBucketNew(scheme, host, subDomain, moreSubDomain, v.(string)))
  35. }
  36. if imageListUrlTmp != nil {
  37. goods.Image = imageListUrlTmp[0]
  38. }
  39. }
  40. goods.UpdateAt = item["update_at"]
  41. goods.Title = item["title"]
  42. // sku
  43. for _, skuItem := range skus {
  44. if skuItem.GoodsId == utils.StrToInt64(item["goods_id"]) {
  45. goods.SkuList = append(goods.SkuList, skuItem)
  46. }
  47. }
  48. // 获取价格、库存、重量范围、利润空间
  49. goods.Price = item["price"]
  50. goodsListResp = append(goodsListResp, goods)
  51. }
  52. return goodsListResp, total, err
  53. }
  54. func CheckSkuCode(c *gin.Context, skuCode, goodsId string) (bool, error) {
  55. engine := db.Db
  56. isHas, _, err := db.GetMallSkuBySkuCode(engine, skuCode, goodsId)
  57. if err != nil {
  58. return false, err
  59. }
  60. return isHas, nil
  61. }