附近小店
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 

138 Zeilen
3.4 KiB

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