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

255 regels
6.8 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 NewStore(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"] = "3"
  68. user, _ := GetDefaultUser(c, c.GetHeader("Authorization"))
  69. var store = make([]map[string]string, 0)
  70. if arg["cid"] == "2" {
  71. store = db.GetStoreLike(MasterDb(c), arg)
  72. } else {
  73. store = db.GetStore(MasterDb(c), arg)
  74. }
  75. storeList := make([]map[string]interface{}, 0)
  76. for _, v := range store {
  77. km := v["km"]
  78. if utils.StrToFloat64(v["km"]) < 1 {
  79. v["km"] = utils.IntToStr(int(utils.StrToFloat64(v["km"])*1000)) + "m"
  80. } else {
  81. v["km"] = GetCommissionPrec(c, v["km"], "2", "1")
  82. v["km"] += "km"
  83. }
  84. if utils.StrToFloat64(km) <= 0 || utils.StrToFloat64(v["lat"]) == 0 || utils.StrToFloat64(v["lng"]) == 0 {
  85. v["km"] = "-"
  86. }
  87. tmp := map[string]interface{}{
  88. "lat": v["lat"],
  89. "lng": v["lng"],
  90. "address": v["address"],
  91. "name": v["name"],
  92. "id": v["id"],
  93. "km": v["km"],
  94. "time_str": v["timer"],
  95. "uid": v["uid"],
  96. "store_id": v["uid"],
  97. "store_type": v["store_type"],
  98. "phone": v["phone"],
  99. "logo": v["logo"],
  100. "is_like": "0",
  101. "fan": "",
  102. }
  103. if user != nil {
  104. count, _ := MasterDb(c).Where("uid=? and store_id=?", user.Info.Uid, v["id"]).Count(&model.CommunityTeamStoreLike{})
  105. if count > 0 {
  106. tmp["is_like"] = "1"
  107. }
  108. }
  109. storeList = append(storeList, tmp)
  110. }
  111. e.OutSuc(c, storeList, nil)
  112. return
  113. }
  114. func StoreLike(c *gin.Context) {
  115. var arg map[string]string
  116. if err := c.ShouldBindJSON(&arg); err != nil {
  117. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  118. return
  119. }
  120. arg["store_type"] = "0"
  121. storeId := c.GetHeader("store_id")
  122. if utils.StrToInt(storeId) > 0 {
  123. arg["store_id"] = storeId
  124. arg["store_type"] = "1"
  125. }
  126. user, _ := GetDefaultUser(c, c.GetHeader("Authorization"))
  127. store := db.GetStoreLike(MasterDb(c), arg)
  128. storeList := make([]map[string]interface{}, 0)
  129. for _, v := range store {
  130. km := v["km"]
  131. if utils.StrToFloat64(v["km"]) < 1 {
  132. v["km"] = utils.IntToStr(int(utils.StrToFloat64(v["km"])*1000)) + "m"
  133. } else {
  134. v["km"] = GetCommissionPrec(c, v["km"], "2", "1")
  135. v["km"] += "km"
  136. }
  137. if utils.StrToFloat64(km) <= 0 || utils.StrToFloat64(v["lat"]) == 0 || utils.StrToFloat64(v["lng"]) == 0 {
  138. v["km"] = "-"
  139. }
  140. label := make([]string, 0)
  141. tmp := map[string]interface{}{
  142. "lat": v["lat"],
  143. "lng": v["lng"],
  144. "address": v["address"],
  145. "work_state": v["work_state"],
  146. "name": v["name"],
  147. "id": v["id"],
  148. "uid": v["uid"],
  149. "km": v["km"],
  150. "time_str": v["timer"],
  151. "phone": v["phone"],
  152. "label": label,
  153. "is_like": "0",
  154. }
  155. if user != nil {
  156. count, _ := MasterDb(c).Where("uid=? and store_id=?", user.Info.Uid, v["id"]).Count(&model.CommunityTeamStoreLike{})
  157. if count > 0 {
  158. tmp["is_like"] = "1"
  159. }
  160. }
  161. storeList = append(storeList, tmp)
  162. }
  163. e.OutSuc(c, storeList, nil)
  164. return
  165. }
  166. func Store(c *gin.Context) {
  167. var arg map[string]string
  168. if err := c.ShouldBindJSON(&arg); err != nil {
  169. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  170. return
  171. }
  172. arg["store_type"] = "0"
  173. storeId := c.GetHeader("store_id")
  174. if utils.StrToInt(storeId) > 0 {
  175. arg["store_id"] = storeId
  176. arg["store_type"] = "1"
  177. }
  178. user, _ := GetDefaultUser(c, c.GetHeader("Authorization"))
  179. store := db.GetStore(MasterDb(c), arg)
  180. storeList := make([]map[string]interface{}, 0)
  181. for _, v := range store {
  182. km := v["km"]
  183. if utils.StrToFloat64(v["km"]) < 1 {
  184. v["km"] = utils.IntToStr(int(utils.StrToFloat64(v["km"])*1000)) + "m"
  185. } else {
  186. v["km"] = GetCommissionPrec(c, v["km"], "2", "1")
  187. v["km"] += "km"
  188. }
  189. if utils.StrToFloat64(km) <= 0 || utils.StrToFloat64(v["lat"]) == 0 || utils.StrToFloat64(v["lng"]) == 0 {
  190. v["km"] = "-"
  191. }
  192. label := make([]string, 0)
  193. tmp := map[string]interface{}{
  194. "lat": v["lat"],
  195. "lng": v["lng"],
  196. "address": v["address"],
  197. "work_state": v["work_state"],
  198. "name": v["name"],
  199. "id": v["id"],
  200. "uid": v["uid"],
  201. "km": v["km"],
  202. "time_str": v["timer"],
  203. "phone": v["phone"],
  204. "label": label,
  205. "is_like": "0",
  206. }
  207. if user != nil {
  208. count, _ := MasterDb(c).Where("uid=? and store_id=?", user.Info.Uid, v["id"]).Count(&model.CommunityTeamStoreLike{})
  209. if count > 0 {
  210. tmp["is_like"] = "1"
  211. }
  212. }
  213. storeList = append(storeList, tmp)
  214. }
  215. e.OutSuc(c, storeList, nil)
  216. return
  217. }
  218. func StoreAddLike(c *gin.Context) {
  219. var arg map[string]string
  220. if err := c.ShouldBindJSON(&arg); err != nil {
  221. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  222. return
  223. }
  224. user := GetUser(c)
  225. count, _ := MasterDb(c).Where("uid=? and store_id=?", user.Info.Uid, arg["id"]).Count(&model.CommunityTeamStoreLike{})
  226. if count > 0 {
  227. e.OutErr(c, 400, e.NewErr(400, "已收藏"))
  228. return
  229. }
  230. var data = model.CommunityTeamStoreLike{
  231. Uid: user.Info.Uid,
  232. StoreId: utils.StrToInt(arg["id"]),
  233. Time: time.Now(),
  234. }
  235. MasterDb(c).Insert(&data)
  236. e.OutSuc(c, "success", nil)
  237. return
  238. }
  239. func StoreCancelLike(c *gin.Context) {
  240. var arg map[string]string
  241. if err := c.ShouldBindJSON(&arg); err != nil {
  242. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  243. return
  244. }
  245. user := GetUser(c)
  246. MasterDb(c).Where("uid=? and store_id=?", user.Info.Uid, arg["id"]).Delete(&model.CommunityTeamStoreLike{})
  247. e.OutSuc(c, "success", nil)
  248. return
  249. }