瀏覽代碼

Merge branch 'dev' of http://git.ycjcjy.com/SpaceOfCheng/services into dev

胡轶钦 6 年之前
父節點
當前提交
baf9416f95
共有 49 個文件被更改,包括 2157 次插入876 次删除
  1. 5
    0
      conf/app.conf
  2. 1
    0
      conf/wechat.conf
  3. 7
    0
      controllers/base.go
  4. 11
    257
      controllers/bodycheck/bodycheck.go
  5. 0
    177
      controllers/bodycheck/wechat.go
  6. 229
    1
      controllers/statistics/cardcoupon.go
  7. 111
    1
      controllers/statistics/course.go
  8. 45
    0
      controllers/statistics/dashboard.go
  9. 139
    1
      controllers/statistics/goods.go
  10. 163
    0
      controllers/wechat.go
  11. 273
    0
      log/common.log
  12. 15
    34
      models/bodycheck/bodycheck.go
  13. 3
    0
      models/constant.go
  14. 93
    130
      models/luckdraw/luckdraw.go
  15. 4
    4
      models/model/ta_body_check.go
  16. 2
    2
      models/model/ta_case_equipment.go
  17. 2
    2
      models/model/ta_luckdraw.go
  18. 2
    2
      models/model/ta_luckdraw_prize.go
  19. 3
    3
      models/model/ta_luckdraw_record.go
  20. 3
    3
      models/model/ta_luckdraw_writeoff.go
  21. 2
    2
      models/model/ta_presentation.go
  22. 2
    2
      models/model/ta_presentation_detail.go
  23. 3
    3
      models/model/ta_prize_detail.go
  24. 2
    2
      models/model/ta_share_lucky_record.go
  25. 9
    0
      models/model/ta_sta_arrived_daily.go
  26. 9
    0
      models/model/ta_sta_course_daily.go
  27. 11
    0
      models/model/ta_sta_course_order_daily.go
  28. 9
    0
      models/model/ta_sta_customer_daily.go
  29. 11
    0
      models/model/ta_sta_goods_daily.go
  30. 1
    1
      models/model/td_check_spec.go
  31. 1
    1
      models/model/td_check_type.go
  32. 1
    1
      models/model/td_luckdraw_theme.go
  33. 1
    0
      models/model/td_statistics_comps.go
  34. 7
    7
      models/statistics/cardcoupon.go
  35. 4
    4
      models/statistics/course.go
  36. 418
    0
      models/statistics/dashboard.go
  37. 9
    6
      models/statistics/goods.go
  38. 0
    84
      models/statistics/statistics.go
  39. 16
    5
      routers/common.go
  40. 4
    0
      routers/guest.go
  41. 7
    7
      routers/wechat.go
  42. 176
    92
      service/bodycheck/bodycheck.go
  43. 21
    0
      service/card/card.go
  44. 46
    7
      service/statistics/cardcoupon.go
  45. 32
    4
      service/statistics/course.go
  46. 183
    23
      service/statistics/dashboard.go
  47. 30
    4
      service/statistics/goods.go
  48. 23
    0
      service/statistics/setting.go
  49. 8
    4
      service/sys.go

+ 5
- 0
conf/app.conf 查看文件

@@ -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 查看文件

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

+ 7
- 0
controllers/base.go 查看文件

@@ -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

+ 11
- 257
controllers/bodycheck/bodycheck.go 查看文件

@@ -4,77 +4,30 @@ import (
4 4
 	"encoding/json"
5 5
 	"io/ioutil"
6 6
 	"spaceofcheng/services/controllers"
7
-	"spaceofcheng/services/models/model"
8 7
 	"spaceofcheng/services/service/bodycheck"
9 8
 	"spaceofcheng/services/utils"
10
-	"strconv"
11
-	"time"
12
-
13
-	"github.com/astaxie/beego"
14
-
15
-	"github.com/astaxie/beego/config"
16
-	"github.com/zjxpcyc/wechat/wx"
17 9
 )
18 10
 
19
-// BodyCheckController 应用
11
+// BodyCheckController 商品
20 12
 type BodyCheckController struct {
21
-	dao *bodycheck.BodycheckServ
13
+	serv *bodycheck.BodyCheckServ
22 14
 	controllers.BaseController
23
-	weixin *wx.Client
24 15
 }
25 16
 
26 17
 // Constructor 初始化 Controller
27 18
 // @Title Constructor
28 19
 // @Description 初始化 Controller, 系统自动调用
29 20
 func (c *BodyCheckController) Constructor() {
30
-	c.dao = bodycheck.NewBodycheckServ(c.Context)
31
-	org := c.Context.Get("org").(model.SysOrg)
32
-	c.weixin = utils.WxClientFor(org.OrgId)
21
+	c.serv = bodycheck.NewBodyCheckServ(c.Context)
33 22
 }
34 23
 
35 24
 // GetCheckByUser 根据用户获取体检报告
36 25
 func (c *BodyCheckController) GetCheckByUser() {
37
-	code := c.GetString("code")
38
-	openid, err := c.weixin.GetOpenID(code)
39
-	if err != nil {
40
-		beego.Error("获取openid失败!", err.Error())
41
-		c.ResponseError(err)
42
-	}
43
-	// openid := "o5EGQ0ytw9JUpSa6N84ddo3CYFO4"
44
-	user, err := c.dao.GetUserByOpenID(openid)
26
+	info, err := c.serv.GetCheckByUser()
45 27
 	if err != nil {
46 28
 		c.ResponseError(err)
47 29
 	}
48
-	if user == nil {
49
-		c.ResponseError(err)
50
-	}
51
-
52
-	bodyCheck, err := c.dao.GetBodyCheckByUser(user.CustomerId)
53
-	if err != nil {
54
-		c.ResponseJSON(map[string]interface{}{
55
-			"Status":  false,
56
-			"Message": err.Error(),
57
-		})
58
-	}
59
-	if len(bodyCheck) == 0 {
60
-		c.ResponseJSON(map[string]interface{}{
61
-			"Status":  false,
62
-			"Message": "没有查询到数据",
63
-		})
64
-	}
65
-	presentations, err := c.dao.GetPresentationByCheckID(bodyCheck[0].Id)
66
-	if err != nil {
67
-		c.ResponseJSON(map[string]interface{}{
68
-			"Status":  false,
69
-			"Message": err.Error(),
70
-		})
71
-	}
72
-	c.ResponseJSON(map[string]interface{}{
73
-		"Status":   true,
74
-		"Message":  presentations,
75
-		"Info":     bodyCheck,
76
-		"UserInfo": user,
77
-	})
30
+	c.ResponseJSON(info)
78 31
 }
79 32
 
80 33
 // PostCheckResult 测量结果返回
@@ -86,213 +39,14 @@ func (c *BodyCheckController) PostCheckResult() {
86 39
 	var formVal map[string]interface{}
87 40
 	err := json.Unmarshal(con, &formVal)
88 41
 	if err != nil {
89
-		beego.Error(err)
90
-		c.ResponseJSON(map[string]interface{}{
91
-			"Status":  false,
92
-			"Message": err.Error(),
93
-		})
94
-	}
95
-
96
-	type CheckResult struct {
97
-		WechatAccount string
98
-		EquipmentId   string
99
-		CheckType     int
100
-		CheckDate     time.Time
101
-		CheckResult   string
102
-		ReportUrl     string
103
-		HMSReportUrl  string
104
-	}
105
-
106
-	var result = CheckResult{}
107
-
108
-	result.EquipmentId = formVal["EquipmentId"].(string)
109
-	result.WechatAccount = formVal["WechatAccount"].(string)
110
-	// result.CheckResult = formVal["CheckResult"].(string)
111
-	result.CheckResult = ""
112
-	result.ReportUrl = formVal["ReportUrl"].(string)
113
-	result.HMSReportUrl = formVal["HMSReportUrl"].(string)
114
-	result.CheckType = int(formVal["CheckType"].(float64))
115
-	if err != nil {
116
-		beego.Error(err.Error())
117
-		c.ResponseJSON(map[string]interface{}{
118
-			"Status":  false,
119
-			"Message": err.Error(),
120
-		})
121
-	}
122
-	loc, _ := time.LoadLocation("Local")
123
-	result.CheckDate, err = time.ParseInLocation("2006-01-02 15:04:05", formVal["CheckDate"].(string), loc)
124
-	if err != nil {
125
-		beego.Error(err.Error())
126
-		c.ResponseJSON(map[string]interface{}{
127
-			"Status":  false,
128
-			"Message": err.Error(),
129
-		})
130
-	}
131
-
132
-	user, err := c.dao.GetUserByOpenID(result.WechatAccount)
133
-	if err != nil {
134
-		beego.Error(err.Error())
135
-		c.ResponseJSON(map[string]interface{}{
136
-			"Status":  false,
137
-			"Message": err.Error(),
138
-		})
139
-	}
140
-
141
-	if user == nil || user.CustomerId == "" {
142
-		beego.Error("没有当前用户信息!")
143
-		c.ResponseJSON(map[string]interface{}{
144
-			"Status":  false,
145
-			"Message": "没有当前用户信息!",
146
-		})
147
-	}
148
-	userid := user.CustomerId
149
-
150
-	checkinfo, err := c.dao.GetCheckByUserAndEquipmentID(userid, result.EquipmentId)
151
-	if err != nil {
152
-		beego.Error(err.Error())
153
-		c.ResponseJSON(map[string]interface{}{
154
-			"Status":  false,
155
-			"Message": err.Error(),
156
-		})
157
-	}
158
-	if checkinfo == nil || checkinfo.Id < 1 || time.Now().Local().Format("2006-01-02") != checkinfo.CreateDate.Format("2006-01-02") {
159
-		caseEquipment, err := c.dao.GetCaseEquipment(result.EquipmentId)
160
-		if err != nil {
161
-			beego.Error(err.Error())
162
-			c.ResponseJSON(map[string]interface{}{
163
-				"Status":  false,
164
-				"Message": err.Error(),
165
-			})
166
-		}
167
-		if caseEquipment == nil || caseEquipment.Id < 1 {
168
-			beego.Error("设备未维护!")
169
-			c.ResponseJSON(map[string]interface{}{
170
-				"Status":  false,
171
-				"Message": "设备未维护!",
172
-			})
173
-		}
174
-		var checkNew = model.TaBodyCheck{}
175
-		checkNew.CaseId = caseEquipment.CaseId
176
-		checkNew.EquipmentId = result.EquipmentId
177
-		checkNew.UserId = userid
178
-		checkNew.ReportUrl = result.HMSReportUrl
179
-		checkNew.CreateDate = result.CheckDate
180
-		checkinfo, err = c.dao.SaveBodyCheckInfo(checkNew)
181
-
182
-		wxconf, _ := config.NewConfig("ini", "conf/wechat.conf")
183
-		messageTplID := wxconf.String("messageTplID")
184
-
185
-		c.weixin.SendTplMessage(result.WechatAccount, messageTplID, beego.AppConfig.String("resultURL"), map[string]wx.TplMessageData{
186
-			"first": wx.TplMessageData{
187
-				Value: "您的体检报告已生成",
188
-			},
189
-			"keyword1": wx.TplMessageData{
190
-				Value: strconv.Itoa(checkinfo.Id),
191
-			},
192
-			"keyword2": wx.TplMessageData{
193
-				Value: result.CheckDate.Format("2006-01-02 15:04"),
194
-			},
195
-			"remark": wx.TplMessageData{
196
-				Value: "",
197
-			},
198
-		})
199
-	}
200
-
201
-	presentation, err := c.dao.GetPresentation(checkinfo.Id, result.CheckType)
202
-	if err != nil {
203
-		beego.Error(err.Error())
204
-		c.ResponseJSON(map[string]interface{}{
205
-			"Status":  false,
206
-			"Message": err.Error(),
207
-		})
208
-	}
209
-	if presentation == nil || presentation.Id < 1 {
210
-		// 新增
211
-		var preNew = model.TaPresentation{}
212
-		preNew.CheckId = checkinfo.Id
213
-		preNew.CheckDate = result.CheckDate
214
-		preNew.CheckResult = result.CheckResult
215
-		preNew.CheckType = result.CheckType
216
-		preNew.ReportUrl = result.ReportUrl
217
-		presentation, err = c.dao.SavePresentation(preNew)
218
-		if err != nil {
219
-			beego.Error(err.Error())
220
-			c.ResponseJSON(map[string]interface{}{
221
-				"Status":  false,
222
-				"Message": err.Error(),
223
-			})
224
-		}
225
-	} else {
226
-		// 修改
227
-		presentation.CheckDate = result.CheckDate
228
-		presentation.CheckResult = result.CheckResult
229
-		presentation.ReportUrl = result.ReportUrl
230
-		err = c.dao.UpdatePresentation(presentation)
231
-		if err != nil {
232
-			beego.Error(err.Error())
233
-			c.ResponseJSON(map[string]interface{}{
234
-				"Status":  false,
235
-				"Message": err.Error(),
236
-			})
237
-		}
238
-		// 删除之前的记录
239
-		err = c.dao.DeletePresentionDetail(presentation.Id)
240
-		if err != nil {
241
-			beego.Error(err.Error())
242
-			c.ResponseJSON(map[string]interface{}{
243
-				"Status":  false,
244
-				"Message": err.Error(),
245
-			})
246
-		}
42
+		utils.LogError("参数错误:", err)
43
+		c.ResponseError(err)
247 44
 	}
248 45
 
249
-	specs, err := c.dao.GetCheckSpecs()
46
+	err = c.serv.PostCheckResult(formVal)
250 47
 	if err != nil {
251
-		beego.Error(err.Error())
252
-		c.ResponseJSON(map[string]interface{}{
253
-			"Status":  false,
254
-			"Message": err.Error(),
255
-		})
256
-	}
257
-
258
-	if len(formVal) > 0 {
259
-		var details []model.TaPresentationDetail
260
-		for k, v := range formVal {
261
-			if k != "WechatAccount" && k != "EquipmentId" && k != "CheckType" && k != "CheckDate" && k != "CheckResult" && k != "ReportUrl" && k != "HMSReportUrl" && k != "WXID" {
262
-				var detail model.TaPresentationDetail
263
-				detail.CheckName = k
264
-				switch vx := v.(type) {
265
-				case string:
266
-					detail.CheckVal = vx
267
-				case float64:
268
-					detail.CheckVal = strconv.FormatFloat(vx, 'f', 2, 64)
269
-				}
270
-
271
-				detail.PresentationId = presentation.Id
272
-				var specName = ""
273
-				for _, spec := range specs {
274
-					if spec.SortName == k {
275
-						specName = spec.Name
276
-						break
277
-					}
278
-				}
279
-				detail.SpecName = specName
280
-				details = append(details, detail)
281
-			}
282
-		}
283
-		if len(details) > 0 {
284
-			err := c.dao.SavePresentationDetail(details)
285
-			if err != nil {
286
-				beego.Error(err.Error())
287
-				c.ResponseJSON(map[string]interface{}{
288
-					"Status":  false,
289
-					"Message": err.Error(),
290
-				})
291
-			}
292
-		}
48
+		utils.LogError("操作错误:", err)
49
+		c.ResponseError(err)
293 50
 	}
294
-	c.ResponseJSON(map[string]interface{}{
295
-		"Status":  true,
296
-		"Message": "",
297
-	})
51
+	c.ResponseJSON("")
298 52
 }

+ 0
- 177
controllers/bodycheck/wechat.go 查看文件

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

+ 229
- 1
controllers/statistics/cardcoupon.go 查看文件

@@ -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 查看文件

@@ -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
+}

+ 45
- 0
controllers/statistics/dashboard.go 查看文件

@@ -0,0 +1,45 @@
1
+package statistics
2
+
3
+import (
4
+	"strings"
5
+)
6
+
7
+// GetDashData 统计人员数据
8
+func (c *StatisticsController) GetDashData() {
9
+	caseids := c.GetString("caseids")
10
+	caseIDs := []string{}
11
+
12
+	if caseids != "" {
13
+		caseIDs = strings.Split(caseids, ",")
14
+	}
15
+
16
+	data, err := c.serv.StaDashboard(caseIDs)
17
+	if err != nil {
18
+		c.ResponseError(err)
19
+	}
20
+
21
+	c.ResponseJSON(data)
22
+}
23
+
24
+// GetDashFilterCharts 统计过滤条件报表
25
+func (c *StatisticsController) GetDashFilterCharts() {
26
+	// 目前只支持 week, month 两种
27
+	staType := c.GetString("statype")
28
+	if staType == "" {
29
+		staType = "week"
30
+	}
31
+
32
+	caseids := c.GetString("caseids")
33
+	caseIDs := []string{}
34
+
35
+	if caseids != "" {
36
+		caseIDs = strings.Split(caseids, ",")
37
+	}
38
+
39
+	data, err := c.serv.GetStaFilterCharts(caseIDs, staType)
40
+	if err != nil {
41
+		c.ResponseError(err)
42
+	}
43
+
44
+	c.ResponseJSON(data)
45
+}

+ 139
- 1
controllers/statistics/goods.go 查看文件

@@ -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 查看文件

@@ -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)

+ 273
- 0
log/common.log 查看文件

@@ -73,3 +73,276 @@
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] 用户没有设置默认案场
345
+2018/09/16 23:14:52 [E] 用户没有设置默认案场
346
+2018/09/16 23:15:52 [E] 用户没有设置默认案场
347
+2018/09/16 23:15:55 [E] 用户没有设置默认案场
348
+2018/09/16 23:15:55 [E] 用户没有设置默认案场

+ 15
- 34
models/bodycheck/bodycheck.go 查看文件

@@ -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
 )
@@ -27,7 +27,7 @@ func NewDAO(ctx *utils.Context) *DAO {
27 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
 
@@ -41,7 +41,7 @@ func (m *DAO) GetCheckSpecs() ([]model.TdCheckSpec, error) {
41 41
 // GetCheckByUserAndEquipmentID 根据用户与设备ID获取体检信息
42 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 string, EquipmentID string) (*
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 string) (*model.TaCustomer, error) {
86
-	var cust model.TaCustomer
87
-	_, err := m.db.Where("customer_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
 }

+ 3
- 0
models/constant.go 查看文件

@@ -12,6 +12,9 @@ const (
12 12
 	STATUS_NORMAL
13 13
 )
14 14
 
15
+// 过期
16
+const STATUS_EXPIRE = 9
17
+
15 18
 // 映射数据库的布尔型
16 19
 const (
17 20
 	BOOL_FALSE = 0

+ 93
- 130
models/luckdraw/luckdraw.go 查看文件

@@ -1,6 +1,7 @@
1 1
 package luckdraw
2 2
 
3 3
 import (
4
+	"errors"
4 5
 	"spaceofcheng/services/models"
5 6
 	"spaceofcheng/services/models/model"
6 7
 	"spaceofcheng/services/utils"
@@ -10,28 +11,20 @@ import (
10 11
 	"github.com/go-xorm/xorm"
11 12
 )
12 13
 
13
-const (
14
-	StatusNormal = 1
15
-)
16
-
17
-// DAO 当前数据库操作对象
18
-type DAO struct {
14
+// LuckDrawDao 当前数据库操作对象
15
+type LuckDrawDao struct {
19 16
 	ctx *utils.Context
20 17
 	db  *xorm.Session
21 18
 }
22 19
 
23 20
 // NewDAO 初始化DAO
24
-func NewDAO(ctx *utils.Context) *DAO {
25
-	return &DAO{
21
+func NewDAO(ctx *utils.Context) *LuckDrawDao {
22
+	return &LuckDrawDao{
26 23
 		ctx: ctx,
27 24
 		db:  ctx.DB,
28 25
 	}
29 26
 }
30 27
 
31
-const (
32
-	STATUS_NOWRITROFF = 0
33
-)
34
-
35 28
 // LuckDraw 抽奖记录
36 29
 type LuckDraw struct {
37 30
 	model.TaLuckdraw `xorm:"extends"`
@@ -39,101 +32,110 @@ type LuckDraw struct {
39 32
 }
40 33
 
41 34
 // GetLuckDraw 获取抽奖信息
42
-func (m *DAO) GetLuckDraw(id int) (*LuckDraw, error) {
43
-	if id == 0 {
44
-		return nil, utils.LogError("不存在抽奖信息!")
35
+func (m *LuckDrawDao) GetLuckDraw(id string) (*LuckDraw, error) {
36
+	if id == "" {
37
+		return nil, errors.New("不存在抽奖信息!")
45 38
 	}
46
-
47 39
 	luckdraw, err := m.GetLuckDrawByID(id)
48 40
 	if err != nil {
49
-		return nil, err
41
+		utils.LogError("获取抽奖信息失败:", err)
42
+		return nil, errors.New("获取抽奖信息失败")
50 43
 	}
51 44
 	prizes, err := m.GetPrizes(id)
52 45
 	if err != nil {
53
-		return nil, err
46
+		utils.LogError("获取奖品信息失败:", err)
47
+		return nil, errors.New("获取奖品信息失败")
54 48
 	}
55 49
 	luckdraw.Prizes = prizes
56 50
 	return luckdraw, nil
57 51
 }
58 52
 
59 53
 // LuckDraw 抽奖
60
-func (m *DAO) LuckDraw(id int, user *model.TaCustomer) (*model.TaLuckdrawPrize, *model.TaPrizeDetail, error) {
54
+func (m *LuckDrawDao) LuckDraw(id string, user *model.TaCustomer) (*model.TaLuckdrawPrize, *model.TaPrizeDetail, error) {
61 55
 	luckdraw, err := m.GetLuckDrawByID(id)
62 56
 	if err != nil {
63
-		return nil, nil, utils.LogError("获取抽奖信息失败!", err)
57
+		return nil, nil, errors.New("获取抽奖信息失败!")
64 58
 	}
65 59
 	if luckdraw.Status != models.STATUS_NORMAL {
66
-		return nil, nil, utils.LogError("当前抽奖活动状态异常!")
60
+		return nil, nil, errors.New("当前抽奖活动状态异常!")
67 61
 	}
68 62
 	if time.Now().Before(luckdraw.BeginDate) {
69
-		return nil, nil, utils.LogError("活动还未开始!")
63
+		return nil, nil, errors.New("活动还未开始!")
70 64
 	}
71 65
 	if time.Now().After(luckdraw.EndDate) {
72
-		return nil, nil, utils.LogError("活动已结束!")
66
+		return nil, nil, errors.New("活动已结束!")
73 67
 	}
74 68
 	if user.Phone != "" {
75 69
 		sysuser, err := m.GetUserByTel(user.Phone)
76 70
 		if err != nil {
77
-			return nil, nil, utils.LogError("获取信息失败!", err)
71
+			return nil, nil, errors.New("获取信息失败!")
78 72
 		}
79 73
 		if sysuser != nil {
80
-			return nil, nil, utils.LogError("内部人员不允许进行抽奖!")
74
+			return nil, nil, errors.New("内部人员不允许进行抽奖!")
81 75
 		}
82 76
 	}
83 77
 	userluckdraws, err := m.GetUserRecordByLuckDraw(user.CustomerId, id)
84 78
 	if err != nil {
85
-		return nil, nil, utils.LogError("获取用户抽奖信息失败!", err)
79
+		utils.LogError("获取用户抽奖信息失败:", err)
80
+		return nil, nil, errors.New("获取用户抽奖信息失败!")
86 81
 	}
87 82
 	if len(userluckdraws) > 0 {
88
-		return nil, nil, utils.LogError("您已参与过此次抽奖,不允许重复抽奖!")
83
+		return nil, nil, errors.New("您已参与过此次抽奖,不允许重复抽奖!")
89 84
 	}
90 85
 	prizes, err := m.GetPrizeStock(id)
91 86
 	if err != nil {
92
-		return nil, nil, utils.LogError("获取奖项失败!", err)
87
+		utils.LogError("获取奖项失败:", err)
88
+		return nil, nil, errors.New("获取奖项失败!")
93 89
 	}
94 90
 	if len(prizes) == 0 {
95 91
 		err = m.UpdateLuckDrawEndDate(luckdraw.Id)
96 92
 		if err != nil {
97
-			return nil, nil, utils.LogError("操作失败,请刷新后重试!", err)
93
+			utils.LogError("操作失败,请刷新后重试:", err)
94
+			return nil, nil, errors.New("操作失败,请刷新后重试!")
98 95
 		}
99
-		return nil, nil, utils.LogError("活动已结束!")
96
+		return nil, nil, errors.New("活动已结束!")
100 97
 	}
101 98
 	prize, err := m.GetWinning(prizes)
102 99
 	if err != nil {
103
-		return nil, nil, utils.LogError("获取奖项失败!", err)
100
+		utils.LogError("获取奖项失败:", err)
101
+		return nil, nil, errors.New("获取奖项失败!")
104 102
 	}
105 103
 
106
-	details, err := m.GetPrizeDetail(prize.Id)
107
-	if err != nil {
108
-		return nil, nil, utils.LogError("获取奖项详情失败!", err)
109
-	}
104
+	// details, err := m.GetPrizeDetail(prize.Id)
105
+	// if err != nil {
106
+	// 	utils.LogError("获取奖项详情失败:", err)
107
+	// 	return nil, nil, errors.New("获取奖项详情失败!")
108
+	// }
110 109
 
111 110
 	// 保存中奖记录
112 111
 	var record = model.TaLuckdrawRecord{}
112
+	record.Id = utils.GetGUID()
113 113
 	record.OrgId = luckdraw.OrgId
114 114
 	record.CaseId = luckdraw.CaseId
115 115
 	record.PrizeId = prize.Id
116 116
 	record.PrizeName = prize.PrizeName
117 117
 	record.UserId = user.CustomerId
118
-	record.UserName = user.Name
118
+	record.UserName = user.CustomerName
119 119
 	record.UserHeadImg = user.Headimgurl
120 120
 	record.LuckdrawId = luckdraw.Id
121
-	newrecord, err := m.SaveRecord(record)
122
-	var detail = model.TaPrizeDetail{}
123
-	if len(details) > 0 {
124
-		// 更新中奖纪录明细
125
-		details[0].ReceiveId = newrecord.Id
126
-		err = m.UpdatePrizeDetail(details[0])
127
-		if err != nil {
128
-			return nil, nil, utils.LogError("操作失败!", err)
129
-		}
130
-		detail = details[0]
131
-		// 奖项自动核销,走卡券核销流程
132
-		err = m.PrizeWriteOff(newrecord.Id, user.CustomerId)
133
-		if err != nil {
134
-			return nil, nil, utils.LogError("操作失败!", err)
135
-		}
136
-	}
121
+	_, err = m.SaveRecord(record)
122
+	// var detail = model.TaPrizeDetail{}
123
+	// if len(details) > 0 {
124
+	// 	// 更新中奖纪录明细
125
+	// 	details[0].ReceiveId = newrecord.Id
126
+	// 	err = m.UpdatePrizeDetail(details[0])
127
+	// 	if err != nil {
128
+	// 		utils.LogError("更新中奖纪录明细失败:", err)
129
+	// 		return nil, nil, errors.New("操作失败!")
130
+	// 	}
131
+	// 	detail = details[0]
132
+	// 	// 奖项自动核销,走卡券核销流程
133
+	// 	err = m.PrizeWriteOff(newrecord.Id, user.CustomerId)
134
+	// 	if err != nil {
135
+	// 		utils.LogError("卡券核销失败:", err)
136
+	// 		return nil, nil, errors.New("操作失败!")
137
+	// 	}
138
+	// }
137 139
 	// 更新库存
138 140
 	if prize.IsReality == 1 {
139 141
 		prize.Remainder = prize.Remainder - 1
@@ -143,7 +145,8 @@ func (m *DAO) LuckDraw(id int, user *model.TaCustomer) (*model.TaLuckdrawPrize,
143 145
 		}
144 146
 		stockprizes, err := m.GetPrizeStock(id)
145 147
 		if err != nil {
146
-			return nil, nil, utils.LogError("操作失败,请刷新后重试!", err)
148
+			utils.LogError("更新库存失败:", err)
149
+			return nil, nil, errors.New("操作失败,请刷新后重试!")
147 150
 		}
148 151
 		if len(stockprizes) == 0 {
149 152
 			// 更新活动截止时间
@@ -151,11 +154,11 @@ func (m *DAO) LuckDraw(id int, user *model.TaCustomer) (*model.TaLuckdrawPrize,
151 154
 		}
152 155
 	}
153 156
 
154
-	return prize, &detail, err
157
+	return prize, nil, err
155 158
 }
156 159
 
157 160
 // PrizeWriteOff 奖品核销
158
-func (m *DAO) PrizeWriteOff(recordid int, userid string) error {
161
+func (m *LuckDrawDao) PrizeWriteOff(recordid, userid string) error {
159 162
 	record, err := m.GetRecordByID(recordid)
160 163
 	if err != nil {
161 164
 		return err
@@ -175,7 +178,7 @@ func (m *DAO) PrizeWriteOff(recordid int, userid string) error {
175 178
 }
176 179
 
177 180
 // GetWinning 获取中奖信息
178
-func (m *DAO) GetWinning(prizes []model.TaLuckdrawPrize) (*model.TaLuckdrawPrize, error) {
181
+func (m *LuckDrawDao) GetWinning(prizes []model.TaLuckdrawPrize) (*model.TaLuckdrawPrize, error) {
179 182
 	pList := make([]map[string]interface{}, 0)
180 183
 	now := time.Now().Local()
181 184
 
@@ -192,7 +195,7 @@ func (m *DAO) GetWinning(prizes []model.TaLuckdrawPrize) (*model.TaLuckdrawPrize
192 195
 	}
193 196
 
194 197
 	if len(pList) == 0 {
195
-		return nil, utils.LogError("所有奖品已抽完")
198
+		return nil, errors.New("所有奖品已抽完")
196 199
 	}
197 200
 
198 201
 	thePrize := utils.LuckyDraw(pList).(model.TaLuckdrawPrize)
@@ -201,7 +204,7 @@ func (m *DAO) GetWinning(prizes []model.TaLuckdrawPrize) (*model.TaLuckdrawPrize
201 204
 }
202 205
 
203 206
 // GetLuckDrawByID 获取抽奖信息
204
-func (m *DAO) GetLuckDrawByID(id int) (*LuckDraw, error) {
207
+func (m *LuckDrawDao) GetLuckDrawByID(id string) (*LuckDraw, error) {
205 208
 	var luckdraws []LuckDraw
206 209
 	sql := `select * from ta_luckdraw where id= ?`
207 210
 	err := m.db.SQL(sql, id).Find(&luckdraws)
@@ -214,32 +217,8 @@ func (m *DAO) GetLuckDrawByID(id int) (*LuckDraw, error) {
214 217
 	return nil, nil
215 218
 }
216 219
 
217
-// GetCaseAddressByLuckDarw 获取案场地址
218
-func (m *DAO) GetCaseAddressByLuckDarw(luckdraw int) (string, error) {
219
-	sql := `
220
-		SELECT
221
-			t.address
222
-		FROM
223
-			sys_case t
224
-		INNER JOIN ta_luckdraw s ON t.case_id = s.case_id
225
-		WHERE
226
-			s.id = ?
227
-	`
228
-
229
-	res, err := m.db.Query(sql, luckdraw)
230
-	if err != nil {
231
-		return "", err
232
-	}
233
-
234
-	if res == nil || len(res) == 0 {
235
-		return "", nil
236
-	}
237
-
238
-	return string(res[0]["address"]), nil
239
-}
240
-
241 220
 // UpdateLuckDrawEndDate 更新活动结束时间
242
-func (m *DAO) UpdateLuckDrawEndDate(id int) error {
221
+func (m *LuckDrawDao) UpdateLuckDrawEndDate(id string) error {
243 222
 	var luckdraw = model.TaLuckdraw{
244 223
 		Id:      id,
245 224
 		EndDate: time.Now(),
@@ -252,14 +231,14 @@ func (m *DAO) UpdateLuckDrawEndDate(id int) error {
252 231
 }
253 232
 
254 233
 // GetPrizes 获取奖品信息
255
-func (m *DAO) GetPrizes(luckdrawid int) ([]model.TaLuckdrawPrize, error) {
234
+func (m *LuckDrawDao) GetPrizes(luckdrawid string) ([]model.TaLuckdrawPrize, error) {
256 235
 	var prizes []model.TaLuckdrawPrize
257 236
 	err := m.db.Where("luckdraw_id=?", luckdrawid).And("status=?", models.STATUS_NORMAL).Find(&prizes)
258 237
 	return prizes, err
259 238
 }
260 239
 
261 240
 // UpdateStock 修改库存
262
-func (m *DAO) UpdateStock(prize *model.TaLuckdrawPrize) error {
241
+func (m *LuckDrawDao) UpdateStock(prize *model.TaLuckdrawPrize) error {
263 242
 	cols := []string{
264 243
 		"remainder",
265 244
 	}
@@ -268,36 +247,44 @@ func (m *DAO) UpdateStock(prize *model.TaLuckdrawPrize) error {
268 247
 }
269 248
 
270 249
 // GetPrizeStock 判断奖项库存
271
-func (m *DAO) GetPrizeStock(luckdrawid int) ([]model.TaLuckdrawPrize, error) {
250
+func (m *LuckDrawDao) GetPrizeStock(luckdrawid string) ([]model.TaLuckdrawPrize, error) {
272 251
 	var prizes []model.TaLuckdrawPrize
273 252
 	err := m.db.Where("luckdraw_id=?", luckdrawid).And("status=?", models.STATUS_NORMAL).And("(remainder>0 or is_reality=0)").Find(&prizes)
274 253
 	return prizes, err
275 254
 }
276 255
 
277 256
 // GetPrizeByID 根据id获取奖品信息
278
-func (m *DAO) GetPrizeByID(id int) (model.TaLuckdrawPrize, error) {
257
+func (m *LuckDrawDao) GetPrizeByID(id int) (model.TaLuckdrawPrize, error) {
279 258
 	var prize = model.TaLuckdrawPrize{}
280 259
 	_, err := m.db.Where("id=?", id).Get(&prize)
281 260
 	return prize, err
282 261
 }
283 262
 
284 263
 // SaveRecord 保存抽奖记录
285
-func (m *DAO) SaveRecord(record model.TaLuckdrawRecord) (*model.TaLuckdrawRecord, error) {
264
+func (m *LuckDrawDao) SaveRecord(record model.TaLuckdrawRecord) (*model.TaLuckdrawRecord, error) {
286 265
 	record.CreateDate = time.Now()
287
-	record.Status = STATUS_NOWRITROFF
266
+	record.Status = models.STATUS_READY
267
+	record.Id = utils.GetGUID()
288 268
 	_, err := m.db.Insert(&record)
289 269
 	return &record, err
290 270
 }
291 271
 
272
+// GetUserByTel 根据电话获取用户信息
273
+func (m *LuckDrawDao) GetUserByTel(tel string) (*model.SysUser, error) {
274
+	var user = model.SysUser{}
275
+	_, err := m.db.Where("phone=?", tel).Get(&user)
276
+	return &user, err
277
+}
278
+
292 279
 // GetPrizeDetail 获取未领取的奖品详情
293
-func (m *DAO) GetPrizeDetail(prizeid int) ([]model.TaPrizeDetail, error) {
280
+func (m *LuckDrawDao) GetPrizeDetail(prizeid string) ([]model.TaPrizeDetail, error) {
294 281
 	var details []model.TaPrizeDetail
295
-	err := m.db.Where("prize_id=?", prizeid).And("status=?", STATUS_NOWRITROFF).Find(&details)
282
+	err := m.db.Where("prize_id=?", prizeid).And("status=?", models.STATUS_READY).Find(&details)
296 283
 	return details, err
297 284
 }
298 285
 
299 286
 // UpdatePrizeDetail 更新库存明细为已领取
300
-func (m *DAO) UpdatePrizeDetail(detail model.TaPrizeDetail) error {
287
+func (m *LuckDrawDao) UpdatePrizeDetail(detail model.TaPrizeDetail) error {
301 288
 	detail.Status = models.STATUS_NORMAL
302 289
 	detail.ReceiveDate = time.Now()
303 290
 	cols := []string{
@@ -310,7 +297,7 @@ func (m *DAO) UpdatePrizeDetail(detail model.TaPrizeDetail) error {
310 297
 }
311 298
 
312 299
 // UpdateRecord 核销更新抽奖记录表
313
-func (m *DAO) UpdateRecord(record *model.TaLuckdrawRecord) error {
300
+func (m *LuckDrawDao) UpdateRecord(record *model.TaLuckdrawRecord) error {
314 301
 	record.Status = models.STATUS_NORMAL
315 302
 	record.WriteoffDate = time.Now()
316 303
 	cols := []string{
@@ -322,22 +309,23 @@ func (m *DAO) UpdateRecord(record *model.TaLuckdrawRecord) error {
322 309
 }
323 310
 
324 311
 // SaveWirteOff 保存核销信息
325
-func (m *DAO) SaveWirteOff(writeoff model.TaLuckdrawWriteoff) (*model.TaLuckdrawWriteoff, error) {
312
+func (m *LuckDrawDao) SaveWirteOff(writeoff model.TaLuckdrawWriteoff) (*model.TaLuckdrawWriteoff, error) {
326 313
 	writeoff.Status = models.STATUS_NORMAL
314
+	writeoff.Id = utils.GetGUID()
327 315
 	writeoff.WriteoffDate = time.Now()
328 316
 	_, err := m.db.Insert(&writeoff)
329 317
 	return &writeoff, err
330 318
 }
331 319
 
332 320
 // GetUserRecordByLuckDraw 获取用户的抽奖信息
333
-func (m *DAO) GetUserRecordByLuckDraw(userid string, luckdrawid int) ([]model.TaLuckdrawRecord, error) {
321
+func (m *LuckDrawDao) GetUserRecordByLuckDraw(userid string, luckdrawid string) ([]model.TaLuckdrawRecord, error) {
334 322
 	var records []model.TaLuckdrawRecord
335 323
 	err := m.db.Where("user_id=?", userid).And("luckdraw_id=?", luckdrawid).And("status>" + strconv.Itoa(models.STATUS_DEL)).Find(&records)
336 324
 	return records, err
337 325
 }
338 326
 
339 327
 // GetUserLuckDrawByLuckDraw 获取用户的抽奖信息
340
-func (m *DAO) GetUserLuckDrawByLuckDraw(userid string, luckdrawid int) (*model.TaLuckdrawRecord, error) {
328
+func (m *LuckDrawDao) GetUserLuckDrawByLuckDraw(userid string, luckdrawid string) (*model.TaLuckdrawRecord, error) {
341 329
 	var records []model.TaLuckdrawRecord
342 330
 	err := m.db.Where("user_id=?", userid).And("luckdraw_id=?", luckdrawid).And("status>" + strconv.Itoa(models.STATUS_DEL)).Find(&records)
343 331
 	if err != nil {
@@ -350,7 +338,7 @@ func (m *DAO) GetUserLuckDrawByLuckDraw(userid string, luckdrawid int) (*model.T
350 338
 }
351 339
 
352 340
 // GetDetailByRecord 获取detail
353
-func (m *DAO) GetDetailByRecord(recordid int) (*model.TaPrizeDetail, error) {
341
+func (m *LuckDrawDao) GetDetailByRecord(recordid string) (*model.TaPrizeDetail, error) {
354 342
 	var details []model.TaPrizeDetail
355 343
 	err := m.db.Where("receive_id=?", recordid).And("status>" + strconv.Itoa(models.STATUS_DEL)).Find(&details)
356 344
 	if err != nil {
@@ -369,7 +357,7 @@ type UserRecord struct {
369 357
 }
370 358
 
371 359
 // GetUserLuckDraw 获取用户的抽奖信息
372
-func (m *DAO) GetUserLuckDraw(userid string) ([]UserRecord, error) {
360
+func (m *LuckDrawDao) GetUserLuckDraw(userid string) ([]UserRecord, error) {
373 361
 	var records []UserRecord
374 362
 	sql := `select a.*,b.url from ta_luckdraw_record a left join ta_prize_detail b on a.id=b.receive_id where a.user_id=? and a.status>` + strconv.Itoa(models.STATUS_DEL)
375 363
 	err := m.db.Sql(sql, userid).Find(&records)
@@ -377,49 +365,24 @@ func (m *DAO) GetUserLuckDraw(userid string) ([]UserRecord, error) {
377 365
 }
378 366
 
379 367
 // GetRecordByLuckDraw 抽奖记录
380
-func (m *DAO) GetRecordByLuckDraw(luckdrawid int) ([]model.TaLuckdrawRecord, error) {
368
+func (m *LuckDrawDao) GetRecordByLuckDraw(luckdrawid string) ([]model.TaLuckdrawRecord, error) {
381 369
 	var records []model.TaLuckdrawRecord
382 370
 	err := m.db.Where("luckdraw_id=?", luckdrawid).And("status>" + strconv.Itoa(models.STATUS_DEL)).Desc("create_date").Find(&records)
383 371
 	return records, err
384 372
 }
385 373
 
386 374
 // GetRecordByID 获取抽奖记录明细
387
-func (m *DAO) GetRecordByID(id int) (*model.TaLuckdrawRecord, error) {
375
+func (m *LuckDrawDao) GetRecordByID(id string) (*model.TaLuckdrawRecord, error) {
388 376
 	var record model.TaLuckdrawRecord
389 377
 	_, err := m.db.Where("id=?", id).Get(&record)
390 378
 	return &record, err
391 379
 }
392 380
 
393
-// GetUserByOpenID 根据 openid 获取用户人员信息
394
-func (m *DAO) GetUserByOpenID(openid string) (*model.SysUser, error) {
395
-	var users []model.SysUser
396
-	err := m.db.Where("open_id=?", openid).Find(&users)
397
-	if err != nil {
398
-		return nil, err
399
-	}
400
-	if len(users) > 0 {
401
-		return &users[0], nil
402
-	}
403
-	return nil, nil
404
-}
405
-
406
-// GetUserByTel 根据 Tel 获取用户人员信息
407
-func (m *DAO) GetUserByTel(tel string) (*model.SysUser, error) {
408
-	var users = model.SysUser{}
409
-	has, err := m.db.Where("phone=?", tel).Get(&users)
410
-	if err != nil {
411
-		return nil, err
412
-	}
413
-	if !has {
414
-		return nil, nil
415
-	}
416
-	return &users, nil
417
-}
418
-
419 381
 // SaveLuckDrawShareData 保存用户分享信息
420
-func (m *DAO) SaveLuckDrawShareData(dt *model.TaShareLuckyRecord) error {
382
+func (m *LuckDrawDao) SaveLuckDrawShareData(dt *model.TaShareLuckyRecord) error {
421 383
 	dt.CreateDate = time.Now().Local()
422
-	dt.Status = StatusNormal
384
+	dt.Status = models.STATUS_NORMAL
385
+	dt.Id = utils.GetGUID()
423 386
 
424 387
 	if _, err := m.db.Insert(dt); err != nil {
425 388
 		return err
@@ -429,14 +392,14 @@ func (m *DAO) SaveLuckDrawShareData(dt *model.TaShareLuckyRecord) error {
429 392
 }
430 393
 
431 394
 // GetLuckDrawShareData 获取用户分享内容
432
-func (m *DAO) GetLuckDrawShareData(luckID int, from, to, caseID string) ([]model.TaShareLuckyRecord, error) {
395
+func (m *LuckDrawDao) GetLuckDrawShareData(from, to, luckID, caseID int) ([]model.TaShareLuckyRecord, error) {
433 396
 	var dts []model.TaShareLuckyRecord
434 397
 
435 398
 	if err := m.db.Where("from_customer_id=?", from).
436 399
 		And("to_customer_id=?", to).
437 400
 		And("luckydraw_id=?", luckID).
438 401
 		And("case_id=?", caseID).
439
-		And("status=?", StatusNormal).
402
+		And("status=?", models.STATUS_NORMAL).
440 403
 		Find(&dts); err != nil {
441 404
 		return nil, err
442 405
 	}

+ 4
- 4
models/model/ta_body_check.go 查看文件

@@ -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      string    `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 查看文件

@@ -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_luckdraw.go 查看文件

@@ -5,9 +5,9 @@ import (
5 5
 )
6 6
 
7 7
 type TaLuckdraw struct {
8
-	Id           int       `xorm:"not null pk autoincr INT(11)"`
8
+	Id           string    `xorm:"not null pk VARCHAR(64)"`
9 9
 	Name         string    `xorm:"VARCHAR(50)"`
10
-	ThemeId      int       `xorm:"INT(11)"`
10
+	ThemeId      string    `xorm:"VARCHAR(64)"`
11 11
 	LuckdrawRule string    `xorm:"TEXT"`
12 12
 	BeginDate    time.Time `xorm:"DATETIME"`
13 13
 	EndDate      time.Time `xorm:"DATETIME"`

+ 2
- 2
models/model/ta_luckdraw_prize.go 查看文件

@@ -5,8 +5,8 @@ import (
5 5
 )
6 6
 
7 7
 type TaLuckdrawPrize struct {
8
-	Id                int       `xorm:"not null pk autoincr INT(11)"`
9
-	LuckdrawId        int       `xorm:"INT(11)"`
8
+	Id                string    `xorm:"not null pk VARCHAR(64)"`
9
+	LuckdrawId        string    `xorm:"VARCHAR(64)"`
10 10
 	PrizeName         string    `xorm:"VARCHAR(50)"`
11 11
 	PrizeImg          string    `xorm:"TEXT"`
12 12
 	Stock             int       `xorm:"INT(11)"`

+ 3
- 3
models/model/ta_luckdraw_record.go 查看文件

@@ -5,9 +5,9 @@ import (
5 5
 )
6 6
 
7 7
 type TaLuckdrawRecord struct {
8
-	Id           int       `xorm:"not null pk autoincr INT(11)"`
9
-	LuckdrawId   int       `xorm:"INT(11)"`
10
-	PrizeId      int       `xorm:"INT(11)"`
8
+	Id           string    `xorm:"not null pk VARCHAR(64)"`
9
+	LuckdrawId   string    `xorm:"VARCHAR(64)"`
10
+	PrizeId      string    `xorm:"VARCHAR(64)"`
11 11
 	PrizeName    string    `xorm:"VARCHAR(50)"`
12 12
 	UserId       string    `xorm:"VARCHAR(64)"`
13 13
 	UserName     string    `xorm:"VARCHAR(50)"`

+ 3
- 3
models/model/ta_luckdraw_writeoff.go 查看文件

@@ -5,9 +5,9 @@ import (
5 5
 )
6 6
 
7 7
 type TaLuckdrawWriteoff struct {
8
-	Id           int       `xorm:"not null pk autoincr INT(11)"`
9
-	LuckdrawId   int       `xorm:"INT(11)"`
10
-	RecordId     int       `xorm:"INT(11)"`
8
+	Id           string    `xorm:"not null pk VARCHAR(64)"`
9
+	LuckdrawId   string    `xorm:"VARCHAR(64)"`
10
+	RecordId     string    `xorm:"VARCHAR(64)"`
11 11
 	WriteoffDate time.Time `xorm:"DATETIME"`
12 12
 	WriteoffUser string    `xorm:"VARCHAR(64)"`
13 13
 	Status       int       `xorm:"SMALLINT(6)"`

+ 2
- 2
models/model/ta_presentation.go 查看文件

@@ -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 查看文件

@@ -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)"`

+ 3
- 3
models/model/ta_prize_detail.go 查看文件

@@ -5,10 +5,10 @@ import (
5 5
 )
6 6
 
7 7
 type TaPrizeDetail struct {
8
-	Id          int       `xorm:"not null pk autoincr INT(11)"`
9
-	PrizeId     int       `xorm:"INT(11)"`
8
+	Id          string    `xorm:"not null pk VARCHAR(64)"`
9
+	PrizeId     string    `xorm:"VARCHAR(64)"`
10 10
 	Url         string    `xorm:"TEXT"`
11 11
 	Status      int       `xorm:"SMALLINT(6)"`
12
-	ReceiveId   int       `xorm:"INT(11)"`
12
+	ReceiveId   string    `xorm:"VARCHAR(64)"`
13 13
 	ReceiveDate time.Time `xorm:"DATETIME"`
14 14
 }

+ 2
- 2
models/model/ta_share_lucky_record.go 查看文件

@@ -5,7 +5,7 @@ import (
5 5
 )
6 6
 
7 7
 type TaShareLuckyRecord struct {
8
-	Id                 int       `xorm:"not null pk autoincr INT(11)"`
8
+	Id                 string    `xorm:"not null pk VARCHAR(64)"`
9 9
 	FromCustomerId     string    `xorm:"VARCHAR(64)"`
10 10
 	FromCustomerName   string    `xorm:"VARCHAR(32)"`
11 11
 	FromCustomerWxname string    `xorm:"VARCHAR(64)"`
@@ -17,6 +17,6 @@ type TaShareLuckyRecord struct {
17 17
 	CreateDate         time.Time `xorm:"DATETIME"`
18 18
 	CaseId             string    `xorm:"VARCHAR(64)"`
19 19
 	Status             int       `xorm:"SMALLINT(6)"`
20
-	LuckydrawId        int       `xorm:"INT(11)"`
20
+	LuckydrawId        string    `xorm:"VARCHAR(64)"`
21 21
 	LuckydrawName      string    `xorm:"VARCHAR(128)"`
22 22
 }

+ 9
- 0
models/model/ta_sta_arrived_daily.go 查看文件

@@ -0,0 +1,9 @@
1
+package model
2
+
3
+type TaStaArrivedDaily struct {
4
+	Id      int    `xorm:"not null pk autoincr INT(11)"`
5
+	OrgId   string `xorm:"VARCHAR(64)"`
6
+	CaseId  string `xorm:"VARCHAR(64)"`
7
+	StaDate string `xorm:"VARCHAR(20)"`
8
+	Amount  int    `xorm:"INT(11)"`
9
+}

+ 9
- 0
models/model/ta_sta_course_daily.go 查看文件

@@ -0,0 +1,9 @@
1
+package model
2
+
3
+type TaStaCourseDaily struct {
4
+	Id      int    `xorm:"not null pk autoincr INT(11)"`
5
+	OrgId   string `xorm:"VARCHAR(64)"`
6
+	CaseId  string `xorm:"VARCHAR(64)"`
7
+	StaDate string `xorm:"VARCHAR(20)"`
8
+	Amount  int    `xorm:"INT(11)"`
9
+}

+ 11
- 0
models/model/ta_sta_course_order_daily.go 查看文件

@@ -0,0 +1,11 @@
1
+package model
2
+
3
+type TaStaCourseOrderDaily struct {
4
+	Id         int    `xorm:"not null pk autoincr INT(11)"`
5
+	OrgId      string `xorm:"VARCHAR(64)"`
6
+	CaseId     string `xorm:"VARCHAR(64)"`
7
+	StaDate    string `xorm:"VARCHAR(20)"`
8
+	CourseType string `xorm:"VARCHAR(64)"`
9
+	TypeName   string `xorm:"VARCHAR(255)"`
10
+	Amount     int    `xorm:"INT(11)"`
11
+}

+ 9
- 0
models/model/ta_sta_customer_daily.go 查看文件

@@ -0,0 +1,9 @@
1
+package model
2
+
3
+type TaStaCustomerDaily struct {
4
+	Id      int    `xorm:"not null pk autoincr INT(11)"`
5
+	OrgId   string `xorm:"VARCHAR(64)"`
6
+	CaseId  string `xorm:"VARCHAR(64)"`
7
+	StaDate string `xorm:"VARCHAR(20)"`
8
+	Amount  int    `xorm:"INT(11)"`
9
+}

+ 11
- 0
models/model/ta_sta_goods_daily.go 查看文件

@@ -0,0 +1,11 @@
1
+package model
2
+
3
+type TaStaGoodsDaily struct {
4
+	Id       int    `xorm:"not null pk autoincr INT(11)"`
5
+	OrgId    string `xorm:"VARCHAR(64)"`
6
+	CaseId   string `xorm:"VARCHAR(64)"`
7
+	StaDate  string `xorm:"VARCHAR(20)"`
8
+	UserType string `xorm:"VARCHAR(20)"`
9
+	TypeName string `xorm:"VARCHAR(255)"`
10
+	Amount   int    `xorm:"INT(11)"`
11
+}

+ 1
- 1
models/model/td_check_spec.go 查看文件

@@ -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 查看文件

@@ -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
 }

+ 1
- 1
models/model/td_luckdraw_theme.go 查看文件

@@ -1,7 +1,7 @@
1 1
 package model
2 2
 
3 3
 type TdLuckdrawTheme struct {
4
-	Id        int    `xorm:"not null pk autoincr INT(11)"`
4
+	Id        string `xorm:"not null pk VARCHAR(64)"`
5 5
 	ThemeName string `xorm:"VARCHAR(50)"`
6 6
 	Status    int    `xorm:"SMALLINT(6)"`
7 7
 	OrgId     string `xorm:"VARCHAR(64)"`

+ 1
- 0
models/model/td_statistics_comps.go 查看文件

@@ -5,4 +5,5 @@ type TdStatisticsComps struct {
5 5
 	CompName string `xorm:"VARCHAR(255)"`
6 6
 	CompType string `xorm:"VARCHAR(64)"`
7 7
 	TypeName string `xorm:"VARCHAR(255)"`
8
+	Group    int    `xorm:"SMALLINT(6)"`
8 9
 }

+ 7
- 7
models/statistics/cardcoupon.go 查看文件

@@ -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 查看文件

@@ -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
 }

+ 418
- 0
models/statistics/dashboard.go 查看文件

@@ -0,0 +1,418 @@
1
+package statistics
2
+
3
+import (
4
+	"spaceofcheng/services/models"
5
+	"strconv"
6
+	"strings"
7
+	"time"
8
+)
9
+
10
+var sqlThisWeek = `
11
+SELECT
12
+	DATE_FORMAT(
13
+		date_add(
14
+			date_sub(
15
+				curdate(),
16
+				INTERVAL WEEKDAY(curdate()) + 1 DAY
17
+			),
18
+			INTERVAL rownum DAY
19
+		),
20
+		'%Y-%m-%d'
21
+	) AS dt
22
+FROM sequence
23
+WHERE rownum < 7
24
+`
25
+
26
+var sqlThisMonth = `
27
+SELECT
28
+	DATE_FORMAT(
29
+		DATE_add(
30
+			DATE_add(
31
+				LAST_DAY(curdate() - INTERVAL 1 MONTH),
32
+				INTERVAL 1 DAY
33
+			),
34
+			INTERVAL rownum DAY
35
+		),
36
+		'%Y-%m-%d'
37
+	) AS dt
38
+FROM
39
+	sequence
40
+WHERE
41
+	rownum < (
42
+		SELECT
43
+			DATEDIFF(
44
+				date_add(
45
+					curdate() - DAY (curdate()) + 1,
46
+					INTERVAL 1 MONTH
47
+				),
48
+				DATE_ADD(
49
+					curdate(),
50
+					INTERVAL - DAY (curdate()) + 1 DAY
51
+				)
52
+			)
53
+	)
54
+`
55
+
56
+// GetCustomerNumber 获取会员数量
57
+func (m *StatisticsDAO) GetCustomerNumber(orgID string, caseIDs []string, start, end *time.Time) (int64, error) {
58
+	return m.execMySQLFunc("fun_total_customer", orgID, caseIDs, start, end)
59
+}
60
+
61
+// GetCourseOrderNumber 获取课程预约 - 统计课程
62
+func (m *StatisticsDAO) GetCourseOrderNumber(orgID string, caseIDs []string, start, end *time.Time) (int64, error) {
63
+	return m.execMySQLFunc("fun_course_order", orgID, caseIDs, start, end)
64
+}
65
+
66
+// GetCourseOrderCustomer 获取课程预约 - 统计人员
67
+func (m *StatisticsDAO) GetCourseOrderCustomer(orgID string, caseIDs []string, start, end *time.Time) (int64, error) {
68
+	return m.execMySQLFunc("fun_course_order_customer", orgID, caseIDs, start, end)
69
+}
70
+
71
+// GetUsedCourseOrderCustomer 获取课程核销 - 统计人员
72
+func (m *StatisticsDAO) GetUsedCourseOrderCustomer(orgID string, caseIDs []string, start, end *time.Time) (int64, error) {
73
+	return m.execMySQLFunc("fun_used_course_order_customer", orgID, caseIDs, start, end)
74
+}
75
+
76
+// GetOrderGoodsNumber 获取商品下单数量
77
+func (m *StatisticsDAO) GetOrderGoodsNumber(orgID string, caseIDs []string, start, end *time.Time) (int64, error) {
78
+	return m.execMySQLFunc("fun_order_goods_num", orgID, caseIDs, start, end)
79
+}
80
+
81
+// GetCourseNumber 获取课程数量
82
+func (m *StatisticsDAO) GetCourseNumber(orgID string, caseIDs []string, start, end *time.Time) (int64, error) {
83
+	return m.execMySQLFunc("fun_total_course", orgID, caseIDs, start, end)
84
+}
85
+
86
+// GetArrivedCustomerNumber 获取到场人数
87
+func (m *StatisticsDAO) GetArrivedCustomerNumber(orgID string, caseIDs []string, start, end *time.Time) (int64, error) {
88
+	return m.execMySQLFunc("fun_arrived_customer", orgID, caseIDs, start, end)
89
+}
90
+
91
+// GetCourseCardCustomer 获取预约人数 - 含健身卡
92
+func (m *StatisticsDAO) GetCourseCardCustomer(orgID string, caseIDs []string, start, end *time.Time) (int64, error) {
93
+	return m.execMySQLFunc("fun_course_card_customer", orgID, caseIDs, start, end)
94
+}
95
+
96
+// GetCouponCardNumber 获取卡券总数
97
+func (m *StatisticsDAO) GetCouponCardNumber(orgID string, caseIDs []string, start, end *time.Time) (int64, error) {
98
+	return m.execMySQLFunc("fun_total_coupon_card", orgID, caseIDs, start, end)
99
+}
100
+
101
+// GetUsedCouponCardNumber 获取已使用卡券
102
+func (m *StatisticsDAO) GetUsedCouponCardNumber(orgID string, caseIDs []string, start, end *time.Time) (int64, error) {
103
+	return m.execMySQLFunc("fun_used_coupon_card", orgID, caseIDs, start, end)
104
+}
105
+
106
+// GetCustomerCouponCardNumber 获取已发放卡券总数
107
+func (m *StatisticsDAO) GetCustomerCouponCardNumber(orgID string, caseIDs []string, start, end *time.Time) (int64, error) {
108
+	return m.execMySQLFunc("fun_total_customer_coupon_card", orgID, caseIDs, start, end)
109
+}
110
+
111
+// StaCommData 折线图 或 柱图类数据
112
+type StaCommData struct {
113
+	Dt     string `json:"x"`
114
+	Amount int    `json:"y"`
115
+}
116
+
117
+// StaCommGroupData 折线图 或 柱图类数据 含分组
118
+type StaCommGroupData struct {
119
+	Dt     string `json:"x"`
120
+	Amount int    `json:"y"`
121
+	Group  string `json:"g"`
122
+}
123
+
124
+// StaPieData 饼图类数据
125
+type StaPieData struct {
126
+	Item    string  `json:"item"`
127
+	Amount  int     `json:"count"`
128
+	Percent float64 `json:"percent"`
129
+}
130
+
131
+// GetCourseOrderPie 获取预约课程
132
+func (m *StatisticsDAO) GetCourseOrderPie(orgID string, caseIDs []string, start, end *time.Time) ([]StaPieData, error) {
133
+	sql := `
134
+		SELECT
135
+			t.course_name AS item,
136
+			count(DISTINCT course_id) AS amount,
137
+			0.0 AS percent
138
+		FROM
139
+			ta_customer_course_detail t
140
+		WHERE
141
+			t.status = ?
142
+			AND t.org_id = ?
143
+	`
144
+	if caseIDs != nil && len(caseIDs) > 0 {
145
+		sql += ` AND t.case_id in ('` + strings.Join(caseIDs, "','") + `')`
146
+	}
147
+
148
+	startDate := ""
149
+	endDate := ""
150
+
151
+	if start != nil {
152
+		startDate = start.Format("2006-01-02 15:04:05")
153
+	}
154
+	if end != nil {
155
+		endDate = end.Format("2006-01-02 15:04:05")
156
+	}
157
+
158
+	if startDate != "" {
159
+		sql += ` AND DATE_FORMAT(t.start_date, '%Y-%m-%d %T') >= '` + startDate + `'`
160
+	}
161
+
162
+	if endDate != "" {
163
+		sql += ` AND DATE_FORMAT(t.start_date, '%Y-%m-%d %T') <= '` + endDate + `'`
164
+	}
165
+
166
+	sql += `		
167
+		GROUP BY
168
+			t.course_name
169
+	`
170
+
171
+	var data []StaPieData
172
+	if err := m.db.SQL(sql, models.STATUS_NORMAL, orgID).Find(&data); err != nil {
173
+		return nil, err
174
+	}
175
+
176
+	if data == nil || len(data) == 0 {
177
+		return nil, nil
178
+	}
179
+
180
+	total := 0
181
+	for _, dt := range data {
182
+		total += dt.Amount
183
+	}
184
+
185
+	if total != 0 {
186
+		for i := range data {
187
+			data[i].Percent = float64(data[i].Amount / total)
188
+		}
189
+	}
190
+
191
+	return data, nil
192
+}
193
+
194
+// GetNewCustomerDaily 按天统计新增会员
195
+func (m *StatisticsDAO) GetNewCustomerDaily(orgID string, caseIDs []string, staType string) ([]StaCommData, error) {
196
+	sql := `
197
+		SELECT
198
+			t.dt,
199
+			IFNULL(s.amount, 0) AS amount
200
+		FROM (
201
+	`
202
+
203
+	if staType == "week" {
204
+		sql += sqlThisWeek
205
+	} else {
206
+		sql += sqlThisMonth
207
+	}
208
+
209
+	sql += `) t
210
+		LEFT JOIN ta_sta_customer_daily s ON t.dt = s.sta_date
211
+		AND s.org_id = '` + orgID + `'
212
+	`
213
+
214
+	if caseIDs != nil && len(caseIDs) > 0 {
215
+		sql += ` AND case_id in ('` + strings.Join(caseIDs, "','") + `')`
216
+	}
217
+
218
+	var res []StaCommData
219
+	if err := m.db.SQL(sql).Find(&res); err != nil {
220
+		return nil, err
221
+	}
222
+
223
+	return res, nil
224
+}
225
+
226
+// GetCourseDaily 按天统计排课数
227
+func (m *StatisticsDAO) GetCourseDaily(orgID string, caseIDs []string, staType string) ([]StaCommData, error) {
228
+	sql := `
229
+		SELECT
230
+			t.dt,
231
+			IFNULL(s.amount, 0) AS amount
232
+		FROM (
233
+	`
234
+
235
+	if staType == "week" {
236
+		sql += sqlThisWeek
237
+	} else {
238
+		sql += sqlThisMonth
239
+	}
240
+
241
+	sql += `) t
242
+		LEFT JOIN ta_sta_course_daily s ON t.dt = s.sta_date
243
+		AND s.org_id = '` + orgID + `'
244
+	`
245
+
246
+	if caseIDs != nil && len(caseIDs) > 0 {
247
+		sql += ` AND case_id in ('` + strings.Join(caseIDs, "','") + `')`
248
+	}
249
+
250
+	var res []StaCommData
251
+	if err := m.db.SQL(sql).Find(&res); err != nil {
252
+		return nil, err
253
+	}
254
+
255
+	return res, nil
256
+}
257
+
258
+// GetCourseOrderDaily 按天统计课程预约数
259
+func (m *StatisticsDAO) GetCourseOrderDaily(orgID string, caseIDs []string, staType string) ([]StaCommData, error) {
260
+	sql := `
261
+		SELECT
262
+			t.dt,
263
+			sum(IFNULL(s.amount, 0)) AS amount
264
+		FROM (
265
+	`
266
+
267
+	if staType == "week" {
268
+		sql += sqlThisWeek
269
+	} else {
270
+		sql += sqlThisMonth
271
+	}
272
+
273
+	sql += `) t
274
+		LEFT JOIN ta_sta_course_order_daily s ON t.dt = s.sta_date
275
+		AND s.org_id = '` + orgID + `'
276
+	`
277
+
278
+	if caseIDs != nil && len(caseIDs) > 0 {
279
+		sql += ` AND case_id in ('` + strings.Join(caseIDs, "','") + `')`
280
+	}
281
+
282
+	sql += ` group by t.dt`
283
+
284
+	var res []StaCommData
285
+	if err := m.db.SQL(sql).Find(&res); err != nil {
286
+		return nil, err
287
+	}
288
+
289
+	return res, nil
290
+}
291
+
292
+// GetGoodsDaily 按天统计饮品下单数
293
+func (m *StatisticsDAO) GetGoodsDaily(orgID string, caseIDs []string, staType string) ([]StaCommData, error) {
294
+	sql := `
295
+		SELECT
296
+			t.dt,
297
+			sum(IFNULL(s.amount, 0)) AS amount
298
+		FROM (
299
+	`
300
+
301
+	if staType == "week" {
302
+		sql += sqlThisWeek
303
+	} else {
304
+		sql += sqlThisMonth
305
+	}
306
+
307
+	sql += `) t
308
+		LEFT JOIN ta_sta_goods_daily s ON t.dt = s.sta_date
309
+		AND s.org_id = '` + orgID + `'
310
+	`
311
+
312
+	if caseIDs != nil && len(caseIDs) > 0 {
313
+		sql += ` AND case_id in ('` + strings.Join(caseIDs, "','") + `')`
314
+	}
315
+
316
+	sql += ` group by t.dt`
317
+
318
+	var res []StaCommData
319
+	if err := m.db.SQL(sql).Find(&res); err != nil {
320
+		return nil, err
321
+	}
322
+
323
+	return res, nil
324
+}
325
+
326
+// GetGoodsWithTypeDaily 按天分组统计饮品下单数
327
+func (m *StatisticsDAO) GetGoodsWithTypeDaily(orgID string, caseIDs []string) ([]StaCommGroupData, error) {
328
+	sql := `
329
+		SELECT
330
+			t.dt,
331
+			s.type_name as group,
332
+			sum(IFNULL(s.amount, 0)) AS amount
333
+		FROM (
334
+	`
335
+
336
+	sql += sqlThisMonth + `) t
337
+		LEFT JOIN ta_sta_goods_daily s ON t.dt = s.sta_date
338
+		AND s.org_id = '` + orgID + `'
339
+	`
340
+
341
+	if caseIDs != nil && len(caseIDs) > 0 {
342
+		sql += ` AND case_id in ('` + strings.Join(caseIDs, "','") + `')`
343
+	}
344
+
345
+	sql += ` group by t.dt, s.type_name`
346
+
347
+	var res []StaCommGroupData
348
+	if err := m.db.SQL(sql).Find(&res); err != nil {
349
+		return nil, err
350
+	}
351
+
352
+	return res, nil
353
+}
354
+
355
+// GetArrivedDaily 按天统计到场人次
356
+func (m *StatisticsDAO) GetArrivedDaily(orgID string, caseIDs []string, staType string) ([]StaCommData, error) {
357
+	sql := `
358
+		SELECT
359
+			t.dt,
360
+			IFNULL(s.amount, 0) AS amount
361
+		FROM (
362
+	`
363
+
364
+	if staType == "week" {
365
+		sql += sqlThisWeek
366
+	} else {
367
+		sql += sqlThisMonth
368
+	}
369
+
370
+	sql += `) t
371
+		LEFT JOIN ta_sta_arrived_daily s ON t.dt = s.sta_date
372
+		AND s.org_id = '` + orgID + `'
373
+	`
374
+
375
+	if caseIDs != nil && len(caseIDs) > 0 {
376
+		sql += ` AND case_id in ('` + strings.Join(caseIDs, "','") + `')`
377
+	}
378
+
379
+	sql += ` group by t.dt`
380
+
381
+	var res []StaCommData
382
+	if err := m.db.SQL(sql).Find(&res); err != nil {
383
+		return nil, err
384
+	}
385
+
386
+	return res, nil
387
+}
388
+
389
+// execMySQLFunc 执行 mysql 函数
390
+func (m *StatisticsDAO) execMySQLFunc(funName, orgID string, caseIDs []string, start, end *time.Time) (int64, error) {
391
+	csids := ""
392
+	if caseIDs == nil && len(caseIDs) == 0 {
393
+		csids = strings.Join(caseIDs, ",")
394
+	}
395
+
396
+	startDate := ""
397
+	endDate := ""
398
+
399
+	if start != nil {
400
+		startDate = start.Format("2006-01-02 15:04:05")
401
+	}
402
+	if end != nil {
403
+		endDate = end.Format("2006-01-02 15:04:05")
404
+	}
405
+
406
+	sql := "select " + funName + "(?,?,?,?) as total"
407
+	res, err := m.db.Query(sql, orgID, csids, startDate, endDate)
408
+	if err != nil {
409
+		return 0, err
410
+	}
411
+
412
+	if res == nil || len(res) == 0 {
413
+		return 0, nil
414
+	}
415
+
416
+	total, _ := strconv.ParseInt(string(res[0]["total"]), 10, 64)
417
+	return total, nil
418
+}

+ 9
- 6
models/statistics/goods.go 查看文件

@@ -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
 }

+ 0
- 84
models/statistics/statistics.go 查看文件

@@ -2,9 +2,6 @@ package statistics
2 2
 
3 3
 import (
4 4
 	"spaceofcheng/services/utils"
5
-	"strconv"
6
-	"strings"
7
-	"time"
8 5
 
9 6
 	"github.com/go-xorm/xorm"
10 7
 )
@@ -22,84 +19,3 @@ func NewStatisticsDAO(ctx *utils.Context) *StatisticsDAO {
22 19
 		db:  ctx.DB,
23 20
 	}
24 21
 }
25
-
26
-// GetCustomerNumber 获取会员数量
27
-func (m *StatisticsDAO) GetCustomerNumber(orgID string, caseIDs []string, start, end *time.Time) (int64, error) {
28
-	return m.execMySQLFunc("fun_total_customer", orgID, caseIDs, start, end)
29
-}
30
-
31
-// GetCourseOrderNumber 获取课程预约 - 统计课程
32
-func (m *StatisticsDAO) GetCourseOrderNumber(orgID string, caseIDs []string, start, end *time.Time) (int64, error) {
33
-	return m.execMySQLFunc("fun_course_order", orgID, caseIDs, start, end)
34
-}
35
-
36
-// GetCourseOrderCustomer 获取课程预约 - 统计人员
37
-func (m *StatisticsDAO) GetCourseOrderCustomer(orgID string, caseIDs []string, start, end *time.Time) (int64, error) {
38
-	return m.execMySQLFunc("fun_course_order_customer", orgID, caseIDs, start, end)
39
-}
40
-
41
-// GetOrderGoodsNumber 获取商品下单数量
42
-func (m *StatisticsDAO) GetOrderGoodsNumber(orgID string, caseIDs []string, start, end *time.Time) (int64, error) {
43
-	return m.execMySQLFunc("fun_order_goods_num", orgID, caseIDs, start, end)
44
-}
45
-
46
-// GetCourseNumber 获取课程数量
47
-func (m *StatisticsDAO) GetCourseNumber(orgID string, caseIDs []string, start, end *time.Time) (int64, error) {
48
-	return m.execMySQLFunc("fun_total_course", orgID, caseIDs, start, end)
49
-}
50
-
51
-// GetArrivedCustomerNumber 获取到场人数
52
-func (m *StatisticsDAO) GetArrivedCustomerNumber(orgID string, caseIDs []string, start, end *time.Time) (int64, error) {
53
-	return m.execMySQLFunc("fun_arrived_customer", orgID, caseIDs, start, end)
54
-}
55
-
56
-// GetCourseCardCustomer 获取预约人数 - 含健身卡
57
-func (m *StatisticsDAO) GetCourseCardCustomer(orgID string, caseIDs []string, start, end *time.Time) (int64, error) {
58
-	return m.execMySQLFunc("fun_course_card_customer", orgID, caseIDs, start, end)
59
-}
60
-
61
-// GetCouponCardNumber 获取卡券总数
62
-func (m *StatisticsDAO) GetCouponCardNumber(orgID string, caseIDs []string, start, end *time.Time) (int64, error) {
63
-	return m.execMySQLFunc("fun_total_coupon_card", orgID, caseIDs, start, end)
64
-}
65
-
66
-// GetUsedCouponCardNumber 获取已使用卡券
67
-func (m *StatisticsDAO) GetUsedCouponCardNumber(orgID string, caseIDs []string, start, end *time.Time) (int64, error) {
68
-	return m.execMySQLFunc("fun_used_coupon_card", orgID, caseIDs, start, end)
69
-}
70
-
71
-// GetCustomerCouponCardNumber 获取已发放卡券总数
72
-func (m *StatisticsDAO) GetCustomerCouponCardNumber(orgID string, caseIDs []string, start, end *time.Time) (int64, error) {
73
-	return m.execMySQLFunc("fun_total_customer_coupon_card", orgID, caseIDs, start, end)
74
-}
75
-
76
-// execMySQLFunc 执行 mysql 函数
77
-func (m *StatisticsDAO) execMySQLFunc(funName, orgID string, caseIDs []string, start, end *time.Time) (int64, error) {
78
-	csids := ""
79
-	if caseIDs == nil && len(caseIDs) == 0 {
80
-		csids = strings.Join(caseIDs, ",")
81
-	}
82
-
83
-	startDate := ""
84
-	endDate := ""
85
-
86
-	if start != nil {
87
-		startDate = start.Format("2006-01-02 15:04:05")
88
-	}
89
-	if end != nil {
90
-		endDate = end.Format("2006-01-02 15:04:05")
91
-	}
92
-
93
-	sql := "select " + funName + "(?,?,?,?) as total"
94
-	res, err := m.db.Query(sql, orgID, csids, startDate, endDate)
95
-	if err != nil {
96
-		return 0, err
97
-	}
98
-
99
-	if res == nil || len(res) == 0 {
100
-		return 0, nil
101
-	}
102
-
103
-	total, _ := strconv.ParseInt(string(res[0]["total"]), 10, 64)
104
-	return total, nil
105
-}

+ 16
- 5
routers/common.go 查看文件

@@ -11,7 +11,6 @@ import (
11 11
 	"spaceofcheng/services/controllers/customer"
12 12
 	"spaceofcheng/services/controllers/goods"
13 13
 	"spaceofcheng/services/controllers/gymcard"
14
-	"spaceofcheng/services/controllers/luckdrawlist"
15 14
 	"spaceofcheng/services/controllers/marketing"
16 15
 	"spaceofcheng/services/controllers/message"
17 16
 	"spaceofcheng/services/controllers/statistics"
@@ -52,6 +51,10 @@ func getCommonRoutes() beego.LinkNamespace {
52 51
 		beego.NSRouter("/signout", &user.UserController{}, "post:SignOut"),
53 52
 		beego.NSRouter("/user/tel/:tel", &user.UserController{}, "get:GetUserByTel"),
54 53
 
54
+		// Dashboard
55
+		beego.NSRouter("/dashboard", &statistics.StatisticsController{}, "get:GetDashData"),
56
+		beego.NSRouter("/dashboard/charts", &statistics.StatisticsController{}, "get:GetDashFilterCharts"),
57
+
55 58
 		// 用户类型
56 59
 		beego.NSRouter("/usertype", &user.UserController{}, "get:GetUserTypes"),
57 60
 
@@ -184,10 +187,11 @@ func getCommonRoutes() beego.LinkNamespace {
184 187
 		beego.NSRouter("/gymcard/:id/to/:users", &gymcard.GymcardController{}, "post:GiveGymToCustomer"),
185 188
 
186 189
 		// luckdrawlist 抽奖
187
-		beego.NSRouter("luckdrawlist", &luckdrawlist.LuckdrawlistController{}, "get:GetLuckdrawList"),
188
-		beego.NSRouter("luckdrawlist/:toPhone/:fromPhone", &luckdrawlist.LuckdrawlistController{}, "get:GetLuckShareList"),
189
-		beego.NSRouter("luckdrawlist/:luckdrawId", &luckdrawlist.LuckdrawlistController{}, "get:GetVerifyList"),
190
-		beego.NSRouter("luckdrawlist/:luckdrawId", &luckdrawlist.LuckdrawlistController{}, "put:VerifyLuckdraw"),
190
+		// beego.NSRouter("luckdrawlist", &luckdrawlist.LuckdrawlistController{}, "get:GetLuckdrawList"),
191
+		// beego.NSRouter("luckdrawlist/:toPhone/:fromPhone", &luckdrawlist.LuckdrawlistController{}, "get:GetLuckShareList"),
192
+		// beego.NSRouter("luckdrawlist/:luckdrawId", &luckdrawlist.LuckdrawlistController{}, "get:GetVerifyList"),
193
+		// beego.NSRouter("luckdrawlist/:luckdrawId", &luckdrawlist.LuckdrawlistController{}, "put:VerifyLuckdraw"),
194
+
191 195
 		// bodychecklist 体检列表
192 196
 		beego.NSRouter("bodychecklist", &bodychecklist.BodychecklistController{}, "get:GetBodyCheckList"),
193 197
 		// role 角色
@@ -280,11 +284,18 @@ func getCommonRoutes() beego.LinkNamespace {
280 284
 
281 285
 		// 统计类
282 286
 		beego.NSRouter("/statistics/goods", &statistics.StatisticsController{}, "get:GetGoodsStatistics"),
287
+		beego.NSRouter("/statistics/goods/excel", &statistics.StatisticsController{}, "get:GetGoodsStatisticsExcel"),
283 288
 		beego.NSRouter("/statistics/goodsorders", &statistics.StatisticsController{}, "get:GetGoodsOrdersStatistics"),
289
+		beego.NSRouter("/statistics/goodsorders/excel", &statistics.StatisticsController{}, "get:GetGoodsOrdersStatisticsExcel"),
284 290
 		beego.NSRouter("/statistics/courseorders", &statistics.StatisticsController{}, "get:GetCourseOrdersStatistics"),
291
+		beego.NSRouter("/statistics/courseorders/excel", &statistics.StatisticsController{}, "get:GetCourseOrdersStatisticsExcel"),
285 292
 		beego.NSRouter("/statistics/courses", &statistics.StatisticsController{}, "get:GetCourseStatistics"),
293
+		beego.NSRouter("/statistics/courses/excel", &statistics.StatisticsController{}, "get:GetCourseStatisticsExcel"),
286 294
 		beego.NSRouter("/statistics/cardcoupon", &statistics.StatisticsController{}, "get:CardCouponStatistics"),
295
+		beego.NSRouter("/statistics/cardcoupon/excel", &statistics.StatisticsController{}, "get:CardCouponStatisticsExcel"),
287 296
 		beego.NSRouter("/statistics/cardcouponused", &statistics.StatisticsController{}, "get:CardCouponUsedStatistics"),
297
+		beego.NSRouter("/statistics/cardcouponused/excel", &statistics.StatisticsController{}, "get:CardCouponUsedStatisticsExcel"),
288 298
 		beego.NSRouter("/statistics/cardcouponverify", &statistics.StatisticsController{}, "get:CardCouponVerifyStatistics"),
299
+		beego.NSRouter("/statistics/cardcouponverify/excel", &statistics.StatisticsController{}, "get:CardCouponVerifyStatisticsExcel"),
289 300
 	)
290 301
 }

+ 4
- 0
routers/guest.go 查看文件

@@ -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
 }

+ 7
- 7
routers/wechat.go 查看文件

@@ -77,12 +77,12 @@ func getWechatRoutes() beego.LinkNamespace {
77 77
 		beego.NSRouter("/GetQrcodeURL", &bodycheck.BodyCheckController{}, "get:GetQrcodeURL"),
78 78
 
79 79
 		// 抽奖
80
-		beego.NSRouter("/user", &luckdraw.LuckDrawController{}, "get:GetUserByCode"),
81
-		beego.NSRouter("/luckdraw/:id", &luckdraw.LuckDrawController{}, "get:GetLuckDraw"),
82
-		beego.NSRouter("/luckdraw/:id", &luckdraw.LuckDrawController{}, "post:LuckDraw"),
83
-		beego.NSRouter("/luckdraw/:id/share", &luckdraw.LuckDrawController{}, "post:SaveShareRecord"),
84
-		beego.NSRouter("/record", &luckdraw.LuckDrawController{}, "get:GetRecordByLuckDraw"),
85
-		beego.NSRouter("/user/record", &luckdraw.LuckDrawController{}, "get:GetUserLuckDraw"),
86
-		beego.NSRouter("/user/record/:id", &luckdraw.LuckDrawController{}, "get:GetRecordByID"),
80
+		// beego.NSRouter("/user", &luckdraw.LuckDrawController{}, "get:GetUserByCode"),
81
+		// beego.NSRouter("/luckdraw/:id", &luckdraw.LuckDrawController{}, "get:GetLuckDraw"),
82
+		// beego.NSRouter("/luckdraw/:id", &luckdraw.LuckDrawController{}, "post:LuckDraw"),
83
+		// beego.NSRouter("/luckdraw/:id/share", &luckdraw.LuckDrawController{}, "post:SaveShareRecord"),
84
+		// beego.NSRouter("/record", &luckdraw.LuckDrawController{}, "get:GetRecordByLuckDraw"),
85
+		// beego.NSRouter("/user/record", &luckdraw.LuckDrawController{}, "get:GetUserLuckDraw"),
86
+		// beego.NSRouter("/user/record/:id", &luckdraw.LuckDrawController{}, "get:GetRecordByID"),
87 87
 	)
88 88
 }

+ 176
- 92
service/bodycheck/bodycheck.go 查看文件

@@ -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 string) ([]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 string, 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 查看文件

@@ -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 查看文件

@@ -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 查看文件

@@ -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
+}

+ 183
- 23
service/statistics/dashboard.go 查看文件

@@ -2,7 +2,6 @@ package statistics
2 2
 
3 3
 import (
4 4
 	"errors"
5
-	"sort"
6 5
 	"spaceofcheng/services/models/model"
7 6
 	"spaceofcheng/services/utils"
8 7
 	"time"
@@ -42,11 +41,21 @@ func (s *StatisticsServ) StaDashboard(caseIDs []string) ([]interface{}, error) {
42 41
 		utils.LogError("获取支持组件失败: " + err.Error())
43 42
 		return nil, errors.New("")
44 43
 	}
44
+
45 45
 	compMapType := make(map[string]model.TdStatisticsComps)
46
+	groupComps := map[int]string{}
47
+	maxGroup := 0
46 48
 	for _, cmp := range comps {
47 49
 		compMapType[cmp.CompId] = cmp
50
+		groupComps[cmp.Group] = cmp.CompType
51
+
52
+		if maxGroup < cmp.Group {
53
+			maxGroup = cmp.Group
54
+		}
48 55
 	}
49 56
 
57
+	staDatas := make([]interface{}, maxGroup)
58
+
50 59
 	// 机构与案场
51 60
 	org := s.ctx.Get("org").(model.SysOrg)
52 61
 	// curcase := s.ctx.Get("currentCase").(model.SysUserCase)
@@ -74,11 +83,13 @@ func (s *StatisticsServ) StaDashboard(caseIDs []string) ([]interface{}, error) {
74 83
 	// 后天
75 84
 	ntd := nd.Add(24 * time.Hour)
76 85
 	// 本周
77
-	// tw := td.Add(time.Duration((1-wd)*24) * time.Hour)
86
+	tw := td.Add(time.Duration((1-wd)*24) * time.Hour)
87
+	// 下周
88
+	nw := tw.Add(7 * 24 * time.Hour)
78 89
 	// 本月
79 90
 	tm := time.Date(y, m, 1, 0, 0, 0, 0, time.Local)
80 91
 	// 下个月
81
-	// nm := time.Date(y, m+1, 1, 0, 0, 0, 0, time.Local)
92
+	nm := time.Date(y, m+1, 1, 0, 0, 0, 0, time.Local)
82 93
 
83 94
 	// 统计结果
84 95
 	res := make(map[string][]interface{})
@@ -129,7 +140,7 @@ func (s *StatisticsServ) StaDashboard(caseIDs []string) ([]interface{}, error) {
129 140
 			list := make([]map[string]interface{}, 0)
130 141
 
131 142
 			// 会员新增
132
-			dt, err := s.dao.GetCustomerNumber(org.OrgId, caseIDs, &td, nil)
143
+			dt, err := s.dao.GetCustomerNumber(org.OrgId, caseIDs, &td, &nd)
133 144
 			if err != nil {
134 145
 				utils.LogError("统计会员新增失败: " + err.Error())
135 146
 				return nil, errors.New("统计会员新增失败")
@@ -162,7 +173,7 @@ func (s *StatisticsServ) StaDashboard(caseIDs []string) ([]interface{}, error) {
162 173
 			})
163 174
 
164 175
 			// 到场人次
165
-			dt, err = s.dao.GetArrivedCustomerNumber(org.OrgId, caseIDs, &td, nil)
176
+			dt, err = s.dao.GetArrivedCustomerNumber(org.OrgId, caseIDs, &td, &nd)
166 177
 			if err != nil {
167 178
 				utils.LogError("统计到场人次失败: " + err.Error())
168 179
 				return nil, errors.New("统计到场人次失败")
@@ -175,7 +186,13 @@ func (s *StatisticsServ) StaDashboard(caseIDs []string) ([]interface{}, error) {
175 186
 			data["value"] = list
176 187
 
177 188
 		// 明日课程
178
-		// TODO
189
+		case STA_TOMORROWCOURSEORDER:
190
+			dt, err := s.dao.GetCourseOrderPie(org.OrgId, caseIDs, &nd, &ntd)
191
+			if err != nil {
192
+				utils.LogError("统计明日预约课程失败: " + err.Error())
193
+				return nil, errors.New("统计明日预约课程失败")
194
+			}
195
+			data["value"] = dt
179 196
 
180 197
 		// -------
181 198
 		// 运营
@@ -191,7 +208,7 @@ func (s *StatisticsServ) StaDashboard(caseIDs []string) ([]interface{}, error) {
191 208
 
192 209
 		// 今日到场人数
193 210
 		case STA_TODAY_ARRIVED:
194
-			dt, err := s.dao.GetArrivedCustomerNumber(org.OrgId, caseIDs, &td, nil)
211
+			dt, err := s.dao.GetArrivedCustomerNumber(org.OrgId, caseIDs, &td, &nd)
195 212
 			if err != nil {
196 213
 				utils.LogError("统计到场人次失败: " + err.Error())
197 214
 				return nil, errors.New("统计到场人次失败")
@@ -209,7 +226,7 @@ func (s *StatisticsServ) StaDashboard(caseIDs []string) ([]interface{}, error) {
209 226
 
210 227
 		// 本月卡券总数
211 228
 		case STA_MONTHCOUPONCARD:
212
-			dt, err := s.dao.GetCouponCardNumber(org.OrgId, caseIDs, &tm, nil)
229
+			dt, err := s.dao.GetCouponCardNumber(org.OrgId, caseIDs, &tm, &nm)
213 230
 			if err != nil {
214 231
 				utils.LogError("统计卡券总数失败: " + err.Error())
215 232
 				return nil, errors.New("统计卡券总数失败")
@@ -218,7 +235,7 @@ func (s *StatisticsServ) StaDashboard(caseIDs []string) ([]interface{}, error) {
218 235
 
219 236
 		// 本月客户已使用
220 237
 		case STA_MONTHUSEDCOUPONCARD:
221
-			dt, err := s.dao.GetUsedCouponCardNumber(org.OrgId, caseIDs, &tm, nil)
238
+			dt, err := s.dao.GetUsedCouponCardNumber(org.OrgId, caseIDs, &tm, &nm)
222 239
 			if err != nil {
223 240
 				utils.LogError("统计客户使用数失败: " + err.Error())
224 241
 				return nil, errors.New("统计客户使用数失败")
@@ -227,7 +244,7 @@ func (s *StatisticsServ) StaDashboard(caseIDs []string) ([]interface{}, error) {
227 244
 
228 245
 		// 本月已发放
229 246
 		case STA_MONTHUNUSEDCOUPONCARD:
230
-			dt, err := s.dao.GetCustomerCouponCardNumber(org.OrgId, caseIDs, &tm, nil)
247
+			dt, err := s.dao.GetCustomerCouponCardNumber(org.OrgId, caseIDs, &tm, &nm)
231 248
 			if err != nil {
232 249
 				utils.LogError("统计已发放卡券数失败: " + err.Error())
233 250
 				return nil, errors.New("统计已发放卡券数失败")
@@ -236,7 +253,7 @@ func (s *StatisticsServ) StaDashboard(caseIDs []string) ([]interface{}, error) {
236 253
 
237 254
 		// 本月饮品数
238 255
 		case STA_MONTHGOODS:
239
-			dt, err := s.dao.GetOrderGoodsNumber(org.OrgId, caseIDs, &tm, nil)
256
+			dt, err := s.dao.GetOrderGoodsNumber(org.OrgId, caseIDs, &tm, &nm)
240 257
 			if err != nil {
241 258
 				utils.LogError("统计商品下单失败: " + err.Error())
242 259
 				return nil, errors.New("统计商品下单失败")
@@ -245,15 +262,75 @@ func (s *StatisticsServ) StaDashboard(caseIDs []string) ([]interface{}, error) {
245 262
 
246 263
 		// 今天饮品数
247 264
 		case STA_TODAYGOODS:
248
-			dt, err := s.dao.GetOrderGoodsNumber(org.OrgId, caseIDs, &td, nil)
265
+			dt, err := s.dao.GetOrderGoodsNumber(org.OrgId, caseIDs, &td, &nd)
249 266
 			if err != nil {
250 267
 				utils.LogError("统计商品下单失败: " + err.Error())
251 268
 				return nil, errors.New("统计商品下单失败")
252 269
 			}
253 270
 			data["value"] = dt
254 271
 
272
+		// 本月课程预约
273
+		case STA_MONTHCOURSEORDER:
274
+			dt, err := s.dao.GetCourseOrderPie(org.OrgId, caseIDs, &tm, &nm)
275
+			if err != nil {
276
+				utils.LogError("统计本月预约课程失败: " + err.Error())
277
+				return nil, errors.New("统计本月预约课程失败")
278
+			}
279
+			data["value"] = dt
280
+
281
+		// 本月课程参与率
282
+		case STA_MONTHCOURSEPERCENT:
283
+			dt1, err := s.dao.GetCourseOrderCustomer(org.OrgId, caseIDs, &tm, &nm)
284
+			if err != nil {
285
+				utils.LogError("统计本月预约人数失败: " + err.Error())
286
+				return nil, errors.New("统计本月预约人数失败")
287
+			}
288
+
289
+			dt2, err := s.dao.GetUsedCourseOrderCustomer(org.OrgId, caseIDs, &tm, &nm)
290
+			if err != nil {
291
+				utils.LogError("统计本月核销人数失败: " + err.Error())
292
+				return nil, errors.New("统计本月核销人数失败")
293
+			}
294
+
295
+			dt := float64(0.0)
296
+			if dt2 != 0 {
297
+				dt = float64(dt1/dt2) * 10
298
+			}
299
+
300
+			data["value"] = dt
301
+
302
+		// 本周课程参与率
303
+		case STA_WEEKCOURSEPERCENT:
304
+			dt1, err := s.dao.GetCourseOrderCustomer(org.OrgId, caseIDs, &tw, &nw)
305
+			if err != nil {
306
+				utils.LogError("统计本周预约人数失败: " + err.Error())
307
+				return nil, errors.New("统计本周预约人数失败")
308
+			}
309
+
310
+			dt2, err := s.dao.GetUsedCourseOrderCustomer(org.OrgId, caseIDs, &tw, &nw)
311
+			if err != nil {
312
+				utils.LogError("统计本周核销人数失败: " + err.Error())
313
+				return nil, errors.New("统计本周核销人数失败")
314
+			}
315
+
316
+			dt := float64(0.0)
317
+			if dt2 != 0 {
318
+				dt = float64(dt1/dt2) * 10
319
+			}
320
+
321
+			data["value"] = dt
322
+
323
+		// 本月饮品日下单
324
+		case STA_GOODSDAILY:
325
+			dt, err := s.dao.GetGoodsWithTypeDaily(org.OrgId, caseIDs)
326
+			if err != nil {
327
+				utils.LogError("统计本月饮品下单失败: " + err.Error())
328
+				return nil, errors.New("统计本月饮品下单失败")
329
+			}
330
+			data["value"] = dt
331
+
255 332
 		default:
256
-			// 暂不支持的统计
333
+			// 其余的不在本次中返回
257 334
 			data["value"] = nil
258 335
 		}
259 336
 
@@ -266,19 +343,102 @@ func (s *StatisticsServ) StaDashboard(caseIDs []string) ([]interface{}, error) {
266 343
 		res[cmp.CompType] = typeData
267 344
 	}
268 345
 
269
-	// 对 comp-type 进行字典排序
270
-	// 因为 数据库没有设置序号字段,所以约定 comp-type 按照字典顺序进行命名
271
-	typeIDs := []string{}
272
-	for k := range res {
273
-		typeIDs = append(typeIDs, k)
346
+	for g, cmpType := range groupComps {
347
+		staDatas[g] = res[cmpType]
274 348
 	}
275 349
 
276
-	sort.Strings(typeIDs)
350
+	return staDatas, nil
351
+}
277 352
 
278
-	staDatas := make([]interface{}, 0)
279
-	for _, k := range typeIDs {
280
-		staDatas = append(staDatas, res[k])
353
+// GetStaFilterCharts 获取
354
+func (s *StatisticsServ) GetStaFilterCharts(caseIDs []string, staType string) ([]interface{}, error) {
355
+	// 人员及类型
356
+	user := s.ctx.Get("user").(model.SysUser)
357
+	userTypes, err := s.dao.GetUserTypes(user.UserId)
358
+	if err != nil {
359
+		utils.LogError("获取用户类型失败: " + err.Error())
360
+		return nil, errors.New("获取用户类型失败")
281 361
 	}
282 362
 
283
-	return staDatas, nil
363
+	tps := make([]string, 0)
364
+	if userTypes != nil {
365
+		for _, tp := range userTypes {
366
+			tps = append(tps, tp.TypeId)
367
+		}
368
+	}
369
+
370
+	// 统计配置
371
+	settings, err := s.dao.GetDashboardSetting(user.UserId, tps)
372
+	if err != nil {
373
+		utils.LogError("获取用户 Dashboard 配置失败: " + err.Error())
374
+		return nil, errors.New("获取用户 Dashboard 配置失败")
375
+	}
376
+
377
+	if settings == nil {
378
+		return nil, nil
379
+	}
380
+	// 机构与案场
381
+	org := s.ctx.Get("org").(model.SysOrg)
382
+	// curcase := s.ctx.Get("currentCase").(model.SysUserCase)
383
+
384
+	if caseIDs == nil || len(caseIDs) > 0 {
385
+		allCases := s.ctx.Get("cases").([]model.SysUserCase)
386
+		caseIDs = []string{}
387
+		for _, cs := range allCases {
388
+			caseIDs = append(caseIDs, cs.CaseId)
389
+		}
390
+	}
391
+
392
+	res := make([]interface{}, 0)
393
+
394
+	for _, setting := range settings {
395
+		switch setting {
396
+		case STA_FILTER_CUSTOMER:
397
+			dt, err := s.dao.GetNewCustomerDaily(org.OrgId, caseIDs, staType)
398
+			if err != nil {
399
+				utils.LogError("统计日推荐会员失败: " + err.Error())
400
+				return nil, errors.New("统计日推荐会员失败")
401
+			}
402
+
403
+			res = append(res, dt)
404
+
405
+		case STA_FILTER_COURSE:
406
+			dt, err := s.dao.GetCourseDaily(org.OrgId, caseIDs, staType)
407
+			if err != nil {
408
+				utils.LogError("统计日排课量失败: " + err.Error())
409
+				return nil, errors.New("统计日排课量失败")
410
+			}
411
+
412
+			res = append(res, dt)
413
+
414
+		case STA_FILTER_COURSE_ORDER:
415
+			dt, err := s.dao.GetCourseOrderDaily(org.OrgId, caseIDs, staType)
416
+			if err != nil {
417
+				utils.LogError("统计日课程预约失败: " + err.Error())
418
+				return nil, errors.New("统计日课程预约失败")
419
+			}
420
+
421
+			res = append(res, dt)
422
+
423
+		case STA_FILTER_GOODS:
424
+			dt, err := s.dao.GetGoodsDaily(org.OrgId, caseIDs, staType)
425
+			if err != nil {
426
+				utils.LogError("统计日饮品下单失败: " + err.Error())
427
+				return nil, errors.New("统计日饮品下单失败")
428
+			}
429
+
430
+			res = append(res, dt)
431
+
432
+		case STA_FILTER_ARRIVED:
433
+			dt, err := s.dao.GetArrivedDaily(org.OrgId, caseIDs, staType)
434
+			if err != nil {
435
+				utils.LogError("统计日到场人次失败: " + err.Error())
436
+				return nil, errors.New("统计日到场人次失败")
437
+			}
438
+
439
+			res = append(res, dt)
440
+		}
441
+	}
442
+
443
+	return res, nil
284 444
 }

+ 30
- 4
service/statistics/goods.go 查看文件

@@ -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
+}

+ 23
- 0
service/statistics/setting.go 查看文件

@@ -42,4 +42,27 @@ const (
42 42
 
43 43
 	// 本月客户已使用
44 44
 	STA_MONTHUSEDCOUPONCARD = "month_unused_coupon_card"
45
+
46
+	// 本月课程预约
47
+	STA_MONTHCOURSEORDER = "month_course_order"
48
+
49
+	// 本月课程参与率
50
+	STA_MONTHCOURSEPERCENT = "month_course_percent"
51
+
52
+	// 本周课程参与率
53
+	STA_WEEKCOURSEPERCENT = "week_course_percent"
54
+
55
+	// 日下单数据
56
+	STA_GOODSDAILY = "goods_daily"
57
+
58
+	// 推荐会员
59
+	STA_FILTER_CUSTOMER = "sta_customer"
60
+	// 排课数
61
+	STA_FILTER_COURSE = "sta_course"
62
+	// 课程预约
63
+	STA_FILTER_COURSE_ORDER = "sta_course_order"
64
+	// 饮品下单
65
+	STA_FILTER_GOODS = "sta_goods"
66
+	// 到场人次
67
+	STA_FILTER_ARRIVED = "sta_arrived"
45 68
 )

+ 8
- 4
service/sys.go 查看文件

@@ -348,12 +348,16 @@ func (s *SysServ) wechartSignIn(gctx *context.Context, code string) (*utils.Wech
348 348
 }
349 349
 
350 350
 func (s *SysServ) getToken(gctx *context.Context) (*utils.JWTToken, error) {
351
-	tokenRaw := gctx.Input.Header(utils.TokenHeader)
352
-	if tokenRaw == "" {
353
-		return new(utils.JWTToken), nil
351
+	tokenEnStr := gctx.Input.Query("token")
352
+	if tokenEnStr == "" {
353
+		tokenRaw := gctx.Input.Header(utils.TokenHeader)
354
+		if tokenRaw == "" {
355
+			return new(utils.JWTToken), nil
356
+		}
357
+
358
+		tokenEnStr = strings.Trim(strings.TrimLeft(tokenRaw, utils.TokenSchema), " ")
354 359
 	}
355 360
 
356
-	tokenEnStr := strings.Trim(strings.TrimLeft(tokenRaw, utils.TokenSchema), " ")
357 361
 	s.ctx.Set("token", tokenEnStr)
358 362
 
359 363
 	token, err := utils.PareseToken(tokenEnStr)