Complaint.go
4.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
package Api
import (
"encoding/json"
"github.com/aarongao/tools"
"github.com/gin-gonic/gin"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo/options"
"letu/DB"
"letu/Lib/Auth"
"math"
"regexp"
"strconv"
"time"
)
// @Title 增加投诉
// @Description 投诉 - 增加投诉
// @Accept json
// @Produce json
// @Param Mobile 18616619599 string true "联系电话"
// @Param Name 高先生 string true "姓名"
// @Param Code 123456 string true "验证码"
// @Param Sex 男 string true "性别"
// @Param ScenicId 5e1ed07524e03431008b4572 string true "景区id"
// @Param Type 1 string true "类型"
// @Param Content 卫生不干净 string true "投诉内容"
// @Param Image ["http://www.xx.com/123.jpg","http://www.xx.com/123.jpg"] string true "照片数组"
// @Success 200 {object} tools.ResponseSeccess "{"errcode":0,"result":"ok"}"
// @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}"
// @Router /CreateComplaint? [post]
func CreateComplaint(c *gin.Context) {
c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin"))
c.Header("Access-Control-Allow-Credentials", "true")
reg := regexp.MustCompile(Regular)
if !reg.MatchString(c.PostForm("Mobile")) {
c.JSON(200, tools.ResponseError{
1,
"手机号格式不正确",
})
return
}
if c.PostForm("Mobile") == "" {
c.JSON(200, tools.ResponseError{
1,
"手机号为空",
})
return
}
// 检查验证码
cacheCode := DB.Redis.Get("code_" + c.PostForm("Mobile"))
if cacheCode != c.PostForm("Code") {
c.JSON(200, tools.ResponseError{
1,
"验证码不正确",
})
return
}
var images []string
json.Unmarshal([]byte(c.PostForm("Image")), &images)
objectID := primitive.NewObjectID()
DB.CComplaint.InsertOne(tools.GetContext(), DB.SComplaint{
&objectID,
c.PostForm("Type"),
c.PostForm("ScenicId"),
c.PostForm("Mobile"),
c.PostForm("Name"),
c.PostForm("Sex"),
c.PostForm("Content"),
images,
"未处理",
time.Now().Unix(),
})
c.JSON(200, tools.ResponseSeccess{
0,
"ok",
})
}
// @Title 查询所有投诉
// @Description 投诉 - 查询所有投诉
// @Accept json
// @Produce json
// @Param ScenicId 5e1ed07524e03431008b4572 string true "景区id"
// @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.CountDocuments(tools.GetContext(), bson.M{"ScenicId": c.Query("ScenicId")})
limit, _ := strconv.ParseInt(c.Query("Limit"), 10, 64)
if limit == 0 {
limit = 50
}
currPage, _ := strconv.ParseInt(c.Query("Page"), 10, 64)
if currPage == 0 {
currPage = 1
}
skip := (currPage - 1) * limit
var aComplaint = []bson.M{}
cur, err := DB.CComplaint.Find(tools.GetContext(), bson.M{"ScenicId": c.Query("ScenicId")}, &options.FindOptions{Limit: &limit, Skip: &skip, Sort: bson.M{"_id": -1}})
defer cur.Close(tools.GetContext())
if err == nil {
for cur.Next(tools.GetContext()) {
var e bson.M
cur.Decode(&e)
aComplaint = append(aComplaint, e)
}
}
c.JSON(200, tools.Page{
0,
total,
currPage,
int64(math.Ceil(float64(total) / float64(limit))),
limit,
aComplaint,
})
}
// @Title 处理投诉
// @Description 处理投诉
// @Accept json
// @Produce json
// @Param id 5dfb03070a9ac17ac7a82054 string true "投诉id"
// @Param ScenicId wgergejfwe string true "景区id"
// @Param Token wgergejfwe string true "用户token"
// @Success 200 {object} tools.ResponseSeccess "{"errcode":0,"result":"ok"}"
// @Failure 500 {object} tools.ResponseError "{"errcode":1,"errmsg":"错误原因"}"
// @Router /HandleComplaint? [post]
func HandleComplaint(c *gin.Context) {
c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin"))
c.Header("Access-Control-Allow-Credentials", "true")
_user, _ := c.Get("UserInfo")
user := _user.(*DB.SMember)
err := Auth.CheckScenicAuth(c.PostForm("ScenicId"), user)
if err != nil {
c.JSON(200, tools.ResponseError{
401,
"没有权限",
})
return
}
objectID, _ := primitive.ObjectIDFromHex(c.PostForm("id"))
_, err = DB.CComplaint.UpdateOne(tools.GetContext(),
bson.M{"_id": objectID},
bson.M{"$set": bson.M{
"State": "已处理",
}},
)
c.JSON(200, tools.ResponseSeccess{
0,
"ok",
})
}