Bladeren bron

体检更新

wangfei 6 jaren geleden
bovenliggende
commit
b7b79500f4

+ 5
- 0
conf/app.conf Bestand weergeven

@@ -29,3 +29,8 @@ guest = "/guest/:org"
29 29
 common = "/common/:org"
30 30
 wechat = "/wechat/:org"
31 31
 
32
+
33
+postwechatInfo = http://testapi.chioy.com.cn/api/network/postwechatInfo
34
+qrcodePrefix = bodycheck_
35
+followText = 您正在使用悦琦设备进行体检~
36
+resultURL = http://dev.ycjcjy.com/bodyCheck

+ 1
- 0
conf/wechat.conf Bestand weergeven

@@ -0,0 +1 @@
1
+messageTplID = 1ft8YDwqOYwIHxTXXVlJh5Q7ST5qU1a0qlnF6B6TCBU

+ 7
- 0
controllers/base.go Bestand weergeven

@@ -48,6 +48,13 @@ func (c *BaseController) ResponseError(err error, code ...int) {
48 48
 	c.ResponseData(nil, err, http.StatusBadRequest)
49 49
 }
50 50
 
51
+// ResponseRaw 返回
52
+func (c *BaseController) ResponseRaw(msg []byte) {
53
+	c.destroyContext(true)
54
+	c.Ctx.ResponseWriter.Write(msg)
55
+	c.StopRun()
56
+}
57
+
51 58
 // ResponseData 自定义的JSON返回
52 59
 func (c *BaseController) ResponseData(data interface{}, msg interface{}, code int) {
53 60
 	status := code

+ 52
- 0
controllers/bodycheck/bodycheck.go Bestand weergeven

@@ -0,0 +1,52 @@
1
+package bodycheck
2
+
3
+import (
4
+	"encoding/json"
5
+	"io/ioutil"
6
+	"spaceofcheng/services/controllers"
7
+	"spaceofcheng/services/service/bodycheck"
8
+	"spaceofcheng/services/utils"
9
+)
10
+
11
+// BodyCheckController 商品
12
+type BodyCheckController struct {
13
+	serv *bodycheck.BodyCheckServ
14
+	controllers.BaseController
15
+}
16
+
17
+// Constructor 初始化 Controller
18
+// @Title Constructor
19
+// @Description 初始化 Controller, 系统自动调用
20
+func (c *BodyCheckController) Constructor() {
21
+	c.serv = bodycheck.NewBodyCheckServ(c.Context)
22
+}
23
+
24
+// GetCheckByUser 根据用户获取体检报告
25
+func (c *BodyCheckController) GetCheckByUser() {
26
+	info, err := c.serv.GetCheckByUser()
27
+	if err != nil {
28
+		c.ResponseError(err)
29
+	}
30
+	c.ResponseJSON(info)
31
+}
32
+
33
+// PostCheckResult 测量结果返回
34
+func (c *BodyCheckController) PostCheckResult() {
35
+	r := c.Ctx.Request
36
+	defer r.Body.Close()
37
+	con, _ := ioutil.ReadAll(r.Body) //获取post的数据
38
+
39
+	var formVal map[string]interface{}
40
+	err := json.Unmarshal(con, &formVal)
41
+	if err != nil {
42
+		utils.LogError("参数错误:", err)
43
+		c.ResponseError(err)
44
+	}
45
+
46
+	err = c.serv.PostCheckResult(formVal)
47
+	if err != nil {
48
+		utils.LogError("操作错误:", err)
49
+		c.ResponseError(err)
50
+	}
51
+	c.ResponseJSON("")
52
+}

+ 229
- 1
controllers/statistics/cardcoupon.go Bestand weergeven

@@ -1,6 +1,11 @@
1 1
 package statistics
2 2
 
3
-import "spaceofcheng/services/models/model"
3
+import (
4
+	"errors"
5
+	"spaceofcheng/services/models/model"
6
+	"spaceofcheng/services/utils"
7
+	"strconv"
8
+)
4 9
 
5 10
 // CardCouponStatistics 获取卡券统计数据
6 11
 func (c *StatisticsController) CardCouponStatistics() {
@@ -22,6 +27,72 @@ func (c *StatisticsController) CardCouponStatistics() {
22 27
 	c.ResponseJSON(list)
23 28
 }
24 29
 
30
+// CardCouponStatisticsExcel 获取卡券统计数据
31
+func (c *StatisticsController) CardCouponStatisticsExcel() {
32
+	caseids := c.GetString("caseid")
33
+	name := c.GetString("name")
34
+	ctype := c.GetString("ctype")
35
+
36
+	if caseids == "" {
37
+		cases := c.Context.Get("cases").([]model.SysUserCase)
38
+		caseids = c.GetCaseIDs(cases)
39
+	}
40
+
41
+	list, err := c.serv.CardCouponStatisticsExcel(caseids, ctype, name)
42
+	if err != nil {
43
+		c.ResponseError(err)
44
+	}
45
+	excel, err := utils.NewTinyXLSXEngine()
46
+	if err != nil {
47
+		utils.LogError("初始化Excel服务失败: " + err.Error())
48
+		c.ResponseError(errors.New("初始化Excel服务失败"))
49
+	}
50
+
51
+	excel.SetCell(excel.InsertRow(), []string{
52
+		"案场",
53
+		"卡券名称",
54
+		"卡券类型",
55
+		"发送类型",
56
+		"价格",
57
+		"领取数",
58
+		"实际使用数",
59
+		"总费用",
60
+	})
61
+
62
+	for _, item := range list {
63
+		row := excel.InsertRow()
64
+		sendtype := ""
65
+		switch item.SendType {
66
+		case "system":
67
+			sendtype = "系统"
68
+			break
69
+		case "case":
70
+			sendtype = "案场"
71
+			break
72
+		case "channel":
73
+			sendtype = "渠道"
74
+			break
75
+		}
76
+		price, err := strconv.ParseFloat(item.Price, 64)
77
+		if err != nil {
78
+			c.ResponseError(errors.New("金额类型不正确!"))
79
+		}
80
+		amount := price * float64(item.UsedCount)
81
+
82
+		excel.SetCell(row, []string{
83
+			item.CaseName,
84
+			item.CName,
85
+			item.TypeName,
86
+			sendtype,
87
+			item.Price,
88
+			strconv.Itoa(item.SentCount),
89
+			strconv.Itoa(item.UsedCount),
90
+			strconv.FormatFloat(amount, 'f', -1, 64),
91
+		})
92
+	}
93
+	c.SaveToExcel("卡券统计列表.xlsx", excel)
94
+}
95
+
25 96
 // CardCouponUsedStatistics 获取卡券使用统计数据
26 97
 func (c *StatisticsController) CardCouponUsedStatistics() {
27 98
 	page, _ := c.GetInt("page")
@@ -46,6 +117,94 @@ func (c *StatisticsController) CardCouponUsedStatistics() {
46 117
 	c.ResponseJSON(list)
47 118
 }
48 119
 
120
+// CardCouponUsedStatisticsExcel 卡券使用导出
121
+func (c *StatisticsController) CardCouponUsedStatisticsExcel() {
122
+	caseids := c.GetString("caseid")
123
+	name := c.GetString("name")
124
+	receivetype := c.GetString("receivetype")
125
+	tel := c.GetString("tel")
126
+	begindate := c.GetString("begindate")
127
+	enddate := c.GetString("enddate")
128
+	status := c.GetString("status")
129
+
130
+	if caseids == "" {
131
+		cases := c.Context.Get("cases").([]model.SysUserCase)
132
+		caseids = c.GetCaseIDs(cases)
133
+	}
134
+	list, err := c.serv.CardCouponUsedStatisticsExcel(caseids, tel, name, receivetype, begindate, enddate, status)
135
+	if err != nil {
136
+		c.ResponseError(err)
137
+	}
138
+
139
+	excel, err := utils.NewTinyXLSXEngine()
140
+	if err != nil {
141
+		utils.LogError("初始化Excel服务失败: " + err.Error())
142
+		c.ResponseError(errors.New("初始化Excel服务失败"))
143
+	}
144
+
145
+	excel.SetCell(excel.InsertRow(), []string{
146
+		"案场",
147
+		"卡券名称",
148
+		"使用商品",
149
+		"获取方式",
150
+		"微信昵称",
151
+		"手机号",
152
+		"有效期",
153
+		"获取时间",
154
+		"使用时间",
155
+		"状态",
156
+	})
157
+
158
+	for _, item := range list {
159
+		row := excel.InsertRow()
160
+		receivetype := ""
161
+		switch item.ReceivingType {
162
+		case "event":
163
+			receivetype = "系统"
164
+			break
165
+		case "case":
166
+			receivetype = "案场"
167
+			break
168
+		case "channel":
169
+			receivetype = "渠道"
170
+			break
171
+		case "give":
172
+			receivetype = "后台赠送"
173
+			break
174
+		}
175
+
176
+		verifystatus := ""
177
+		switch item.VerifyStatus {
178
+		case "useable":
179
+			verifystatus = "未使用"
180
+			break
181
+		case "used":
182
+			verifystatus = "已使用"
183
+			break
184
+		case "late":
185
+			verifystatus = "逾期核销"
186
+			break
187
+		case "expire":
188
+			verifystatus = "已失效"
189
+			break
190
+		}
191
+
192
+		excel.SetCell(row, []string{
193
+			item.CaseName,
194
+			item.CardCouponName,
195
+			item.TargetName,
196
+			receivetype,
197
+			item.CustomerName,
198
+			item.Phone,
199
+			item.EndDate.Format("2006-01-02 15:04:05"),
200
+			item.ReceiveDate.Format("2006-01-02 15:04:05"),
201
+			item.UsedDate.Format("2006-01-02 15:04:05"),
202
+			verifystatus,
203
+		})
204
+	}
205
+	c.SaveToExcel("卡券使用列表.xlsx", excel)
206
+}
207
+
49 208
 // CardCouponVerifyStatistics 获取卡券核销统计数据
50 209
 func (c *StatisticsController) CardCouponVerifyStatistics() {
51 210
 	page, _ := c.GetInt("page")
@@ -66,3 +225,72 @@ func (c *StatisticsController) CardCouponVerifyStatistics() {
66 225
 
67 226
 	c.ResponseJSON(list)
68 227
 }
228
+
229
+// CardCouponVerifyStatisticsExcel 卡券核销统计导出
230
+func (c *StatisticsController) CardCouponVerifyStatisticsExcel() {
231
+	caseids := c.GetString("caseid")
232
+	name := c.GetString("name")
233
+	tel := c.GetString("tel")
234
+	status := c.GetString("status")
235
+
236
+	if caseids == "" {
237
+		cases := c.Context.Get("cases").([]model.SysUserCase)
238
+		caseids = c.GetCaseIDs(cases)
239
+	}
240
+	list, err := c.serv.CardCouponVerifyStatisticsExcel(caseids, tel, name, status)
241
+	if err != nil {
242
+		c.ResponseError(err)
243
+	}
244
+
245
+	excel, err := utils.NewTinyXLSXEngine()
246
+	if err != nil {
247
+		utils.LogError("初始化Excel服务失败: " + err.Error())
248
+		c.ResponseError(errors.New("初始化Excel服务失败"))
249
+	}
250
+
251
+	excel.SetCell(excel.InsertRow(), []string{
252
+		"案场",
253
+		"课程名称",
254
+		"课程时间",
255
+		"姓名",
256
+		"微信昵称",
257
+		"手机号",
258
+		"下单时间",
259
+		"核销时间",
260
+		"状态",
261
+	})
262
+
263
+	for _, item := range list {
264
+		row := excel.InsertRow()
265
+		verifystatus := ""
266
+		switch item.Status {
267
+		case "useable":
268
+			verifystatus = "未使用"
269
+			break
270
+		case "used":
271
+			verifystatus = "已使用"
272
+			break
273
+		case "late":
274
+			verifystatus = "逾期核销"
275
+			break
276
+		}
277
+
278
+		verifydate := ""
279
+		if !item.VerifyDate.IsZero() {
280
+			verifydate = item.VerifyDate.Format("2006-01-02 15:04:05")
281
+		}
282
+
283
+		excel.SetCell(row, []string{
284
+			item.CaseName,
285
+			item.CourseName,
286
+			item.BeginDate.Format("2006-01-02 15:04:05") + "~" + item.EndDate.Format("2006-01-02 15:04:05"),
287
+			item.Name,
288
+			item.CustomerName,
289
+			item.Phone,
290
+			item.CreateDate.Format("2006-01-02 15:04:05"),
291
+			verifydate,
292
+			verifystatus,
293
+		})
294
+	}
295
+	c.SaveToExcel("卡券核销列表.xlsx", excel)
296
+}

+ 111
- 1
controllers/statistics/course.go Bestand weergeven

@@ -1,6 +1,11 @@
1 1
 package statistics
2 2
 
3
-import "spaceofcheng/services/models/model"
3
+import (
4
+	"errors"
5
+	"spaceofcheng/services/models/model"
6
+	"spaceofcheng/services/utils"
7
+	"strconv"
8
+)
4 9
 
5 10
 // GetCourseOrdersStatistics 获取课程订单统计数据
6 11
 func (c *StatisticsController) GetCourseOrdersStatistics() {
@@ -24,6 +29,56 @@ func (c *StatisticsController) GetCourseOrdersStatistics() {
24 29
 	c.ResponseJSON(ordersList)
25 30
 }
26 31
 
32
+// GetCourseOrdersStatisticsExcel 课程订单导出
33
+func (c *StatisticsController) GetCourseOrdersStatisticsExcel() {
34
+	caseids := c.GetString("caseid")
35
+	name := c.GetString("name")
36
+	typeid := c.GetString("typeid")
37
+	begindate := c.GetString("begindate")
38
+	enddate := c.GetString("enddate")
39
+
40
+	if caseids == "" {
41
+		cases := c.Context.Get("cases").([]model.SysUserCase)
42
+		caseids = c.GetCaseIDs(cases)
43
+	}
44
+	list, err := c.serv.GetCourseOrdersStatisticsExcel(typeid, caseids, name, begindate, enddate)
45
+	if err != nil {
46
+		c.ResponseError(err)
47
+	}
48
+
49
+	excel, err := utils.NewTinyXLSXEngine()
50
+	if err != nil {
51
+		utils.LogError("初始化Excel服务失败: " + err.Error())
52
+		c.ResponseError(errors.New("初始化Excel服务失败"))
53
+	}
54
+
55
+	excel.SetCell(excel.InsertRow(), []string{
56
+		"订单编号",
57
+		"课程名称",
58
+		"案场",
59
+		"课程类别",
60
+		"课程时间",
61
+		"用户姓名",
62
+		"手机号",
63
+		"下单时间",
64
+	})
65
+
66
+	for _, item := range list {
67
+		row := excel.InsertRow()
68
+		excel.SetCell(row, []string{
69
+			item.OrdersNo,
70
+			item.CourseName,
71
+			item.CaseName,
72
+			item.LocationName,
73
+			item.BeginDate.Format("2006-01-02 15:04:05") + "~" + item.EndDate.Format("2006-01-02 15:04:05"),
74
+			item.CustomerName,
75
+			item.Phone,
76
+			item.CreateDate.Format("2006-01-02 15:04:05"),
77
+		})
78
+	}
79
+	c.SaveToExcel("课程订单列表.xlsx", excel)
80
+}
81
+
27 82
 // GetCourseStatistics 获取课程统计数据
28 83
 func (c *StatisticsController) GetCourseStatistics() {
29 84
 	page, _ := c.GetInt("page")
@@ -43,3 +98,58 @@ func (c *StatisticsController) GetCourseStatistics() {
43 98
 
44 99
 	c.ResponseJSON(ordersList)
45 100
 }
101
+
102
+// GetCourseStatisticsExcel 课程统计数据导出
103
+func (c *StatisticsController) GetCourseStatisticsExcel() {
104
+
105
+	caseids := c.GetString("caseid")
106
+	name := c.GetString("name")
107
+	typeid := c.GetString("typeid")
108
+
109
+	if caseids == "" {
110
+		cases := c.Context.Get("cases").([]model.SysUserCase)
111
+		caseids = c.GetCaseIDs(cases)
112
+	}
113
+	list, err := c.serv.GetCourseStatisticsExcel(typeid, caseids, name)
114
+	if err != nil {
115
+		c.ResponseError(err)
116
+	}
117
+
118
+	excel, err := utils.NewTinyXLSXEngine()
119
+	if err != nil {
120
+		utils.LogError("初始化Excel服务失败: " + err.Error())
121
+		c.ResponseError(errors.New("初始化Excel服务失败"))
122
+	}
123
+
124
+	excel.SetCell(excel.InsertRow(), []string{
125
+		"案场",
126
+		"课程名称",
127
+		"课程类别",
128
+		"课程时间",
129
+		"课程价格",
130
+		"报名人数",
131
+		"核销人数",
132
+		"总费用",
133
+	})
134
+
135
+	for _, item := range list {
136
+		row := excel.InsertRow()
137
+		price, err := strconv.ParseFloat(item.Price, 64)
138
+		if err != nil {
139
+			c.ResponseError(errors.New("金额类型不正确!"))
140
+		}
141
+		amount := price * float64(item.JoinTotal)
142
+
143
+		excel.SetCell(row, []string{
144
+			item.CaseName,
145
+			item.CourseName,
146
+			item.LocationName,
147
+			item.BeginDate.Format("2006-01-02 15:04:05") + "~" + item.EndDate.Format("2006-01-02 15:04:05"),
148
+			item.Price,
149
+			strconv.Itoa(item.Total),
150
+			strconv.Itoa(item.JoinTotal),
151
+			strconv.FormatFloat(amount, 'f', -1, 64),
152
+		})
153
+	}
154
+	c.SaveToExcel("课程统计列表.xlsx", excel)
155
+}

+ 139
- 1
controllers/statistics/goods.go Bestand weergeven

@@ -1,6 +1,11 @@
1 1
 package statistics
2 2
 
3
-import "spaceofcheng/services/models/model"
3
+import (
4
+	"errors"
5
+	"spaceofcheng/services/models/model"
6
+	"spaceofcheng/services/utils"
7
+	"strconv"
8
+)
4 9
 
5 10
 // GetGoodsStatistics 获取商品统计数据
6 11
 func (c *StatisticsController) GetGoodsStatistics() {
@@ -22,6 +27,58 @@ func (c *StatisticsController) GetGoodsStatistics() {
22 27
 	c.ResponseJSON(goodsList)
23 28
 }
24 29
 
30
+// GetGoodsStatisticsExcel 商品统计导出
31
+func (c *StatisticsController) GetGoodsStatisticsExcel() {
32
+	caseids := c.GetString("caseid")
33
+	name := c.GetString("name")
34
+	typeid := c.GetString("typeid")
35
+
36
+	if caseids == "" {
37
+		cases := c.Context.Get("cases").([]model.SysUserCase)
38
+		caseids = c.GetCaseIDs(cases)
39
+	}
40
+	list, err := c.serv.GetGoodsStatisticsExcel(caseids, typeid, name)
41
+	if err != nil {
42
+		c.ResponseError(err)
43
+	}
44
+
45
+	excel, err := utils.NewTinyXLSXEngine()
46
+	if err != nil {
47
+		utils.LogError("初始化Excel服务失败: " + err.Error())
48
+		c.ResponseError(errors.New("初始化Excel服务失败"))
49
+	}
50
+
51
+	excel.SetCell(excel.InsertRow(), []string{
52
+		"案场",
53
+		"商品名称",
54
+		"分类",
55
+		"价格",
56
+		"下单数",
57
+		"完成数",
58
+		"总费用",
59
+	})
60
+
61
+	for _, item := range list {
62
+		row := excel.InsertRow()
63
+		price, err := strconv.ParseFloat(item.Price, 64)
64
+		if err != nil {
65
+			c.ResponseError(errors.New("金额类型不正确!"))
66
+		}
67
+		amount := price * float64(item.FinishTotal)
68
+
69
+		excel.SetCell(row, []string{
70
+			item.CaseName,
71
+			item.GoodsName,
72
+			item.TypeName,
73
+			item.Price,
74
+			strconv.Itoa(item.Total),
75
+			strconv.Itoa(item.FinishTotal),
76
+			strconv.FormatFloat(amount, 'f', -1, 64),
77
+		})
78
+	}
79
+	c.SaveToExcel("商品统计列表.xlsx", excel)
80
+}
81
+
25 82
 // GetGoodsOrdersStatistics 获取商品订单统计数据
26 83
 func (c *StatisticsController) GetGoodsOrdersStatistics() {
27 84
 	page, _ := c.GetInt("page")
@@ -43,3 +100,84 @@ func (c *StatisticsController) GetGoodsOrdersStatistics() {
43 100
 
44 101
 	c.ResponseJSON(goodsList)
45 102
 }
103
+
104
+// GetGoodsOrdersStatisticsExcel 商品订单统计导出
105
+func (c *StatisticsController) GetGoodsOrdersStatisticsExcel() {
106
+	caseids := c.GetString("caseid")
107
+	status := c.GetString("status")
108
+	usertype := c.GetString("usertype")
109
+	begindate := c.GetString("begindate")
110
+	enddate := c.GetString("enddate")
111
+
112
+	if caseids == "" {
113
+		cases := c.Context.Get("cases").([]model.SysUserCase)
114
+		caseids = c.GetCaseIDs(cases)
115
+	}
116
+	list, err := c.serv.GetGoodsOrdersStatisticsExcel(status, usertype, caseids, begindate, enddate)
117
+	if err != nil {
118
+		c.ResponseError(err)
119
+	}
120
+
121
+	excel, err := utils.NewTinyXLSXEngine()
122
+	if err != nil {
123
+		utils.LogError("初始化Excel服务失败: " + err.Error())
124
+		c.ResponseError(errors.New("初始化Excel服务失败"))
125
+	}
126
+
127
+	excel.SetCell(excel.InsertRow(), []string{
128
+		"订单编号",
129
+		"案场",
130
+		"用户类型",
131
+		"下单时间",
132
+		"订单状态",
133
+		"商品",
134
+		"数量",
135
+		"金额",
136
+		"桌位",
137
+		"下单人",
138
+		"电话",
139
+	})
140
+
141
+	for _, item := range list {
142
+		row := excel.InsertRow()
143
+		usertype := ""
144
+		switch item.UserType {
145
+		case "customer":
146
+			usertype = "用户"
147
+			break
148
+		case "sales":
149
+			usertype = "销售"
150
+			break
151
+		case "manager":
152
+			usertype = "主管"
153
+			break
154
+		}
155
+
156
+		orderStatus := ""
157
+		if item.Status == 1 {
158
+			orderStatus = "已完成"
159
+		} else {
160
+			orderStatus = "已取消"
161
+		}
162
+		for _, detail := range item.Details {
163
+			name := detail.GoodsName
164
+			if detail.SpecName != "" {
165
+				name = name + "(" + detail.SpecName + ")"
166
+			}
167
+			excel.SetCell(row, []string{
168
+				item.OrdersNo,
169
+				item.CaseName,
170
+				usertype,
171
+				item.CreateDate.Format("2006-01-02 15:04:05"),
172
+				orderStatus,
173
+				name,
174
+				strconv.Itoa(detail.Number),
175
+				item.AreaName + item.TableNo,
176
+				item.CustomerName,
177
+				item.Phone,
178
+			})
179
+		}
180
+
181
+	}
182
+	c.SaveToExcel("商品订单统计列表.xlsx", excel)
183
+}

+ 163
- 0
controllers/wechat.go Bestand weergeven

@@ -1,12 +1,175 @@
1 1
 package controllers
2 2
 
3 3
 import (
4
+	"bytes"
5
+	"encoding/json"
4 6
 	"errors"
7
+	"io/ioutil"
8
+	"net/http"
5 9
 	"net/url"
6 10
 	"spaceofcheng/services/models/model"
11
+	"spaceofcheng/services/service/customer"
7 12
 	"spaceofcheng/services/utils"
13
+	"strings"
14
+
15
+	"github.com/astaxie/beego"
8 16
 )
9 17
 
18
+// WechatInfo 微信接入
19
+func (c *BaseController) WechatInfo() {
20
+	// signature := c.GetString("signature")
21
+	// timestamp := c.GetString("timestamp")
22
+	// nonce := c.GetString("nonce")
23
+	echostr := c.GetString("echostr")
24
+	c.ResponseRaw([]byte(echostr))
25
+}
26
+
27
+// GetQrcodeURL 获取二维码信息
28
+func (c *BaseController) GetQrcodeURL() {
29
+	EquipmentID := c.GetString("EquipmentId")
30
+	qrcodePrefix := beego.AppConfig.String("qrcodePrefix")
31
+	org := c.Context.Get("org").(model.SysOrg)
32
+
33
+	qrcode, err := utils.WxClientFor(org.OrgId).GetTempStrQRCode(qrcodePrefix + EquipmentID)
34
+	if err != nil {
35
+		utils.LogError("获取二维码失败!")
36
+		c.ResponseError(err)
37
+	}
38
+	c.ResponseJSON(map[string]interface{}{
39
+		"QrcodeUrl": qrcode,
40
+	})
41
+}
42
+
43
+// WxReceive
44
+func (c *BaseController) WxReceive() {
45
+	org := c.Context.Get("org").(model.SysOrg)
46
+	wechat := utils.WxClientFor(org.OrgId)
47
+	r := c.Ctx.Request
48
+	defer r.Body.Close()
49
+	con, _ := ioutil.ReadAll(r.Body) //获取post的数据
50
+	val, err := wechat.TransformMessage(string(con))
51
+	if err != nil {
52
+		beego.Error(err.Error())
53
+		c.ResponseRaw([]byte(""))
54
+	}
55
+
56
+	if val["MsgType"] == "event" {
57
+		qrcodePrefix := beego.AppConfig.String("qrcodePrefix")
58
+		if (val["Event"] == "subscribe" && strings.Contains(val["EventKey"], "qrscene_"+qrcodePrefix)) || val["Event"] == "SCAN" {
59
+			EquipmentID := strings.Split(val["EventKey"], qrcodePrefix)[1]
60
+			messagetxt, err := c.scanDo(val, EquipmentID)
61
+			if err != nil {
62
+				beego.Error(err.Error())
63
+				c.ResponseRaw([]byte(""))
64
+			}
65
+			c.ResponseRaw(messagetxt)
66
+		}
67
+	}
68
+	c.ResponseRaw([]byte(""))
69
+}
70
+
71
+func (c *BaseController) scanDo(val map[string]string, EquipmentID string) ([]byte, error) {
72
+	org := c.Context.Get("org").(model.SysOrg)
73
+	wechat := utils.WxClientFor(org.OrgId)
74
+
75
+	if val["FromUserName"] == "" {
76
+		return nil, errors.New("openid为空")
77
+	}
78
+
79
+	user, err := wechat.GetUserDetail(val["FromUserName"])
80
+	if err != nil {
81
+		return nil, err
82
+	}
83
+
84
+	var customerserv = customer.NewCustomerServ(c.Context)
85
+
86
+	// 判断用户是否存在
87
+	getUser, err := customerserv.GetCustUserByOpenID(user["openid"].(string))
88
+	if err != nil {
89
+		return nil, err
90
+	}
91
+	name := user["nickname"].(string)
92
+	name = UnicodeEmojiCode(name)
93
+	user["nickname"] = name
94
+	if getUser == nil || getUser.CustomerId != "" {
95
+		// 新增用户
96
+		_, err := customerserv.SaveNewCustomer(user, "", "", "", "")
97
+		if err != nil {
98
+			utils.LogError("用户保存失败:", err)
99
+			return nil, err
100
+		}
101
+	}
102
+
103
+	type WechatInfo struct {
104
+		EquipmentId    string
105
+		WXID           int
106
+		WechatUserInfo map[string]interface{}
107
+	}
108
+	appid := wechat.GetAppID()
109
+	user["wechataccount"] = user["openid"].(string)
110
+	user["wechatofficial"] = appid
111
+	var userinfo = WechatInfo{}
112
+	userinfo.EquipmentId = EquipmentID
113
+	userinfo.WechatUserInfo = user
114
+	userinfo.WXID = 1
115
+
116
+	apiPrefix := beego.AppConfig.String("postwechatInfo")
117
+
118
+	b, err := json.Marshal(userinfo)
119
+	if err != nil {
120
+		return nil, err
121
+	}
122
+
123
+	body := bytes.NewBuffer([]byte(b))
124
+
125
+	res, err := http.Post(apiPrefix, "application/json;charset=utf-8", body)
126
+	if err != nil {
127
+		beego.Error(err)
128
+		return nil, err
129
+	}
130
+	result, err := ioutil.ReadAll(res.Body)
131
+	res.Body.Close()
132
+	if err != nil {
133
+		utils.LogError("发送消息失败:", err)
134
+		return nil, err
135
+	}
136
+	var postResult struct {
137
+		Status  bool
138
+		Message string
139
+	}
140
+	if err = json.Unmarshal(result, &postResult); err != nil {
141
+		utils.LogError("发送消息失败:", err)
142
+		return nil, err
143
+	}
144
+
145
+	if !postResult.Status {
146
+		beego.Error(postResult.Message)
147
+		return nil, errors.New(postResult.Message)
148
+	}
149
+
150
+	messagetxt, err := wechat.ResponseMessageText(user["openid"].(string), beego.AppConfig.String("followText"))
151
+	if err != nil {
152
+		beego.Error(err)
153
+		return nil, err
154
+	}
155
+	return messagetxt, nil
156
+}
157
+
158
+// UnicodeEmojiCode 过滤表情
159
+func UnicodeEmojiCode(s string) string {
160
+	ret := ""
161
+	rs := []rune(s)
162
+	for i := 0; i < len(rs); i++ {
163
+		if len(string(rs[i])) == 4 {
164
+			// u := `[\u` + strconv.FormatInt(int64(rs[i]), 16) + `]`
165
+			ret += ""
166
+		} else {
167
+			ret += string(rs[i])
168
+		}
169
+	}
170
+	return ret
171
+}
172
+
10 173
 // GetWxJsSDKSignature 获取 微信 jssdk 签名
11 174
 func (c *BaseController) GetWxJsSDKSignature() {
12 175
 	org := c.Context.Get("org").(model.SysOrg)

+ 269
- 0
log/common.log Bestand weergeven

@@ -73,3 +73,272 @@
73 73
 2018/09/16 17:39:13 [E] 用户没有设置默认案场
74 74
 2018/09/16 18:43:58 [E] 用户没有设置默认案场
75 75
 2018/09/16 18:43:58 [E] 用户没有设置默认案场
76
+2018/09/16 19:21:38 [E] 用户没有设置默认案场
77
+2018/09/16 19:21:38 [E] 用户没有设置默认案场
78
+2018/09/16 19:23:09 [E] 用户没有设置默认案场
79
+2018/09/16 19:23:09 [E] 用户没有设置默认案场
80
+2018/09/16 19:23:14 [E] 用户没有设置默认案场
81
+2018/09/16 19:23:15 [E] 用户没有设置默认案场
82
+2018/09/16 19:24:16 [E] 用户没有设置默认案场
83
+2018/09/16 19:24:16 [E] 用户没有设置默认案场
84
+2018/09/16 19:24:16 [E] 用户没有设置默认案场
85
+2018/09/16 19:25:07 [E] 用户没有设置默认案场
86
+2018/09/16 19:25:07 [E] 用户没有设置默认案场
87
+2018/09/16 19:25:07 [E] 用户没有设置默认案场
88
+2018/09/16 19:26:15 [E] 用户没有设置默认案场
89
+2018/09/16 19:26:42 [E] 用户没有设置默认案场
90
+2018/09/16 19:26:45 [E] 用户没有设置默认案场
91
+2018/09/16 19:26:45 [E] 用户没有设置默认案场
92
+2018/09/16 19:27:06 [E] 用户没有设置默认案场
93
+2018/09/16 19:27:06 [E] 用户没有设置默认案场
94
+2018/09/16 19:29:45 [E] 用户没有设置默认案场
95
+2018/09/16 19:30:00 [E] 用户没有设置默认案场
96
+2018/09/16 19:30:00 [E] 用户没有设置默认案场
97
+2018/09/16 19:30:26 [E] 用户没有设置默认案场
98
+2018/09/16 19:33:11 [E] 用户没有设置默认案场
99
+2018/09/16 19:34:19 [E] 用户没有设置默认案场
100
+2018/09/16 19:35:56 [E] 用户没有设置默认案场
101
+2018/09/16 19:36:33 [E] 用户没有设置默认案场
102
+2018/09/16 19:37:06 [E] 用户没有设置默认案场
103
+2018/09/16 19:37:17 [E] 用户没有设置默认案场
104
+2018/09/16 19:37:19 [E] 用户没有设置默认案场
105
+2018/09/16 19:37:20 [E] 用户没有设置默认案场
106
+2018/09/16 19:37:21 [E] 用户没有设置默认案场
107
+2018/09/16 19:37:36 [E] 用户没有设置默认案场
108
+2018/09/16 19:37:46 [E] 用户没有设置默认案场
109
+2018/09/16 19:37:46 [E] 用户没有设置默认案场
110
+2018/09/16 19:38:13 [E] 用户没有设置默认案场
111
+2018/09/16 19:38:24 [E] 用户没有设置默认案场
112
+2018/09/16 19:38:31 [E] 用户没有设置默认案场
113
+2018/09/16 19:38:31 [E] 用户没有设置默认案场
114
+2018/09/16 19:38:33 [E] 用户没有设置默认案场
115
+2018/09/16 19:38:38 [E] 用户没有设置默认案场
116
+2018/09/16 19:38:43 [E] 用户没有设置默认案场
117
+2018/09/16 19:38:43 [E] 用户没有设置默认案场
118
+2018/09/16 19:38:56 [E] 用户没有设置默认案场
119
+2018/09/16 19:39:00 [E] 用户没有设置默认案场
120
+2018/09/16 19:41:09 [E] 用户没有设置默认案场
121
+2018/09/16 19:41:48 [E] 用户没有设置默认案场
122
+2018/09/16 19:41:48 [E] 用户没有设置默认案场
123
+2018/09/16 19:43:37 [E] 用户没有设置默认案场
124
+2018/09/16 19:43:38 [E] 用户没有设置默认案场
125
+2018/09/16 19:43:39 [E] 用户没有设置默认案场
126
+2018/09/16 19:43:40 [E] 用户没有设置默认案场
127
+2018/09/16 19:43:40 [E] 用户没有设置默认案场
128
+2018/09/16 19:43:41 [E] 用户没有设置默认案场
129
+2018/09/16 19:43:41 [E] 用户没有设置默认案场
130
+2018/09/16 19:43:42 [E] 用户没有设置默认案场
131
+2018/09/16 19:43:44 [E] 用户没有设置默认案场
132
+2018/09/16 19:43:44 [E] 用户没有设置默认案场
133
+2018/09/16 19:43:50 [E] 用户没有设置默认案场
134
+2018/09/16 19:43:52 [E] 用户没有设置默认案场
135
+2018/09/16 19:43:53 [E] 用户没有设置默认案场
136
+2018/09/16 19:43:54 [E] 用户没有设置默认案场
137
+2018/09/16 19:43:55 [E] 用户没有设置默认案场
138
+2018/09/16 19:44:13 [E] 用户没有设置默认案场
139
+2018/09/16 19:44:13 [E] 用户没有设置默认案场
140
+2018/09/16 19:44:14 [E] 用户没有设置默认案场
141
+2018/09/16 19:45:09 [E] 用户没有设置默认案场
142
+2018/09/16 19:45:44 [E] 用户没有设置默认案场
143
+2018/09/16 19:45:47 [E] 用户没有设置默认案场
144
+2018/09/16 19:45:50 [E] 用户没有设置默认案场
145
+2018/09/16 19:46:15 [E] 用户没有设置默认案场
146
+2018/09/16 19:46:15 [E] 用户没有设置默认案场
147
+2018/09/16 20:00:54 [E] 用户没有设置默认案场
148
+2018/09/16 20:02:25 [E] 用户没有设置默认案场
149
+2018/09/16 20:04:08 [E] 用户没有设置默认案场
150
+2018/09/16 20:06:11 [E] 用户没有设置默认案场
151
+2018/09/16 20:06:17 [E] 用户没有设置默认案场
152
+2018/09/16 20:08:16 [E] 用户没有设置默认案场
153
+2018/09/16 20:13:41 [E] 用户没有设置默认案场
154
+2018/09/16 20:13:45 [E] 用户没有设置默认案场
155
+2018/09/16 20:13:45 [E] 用户没有设置默认案场
156
+2018/09/16 20:15:55 [E] 用户没有设置默认案场
157
+2018/09/16 20:15:55 [E] 用户没有设置默认案场
158
+2018/09/16 20:15:58 [E] 用户没有设置默认案场
159
+2018/09/16 20:15:58 [E] 用户没有设置默认案场
160
+2018/09/16 20:16:07 [E] 用户没有设置默认案场
161
+2018/09/16 20:16:07 [E] 用户没有设置默认案场
162
+2018/09/16 20:16:08 [E] 用户没有设置默认案场
163
+2018/09/16 20:16:31 [E] 用户没有设置默认案场
164
+2018/09/16 20:16:36 [E] 用户没有设置默认案场
165
+2018/09/16 20:16:36 [E] 用户没有设置默认案场
166
+2018/09/16 20:16:37 [E] 用户没有设置默认案场
167
+2018/09/16 20:18:25 [E] 用户没有设置默认案场
168
+2018/09/16 20:18:25 [E] 用户没有设置默认案场
169
+2018/09/16 20:22:33 [E] 用户没有设置默认案场
170
+2018/09/16 20:34:05 [E] 用户没有设置默认案场
171
+2018/09/16 20:36:10 [E] 用户没有设置默认案场
172
+2018/09/16 20:38:03 [E] 用户没有设置默认案场
173
+2018/09/16 20:38:03 [E] 用户没有设置默认案场
174
+2018/09/16 20:42:12 [E] 用户没有设置默认案场
175
+2018/09/16 20:42:12 [E] 用户没有设置默认案场
176
+2018/09/16 20:42:45 [E] 用户没有设置默认案场
177
+2018/09/16 20:42:45 [E] 用户没有设置默认案场
178
+2018/09/16 20:44:07 [E] 用户没有设置默认案场
179
+2018/09/16 20:44:07 [E] 用户没有设置默认案场
180
+2018/09/16 20:46:02 [E] 用户没有设置默认案场
181
+2018/09/16 20:46:20 [E] 用户没有设置默认案场
182
+2018/09/16 20:46:46 [E] 用户没有设置默认案场
183
+2018/09/16 20:47:04 [E] 用户没有设置默认案场
184
+2018/09/16 20:47:13 [E] 用户没有设置默认案场
185
+2018/09/16 20:47:18 [E] 用户没有设置默认案场
186
+2018/09/16 20:47:18 [E] 用户没有设置默认案场
187
+2018/09/16 20:48:47 [E] 用户没有设置默认案场
188
+2018/09/16 21:00:31 [E] 用户没有设置默认案场
189
+2018/09/16 21:00:31 [E] 用户没有设置默认案场
190
+2018/09/16 21:00:37 [E] 用户没有设置默认案场
191
+2018/09/16 21:00:37 [E] 用户没有设置默认案场
192
+2018/09/16 21:01:37 [E] 用户没有设置默认案场
193
+2018/09/16 21:01:37 [E] 用户没有设置默认案场
194
+2018/09/16 21:01:37 [E] 用户没有设置默认案场
195
+2018/09/16 21:01:41 [E] 用户没有设置默认案场
196
+2018/09/16 21:01:41 [E] 用户没有设置默认案场
197
+2018/09/16 21:01:41 [E] 用户没有设置默认案场
198
+2018/09/16 21:01:45 [E] 用户没有设置默认案场
199
+2018/09/16 21:01:45 [E] 用户没有设置默认案场
200
+2018/09/16 21:01:45 [E] 用户没有设置默认案场
201
+2018/09/16 21:05:12 [E] 用户没有设置默认案场
202
+2018/09/16 21:05:12 [E] 用户没有设置默认案场
203
+2018/09/16 21:05:19 [E] 用户没有设置默认案场
204
+2018/09/16 21:05:19 [E] 用户没有设置默认案场
205
+2018/09/16 21:10:23 [E] 用户没有设置默认案场
206
+2018/09/16 21:10:23 [E] 用户没有设置默认案场
207
+2018/09/16 21:10:26 [E] 用户没有设置默认案场
208
+2018/09/16 21:10:26 [E] 用户没有设置默认案场
209
+2018/09/16 21:15:42 [E] 用户没有设置默认案场
210
+2018/09/16 21:15:42 [E] 用户没有设置默认案场
211
+2018/09/16 21:16:22 [E] 用户没有设置默认案场
212
+2018/09/16 21:16:22 [E] 用户没有设置默认案场
213
+2018/09/16 21:16:35 [E] 用户没有设置默认案场
214
+2018/09/16 21:16:36 [E] 用户没有设置默认案场
215
+2018/09/16 21:21:26 [E] 用户没有设置默认案场
216
+2018/09/16 21:21:26 [E] 用户没有设置默认案场
217
+2018/09/16 21:21:35 [E] 用户没有设置默认案场
218
+2018/09/16 21:21:35 [E] 用户没有设置默认案场
219
+2018/09/16 21:23:58 [E] 用户没有设置默认案场
220
+2018/09/16 21:23:58 [E] 用户没有设置默认案场
221
+2018/09/16 21:24:05 [E] 用户没有设置默认案场
222
+2018/09/16 21:24:05 [E] 用户没有设置默认案场
223
+2018/09/16 21:29:34 [E] 用户没有设置默认案场
224
+2018/09/16 21:29:34 [E] 用户没有设置默认案场
225
+2018/09/16 21:29:38 [E] 用户没有设置默认案场
226
+2018/09/16 21:29:38 [E] 用户没有设置默认案场
227
+2018/09/16 21:31:47 [E] 用户没有设置默认案场
228
+2018/09/16 21:33:12 [E] 用户没有设置默认案场
229
+2018/09/16 21:33:12 [E] 用户没有设置默认案场
230
+2018/09/16 21:33:13 [E] 用户没有设置默认案场
231
+2018/09/16 21:33:15 [E] 用户没有设置默认案场
232
+2018/09/16 21:33:15 [E] 用户没有设置默认案场
233
+2018/09/16 21:33:16 [E] 用户没有设置默认案场
234
+2018/09/16 21:33:17 [E] 用户没有设置默认案场
235
+2018/09/16 21:33:18 [E] 用户没有设置默认案场
236
+2018/09/16 21:33:19 [E] 用户没有设置默认案场
237
+2018/09/16 21:33:20 [E] 用户没有设置默认案场
238
+2018/09/16 21:33:34 [E] 用户没有设置默认案场
239
+2018/09/16 21:33:35 [E] 用户没有设置默认案场
240
+2018/09/16 21:33:36 [E] 用户没有设置默认案场
241
+2018/09/16 21:33:36 [E] 用户没有设置默认案场
242
+2018/09/16 21:33:39 [E] 用户没有设置默认案场
243
+2018/09/16 21:33:39 [E] 用户没有设置默认案场
244
+2018/09/16 21:33:39 [E] 用户没有设置默认案场
245
+2018/09/16 21:33:39 [E] 用户没有设置默认案场
246
+2018/09/16 21:33:40 [E] 用户没有设置默认案场
247
+2018/09/16 21:33:40 [E] 用户没有设置默认案场
248
+2018/09/16 21:33:41 [E] 用户没有设置默认案场
249
+2018/09/16 21:33:41 [E] 用户没有设置默认案场
250
+2018/09/16 21:33:42 [E] 用户没有设置默认案场
251
+2018/09/16 21:33:43 [E] 用户没有设置默认案场
252
+2018/09/16 21:33:43 [E] 用户没有设置默认案场
253
+2018/09/16 21:33:43 [E] 用户没有设置默认案场
254
+2018/09/16 21:33:44 [E] 用户没有设置默认案场
255
+2018/09/16 21:33:44 [E] 用户没有设置默认案场
256
+2018/09/16 21:33:44 [E] 用户没有设置默认案场
257
+2018/09/16 21:33:52 [E] 用户没有设置默认案场
258
+2018/09/16 21:33:57 [E] 用户没有设置默认案场
259
+2018/09/16 21:37:56 [E] 用户没有设置默认案场
260
+2018/09/16 21:37:59 [E] 用户没有设置默认案场
261
+2018/09/16 21:39:29 [E] 用户没有设置默认案场
262
+2018/09/16 21:39:29 [E] 用户没有设置默认案场
263
+2018/09/16 21:40:26 [E] 用户没有设置默认案场
264
+2018/09/16 21:40:26 [E] 用户没有设置默认案场
265
+2018/09/16 21:41:01 [E] 用户没有设置默认案场
266
+2018/09/16 21:41:01 [E] 用户没有设置默认案场
267
+2018/09/16 21:41:11 [E] 用户没有设置默认案场
268
+2018/09/16 21:41:48 [E] 用户没有设置默认案场
269
+2018/09/16 21:41:59 [E] 用户没有设置默认案场
270
+2018/09/16 21:42:01 [E] 用户没有设置默认案场
271
+2018/09/16 21:47:50 [E] 用户没有设置默认案场
272
+2018/09/16 21:47:51 [E] 解密 Base64 字串失败: illegal base64 data at input byte 0
273
+2018/09/16 21:47:51 [E] 获取组织信息失败: 没有查询到机构信息
274
+2018/09/16 21:48:05 [E] 用户没有设置默认案场
275
+2018/09/16 21:48:05 [E] 用户没有设置默认案场
276
+2018/09/16 21:48:09 [E] 解密 Base64 字串失败: illegal base64 data at input byte 0
277
+2018/09/16 21:48:09 [E] 获取组织信息失败: 没有查询到机构信息
278
+2018/09/16 21:49:17 [E] 用户没有设置默认案场
279
+2018/09/16 21:49:17 [E] 用户没有设置默认案场
280
+2018/09/16 21:51:16 [E] 用户没有设置默认案场
281
+2018/09/16 21:51:16 [E] 用户没有设置默认案场
282
+2018/09/16 21:52:15 [E] 用户没有设置默认案场
283
+2018/09/16 21:52:15 [E] 用户没有设置默认案场
284
+2018/09/16 21:58:57 [E] 用户没有设置默认案场
285
+2018/09/16 21:58:57 [E] 用户没有设置默认案场
286
+2018/09/16 21:59:01 [E] 用户没有设置默认案场
287
+2018/09/16 21:59:01 [E] 用户没有设置默认案场
288
+2018/09/16 22:01:01 [E] 用户没有设置默认案场
289
+2018/09/16 22:01:10 [E] 用户没有设置默认案场
290
+2018/09/16 22:02:34 [E] 用户没有设置默认案场
291
+2018/09/16 22:02:34 [E] 用户没有设置默认案场
292
+2018/09/16 22:03:01 [E] 用户没有设置默认案场
293
+2018/09/16 22:03:05 [E] 用户没有设置默认案场
294
+2018/09/16 22:03:05 [E] 用户没有设置默认案场
295
+2018/09/16 22:07:01 [E] 用户没有设置默认案场
296
+2018/09/16 22:07:01 [E] 用户没有设置默认案场
297
+2018/09/16 22:07:05 [E] 用户没有设置默认案场
298
+2018/09/16 22:07:05 [E] 用户没有设置默认案场
299
+2018/09/16 22:12:51 [E] 用户没有设置默认案场
300
+2018/09/16 22:18:09 [E] 用户没有设置默认案场
301
+2018/09/16 22:18:13 [E] 用户没有设置默认案场
302
+2018/09/16 22:18:13 [E] 用户没有设置默认案场
303
+2018/09/16 22:18:17 [E] 用户没有设置默认案场
304
+2018/09/16 22:18:17 [E] 用户没有设置默认案场
305
+2018/09/16 22:19:23 [E] 用户没有设置默认案场
306
+2018/09/16 22:19:36 [E] 用户没有设置默认案场
307
+2018/09/16 22:20:28 [E] 用户没有设置默认案场
308
+2018/09/16 22:20:32 [E] 用户没有设置默认案场
309
+2018/09/16 22:20:33 [E] 用户没有设置默认案场
310
+2018/09/16 22:26:31 [E] 用户没有设置默认案场
311
+2018/09/16 22:26:54 [E] 用户没有设置默认案场
312
+2018/09/16 22:26:54 [E] 用户没有设置默认案场
313
+2018/09/16 22:27:39 [E] 用户没有设置默认案场
314
+2018/09/16 22:27:48 [E] 用户没有设置默认案场
315
+2018/09/16 22:27:49 [E] 用户没有设置默认案场
316
+2018/09/16 22:28:15 [E] 用户没有设置默认案场
317
+2018/09/16 22:28:15 [E] 用户没有设置默认案场
318
+2018/09/16 22:28:15 [E] 用户没有设置默认案场
319
+2018/09/16 22:28:57 [E] 用户没有设置默认案场
320
+2018/09/16 22:28:57 [E] 用户没有设置默认案场
321
+2018/09/16 22:29:11 [E] 用户没有设置默认案场
322
+2018/09/16 22:29:12 [E] 用户没有设置默认案场
323
+2018/09/16 22:29:36 [E] 用户没有设置默认案场
324
+2018/09/16 22:29:36 [E] 用户没有设置默认案场
325
+2018/09/16 22:29:36 [E] 用户没有设置默认案场
326
+2018/09/16 22:30:14 [E] 用户没有设置默认案场
327
+2018/09/16 22:30:14 [E] 用户没有设置默认案场
328
+2018/09/16 22:30:18 [E] 用户没有设置默认案场
329
+2018/09/16 22:30:55 [E] 用户没有设置默认案场
330
+2018/09/16 22:30:55 [E] 用户没有设置默认案场
331
+2018/09/16 22:31:13 [E] 用户没有设置默认案场
332
+2018/09/16 22:31:15 [E] 用户没有设置默认案场
333
+2018/09/16 22:31:15 [E] 用户没有设置默认案场
334
+2018/09/16 22:31:57 [E] 用户没有设置默认案场
335
+2018/09/16 22:31:57 [E] 用户没有设置默认案场
336
+2018/09/16 22:32:21 [E] 用户没有设置默认案场
337
+2018/09/16 22:32:21 [E] 用户没有设置默认案场
338
+2018/09/16 22:32:22 [E] 用户没有设置默认案场
339
+2018/09/16 22:32:27 [E] 用户没有设置默认案场
340
+2018/09/16 22:32:56 [E] 用户没有设置默认案场
341
+2018/09/16 22:32:56 [E] 用户没有设置默认案场
342
+2018/09/16 22:33:10 [E] 用户没有设置默认案场
343
+2018/09/16 22:33:16 [E] 用户没有设置默认案场
344
+2018/09/16 22:33:58 [E] 用户没有设置默认案场

+ 17
- 36
models/bodycheck/bodycheck.go Bestand weergeven

@@ -1,10 +1,10 @@
1 1
 package bodycheck
2 2
 
3 3
 import (
4
+	"spaceofcheng/services/models"
4 5
 	"spaceofcheng/services/models/model"
5 6
 	"spaceofcheng/services/utils"
6 7
 	"strconv"
7
-	"time"
8 8
 
9 9
 	"github.com/go-xorm/xorm"
10 10
 )
@@ -24,10 +24,10 @@ func NewDAO(ctx *utils.Context) *DAO {
24 24
 }
25 25
 
26 26
 // GetBodyCheckByUser 根据用户信息获取体检信息
27
-func (m *DAO) GetBodyCheckByUser(userID int) ([]model.TaBodyCheck, error) {
27
+func (m *DAO) GetBodyCheckByUser(userID string) ([]model.TaBodyCheck, error) {
28 28
 	var bodychecks []model.TaBodyCheck
29 29
 	var err error
30
-	err = m.db.Where("user_id=?", userID).And("status=?", 1).Desc("create_date").Find(&bodychecks)
30
+	err = m.db.Where("user_id=?", userID).And("status=?", models.STATUS_NORMAL).Desc("create_date").Find(&bodychecks)
31 31
 	return bodychecks, err
32 32
 }
33 33
 
@@ -39,9 +39,9 @@ func (m *DAO) GetCheckSpecs() ([]model.TdCheckSpec, error) {
39 39
 }
40 40
 
41 41
 // GetCheckByUserAndEquipmentID 根据用户与设备ID获取体检信息
42
-func (m *DAO) GetCheckByUserAndEquipmentID(userID int, EquipmentID string) (*model.TaBodyCheck, error) {
42
+func (m *DAO) GetCheckByUserAndEquipmentID(userID string, EquipmentID string) (*model.TaBodyCheck, error) {
43 43
 	var check []model.TaBodyCheck
44
-	err := m.db.Where("user_id=?", userID).And("equipment_id=?", EquipmentID).And("status=?", 1).Desc("create_date").Find(&check)
44
+	err := m.db.Where("user_id=?", userID).And("equipment_id=?", EquipmentID).And("status=?", models.STATUS_NORMAL).Desc("create_date").Find(&check)
45 45
 	if err != nil {
46 46
 		return nil, err
47 47
 	}
@@ -53,41 +53,21 @@ func (m *DAO) GetCheckByUserAndEquipmentID(userID int, EquipmentID string) (*mod
53 53
 
54 54
 // SaveBodyCheckInfo 用户体检信息新增
55 55
 func (m *DAO) SaveBodyCheckInfo(checkNew model.TaBodyCheck) (*model.TaBodyCheck, error) {
56
-	checkNew.Status = 1
56
+	checkNew.Status = models.STATUS_NORMAL
57
+	checkNew.Id = utils.GetGUID()
57 58
 	// checkNew.CreateDate = time.Now()
58 59
 	_, err := m.db.Insert(&checkNew)
59 60
 	return &checkNew, err
60 61
 }
61 62
 
62
-// SaveUser 新增用户信息
63
-func (m *DAO) SaveUser(user model.TaCustomer) (*model.TaCustomer, error) {
64
-	user.CreateDate = time.Now()
65
-	_, err := m.db.Insert(&user)
66
-	return &user, err
67
-}
68
-
69 63
 // GetCaseEquipment 获取设备案场信息
70 64
 func (m *DAO) GetCaseEquipment(EquipmentID string) (*model.TaCaseEquipment, error) {
71 65
 	var caseEquipment model.TaCaseEquipment
72 66
 
73
-	_, err := m.db.Where("equipment_id=?", EquipmentID).And("status=?", 1).Get(&caseEquipment)
67
+	_, err := m.db.Where("equipment_id=?", EquipmentID).And("status=?", models.STATUS_NORMAL).Get(&caseEquipment)
74 68
 	return &caseEquipment, err
75 69
 }
76 70
 
77
-// GetUserByOpenID 根据openid获取用户信息
78
-func (m *DAO) GetUserByOpenID(openid string) (*model.TaCustomer, error) {
79
-	var user model.TaCustomer
80
-	_, err := m.db.Where("open_id=?", openid).Get(&user)
81
-	return &user, err
82
-}
83
-
84
-// GetCustomerByID 根据客户ID 获取用户信息
85
-func (m *DAO) GetCustomerByID(id int) (*model.TaCustomer, error) {
86
-	var cust model.TaCustomer
87
-	_, err := m.db.Where("id=?", id).Get(&cust)
88
-	return &cust, err
89
-}
90
-
91 71
 type Presentation struct {
92 72
 	model.TaPresentation `xorm:"extends"`
93 73
 	TypeName             string
@@ -95,9 +75,9 @@ type Presentation struct {
95 75
 }
96 76
 
97 77
 // GetPresentationByCheckID 根据体检ID获取项目信息
98
-func (m *DAO) GetPresentationByCheckID(checkID int) ([]Presentation, error) {
78
+func (m *DAO) GetPresentationByCheckID(checkID string) ([]Presentation, error) {
99 79
 	var presentations []Presentation
100
-	sql := `select a.*,b.type_name from ta_presentation a inner join td_check_type b on a.check_type=b.id where a.check_id=` + strconv.Itoa(checkID)
80
+	sql := `select a.*,b.type_name from ta_presentation a inner join td_check_type b on a.check_type=b.id where a.check_id='` + checkID + `'`
101 81
 
102 82
 	err := m.db.Sql(sql).Find(&presentations)
103 83
 	if err != nil {
@@ -117,21 +97,22 @@ func (m *DAO) GetPresentationByCheckID(checkID int) ([]Presentation, error) {
117 97
 }
118 98
 
119 99
 // GetDetailsByPresentID 根据项目ID获取详情
120
-func (m *DAO) GetDetailsByPresentID(ID int) ([]model.TaPresentationDetail, error) {
100
+func (m *DAO) GetDetailsByPresentID(ID string) ([]model.TaPresentationDetail, error) {
121 101
 	var details []model.TaPresentationDetail
122 102
 	err := m.db.Where("presentation_id=?", ID).Find(&details)
123 103
 	return details, err
124 104
 }
125 105
 
126 106
 // GetPresentation 获取体检项目信息
127
-func (m *DAO) GetPresentation(checkID, typeID int) (*model.TaPresentation, error) {
107
+func (m *DAO) GetPresentation(checkID string, typeID int) (*model.TaPresentation, error) {
128 108
 	var presentation model.TaPresentation
129
-	_, err := m.db.Where("check_id=?", checkID).And("check_type=?", typeID).Get(&presentation)
109
+	_, err := m.db.Where("check_id=?", checkID).And("check_type='" + strconv.Itoa(typeID) + "'").Get(&presentation)
130 110
 	return &presentation, err
131 111
 }
132 112
 
133 113
 // SavePresentation 新增体检项目信息
134 114
 func (m *DAO) SavePresentation(info model.TaPresentation) (*model.TaPresentation, error) {
115
+	info.Id = utils.GetGUID()
135 116
 	_, err := m.db.Insert(&info)
136 117
 	return &info, err
137 118
 }
@@ -154,8 +135,8 @@ func (m *DAO) SavePresentationDetail(details []model.TaPresentationDetail) error
154 135
 }
155 136
 
156 137
 // DeletePresentionDetail 根据项目ID删除明细信息
157
-func (m *DAO) DeletePresentionDetail(ID int) error {
158
-	sql := "delete from ta_presentation_detail where presentation_id=" + strconv.Itoa(ID)
159
-	_, err := m.db.Exec(sql)
138
+func (m *DAO) DeletePresentionDetail(ID string) error {
139
+	sql := "delete from ta_presentation_detail where presentation_id=?"
140
+	_, err := m.db.Exec(sql, ID)
160 141
 	return err
161 142
 }

+ 4
- 4
models/model/ta_body_check.go Bestand weergeven

@@ -5,11 +5,11 @@ import (
5 5
 )
6 6
 
7 7
 type TaBodyCheck struct {
8
-	Id          int       `xorm:"not null pk autoincr INT(11)"`
9
-	UserId      int       `xorm:"not null INT(11)"`
10
-	EquipmentId string    `xorm:"not null VARCHAR(100)"`
8
+	Id          string    `xorm:"not null pk VARCHAR(64)"`
9
+	UserId      string    `xorm:"VARCHAR(64)"`
10
+	EquipmentId string    `xorm:"not null VARCHAR(200)"`
11 11
 	CreateDate  time.Time `xorm:"not null DATETIME"`
12 12
 	Status      int       `xorm:"not null comment('1为正常') INT(11)"`
13
-	CaseId      int       `xorm:"INT(11)"`
13
+	CaseId      string    `xorm:"VARCHAR(64)"`
14 14
 	ReportUrl   string    `xorm:"TEXT"`
15 15
 }

+ 2
- 2
models/model/ta_case_equipment.go Bestand weergeven

@@ -5,8 +5,8 @@ import (
5 5
 )
6 6
 
7 7
 type TaCaseEquipment struct {
8
-	Id          int       `xorm:"not null pk autoincr INT(11)"`
9
-	CaseId      int       `xorm:"not null INT(11)"`
8
+	Id          string    `xorm:"not null pk VARCHAR(64)"`
9
+	CaseId      string    `xorm:"not null pk VARCHAR(64)"`
10 10
 	EquipmentId string    `xorm:"VARCHAR(200)"`
11 11
 	Status      int       `xorm:"INT(11)"`
12 12
 	CreateDate  time.Time `xorm:"DATETIME"`

+ 2
- 2
models/model/ta_presentation.go Bestand weergeven

@@ -5,8 +5,8 @@ import (
5 5
 )
6 6
 
7 7
 type TaPresentation struct {
8
-	Id          int       `xorm:"not null pk autoincr INT(11)"`
9
-	CheckId     int       `xorm:"not null INT(11)"`
8
+	Id          string    `xorm:"not null pk VARCHAR(64)"`
9
+	CheckId     string    `xorm:"not null pk VARCHAR(64)"`
10 10
 	CheckType   int       `xorm:"SMALLINT(6)"`
11 11
 	CheckDate   time.Time `xorm:"DATETIME"`
12 12
 	CheckResult string    `xorm:"TEXT"`

+ 2
- 2
models/model/ta_presentation_detail.go Bestand weergeven

@@ -1,8 +1,8 @@
1 1
 package model
2 2
 
3 3
 type TaPresentationDetail struct {
4
-	Id             int    `xorm:"not null pk autoincr INT(11)"`
5
-	PresentationId int    `xorm:"not null INT(11)"`
4
+	Id             string `xorm:"not null pk VARCHAR(64)"`
5
+	PresentationId string `xorm:"not null pk VARCHAR(64)"`
6 6
 	CheckName      string `xorm:"VARCHAR(50)"`
7 7
 	CheckVal       string `xorm:"VARCHAR(500)"`
8 8
 	SpecName       string `xorm:"VARCHAR(50)"`

+ 1
- 1
models/model/td_check_spec.go Bestand weergeven

@@ -1,7 +1,7 @@
1 1
 package model
2 2
 
3 3
 type TdCheckSpec struct {
4
-	Id       int    `xorm:"not null pk autoincr INT(11)"`
4
+	Id       string `xorm:"not null pk VARCHAR(64)"`
5 5
 	Name     string `xorm:"not null VARCHAR(50)"`
6 6
 	SortName string `xorm:"not null VARCHAR(50)"`
7 7
 	Standard string `xorm:"VARCHAR(50)"`

+ 1
- 1
models/model/td_check_type.go Bestand weergeven

@@ -1,6 +1,6 @@
1 1
 package model
2 2
 
3 3
 type TdCheckType struct {
4
-	Id       int    `xorm:"not null pk autoincr INT(11)"`
4
+	Id       string `xorm:"not null pk VARCHAR(64)"`
5 5
 	TypeName string `xorm:"VARCHAR(50)"`
6 6
 }

+ 7
- 7
models/statistics/cardcoupon.go Bestand weergeven

@@ -105,7 +105,7 @@ func (m *StatisticsDAO) CardCouponStatistics(caseids, ctype, name string, page,
105 105
 }
106 106
 
107 107
 // CardCouponStatisticsCount 获取总数
108
-func (m *StatisticsDAO) CardCouponStatisticsCount(caseids, ctype, name string) (int, error) {
108
+func (m *StatisticsDAO) CardCouponStatisticsCount(caseids, ctype, name string) ([]CardCouponStatistics, error) {
109 109
 	var cardCoupons []CardCouponStatistics
110 110
 	couponsql := `SELECT
111 111
 		b.case_name,
@@ -175,7 +175,7 @@ func (m *StatisticsDAO) CardCouponStatisticsCount(caseids, ctype, name string) (
175 175
 		// 	sql = "select * from (" + gymcardsql + ") tab"
176 176
 		// 	break
177 177
 		default:
178
-			return 0, errors.New("类型不正确")
178
+			return cardCoupons, errors.New("类型不正确")
179 179
 		}
180 180
 	} else {
181 181
 		sql = "select * from (" + cardsql + " union " + couponsql + ") tab"
@@ -185,7 +185,7 @@ func (m *StatisticsDAO) CardCouponStatisticsCount(caseids, ctype, name string) (
185 185
 		sql = sql + ` where c_name like '%` + name + `%'`
186 186
 	}
187 187
 	err := m.db.Sql(sql).Find(&cardCoupons)
188
-	return len(cardCoupons), err
188
+	return cardCoupons, err
189 189
 }
190 190
 
191 191
 // CardCouponUsedStatistics 卡券使用情况
@@ -308,7 +308,7 @@ func (m *StatisticsDAO) CardCouponUsedStatistics(caseids, tel, name, receivetype
308 308
 }
309 309
 
310 310
 // CardCouponUsedCountStatistics 获取卡券使用情况统计
311
-func (m *StatisticsDAO) CardCouponUsedCountStatistics(caseids, tel, name, receivetype, begindate, enddate, status string) (int, error) {
311
+func (m *StatisticsDAO) CardCouponUsedCountStatistics(caseids, tel, name, receivetype, begindate, enddate, status string) ([]CardCouponUsedStatistics, error) {
312 312
 	var cardCoupons []CardCouponUsedStatistics
313 313
 	cardsql := `SELECT
314 314
 							d.case_name,
@@ -402,7 +402,7 @@ func (m *StatisticsDAO) CardCouponUsedCountStatistics(caseids, tel, name, receiv
402 402
 		sql = sql + ` and DATE_FORMAT(tab.receive_date, '%Y-%m-%d') <= '` + enddate + `'`
403 403
 	}
404 404
 	err := m.db.Sql(sql).Find(&cardCoupons)
405
-	return len(cardCoupons), err
405
+	return cardCoupons, err
406 406
 }
407 407
 
408 408
 // CardCouponVerifyStatistics 卡券使用情况
@@ -481,7 +481,7 @@ func (m *StatisticsDAO) CardCouponVerifyStatistics(caseids, tel, name, status st
481 481
 }
482 482
 
483 483
 // CardCouponVerifyStatisticsCount 获取卡券核销情况数量统计
484
-func (m *StatisticsDAO) CardCouponVerifyStatisticsCount(caseids, tel, name, status string) (int, error) {
484
+func (m *StatisticsDAO) CardCouponVerifyStatisticsCount(caseids, tel, name, status string) ([]CardCouponVerifyStatistics, error) {
485 485
 	var cardCoupons []CardCouponVerifyStatistics
486 486
 	sql := `SELECT
487 487
 							c.case_id,
@@ -535,5 +535,5 @@ func (m *StatisticsDAO) CardCouponVerifyStatisticsCount(caseids, tel, name, stat
535 535
 		}
536 536
 	}
537 537
 	err := m.db.Sql(sql).Find(&cardCoupons)
538
-	return len(cardCoupons), err
538
+	return cardCoupons, err
539 539
 }

+ 4
- 4
models/statistics/course.go Bestand weergeven

@@ -63,7 +63,7 @@ func (m *StatisticsDAO) GetCourseOrdersStatistics(typeid, caseids, name, beginda
63 63
 }
64 64
 
65 65
 // GetCourseOrdersStatisticsCount 获取课程订单统计数量
66
-func (m *StatisticsDAO) GetCourseOrdersStatisticsCount(typeid, caseids, name, begindate, enddate string) (int, error) {
66
+func (m *StatisticsDAO) GetCourseOrdersStatisticsCount(typeid, caseids, name, begindate, enddate string) ([]CourseOrdersStatistics, error) {
67 67
 	var courseOrders []CourseOrdersStatistics
68 68
 	sql := `SELECT
69 69
 					a.orders_id,
@@ -98,7 +98,7 @@ func (m *StatisticsDAO) GetCourseOrdersStatisticsCount(typeid, caseids, name, be
98 98
 	}
99 99
 
100 100
 	err := m.db.Sql(sql).Find(&courseOrders)
101
-	return len(courseOrders), err
101
+	return courseOrders, err
102 102
 }
103 103
 
104 104
 // CourseStatistics 课程统计数据
@@ -166,7 +166,7 @@ func (m *StatisticsDAO) GetCourseStatistics(typeid, caseids, name string, page,
166 166
 }
167 167
 
168 168
 // GetCourseStatisticsCount 获取课程统计信息数量
169
-func (m *StatisticsDAO) GetCourseStatisticsCount(typeid, caseids, name string) (int, error) {
169
+func (m *StatisticsDAO) GetCourseStatisticsCount(typeid, caseids, name string) ([]CourseStatistics, error) {
170 170
 	var courses []CourseStatistics
171 171
 	sql := `SELECT
172 172
 					a.course_id,
@@ -188,5 +188,5 @@ func (m *StatisticsDAO) GetCourseStatisticsCount(typeid, caseids, name string) (
188 188
 		sql = sql + ` and a.course_name like '%` + name + `%'`
189 189
 	}
190 190
 	err := m.db.Sql(sql).Find(&courses)
191
-	return len(courses), err
191
+	return courses, err
192 192
 }

+ 9
- 6
models/statistics/goods.go Bestand weergeven

@@ -63,7 +63,7 @@ func (m *StatisticsDAO) GetGoodsStatistics(caseids, typeid, name string, page, p
63 63
 }
64 64
 
65 65
 // GetGoodsStatisticsCount 获取总数
66
-func (m *StatisticsDAO) GetGoodsStatisticsCount(caseids, typeid, name string) (int, error) {
66
+func (m *StatisticsDAO) GetGoodsStatisticsCount(caseids, typeid, name string) ([]GoodsStatistics, error) {
67 67
 	var goods []GoodsStatistics
68 68
 	sql := `SELECT
69 69
 					e.case_name,
@@ -103,7 +103,7 @@ func (m *StatisticsDAO) GetGoodsStatisticsCount(caseids, typeid, name string) (i
103 103
 					c.type_name,
104 104
 					b.price`
105 105
 	err := m.db.Sql(sql).Find(&goods)
106
-	return len(goods), err
106
+	return goods, err
107 107
 }
108 108
 
109 109
 // GoodsOrdersStatistics 商品订单统计信息
@@ -120,6 +120,7 @@ type GoodsOrdersStatistics struct {
120 120
 	CustomerName string
121 121
 	Phone        string
122 122
 	Name         string
123
+	Remark       string
123 124
 	Details      []model.TaGoodsOrdersDetail
124 125
 }
125 126
 
@@ -138,7 +139,8 @@ func (m *StatisticsDAO) GetGoodsOrderStatistics(status, usertype, caseids, begin
138 139
 						a.table_no,
139 140
 						c.customer_name,
140 141
 						c. NAME,
141
-						c.phone
142
+						c.phone,
143
+						a.remark
142 144
 					FROM
143 145
 						ta_goods_orders a
144 146
 					INNER JOIN ta_customer b ON a.user_id = b.customer_id
@@ -176,7 +178,7 @@ func (m *StatisticsDAO) GetGoodsOrderStatistics(status, usertype, caseids, begin
176 178
 }
177 179
 
178 180
 // GetGoodsOrderStatisticsCount 获取商品订单Count
179
-func (m *StatisticsDAO) GetGoodsOrderStatisticsCount(status, usertype, caseids, begindate, enddate string) (int, error) {
181
+func (m *StatisticsDAO) GetGoodsOrderStatisticsCount(status, usertype, caseids, begindate, enddate string) ([]GoodsOrdersStatistics, error) {
180 182
 	var orders []GoodsOrdersStatistics
181 183
 	sql := `SELECT
182 184
 						a.orders_id,
@@ -190,7 +192,8 @@ func (m *StatisticsDAO) GetGoodsOrderStatisticsCount(status, usertype, caseids,
190 192
 						a.table_no,
191 193
 						c.customer_name,
192 194
 						c. NAME,
193
-						c.phone
195
+						c.phone,
196
+						a.remark
194 197
 					FROM
195 198
 						ta_goods_orders a
196 199
 					INNER JOIN ta_customer b ON a.user_id = b.customer_id
@@ -212,5 +215,5 @@ func (m *StatisticsDAO) GetGoodsOrderStatisticsCount(status, usertype, caseids,
212 215
 	}
213 216
 
214 217
 	err := m.db.Sql(sql).Find(&orders)
215
-	return len(orders), err
218
+	return orders, err
216 219
 }

+ 7
- 0
routers/common.go Bestand weergeven

@@ -280,11 +280,18 @@ func getCommonRoutes() beego.LinkNamespace {
280 280
 
281 281
 		// 统计类
282 282
 		beego.NSRouter("/statistics/goods", &statistics.StatisticsController{}, "get:GetGoodsStatistics"),
283
+		beego.NSRouter("/statistics/goods/excel", &statistics.StatisticsController{}, "get:GetGoodsStatisticsExcel"),
283 284
 		beego.NSRouter("/statistics/goodsorders", &statistics.StatisticsController{}, "get:GetGoodsOrdersStatistics"),
285
+		beego.NSRouter("/statistics/goodsorders/excel", &statistics.StatisticsController{}, "get:GetGoodsOrdersStatisticsExcel"),
284 286
 		beego.NSRouter("/statistics/courseorders", &statistics.StatisticsController{}, "get:GetCourseOrdersStatistics"),
287
+		beego.NSRouter("/statistics/courseorders/excel", &statistics.StatisticsController{}, "get:GetCourseOrdersStatisticsExcel"),
285 288
 		beego.NSRouter("/statistics/courses", &statistics.StatisticsController{}, "get:GetCourseStatistics"),
289
+		beego.NSRouter("/statistics/courses/excel", &statistics.StatisticsController{}, "get:GetCourseStatisticsExcel"),
286 290
 		beego.NSRouter("/statistics/cardcoupon", &statistics.StatisticsController{}, "get:CardCouponStatistics"),
291
+		beego.NSRouter("/statistics/cardcoupon/excel", &statistics.StatisticsController{}, "get:CardCouponStatisticsExcel"),
287 292
 		beego.NSRouter("/statistics/cardcouponused", &statistics.StatisticsController{}, "get:CardCouponUsedStatistics"),
293
+		beego.NSRouter("/statistics/cardcouponused/excel", &statistics.StatisticsController{}, "get:CardCouponUsedStatisticsExcel"),
288 294
 		beego.NSRouter("/statistics/cardcouponverify", &statistics.StatisticsController{}, "get:CardCouponVerifyStatistics"),
295
+		beego.NSRouter("/statistics/cardcouponverify/excel", &statistics.StatisticsController{}, "get:CardCouponVerifyStatisticsExcel"),
289 296
 	)
290 297
 }

+ 4
- 0
routers/guest.go Bestand weergeven

@@ -1,6 +1,7 @@
1 1
 package routers
2 2
 
3 3
 import (
4
+	"cdkj-check/controllers/bodycheck"
4 5
 	"spaceofcheng/services/controllers"
5 6
 	"spaceofcheng/services/controllers/cases"
6 7
 	"spaceofcheng/services/controllers/course"
@@ -57,5 +58,8 @@ func getGuestRoutes() beego.LinkNamespace {
57 58
 		beego.NSRouter("/wechat/mini/decodedata", &controllers.BaseController{}, "post:DecodeMiniData"),
58 59
 
59 60
 		beego.NSRouter("/websocket/:grps/:id", &controllers.BaseController{}, "get:Ws"),
61
+
62
+		// 体检参数接收
63
+		beego.NSRouter("/PostCheckResult", &bodycheck.BodyCheckController{}, "post:PostCheckResult"),
60 64
 	)
61 65
 }

+ 4
- 0
routers/wechat.go Bestand weergeven

@@ -1,6 +1,7 @@
1 1
 package routers
2 2
 
3 3
 import (
4
+	"cdkj-check/controllers/bodycheck"
4 5
 	"spaceofcheng/services/controllers/card"
5 6
 	"spaceofcheng/services/controllers/coupon"
6 7
 	"spaceofcheng/services/controllers/course"
@@ -69,5 +70,8 @@ func getWechatRoutes() beego.LinkNamespace {
69 70
 		beego.NSRouter("/card/detail/:id", &card.CardController{}, "get:GetCardWithCustomer"),
70 71
 		beego.NSRouter("/card/:id", &card.CardController{}, "post:ReceiveCard"),
71 72
 		beego.NSRouter("/channel/card/:id", &card.CardController{}, "post:ChannelReceiveCard"),
73
+
74
+		// 体检
75
+		beego.NSRouter("/GetCheckByUser", &bodycheck.BodyCheckController{}, "get:GetCheckByUser"),
72 76
 	)
73 77
 }

+ 176
- 92
service/bodycheck/bodycheck.go Bestand weergeven

@@ -3,130 +3,214 @@ package bodycheck
3 3
 import (
4 4
 	"errors"
5 5
 	"spaceofcheng/services/models/bodycheck"
6
+	"spaceofcheng/services/models/customer"
6 7
 	"spaceofcheng/services/models/model"
7 8
 	"spaceofcheng/services/utils"
9
+	"strconv"
10
+	"time"
11
+
12
+	"github.com/astaxie/beego"
13
+	"github.com/astaxie/beego/config"
14
+	"github.com/zjxpcyc/wechat/wx"
8 15
 )
9 16
 
10
-// BodycheckServ 系统处理
11
-type BodycheckServ struct {
12
-	ctx *utils.Context
13
-	dao *bodycheck.DAO
17
+// BodyCheckServ 系统处理
18
+type BodyCheckServ struct {
19
+	ctx         *utils.Context
20
+	dao         *bodycheck.DAO
21
+	customerdao *customer.CustomerDAO
14 22
 }
15 23
 
16
-// NewBodycheckServ 初始化
17
-func NewBodycheckServ(ctx *utils.Context) *BodycheckServ {
18
-	return &BodycheckServ{
19
-		ctx: ctx,
20
-		dao: bodycheck.NewDAO(ctx),
24
+// NewBodyCheckServ 初始化
25
+func NewBodyCheckServ(ctx *utils.Context) *BodyCheckServ {
26
+	return &BodyCheckServ{
27
+		ctx:         ctx,
28
+		dao:         bodycheck.NewDAO(ctx),
29
+		customerdao: customer.NewCustomerDAO(ctx),
21 30
 	}
22 31
 }
23
-func (s *BodycheckServ) GetBodyCheckByUser(userID int) ([]model.TaBodyCheck, error) {
24
-	bodychecks, err := s.dao.GetBodyCheckByUser(userID)
25
-	if err != nil {
26
-		utils.LogError("查询用户体检信息失败: " + err.Error())
27
-		return nil, errors.New("查询用户体检信息失败")
28
-	}
29
-	return bodychecks, nil
30
-}
31
-func (s *BodycheckServ) GetCheckSpecs() ([]model.TdCheckSpec, error) {
32
-	specs, err := s.dao.GetCheckSpecs()
32
+
33
+// GetCheckByUser 根据用户获取体检报告
34
+func (s *BodyCheckServ) GetCheckByUser() (map[string]interface{}, error) {
35
+	customer := s.ctx.Get("customer").(model.TaCustomer)
36
+	bodyCheck, err := s.dao.GetBodyCheckByUser(customer.CustomerId)
33 37
 	if err != nil {
34
-		utils.LogError("获取项目指标信息失败: " + err.Error())
35
-		return nil, errors.New("获取项目指标信息失败")
38
+		return nil, err
36 39
 	}
37
-	return specs, nil
38
-}
39
-func (s *BodycheckServ) GetCheckByUserAndEquipmentID(userID int, EquipmentID string) (*model.TaBodyCheck, error) {
40
-	check, err := s.dao.GetCheckByUserAndEquipmentID(userID, EquipmentID)
41
-	if err != nil {
42
-		utils.LogError("根据用户与设备ID获取体检信息失败: " + err.Error())
43
-		return nil, errors.New("根据用户与设备ID获取体检信息失败")
40
+	if len(bodyCheck) == 0 {
41
+		return nil, errors.New("没有查询到数据")
44 42
 	}
45
-	return check, nil
46
-}
47
-func (s *BodycheckServ) SaveBodyCheckInfo(checkNew model.TaBodyCheck) (*model.TaBodyCheck, error) {
48
-	checkNews, err := s.dao.SaveBodyCheckInfo(checkNew)
43
+	presentations, err := s.dao.GetPresentationByCheckID(bodyCheck[0].Id)
49 44
 	if err != nil {
50
-		utils.LogError("用户体检信息新增失败: " + err.Error())
51
-		return nil, errors.New("用户体检信息新增失败")
45
+		return nil, err
52 46
 	}
53
-	return checkNews, nil
47
+
48
+	return map[string]interface{}{
49
+		"Message":  presentations,
50
+		"Info":     bodyCheck,
51
+		"UserInfo": customer,
52
+	}, nil
54 53
 }
55
-func (s *BodycheckServ) GetCaseEquipment(EquipmentID string) (*model.TaCaseEquipment, error) {
56
-	caseEquipment, err := s.dao.GetCaseEquipment(EquipmentID)
57
-	if err != nil {
58
-		utils.LogError("获取设备案场信息失败: " + err.Error())
59
-		return nil, errors.New("获取设备案场信息失败")
54
+
55
+// PostCheckResult 测量结果返回
56
+func (s *BodyCheckServ) PostCheckResult(formVal map[string]interface{}) error {
57
+	type CheckResult struct {
58
+		WechatAccount string
59
+		EquipmentId   string
60
+		CheckType     int
61
+		CheckDate     time.Time
62
+		CheckResult   string
63
+		ReportUrl     string
64
+		HMSReportUrl  string
60 65
 	}
61
-	return caseEquipment, nil
62
-}
63
-func (s *BodycheckServ) GetUserByOpenID(openid string) (*model.TaCustomer, error) {
64
-	customer, err := s.dao.GetUserByOpenID(openid)
66
+	var result = CheckResult{}
67
+
68
+	result.EquipmentId = formVal["EquipmentId"].(string)
69
+	result.WechatAccount = formVal["WechatAccount"].(string)
70
+	// result.CheckResult = formVal["CheckResult"].(string)
71
+	result.CheckResult = ""
72
+	result.ReportUrl = formVal["ReportUrl"].(string)
73
+	result.HMSReportUrl = formVal["HMSReportUrl"].(string)
74
+	result.CheckType = int(formVal["CheckType"].(float64))
75
+
76
+	var err error
77
+	loc, _ := time.LoadLocation("Local")
78
+	result.CheckDate, err = time.ParseInLocation("2006-01-02 15:04:05", formVal["CheckDate"].(string), loc)
65 79
 	if err != nil {
66
-		utils.LogError("根据openid获取用户信息失败: " + err.Error())
67
-		return nil, errors.New("根据openid获取用户信息失败")
80
+		utils.LogError("参数错误:", err)
81
+		return errors.New("参数错误")
68 82
 	}
69
-	return customer, nil
70
-}
71 83
 
72
-func (s *BodycheckServ) GetPresentationByCheckID(checkID int) ([]bodycheck.Presentation, error) {
73
-	presentations, err := s.dao.GetPresentationByCheckID(checkID)
84
+	openid := result.WechatAccount
85
+	customer, err := s.customerdao.GetCustWithWXByOpenID(openid)
74 86
 	if err != nil {
75
-		utils.LogError("根据体检ID获取项目信息失败: " + err.Error())
76
-		return nil, errors.New("根据体检ID获取项目信息失败")
87
+		utils.LogError("获取用户信息失败:", err)
88
+		return errors.New("获取用户信息失败")
77 89
 	}
78
-	return presentations, nil
79
-}
80
-
81
-func (s *BodycheckServ) GetDetailsByPresentID(ID int) ([]model.TaPresentationDetail, error) {
82
-	detail, err := s.dao.GetDetailsByPresentID(ID)
90
+	if customer == nil || customer.CustomerId == "" {
91
+		return errors.New("没有当前用户信息!")
92
+	}
93
+	userid := customer.CustomerId
94
+	checkinfo, err := s.dao.GetCheckByUserAndEquipmentID(userid, result.EquipmentId)
83 95
 	if err != nil {
84
-		utils.LogError("根据项目ID获取详情失败: " + err.Error())
85
-		return nil, errors.New("根据项目ID获取详情失败")
96
+		utils.LogError("获取体检信息失败:", err)
97
+		return errors.New("获取体检信息失败")
86 98
 	}
87
-	return detail, nil
88
-}
89 99
 
90
-func (s *BodycheckServ) GetPresentation(checkID, typeID int) (*model.TaPresentation, error) {
91
-	presentation, err := s.dao.GetPresentation(checkID, typeID)
92
-	if err != nil {
93
-		utils.LogError("获取体检项目信息失败: " + err.Error())
94
-		return nil, errors.New("获取体检项目信息失败")
100
+	if checkinfo == nil || checkinfo.Id != "" || time.Now().Local().Format("2006-01-02") != checkinfo.CreateDate.Format("2006-01-02") {
101
+		caseEquipment, err := s.dao.GetCaseEquipment(result.EquipmentId)
102
+		if err != nil {
103
+			utils.LogError("获取设备信息失败:", err)
104
+			return errors.New("获取设备信息失败")
105
+		}
106
+		if caseEquipment == nil || caseEquipment.Id == "" {
107
+			return errors.New("设备未维护!")
108
+		}
109
+
110
+		var checkNew = model.TaBodyCheck{}
111
+		checkNew.CaseId = caseEquipment.CaseId
112
+		checkNew.EquipmentId = result.EquipmentId
113
+		checkNew.UserId = userid
114
+		checkNew.ReportUrl = result.HMSReportUrl
115
+		checkNew.CreateDate = result.CheckDate
116
+		checkinfo, err = s.dao.SaveBodyCheckInfo(checkNew)
117
+
118
+		wxconf, _ := config.NewConfig("ini", "conf/wechat.conf")
119
+		messageTplID := wxconf.String("messageTplID")
120
+
121
+		org := s.ctx.Get("org").(model.SysOrg)
122
+
123
+		utils.WxClientFor(org.OrgId).SendTplMessage(result.WechatAccount, messageTplID, beego.AppConfig.String("resultURL"), map[string]wx.TplMessageData{
124
+			"first": wx.TplMessageData{
125
+				Value: "您的体检报告已生成",
126
+			},
127
+			"keyword1": wx.TplMessageData{
128
+				Value: checkinfo.Id,
129
+			},
130
+			"keyword2": wx.TplMessageData{
131
+				Value: result.CheckDate.Format("2006-01-02 15:04"),
132
+			},
133
+			"remark": wx.TplMessageData{
134
+				Value: "",
135
+			},
136
+		})
95 137
 	}
96
-	return presentation, nil
97
-}
98 138
 
99
-func (s *BodycheckServ) SavePresentation(info model.TaPresentation) (*model.TaPresentation, error) {
100
-	presentation, err := s.dao.SavePresentation(info)
139
+	presentation, err := s.dao.GetPresentation(checkinfo.Id, result.CheckType)
101 140
 	if err != nil {
102
-		utils.LogError("新增体检项目信息失败: " + err.Error())
103
-		return nil, errors.New("新增体检项目信息失败")
141
+		utils.LogError("获取报告明细失败:", err)
142
+		return errors.New("获取报告明细失败")
104 143
 	}
105
-	return presentation, err
106
-}
107
-func (s *BodycheckServ) UpdatePresentation(info *model.TaPresentation) error {
108
-	err := s.dao.UpdatePresentation(info)
109
-	if err != nil {
110
-		utils.LogError("更新体检项目信息失败: " + err.Error())
111
-		return errors.New("更新体检项目信息失败")
144
+	if presentation == nil || presentation.Id != "" {
145
+		// 新增
146
+		var preNew = model.TaPresentation{}
147
+		preNew.CheckId = checkinfo.Id
148
+		preNew.CheckDate = result.CheckDate
149
+		preNew.CheckResult = result.CheckResult
150
+		preNew.CheckType = result.CheckType
151
+		preNew.ReportUrl = result.ReportUrl
152
+		presentation, err = s.dao.SavePresentation(preNew)
153
+		if err != nil {
154
+			utils.LogError("保存报告明细失败:", err)
155
+			return errors.New("保存报告明细失败")
156
+		}
157
+	} else {
158
+		// 修改
159
+		presentation.CheckDate = result.CheckDate
160
+		presentation.CheckResult = result.CheckResult
161
+		presentation.ReportUrl = result.ReportUrl
162
+		err = s.dao.UpdatePresentation(presentation)
163
+		if err != nil {
164
+			utils.LogError("修改报告明细失败:", err)
165
+			return errors.New("修改报告明细失败")
166
+		}
167
+		// 删除之前的记录
168
+		err = s.dao.DeletePresentionDetail(presentation.Id)
169
+		if err != nil {
170
+			utils.LogError("删除报告明细失败:", err)
171
+			return errors.New("删除报告明细失败")
172
+		}
112 173
 	}
113
-	return nil
114
-}
115 174
 
116
-func (s *BodycheckServ) SavePresentationDetail(details []model.TaPresentationDetail) error {
117
-	err := s.dao.SavePresentationDetail(details)
175
+	specs, err := s.dao.GetCheckSpecs()
118 176
 	if err != nil {
119
-		utils.LogError("保存体检项目明细失败: " + err.Error())
120
-		return errors.New("保存体检项目明细失败")
177
+		utils.LogError("获取spec信息失败:", err)
178
+		return errors.New("获取spec信息失败")
121 179
 	}
122
-	return nil
123 180
 
124
-}
125
-func (s *BodycheckServ) DeletePresentionDetail(ID int) error {
126
-	err := s.dao.DeletePresentionDetail(ID)
127
-	if err != nil {
128
-		utils.LogError("根据项目ID删除明细信息失败: " + err.Error())
129
-		return errors.New("根据项目ID删除明细信息失败")
181
+	if len(formVal) > 0 {
182
+		var details []model.TaPresentationDetail
183
+		for k, v := range formVal {
184
+			if k != "WechatAccount" && k != "EquipmentId" && k != "CheckType" && k != "CheckDate" && k != "CheckResult" && k != "ReportUrl" && k != "HMSReportUrl" && k != "WXID" {
185
+				var detail model.TaPresentationDetail
186
+				detail.CheckName = k
187
+				switch vx := v.(type) {
188
+				case string:
189
+					detail.CheckVal = vx
190
+				case float64:
191
+					detail.CheckVal = strconv.FormatFloat(vx, 'f', 2, 64)
192
+				}
193
+
194
+				detail.PresentationId = presentation.Id
195
+				var specName = ""
196
+				for _, spec := range specs {
197
+					if spec.SortName == k {
198
+						specName = spec.Name
199
+						break
200
+					}
201
+				}
202
+				detail.SpecName = specName
203
+				detail.Id = utils.GetGUID()
204
+				details = append(details, detail)
205
+			}
206
+		}
207
+		if len(details) > 0 {
208
+			err := s.dao.SavePresentationDetail(details)
209
+			if err != nil {
210
+				utils.LogError("保存体检明细失败:", err)
211
+				return errors.New("保存体检明细失败")
212
+			}
213
+		}
130 214
 	}
131 215
 	return nil
132 216
 }

+ 21
- 0
service/card/card.go Bestand weergeven

@@ -4,6 +4,7 @@ import (
4 4
 	"errors"
5 5
 	"spaceofcheng/services/models"
6 6
 	"spaceofcheng/services/models/card"
7
+	"spaceofcheng/services/models/coupon"
7 8
 	"spaceofcheng/services/models/course"
8 9
 	"spaceofcheng/services/models/customer"
9 10
 	"spaceofcheng/services/models/model"
@@ -23,6 +24,7 @@ type CardServ struct {
23 24
 	custDao   *customer.CustomerDAO
24 25
 	userDao   *system.UserDAO
25 26
 	courseDao *course.CourseDAO
27
+	coupondao *coupon.CouponDAO
26 28
 }
27 29
 
28 30
 // NewCardServ 初始化
@@ -33,6 +35,7 @@ func NewCardServ(ctx *utils.Context) *CardServ {
33 35
 		custDao:   customer.NewCustomerDAO(ctx),
34 36
 		userDao:   system.NewUserDAO(ctx),
35 37
 		courseDao: course.NewCourseDAO(ctx),
38
+		coupondao: coupon.NewCouponDAO(ctx),
36 39
 	}
37 40
 }
38 41
 
@@ -195,6 +198,7 @@ func (s *CardServ) GiveCard(CardID string, uids []string) error {
195 198
 		if err := s.GiveCardTo(&user, cust, card); err != nil {
196 199
 			return err
197 200
 		}
201
+
198 202
 	}
199 203
 
200 204
 	return nil
@@ -246,12 +250,29 @@ func (s *CardServ) GiveCardTo(from *model.SysUser, to *model.TaCustomer, card *c
246 250
 		Price:            card.Price,
247 251
 	}
248 252
 
253
+	// 放入赠送记录
254
+	rec := model.TaCouponGiveRecord{
255
+		GiftType:   models.GIVE_GIFT_COUPON,
256
+		GiftId:     card.CardId,
257
+		GiftName:   card.CardName,
258
+		FromId:     from.UserId,
259
+		FromName:   from.UserName,
260
+		ToId:       to.CustomerId,
261
+		ToName:     to.CustomerName,
262
+		CreateDate: time.Now().Local(),
263
+	}
264
+
249 265
 	// 入库
250 266
 	if err := s.dao.SaveCustomerCards([]model.TaCustomerCard{custcard}); err != nil {
251 267
 		utils.LogError("保存客户卡失败: " + err.Error())
252 268
 		return errors.New("保存客户卡失败")
253 269
 	}
254 270
 
271
+	if err := s.coupondao.SaveCouponRecoreds([]model.TaCouponGiveRecord{rec}); err != nil {
272
+		utils.LogError("保存卡赠送记录失败: " + err.Error())
273
+		return errors.New("保存卡赠送记录失败")
274
+	}
275
+
255 276
 	// 加入我的课程信息
256 277
 	err := s.SaveCustomerCourseByCard(&custcard)
257 278
 	if err != nil {

+ 46
- 7
service/statistics/cardcoupon.go Bestand weergeven

@@ -2,6 +2,7 @@ package statistics
2 2
 
3 3
 import (
4 4
 	"errors"
5
+	"spaceofcheng/services/models/statistics"
5 6
 	"spaceofcheng/services/service"
6 7
 	"spaceofcheng/services/utils"
7 8
 )
@@ -24,7 +25,7 @@ func (s *StatisticsServ) CardCouponStatistics(caseids, ctype, name string, page,
24 25
 		utils.LogError("获取卡券统计数据失败: " + err.Error())
25 26
 		return nil, errors.New("获取卡券统计数据失败")
26 27
 	}
27
-	total, err := s.dao.CardCouponStatisticsCount(caseids, ctype, name)
28
+	all, err := s.dao.CardCouponStatisticsCount(caseids, ctype, name)
28 29
 	if err != nil {
29 30
 		utils.LogError("获取卡券统计数据失败: " + err.Error())
30 31
 		return nil, errors.New("获取卡券统计数据失败")
@@ -33,11 +34,26 @@ func (s *StatisticsServ) CardCouponStatistics(caseids, ctype, name string, page,
33 34
 	return map[string]interface{}{
34 35
 		"list":     list,
35 36
 		"pagesize": pageSize,
36
-		"pagenum":  total,
37
+		"pagenum":  len(all),
37 38
 		"page":     page,
38 39
 	}, nil
39 40
 }
40 41
 
42
+// CardCouponStatisticsExcel 导出
43
+func (s *StatisticsServ) CardCouponStatisticsExcel(caseids, ctype, name string) ([]statistics.CardCouponStatistics, error) {
44
+	if caseids == "" {
45
+		return nil, errors.New("请先选择案场信息")
46
+	}
47
+
48
+	all, err := s.dao.CardCouponStatisticsCount(caseids, ctype, name)
49
+	if err != nil {
50
+		utils.LogError("获取卡券统计数据失败: " + err.Error())
51
+		return nil, errors.New("获取卡券统计数据失败")
52
+	}
53
+
54
+	return all, nil
55
+}
56
+
41 57
 // CardCouponUsedStatistics 获取卡券使用统计信息
42 58
 func (s *StatisticsServ) CardCouponUsedStatistics(caseids, tel, name, receivetype, begindate, enddate, status string, page, pageSize int) (map[string]interface{}, error) {
43 59
 	if pageSize == 0 {
@@ -56,7 +72,7 @@ func (s *StatisticsServ) CardCouponUsedStatistics(caseids, tel, name, receivetyp
56 72
 		utils.LogError("获取卡券统计数据失败: " + err.Error())
57 73
 		return nil, errors.New("获取卡券统计数据失败")
58 74
 	}
59
-	total, err := s.dao.CardCouponUsedCountStatistics(caseids, tel, name, receivetype, begindate, enddate, status)
75
+	all, err := s.dao.CardCouponUsedCountStatistics(caseids, tel, name, receivetype, begindate, enddate, status)
60 76
 	if err != nil {
61 77
 		utils.LogError("获取卡券统计数据失败: " + err.Error())
62 78
 		return nil, errors.New("获取卡券统计数据失败")
@@ -65,12 +81,22 @@ func (s *StatisticsServ) CardCouponUsedStatistics(caseids, tel, name, receivetyp
65 81
 	return map[string]interface{}{
66 82
 		"list":     list,
67 83
 		"pagesize": pageSize,
68
-		"pagenum":  total,
84
+		"pagenum":  len(all),
69 85
 		"page":     page,
70 86
 	}, nil
71 87
 }
72 88
 
73
-// CardCouponVerifyStatistics 获取卡券使用统计信息
89
+// CardCouponUsedStatisticsExcel 卡券使用数据导出
90
+func (s *StatisticsServ) CardCouponUsedStatisticsExcel(caseids, tel, name, receivetype, begindate, enddate, status string) ([]statistics.CardCouponUsedStatistics, error) {
91
+	all, err := s.dao.CardCouponUsedCountStatistics(caseids, tel, name, receivetype, begindate, enddate, status)
92
+	if err != nil {
93
+		utils.LogError("获取卡券统计数据失败: " + err.Error())
94
+		return nil, errors.New("获取卡券统计数据失败")
95
+	}
96
+	return all, nil
97
+}
98
+
99
+// CardCouponVerifyStatistics 获取卡券核销统计信息
74 100
 func (s *StatisticsServ) CardCouponVerifyStatistics(caseids, tel, name, status string, page, pageSize int) (map[string]interface{}, error) {
75 101
 	if pageSize == 0 {
76 102
 		pageSize = service.PAGENUM
@@ -88,7 +114,7 @@ func (s *StatisticsServ) CardCouponVerifyStatistics(caseids, tel, name, status s
88 114
 		utils.LogError("获取卡券统计数据失败: " + err.Error())
89 115
 		return nil, errors.New("获取卡券统计数据失败")
90 116
 	}
91
-	total, err := s.dao.CardCouponVerifyStatisticsCount(caseids, tel, name, status)
117
+	all, err := s.dao.CardCouponVerifyStatisticsCount(caseids, tel, name, status)
92 118
 	if err != nil {
93 119
 		utils.LogError("获取卡券统计数据失败: " + err.Error())
94 120
 		return nil, errors.New("获取卡券统计数据失败")
@@ -97,7 +123,20 @@ func (s *StatisticsServ) CardCouponVerifyStatistics(caseids, tel, name, status s
97 123
 	return map[string]interface{}{
98 124
 		"list":     list,
99 125
 		"pagesize": pageSize,
100
-		"pagenum":  total,
126
+		"pagenum":  len(all),
101 127
 		"page":     page,
102 128
 	}, nil
103 129
 }
130
+
131
+// CardCouponVerifyStatisticsExcel 卡券核销统计导出
132
+func (s *StatisticsServ) CardCouponVerifyStatisticsExcel(caseids, tel, name, status string) ([]statistics.CardCouponVerifyStatistics, error) {
133
+	if caseids == "" {
134
+		return nil, errors.New("请先选择案场信息")
135
+	}
136
+	all, err := s.dao.CardCouponVerifyStatisticsCount(caseids, tel, name, status)
137
+	if err != nil {
138
+		utils.LogError("获取卡券统计数据失败: " + err.Error())
139
+		return nil, errors.New("获取卡券统计数据失败")
140
+	}
141
+	return all, nil
142
+}

+ 32
- 4
service/statistics/course.go Bestand weergeven

@@ -2,6 +2,7 @@ package statistics
2 2
 
3 3
 import (
4 4
 	"errors"
5
+	"spaceofcheng/services/models/statistics"
5 6
 	"spaceofcheng/services/service"
6 7
 	"spaceofcheng/services/utils"
7 8
 )
@@ -24,7 +25,7 @@ func (s *StatisticsServ) GetCourseOrdersStatistics(typeid, caseids, name, begind
24 25
 		utils.LogError("获取课程订单统计数据失败: " + err.Error())
25 26
 		return nil, errors.New("获取课程订单统计数据失败")
26 27
 	}
27
-	total, err := s.dao.GetCourseOrdersStatisticsCount(typeid, caseids, name, begindate, enddate)
28
+	all, err := s.dao.GetCourseOrdersStatisticsCount(typeid, caseids, name, begindate, enddate)
28 29
 	if err != nil {
29 30
 		utils.LogError("获取课程订单统计数据失败: " + err.Error())
30 31
 		return nil, errors.New("获取课程订单统计数据失败")
@@ -33,11 +34,24 @@ func (s *StatisticsServ) GetCourseOrdersStatistics(typeid, caseids, name, begind
33 34
 	return map[string]interface{}{
34 35
 		"list":     list,
35 36
 		"pagesize": pageSize,
36
-		"pagenum":  total,
37
+		"pagenum":  len(all),
37 38
 		"page":     page,
38 39
 	}, nil
39 40
 }
40 41
 
42
+// GetCourseOrdersStatisticsExcel 课程订单导出
43
+func (s *StatisticsServ) GetCourseOrdersStatisticsExcel(typeid, caseids, name, begindate, enddate string) ([]statistics.CourseOrdersStatistics, error) {
44
+	if caseids == "" {
45
+		return nil, errors.New("请先选择案场信息")
46
+	}
47
+	all, err := s.dao.GetCourseOrdersStatisticsCount(typeid, caseids, name, begindate, enddate)
48
+	if err != nil {
49
+		utils.LogError("获取课程订单统计数据失败: " + err.Error())
50
+		return nil, errors.New("获取课程订单统计数据失败")
51
+	}
52
+	return all, nil
53
+}
54
+
41 55
 // GetCourseStatistics 获取课程统计信息
42 56
 func (s *StatisticsServ) GetCourseStatistics(typeid, caseids, name string, page, pageSize int) (map[string]interface{}, error) {
43 57
 	if pageSize == 0 {
@@ -56,7 +70,7 @@ func (s *StatisticsServ) GetCourseStatistics(typeid, caseids, name string, page,
56 70
 		utils.LogError("获取课程统计数据失败: " + err.Error())
57 71
 		return nil, errors.New("获取课程统计数据失败")
58 72
 	}
59
-	total, err := s.dao.GetCourseStatisticsCount(typeid, caseids, name)
73
+	all, err := s.dao.GetCourseStatisticsCount(typeid, caseids, name)
60 74
 	if err != nil {
61 75
 		utils.LogError("获取课程统计数据失败: " + err.Error())
62 76
 		return nil, errors.New("获取课程统计数据失败")
@@ -65,7 +79,21 @@ func (s *StatisticsServ) GetCourseStatistics(typeid, caseids, name string, page,
65 79
 	return map[string]interface{}{
66 80
 		"list":     list,
67 81
 		"pagesize": pageSize,
68
-		"pagenum":  total,
82
+		"pagenum":  len(all),
69 83
 		"page":     page,
70 84
 	}, nil
71 85
 }
86
+
87
+// GetCourseStatisticsExcel 课程统计导出
88
+func (s *StatisticsServ) GetCourseStatisticsExcel(typeid, caseids, name string) ([]statistics.CourseStatistics, error) {
89
+	if caseids == "" {
90
+		return nil, errors.New("请先选择案场信息")
91
+	}
92
+
93
+	all, err := s.dao.GetCourseStatisticsCount(typeid, caseids, name)
94
+	if err != nil {
95
+		utils.LogError("获取课程统计数据失败: " + err.Error())
96
+		return nil, errors.New("获取课程统计数据失败")
97
+	}
98
+	return all, nil
99
+}

+ 30
- 4
service/statistics/goods.go Bestand weergeven

@@ -2,6 +2,7 @@ package statistics
2 2
 
3 3
 import (
4 4
 	"errors"
5
+	"spaceofcheng/services/models/statistics"
5 6
 	"spaceofcheng/services/service"
6 7
 	"spaceofcheng/services/utils"
7 8
 )
@@ -24,7 +25,7 @@ func (s *StatisticsServ) GetGoodsStatistics(caseids, typeid, name string, page,
24 25
 		utils.LogError("获取商品统计数据失败: " + err.Error())
25 26
 		return nil, errors.New("获取商品统计数据失败")
26 27
 	}
27
-	total, err := s.dao.GetGoodsStatisticsCount(caseids, typeid, name)
28
+	all, err := s.dao.GetGoodsStatisticsCount(caseids, typeid, name)
28 29
 	if err != nil {
29 30
 		utils.LogError("获取商品统计数据失败: " + err.Error())
30 31
 		return nil, errors.New("获取商品统计数据失败")
@@ -33,11 +34,21 @@ func (s *StatisticsServ) GetGoodsStatistics(caseids, typeid, name string, page,
33 34
 	return map[string]interface{}{
34 35
 		"list":     list,
35 36
 		"pagesize": pageSize,
36
-		"pagenum":  total,
37
+		"pagenum":  len(all),
37 38
 		"page":     page,
38 39
 	}, nil
39 40
 }
40 41
 
42
+// GetGoodsStatisticsExcel 获取商品统计信息导出
43
+func (s *StatisticsServ) GetGoodsStatisticsExcel(caseids, typeid, name string) ([]statistics.GoodsStatistics, error) {
44
+	all, err := s.dao.GetGoodsStatisticsCount(caseids, typeid, name)
45
+	if err != nil {
46
+		utils.LogError("获取商品统计数据失败: " + err.Error())
47
+		return nil, errors.New("获取商品统计数据失败")
48
+	}
49
+	return all, nil
50
+}
51
+
41 52
 // GetGoodsOrdersStatistics 获取商品订单统计信息
42 53
 func (s *StatisticsServ) GetGoodsOrdersStatistics(status, usertype, caseids, begindate, enddate string, page, pageSize int) (map[string]interface{}, error) {
43 54
 	if pageSize == 0 {
@@ -56,7 +67,7 @@ func (s *StatisticsServ) GetGoodsOrdersStatistics(status, usertype, caseids, beg
56 67
 		utils.LogError("获取商品订单统计数据失败: " + err.Error())
57 68
 		return nil, errors.New("获取商品订单统计数据失败")
58 69
 	}
59
-	total, err := s.dao.GetGoodsOrderStatisticsCount(status, usertype, caseids, begindate, enddate)
70
+	all, err := s.dao.GetGoodsOrderStatisticsCount(status, usertype, caseids, begindate, enddate)
60 71
 	if err != nil {
61 72
 		utils.LogError("获取商品订单统计数据失败: " + err.Error())
62 73
 		return nil, errors.New("获取商品订单统计数据失败")
@@ -65,7 +76,22 @@ func (s *StatisticsServ) GetGoodsOrdersStatistics(status, usertype, caseids, beg
65 76
 	return map[string]interface{}{
66 77
 		"list":     list,
67 78
 		"pagesize": pageSize,
68
-		"pagenum":  total,
79
+		"pagenum":  len(all),
69 80
 		"page":     page,
70 81
 	}, nil
71 82
 }
83
+
84
+// GetGoodsOrdersStatisticsExcel 商品订单导出
85
+func (s *StatisticsServ) GetGoodsOrdersStatisticsExcel(status, usertype, caseids, begindate, enddate string) ([]statistics.GoodsOrdersStatistics, error) {
86
+	if caseids == "" {
87
+		return nil, errors.New("请先选择案场信息")
88
+	}
89
+
90
+	all, err := s.dao.GetGoodsOrderStatisticsCount(status, usertype, caseids, begindate, enddate)
91
+	if err != nil {
92
+		utils.LogError("获取商品订单统计数据失败: " + err.Error())
93
+		return nil, errors.New("获取商品订单统计数据失败")
94
+	}
95
+
96
+	return all, nil
97
+}