附近小店
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

db_store.go 4.8 KiB

2 maanden geleden
2 maanden geleden
2 maanden geleden
1 maand geleden
2 maanden geleden
2 maanden geleden
2 maanden geleden
2 maanden geleden
2 maanden geleden
2 maanden geleden
2 maanden geleden
2 maanden geleden
1 maand geleden
1 maand geleden
1 maand geleden
1 maand geleden
2 maanden geleden
2 maanden geleden
1 maand geleden
2 maanden geleden
2 maanden geleden
2 maanden geleden
1 maand geleden
2 maanden geleden
1 maand geleden
2 maanden geleden
2 maanden geleden
2 maanden geleden
2 maanden geleden
2 maanden geleden
2 maanden geleden
2 maanden geleden
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. str := "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) ) )"
  20. str = fmt.Sprintf(str, lng, lat, lng, lat, lat, lat)
  21. sel := ` *,%s AS km`
  22. sel = fmt.Sprintf(sel, str)
  23. sql := `select %s from community_team_store where %s %s`
  24. where := "state=1"
  25. if arg["parent_uid"] != "" {
  26. where += " and store_type=2 and parent_uid=" + arg["parent_uid"]
  27. } else if arg["uid"] != "" {
  28. where += " and store_type=1 and uid=" + arg["uid"]
  29. } else {
  30. if arg["store_type"] == "3" {
  31. where += " and store_type in(1,2)"
  32. } else {
  33. where += " and store_type=" + arg["store_type"]
  34. }
  35. }
  36. if arg["store_id"] != "" {
  37. where += " and uid = '" + arg["store_id"] + "'"
  38. }
  39. if arg["work_state"] != "" {
  40. where += " and work_state = '" + arg["work_state"] + "'"
  41. }
  42. if arg["is_new"] != "" {
  43. where += " and is_new = '" + arg["is_new"] + "'"
  44. }
  45. if utils.StrToFloat64(arg["km"]) > 0 {
  46. where += " and " + str + "<=" + utils.Float64ToStr(utils.StrToFloat64(arg["km"])/1000)
  47. } else {
  48. if utils.StrToFloat64(arg["lat"]) > 0 && arg["city_id"] == "" {
  49. where += " and " + str + "<=1000"
  50. }
  51. }
  52. if arg["city"] != "" {
  53. where += " and city like '%" + arg["city"] + "%'"
  54. }
  55. if arg["province_id"] != "" {
  56. where += " and province_id = '" + arg["province_id"] + "'"
  57. }
  58. if arg["city_id"] != "" {
  59. where += " and city_id = '" + arg["city_id"] + "'"
  60. }
  61. if arg["district_id"] != "" {
  62. where += " and district_id = '" + arg["district_id"] + "'"
  63. }
  64. if arg["name"] != "" {
  65. where += " and name like '%" + arg["name"] + "'"
  66. }
  67. start := (utils.StrToInt(arg["p"]) - 1) * utils.StrToInt(arg["size"])
  68. group := " order by %s limit " + utils.IntToStr(start) + "," + arg["size"]
  69. groupStr := "fan desc,km asc,id asc"
  70. if arg["cid"] == "1" {
  71. groupStr = "km asc,id asc"
  72. }
  73. group = fmt.Sprintf(group, groupStr)
  74. sql = fmt.Sprintf(sql, sel, where, group)
  75. fmt.Println(sql)
  76. nativeString, _ := QueryNativeString(eg, sql)
  77. return nativeString
  78. }
  79. func GetStoreLike(eg *xorm.Engine, arg map[string]string) []map[string]string {
  80. lng := utils.StrToFloat64(arg["lng"])
  81. lat := utils.StrToFloat64(arg["lat"])
  82. str := "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) ) )"
  83. str = fmt.Sprintf(str, lng, lat, lng, lat, lat, lat)
  84. sel := ` cts.*,%s AS km`
  85. sel = fmt.Sprintf(sel, str)
  86. sql := `select %s from community_team_store_like ctsl
  87. left join community_team_store cts on ctsl.store_id=cts.id
  88. where %s %s`
  89. where := "cts.state=1"
  90. if arg["parent_uid"] != "" {
  91. where += " and cts.store_type=2 and cts.parent_uid=" + arg["parent_uid"]
  92. } else if arg["uid"] != "" {
  93. where += " and cts.store_type=1 and cts.uid=" + arg["parent_uid"]
  94. } else {
  95. if arg["store_type"] == "3" {
  96. where += " and cts.store_type in(1,2)"
  97. } else {
  98. where += " and cts.store_type=" + arg["store_type"]
  99. }
  100. }
  101. if utils.StrToFloat64(arg["km"]) > 0 {
  102. where += " and " + str + "<=" + utils.Float64ToStr(utils.StrToFloat64(arg["km"])/1000)
  103. }
  104. if arg["store_id"] != "" {
  105. where += " and cts.uid = '" + arg["store_id"] + "'"
  106. }
  107. //if arg["city"] != "" {
  108. // where += " and cts.city='" + arg["city"] + "'"
  109. //}
  110. if arg["province_id"] != "" {
  111. where += " and cts.province_id = '" + arg["province_id"] + "'"
  112. }
  113. if arg["city_id"] != "" {
  114. where += " and cts.city_id = '" + arg["city_id"] + "'"
  115. }
  116. if arg["district_id"] != "" {
  117. where += " and cts.district_id = '" + arg["district_id"] + "'"
  118. }
  119. if arg["name"] != "" {
  120. where += " and cts.name like '%" + arg["name"] + "'"
  121. }
  122. start := (utils.StrToInt(arg["p"]) - 1) * utils.StrToInt(arg["size"])
  123. group := " order by km asc,cts.id asc limit " + utils.IntToStr(start) + "," + arg["size"]
  124. sql = fmt.Sprintf(sql, sel, where, group)
  125. fmt.Println(sql)
  126. nativeString, _ := QueryNativeString(eg, sql)
  127. return nativeString
  128. }
  129. func GetStoreId(sess *xorm.Session, id string) *model.CommunityTeamStore {
  130. var data model.CommunityTeamStore
  131. get, err := sess.Where("uid=?", id).Get(&data)
  132. if get == false || err != nil {
  133. return nil
  134. }
  135. return &data
  136. }
  137. func GetStoreIdEg(eg *xorm.Engine, id string) *model.CommunityTeamStore {
  138. var data model.CommunityTeamStore
  139. get, err := eg.Where("uid=?", id).Get(&data)
  140. if get == false || err != nil {
  141. return nil
  142. }
  143. return &data
  144. }