附近小店
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

svc_store.go 14 KiB

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