From da5bf47446eb9597fa6cb7d88abcffd549053521 Mon Sep 17 00:00:00 2001 From: aarongao Date: Fri, 7 Feb 2020 16:37:05 +0800 Subject: [PATCH] .. --- API/Complaint.go | 51 +++++++++++++++++++++++++++++++++++++++++++++------ API/Investigation.go | 43 ++++++++++++++++++++++++++++++++++++++++++- API/Item.go | 47 +++++++++++++++++++++++++---------------------- DB/db.go | 34 +++++++++++++++++++--------------- README.md | 53 ++++++++++++++++++++++++++++++++++++++++++++++------- main.go | 2 ++ 6 files changed, 179 insertions(+), 51 deletions(-) diff --git a/API/Complaint.go b/API/Complaint.go index 965f7fd..5f45e2b 100644 --- a/API/Complaint.go +++ b/API/Complaint.go @@ -4,12 +4,15 @@ import ( "encoding/json" "github.com/aarongao/tools" "github.com/gin-gonic/gin" + "gopkg.in/mgo.v2/bson" "letu/DB" + "math" "regexp" + "strconv" ) // @Title 增加投诉 -// @Description 增加投诉 +// @Description 投诉 - 增加投诉 // @Accept json // @Produce json // @Param Mobile 18616619599 string true "联系电话" @@ -60,11 +63,6 @@ func CreateComplaint(c *gin.Context) { } - - - - - var images []string json.Unmarshal([]byte(c.PostForm("Image")), &images) @@ -86,3 +84,44 @@ func CreateComplaint(c *gin.Context) { } + + + + + +// @Title 查询所有投诉 +// @Description 投诉 - 查询所有投诉 +// @Accept json +// @Produce json +// @Param Page 1 int true "当前第几页" +// @Success 200 {object} tools.ResponseSeccess "" +// @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}" +// @Router /AllComplaint? [get] +func AllComplaint(c *gin.Context) { + c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin")) + c.Header("Access-Control-Allow-Credentials", "true") + + total,_ := DB.CComplaint.Find(bson.M{}).Count() + limit,_ := strconv.Atoi(c.Query("Limit")) + if limit == 0 { + limit = 50 + } + currPage, _ := strconv.Atoi(c.Query("Page")) + if currPage == 0 { + currPage = 1 + } + skip := (currPage - 1) * limit + + var aComplaint = []DB.SComplaint{} + DB.CComplaint.Find(bson.M{}).Limit(limit).Skip(int(skip)).Sort("-_id").All(&aComplaint) + + c.JSON(200, tools.Page{ + 0, + total, + currPage, + int(math.Ceil(float64(total) / float64(limit))), + limit, + aComplaint, + }) + +} \ No newline at end of file diff --git a/API/Investigation.go b/API/Investigation.go index 44240d4..48aea9e 100644 --- a/API/Investigation.go +++ b/API/Investigation.go @@ -4,11 +4,14 @@ import ( "encoding/json" "github.com/aarongao/tools" "github.com/gin-gonic/gin" + "gopkg.in/mgo.v2/bson" "letu/DB" + "math" + "strconv" ) // @Title 增加调查 -// @Description 增加调查 +// @Description 问券调查 - 增加调查 // @Accept json // @Produce json // @Param UserId 1111111 string true "UserId" @@ -36,3 +39,41 @@ func SaveInvestigation(c *gin.Context) { }) } + +// @Title 查询所有问券调查 +// @Description 问券调查 - 查询所有问券调查 +// @Accept json +// @Produce json +// @Param Page 1 int true "当前第几页" +// @Success 200 {object} tools.ResponseSeccess "{"errcode":0,"total":1,"currpage":1,"totalpages":1,"prepage":20,"result":}" +// @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}" +// @Router /Investigation/List? [get] +func AllInvestigation(c *gin.Context) { + c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin")) + c.Header("Access-Control-Allow-Credentials", "true") + + + total,_ := DB.CComplaint.Find(bson.M{}).Count() + limit,_ := strconv.Atoi(c.Query("Limit")) + if limit == 0 { + limit = 50 + } + currPage, _ := strconv.Atoi(c.Query("Page")) + if currPage == 0 { + currPage = 1 + } + skip := (currPage - 1) * limit + + var aInvestigation []DB.SInvestigation + DB.CInvestigation.Find(bson.M{}).Limit(limit).Skip(int(skip)).Sort("-_id").All(&aInvestigation) + + c.JSON(200, tools.Page{ + 0, + total, + currPage, + int(math.Ceil(float64(total) / float64(limit))), + limit, + aInvestigation, + }) + +} diff --git a/API/Item.go b/API/Item.go index 9f8a42f..433f4a4 100644 --- a/API/Item.go +++ b/API/Item.go @@ -6,6 +6,7 @@ import ( "github.com/gin-gonic/gin" "gopkg.in/mgo.v2/bson" "letu/DB" + "strconv" "time" ) @@ -14,7 +15,7 @@ import ( // @Accept json // @Produce json // @Param id 5dfb03070a9ac17ac7a82054 string true "设备id" -// @Success 200 {object} tools.ResponseSeccess "{"errcode":0,"result":{"Name":"名称","Describe":"介绍","OpenHours":"开放时间","Mobile":"电话","Address":"地址","SLocation":{"Latitude":0,"Longitude":0},"Picture":["照片1","照片2"]}}" +// @Success 200 {object} tools.ResponseSeccess "Tags所属标签,标签有分类;LimitHeight限高;PlayDuration游玩时长;SceneTime场次时间;Picture照片;Voice音频;AverageConsumption平均消费;Menu菜单, OpenHours开放时间: LocationDescription位置描述; Reminder温馨提示; State运行状态0=正常1=停运" // @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}" // @Router /ItemInfo? [get] func ItemInfo(c *gin.Context) { @@ -43,14 +44,14 @@ func ItemInfo(c *gin.Context) { // @Description 设备管理 - 查询所有游玩项目 // @Accept json // @Produce json -// @Success 200 {object} tools.ResponseSeccess "Tags所属标签,标签有分类;LimitHeight限高;PlayDuration游玩时长;SceneTime场次时间;Picture照片;Voice音频;AverageConsumption平均消费;Menu菜单" +// @Success 200 {object} tools.ResponseSeccess "Tags所属标签,标签有分类;LimitHeight限高;PlayDuration游玩时长;SceneTime场次时间;Picture照片;Voice音频;AverageConsumption平均消费;Menu菜单, OpenHours开放时间: LocationDescription位置描述; Reminder温馨提示; State运行状态0=正常1=停运" // @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}" // @Router /AllItems? [get] func AllItems(c *gin.Context) { c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin")) c.Header("Access-Control-Allow-Credentials", "true") - var aItems []DB.SItem + var aItems = []DB.SItem{} DB.CItem.Find(bson.M{}).All(&aItems) c.JSON(200, aItems) @@ -61,7 +62,7 @@ func AllItems(c *gin.Context) { // @Description 设备管理 - 更新设施 // @Accept json // @Produce json -// @Success 200 {object} tools.ResponseSeccess "Tags所属标签,标签有分类;LimitHeight限高;PlayDuration游玩时长;SceneTime场次时间;Picture照片;Voice音频;AverageConsumption平均消费;Menu菜单" +// @Success 200 {object} tools.ResponseSeccess "Tags所属标签,标签有分类;LimitHeight限高;PlayDuration游玩时长;SceneTime场次时间;Picture照片;Voice音频;AverageConsumption平均消费;Menu菜单, OpenHours开放时间: LocationDescription位置描述; Reminder温馨提示; State运行状态0=正常1=停运" // @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}" // @Router /UpdateItem? [post] func UpdateItem(c *gin.Context) { @@ -84,22 +85,27 @@ func UpdateItem(c *gin.Context) { id = bson.ObjectIdHex(pid) } + poststate, _ := strconv.Atoi(c.PostForm("State")) DB.CItem.UpsertId( id, bson.M{"$set": bson.M{ - "Name": c.PostForm("Name"), - "SubName": c.PostForm("SubName"), - "Location": Location, - "Icon": c.PostForm("Icon"), - "LimitHeight": c.PostForm("LimitHeight"), - "PlayDuration": c.PostForm("PlayDuration"), - "SceneTime": c.PostForm("SceneTime"), - "Picture": Picture, - "Voice": c.PostForm("Voice"), - "Tel": c.PostForm("Tel"), - "AverageConsumption": c.PostForm("AverageConsumption"), - "Menu": c.PostForm("Menu"), - "Tags": Tags, + "Name": c.PostForm("Name"), + "SubName": c.PostForm("SubName"), + "Location": Location, + "Icon": c.PostForm("Icon"), + "LimitHeight": c.PostForm("LimitHeight"), + "PlayDuration": c.PostForm("PlayDuration"), + "SceneTime": c.PostForm("SceneTime"), + "Picture": Picture, + "Voice": c.PostForm("Voice"), + "Tel": c.PostForm("Tel"), + "AverageConsumption": c.PostForm("AverageConsumption"), + "Menu": c.PostForm("Menu"), + "Tags": Tags, + "OpenHours": c.PostForm("OpenHours"), + "LocationDescription": c.PostForm("LocationDescription"), + "Reminder": c.PostForm("Reminder"), + "State": poststate, }}, ) @@ -135,7 +141,6 @@ func UpdateItemTime(c *gin.Context) { RedisData[v.Id] = v.Time } - DB.Redis.Set("AllItemTime", RedisData, time.Second*60*60*24*30) c.JSON(200, tools.ResponseSeccess{ 0, @@ -144,7 +149,6 @@ func UpdateItemTime(c *gin.Context) { } - // @Title 获得所有设备的等待时间 // @Description 设备管理 - 获得所有设备的等待时间 // @Accept json @@ -160,11 +164,10 @@ func AllItemTime(c *gin.Context) { json.Unmarshal([]byte(c.PostForm("items")), &ItemTime) allteim := DB.Redis.Get("AllItemTime") - if allteim != nil{ + if allteim != nil { c.JSON(200, allteim) - }else{ + } else { c.String(200, "{}") } - } diff --git a/DB/db.go b/DB/db.go index d3987eb..b879832 100644 --- a/DB/db.go +++ b/DB/db.go @@ -23,21 +23,25 @@ var CTrajectory *mgo.Collection //移动轨迹 var DB *mgo.Database type SItem struct { - Id *bson.ObjectId `bson:"_id" json:"Id" valid:"required"` - Name string `bson:"Name" json:"Name"` - SubName string `bson:"SubName" json:"SubName"` - Location SLocation `bson:"Location" json:"Location"` - Tags []STag `bson:"Tags" json:"Tags"` - Icon string `bson:"Icon" json:"Icon"` - LimitHeight string `bson:"LimitHeight" json:"LimitHeight"` //限高 - PlayDuration string `bson:"PlayDuration" json:"PlayDuration"` //游玩时长 - SceneTime string `bson:"SceneTime" json:"SceneTime"` //场次时间 - Picture []string `bson:"Picture" json:"Picture"` - Voice string `bson:"Voice" json:"Voice"` //音频 - Tel string `bson:"Tel" json:"Tel"` - AverageConsumption string `bson:"AverageConsumption" json:"AverageConsumption"` //人均消费 - Menu string `bson:"Menu" json:"Menu"` //菜单 - Time string `bson:"Time" json:"Time"` + Id *bson.ObjectId `bson:"_id" json:"Id" valid:"required"` + Name string `bson:"Name" json:"Name"` + SubName string `bson:"SubName" json:"SubName"` + Location SLocation `bson:"Location" json:"Location"` + Tags []STag `bson:"Tags" json:"Tags"` + Icon string `bson:"Icon" json:"Icon"` + LimitHeight string `bson:"LimitHeight" json:"LimitHeight"` //限高 + PlayDuration string `bson:"PlayDuration" json:"PlayDuration"` //游玩时长 + SceneTime string `bson:"SceneTime" json:"SceneTime"` //场次时间 + Picture []string `bson:"Picture" json:"Picture"` + Voice string `bson:"Voice" json:"Voice"` //音频 + Tel string `bson:"Tel" json:"Tel"` + AverageConsumption string `bson:"AverageConsumption" json:"AverageConsumption"` //人均消费 + Menu string `bson:"Menu" json:"Menu"` //目录 + Time string `bson:"Time" json:"Time"` + OpenHours string `bson:"OpenHours" json:"OpenHours"` //开放时间 + LocationDescription string `bson:"LocationDescription" json:"LocationDescription"` //位置描述 + Reminder string `bson:"Reminder" json:"Reminder"` //温馨提示 + State int `bson:"State" json:"State"` // 运行状态0=正常1=停运 } type STrajectory struct { UserId string `bson:"UserId" json:"UserId"` // 用户ID diff --git a/README.md b/README.md index 08f2f8b..ddcdf8a 100644 --- a/README.md +++ b/README.md @@ -9,17 +9,19 @@ ### API List 1. [查询所有商品](#allcommodity-get) +1. [投诉 - 查询所有投诉](#allcomplaint-get) 1. [设备管理 - 获得所有设备的等待时间](#allitemtime-get) 1. [设备管理 - 查询所有游玩项目](#allitems-get) 1. [查询所有线路](#allline-get) 1. [所有景区基础信息](#allscenic-get) 1. [查询商品信息](#commodityinfo-get) -1. [增加投诉](#createcomplaint-post) +1. [投诉 - 增加投诉](#createcomplaint-post) 1. [查询用户的定时提醒](#dealymessage-info-get) 1. [创建提醒](#dealymessage-create-post) 1. [删除提醒](#dealymessage-remove-post) 1. [增加访问日志](#eventlog-post) -1. [增加调查](#investigation-save-post) +1. [问券调查 - 增加调查](#investigation-save-post) +1. [问券调查 - 查询所有问券调查](#investigation-list-get) 1. [设备管理 - 查询设备信息](#iteminfo-get) 1. [查询线路信息](#lineinfo-get) 1. [用户管理 - 用户登录&注册](#loginuser-post) @@ -52,6 +54,25 @@ + + +#### /AllComplaint (GET) + + +投诉 - 查询所有投诉 + +| Param Name | Example | Data Type | Description | Required? | +|-----|-----|-----|-----|-----| +| Page | 1 | int | 当前第几页 | Yes | + + +| Code | Type | Model | Message | +|-----|-----|-----|-----| +| 200 | object | [ResponseSeccess](#github.com.aarongao.tools.ResponseSeccess) | | +| 500 | object | [ResponseError](#github.com.aarongao.tools.ResponseError) | {"errcode":1,"errmsg":"错误原因"} | + + + #### /AllItemTime (GET) @@ -75,7 +96,7 @@ | Code | Type | Model | Message | |-----|-----|-----|-----| -| 200 | object | [ResponseSeccess](#github.com.aarongao.tools.ResponseSeccess) | Tags所属标签,标签有分类;LimitHeight限高;PlayDuration游玩时长;SceneTime场次时间;Picture照片;Voice音频;AverageConsumption平均消费;Menu菜单 | +| 200 | object | [ResponseSeccess](#github.com.aarongao.tools.ResponseSeccess) | Tags所属标签,标签有分类;LimitHeight限高;PlayDuration游玩时长;SceneTime场次时间;Picture照片;Voice音频;AverageConsumption平均消费;Menu菜单, OpenHours开放时间: LocationDescription位置描述; Reminder温馨提示; State运行状态0=正常1=停运 | | 500 | object | [ResponseError](#github.com.aarongao.tools.ResponseError) | {"errcode":1,"errmsg":"错误原因"} | @@ -132,7 +153,7 @@ #### /CreateComplaint (POST) -增加投诉 +投诉 - 增加投诉 | Param Name | Example | Data Type | Description | Required? | |-----|-----|-----|-----|-----| @@ -242,7 +263,7 @@ #### /Investigation/Save (POST) -增加调查 +问券调查 - 增加调查 | Param Name | Example | Data Type | Description | Required? | |-----|-----|-----|-----|-----| @@ -257,6 +278,24 @@ | 500 | object | [ResponseError](#github.com.aarongao.tools.ResponseError) | {"errcode":1,"errmsg":"错误原因"} | + + +#### /Investigation/List (GET) + + +问券调查 - 查询所有问券调查 + +| Param Name | Example | Data Type | Description | Required? | +|-----|-----|-----|-----|-----| +| Page | 1 | int | 当前第几页 | Yes | + + +| Code | Type | Model | Message | +|-----|-----|-----|-----| +| 200 | object | [ResponseSeccess](#github.com.aarongao.tools.ResponseSeccess) | {"errcode":0,"total":1,"currpage":1,"totalpages":1,"prepage":20,"result":} | +| 500 | object | [ResponseError](#github.com.aarongao.tools.ResponseError) | {"errcode":1,"errmsg":"错误原因"} | + + @@ -272,7 +311,7 @@ | Code | Type | Model | Message | |-----|-----|-----|-----| -| 200 | object | [ResponseSeccess](#github.com.aarongao.tools.ResponseSeccess) | {"errcode":0,"result":{"Name":"名称","Describe":"介绍","OpenHours":"开放时间","Mobile":"电话","Address":"地址","SLocation":{"Latitude":0,"Longitude":0},"Picture":["照片1","照片2"]}} | +| 200 | object | [ResponseSeccess](#github.com.aarongao.tools.ResponseSeccess) | Tags所属标签,标签有分类;LimitHeight限高;PlayDuration游玩时长;SceneTime场次时间;Picture照片;Voice音频;AverageConsumption平均消费;Menu菜单, OpenHours开放时间: LocationDescription位置描述; Reminder温馨提示; State运行状态0=正常1=停运 | | 500 | object | [ResponseError](#github.com.aarongao.tools.ResponseError) | {"errcode":1,"errmsg":"错误原因"} | @@ -412,7 +451,7 @@ | Code | Type | Model | Message | |-----|-----|-----|-----| -| 200 | object | [ResponseSeccess](#github.com.aarongao.tools.ResponseSeccess) | Tags所属标签,标签有分类;LimitHeight限高;PlayDuration游玩时长;SceneTime场次时间;Picture照片;Voice音频;AverageConsumption平均消费;Menu菜单 | +| 200 | object | [ResponseSeccess](#github.com.aarongao.tools.ResponseSeccess) | Tags所属标签,标签有分类;LimitHeight限高;PlayDuration游玩时长;SceneTime场次时间;Picture照片;Voice音频;AverageConsumption平均消费;Menu菜单, OpenHours开放时间: LocationDescription位置描述; Reminder温馨提示; State运行状态0=正常1=停运 | | 500 | object | [ResponseError](#github.com.aarongao.tools.ResponseError) | {"errcode":1,"errmsg":"错误原因"} | diff --git a/main.go b/main.go index 0598724..e8f07e6 100644 --- a/main.go +++ b/main.go @@ -74,6 +74,7 @@ func main() { r.GET("/ItemInfo", Api.ItemInfo) r.GET("/CommodityInfo", Api.CommodityInfo) r.POST("/CreateComplaint", Api.CreateComplaint) + r.GET("/AllComplaint", Api.AllComplaint) //r.POST("/CreateUser", Api.CreateUser) r.POST("/LoginUser", Api.LoginUser) r.POST("/UpdateUser", Api.UpdateUser) @@ -92,6 +93,7 @@ func main() { r.GET("/EventLog", Api.EventLog) r.POST("/Sms/Send", Api.Send) r.POST("/Investigation/Save", Api.SaveInvestigation) + r.GET("/Investigation/List", Api.AllInvestigation) r.POST("/Trajectory/Save", Api.SaveTrajectory) r.POST("/DealyMessage/Create", Api.CreateDealyMessage) r.GET("/DealyMessage/Info", Api.DealyMessageInfo) -- libgit2 0.21.0