附近小店
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 

263 linhas
7.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 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. storeData := db.GetStoreIdEg(MasterDb(c), storeId)
  125. if storeData.StoreType == 0 {
  126. arg["store_id"] = "0"
  127. }
  128. arg["store_type"] = utils.IntToStr(storeData.StoreType)
  129. }
  130. user, _ := GetDefaultUser(c, c.GetHeader("Authorization"))
  131. store := db.GetStoreLike(MasterDb(c), arg)
  132. storeList := make([]map[string]interface{}, 0)
  133. for _, v := range store {
  134. km := v["km"]
  135. if utils.StrToFloat64(v["km"]) < 1 {
  136. v["km"] = utils.IntToStr(int(utils.StrToFloat64(v["km"])*1000)) + "m"
  137. } else {
  138. v["km"] = GetCommissionPrec(c, v["km"], "2", "1")
  139. v["km"] += "km"
  140. }
  141. if utils.StrToFloat64(km) <= 0 || utils.StrToFloat64(v["lat"]) == 0 || utils.StrToFloat64(v["lng"]) == 0 {
  142. v["km"] = "-"
  143. }
  144. label := make([]string, 0)
  145. tmp := map[string]interface{}{
  146. "lat": v["lat"],
  147. "lng": v["lng"],
  148. "address": v["address"],
  149. "work_state": v["work_state"],
  150. "name": v["name"],
  151. "id": v["id"],
  152. "uid": v["uid"],
  153. "km": v["km"],
  154. "time_str": v["timer"],
  155. "phone": v["phone"],
  156. "label": label,
  157. "is_like": "0",
  158. }
  159. if user != nil {
  160. count, _ := MasterDb(c).Where("uid=? and store_id=?", user.Info.Uid, v["id"]).Count(&model.CommunityTeamStoreLike{})
  161. if count > 0 {
  162. tmp["is_like"] = "1"
  163. }
  164. }
  165. storeList = append(storeList, tmp)
  166. }
  167. e.OutSuc(c, storeList, nil)
  168. return
  169. }
  170. func Store(c *gin.Context) {
  171. var arg map[string]string
  172. if err := c.ShouldBindJSON(&arg); err != nil {
  173. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  174. return
  175. }
  176. arg["store_type"] = "0"
  177. storeId := c.GetHeader("store_id")
  178. if utils.StrToInt(storeId) > 0 {
  179. arg["store_id"] = storeId
  180. storeData := db.GetStoreIdEg(MasterDb(c), storeId)
  181. if storeData.StoreType == 0 {
  182. arg["store_id"] = "0"
  183. }
  184. arg["store_type"] = utils.IntToStr(storeData.StoreType)
  185. }
  186. user, _ := GetDefaultUser(c, c.GetHeader("Authorization"))
  187. store := db.GetStore(MasterDb(c), arg)
  188. storeList := make([]map[string]interface{}, 0)
  189. for _, v := range store {
  190. km := v["km"]
  191. if utils.StrToFloat64(v["km"]) < 1 {
  192. v["km"] = utils.IntToStr(int(utils.StrToFloat64(v["km"])*1000)) + "m"
  193. } else {
  194. v["km"] = GetCommissionPrec(c, v["km"], "2", "1")
  195. v["km"] += "km"
  196. }
  197. if utils.StrToFloat64(km) <= 0 || utils.StrToFloat64(v["lat"]) == 0 || utils.StrToFloat64(v["lng"]) == 0 {
  198. v["km"] = "-"
  199. }
  200. label := make([]string, 0)
  201. tmp := map[string]interface{}{
  202. "lat": v["lat"],
  203. "lng": v["lng"],
  204. "address": v["address"],
  205. "work_state": v["work_state"],
  206. "name": v["name"],
  207. "id": v["id"],
  208. "uid": v["uid"],
  209. "km": v["km"],
  210. "time_str": v["timer"],
  211. "phone": v["phone"],
  212. "label": label,
  213. "is_like": "0",
  214. }
  215. if user != nil {
  216. count, _ := MasterDb(c).Where("uid=? and store_id=?", user.Info.Uid, v["id"]).Count(&model.CommunityTeamStoreLike{})
  217. if count > 0 {
  218. tmp["is_like"] = "1"
  219. }
  220. }
  221. storeList = append(storeList, tmp)
  222. }
  223. e.OutSuc(c, storeList, nil)
  224. return
  225. }
  226. func StoreAddLike(c *gin.Context) {
  227. var arg map[string]string
  228. if err := c.ShouldBindJSON(&arg); err != nil {
  229. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  230. return
  231. }
  232. user := GetUser(c)
  233. count, _ := MasterDb(c).Where("uid=? and store_id=?", user.Info.Uid, arg["id"]).Count(&model.CommunityTeamStoreLike{})
  234. if count > 0 {
  235. e.OutErr(c, 400, e.NewErr(400, "已收藏"))
  236. return
  237. }
  238. var data = model.CommunityTeamStoreLike{
  239. Uid: user.Info.Uid,
  240. StoreId: utils.StrToInt(arg["id"]),
  241. Time: time.Now(),
  242. }
  243. MasterDb(c).Insert(&data)
  244. e.OutSuc(c, "success", nil)
  245. return
  246. }
  247. func StoreCancelLike(c *gin.Context) {
  248. var arg map[string]string
  249. if err := c.ShouldBindJSON(&arg); err != nil {
  250. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  251. return
  252. }
  253. user := GetUser(c)
  254. MasterDb(c).Where("uid=? and store_id=?", user.Info.Uid, arg["id"]).Delete(&model.CommunityTeamStoreLike{})
  255. e.OutSuc(c, "success", nil)
  256. return
  257. }