附近小店
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

db_store.go 3.7 KiB

10 个月前
10 个月前
10 个月前
10 个月前
10 个月前
10 个月前
10 个月前
10 个月前
10 个月前
10 个月前
10 个月前
10 个月前
10 个月前
10 个月前
10 个月前
10 个月前
10 个月前
10 个月前
10 个月前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. package db
  2. import (
  3. "applet/app/db/model"
  4. "applet/app/utils"
  5. "fmt"
  6. "xorm.io/xorm"
  7. )
  8. func GetUserStore(eg *xorm.Engine, id int) *model.CommunityTeamStore {
  9. var data model.CommunityTeamStore
  10. get, err := eg.Where("uid=?", id).Get(&data)
  11. if get == false || err != nil {
  12. return nil
  13. }
  14. return &data
  15. }
  16. func GetStore(eg *xorm.Engine, arg map[string]string) []map[string]string {
  17. lng := utils.StrToFloat64(arg["lng"])
  18. lat := utils.StrToFloat64(arg["lat"])
  19. sel := ` *,sqrt( ( (( %f - lng)*PI()*12656*cos((( %f +lat)/2)*PI()/180)/180) * (( %f - lng)*PI()*12656*cos (((%f+lat)/2)*PI()/180)/180) ) + ( ((%f-lat)*PI()*12656/180) * ((%f-lat)*PI()*12656/180) ) ) AS km`
  20. sel = fmt.Sprintf(sel, lng, lat, lng, lat, lat, lat)
  21. sql := `select %s from community_team_store where %s %s`
  22. where := "state=1"
  23. if arg["parent_uid"] != "" {
  24. where += " and store_type=2 and parent_uid=" + arg["parent_uid"]
  25. } else if arg["uid"] != "" {
  26. where += " and store_type=1 and uid=" + arg["parent_uid"]
  27. } else {
  28. if arg["store_type"] == "3" {
  29. where += " and store_type in(1,2)"
  30. } else {
  31. where += " and store_type=" + arg["store_type"]
  32. }
  33. }
  34. if arg["city"] != "" {
  35. where += " and city like '%" + arg["city"] + "%'"
  36. }
  37. if arg["province_id"] != "" {
  38. where += " and province_id = '" + arg["province_id"] + "'"
  39. }
  40. if arg["city_id"] != "" {
  41. where += " and city_id = '" + arg["city_id"] + "'"
  42. }
  43. if arg["district_id"] != "" {
  44. where += " and district_id = '" + arg["district_id"] + "'"
  45. }
  46. if arg["name"] != "" {
  47. where += " and name like '%" + arg["name"] + "'"
  48. }
  49. start := (utils.StrToInt(arg["p"]) - 1) * utils.StrToInt(arg["size"])
  50. group := " order by %s limit " + utils.IntToStr(start) + "," + arg["size"]
  51. groupStr := "fan desc,km asc,id asc"
  52. if arg["cid"] == "1" {
  53. groupStr = "km asc,id asc"
  54. }
  55. group = fmt.Sprintf(group, groupStr)
  56. sql = fmt.Sprintf(sql, sel, where, group)
  57. fmt.Println(sql)
  58. nativeString, _ := QueryNativeString(eg, sql)
  59. return nativeString
  60. }
  61. func GetStoreLike(eg *xorm.Engine, arg map[string]string) []map[string]string {
  62. lng := utils.StrToFloat64(arg["lng"])
  63. lat := utils.StrToFloat64(arg["lat"])
  64. sel := ` cts.*,sqrt( ( (( %f - cts.lng)*PI()*12656*cos((( %f +cts.lat)/2)*PI()/180)/180) * (( %f - cts.lng)*PI()*12656*cos (((%f+cts.lat)/2)*PI()/180)/180) ) + ( ((%f-cts.lat)*PI()*12656/180) * ((%f-cts.lat)*PI()*12656/180) ) ) AS km`
  65. sel = fmt.Sprintf(sel, lng, lat, lng, lat, lat, lat)
  66. sql := `select %s from community_team_store_like ctsl
  67. left join community_team_store cts on ctsl.store_id=cts.id
  68. where %s %s`
  69. where := "cts.state=1"
  70. if arg["parent_uid"] != "" {
  71. where += " and cts.store_type=2 and cts.parent_uid=" + arg["parent_uid"]
  72. } else if arg["uid"] != "" {
  73. where += " and cts.store_type=1 and cts.uid=" + arg["parent_uid"]
  74. } else {
  75. if arg["store_type"] == "3" {
  76. where += " and cts.store_type in(1,2)"
  77. } else {
  78. where += " and cts.store_type=" + arg["store_type"]
  79. }
  80. }
  81. if arg["city"] != "" {
  82. where += " and cts.city='" + arg["city"] + "'"
  83. }
  84. if arg["name"] != "" {
  85. where += " and cts.name like '%" + arg["name"] + "'"
  86. }
  87. start := (utils.StrToInt(arg["p"]) - 1) * utils.StrToInt(arg["size"])
  88. group := " order by km asc,cts.id asc limit " + utils.IntToStr(start) + "," + arg["size"]
  89. sql = fmt.Sprintf(sql, sel, where, group)
  90. fmt.Println(sql)
  91. nativeString, _ := QueryNativeString(eg, sql)
  92. return nativeString
  93. }
  94. func GetStoreId(sess *xorm.Session, id string) *model.CommunityTeamStore {
  95. var data model.CommunityTeamStore
  96. get, err := sess.Where("uid=?", id).Get(&data)
  97. if get == false || err != nil {
  98. return nil
  99. }
  100. return &data
  101. }
  102. func GetStoreIdEg(eg *xorm.Engine, id string) *model.CommunityTeamStore {
  103. var data model.CommunityTeamStore
  104. get, err := eg.Where("uid=?", id).Get(&data)
  105. if get == false || err != nil {
  106. return nil
  107. }
  108. return &data
  109. }