附近小店
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

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