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

3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. goods := db.GetGoodsId(MasterDb(c), arg["goods_id"])
  61. res := map[string]interface{}{
  62. "spe": goods.Spe,
  63. "sku_list": skuList,
  64. }
  65. e.OutSuc(c, res, nil)
  66. return
  67. }
  68. func GoodsCoupon(c *gin.Context) {
  69. var arg map[string]string
  70. if err := c.ShouldBindJSON(&arg); err != nil {
  71. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  72. return
  73. }
  74. returnData := CommCoupon(c, arg["amount"])
  75. e.OutSuc(c, returnData, nil)
  76. return
  77. }