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

82 lines
2.0 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.Sales = utils.StrToInt(item["sales"])
  29. goods.CreateAt = item["create_at"]
  30. // 商品主图
  31. if item["image_list"] != "" {
  32. utils.Unserialize([]byte(item["image_list"]), &tmpMap)
  33. var imageListUrlTmp []string
  34. for _, v := range tmpMap.([]interface{}) {
  35. imageListUrlTmp = append(imageListUrlTmp, svc.ImageFormatWithBucketNew(scheme, host, subDomain, moreSubDomain, v.(string)))
  36. }
  37. if imageListUrlTmp != nil {
  38. goods.Image = imageListUrlTmp[0]
  39. }
  40. }
  41. goods.UpdateAt = item["update_at"]
  42. goods.Title = item["title"]
  43. // 状态
  44. switch utils.StrToInt64(item["sale_state"]) {
  45. case 1.00:
  46. goods.SaleStateText = "銷售中"
  47. break
  48. case 2.00:
  49. goods.SaleStateText = "下架"
  50. break
  51. }
  52. // sku
  53. for _, skuItem := range skus {
  54. if skuItem.GoodsId == utils.StrToInt64(item["goods_id"]) {
  55. goods.SkuList = append(goods.SkuList, skuItem)
  56. }
  57. }
  58. // 获取价格、库存、重量范围、利润空间
  59. goods.Price = item["price"]
  60. goodsListResp = append(goodsListResp, goods)
  61. }
  62. return goodsListResp, total, err
  63. }
  64. func CheckSkuCode(c *gin.Context, skuCode, goodsId string) (bool, error) {
  65. engine := db.Db
  66. isHas, _, err := db.GetMallSkuBySkuCode(engine, skuCode, goodsId)
  67. if err != nil {
  68. return false, err
  69. }
  70. return isHas, nil
  71. }