|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254 |
- package svc
-
- import (
- "applet/app/db"
- "applet/app/db/model"
- "applet/app/e"
- "applet/app/utils"
- "github.com/gin-gonic/gin"
- "time"
- )
-
- func BankStore(c *gin.Context) {
- var arg map[string]string
- if err := c.ShouldBindJSON(&arg); err != nil {
- e.OutErr(c, e.ERR_INVALID_ARGS, err)
- return
- }
- arg["store_type"] = "0"
- user, _ := GetDefaultUser(c, c.GetHeader("Authorization"))
- var store = make([]map[string]string, 0)
- if arg["cid"] == "2" {
- store = db.GetStoreLike(MasterDb(c), arg)
- } else {
- store = db.GetStore(MasterDb(c), arg)
- }
- storeList := make([]map[string]interface{}, 0)
- for _, v := range store {
- km := v["km"]
- if utils.StrToFloat64(v["km"]) < 1 {
- v["km"] = utils.IntToStr(int(utils.StrToFloat64(v["km"])*1000)) + "m"
- } else {
- v["km"] = GetCommissionPrec(c, v["km"], "2", "1")
- v["km"] += "km"
- }
- if utils.StrToFloat64(km) <= 0 || utils.StrToFloat64(v["lat"]) == 0 || utils.StrToFloat64(v["lng"]) == 0 {
- v["km"] = "-"
- }
- tmp := map[string]interface{}{
- "lat": v["lat"],
- "lng": v["lng"],
- "address": v["address"],
- "name": v["name"],
- "id": v["id"],
- "km": v["km"],
- "time_str": v["timer"],
- "uid": v["uid"],
- "phone": v["phone"],
- "logo": v["logo"],
- "is_like": "0",
- "fan": "",
- }
- if user != nil {
- count, _ := MasterDb(c).Where("uid=? and store_id=?", user.Info.Uid, v["id"]).Count(&model.CommunityTeamStoreLike{})
- if count > 0 {
- tmp["is_like"] = "1"
- }
- }
- storeList = append(storeList, tmp)
- }
- e.OutSuc(c, storeList, nil)
- return
- }
- func NewStore(c *gin.Context) {
- var arg map[string]string
- if err := c.ShouldBindJSON(&arg); err != nil {
- e.OutErr(c, e.ERR_INVALID_ARGS, err)
- return
- }
- arg["store_type"] = "3"
- user, _ := GetDefaultUser(c, c.GetHeader("Authorization"))
- var store = make([]map[string]string, 0)
- if arg["cid"] == "2" {
- store = db.GetStoreLike(MasterDb(c), arg)
- } else {
- store = db.GetStore(MasterDb(c), arg)
- }
- storeList := make([]map[string]interface{}, 0)
- for _, v := range store {
- km := v["km"]
- if utils.StrToFloat64(v["km"]) < 1 {
- v["km"] = utils.IntToStr(int(utils.StrToFloat64(v["km"])*1000)) + "m"
- } else {
- v["km"] = GetCommissionPrec(c, v["km"], "2", "1")
- v["km"] += "km"
- }
- if utils.StrToFloat64(km) <= 0 || utils.StrToFloat64(v["lat"]) == 0 || utils.StrToFloat64(v["lng"]) == 0 {
- v["km"] = "-"
- }
- tmp := map[string]interface{}{
- "lat": v["lat"],
- "lng": v["lng"],
- "address": v["address"],
- "name": v["name"],
- "id": v["id"],
- "km": v["km"],
- "time_str": v["timer"],
- "uid": v["uid"],
- "store_id": v["uid"],
- "store_type": v["store_type"],
- "phone": v["phone"],
- "logo": v["logo"],
- "is_like": "0",
- "fan": "",
- }
- if user != nil {
- count, _ := MasterDb(c).Where("uid=? and store_id=?", user.Info.Uid, v["id"]).Count(&model.CommunityTeamStoreLike{})
- if count > 0 {
- tmp["is_like"] = "1"
- }
- }
- storeList = append(storeList, tmp)
- }
- e.OutSuc(c, storeList, nil)
- return
- }
- func StoreLike(c *gin.Context) {
- var arg map[string]string
- if err := c.ShouldBindJSON(&arg); err != nil {
- e.OutErr(c, e.ERR_INVALID_ARGS, err)
- return
- }
- arg["store_type"] = "0"
- storeId := c.GetHeader("store_id")
- if utils.StrToInt(storeId) > 0 {
- arg["store_id"] = storeId
- arg["store_type"] = "1"
- }
- user, _ := GetDefaultUser(c, c.GetHeader("Authorization"))
- store := db.GetStoreLike(MasterDb(c), arg)
- storeList := make([]map[string]interface{}, 0)
- for _, v := range store {
- km := v["km"]
- if utils.StrToFloat64(v["km"]) < 1 {
- v["km"] = utils.IntToStr(int(utils.StrToFloat64(v["km"])*1000)) + "m"
- } else {
- v["km"] = GetCommissionPrec(c, v["km"], "2", "1")
- v["km"] += "km"
- }
- if utils.StrToFloat64(km) <= 0 || utils.StrToFloat64(v["lat"]) == 0 || utils.StrToFloat64(v["lng"]) == 0 {
- v["km"] = "-"
- }
- label := make([]string, 0)
- tmp := map[string]interface{}{
- "lat": v["lat"],
- "lng": v["lng"],
- "address": v["address"],
- "work_state": v["work_state"],
- "name": v["name"],
- "id": v["id"],
- "uid": v["uid"],
- "km": v["km"],
- "time_str": v["timer"],
- "phone": v["phone"],
- "label": label,
- "is_like": "0",
- }
- if user != nil {
- count, _ := MasterDb(c).Where("uid=? and store_id=?", user.Info.Uid, v["id"]).Count(&model.CommunityTeamStoreLike{})
- if count > 0 {
- tmp["is_like"] = "1"
- }
- }
-
- storeList = append(storeList, tmp)
- }
- e.OutSuc(c, storeList, nil)
- return
- }
- func Store(c *gin.Context) {
- var arg map[string]string
- if err := c.ShouldBindJSON(&arg); err != nil {
- e.OutErr(c, e.ERR_INVALID_ARGS, err)
- return
- }
- arg["store_type"] = "0"
- storeId := c.GetHeader("store_id")
- if utils.StrToInt(storeId) > 0 {
- arg["store_id"] = storeId
- arg["store_type"] = "1"
- }
- user, _ := GetDefaultUser(c, c.GetHeader("Authorization"))
- store := db.GetStore(MasterDb(c), arg)
- storeList := make([]map[string]interface{}, 0)
- for _, v := range store {
- km := v["km"]
- if utils.StrToFloat64(v["km"]) < 1 {
- v["km"] = utils.IntToStr(int(utils.StrToFloat64(v["km"])*1000)) + "m"
- } else {
- v["km"] = GetCommissionPrec(c, v["km"], "2", "1")
- v["km"] += "km"
- }
- if utils.StrToFloat64(km) <= 0 || utils.StrToFloat64(v["lat"]) == 0 || utils.StrToFloat64(v["lng"]) == 0 {
- v["km"] = "-"
- }
- label := make([]string, 0)
- tmp := map[string]interface{}{
- "lat": v["lat"],
- "lng": v["lng"],
- "address": v["address"],
- "work_state": v["work_state"],
- "name": v["name"],
- "id": v["id"],
- "uid": v["uid"],
- "km": v["km"],
- "time_str": v["timer"],
- "phone": v["phone"],
- "label": label,
- "is_like": "0",
- }
- if user != nil {
- count, _ := MasterDb(c).Where("uid=? and store_id=?", user.Info.Uid, v["id"]).Count(&model.CommunityTeamStoreLike{})
- if count > 0 {
- tmp["is_like"] = "1"
- }
- }
-
- storeList = append(storeList, tmp)
- }
- e.OutSuc(c, storeList, nil)
- return
- }
- func StoreAddLike(c *gin.Context) {
- var arg map[string]string
- if err := c.ShouldBindJSON(&arg); err != nil {
- e.OutErr(c, e.ERR_INVALID_ARGS, err)
- return
- }
- user := GetUser(c)
- count, _ := MasterDb(c).Where("uid=? and store_id=?", user.Info.Uid, arg["id"]).Count(&model.CommunityTeamStoreLike{})
- if count > 0 {
- e.OutErr(c, 400, e.NewErr(400, "已收藏"))
- return
- }
- var data = model.CommunityTeamStoreLike{
- Uid: user.Info.Uid,
- StoreId: utils.StrToInt(arg["id"]),
- Time: time.Now(),
- }
- MasterDb(c).Insert(&data)
- e.OutSuc(c, "success", nil)
- return
- }
-
- func StoreCancelLike(c *gin.Context) {
- var arg map[string]string
- if err := c.ShouldBindJSON(&arg); err != nil {
- e.OutErr(c, e.ERR_INVALID_ARGS, err)
- return
- }
- user := GetUser(c)
- MasterDb(c).Where("uid=? and store_id=?", user.Info.Uid, arg["id"]).Delete(&model.CommunityTeamStoreLike{})
- e.OutSuc(c, "success", nil)
- return
- }
|