附近小店
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 

97 líneas
3.4 KiB

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