附近小店
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.go 2.3 KiB

3 months ago
3 months ago
2 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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["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. }