附近小店
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 

359 satır
9.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 StorePayScan(c *gin.Context) {
  11. kind := c.DefaultQuery("type", "alipay") //1:支付宝 2:微信
  12. id, _ := c.GetQuery("id")
  13. if id == "" {
  14. e.OutErr(c, e.ERR_INVALID_ARGS, nil)
  15. return
  16. }
  17. engine := MasterDb(c)
  18. data := db.GetStorePayQrcodeById(engine, id)
  19. if data == nil {
  20. e.OutErr(c, 400, e.NewErr(400, "桌码不存在"))
  21. return
  22. }
  23. if data.IsUse != 1 {
  24. e.OutErr(c, 400, e.NewErr(400, "桌码不可用"))
  25. return
  26. }
  27. type RefundReq struct {
  28. StoreId string `json:"store_id" `
  29. StoreType string `json:"store_type" `
  30. AppId string `json:"app_id" `
  31. InviteCode string `json:"invite_code"`
  32. }
  33. store := db.GetStoreIdEg(engine, utils.IntToStr(data.Uid))
  34. if store == nil {
  35. e.OutErr(c, 400, e.NewErr(400, "门店不存在"))
  36. return
  37. }
  38. user, _ := db.UserProfileFindByID(engine, store.Uid)
  39. var appId = ""
  40. var inviteCode = user.InviteCode
  41. if kind != "alipay" {
  42. communityTeamStoreWxAppletId := db.SysCfgGet(c, "community_team_store_wx_applet_id")
  43. var wxApplet model.WxAppletList
  44. MasterDb(c).Where("id=?", communityTeamStoreWxAppletId).Get(&wxApplet)
  45. appId = wxApplet.OriginalAppId
  46. }
  47. var result = RefundReq{
  48. StoreId: utils.IntToStr(data.Uid),
  49. AppId: appId,
  50. StoreType: utils.IntToStr(store.StoreType),
  51. InviteCode: inviteCode,
  52. }
  53. e.OutSuc(c, result, nil)
  54. return
  55. }
  56. func StoreScan(c *gin.Context) {
  57. kind := c.DefaultQuery("type", "alipay") //1:支付宝 2:微信
  58. id, _ := c.GetQuery("id")
  59. if id == "" {
  60. e.OutErr(c, e.ERR_INVALID_ARGS, nil)
  61. return
  62. }
  63. engine := MasterDb(c)
  64. data := db.GetStoreQrcodeById(engine, id)
  65. if data == nil {
  66. e.OutErr(c, 400, e.NewErr(400, "桌码不存在"))
  67. return
  68. }
  69. if data.IsUse != 1 {
  70. e.OutErr(c, 400, e.NewErr(400, "桌码不可用"))
  71. return
  72. }
  73. type RefundReq struct {
  74. StoreId string `json:"store_id" `
  75. StoreType string `json:"store_type" `
  76. TableNumber string `json:"table_number" `
  77. AppId string `json:"app_id" `
  78. InviteCode string `json:"invite_code"`
  79. }
  80. store := db.GetStoreIdEg(engine, utils.IntToStr(data.Uid))
  81. if store == nil {
  82. e.OutErr(c, 400, e.NewErr(400, "门店不存在"))
  83. return
  84. }
  85. user, _ := db.UserProfileFindByID(engine, store.Uid)
  86. var appId = ""
  87. var inviteCode = user.InviteCode
  88. if kind != "alipay" {
  89. communityTeamStoreWxAppletId := db.SysCfgGet(c, "community_team_store_wx_applet_id")
  90. var wxApplet model.WxAppletList
  91. MasterDb(c).Where("id=?", communityTeamStoreWxAppletId).Get(&wxApplet)
  92. appId = wxApplet.OriginalAppId
  93. }
  94. var result = RefundReq{
  95. StoreId: utils.IntToStr(data.Uid),
  96. TableNumber: data.TableNum,
  97. AppId: appId,
  98. StoreType: utils.IntToStr(store.StoreType),
  99. InviteCode: inviteCode,
  100. }
  101. e.OutSuc(c, result, nil)
  102. return
  103. }
  104. func BankStore(c *gin.Context) {
  105. var arg map[string]string
  106. if err := c.ShouldBindJSON(&arg); err != nil {
  107. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  108. return
  109. }
  110. arg["store_type"] = "0"
  111. user, _ := GetDefaultUser(c, c.GetHeader("Authorization"))
  112. var store = make([]map[string]string, 0)
  113. if arg["cid"] == "2" {
  114. store = db.GetStoreLike(MasterDb(c), arg)
  115. } else {
  116. store = db.GetStore(MasterDb(c), arg)
  117. }
  118. storeList := make([]map[string]interface{}, 0)
  119. for _, v := range store {
  120. km := v["km"]
  121. if utils.StrToFloat64(v["km"]) < 1 {
  122. v["km"] = utils.IntToStr(int(utils.StrToFloat64(v["km"])*1000)) + "m"
  123. } else {
  124. v["km"] = GetCommissionPrec(c, v["km"], "2", "1")
  125. v["km"] += "km"
  126. }
  127. if utils.StrToFloat64(km) <= 0 || utils.StrToFloat64(v["lat"]) == 0 || utils.StrToFloat64(v["lng"]) == 0 {
  128. v["km"] = "-"
  129. }
  130. tmp := map[string]interface{}{
  131. "lat": v["lat"],
  132. "lng": v["lng"],
  133. "address": v["address"],
  134. "name": v["name"],
  135. "id": v["id"],
  136. "km": v["km"],
  137. "time_str": v["timer"],
  138. "uid": v["uid"],
  139. "phone": v["phone"],
  140. "logo": v["logo"],
  141. "is_like": "0",
  142. "fan": "",
  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 NewStore(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. arg["store_type"] = "3"
  162. user, _ := GetDefaultUser(c, c.GetHeader("Authorization"))
  163. var store = make([]map[string]string, 0)
  164. if arg["cid"] == "2" {
  165. store = db.GetStoreLike(MasterDb(c), arg)
  166. } else {
  167. store = db.GetStore(MasterDb(c), arg)
  168. }
  169. storeList := make([]map[string]interface{}, 0)
  170. for _, v := range store {
  171. km := v["km"]
  172. if utils.StrToFloat64(v["km"]) < 1 {
  173. v["km"] = utils.IntToStr(int(utils.StrToFloat64(v["km"])*1000)) + "m"
  174. } else {
  175. v["km"] = GetCommissionPrec(c, v["km"], "2", "1")
  176. v["km"] += "km"
  177. }
  178. if utils.StrToFloat64(km) <= 0 || utils.StrToFloat64(v["lat"]) == 0 || utils.StrToFloat64(v["lng"]) == 0 {
  179. v["km"] = "-"
  180. }
  181. tmp := map[string]interface{}{
  182. "lat": v["lat"],
  183. "lng": v["lng"],
  184. "address": v["address"],
  185. "name": v["name"],
  186. "id": v["id"],
  187. "km": v["km"],
  188. "time_str": v["timer"],
  189. "uid": v["uid"],
  190. "store_id": v["uid"],
  191. "store_type": v["store_type"],
  192. "phone": v["phone"],
  193. "logo": v["logo"],
  194. "is_like": "0",
  195. "fan": "",
  196. }
  197. if user != nil {
  198. count, _ := MasterDb(c).Where("uid=? and store_id=?", user.Info.Uid, v["id"]).Count(&model.CommunityTeamStoreLike{})
  199. if count > 0 {
  200. tmp["is_like"] = "1"
  201. }
  202. }
  203. storeList = append(storeList, tmp)
  204. }
  205. e.OutSuc(c, storeList, nil)
  206. return
  207. }
  208. func StoreLike(c *gin.Context) {
  209. var arg map[string]string
  210. if err := c.ShouldBindJSON(&arg); err != nil {
  211. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  212. return
  213. }
  214. arg["store_type"] = "0"
  215. storeId := c.GetHeader("store_id")
  216. if utils.StrToInt(storeId) > 0 {
  217. arg["store_id"] = storeId
  218. storeData := db.GetStoreIdEg(MasterDb(c), storeId)
  219. if storeData.StoreType == 0 {
  220. arg["store_id"] = "0"
  221. }
  222. arg["store_type"] = utils.IntToStr(storeData.StoreType)
  223. }
  224. user, _ := GetDefaultUser(c, c.GetHeader("Authorization"))
  225. store := db.GetStoreLike(MasterDb(c), arg)
  226. storeList := make([]map[string]interface{}, 0)
  227. for _, v := range store {
  228. km := v["km"]
  229. if utils.StrToFloat64(v["km"]) < 1 {
  230. v["km"] = utils.IntToStr(int(utils.StrToFloat64(v["km"])*1000)) + "m"
  231. } else {
  232. v["km"] = GetCommissionPrec(c, v["km"], "2", "1")
  233. v["km"] += "km"
  234. }
  235. if utils.StrToFloat64(km) <= 0 || utils.StrToFloat64(v["lat"]) == 0 || utils.StrToFloat64(v["lng"]) == 0 {
  236. v["km"] = "-"
  237. }
  238. label := make([]string, 0)
  239. tmp := map[string]interface{}{
  240. "lat": v["lat"],
  241. "lng": v["lng"],
  242. "address": v["address"],
  243. "work_state": v["work_state"],
  244. "name": v["name"],
  245. "id": v["id"],
  246. "uid": v["uid"],
  247. "km": v["km"],
  248. "time_str": v["timer"],
  249. "phone": v["phone"],
  250. "label": label,
  251. "is_like": "0",
  252. }
  253. if user != nil {
  254. count, _ := MasterDb(c).Where("uid=? and store_id=?", user.Info.Uid, v["id"]).Count(&model.CommunityTeamStoreLike{})
  255. if count > 0 {
  256. tmp["is_like"] = "1"
  257. }
  258. }
  259. storeList = append(storeList, tmp)
  260. }
  261. e.OutSuc(c, storeList, nil)
  262. return
  263. }
  264. func Store(c *gin.Context) {
  265. var arg map[string]string
  266. if err := c.ShouldBindJSON(&arg); err != nil {
  267. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  268. return
  269. }
  270. arg["store_type"] = "0"
  271. storeId := c.GetHeader("store_id")
  272. if utils.StrToInt(storeId) > 0 {
  273. arg["store_id"] = storeId
  274. storeData := db.GetStoreIdEg(MasterDb(c), storeId)
  275. if storeData.StoreType == 0 {
  276. arg["store_id"] = "0"
  277. }
  278. arg["store_type"] = utils.IntToStr(storeData.StoreType)
  279. }
  280. user, _ := GetDefaultUser(c, c.GetHeader("Authorization"))
  281. store := db.GetStore(MasterDb(c), arg)
  282. storeList := make([]map[string]interface{}, 0)
  283. for _, v := range store {
  284. km := v["km"]
  285. if utils.StrToFloat64(v["km"]) < 1 {
  286. v["km"] = utils.IntToStr(int(utils.StrToFloat64(v["km"])*1000)) + "m"
  287. } else {
  288. v["km"] = GetCommissionPrec(c, v["km"], "2", "1")
  289. v["km"] += "km"
  290. }
  291. if utils.StrToFloat64(km) <= 0 || utils.StrToFloat64(v["lat"]) == 0 || utils.StrToFloat64(v["lng"]) == 0 {
  292. v["km"] = "-"
  293. }
  294. label := make([]string, 0)
  295. tmp := map[string]interface{}{
  296. "lat": v["lat"],
  297. "lng": v["lng"],
  298. "address": v["address"],
  299. "work_state": v["work_state"],
  300. "name": v["name"],
  301. "id": v["id"],
  302. "uid": v["uid"],
  303. "km": v["km"],
  304. "time_str": v["timer"],
  305. "phone": v["phone"],
  306. "label": label,
  307. "is_like": "0",
  308. }
  309. if user != nil {
  310. count, _ := MasterDb(c).Where("uid=? and store_id=?", user.Info.Uid, v["id"]).Count(&model.CommunityTeamStoreLike{})
  311. if count > 0 {
  312. tmp["is_like"] = "1"
  313. }
  314. }
  315. storeList = append(storeList, tmp)
  316. }
  317. e.OutSuc(c, storeList, nil)
  318. return
  319. }
  320. func StoreAddLike(c *gin.Context) {
  321. var arg map[string]string
  322. if err := c.ShouldBindJSON(&arg); err != nil {
  323. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  324. return
  325. }
  326. user := GetUser(c)
  327. count, _ := MasterDb(c).Where("uid=? and store_id=?", user.Info.Uid, arg["id"]).Count(&model.CommunityTeamStoreLike{})
  328. if count > 0 {
  329. e.OutErr(c, 400, e.NewErr(400, "已收藏"))
  330. return
  331. }
  332. var data = model.CommunityTeamStoreLike{
  333. Uid: user.Info.Uid,
  334. StoreId: utils.StrToInt(arg["id"]),
  335. Time: time.Now(),
  336. }
  337. MasterDb(c).Insert(&data)
  338. e.OutSuc(c, "success", nil)
  339. return
  340. }
  341. func StoreCancelLike(c *gin.Context) {
  342. var arg map[string]string
  343. if err := c.ShouldBindJSON(&arg); err != nil {
  344. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  345. return
  346. }
  347. user := GetUser(c)
  348. MasterDb(c).Where("uid=? and store_id=?", user.Info.Uid, arg["id"]).Delete(&model.CommunityTeamStoreLike{})
  349. e.OutSuc(c, "success", nil)
  350. return
  351. }