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

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