|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- package db
-
- import (
- "applet/app/db/model"
- "applet/app/utils"
- "fmt"
- "xorm.io/xorm"
- )
-
- func GetUserStore(eg *xorm.Engine, id int) *model.CommunityTeamStore {
- var data model.CommunityTeamStore
- get, err := eg.Where("uid=?", id).Get(&data)
- if get == false || err != nil {
- return nil
- }
- return &data
- }
-
- func GetStore(eg *xorm.Engine, arg map[string]string) []map[string]string {
- lng := utils.StrToFloat64(arg["lng"])
- lat := utils.StrToFloat64(arg["lat"])
- 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) ) )"
- str = fmt.Sprintf(str, lng, lat, lng, lat, lat, lat)
- sel := ` *,%s AS km`
- sel = fmt.Sprintf(sel, str)
- sql := `select %s from community_team_store where %s %s`
- where := "state=1"
- if arg["parent_uid"] != "" {
- where += " and store_type=2 and parent_uid=" + arg["parent_uid"]
- } else if arg["uid"] != "" {
- where += " and store_type=1 and uid=" + arg["uid"]
- } else {
- if arg["store_type"] == "3" {
- where += " and store_type in(1,2)"
- } else {
- where += " and store_type=" + arg["store_type"]
- }
- }
- if arg["store_id"] != "" {
- where += " and uid = '" + arg["store_id"] + "'"
- }
- if arg["work_state"] != "" {
- where += " and work_state = '" + arg["work_state"] + "'"
- }
- if arg["is_new"] != "" {
- where += " and is_new = '" + arg["is_new"] + "'"
- }
-
- if utils.StrToFloat64(arg["km"]) > 0 {
- where += " and " + str + "<=" + utils.Float64ToStr(utils.StrToFloat64(arg["km"])/1000)
- } else {
- if utils.StrToFloat64(arg["lat"]) > 0 && arg["city_id"] == "" {
- where += " and " + str + "<=1000"
- }
- }
- if arg["city"] != "" {
- where += " and city like '%" + arg["city"] + "%'"
- }
- if arg["province_id"] != "" {
- where += " and province_id = '" + arg["province_id"] + "'"
- }
- if arg["city_id"] != "" {
- where += " and city_id = '" + arg["city_id"] + "'"
- }
- if arg["district_id"] != "" {
- where += " and district_id = '" + arg["district_id"] + "'"
- }
- if arg["name"] != "" {
- where += " and name like '%" + arg["name"] + "'"
- }
- start := (utils.StrToInt(arg["p"]) - 1) * utils.StrToInt(arg["size"])
- group := " order by %s limit " + utils.IntToStr(start) + "," + arg["size"]
- groupStr := "fan desc,km asc,id asc"
- if arg["cid"] == "1" {
- groupStr = "km asc,id asc"
- }
- group = fmt.Sprintf(group, groupStr)
- sql = fmt.Sprintf(sql, sel, where, group)
- fmt.Println(sql)
- nativeString, _ := QueryNativeString(eg, sql)
- return nativeString
- }
- func GetStoreLike(eg *xorm.Engine, arg map[string]string) []map[string]string {
- lng := utils.StrToFloat64(arg["lng"])
- lat := utils.StrToFloat64(arg["lat"])
- 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) ) )"
- str = fmt.Sprintf(str, lng, lat, lng, lat, lat, lat)
- sel := ` cts.*,%s AS km`
- sel = fmt.Sprintf(sel, str)
- sql := `select %s from community_team_store_like ctsl
- left join community_team_store cts on ctsl.store_id=cts.id
- where %s %s`
- where := "cts.state=1"
- if arg["parent_uid"] != "" {
- where += " and cts.store_type=2 and cts.parent_uid=" + arg["parent_uid"]
- } else if arg["uid"] != "" {
- where += " and cts.store_type=1 and cts.uid=" + arg["parent_uid"]
- } else {
- if arg["store_type"] == "3" {
- where += " and cts.store_type in(1,2)"
- } else {
- where += " and cts.store_type=" + arg["store_type"]
- }
- }
- if utils.StrToFloat64(arg["km"]) > 0 {
- where += " and " + str + "<=" + utils.Float64ToStr(utils.StrToFloat64(arg["km"])/1000)
- }
- if arg["store_id"] != "" {
- where += " and cts.uid = '" + arg["store_id"] + "'"
- }
- //if arg["city"] != "" {
- // where += " and cts.city='" + arg["city"] + "'"
- //}
- if arg["province_id"] != "" {
- where += " and cts.province_id = '" + arg["province_id"] + "'"
- }
- if arg["city_id"] != "" {
- where += " and cts.city_id = '" + arg["city_id"] + "'"
- }
- if arg["district_id"] != "" {
- where += " and cts.district_id = '" + arg["district_id"] + "'"
- }
- if arg["name"] != "" {
- where += " and cts.name like '%" + arg["name"] + "'"
- }
- start := (utils.StrToInt(arg["p"]) - 1) * utils.StrToInt(arg["size"])
- group := " order by km asc,cts.id asc limit " + utils.IntToStr(start) + "," + arg["size"]
- sql = fmt.Sprintf(sql, sel, where, group)
- fmt.Println(sql)
- nativeString, _ := QueryNativeString(eg, sql)
- return nativeString
- }
- func GetStoreId(sess *xorm.Session, id string) *model.CommunityTeamStore {
- var data model.CommunityTeamStore
- get, err := sess.Where("uid=?", id).Get(&data)
- if get == false || err != nil {
- return nil
- }
- return &data
- }
-
- func GetStoreIdEg(eg *xorm.Engine, id string) *model.CommunityTeamStore {
- var data model.CommunityTeamStore
- get, err := eg.Where("uid=?", id).Get(&data)
- if get == false || err != nil {
- return nil
- }
- return &data
- }
|