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

87 行
3.1 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 city='" + arg["city"] + "'"
  24. }
  25. if arg["name"] != "" {
  26. where += " and name like '%" + arg["name"] + "'"
  27. }
  28. start := (utils.StrToInt(arg["p"]) - 1) * utils.StrToInt(arg["size"])
  29. group := " order by %s limit " + utils.IntToStr(start) + "," + arg["size"]
  30. groupStr := "fan desc,km asc,id asc"
  31. if arg["cid"] == "1" {
  32. groupStr = "km asc,id asc"
  33. }
  34. group = fmt.Sprintf(group, groupStr)
  35. sql = fmt.Sprintf(sql, sel, where, group)
  36. fmt.Println(sql)
  37. nativeString, _ := QueryNativeString(eg, sql)
  38. return nativeString
  39. }
  40. func GetStoreLike(eg *xorm.Engine, arg map[string]string) []map[string]string {
  41. lng := utils.StrToFloat64(arg["lng"])
  42. lat := utils.StrToFloat64(arg["lat"])
  43. 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`
  44. sel = fmt.Sprintf(sel, lng, lat, lng, lat, lat, lat)
  45. sql := `select %s from community_team_store_like ctsl
  46. left join community_team_store cts on ctsl.store_id=cts.id
  47. where %s %s`
  48. where := "cts.state=1"
  49. if arg["parent_uid"] != "" {
  50. where += " and cts.store_type=2 and cts.parent_uid=" + arg["parent_uid"]
  51. } else if arg["uid"] != "" {
  52. where += " and cts.store_type=1 and cts.uid=" + arg["parent_uid"]
  53. } else {
  54. where += " and cts.store_type=" + arg["store_type"]
  55. }
  56. if arg["city"] != "" {
  57. where += " and cts.city='" + arg["city"] + "'"
  58. }
  59. if arg["name"] != "" {
  60. where += " and cts.name like '%" + arg["name"] + "'"
  61. }
  62. start := (utils.StrToInt(arg["p"]) - 1) * utils.StrToInt(arg["size"])
  63. group := " order by km asc,cts.id asc limit " + utils.IntToStr(start) + "," + arg["size"]
  64. sql = fmt.Sprintf(sql, sel, where, group)
  65. fmt.Println(sql)
  66. nativeString, _ := QueryNativeString(eg, sql)
  67. return nativeString
  68. }
  69. func GetStoreId(sess *xorm.Session, id string) *model.CommunityTeamStore {
  70. var data model.CommunityTeamStore
  71. get, err := sess.Where("id=?", id).Get(&data)
  72. if get == false || err != nil {
  73. return nil
  74. }
  75. return &data
  76. }
  77. func GetStoreIdEg(eg *xorm.Engine, id string) *model.CommunityTeamStore {
  78. var data model.CommunityTeamStore
  79. get, err := eg.Where("id=?", id).Get(&data)
  80. if get == false || err != nil {
  81. return nil
  82. }
  83. return &data
  84. }