附近小店
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 

538 wiersze
14 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 BankCardDetail(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. detail := db.GetCardDetail(MasterDb(c), arg)
  273. if detail == nil {
  274. e.OutErr(c, 400, e.NewErr(400, "记录不存在"))
  275. return
  276. }
  277. tmp := map[string]string{
  278. "id": utils.IntToStr(detail.Id),
  279. "title": detail.Title,
  280. "first_tip": detail.FirstTip,
  281. "second_tip": detail.SecondTip,
  282. "time_str": "",
  283. "content": detail.Content,
  284. "type": "0",
  285. }
  286. if tmp["time_str"] != "" {
  287. tmp["type"] = "1"
  288. }
  289. if detail.IsUse == 0 {
  290. tmp["type"] = "2"
  291. }
  292. e.OutSuc(c, tmp, nil)
  293. return
  294. }
  295. func BankCard(c *gin.Context) {
  296. var arg map[string]string
  297. if err := c.ShouldBindJSON(&arg); err != nil {
  298. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  299. return
  300. }
  301. list := make([]map[string]string, 0)
  302. data := db.GetCard(MasterDb(c), arg)
  303. if data != nil {
  304. for _, v := range *data {
  305. tmp := map[string]string{
  306. "id": utils.IntToStr(v.Id),
  307. "title": v.Title,
  308. "first_tip": v.FirstTip,
  309. "second_tip": v.SecondTip,
  310. "time_str": "",
  311. "type": "0",
  312. }
  313. if tmp["time_str"] != "" {
  314. tmp["type"] = "1"
  315. }
  316. if v.IsUse == 0 {
  317. tmp["type"] = "2"
  318. }
  319. list = append(list, tmp)
  320. }
  321. }
  322. e.OutSuc(c, list, nil)
  323. return
  324. }
  325. func NewStore(c *gin.Context) {
  326. var arg map[string]string
  327. if err := c.ShouldBindJSON(&arg); err != nil {
  328. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  329. return
  330. }
  331. arg["store_type"] = "3"
  332. user, _ := GetDefaultUser(c, c.GetHeader("Authorization"))
  333. var store = make([]map[string]string, 0)
  334. if arg["cid"] == "2" {
  335. store = db.GetStoreLike(MasterDb(c), arg)
  336. } else {
  337. store = db.GetStore(MasterDb(c), arg)
  338. }
  339. storeList := make([]map[string]interface{}, 0)
  340. for _, v := range store {
  341. km := v["km"]
  342. if utils.StrToFloat64(v["km"]) < 1 {
  343. v["km"] = utils.IntToStr(int(utils.StrToFloat64(v["km"])*1000)) + "m"
  344. } else {
  345. v["km"] = GetCommissionPrec(c, v["km"], "2", "1")
  346. v["km"] += "km"
  347. }
  348. if utils.StrToFloat64(km) <= 0 || utils.StrToFloat64(v["lat"]) == 0 || utils.StrToFloat64(v["lng"]) == 0 {
  349. v["km"] = "-"
  350. }
  351. tmp := map[string]interface{}{
  352. "lat": v["lat"],
  353. "lng": v["lng"],
  354. "address": v["address"],
  355. "name": v["name"],
  356. "id": v["id"],
  357. "km": v["km"],
  358. "time_str": v["timer"],
  359. "uid": v["uid"],
  360. "store_id": v["uid"],
  361. "store_type": v["store_type"],
  362. "phone": v["phone"],
  363. "logo": v["logo"],
  364. "is_like": "0",
  365. "fan": "",
  366. }
  367. if user != nil {
  368. count, _ := MasterDb(c).Where("uid=? and store_id=?", user.Info.Uid, v["id"]).Count(&model.CommunityTeamStoreLike{})
  369. if count > 0 {
  370. tmp["is_like"] = "1"
  371. }
  372. }
  373. storeList = append(storeList, tmp)
  374. }
  375. e.OutSuc(c, storeList, nil)
  376. return
  377. }
  378. func StoreLike(c *gin.Context) {
  379. var arg map[string]string
  380. if err := c.ShouldBindJSON(&arg); err != nil {
  381. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  382. return
  383. }
  384. arg["store_type"] = "0"
  385. storeId := c.GetHeader("store_id")
  386. if utils.StrToInt(storeId) > 0 {
  387. arg["store_id"] = storeId
  388. storeData := db.GetStoreIdEg(MasterDb(c), storeId)
  389. if storeData.StoreType == 0 {
  390. arg["store_id"] = "0"
  391. }
  392. arg["store_type"] = utils.IntToStr(storeData.StoreType)
  393. }
  394. user, _ := GetDefaultUser(c, c.GetHeader("Authorization"))
  395. store := db.GetStoreLike(MasterDb(c), arg)
  396. storeList := make([]map[string]interface{}, 0)
  397. for _, v := range store {
  398. km := v["km"]
  399. if utils.StrToFloat64(v["km"]) < 1 {
  400. v["km"] = utils.IntToStr(int(utils.StrToFloat64(v["km"])*1000)) + "m"
  401. } else {
  402. v["km"] = GetCommissionPrec(c, v["km"], "2", "1")
  403. v["km"] += "km"
  404. }
  405. if utils.StrToFloat64(km) <= 0 || utils.StrToFloat64(v["lat"]) == 0 || utils.StrToFloat64(v["lng"]) == 0 {
  406. v["km"] = "-"
  407. }
  408. label := make([]string, 0)
  409. tmp := map[string]interface{}{
  410. "lat": v["lat"],
  411. "lng": v["lng"],
  412. "address": v["address"],
  413. "work_state": v["work_state"],
  414. "name": v["name"],
  415. "id": v["id"],
  416. "uid": v["uid"],
  417. "km": v["km"],
  418. "time_str": v["timer"],
  419. "phone": v["phone"],
  420. "label": label,
  421. "is_like": "0",
  422. }
  423. if user != nil {
  424. count, _ := MasterDb(c).Where("uid=? and store_id=?", user.Info.Uid, v["id"]).Count(&model.CommunityTeamStoreLike{})
  425. if count > 0 {
  426. tmp["is_like"] = "1"
  427. }
  428. }
  429. storeList = append(storeList, tmp)
  430. }
  431. e.OutSuc(c, storeList, nil)
  432. return
  433. }
  434. func Store(c *gin.Context) {
  435. var arg map[string]string
  436. if err := c.ShouldBindJSON(&arg); err != nil {
  437. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  438. return
  439. }
  440. arg["store_type"] = "0"
  441. storeId := c.GetHeader("store_id")
  442. if utils.StrToInt(storeId) > 0 {
  443. arg["store_id"] = storeId
  444. storeData := db.GetStoreIdEg(MasterDb(c), storeId)
  445. if storeData.StoreType == 0 {
  446. arg["store_id"] = "0"
  447. }
  448. arg["store_type"] = utils.IntToStr(storeData.StoreType)
  449. }
  450. user, _ := GetDefaultUser(c, c.GetHeader("Authorization"))
  451. store := db.GetStore(MasterDb(c), arg)
  452. storeList := make([]map[string]interface{}, 0)
  453. for _, v := range store {
  454. km := v["km"]
  455. if utils.StrToFloat64(v["km"]) < 1 {
  456. v["km"] = utils.IntToStr(int(utils.StrToFloat64(v["km"])*1000)) + "m"
  457. } else {
  458. v["km"] = GetCommissionPrec(c, v["km"], "2", "1")
  459. v["km"] += "km"
  460. }
  461. if utils.StrToFloat64(km) <= 0 || utils.StrToFloat64(v["lat"]) == 0 || utils.StrToFloat64(v["lng"]) == 0 {
  462. v["km"] = "-"
  463. }
  464. label := make([]string, 0)
  465. tmp := map[string]interface{}{
  466. "lat": v["lat"],
  467. "lng": v["lng"],
  468. "address": v["address"],
  469. "work_state": v["work_state"],
  470. "name": v["name"],
  471. "id": v["id"],
  472. "uid": v["uid"],
  473. "km": v["km"],
  474. "time_str": v["timer"],
  475. "phone": v["phone"],
  476. "label": label,
  477. "is_like": "0",
  478. }
  479. if user != nil {
  480. count, _ := MasterDb(c).Where("uid=? and store_id=?", user.Info.Uid, v["id"]).Count(&model.CommunityTeamStoreLike{})
  481. if count > 0 {
  482. tmp["is_like"] = "1"
  483. }
  484. }
  485. storeList = append(storeList, tmp)
  486. }
  487. e.OutSuc(c, storeList, nil)
  488. return
  489. }
  490. func StoreAddLike(c *gin.Context) {
  491. var arg map[string]string
  492. if err := c.ShouldBindJSON(&arg); err != nil {
  493. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  494. return
  495. }
  496. user := GetUser(c)
  497. count, _ := MasterDb(c).Where("uid=? and store_id=?", user.Info.Uid, arg["id"]).Count(&model.CommunityTeamStoreLike{})
  498. if count > 0 {
  499. e.OutErr(c, 400, e.NewErr(400, "已收藏"))
  500. return
  501. }
  502. var data = model.CommunityTeamStoreLike{
  503. Uid: user.Info.Uid,
  504. StoreId: utils.StrToInt(arg["id"]),
  505. Time: time.Now(),
  506. }
  507. MasterDb(c).Insert(&data)
  508. store := db.GetStoreIdEg(MasterDb(c), arg["id"])
  509. store.Fan++
  510. MasterDb(c).Where("id=?", store.Id).Cols("fan").Update(store)
  511. e.OutSuc(c, "success", nil)
  512. return
  513. }
  514. func StoreCancelLike(c *gin.Context) {
  515. var arg map[string]string
  516. if err := c.ShouldBindJSON(&arg); err != nil {
  517. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  518. return
  519. }
  520. user := GetUser(c)
  521. MasterDb(c).Where("uid=? and store_id=?", user.Info.Uid, arg["id"]).Delete(&model.CommunityTeamStoreLike{})
  522. store := db.GetStoreIdEg(MasterDb(c), arg["id"])
  523. store.Fan--
  524. if store.Fan < 0 {
  525. store.Fan = 0
  526. }
  527. MasterDb(c).Where("id=?", store.Id).Cols("fan").Update(store)
  528. e.OutSuc(c, "success", nil)
  529. return
  530. }