附近小店
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 

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