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

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