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

97 行
2.3 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 := GetStoreId(c)
  16. arg["store_type"] = "0"
  17. if utils.StrToInt(storeId) > 0 {
  18. arg["uid"] = storeId
  19. storeData := db.GetStoreIdEg(MasterDb(c), storeId)
  20. if storeData.StoreType == 2 {
  21. storeData.StoreType = 1
  22. }
  23. if storeData.StoreType == 0 {
  24. arg["uid"] = "0"
  25. }
  26. arg["store_type"] = utils.IntToStr(storeData.StoreType)
  27. }
  28. goods := db.GetGoods(MasterDb(c), arg)
  29. goodsList := make([]map[string]interface{}, 0)
  30. if goods != nil {
  31. scheme, host := ImageBucket(c)
  32. for _, v := range *goods {
  33. speImageList := make([]string, 0)
  34. if v.IsSpeImageOn == 1 {
  35. json.Unmarshal([]byte(v.SpeImages), &speImageList)
  36. }
  37. tmp := map[string]interface{}{
  38. "id": utils.IntToStr(v.Id),
  39. "title": v.Title,
  40. "img": ImageFormatWithBucket(scheme, host, v.Img),
  41. "info": v.Info,
  42. "price": v.Price,
  43. "stock": utils.IntToStr(v.Stock),
  44. "is_single_sku": utils.IntToStr(v.IsSingleSku),
  45. "sale_count": utils.IntToStr(v.SaleCount),
  46. }
  47. goodsList = append(goodsList, tmp)
  48. }
  49. }
  50. e.OutSuc(c, goodsList, nil)
  51. return
  52. }
  53. func GoodsSku(c *gin.Context) {
  54. var arg map[string]string
  55. if err := c.ShouldBindJSON(&arg); err != nil {
  56. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  57. return
  58. }
  59. sku := db.GetGoodsSku(MasterDb(c), arg["goods_id"])
  60. skuList := make([]map[string]string, 0)
  61. if sku != nil {
  62. for _, v := range *sku {
  63. tmp := map[string]string{
  64. "sku_id": utils.Int64ToStr(v.SkuId),
  65. "goods_id": utils.IntToStr(v.GoodsId),
  66. "price": v.Price,
  67. "stock": utils.IntToStr(v.Stock),
  68. "indexes": v.Indexes,
  69. "sku": v.Sku,
  70. }
  71. skuList = append(skuList, tmp)
  72. }
  73. }
  74. goods := db.GetGoodsId(MasterDb(c), arg["goods_id"])
  75. res := map[string]interface{}{
  76. "spe": goods.Spe,
  77. "sku_list": skuList,
  78. }
  79. e.OutSuc(c, res, nil)
  80. return
  81. }
  82. func GoodsCoupon(c *gin.Context) {
  83. var arg map[string]string
  84. if err := c.ShouldBindJSON(&arg); err != nil {
  85. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  86. return
  87. }
  88. returnData := CommCoupon(c, arg["amount"])
  89. e.OutSuc(c, returnData, nil)
  90. return
  91. }