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

1 maand geleden
1 maand geleden
1 maand geleden
1 maand geleden
1 maand geleden
1 maand geleden
1 maand geleden
1 maand geleden
1 maand geleden
1 maand geleden
1 maand geleden
1 maand geleden
1 maand geleden
1 maand geleden
1 maand geleden
1 maand geleden
1 maand geleden
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. package svc
  2. import (
  3. "applet/app/db"
  4. "applet/app/db/model"
  5. "applet/app/e"
  6. "applet/app/utils"
  7. "github.com/gin-gonic/gin"
  8. "time"
  9. )
  10. func BankStore(c *gin.Context) {
  11. var arg map[string]string
  12. if err := c.ShouldBindJSON(&arg); err != nil {
  13. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  14. return
  15. }
  16. arg["store_type"] = "0"
  17. user, _ := GetDefaultUser(c, c.GetHeader("Authorization"))
  18. var store = make([]map[string]string, 0)
  19. if arg["cid"] == "2" {
  20. store = db.GetStoreLike(MasterDb(c), arg)
  21. } else {
  22. store = db.GetStore(MasterDb(c), arg)
  23. }
  24. storeList := make([]map[string]interface{}, 0)
  25. for _, v := range store {
  26. km := v["km"]
  27. if utils.StrToFloat64(v["km"]) < 1 {
  28. v["km"] = utils.IntToStr(int(utils.StrToFloat64(v["km"])*1000)) + "m"
  29. } else {
  30. v["km"] = GetCommissionPrec(c, v["km"], "2", "1")
  31. v["km"] += "km"
  32. }
  33. if utils.StrToFloat64(km) <= 0 || utils.StrToFloat64(v["lat"]) == 0 || utils.StrToFloat64(v["lng"]) == 0 {
  34. v["km"] = "-"
  35. }
  36. tmp := map[string]interface{}{
  37. "lat": v["lat"],
  38. "lng": v["lng"],
  39. "address": v["address"],
  40. "name": v["name"],
  41. "id": v["id"],
  42. "km": v["km"],
  43. "time_str": v["timer"],
  44. "uid": v["uid"],
  45. "phone": v["phone"],
  46. "logo": v["logo"],
  47. "is_like": "0",
  48. "fan": "",
  49. }
  50. if user != nil {
  51. count, _ := MasterDb(c).Where("uid=? and store_id=?", user.Info.Uid, v["id"]).Count(&model.CommunityTeamStoreLike{})
  52. if count > 0 {
  53. tmp["is_like"] = "1"
  54. }
  55. }
  56. storeList = append(storeList, tmp)
  57. }
  58. e.OutSuc(c, storeList, nil)
  59. return
  60. }
  61. func Store(c *gin.Context) {
  62. var arg map[string]string
  63. if err := c.ShouldBindJSON(&arg); err != nil {
  64. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  65. return
  66. }
  67. arg["store_type"] = "0"
  68. user, _ := GetDefaultUser(c, c.GetHeader("Authorization"))
  69. store := db.GetStore(MasterDb(c), arg)
  70. storeList := make([]map[string]interface{}, 0)
  71. for _, v := range store {
  72. km := v["km"]
  73. if utils.StrToFloat64(v["km"]) < 1 {
  74. v["km"] = utils.IntToStr(int(utils.StrToFloat64(v["km"])*1000)) + "m"
  75. } else {
  76. v["km"] = GetCommissionPrec(c, v["km"], "2", "1")
  77. v["km"] += "km"
  78. }
  79. if utils.StrToFloat64(km) <= 0 || utils.StrToFloat64(v["lat"]) == 0 || utils.StrToFloat64(v["lng"]) == 0 {
  80. v["km"] = "-"
  81. }
  82. label := make([]string, 0)
  83. tmp := map[string]interface{}{
  84. "lat": v["lat"],
  85. "lng": v["lng"],
  86. "address": v["address"],
  87. "work_state": v["work_state"],
  88. "name": v["name"],
  89. "id": v["id"],
  90. "uid": v["uid"],
  91. "km": v["km"],
  92. "time_str": v["timer"],
  93. "phone": v["phone"],
  94. "label": label,
  95. "is_like": "0",
  96. }
  97. if user != nil {
  98. count, _ := MasterDb(c).Where("uid=? and store_id=?", user.Info.Uid, v["id"]).Count(&model.CommunityTeamStoreLike{})
  99. if count > 0 {
  100. tmp["is_like"] = "1"
  101. }
  102. }
  103. storeList = append(storeList, tmp)
  104. }
  105. e.OutSuc(c, storeList, nil)
  106. return
  107. }
  108. func StoreAddLike(c *gin.Context) {
  109. var arg map[string]string
  110. if err := c.ShouldBindJSON(&arg); err != nil {
  111. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  112. return
  113. }
  114. user := GetUser(c)
  115. count, _ := MasterDb(c).Where("uid=? and store_id=?", user.Info.Uid, arg["id"]).Count(&model.CommunityTeamStoreLike{})
  116. if count > 0 {
  117. e.OutErr(c, 400, e.NewErr(400, "已收藏"))
  118. return
  119. }
  120. var data = model.CommunityTeamStoreLike{
  121. Uid: user.Info.Uid,
  122. StoreId: utils.StrToInt(arg["id"]),
  123. Time: time.Now(),
  124. }
  125. MasterDb(c).Insert(&data)
  126. e.OutSuc(c, "success", nil)
  127. return
  128. }
  129. func StoreCancelLike(c *gin.Context) {
  130. var arg map[string]string
  131. if err := c.ShouldBindJSON(&arg); err != nil {
  132. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  133. return
  134. }
  135. user := GetUser(c)
  136. MasterDb(c).Where("uid=? and store_id=?", user.Info.Uid, arg["id"]).Delete(&model.CommunityTeamStoreLike{})
  137. e.OutSuc(c, "success", nil)
  138. return
  139. }