附近小店
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 

479 Zeilen
13 KiB

  1. package svc
  2. import (
  3. "applet/app/db"
  4. "applet/app/db/model"
  5. "applet/app/e"
  6. "applet/app/md"
  7. "applet/app/utils"
  8. "encoding/json"
  9. "github.com/gin-gonic/gin"
  10. "time"
  11. )
  12. func StorePayInfo(c *gin.Context) {
  13. var arg map[string]string
  14. if err := c.ShouldBindJSON(&arg); err != nil {
  15. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  16. return
  17. }
  18. engine := MasterDb(c)
  19. store := db.GetStoreIdEg(engine, arg["store_id"])
  20. if store == nil {
  21. e.OutErr(c, 400, e.NewErr(400, "门店不存在"))
  22. return
  23. }
  24. res := map[string]string{
  25. "name": store.Name, "logo": store.Logo,
  26. }
  27. e.OutSuc(c, res, nil)
  28. return
  29. }
  30. func StorePayScan(c *gin.Context) {
  31. kind := c.DefaultQuery("type", "alipay") //1:支付宝 2:微信
  32. id, _ := c.GetQuery("id")
  33. if id == "" {
  34. e.OutErr(c, e.ERR_INVALID_ARGS, nil)
  35. return
  36. }
  37. engine := MasterDb(c)
  38. data := db.GetStorePayQrcodeById(engine, id)
  39. if data == nil {
  40. e.OutErr(c, 400, e.NewErr(400, "桌码不存在"))
  41. return
  42. }
  43. if data.IsUse != 1 {
  44. e.OutErr(c, 400, e.NewErr(400, "桌码不可用"))
  45. return
  46. }
  47. type RefundReq struct {
  48. StoreId string `json:"store_id" `
  49. StoreType string `json:"store_type" `
  50. AppId string `json:"app_id" `
  51. AppLogo string `json:"app_logo"`
  52. InviteCode string `json:"invite_code"`
  53. }
  54. store := db.GetStoreIdEg(engine, utils.IntToStr(data.Uid))
  55. if store == nil {
  56. e.OutErr(c, 400, e.NewErr(400, "门店不存在"))
  57. return
  58. }
  59. user, _ := db.UserProfileFindByID(engine, store.Uid)
  60. var appId = ""
  61. var appLogo = ""
  62. var inviteCode = user.InviteCode
  63. if kind != "alipay" {
  64. communityTeamStoreWxAppletId := db.SysCfgGet(c, "community_team_store_wx_applet_id")
  65. var wxApplet model.WxAppletList
  66. MasterDb(c).Where("id=?", communityTeamStoreWxAppletId).Get(&wxApplet)
  67. appId = wxApplet.OriginalAppId
  68. appLogo = wxApplet.AppletLogo
  69. }
  70. var result = RefundReq{
  71. StoreId: utils.IntToStr(data.Uid),
  72. AppId: appId,
  73. StoreType: utils.IntToStr(store.StoreType),
  74. InviteCode: inviteCode,
  75. AppLogo: appLogo,
  76. }
  77. e.OutSuc(c, result, nil)
  78. return
  79. }
  80. func StoreScan(c *gin.Context) {
  81. kind := c.DefaultQuery("type", "alipay") //1:支付宝 2:微信
  82. id, _ := c.GetQuery("id")
  83. if id == "" {
  84. e.OutErr(c, e.ERR_INVALID_ARGS, nil)
  85. return
  86. }
  87. engine := MasterDb(c)
  88. data := db.GetStoreQrcodeById(engine, id)
  89. if data == nil {
  90. e.OutErr(c, 400, e.NewErr(400, "桌码不存在"))
  91. return
  92. }
  93. if data.IsUse != 1 {
  94. e.OutErr(c, 400, e.NewErr(400, "桌码不可用"))
  95. return
  96. }
  97. type RefundReq struct {
  98. StoreId string `json:"store_id" `
  99. StoreType string `json:"store_type" `
  100. TableNumber string `json:"table_number" `
  101. AppId string `json:"app_id" `
  102. AppLogo string `json:"app_logo"`
  103. InviteCode string `json:"invite_code"`
  104. }
  105. store := db.GetStoreIdEg(engine, utils.IntToStr(data.Uid))
  106. if store == nil {
  107. e.OutErr(c, 400, e.NewErr(400, "门店不存在"))
  108. return
  109. }
  110. user, _ := db.UserProfileFindByID(engine, store.Uid)
  111. var appId = ""
  112. var appLogo = ""
  113. var inviteCode = user.InviteCode
  114. if kind != "alipay" {
  115. communityTeamStoreWxAppletId := db.SysCfgGet(c, "community_team_store_wx_applet_id")
  116. var wxApplet model.WxAppletList
  117. MasterDb(c).Where("id=?", communityTeamStoreWxAppletId).Get(&wxApplet)
  118. appId = wxApplet.OriginalAppId
  119. appLogo = wxApplet.AppletLogo
  120. }
  121. var result = RefundReq{
  122. StoreId: utils.IntToStr(data.Uid),
  123. TableNumber: data.TableNum,
  124. AppId: appId,
  125. StoreType: utils.IntToStr(store.StoreType),
  126. InviteCode: inviteCode,
  127. AppLogo: appLogo,
  128. }
  129. e.OutSuc(c, result, nil)
  130. return
  131. }
  132. func BankStore(c *gin.Context) {
  133. var arg map[string]string
  134. if err := c.ShouldBindJSON(&arg); err != nil {
  135. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  136. return
  137. }
  138. arg["store_type"] = "0"
  139. user, _ := GetDefaultUser(c, c.GetHeader("Authorization"))
  140. var store = make([]map[string]string, 0)
  141. if arg["cid"] == "2" || arg["is_like"] == "1" {
  142. store = db.GetStoreLike(MasterDb(c), arg)
  143. } else {
  144. store = db.GetStore(MasterDb(c), arg)
  145. }
  146. storeList := make([]map[string]interface{}, 0)
  147. for _, v := range store {
  148. km := v["km"]
  149. if utils.StrToFloat64(v["km"]) < 1 {
  150. v["km"] = utils.IntToStr(int(utils.StrToFloat64(v["km"])*1000)) + "m"
  151. } else {
  152. v["km"] = GetCommissionPrec(c, v["km"], "2", "1")
  153. v["km"] += "km"
  154. }
  155. if utils.StrToFloat64(km) <= 0 || utils.StrToFloat64(v["lat"]) == 0 || utils.StrToFloat64(v["lng"]) == 0 {
  156. v["km"] = "-"
  157. }
  158. label := make([]string, 0)
  159. if v["is_new"] == "1" {
  160. label = append(label, "新门店")
  161. }
  162. isWork := "1"
  163. if v["work_state"] == "1" {
  164. isWork = "0"
  165. }
  166. tmp := map[string]interface{}{
  167. "lat": v["lat"],
  168. "lng": v["lng"],
  169. "address": v["address"],
  170. "name": v["name"],
  171. "id": v["id"],
  172. "km": v["km"],
  173. "time_str": v["timer"],
  174. "uid": v["uid"],
  175. "phone": v["phone"],
  176. "logo": v["logo"],
  177. "is_work": isWork,
  178. "is_like": "0",
  179. "fan": "",
  180. "label": label,
  181. }
  182. if utils.StrToInt(v["fan"]) > 0 {
  183. tmp["fan"] = v["fan"]
  184. }
  185. if user != nil {
  186. count, _ := MasterDb(c).Where("uid=? and store_id=?", user.Info.Uid, v["id"]).Count(&model.CommunityTeamStoreLike{})
  187. if count > 0 {
  188. tmp["is_like"] = "1"
  189. }
  190. }
  191. storeList = append(storeList, tmp)
  192. }
  193. e.OutSuc(c, storeList, nil)
  194. return
  195. }
  196. func BankNotice(c *gin.Context) {
  197. var arg map[string]string
  198. if err := c.ShouldBindJSON(&arg); err != nil {
  199. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  200. return
  201. }
  202. data := db.GetBankNotice(MasterDb(c), arg)
  203. list := make([]map[string]string, 0)
  204. if data != nil {
  205. for _, v := range *data {
  206. tmp := map[string]string{
  207. "id": utils.IntToStr(v.Id),
  208. "title": v.Title,
  209. "content": v.Content,
  210. "create_time": v.CreateTime.Format("2006-01-02 15:04"),
  211. }
  212. list = append(list, tmp)
  213. }
  214. }
  215. e.OutSuc(c, list, nil)
  216. return
  217. }
  218. func BankActivity(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. list := make([]map[string]interface{}, 0)
  225. cate := db.GetActivityCate(MasterDb(c), arg["uid"])
  226. if cate != nil {
  227. ids := make([]int, 0)
  228. for _, v := range *cate {
  229. ids = append(ids, v.Id)
  230. }
  231. activityMap := make(map[int][]map[string]interface{})
  232. if len(ids) > 0 {
  233. activity := db.GetActivity(MasterDb(c), ids)
  234. if activity != nil {
  235. scheme, host := ImageBucket(c)
  236. for _, v := range *activity {
  237. _, ok := activityMap[v.Cid]
  238. if ok == false {
  239. activityMap[v.Cid] = make([]map[string]interface{}, 0)
  240. }
  241. var skip md.Skip
  242. json.Unmarshal(utils.MarshalJSONCamelCase2JsonSnakeCase(v.Skip), &skip)
  243. tmp := map[string]interface{}{
  244. "name": v.Name, "img": ImageFormatWithBucket(scheme, host, v.Img), "skip": skip,
  245. }
  246. activityMap[v.Cid] = append(activityMap[v.Cid], tmp)
  247. }
  248. }
  249. }
  250. for _, v := range *cate {
  251. tmpList := make([]map[string]interface{}, 0)
  252. _, ok := activityMap[v.Id]
  253. if ok {
  254. tmpList = activityMap[v.Id]
  255. }
  256. tmp := map[string]interface{}{
  257. "name": v.Name,
  258. "list": tmpList,
  259. }
  260. list = append(list, tmp)
  261. }
  262. }
  263. e.OutSuc(c, list, nil)
  264. return
  265. }
  266. func NewStore(c *gin.Context) {
  267. var arg map[string]string
  268. if err := c.ShouldBindJSON(&arg); err != nil {
  269. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  270. return
  271. }
  272. arg["store_type"] = "3"
  273. user, _ := GetDefaultUser(c, c.GetHeader("Authorization"))
  274. var store = make([]map[string]string, 0)
  275. if arg["cid"] == "2" {
  276. store = db.GetStoreLike(MasterDb(c), arg)
  277. } else {
  278. store = db.GetStore(MasterDb(c), arg)
  279. }
  280. storeList := make([]map[string]interface{}, 0)
  281. for _, v := range store {
  282. km := v["km"]
  283. if utils.StrToFloat64(v["km"]) < 1 {
  284. v["km"] = utils.IntToStr(int(utils.StrToFloat64(v["km"])*1000)) + "m"
  285. } else {
  286. v["km"] = GetCommissionPrec(c, v["km"], "2", "1")
  287. v["km"] += "km"
  288. }
  289. if utils.StrToFloat64(km) <= 0 || utils.StrToFloat64(v["lat"]) == 0 || utils.StrToFloat64(v["lng"]) == 0 {
  290. v["km"] = "-"
  291. }
  292. tmp := map[string]interface{}{
  293. "lat": v["lat"],
  294. "lng": v["lng"],
  295. "address": v["address"],
  296. "name": v["name"],
  297. "id": v["id"],
  298. "km": v["km"],
  299. "time_str": v["timer"],
  300. "uid": v["uid"],
  301. "store_id": v["uid"],
  302. "store_type": v["store_type"],
  303. "phone": v["phone"],
  304. "logo": v["logo"],
  305. "is_like": "0",
  306. "fan": "",
  307. }
  308. if user != nil {
  309. count, _ := MasterDb(c).Where("uid=? and store_id=?", user.Info.Uid, v["id"]).Count(&model.CommunityTeamStoreLike{})
  310. if count > 0 {
  311. tmp["is_like"] = "1"
  312. }
  313. }
  314. storeList = append(storeList, tmp)
  315. }
  316. e.OutSuc(c, storeList, nil)
  317. return
  318. }
  319. func StoreLike(c *gin.Context) {
  320. var arg map[string]string
  321. if err := c.ShouldBindJSON(&arg); err != nil {
  322. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  323. return
  324. }
  325. arg["store_type"] = "0"
  326. storeId := c.GetHeader("store_id")
  327. if utils.StrToInt(storeId) > 0 {
  328. arg["store_id"] = storeId
  329. storeData := db.GetStoreIdEg(MasterDb(c), storeId)
  330. if storeData.StoreType == 0 {
  331. arg["store_id"] = "0"
  332. }
  333. arg["store_type"] = utils.IntToStr(storeData.StoreType)
  334. }
  335. user, _ := GetDefaultUser(c, c.GetHeader("Authorization"))
  336. store := db.GetStoreLike(MasterDb(c), arg)
  337. storeList := make([]map[string]interface{}, 0)
  338. for _, v := range store {
  339. km := v["km"]
  340. if utils.StrToFloat64(v["km"]) < 1 {
  341. v["km"] = utils.IntToStr(int(utils.StrToFloat64(v["km"])*1000)) + "m"
  342. } else {
  343. v["km"] = GetCommissionPrec(c, v["km"], "2", "1")
  344. v["km"] += "km"
  345. }
  346. if utils.StrToFloat64(km) <= 0 || utils.StrToFloat64(v["lat"]) == 0 || utils.StrToFloat64(v["lng"]) == 0 {
  347. v["km"] = "-"
  348. }
  349. label := make([]string, 0)
  350. tmp := map[string]interface{}{
  351. "lat": v["lat"],
  352. "lng": v["lng"],
  353. "address": v["address"],
  354. "work_state": v["work_state"],
  355. "name": v["name"],
  356. "id": v["id"],
  357. "uid": v["uid"],
  358. "km": v["km"],
  359. "time_str": v["timer"],
  360. "phone": v["phone"],
  361. "label": label,
  362. "is_like": "0",
  363. }
  364. if user != nil {
  365. count, _ := MasterDb(c).Where("uid=? and store_id=?", user.Info.Uid, v["id"]).Count(&model.CommunityTeamStoreLike{})
  366. if count > 0 {
  367. tmp["is_like"] = "1"
  368. }
  369. }
  370. storeList = append(storeList, tmp)
  371. }
  372. e.OutSuc(c, storeList, nil)
  373. return
  374. }
  375. func Store(c *gin.Context) {
  376. var arg map[string]string
  377. if err := c.ShouldBindJSON(&arg); err != nil {
  378. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  379. return
  380. }
  381. arg["store_type"] = "0"
  382. storeId := c.GetHeader("store_id")
  383. if utils.StrToInt(storeId) > 0 {
  384. arg["store_id"] = storeId
  385. storeData := db.GetStoreIdEg(MasterDb(c), storeId)
  386. if storeData.StoreType == 0 {
  387. arg["store_id"] = "0"
  388. }
  389. arg["store_type"] = utils.IntToStr(storeData.StoreType)
  390. }
  391. user, _ := GetDefaultUser(c, c.GetHeader("Authorization"))
  392. store := db.GetStore(MasterDb(c), arg)
  393. storeList := make([]map[string]interface{}, 0)
  394. for _, v := range store {
  395. km := v["km"]
  396. if utils.StrToFloat64(v["km"]) < 1 {
  397. v["km"] = utils.IntToStr(int(utils.StrToFloat64(v["km"])*1000)) + "m"
  398. } else {
  399. v["km"] = GetCommissionPrec(c, v["km"], "2", "1")
  400. v["km"] += "km"
  401. }
  402. if utils.StrToFloat64(km) <= 0 || utils.StrToFloat64(v["lat"]) == 0 || utils.StrToFloat64(v["lng"]) == 0 {
  403. v["km"] = "-"
  404. }
  405. label := make([]string, 0)
  406. tmp := map[string]interface{}{
  407. "lat": v["lat"],
  408. "lng": v["lng"],
  409. "address": v["address"],
  410. "work_state": v["work_state"],
  411. "name": v["name"],
  412. "id": v["id"],
  413. "uid": v["uid"],
  414. "km": v["km"],
  415. "time_str": v["timer"],
  416. "phone": v["phone"],
  417. "label": label,
  418. "is_like": "0",
  419. }
  420. if user != nil {
  421. count, _ := MasterDb(c).Where("uid=? and store_id=?", user.Info.Uid, v["id"]).Count(&model.CommunityTeamStoreLike{})
  422. if count > 0 {
  423. tmp["is_like"] = "1"
  424. }
  425. }
  426. storeList = append(storeList, tmp)
  427. }
  428. e.OutSuc(c, storeList, nil)
  429. return
  430. }
  431. func StoreAddLike(c *gin.Context) {
  432. var arg map[string]string
  433. if err := c.ShouldBindJSON(&arg); err != nil {
  434. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  435. return
  436. }
  437. user := GetUser(c)
  438. count, _ := MasterDb(c).Where("uid=? and store_id=?", user.Info.Uid, arg["id"]).Count(&model.CommunityTeamStoreLike{})
  439. if count > 0 {
  440. e.OutErr(c, 400, e.NewErr(400, "已收藏"))
  441. return
  442. }
  443. var data = model.CommunityTeamStoreLike{
  444. Uid: user.Info.Uid,
  445. StoreId: utils.StrToInt(arg["id"]),
  446. Time: time.Now(),
  447. }
  448. MasterDb(c).Insert(&data)
  449. store := db.GetStoreIdEg(MasterDb(c), arg["id"])
  450. store.Fan++
  451. MasterDb(c).Where("id=?", store.Id).Cols("fan").Update(store)
  452. e.OutSuc(c, "success", nil)
  453. return
  454. }
  455. func StoreCancelLike(c *gin.Context) {
  456. var arg map[string]string
  457. if err := c.ShouldBindJSON(&arg); err != nil {
  458. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  459. return
  460. }
  461. user := GetUser(c)
  462. MasterDb(c).Where("uid=? and store_id=?", user.Info.Uid, arg["id"]).Delete(&model.CommunityTeamStoreLike{})
  463. store := db.GetStoreIdEg(MasterDb(c), arg["id"])
  464. store.Fan--
  465. if store.Fan < 0 {
  466. store.Fan = 0
  467. }
  468. MasterDb(c).Where("id=?", store.Id).Cols("fan").Update(store)
  469. e.OutSuc(c, "success", nil)
  470. return
  471. }