Pārlūkot izejas kodu

luckdraw bodycheck

胡轶钦 6 gadus atpakaļ
vecāks
revīzija
297582c5a4

+ 298
- 0
controllers/bodycheck/bodycheck.go Parādīt failu

@@ -0,0 +1,298 @@
1
+package bodycheck
2
+
3
+import (
4
+	"encoding/json"
5
+	"io/ioutil"
6
+	"spaceofcheng/services/controllers"
7
+	"spaceofcheng/services/models/model"
8
+	"spaceofcheng/services/service/bodycheck"
9
+	"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
+)
18
+
19
+// BodyCheckController 应用
20
+type BodyCheckController struct {
21
+	dao *bodycheck.BodycheckServ
22
+	controllers.BaseController
23
+	weixin *wx.Client
24
+}
25
+
26
+// Constructor 初始化 Controller
27
+// @Title Constructor
28
+// @Description 初始化 Controller, 系统自动调用
29
+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)
33
+}
34
+
35
+// GetCheckByUser 根据用户获取体检报告
36
+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)
45
+	if err != nil {
46
+		c.ResponseError(err)
47
+	}
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
+	})
78
+}
79
+
80
+// PostCheckResult 测量结果返回
81
+func (c *BodyCheckController) PostCheckResult() {
82
+	r := c.Ctx.Request
83
+	defer r.Body.Close()
84
+	con, _ := ioutil.ReadAll(r.Body) //获取post的数据
85
+
86
+	var formVal map[string]interface{}
87
+	err := json.Unmarshal(con, &formVal)
88
+	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.Id < 1 {
142
+		beego.Error("没有当前用户信息!")
143
+		c.ResponseJson(map[string]interface{}{
144
+			"Status":  false,
145
+			"Message": "没有当前用户信息!",
146
+		})
147
+	}
148
+	userid := user.Id
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
+		}
247
+	}
248
+
249
+	specs, err := c.dao.GetCheckSpecs()
250
+	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
+		}
293
+	}
294
+	c.ResponseJson(map[string]interface{}{
295
+		"Status":  true,
296
+		"Message": "",
297
+	})
298
+}

+ 177
- 0
controllers/bodycheck/wechat.go Parādīt failu

@@ -0,0 +1,177 @@
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
+}

+ 1
- 1
controllers/coupon/coupon.go Parādīt failu

@@ -6,10 +6,10 @@ import (
6 6
 	"net/http"
7 7
 	"spaceofcheng/services/controllers"
8 8
 	cpModel "spaceofcheng/services/models/coupon"
9
+	"spaceofcheng/services/models/model"
9 10
 	"spaceofcheng/services/service/coupon"
10 11
 	"spaceofcheng/services/utils"
11 12
 	"strings"
12
-	"tolet/models/model"
13 13
 )
14 14
 
15 15
 // CouponController 商品

+ 12
- 12
controllers/gymcard/gymcard.go Parādīt failu

@@ -119,18 +119,18 @@ func (c *GymcardController) SendGymToCustomer() {
119 119
 	c.ResponseJSON(customerGym)
120 120
 }
121 121
 
122
-// SendGymToCustomer 后台发卡给客户
123
-func (c *GymcardController) BackSendGymToCustomer() {
124
-	gymcardId := c.GetString(":gymcardId")
125
-	customerId := c.GetString(":customerId")
126
-	sysUser := c.Context.Get("user").(model.SysUser)
127
-	userId := sysUser.UserId
128
-	customerGym, err := c.dao.BackSendGymCardToUser(gymcardId, userId, customerId)
129
-	if err != nil {
130
-		c.ResponseError(err)
131
-	}
132
-	c.ResponseJSON(customerGym)
133
-}
122
+// // SendGymToCustomer 后台发卡给客户
123
+// func (c *GymcardController) BackSendGymToCustomer() {
124
+// 	gymcardId := c.GetString(":gymcardId")
125
+// 	customerId := c.GetString(":customerId")
126
+// 	sysUser := c.Context.Get("user").(model.SysUser)
127
+// 	userId := sysUser.UserId
128
+// 	customerGym, err := c.dao.BackSendGymCardToUser(gymcardId, userId, customerId)
129
+// 	if err != nil {
130
+// 		c.ResponseError(err)
131
+// 	}
132
+// 	c.ResponseJSON(customerGym)
133
+// }
134 134
 
135 135
 // VerifyCustomerGymcard 核销客户健身卡
136 136
 func (c *GymcardController) VerifyCustomerGymcard() {

+ 357
- 0
controllers/luckdraw/luckdraw.go Parādīt failu

@@ -0,0 +1,357 @@
1
+package luckdraw
2
+
3
+import (
4
+	"spaceofcheng/services/controllers"
5
+	"spaceofcheng/services/models/model"
6
+	"spaceofcheng/services/service/luckdraw"
7
+	"strconv"
8
+)
9
+
10
+// LuckdrawController 应用
11
+type LuckdrawController struct {
12
+	dao *luckdraw.LuckdrawServ
13
+	controllers.BaseController
14
+}
15
+
16
+// Constructor 初始化 Controller
17
+// @Title Constructor
18
+// @Description 初始化 Controller, 系统自动调用
19
+func (c *LuckdrawController) Constructor() {
20
+	c.dao = luckdraw.NewLuckdrawServ(c.Context)
21
+	org := c.Context.Get("org").(model.SysOrg)
22
+}
23
+
24
+// GetUserByCode 根据code获取用户信息
25
+func (c *LuckDrawController) GetUserByCode() {
26
+	custID := 0
27
+	encodeUser, _ := c.GetInt("from")
28
+	if encodeUser != 0 {
29
+		encodeUser = helper.IntXOR(encodeUser, 97)
30
+		enStr := strconv.Itoa(encodeUser)
31
+		enStr = enStr[:len(enStr)-3]
32
+
33
+		custID, _ = strconv.Atoi(enStr)
34
+	}
35
+
36
+	code := c.GetString("code")
37
+	if c.openid == "" && code == "" && custID == 0 {
38
+		c.ResponseJson(map[string]interface{}{
39
+			"Status":  false,
40
+			"Message": "401-" + c.weixin.GetAppID(),
41
+		})
42
+	}
43
+
44
+	var user *model.CustomerUser
45
+	if custID != 0 {
46
+		var err error
47
+		user, err = c.bodydao.GetCustomerByID(custID)
48
+		if err != nil {
49
+			c.ResponseJson(map[string]interface{}{
50
+				"Status":  false,
51
+				"Message": helper.LogError("获取用户信息失败", err.Error()).Error(),
52
+			})
53
+		}
54
+
55
+		c.openid = user.OpenId
56
+	}
57
+
58
+	if c.openid == "" {
59
+		openid, err := c.weixin.GetOpenID(code)
60
+		if err != nil {
61
+			c.ResponseJson(map[string]interface{}{
62
+				"Status":  false,
63
+				"Message": helper.LogError("获取微信 OpenId 失败", err.Error()).Error(),
64
+			})
65
+		}
66
+
67
+		c.openid = openid
68
+		c.SetSession("openid", openid)
69
+	}
70
+
71
+	if user == nil {
72
+		var err error
73
+		user, err = c.bodydao.GetUserByOpenID(c.openid)
74
+		if err != nil {
75
+			c.ResponseJson(map[string]interface{}{
76
+				"Status":  false,
77
+				"Message": helper.LogError("获取用户信息失败", err.Error()).Error(),
78
+			})
79
+		}
80
+	}
81
+
82
+	if user == nil || user.Tel == "" {
83
+		c.ResponseJson(map[string]interface{}{
84
+			"Status":  true,
85
+			"Message": 406,
86
+		})
87
+	}
88
+
89
+	luckdrawid, _ := c.GetInt("luckdrawid")
90
+	record, err := c.dao.GetUserLuckDrawByLuckDraw(user.Id, luckdrawid)
91
+	if err != nil {
92
+		c.ResponseJson(map[string]interface{}{
93
+			"Status":  false,
94
+			"Message": helper.LogError("获取用户抽奖信息失败", err.Error()).Error(),
95
+		})
96
+	}
97
+	var detail *model.TaPrizeDetail
98
+	if record != nil {
99
+		detail, err = c.dao.GetDetailByRecord(record.Id)
100
+		if err != nil {
101
+			c.ResponseJson(map[string]interface{}{
102
+				"Status":  false,
103
+				"Message": helper.LogError("获取用户抽奖信息失败", err.Error()).Error(),
104
+			})
105
+		}
106
+	}
107
+
108
+	c.ResponseJson(map[string]interface{}{
109
+		"Status": true,
110
+		"Message": map[string]interface{}{
111
+			"user":   user,
112
+			"record": record,
113
+			"detail": detail,
114
+		},
115
+	})
116
+}
117
+
118
+// GetLuckDraw 获取抽奖信息
119
+func (c *LuckDrawController) GetLuckDraw() {
120
+	id, _ := c.GetInt(":id")
121
+	luckdraw, err := c.dao.GetLuckDraw(id)
122
+	if err != nil {
123
+		c.ResponseJson(map[string]interface{}{
124
+			"Status":  false,
125
+			"Message": helper.LogError("获取抽奖信息失败", err.Error()).Error(),
126
+		})
127
+	}
128
+	c.ResponseJson(map[string]interface{}{
129
+		"Status":  true,
130
+		"Message": luckdraw,
131
+	})
132
+}
133
+
134
+// LuckDraw 抽奖
135
+func (c *LuckDrawController) LuckDraw() {
136
+	if c.openid == "" {
137
+		c.ResponseJson(map[string]interface{}{
138
+			"Status":  false,
139
+			"Message": "401-" + c.weixin.GetAppID(),
140
+		})
141
+	}
142
+
143
+	id, _ := c.GetInt(":id")
144
+	user, err := c.bodydao.GetUserByOpenID(c.openid)
145
+	if err != nil {
146
+		c.ResponseJson(map[string]interface{}{
147
+			"Status":  false,
148
+			"Message": helper.LogError("获取用户信息失败", err.Error()).Error(),
149
+		})
150
+	}
151
+
152
+	prize, detail, err := c.dao.LuckDraw(id, user)
153
+	if err != nil {
154
+		c.ResponseJson(map[string]interface{}{
155
+			"Status":  false,
156
+			"Message": err.Error(),
157
+		})
158
+	}
159
+	c.ResponseJson(map[string]interface{}{
160
+		"Status": true,
161
+		"Message": map[string]interface{}{
162
+			"prize":  prize,
163
+			"detail": detail,
164
+		},
165
+	})
166
+}
167
+
168
+// GetRecordByLuckDraw 获取抽奖记录
169
+func (c *LuckDrawController) GetRecordByLuckDraw() {
170
+	id, _ := c.GetInt("id")
171
+	records, err := c.dao.GetRecordByLuckDraw(id)
172
+	if err != nil {
173
+		c.ResponseJson(map[string]interface{}{
174
+			"Status":  false,
175
+			"Message": helper.LogError("获取抽奖记录失败", err.Error()).Error(),
176
+		})
177
+	}
178
+	c.ResponseJson(map[string]interface{}{
179
+		"Status":  true,
180
+		"Message": records,
181
+	})
182
+}
183
+
184
+// GetUserLuckDraw 获取用户的抽奖记录
185
+func (c *LuckDrawController) GetUserLuckDraw() {
186
+	userid, _ := c.GetInt("userid")
187
+	records, err := c.dao.GetUserLuckDraw(userid)
188
+	if err != nil {
189
+		c.ResponseJson(map[string]interface{}{
190
+			"Status":  false,
191
+			"Message": helper.LogError("获取用户抽奖记录失败", err.Error()).Error(),
192
+		})
193
+	}
194
+	c.ResponseJson(map[string]interface{}{
195
+		"Status":  true,
196
+		"Message": records,
197
+	})
198
+}
199
+
200
+// GetRecordByID 根据ID获取中奖记录信息
201
+func (c *LuckDrawController) GetRecordByID() {
202
+	id, _ := c.GetInt(":id")
203
+	record, err := c.dao.GetRecordByID(id)
204
+	if err != nil {
205
+		c.ResponseJson(map[string]interface{}{
206
+			"Status":  false,
207
+			"Message": helper.LogError("获取中奖记录失败", err.Error()).Error(),
208
+		})
209
+	}
210
+
211
+	caseAddress, err := c.dao.GetCaseAddressByLuckDarw(record.LuckdrawId)
212
+	if err != nil {
213
+		c.ResponseJson(map[string]interface{}{
214
+			"Status":  false,
215
+			"Message": helper.LogError("获取案场信息失败", err.Error()).Error(),
216
+		})
217
+	}
218
+
219
+	if caseAddress == "" {
220
+		c.ResponseJson(map[string]interface{}{
221
+			"Status":  false,
222
+			"Message": "无案场, 或案场地址没有维护",
223
+		})
224
+	}
225
+
226
+	prize, err := c.dao.GetPrizeByID(record.PrizeId)
227
+	if err != nil {
228
+		c.ResponseJson(map[string]interface{}{
229
+			"Status":  false,
230
+			"Message": helper.LogError("校验奖品记录失败", err.Error()).Error(),
231
+		})
232
+	}
233
+
234
+	c.ResponseJson(map[string]interface{}{
235
+		"Status": true,
236
+		"Message": map[string]interface{}{
237
+			"record":      record,
238
+			"prize":       prize,
239
+			"caseAddress": caseAddress,
240
+		},
241
+	})
242
+}
243
+
244
+func (c *LuckDrawController) SaveShareRecord() {
245
+	if c.openid == "" {
246
+		c.ResponseJson(map[string]interface{}{
247
+			"Status":  false,
248
+			"Message": "401-" + c.weixin.GetAppID(),
249
+		})
250
+	}
251
+
252
+	errPrefix := "logerror-"
253
+
254
+	id, _ := c.GetInt(":id")
255
+
256
+	fromID, _ := c.GetInt("from")
257
+	if fromID == 0 {
258
+		c.ResponseJson(map[string]interface{}{
259
+			"Status":  false,
260
+			"Message": errPrefix + "没有分享人ID",
261
+		})
262
+	}
263
+
264
+	from, err := c.bodydao.GetCustomerByID(fromID)
265
+	if err != nil {
266
+		c.ResponseJson(map[string]interface{}{
267
+			"Status":  false,
268
+			"Message": errPrefix + helper.LogError("获取分享人信息失败", err.Error()).Error(),
269
+		})
270
+	}
271
+
272
+	if from == nil || from.Id == 0 {
273
+		c.ResponseJson(map[string]interface{}{
274
+			"Status":  false,
275
+			"Message": errPrefix + helper.LogError("分享人信息不存在").Error(),
276
+		})
277
+	}
278
+
279
+	current, err := c.bodydao.GetUserByOpenID(c.openid)
280
+	if err != nil {
281
+		c.ResponseJson(map[string]interface{}{
282
+			"Status":  false,
283
+			"Message": errPrefix + helper.LogError("获取当前人员信息失败", err.Error()).Error(),
284
+		})
285
+	}
286
+
287
+	if current == nil || current.Id == 0 {
288
+		c.ResponseJson(map[string]interface{}{
289
+			"Status":  false,
290
+			"Message": errPrefix + "系统错误, 无当前人员信息",
291
+		})
292
+	}
293
+
294
+	// 自己分享给自己
295
+	if from.Id == current.Id {
296
+		c.ResponseJson(map[string]interface{}{
297
+			"Status":  false,
298
+			"Message": errPrefix + "本人分享内容无效",
299
+		})
300
+	}
301
+
302
+	luckdraw, err := c.dao.GetLuckDrawByID(id)
303
+	if err != nil {
304
+		c.ResponseJson(map[string]interface{}{
305
+			"Status":  false,
306
+			"Message": errPrefix + helper.LogError("获取抽奖信息失败", err.Error()).Error(),
307
+		})
308
+	}
309
+
310
+	if luckdraw == nil {
311
+		c.ResponseJson(map[string]interface{}{
312
+			"Status":  false,
313
+			"Message": errPrefix + helper.LogError("没有找到 id ("+strconv.Itoa(id)+") 对应的抽奖信息").Error(),
314
+		})
315
+	}
316
+
317
+	existsRec, err := c.dao.GetLuckDrawShareData(from.Id, current.Id, luckdraw.Id, luckdraw.CaseId)
318
+	if err != nil {
319
+		c.ResponseJson(map[string]interface{}{
320
+			"Status":  false,
321
+			"Message": errPrefix + helper.LogError("获取已有分享信息失败", err.Error()).Error(),
322
+		})
323
+	}
324
+
325
+	if existsRec != nil && len(existsRec) > 0 {
326
+		c.ResponseJson(map[string]interface{}{
327
+			"Status":  false,
328
+			"Message": errPrefix + "已分享记录, 再次分享无效",
329
+		})
330
+	}
331
+
332
+	shareDt := model.TaShareLuckyRecord{
333
+		FromCustomerId:     from.Id,
334
+		FromCustomerName:   from.Username,
335
+		FromCustomerWxname: from.WcNickname,
336
+		FromCustomerTel:    from.Tel,
337
+		ToCustomerId:       current.Id,
338
+		ToCustomerName:     current.Username,
339
+		ToCustomerWxname:   current.WcNickname,
340
+		ToCustomerTel:      current.Tel,
341
+		CaseId:             luckdraw.CaseId,
342
+		LuckydrawId:        luckdraw.Id,
343
+		LuckydrawName:      luckdraw.Name,
344
+	}
345
+
346
+	if err := c.dao.SaveLuckDrawShareData(&shareDt); err != nil {
347
+		c.ResponseJson(map[string]interface{}{
348
+			"Status":  false,
349
+			"Message": errPrefix + helper.LogError("保存分享记录失败", err.Error()).Error(),
350
+		})
351
+	}
352
+
353
+	c.ResponseJson(map[string]interface{}{
354
+		"Status":  true,
355
+		"Message": "ok",
356
+	})
357
+}

+ 14
- 4
controllers/verify/verify.go Parādīt failu

@@ -5,6 +5,7 @@ import (
5 5
 	"spaceofcheng/services/models"
6 6
 	"spaceofcheng/services/models/model"
7 7
 	"spaceofcheng/services/service/verify"
8
+	"time"
8 9
 )
9 10
 
10 11
 // CaseController 信息
@@ -70,11 +71,20 @@ func (c *VerifyController) VerifyCourse() {
70 71
 			c.ResponseError(err)
71 72
 		}
72 73
 		if customerCard.VerifyStatus == models.VERIFY_USEABLE {
73
-			customerCard.VerifyStatus = models.VERIFY_USED
74
-			err := c.dao.UpdateCustomerCard(customerCard)
75
-			if err != nil {
76
-				c.ResponseError(err)
74
+			if customerCard.EndDate.After(time.Now()) {
75
+				customerCard.VerifyStatus = models.VERIFY_LATE
76
+				err := c.dao.UpdateCustomerCard(customerCard)
77
+				if err != nil {
78
+					c.ResponseError(err)
79
+				}
80
+			} else {
81
+				customerCard.VerifyStatus = models.VERIFY_USED
82
+				err := c.dao.UpdateCustomerCard(customerCard)
83
+				if err != nil {
84
+					c.ResponseError(err)
85
+				}
77 86
 			}
87
+
78 88
 		}
79 89
 	}
80 90
 	err = c.dao.UpdateCustomerCourse(customerCourse)

+ 4
- 4
models/bodycheck/bodycheck.go Parādīt failu

@@ -24,7 +24,7 @@ func NewDAO(ctx *utils.Context) *DAO {
24 24
 }
25 25
 
26 26
 // GetBodyCheckByUser 根据用户信息获取体检信息
27
-func (m *DAO) GetBodyCheckByUser(userID int) ([]model.TaBodyCheck, error) {
27
+func (m *DAO) GetBodyCheckByUser(userID string) ([]model.TaBodyCheck, error) {
28 28
 	var bodychecks []model.TaBodyCheck
29 29
 	var err error
30 30
 	err = m.db.Where("user_id=?", userID).And("status=?", 1).Desc("create_date").Find(&bodychecks)
@@ -39,7 +39,7 @@ func (m *DAO) GetCheckSpecs() ([]model.TdCheckSpec, error) {
39 39
 }
40 40
 
41 41
 // GetCheckByUserAndEquipmentID 根据用户与设备ID获取体检信息
42
-func (m *DAO) GetCheckByUserAndEquipmentID(userID int, EquipmentID string) (*model.TaBodyCheck, error) {
42
+func (m *DAO) GetCheckByUserAndEquipmentID(userID string, EquipmentID string) (*model.TaBodyCheck, error) {
43 43
 	var check []model.TaBodyCheck
44 44
 	err := m.db.Where("user_id=?", userID).And("equipment_id=?", EquipmentID).And("status=?", 1).Desc("create_date").Find(&check)
45 45
 	if err != nil {
@@ -82,9 +82,9 @@ func (m *DAO) GetUserByOpenID(openid string) (*model.TaCustomer, error) {
82 82
 }
83 83
 
84 84
 // GetCustomerByID 根据客户ID 获取用户信息
85
-func (m *DAO) GetCustomerByID(id int) (*model.TaCustomer, error) {
85
+func (m *DAO) GetCustomerByID(id string) (*model.TaCustomer, error) {
86 86
 	var cust model.TaCustomer
87
-	_, err := m.db.Where("id=?", id).Get(&cust)
87
+	_, err := m.db.Where("customer_id=?", id).Get(&cust)
88 88
 	return &cust, err
89 89
 }
90 90
 

+ 445
- 0
models/luckdraw/luckdraw.go Parādīt failu

@@ -0,0 +1,445 @@
1
+package luckdraw
2
+
3
+import (
4
+	"spaceofcheng/services/models"
5
+	"spaceofcheng/services/models/model"
6
+	"spaceofcheng/services/utils"
7
+	"strconv"
8
+	"time"
9
+
10
+	"github.com/go-xorm/xorm"
11
+)
12
+
13
+const (
14
+	StatusNormal = 1
15
+)
16
+
17
+// DAO 当前数据库操作对象
18
+type DAO struct {
19
+	ctx *utils.Context
20
+	db  *xorm.Session
21
+}
22
+
23
+// NewDAO 初始化DAO
24
+func NewDAO(ctx *utils.Context) *DAO {
25
+	return &DAO{
26
+		ctx: ctx,
27
+		db:  ctx.DB,
28
+	}
29
+}
30
+
31
+const (
32
+	STATUS_NOWRITROFF = 0
33
+)
34
+
35
+// LuckDraw 抽奖记录
36
+type LuckDraw struct {
37
+	model.TaLuckdraw `xorm:"extends"`
38
+	Prizes           []model.TaLuckdrawPrize
39
+}
40
+
41
+// GetLuckDraw 获取抽奖信息
42
+func (m *DAO) GetLuckDraw(id int) (*LuckDraw, error) {
43
+	if id == 0 {
44
+		return nil, utils.LogError("不存在抽奖信息!")
45
+	}
46
+
47
+	luckdraw, err := m.GetLuckDrawByID(id)
48
+	if err != nil {
49
+		return nil, err
50
+	}
51
+	prizes, err := m.GetPrizes(id)
52
+	if err != nil {
53
+		return nil, err
54
+	}
55
+	luckdraw.Prizes = prizes
56
+	return luckdraw, nil
57
+}
58
+
59
+// LuckDraw 抽奖
60
+func (m *DAO) LuckDraw(id int, user *model.TaCustomer) (*model.TaLuckdrawPrize, *model.TaPrizeDetail, error) {
61
+	luckdraw, err := m.GetLuckDrawByID(id)
62
+	if err != nil {
63
+		return nil, nil, utils.LogError("获取抽奖信息失败!", err)
64
+	}
65
+	if luckdraw.Status != models.STATUS_NORMAL {
66
+		return nil, nil, utils.LogError("当前抽奖活动状态异常!")
67
+	}
68
+	if time.Now().Before(luckdraw.BeginDate) {
69
+		return nil, nil, utils.LogError("活动还未开始!")
70
+	}
71
+	if time.Now().After(luckdraw.EndDate) {
72
+		return nil, nil, utils.LogError("活动已结束!")
73
+	}
74
+	if user.Phone != "" {
75
+		sysuser, err := m.GetUserByTel(user.Phone)
76
+		if err != nil {
77
+			return nil, nil, utils.LogError("获取信息失败!", err)
78
+		}
79
+		if sysuser != nil {
80
+			return nil, nil, utils.LogError("内部人员不允许进行抽奖!")
81
+		}
82
+	}
83
+	userluckdraws, err := m.GetUserRecordByLuckDraw(user.CustomerId, id)
84
+	if err != nil {
85
+		return nil, nil, utils.LogError("获取用户抽奖信息失败!", err)
86
+	}
87
+	if len(userluckdraws) > 0 {
88
+		return nil, nil, utils.LogError("您已参与过此次抽奖,不允许重复抽奖!")
89
+	}
90
+	prizes, err := m.GetPrizeStock(id)
91
+	if err != nil {
92
+		return nil, nil, utils.LogError("获取奖项失败!", err)
93
+	}
94
+	if len(prizes) == 0 {
95
+		err = m.UpdateLuckDrawEndDate(luckdraw.Id)
96
+		if err != nil {
97
+			return nil, nil, utils.LogError("操作失败,请刷新后重试!", err)
98
+		}
99
+		return nil, nil, utils.LogError("活动已结束!")
100
+	}
101
+	prize, err := m.GetWinning(prizes)
102
+	if err != nil {
103
+		return nil, nil, utils.LogError("获取奖项失败!", err)
104
+	}
105
+
106
+	details, err := m.GetPrizeDetail(prize.Id)
107
+	if err != nil {
108
+		return nil, nil, utils.LogError("获取奖项详情失败!", err)
109
+	}
110
+
111
+	// 保存中奖记录
112
+	var record = model.TaLuckdrawRecord{}
113
+	record.OrgId = luckdraw.OrgId
114
+	record.CaseId = luckdraw.CaseId
115
+	record.PrizeId = prize.Id
116
+	record.PrizeName = prize.PrizeName
117
+	record.UserId = user.CustomerId
118
+	record.UserName = user.Name
119
+	record.UserHeadImg = user.Headimgurl
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
+	}
137
+	// 更新库存
138
+	if prize.IsReality == 1 {
139
+		prize.Remainder = prize.Remainder - 1
140
+		err = m.UpdateStock(prize)
141
+		if err != nil {
142
+			return nil, nil, err
143
+		}
144
+		stockprizes, err := m.GetPrizeStock(id)
145
+		if err != nil {
146
+			return nil, nil, utils.LogError("操作失败,请刷新后重试!", err)
147
+		}
148
+		if len(stockprizes) == 0 {
149
+			// 更新活动截止时间
150
+			err = m.UpdateLuckDrawEndDate(luckdraw.Id)
151
+		}
152
+	}
153
+
154
+	return prize, &detail, err
155
+}
156
+
157
+// PrizeWriteOff 奖品核销
158
+func (m *DAO) PrizeWriteOff(recordid int, userid string) error {
159
+	record, err := m.GetRecordByID(recordid)
160
+	if err != nil {
161
+		return err
162
+	}
163
+	var writeoff = model.TaLuckdrawWriteoff{}
164
+	writeoff.LuckdrawId = record.LuckdrawId
165
+	writeoff.CaseId = record.CaseId
166
+	writeoff.OrgId = record.OrgId
167
+	writeoff.RecordId = record.Id
168
+	writeoff.WriteoffUser = userid
169
+	_, err = m.SaveWirteOff(writeoff)
170
+	if err != nil {
171
+		return err
172
+	}
173
+	err = m.UpdateRecord(record)
174
+	return err
175
+}
176
+
177
+// GetWinning 获取中奖信息
178
+func (m *DAO) GetWinning(prizes []model.TaLuckdrawPrize) (*model.TaLuckdrawPrize, error) {
179
+	pList := make([]map[string]interface{}, 0)
180
+	now := time.Now().Local()
181
+
182
+	for _, prize := range prizes {
183
+		// 有剩余的 并且 未过期的
184
+		if prize.Remainder > 0 && now.Before(prize.VerificationEnd) {
185
+			p := map[string]interface{}{
186
+				"prize": prize,
187
+				"prob":  prize.Probability,
188
+			}
189
+
190
+			pList = append(pList, p)
191
+		}
192
+	}
193
+
194
+	if len(pList) == 0 {
195
+		return nil, utils.LogError("所有奖品已抽完")
196
+	}
197
+
198
+	thePrize := utils.LuckyDraw(pList).(model.TaLuckdrawPrize)
199
+
200
+	return &thePrize, nil
201
+}
202
+
203
+// GetLuckDrawByID 获取抽奖信息
204
+func (m *DAO) GetLuckDrawByID(id int) (*LuckDraw, error) {
205
+	var luckdraws []LuckDraw
206
+	sql := `select * from ta_luckdraw where id= ?`
207
+	err := m.db.SQL(sql, id).Find(&luckdraws)
208
+	if err != nil {
209
+		return nil, err
210
+	}
211
+	if len(luckdraws) > 0 {
212
+		return &luckdraws[0], nil
213
+	}
214
+	return nil, nil
215
+}
216
+
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
+// UpdateLuckDrawEndDate 更新活动结束时间
242
+func (m *DAO) UpdateLuckDrawEndDate(id int) error {
243
+	var luckdraw = model.TaLuckdraw{
244
+		Id:      id,
245
+		EndDate: time.Now(),
246
+	}
247
+	cols := []string{
248
+		"end_date",
249
+	}
250
+	_, err := m.db.Update(luckdraw, cols, "id=?", id)
251
+	return err
252
+}
253
+
254
+// GetPrizes 获取奖品信息
255
+func (m *DAO) GetPrizes(luckdrawid int) ([]model.TaLuckdrawPrize, error) {
256
+	var prizes []model.TaLuckdrawPrize
257
+	err := m.db.Where("luckdraw_id=?", luckdrawid).And("status=?", models.STATUS_NORMAL).Find(&prizes)
258
+	return prizes, err
259
+}
260
+
261
+// UpdateStock 修改库存
262
+func (m *DAO) UpdateStock(prize *model.TaLuckdrawPrize) error {
263
+	cols := []string{
264
+		"remainder",
265
+	}
266
+	_, err := m.db.Update(prize, cols, "id=?", prize.Id)
267
+	return err
268
+}
269
+
270
+// GetPrizeStock 判断奖项库存
271
+func (m *DAO) GetPrizeStock(luckdrawid int) ([]model.TaLuckdrawPrize, error) {
272
+	var prizes []model.TaLuckdrawPrize
273
+	err := m.db.Where("luckdraw_id=?", luckdrawid).And("status=?", models.STATUS_NORMAL).And("(remainder>0 or is_reality=0)").Find(&prizes)
274
+	return prizes, err
275
+}
276
+
277
+// GetPrizeByID 根据id获取奖品信息
278
+func (m *DAO) GetPrizeByID(id int) (model.TaLuckdrawPrize, error) {
279
+	var prize = model.TaLuckdrawPrize{}
280
+	_, err := m.db.Where("id=?", id).Get(&prize)
281
+	return prize, err
282
+}
283
+
284
+// SaveRecord 保存抽奖记录
285
+func (m *DAO) SaveRecord(record model.TaLuckdrawRecord) (*model.TaLuckdrawRecord, error) {
286
+	record.CreateDate = time.Now()
287
+	record.Status = STATUS_NOWRITROFF
288
+	_, err := m.db.Insert(&record)
289
+	return &record, err
290
+}
291
+
292
+// GetPrizeDetail 获取未领取的奖品详情
293
+func (m *DAO) GetPrizeDetail(prizeid int) ([]model.TaPrizeDetail, error) {
294
+	var details []model.TaPrizeDetail
295
+	err := m.db.Where("prize_id=?", prizeid).And("status=?", STATUS_NOWRITROFF).Find(&details)
296
+	return details, err
297
+}
298
+
299
+// UpdatePrizeDetail 更新库存明细为已领取
300
+func (m *DAO) UpdatePrizeDetail(detail model.TaPrizeDetail) error {
301
+	detail.Status = models.STATUS_NORMAL
302
+	detail.ReceiveDate = time.Now()
303
+	cols := []string{
304
+		"status",
305
+		"receive_id",
306
+		"receive_date",
307
+	}
308
+	_, err := m.db.Update(detail, cols, "id=?", detail.Id)
309
+	return err
310
+}
311
+
312
+// UpdateRecord 核销更新抽奖记录表
313
+func (m *DAO) UpdateRecord(record *model.TaLuckdrawRecord) error {
314
+	record.Status = models.STATUS_NORMAL
315
+	record.WriteoffDate = time.Now()
316
+	cols := []string{
317
+		"status",
318
+		"writeoff_date",
319
+	}
320
+	_, err := m.db.Update(record, cols, "id=?", record.Id)
321
+	return err
322
+}
323
+
324
+// SaveWirteOff 保存核销信息
325
+func (m *DAO) SaveWirteOff(writeoff model.TaLuckdrawWriteoff) (*model.TaLuckdrawWriteoff, error) {
326
+	writeoff.Status = models.STATUS_NORMAL
327
+	writeoff.WriteoffDate = time.Now()
328
+	_, err := m.db.Insert(&writeoff)
329
+	return &writeoff, err
330
+}
331
+
332
+// GetUserRecordByLuckDraw 获取用户的抽奖信息
333
+func (m *DAO) GetUserRecordByLuckDraw(userid string, luckdrawid int) ([]model.TaLuckdrawRecord, error) {
334
+	var records []model.TaLuckdrawRecord
335
+	err := m.db.Where("user_id=?", userid).And("luckdraw_id=?", luckdrawid).And("status>" + strconv.Itoa(models.STATUS_DEL)).Find(&records)
336
+	return records, err
337
+}
338
+
339
+// GetUserLuckDrawByLuckDraw 获取用户的抽奖信息
340
+func (m *DAO) GetUserLuckDrawByLuckDraw(userid string, luckdrawid int) (*model.TaLuckdrawRecord, error) {
341
+	var records []model.TaLuckdrawRecord
342
+	err := m.db.Where("user_id=?", userid).And("luckdraw_id=?", luckdrawid).And("status>" + strconv.Itoa(models.STATUS_DEL)).Find(&records)
343
+	if err != nil {
344
+		return nil, err
345
+	}
346
+	if len(records) > 0 {
347
+		return &records[0], nil
348
+	}
349
+	return nil, nil
350
+}
351
+
352
+// GetDetailByRecord 获取detail
353
+func (m *DAO) GetDetailByRecord(recordid int) (*model.TaPrizeDetail, error) {
354
+	var details []model.TaPrizeDetail
355
+	err := m.db.Where("receive_id=?", recordid).And("status>" + strconv.Itoa(models.STATUS_DEL)).Find(&details)
356
+	if err != nil {
357
+		return nil, err
358
+	}
359
+	if len(details) > 0 {
360
+		return &details[0], nil
361
+	}
362
+	return nil, nil
363
+}
364
+
365
+// UserRecord 用户抽奖信息
366
+type UserRecord struct {
367
+	model.TaLuckdrawRecord `xorm:"extends"`
368
+	Url                    string
369
+}
370
+
371
+// GetUserLuckDraw 获取用户的抽奖信息
372
+func (m *DAO) GetUserLuckDraw(userid string) ([]UserRecord, error) {
373
+	var records []UserRecord
374
+	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
+	err := m.db.Sql(sql, userid).Find(&records)
376
+	return records, err
377
+}
378
+
379
+// GetRecordByLuckDraw 抽奖记录
380
+func (m *DAO) GetRecordByLuckDraw(luckdrawid int) ([]model.TaLuckdrawRecord, error) {
381
+	var records []model.TaLuckdrawRecord
382
+	err := m.db.Where("luckdraw_id=?", luckdrawid).And("status>" + strconv.Itoa(models.STATUS_DEL)).Desc("create_date").Find(&records)
383
+	return records, err
384
+}
385
+
386
+// GetRecordByID 获取抽奖记录明细
387
+func (m *DAO) GetRecordByID(id int) (*model.TaLuckdrawRecord, error) {
388
+	var record model.TaLuckdrawRecord
389
+	_, err := m.db.Where("id=?", id).Get(&record)
390
+	return &record, err
391
+}
392
+
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
+// SaveLuckDrawShareData 保存用户分享信息
420
+func (m *DAO) SaveLuckDrawShareData(dt *model.TaShareLuckyRecord) error {
421
+	dt.CreateDate = time.Now().Local()
422
+	dt.Status = StatusNormal
423
+
424
+	if _, err := m.db.Insert(dt); err != nil {
425
+		return err
426
+	}
427
+
428
+	return nil
429
+}
430
+
431
+// GetLuckDrawShareData 获取用户分享内容
432
+func (m *DAO) GetLuckDrawShareData(luckID int, from, to, caseID string) ([]model.TaShareLuckyRecord, error) {
433
+	var dts []model.TaShareLuckyRecord
434
+
435
+	if err := m.db.Where("from_customer_id=?", from).
436
+		And("to_customer_id=?", to).
437
+		And("luckydraw_id=?", luckID).
438
+		And("case_id=?", caseID).
439
+		And("status=?", StatusNormal).
440
+		Find(&dts); err != nil {
441
+		return nil, err
442
+	}
443
+
444
+	return dts, nil
445
+}

+ 1
- 1
models/model/ta_luckdraw.go Parādīt failu

@@ -12,7 +12,7 @@ type TaLuckdraw struct {
12 12
 	BeginDate    time.Time `xorm:"DATETIME"`
13 13
 	EndDate      time.Time `xorm:"DATETIME"`
14 14
 	OrgId        string    `xorm:"VARCHAR(64)"`
15
-	CaseId       int       `xorm:"INT(11)"`
15
+	CaseId       string    `xorm:"VARCHAR(64)"`
16 16
 	CreateDate   time.Time `xorm:"DATETIME"`
17 17
 	CreateUser   string    `xorm:"VARCHAR(64)"`
18 18
 	Remark       string    `xorm:"TEXT"`

+ 6
- 0
routers/wechat.go Parādīt failu

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

+ 2
- 2
service/bodycheck/bodycheck.go Parādīt failu

@@ -20,7 +20,7 @@ func NewBodycheckServ(ctx *utils.Context) *BodycheckServ {
20 20
 		dao: bodycheck.NewDAO(ctx),
21 21
 	}
22 22
 }
23
-func (s *BodycheckServ) GetBodyCheckByUser(userID int) ([]model.TaBodyCheck, error) {
23
+func (s *BodycheckServ) GetBodyCheckByUser(userID string) ([]model.TaBodyCheck, error) {
24 24
 	bodychecks, err := s.dao.GetBodyCheckByUser(userID)
25 25
 	if err != nil {
26 26
 		utils.LogError("查询用户体检信息失败: " + err.Error())
@@ -36,7 +36,7 @@ func (s *BodycheckServ) GetCheckSpecs() ([]model.TdCheckSpec, error) {
36 36
 	}
37 37
 	return specs, nil
38 38
 }
39
-func (s *BodycheckServ) GetCheckByUserAndEquipmentID(userID int, EquipmentID string) (*model.TaBodyCheck, error) {
39
+func (s *BodycheckServ) GetCheckByUserAndEquipmentID(userID string, EquipmentID string) (*model.TaBodyCheck, error) {
40 40
 	check, err := s.dao.GetCheckByUserAndEquipmentID(userID, EquipmentID)
41 41
 	if err != nil {
42 42
 		utils.LogError("根据用户与设备ID获取体检信息失败: " + err.Error())

+ 30
- 27
service/gymcard/gymcard.go Parādīt failu

@@ -196,34 +196,37 @@ func (s *GymcardServ) SendGymCardToUser(gymcardId, sysuserId string) (*model.TaC
196 196
 	return customerGym, nil
197 197
 }
198 198
 
199
-// SendGymCardToUser 后台给客户发卡
200
-func (s *GymcardServ) BackSendGymCardToUser(gymcardId, sysuserId, customerId string) (*model.TaCustomerGym, error) {
201
-	var customerGym *model.TaCustomerGym
202
-	var sysuser *model.SysUser
203
-	gymCard, err := s.dao.GetGymcardById(gymcardId)
204
-	if err != nil {
205
-		utils.LogError("发送游泳健身卡给客户失败" + err.Error())
206
-		return nil, errors.New("发送游泳健身卡给客户失败")
207
-	}
208
-	sysuser, err = s.cdao.GetUserByID(sysuserId)
209
-	if err != nil {
210
-		utils.LogError("发送游泳健身卡给客户失败" + err.Error())
211
-		return nil, errors.New("发送游泳健身卡给客户失败")
212
-	}
213
-	gymCard.SentCount = gymCard.SentCount + 1
214
-	customerGym, err = s.dao.SendGymcardToCustomer(&gymCard.TaGymCard, customerId, sysuserId, sysuser.RealName)
215
-	if err != nil {
216
-		utils.LogError("发送游泳健身卡给客户失败" + err.Error())
217
-		return nil, errors.New("发送游泳健身卡给客户失败")
218
-	}
199
+// // SendGymCardToUser 后台给客户发卡
200
+// func (s *GymcardServ) BackSendGymCardToUser(gymcardId, sysuserId, customerId string) (*model.TaCustomerGym, error) {
201
+// 	var customerGym *model.TaCustomerGym
202
+// 	var sysuser *model.SysUser
203
+// 	gymCard, err := s.dao.GetGymcardById(gymcardId)
204
+// 	if err != nil {
205
+// 		utils.LogError("发送游泳健身卡给客户失败" + err.Error())
206
+// 		return nil, errors.New("发送游泳健身卡给客户失败")
207
+// 	}
208
+// 	if gymCard.TotalCount-gymCard.SentCount < 1 {
209
+// 		return nil, errors.New("健身卡剩余数量不足!")
210
+// 	}
211
+// 	sysuser, err = s.cdao.GetUserByID(sysuserId)
212
+// 	if err != nil {
213
+// 		utils.LogError("发送游泳健身卡给客户失败" + err.Error())
214
+// 		return nil, errors.New("发送游泳健身卡给客户失败")
215
+// 	}
216
+// 	gymCard.SentCount = gymCard.SentCount + 1
217
+// 	customerGym, err = s.dao.SendGymcardToCustomer(&gymCard.TaGymCard, customerId, sysuserId, sysuser.RealName,)
218
+// 	if err != nil {
219
+// 		utils.LogError("发送游泳健身卡给客户失败" + err.Error())
220
+// 		return nil, errors.New("发送游泳健身卡给客户失败")
221
+// 	}
219 222
 
220
-	err = s.dao.EditGymcard(&gymCard.TaGymCard)
221
-	if err != nil {
222
-		utils.LogError("发送游泳健身卡给客户失败" + err.Error())
223
-		return nil, errors.New("发送游泳健身卡给客户失败")
224
-	}
225
-	return customerGym, nil
226
-}
223
+// 	err = s.dao.EditGymcard(&gymCard.TaGymCard)
224
+// 	if err != nil {
225
+// 		utils.LogError("发送游泳健身卡给客户失败" + err.Error())
226
+// 		return nil, errors.New("发送游泳健身卡给客户失败")
227
+// 	}
228
+// 	return customerGym, nil
229
+// }
227 230
 
228 231
 // UpdateCustomerGym 核销游泳健身卡
229 232
 func (s *GymcardServ) UpdateCustomerGym(customerGymId, caseid string) error {

+ 237
- 0
service/luckdraw/luckdraw.go Parādīt failu

@@ -0,0 +1,237 @@
1
+package luckdraw
2
+
3
+import (
4
+	"errors"
5
+	"spaceofcheng/services/models/luckdraw"
6
+	"spaceofcheng/services/models/model"
7
+	"spaceofcheng/services/utils"
8
+)
9
+
10
+// LuckdrawServ 系统处理
11
+type LuckdrawServ struct {
12
+	ctx *utils.Context
13
+	dao *luckdraw.DAO
14
+}
15
+
16
+// NewLuckdrawServ 初始化
17
+func NewLuckdrawServ(ctx *utils.Context) *LuckdrawServ {
18
+	return &LuckdrawServ{
19
+		ctx: ctx,
20
+		dao: luckdraw.NewDAO(ctx),
21
+	}
22
+}
23
+
24
+func (s *LuckdrawServ) GetLuckDraw(id int) (*luckdraw.LuckDraw, error) {
25
+	luck, err := s.dao.GetLuckDraw(id)
26
+	if err != nil {
27
+		return nil, err
28
+	}
29
+	return luck, nil
30
+}
31
+func (s *LuckdrawServ) LuckDraw(id int, user *model.TaCustomer) (*model.TaLuckdrawPrize, *model.TaPrizeDetail, error) {
32
+	prize, prizeDetail, err := s.dao.LuckDraw(id, user)
33
+	if err != nil {
34
+		return nil, nil, err
35
+	}
36
+	return prize, prizeDetail, nil
37
+}
38
+func (s *LuckdrawServ) PrizeWriteOff(recordid int, userid string) error {
39
+	err := s.dao.PrizeWriteOff(recordid, userid)
40
+	if err != nil {
41
+		utils.LogError("奖品核销失败: " + err.Error())
42
+		return errors.New("奖品核销失败")
43
+	}
44
+	return nil
45
+}
46
+func (s *LuckdrawServ) GetWinning(prizes []model.TaLuckdrawPrize) (*model.TaLuckdrawPrize, error) {
47
+	prize, err := s.dao.GetWinning(prizes)
48
+	if err != nil {
49
+		return nil, err
50
+	}
51
+	return prize, nil
52
+}
53
+func (s *LuckdrawServ) GetLuckDrawByID(id int) (*luckdraw.LuckDraw, error) {
54
+	luck, err := s.dao.GetLuckDrawByID(id)
55
+	if err != nil {
56
+		utils.LogError("获取抽奖信息失败: " + err.Error())
57
+		return nil, errors.New("获取抽奖信息失败")
58
+	}
59
+	return luck, nil
60
+}
61
+func (s *LuckdrawServ) GetCaseAddressByLuckDarw(luckdraw int) (string, error) {
62
+	address, err := s.dao.GetCaseAddressByLuckDarw(luckdraw)
63
+	if err != nil {
64
+		utils.LogError("获取案场地址失败: " + err.Error())
65
+		return "", errors.New("获取案场地址失败")
66
+	}
67
+	return address, nil
68
+}
69
+func (s *LuckdrawServ) UpdateLuckDrawEndDate(id int) error {
70
+	err := s.dao.UpdateLuckDrawEndDate(id)
71
+	if err != nil {
72
+		utils.LogError("更新活动结束时间失败: " + err.Error())
73
+		return errors.New("更新活动结束时间失败")
74
+	}
75
+	return nil
76
+}
77
+func (s *LuckdrawServ) GetPrizes(luckdrawid int) ([]model.TaLuckdrawPrize, error) {
78
+	prize, err := s.dao.GetPrizes(luckdrawid)
79
+	if err != nil {
80
+		utils.LogError("获取奖品信息失败: " + err.Error())
81
+		return nil, errors.New("获取奖品信息失败")
82
+	}
83
+	return prize, nil
84
+}
85
+func (s *LuckdrawServ) UpdateStock(prize *model.TaLuckdrawPrize) error {
86
+	err := s.dao.UpdateStock(prize)
87
+	if err != nil {
88
+		utils.LogError("修改库存失败: " + err.Error())
89
+		return errors.New("修改库存失败")
90
+	}
91
+	return nil
92
+}
93
+func (s *LuckdrawServ) GetPrizeStock(luckdrawid int) ([]model.TaLuckdrawPrize, error) {
94
+	prize, err := s.dao.GetPrizeStock(luckdrawid)
95
+	if err != nil {
96
+		utils.LogError("判断奖项库存失败: " + err.Error())
97
+		return nil, errors.New("判断奖项库存失败")
98
+	}
99
+	return prize, nil
100
+}
101
+func (s *LuckdrawServ) GetPrizeByID(id int) (model.TaLuckdrawPrize, error) {
102
+	prize, err := s.dao.GetPrizeByID(id)
103
+	if err != nil {
104
+		utils.LogError("根据id获取奖品信息失败: " + err.Error())
105
+		return prize, errors.New("根据id获取奖品信息失败")
106
+	}
107
+	return prize, nil
108
+}
109
+func (s *LuckdrawServ) SaveRecord(record model.TaLuckdrawRecord) (*model.TaLuckdrawRecord, error) {
110
+	newRecord, err := s.dao.SaveRecord(record)
111
+	if err != nil {
112
+		utils.LogError("保存抽奖记录失败: " + err.Error())
113
+		return nil, errors.New("保存抽奖记录失败")
114
+	}
115
+	return newRecord, nil
116
+
117
+}
118
+func (s *LuckdrawServ) GetPrizeDetail(prizeid int) ([]model.TaPrizeDetail, error) {
119
+	detail, err := s.dao.GetPrizeDetail(prizeid)
120
+	if err != nil {
121
+		utils.LogError("获取未领取的奖品详情失败: " + err.Error())
122
+		return nil, errors.New("获取未领取的奖品详情失败")
123
+	}
124
+	return detail, nil
125
+}
126
+
127
+func (s *LuckdrawServ) UpdatePrizeDetail(detail model.TaPrizeDetail) error {
128
+	err := s.dao.UpdatePrizeDetail(detail)
129
+	if err != nil {
130
+		utils.LogError("更新库存明细为已领取失败: " + err.Error())
131
+		return errors.New("更新库存明细为已领取失败")
132
+	}
133
+	return nil
134
+}
135
+func (s *LuckdrawServ) UpdateRecord(record *model.TaLuckdrawRecord) error {
136
+	err := s.dao.UpdateRecord(record)
137
+	if err != nil {
138
+		utils.LogError("核销更新抽奖记录表失败: " + err.Error())
139
+		return errors.New("核销更新抽奖记录表失败")
140
+	}
141
+	return nil
142
+}
143
+func (s *LuckdrawServ) SaveWirteOff(writeoff model.TaLuckdrawWriteoff) (*model.TaLuckdrawWriteoff, error) {
144
+	newWriteoff, err := s.dao.SaveWirteOff(writeoff)
145
+	if err != nil {
146
+		utils.LogError("保存核销信息失败: " + err.Error())
147
+		return nil, errors.New("保存核销信息失败")
148
+	}
149
+	return newWriteoff, nil
150
+}
151
+func (s *LuckdrawServ) GetUserRecordByLuckDraw(userid string, luckdrawid int) ([]model.TaLuckdrawRecord, error) {
152
+	record, err := s.dao.GetUserRecordByLuckDraw(userid, luckdrawid)
153
+	if err != nil {
154
+		utils.LogError("获取用户的抽奖信息失败: " + err.Error())
155
+		return nil, errors.New("获取用户的抽奖信息失败")
156
+	}
157
+	return record, nil
158
+}
159
+func (s *LuckdrawServ) GetUserLuckDrawByLuckDraw(userid string, luckdrawid int) (*model.TaLuckdrawRecord, error) {
160
+	record, err := s.dao.GetUserLuckDrawByLuckDraw(userid, luckdrawid)
161
+	if err != nil {
162
+		utils.LogError("获取用户的抽奖信息失败: " + err.Error())
163
+		return nil, errors.New("获取用户的抽奖信息失败")
164
+	}
165
+	return record, nil
166
+}
167
+func (s *LuckdrawServ) GetDetailByRecord(recordid int) (*model.TaPrizeDetail, error) {
168
+	detail, err := s.dao.GetDetailByRecord(recordid)
169
+	if err != nil {
170
+		utils.LogError("获取detail失败: " + err.Error())
171
+		return nil, errors.New("获取detail失败")
172
+	}
173
+	return detail, nil
174
+
175
+}
176
+func (s *LuckdrawServ) GetUserLuckDraw(userid string) ([]luckdraw.UserRecord, error) {
177
+	record, err := s.dao.GetUserLuckDraw(userid)
178
+	if err != nil {
179
+		utils.LogError("获取用户的抽奖信息失败: " + err.Error())
180
+		return nil, errors.New("获取用户的抽奖信息失败")
181
+	}
182
+	return record, nil
183
+
184
+}
185
+func (s *LuckdrawServ) GetRecordByLuckDraw(luckdrawid int) ([]model.TaLuckdrawRecord, error) {
186
+	record, err := s.dao.GetRecordByLuckDraw(luckdrawid)
187
+	if err != nil {
188
+		utils.LogError("获取抽奖记录失败: " + err.Error())
189
+		return nil, errors.New("获取抽奖记录失败")
190
+	}
191
+	return record, nil
192
+
193
+}
194
+func (s *LuckdrawServ) GetRecordByID(id int) (*model.TaLuckdrawRecord, error) {
195
+	record, err := s.dao.GetRecordByID(id)
196
+	if err != nil {
197
+		utils.LogError("获取抽奖记录明细失败: " + err.Error())
198
+		return nil, errors.New("获取抽奖记录明细失败")
199
+	}
200
+	return record, nil
201
+}
202
+func (s *LuckdrawServ) GetUserByOpenID(openid string) (*model.SysUser, error) {
203
+	user, err := s.dao.GetUserByOpenID(openid)
204
+	if err != nil {
205
+		utils.LogError("根据 openid 获取用户人员信息失败: " + err.Error())
206
+		return nil, errors.New("根据 openid 获取用户人员信息失败")
207
+	}
208
+	return user, nil
209
+
210
+}
211
+func (s *LuckdrawServ) GetUserByTel(tel string) (*model.SysUser, error) {
212
+	user, err := s.dao.GetUserByTel(tel)
213
+	if err != nil {
214
+		utils.LogError("根据 tel 获取用户人员信息失败: " + err.Error())
215
+		return nil, errors.New("根据 tel 获取用户人员信息失败")
216
+	}
217
+	return user, nil
218
+
219
+}
220
+
221
+func (s *LuckdrawServ) SaveLuckDrawShareData(dt *model.TaShareLuckyRecord) error {
222
+	err := s.dao.SaveLuckDrawShareData(dt)
223
+	if err != nil {
224
+		utils.LogError("保存用户分享信息失败: " + err.Error())
225
+		return errors.New("保存用户分享信息失败")
226
+	}
227
+	return nil
228
+
229
+}
230
+func (s *LuckdrawServ) GetLuckDrawShareData(luckID int, from, to, caseID string) ([]model.TaShareLuckyRecord, error) {
231
+	share, err := s.dao.GetLuckDrawShareData(luckID, from, to, caseID)
232
+	if err != nil {
233
+		utils.LogError("获取抽奖分享失败: " + err.Error())
234
+		return nil, errors.New("获取抽奖分享失败")
235
+	}
236
+	return share, nil
237
+}

+ 2
- 2
service/verify/verify.go Parādīt failu

@@ -115,9 +115,9 @@ func (s *VerifyServ) UpdateCustomerCourseDetail(customerDetail *model.TaCustomer
115 115
 	customerDetail.VerifyDate = time.Now()
116 116
 	customerDetail.VerifyUser = userid
117 117
 	if time.Now().After(customerDetail.EndDate) {
118
-		customerDetail.VerifyStatus = "late"
118
+		customerDetail.VerifyStatus = models.VERIFY_LATE
119 119
 	} else {
120
-		customerDetail.VerifyStatus = "used"
120
+		customerDetail.VerifyStatus = models.VERIFY_USED
121 121
 	}
122 122
 	err = s.dao.UpdateCustomerCourseDetail(customerDetail)
123 123
 	if err != nil {

+ 64
- 0
utils/rand.go Parādīt failu

@@ -0,0 +1,64 @@
1
+package utils
2
+
3
+import (
4
+	"math/rand"
5
+	"reflect"
6
+	"time"
7
+)
8
+
9
+var rnd = rand.New(rand.NewSource(time.Now().UnixNano()))
10
+
11
+// Shuffle 随机数组
12
+func Shuffle(arr interface{}) interface{} {
13
+	newSeed()
14
+
15
+	v := reflect.ValueOf(arr)
16
+
17
+	arrLen := v.Len()
18
+	res := reflect.MakeSlice(v.Type(), arrLen, arrLen)
19
+	reflect.Copy(res, v)
20
+
21
+	for i := 0; i < arrLen; i++ {
22
+		m := rnd.Intn(arrLen)
23
+		n := arrLen - m - 1
24
+
25
+		swp := res.Index(m)
26
+		res.Index(m).Set(res.Index(n))
27
+		res.Index(n).Set(swp)
28
+	}
29
+
30
+	return res.Interface()
31
+}
32
+
33
+// LuckyDraw 抽奖
34
+func LuckyDraw(pList []map[string]interface{}) interface{} {
35
+	// 奖池
36
+	pool := make([]interface{}, 0)
37
+
38
+	// 生成奖池
39
+	for _, it := range pList {
40
+		prize := it["prize"]
41
+		prob := it["prob"].(int)
42
+
43
+		for i := 0; i < prob; i++ {
44
+			pool = append(pool, prize)
45
+		}
46
+	}
47
+
48
+	poolLen := len(pool)
49
+	if poolLen == 0 {
50
+		return nil
51
+	}
52
+
53
+	// 打乱奖池 - 打乱两次, 以使其更混乱, 更随机
54
+	pool = Shuffle(pool).([]interface{})
55
+
56
+	newSeed()
57
+	inx := rnd.Intn(poolLen)
58
+	return pool[inx]
59
+}
60
+
61
+func newSeed() {
62
+	seed := time.Now().UnixNano() + int64(rnd.Intn(1000)*1000)
63
+	rnd.Seed(seed)
64
+}