附近小店
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 

120 satır
3.9 KiB

  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["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["store_id"] != "" {
  35. where += " and uid = '" + arg["store_id"] + "'"
  36. }
  37. if arg["city"] != "" {
  38. where += " and city like '%" + arg["city"] + "%'"
  39. }
  40. if arg["province_id"] != "" {
  41. where += " and province_id = '" + arg["province_id"] + "'"
  42. }
  43. if arg["city_id"] != "" {
  44. where += " and city_id = '" + arg["city_id"] + "'"
  45. }
  46. if arg["district_id"] != "" {
  47. where += " and district_id = '" + arg["district_id"] + "'"
  48. }
  49. if arg["name"] != "" {
  50. where += " and name like '%" + arg["name"] + "'"
  51. }
  52. start := (utils.StrToInt(arg["p"]) - 1) * utils.StrToInt(arg["size"])
  53. group := " order by %s limit " + utils.IntToStr(start) + "," + arg["size"]
  54. groupStr := "fan desc,km asc,id asc"
  55. if arg["cid"] == "1" {
  56. groupStr = "km asc,id asc"
  57. }
  58. group = fmt.Sprintf(group, groupStr)
  59. sql = fmt.Sprintf(sql, sel, where, group)
  60. fmt.Println(sql)
  61. nativeString, _ := QueryNativeString(eg, sql)
  62. return nativeString
  63. }
  64. func GetStoreLike(eg *xorm.Engine, arg map[string]string) []map[string]string {
  65. lng := utils.StrToFloat64(arg["lng"])
  66. lat := utils.StrToFloat64(arg["lat"])
  67. 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`
  68. sel = fmt.Sprintf(sel, lng, lat, lng, lat, lat, lat)
  69. sql := `select %s from community_team_store_like ctsl
  70. left join community_team_store cts on ctsl.store_id=cts.id
  71. where %s %s`
  72. where := "cts.state=1"
  73. if arg["parent_uid"] != "" {
  74. where += " and cts.store_type=2 and cts.parent_uid=" + arg["parent_uid"]
  75. } else if arg["uid"] != "" {
  76. where += " and cts.store_type=1 and cts.uid=" + arg["parent_uid"]
  77. } else {
  78. if arg["store_type"] == "3" {
  79. where += " and cts.store_type in(1,2)"
  80. } else {
  81. where += " and cts.store_type=" + arg["store_type"]
  82. }
  83. }
  84. if arg["store_id"] != "" {
  85. where += " and cts.uid = '" + arg["store_id"] + "'"
  86. }
  87. if arg["city"] != "" {
  88. where += " and cts.city='" + arg["city"] + "'"
  89. }
  90. if arg["name"] != "" {
  91. where += " and cts.name like '%" + arg["name"] + "'"
  92. }
  93. start := (utils.StrToInt(arg["p"]) - 1) * utils.StrToInt(arg["size"])
  94. group := " order by km asc,cts.id asc limit " + utils.IntToStr(start) + "," + arg["size"]
  95. sql = fmt.Sprintf(sql, sel, where, group)
  96. fmt.Println(sql)
  97. nativeString, _ := QueryNativeString(eg, sql)
  98. return nativeString
  99. }
  100. func GetStoreId(sess *xorm.Session, id string) *model.CommunityTeamStore {
  101. var data model.CommunityTeamStore
  102. get, err := sess.Where("uid=?", id).Get(&data)
  103. if get == false || err != nil {
  104. return nil
  105. }
  106. return &data
  107. }
  108. func GetStoreIdEg(eg *xorm.Engine, id string) *model.CommunityTeamStore {
  109. var data model.CommunityTeamStore
  110. get, err := eg.Where("uid=?", id).Get(&data)
  111. if get == false || err != nil {
  112. return nil
  113. }
  114. return &data
  115. }