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

193 lines
5.1 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. 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 StoreLike(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.GetStoreLike(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 Store(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. arg["store_type"] = "0"
  115. user, _ := GetDefaultUser(c, c.GetHeader("Authorization"))
  116. store := db.GetStore(MasterDb(c), arg)
  117. storeList := make([]map[string]interface{}, 0)
  118. for _, v := range store {
  119. km := v["km"]
  120. if utils.StrToFloat64(v["km"]) < 1 {
  121. v["km"] = utils.IntToStr(int(utils.StrToFloat64(v["km"])*1000)) + "m"
  122. } else {
  123. v["km"] = GetCommissionPrec(c, v["km"], "2", "1")
  124. v["km"] += "km"
  125. }
  126. if utils.StrToFloat64(km) <= 0 || utils.StrToFloat64(v["lat"]) == 0 || utils.StrToFloat64(v["lng"]) == 0 {
  127. v["km"] = "-"
  128. }
  129. label := make([]string, 0)
  130. tmp := map[string]interface{}{
  131. "lat": v["lat"],
  132. "lng": v["lng"],
  133. "address": v["address"],
  134. "work_state": v["work_state"],
  135. "name": v["name"],
  136. "id": v["id"],
  137. "uid": v["uid"],
  138. "km": v["km"],
  139. "time_str": v["timer"],
  140. "phone": v["phone"],
  141. "label": label,
  142. "is_like": "0",
  143. }
  144. if user != nil {
  145. count, _ := MasterDb(c).Where("uid=? and store_id=?", user.Info.Uid, v["id"]).Count(&model.CommunityTeamStoreLike{})
  146. if count > 0 {
  147. tmp["is_like"] = "1"
  148. }
  149. }
  150. storeList = append(storeList, tmp)
  151. }
  152. e.OutSuc(c, storeList, nil)
  153. return
  154. }
  155. func StoreAddLike(c *gin.Context) {
  156. var arg map[string]string
  157. if err := c.ShouldBindJSON(&arg); err != nil {
  158. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  159. return
  160. }
  161. user := GetUser(c)
  162. count, _ := MasterDb(c).Where("uid=? and store_id=?", user.Info.Uid, arg["id"]).Count(&model.CommunityTeamStoreLike{})
  163. if count > 0 {
  164. e.OutErr(c, 400, e.NewErr(400, "已收藏"))
  165. return
  166. }
  167. var data = model.CommunityTeamStoreLike{
  168. Uid: user.Info.Uid,
  169. StoreId: utils.StrToInt(arg["id"]),
  170. Time: time.Now(),
  171. }
  172. MasterDb(c).Insert(&data)
  173. e.OutSuc(c, "success", nil)
  174. return
  175. }
  176. func StoreCancelLike(c *gin.Context) {
  177. var arg map[string]string
  178. if err := c.ShouldBindJSON(&arg); err != nil {
  179. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  180. return
  181. }
  182. user := GetUser(c)
  183. MasterDb(c).Where("uid=? and store_id=?", user.Info.Uid, arg["id"]).Delete(&model.CommunityTeamStoreLike{})
  184. e.OutSuc(c, "success", nil)
  185. return
  186. }