附近小店
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 

89 行
2.1 KiB

  1. package svc
  2. import (
  3. "applet/app/db"
  4. "applet/app/e"
  5. "applet/app/utils"
  6. "encoding/json"
  7. "github.com/gin-gonic/gin"
  8. )
  9. func Goods(c *gin.Context) {
  10. var arg map[string]string
  11. if err := c.ShouldBindJSON(&arg); err != nil {
  12. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  13. return
  14. }
  15. storeId := c.GetHeader("store_id")
  16. arg["store_type"] = "0"
  17. if utils.StrToInt(storeId) > 0 {
  18. arg["store_id"] = storeId
  19. arg["store_type"] = "1"
  20. }
  21. goods := db.GetGoods(MasterDb(c), arg)
  22. goodsList := make([]map[string]interface{}, 0)
  23. if goods != nil {
  24. scheme, host := ImageBucket(c)
  25. for _, v := range *goods {
  26. speImageList := make([]string, 0)
  27. if v.IsSpeImageOn == 1 {
  28. json.Unmarshal([]byte(v.SpeImages), &speImageList)
  29. }
  30. tmp := map[string]interface{}{
  31. "id": utils.IntToStr(v.Id),
  32. "title": v.Title,
  33. "img": ImageFormatWithBucket(scheme, host, v.Img),
  34. "info": v.Info,
  35. "price": v.Price,
  36. "stock": utils.IntToStr(v.Stock),
  37. "is_single_sku": utils.IntToStr(v.IsSingleSku),
  38. "sale_count": utils.IntToStr(v.SaleCount),
  39. }
  40. goodsList = append(goodsList, tmp)
  41. }
  42. }
  43. e.OutSuc(c, goodsList, nil)
  44. return
  45. }
  46. func GoodsSku(c *gin.Context) {
  47. var arg map[string]string
  48. if err := c.ShouldBindJSON(&arg); err != nil {
  49. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  50. return
  51. }
  52. sku := db.GetGoodsSku(MasterDb(c), arg["goods_id"])
  53. skuList := make([]map[string]string, 0)
  54. if sku != nil {
  55. for _, v := range *sku {
  56. tmp := map[string]string{
  57. "sku_id": utils.Int64ToStr(v.SkuId),
  58. "goods_id": utils.IntToStr(v.GoodsId),
  59. "price": v.Price,
  60. "stock": utils.IntToStr(v.Stock),
  61. "indexes": v.Indexes,
  62. "sku": v.Sku,
  63. }
  64. skuList = append(skuList, tmp)
  65. }
  66. }
  67. goods := db.GetGoodsId(MasterDb(c), arg["goods_id"])
  68. res := map[string]interface{}{
  69. "spe": goods.Spe,
  70. "sku_list": skuList,
  71. }
  72. e.OutSuc(c, res, nil)
  73. return
  74. }
  75. func GoodsCoupon(c *gin.Context) {
  76. var arg map[string]string
  77. if err := c.ShouldBindJSON(&arg); err != nil {
  78. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  79. return
  80. }
  81. returnData := CommCoupon(c, arg["amount"])
  82. e.OutSuc(c, returnData, nil)
  83. return
  84. }