wangfei 6 年之前
父節點
當前提交
7021fcb492
共有 7 個文件被更改,包括 141 次插入38 次删除
  1. 1
    2
      conf/app.conf
  2. 11
    0
      controllers/coupon/coupon.go
  3. 33
    0
      log/common.log
  4. 25
    10
      models/coupon/coupon.go
  5. 6
    0
      models/coupon/types.go
  6. 13
    0
      service/coupon/coupon.go
  7. 52
    26
      service/sys.go

+ 1
- 2
conf/app.conf 查看文件

@@ -1,10 +1,9 @@
1 1
 appname = services
2 2
 httpport = 8080
3
-runmode = dev
3
+runmode = prod
4 4
 autorender = false
5 5
 copyrequestbody = true
6 6
 EnableDocs = true
7
-sessionon = false
8 7
 excelpath = ./
9 8
 clienturl = http://dev.ycjcjy.com/c-v2
10 9
 

+ 11
- 0
controllers/coupon/coupon.go 查看文件

@@ -178,3 +178,14 @@ func (c *CouponController) GetCouponBySendType() {
178 178
 
179 179
 	c.ResponseJSON(coupons)
180 180
 }
181
+
182
+// GetCouponWithCustomer 获取优惠券领取信息
183
+func (c *CouponController) GetCouponWithCustomer() {
184
+	couponid := c.GetString(":id")
185
+	couponDetail, err := c.serv.GetCouponWithCustomer(couponid)
186
+	if err != nil {
187
+		c.ResponseError(err)
188
+	}
189
+
190
+	c.ResponseJSON(couponDetail)
191
+}

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

@@ -3120,3 +3120,36 @@
3120 3120
 2018/09/13 10:24:25 [E] 用户没有设置默认案场
3121 3121
 2018/09/13 10:49:12 [E] 用户没有设置默认案场
3122 3122
 >>>>>>> yansen
3123
+2018/09/13 17:53:24 [I] 请求远程接口: %!(EXTRA string=https://api.weixin.qq.com/cgi-bin/token?appid=wx7320287e057bbeee&grant_type=client_credential&secret=6e844dc2ade439545c47569ba1707673)
3124
+2018/09/13 17:53:24 [I] 远程请求结果:%!(EXTRA string={"access_token":"13_sAtgG_I5C0cIB3oE07TwgL0liULpmiKC2LVmEoLV4qAjnw62EGxoKcM6Rwq4ZDQO80ZDZ6Y0g1gX5yTTgmZM-luw5RIGI9l8fkeOfgTk3paqL9Eaf0Qc40p9cLa8XZlFgXaUvwFshVLM2dv1SMHhAGAMGB","expires_in":7200})
3125
+2018/09/13 17:53:24 [I] 接口返回结果: %!(EXTRA map[string]interface {}=map[access_token:13_sAtgG_I5C0cIB3oE07TwgL0liULpmiKC2LVmEoLV4qAjnw62EGxoKcM6Rwq4ZDQO80ZDZ6Y0g1gX5yTTgmZM-luw5RIGI9l8fkeOfgTk3paqL9Eaf0Qc40p9cLa8XZlFgXaUvwFshVLM2dv1SMHhAGAMGB expires_in:7200])
3126
+2018/09/13 17:55:33 [I] 请求远程接口: %!(EXTRA string=https://api.weixin.qq.com/cgi-bin/token?appid=wx7320287e057bbeee&grant_type=client_credential&secret=6e844dc2ade439545c47569ba1707673)
3127
+2018/09/13 17:55:33 [I] 远程请求结果:%!(EXTRA string={"access_token":"13_BgSpOJyw7POeYv2-lhNILmp7cu0uXc3D0R1xtwtWSDEz26Yci4pkYNra445VNzJCSaTxLHiF_b4UVjq3hzAQ7LH1icPj7qJN_aMNFyC8Li-C4FAxeCTPeaVpAYEGEi3ibB2BC1kTaJeyUUNaFRGbAIAIUJ","expires_in":7200})
3128
+2018/09/13 17:55:33 [I] 接口返回结果: %!(EXTRA map[string]interface {}=map[access_token:13_BgSpOJyw7POeYv2-lhNILmp7cu0uXc3D0R1xtwtWSDEz26Yci4pkYNra445VNzJCSaTxLHiF_b4UVjq3hzAQ7LH1icPj7qJN_aMNFyC8Li-C4FAxeCTPeaVpAYEGEi3ibB2BC1kTaJeyUUNaFRGbAIAIUJ expires_in:7200])
3129
+2018/09/13 18:35:49 [E] 解析 Token 失败: token contains an invalid number of segments
3130
+2018/09/13 18:36:27 [E] 解析 Token 失败: token contains an invalid number of segments
3131
+2018/09/13 18:48:47 [E] 解析 Token 失败: token contains an invalid number of segments
3132
+2018/09/13 18:55:18 [E] 解析 Token 失败: token contains an invalid number of segments
3133
+2018/09/13 18:59:53 [E] 解析 Token 失败: token contains an invalid number of segments
3134
+2018/09/13 18:59:53 [I] 请求远程接口: %!(EXTRA string=https://api.weixin.qq.com/cgi-bin/token?appid=wx7320287e057bbeee&grant_type=client_credential&secret=6e844dc2ade439545c47569ba1707673)
3135
+2018/09/13 18:59:53 [I] 远程请求结果:%!(EXTRA string={"access_token":"13_5wS0P68kkvP1JMUgKvLRHiorDM-9wwzYsyPyvqoO45oQ0svaKslNuzuXiPj_H38ci_CC0I6KOpYftBjHdls38dPUclu9vr-5l2KYA2bQSXzkruy7W_eRaiKgGZm9RDemUtccGpZrt6GsJQd1DRZaAAATHP","expires_in":7200})
3136
+2018/09/13 18:59:53 [I] 接口返回结果: %!(EXTRA map[string]interface {}=map[expires_in:7200 access_token:13_5wS0P68kkvP1JMUgKvLRHiorDM-9wwzYsyPyvqoO45oQ0svaKslNuzuXiPj_H38ci_CC0I6KOpYftBjHdls38dPUclu9vr-5l2KYA2bQSXzkruy7W_eRaiKgGZm9RDemUtccGpZrt6GsJQd1DRZaAAATHP])
3137
+2018/09/13 19:04:23 [I] 请求远程接口: %!(EXTRA string=https://api.weixin.qq.com/cgi-bin/token?appid=wx7320287e057bbeee&grant_type=client_credential&secret=6e844dc2ade439545c47569ba1707673)
3138
+2018/09/13 19:04:24 [I] 远程请求结果:%!(EXTRA string={"access_token":"13_5FVpoe4s6lQAYRgaIhfOemZ8x2JZqaVEC0HLnxX2GVDmozbqIEDsOy_VJvYYiV66RLWNi5i4xCXfwhlWOyJt0PsIJG7_WPIHk3L4xcu3hElyNBonTktgQLSJhLJ4yV2eqGbQglXlbE6HN8Z7SQRjABAMKL","expires_in":7200})
3139
+2018/09/13 19:04:24 [I] 接口返回结果: %!(EXTRA map[string]interface {}=map[access_token:13_5FVpoe4s6lQAYRgaIhfOemZ8x2JZqaVEC0HLnxX2GVDmozbqIEDsOy_VJvYYiV66RLWNi5i4xCXfwhlWOyJt0PsIJG7_WPIHk3L4xcu3hElyNBonTktgQLSJhLJ4yV2eqGbQglXlbE6HN8Z7SQRjABAMKL expires_in:7200])
3140
+2018/09/13 19:09:43 [I] 请求远程接口: %!(EXTRA string=https://api.weixin.qq.com/cgi-bin/token?appid=wx7320287e057bbeee&grant_type=client_credential&secret=6e844dc2ade439545c47569ba1707673)
3141
+2018/09/13 19:09:44 [I] 远程请求结果:%!(EXTRA string={"access_token":"13_Bt-a8HjMB8lI3pECMEnQHNxh1Po7akGhaKn5eNanfovztO5_nfsc0HWTVN1vpReBlOrUsFEJaLdoy4z8fHFOOPFEB4LDtbaKvFBTRfARZwR-rOKNtgyp0wZ38ySOH-JkxWfdZSRAIXeqI3baVAYgACARWU","expires_in":7200})
3142
+2018/09/13 19:09:44 [I] 接口返回结果: %!(EXTRA map[string]interface {}=map[access_token:13_Bt-a8HjMB8lI3pECMEnQHNxh1Po7akGhaKn5eNanfovztO5_nfsc0HWTVN1vpReBlOrUsFEJaLdoy4z8fHFOOPFEB4LDtbaKvFBTRfARZwR-rOKNtgyp0wZ38ySOH-JkxWfdZSRAIXeqI3baVAYgACARWU expires_in:7200])
3143
+2018/09/13 19:11:52 [I] 请求远程接口: %!(EXTRA string=https://api.weixin.qq.com/cgi-bin/token?appid=wx7320287e057bbeee&grant_type=client_credential&secret=6e844dc2ade439545c47569ba1707673)
3144
+2018/09/13 19:11:53 [I] 远程请求结果:%!(EXTRA string={"access_token":"13_BdnfI9eRgdWJ2pX_ptvxYJzNwW1N7Tx5K1fl4Kg96qRNBPiooTJsbFsCie5kE20w8zPX_DVjSwU9i5x12kgxQgFVxkB9gA0BBvpWqzUa4N7BKZCf7sH0o3U7-ZdjeIX5KLRRqnvyQuL7dDIVUVPjADAMNH","expires_in":7200})
3145
+2018/09/13 19:11:53 [I] 接口返回结果: %!(EXTRA map[string]interface {}=map[access_token:13_BdnfI9eRgdWJ2pX_ptvxYJzNwW1N7Tx5K1fl4Kg96qRNBPiooTJsbFsCie5kE20w8zPX_DVjSwU9i5x12kgxQgFVxkB9gA0BBvpWqzUa4N7BKZCf7sH0o3U7-ZdjeIX5KLRRqnvyQuL7dDIVUVPjADAMNH expires_in:7200])
3146
+2018/09/13 19:14:43 [I] 请求远程接口: %!(EXTRA string=https://api.weixin.qq.com/cgi-bin/token?appid=wx7320287e057bbeee&grant_type=client_credential&secret=6e844dc2ade439545c47569ba1707673)
3147
+2018/09/13 19:14:44 [I] 远程请求结果:%!(EXTRA string={"access_token":"13_BMIA6dCwkLjDzepNYIIRFe2JzLIctYG36ppOfwE6i_M6bUIvmfktLfZ26ePesQFSdCvVscBoGHS8MPF_P-LJrquzmexWDTHcfZUBw42eHC_XPABs2jKzKz3ekPy5vK0UZnnO68NRYYzBr2nzLGXbAHABWN","expires_in":7200})
3148
+2018/09/13 19:14:44 [I] 接口返回结果: %!(EXTRA map[string]interface {}=map[access_token:13_BMIA6dCwkLjDzepNYIIRFe2JzLIctYG36ppOfwE6i_M6bUIvmfktLfZ26ePesQFSdCvVscBoGHS8MPF_P-LJrquzmexWDTHcfZUBw42eHC_XPABs2jKzKz3ekPy5vK0UZnnO68NRYYzBr2nzLGXbAHABWN expires_in:7200])
3149
+2018/09/13 19:23:03 [I] 请求远程接口: %!(EXTRA string=https://api.weixin.qq.com/cgi-bin/token?appid=wx7320287e057bbeee&grant_type=client_credential&secret=6e844dc2ade439545c47569ba1707673)
3150
+2018/09/13 19:23:04 [I] 远程请求结果:%!(EXTRA string={"access_token":"13_3F2SCIMWfeDPI5z-531zJHgzuaUav4JQaR18w0wICNTy6XXNQcfIHldt0bppa4YPZLMwYtKsRJbb2jl8scaagJq5wbGsNCjJuCGA32sMqwN-DjMaFmuflHM9tIhOy9Nc1-7yUtNWcVm-m72FWQBhACADXI","expires_in":7200})
3151
+2018/09/13 19:23:04 [I] 接口返回结果: %!(EXTRA map[string]interface {}=map[access_token:13_3F2SCIMWfeDPI5z-531zJHgzuaUav4JQaR18w0wICNTy6XXNQcfIHldt0bppa4YPZLMwYtKsRJbb2jl8scaagJq5wbGsNCjJuCGA32sMqwN-DjMaFmuflHM9tIhOy9Nc1-7yUtNWcVm-m72FWQBhACADXI expires_in:7200])
3152
+2018/09/13 19:36:36 [I] 请求远程接口: %!(EXTRA string=https://api.weixin.qq.com/cgi-bin/token?appid=wx7320287e057bbeee&grant_type=client_credential&secret=6e844dc2ade439545c47569ba1707673)
3153
+2018/09/13 19:36:36 [I] 远程请求结果:%!(EXTRA string={"access_token":"13_Dgj9aFWEtUxeOojlCynPzMk6KposI5qyWTWRhdn_gEBHEEO7uXxaeNRZ-LfWoT8XWB6GFW_Ppk6zj8lotRj0BudhE64k4Pcv9-yuWK-LyvU7ZKqPP2CowT6qzBy0vOjKIvetxFS8yxJeN0C6LSMfAEAUBV","expires_in":7200})
3154
+2018/09/13 19:36:36 [I] 接口返回结果: %!(EXTRA map[string]interface {}=map[access_token:13_Dgj9aFWEtUxeOojlCynPzMk6KposI5qyWTWRhdn_gEBHEEO7uXxaeNRZ-LfWoT8XWB6GFW_Ppk6zj8lotRj0BudhE64k4Pcv9-yuWK-LyvU7ZKqPP2CowT6qzBy0vOjKIvetxFS8yxJeN0C6LSMfAEAUBV expires_in:7200])
3155
+2018/09/13 19:40:08 [E] 解析 Token 失败: token contains an invalid number of segments

+ 25
- 10
models/coupon/coupon.go 查看文件

@@ -259,15 +259,9 @@ func (m *CouponDAO) GetCouponBySendType(caseids, sendtype string) ([]model.TaCou
259 259
 	return coupons, err
260 260
 }
261 261
 
262
-// CaseUsableCoupon 案场可用优惠券信息
263
-type CaseUsableCoupon struct {
264
-	model.TaCoupon `xorm:"extends"`
265
-	CustomerCoupon []model.TaCustomerCoupon
266
-}
267
-
268 262
 // GetCaseUsableCoupon 获取案场可用优惠券信息
269
-func (m *CouponDAO) GetCaseUsableCoupon(caseid, userid string, page, pageSize int) ([]CaseUsableCoupon, error) {
270
-	var Coupons []CaseUsableCoupon
263
+func (m *CouponDAO) GetCaseUsableCoupon(caseid, userid string, page, pageSize int) ([]CaseCouponDetail, error) {
264
+	var Coupons []CaseCouponDetail
271 265
 	sql := `select * from ta_coupon where case_id=? and status=? and end_date>now() order by create_date limit ` + strconv.Itoa((page-1)*pageSize) + `, ` + strconv.Itoa(pageSize)
272 266
 	err := m.db.Sql(sql, caseid, models.STATUS_NORMAL).Find(&Coupons)
273 267
 	if userid != "" {
@@ -290,8 +284,8 @@ func (m *CouponDAO) GetCustomerCouponByCouponAndUser(couponid, userid string) ([
290 284
 }
291 285
 
292 286
 // GetCouponDetail 获取优惠券详情
293
-func (m *CouponDAO) GetCouponDetail(couponid string) (*CaseUsableCoupon, error) {
294
-	var coupon = new(CaseUsableCoupon)
287
+func (m *CouponDAO) GetCouponDetail(couponid string) (*CaseCouponDetail, error) {
288
+	var coupon = new(CaseCouponDetail)
295 289
 	sql := `select * from ta_coupon_Coupon where coupon_id=? and status>?`
296 290
 	_, err := m.db.Sql(sql, couponid, models.STATUS_DEL).Get(&coupon)
297 291
 	if err != nil {
@@ -321,3 +315,24 @@ func (m *CouponDAO) GetCustomerCouponByUser(caseid, userid string) ([]model.TaCu
321 315
 	err := m.db.Where("case_id=?", caseid).And("sales_id=?", userid).And("status>?", models.STATUS_DEL).Find(&customerCoupons)
322 316
 	return customerCoupons, err
323 317
 }
318
+
319
+// GetCouponWithCustomer 获取优惠券明细
320
+func (m CouponDAO) GetCouponWithCustomer(couponid string) (*CaseCouponDetail, error) {
321
+	var coupon = new(CaseCouponDetail)
322
+	sql := `select * from ta_coupon where coupin_id=?`
323
+	_, err := m.db.Sql(sql, couponid).Get(&coupon)
324
+	if err != nil {
325
+		return nil, err
326
+	}
327
+	if coupon == nil || coupon.CouponId == "" {
328
+		return nil, errors.New("无优惠券信息")
329
+	}
330
+	var customerCopons []model.TaCustomerCoupon
331
+	sql = `select * from ta_customer_coupon where coupon_id = ? and status>?`
332
+	err = m.db.Sql(sql, coupon, models.STATUS_DEL).Find(&customerCopons)
333
+	if err != nil {
334
+		return nil, err
335
+	}
336
+	coupon.CustomerCoupon = customerCopons
337
+	return coupon, nil
338
+}

+ 6
- 0
models/coupon/types.go 查看文件

@@ -18,3 +18,9 @@ type CouponInfo struct {
18 18
 	Images         []model.TaCouponImage
19 19
 	Rules          []model.TaCouponRule
20 20
 }
21
+
22
+// CaseUsableCoupon 案场可用优惠券信息
23
+type CaseCouponDetail struct {
24
+	model.TaCoupon `xorm:"extends"`
25
+	CustomerCoupon []model.TaCustomerCoupon
26
+}

+ 13
- 0
service/coupon/coupon.go 查看文件

@@ -368,3 +368,16 @@ func (s *CouponServ) GetCouponBySendType(sendtype string) ([]model.TaCoupon, err
368 368
 	}
369 369
 	return coupon, nil
370 370
 }
371
+
372
+// GetCouponWithCustomer 获取优惠券明细
373
+func (s *CouponServ) GetCouponWithCustomer(couponid string) (*coupon.CaseCouponDetail, error) {
374
+	if couponid == "" {
375
+		return nil, errors.New("没有券信息!")
376
+	}
377
+	couponDetail, err := s.dao.GetCouponDetail(couponid)
378
+	if err != nil {
379
+		utils.LogError("获取优惠券失败: " + err.Error())
380
+		return nil, errors.New("获取优惠券失败")
381
+	}
382
+	return couponDetail, nil
383
+}

+ 52
- 26
service/sys.go 查看文件

@@ -8,6 +8,7 @@ import (
8 8
 	"spaceofcheng/services/models/customer"
9 9
 	"spaceofcheng/services/models/model"
10 10
 	"spaceofcheng/services/utils"
11
+	"strconv"
11 12
 	"strings"
12 13
 	"time"
13 14
 
@@ -54,20 +55,37 @@ func (s *SysServ) AuthAndInitCtx(gctx *context.Context) map[string]interface{} {
54 55
 		}
55 56
 	}
56 57
 
58
+	// 客户端类型
59
+	// 通过 UA 判断
60
+	clientType := utils.GetClientType(gctx.Request)
61
+	if clientType == utils.ClientWechat {
62
+		// 初始化微信配置
63
+		if err := s.initWechatClient(s.org.OrgId); err != nil {
64
+			utils.LogError("初始化微信客户端失败: " + err.Error())
65
+
66
+			return map[string]interface{}{
67
+				"code":  http.StatusInternalServerError,
68
+				"error": errors.New("初始化微信客户端失败"),
69
+			}
70
+		}
71
+	}
72
+
57 73
 	// 获取 token
58
-	token, err := s.getToken(gctx)
74
+	token, err := s.getToken(gctx, clientType)
59 75
 	if err != nil {
76
+		message := make(map[string]interface{})
77
+		if clientType == utils.ClientWechat {
78
+			message["appid"] = utils.GetWxAppID(s.org.OrgId)
79
+		}
80
+
60 81
 		// token 报错一律视为需要重新登录
61 82
 		return map[string]interface{}{
62
-			"code":  http.StatusUnauthorized,
63
-			"error": err,
83
+			"code":    http.StatusUnauthorized,
84
+			"error":   err,
85
+			"message": message,
64 86
 		}
65 87
 	}
66 88
 
67
-	// 客户端类型
68
-	// 通过 UA 判断
69
-	clientType := utils.GetClientType(gctx.Request)
70
-
71 89
 	// pc 管理端
72 90
 	if clientType == utils.ClientAdmin {
73 91
 		return s.authPCAdmin(gctx, token)
@@ -163,21 +181,20 @@ func (s *SysServ) authWechat(gctx *context.Context, token *utils.JWTToken) map[s
163 181
 
164 182
 	// 未登录 或 未验证
165 183
 	if token.ID == "" {
166
-		// 需要微信验证
167
-		if code == "" {
168
-			return map[string]interface{}{
169
-				"code":  http.StatusUnauthorized,
170
-				"error": errors.New("请授权微信用户登录"),
171
-				"message": map[string]interface{}{
172
-					"appid": utils.GetWxAppID(s.org.OrgId),
173
-				},
174
-			}
175
-		}
176
-
177 184
 		// 微信用户信息
178 185
 		var err error
179 186
 		wxUser, err = s.wechartSignIn(gctx, code)
180 187
 		if err != nil {
188
+			if strings.Index(err.Error(), strconv.Itoa(http.StatusUnauthorized)) > -1 {
189
+				return map[string]interface{}{
190
+					"code":  http.StatusUnauthorized,
191
+					"error": errors.New("请授权微信用户登录"),
192
+					"message": map[string]interface{}{
193
+						"appid": utils.GetWxAppID(s.org.OrgId),
194
+					},
195
+				}
196
+			}
197
+
181 198
 			return map[string]interface{}{
182 199
 				"code":  http.StatusInternalServerError,
183 200
 				"error": err,
@@ -299,10 +316,8 @@ func (s *SysServ) wechartSignIn(gctx *context.Context, code string) (*utils.Wech
299 316
 		}, nil
300 317
 	}
301 318
 
302
-	// 初始化微信配置
303
-	if err := s.initWechatClient(s.org.OrgId); err != nil {
304
-		utils.LogError("初始化微信客户端失败: " + err.Error())
305
-		return nil, errors.New("初始化微信客户端失败")
319
+	if code == "" {
320
+		return nil, errors.New(strconv.Itoa(http.StatusUnauthorized))
306 321
 	}
307 322
 
308 323
 	// 获取 微信信息
@@ -319,10 +334,21 @@ func (s *SysServ) wechartSignIn(gctx *context.Context, code string) (*utils.Wech
319 334
 	return utils.MapToWechatUser(wxUserMap), nil
320 335
 }
321 336
 
322
-func (s *SysServ) getToken(gctx *context.Context) (*utils.JWTToken, error) {
337
+func (s *SysServ) getToken(gctx *context.Context, clientType string) (*utils.JWTToken, error) {
338
+	if beego.BConfig.RunMode == "dev" {
339
+		id := "0"
340
+		if clientType == utils.ClientWechat {
341
+			id = "OPENID"
342
+		}
343
+
344
+		return &utils.JWTToken{
345
+			ID: id,
346
+		}, nil
347
+	}
348
+
323 349
 	tokenRaw := gctx.Input.Header(utils.TokenHeader)
324 350
 	if tokenRaw == "" {
325
-		return nil, nil
351
+		return new(utils.JWTToken), nil
326 352
 	}
327 353
 
328 354
 	tokenEnStr := strings.Trim(strings.TrimLeft(tokenRaw, utils.TokenSchema), " ")
@@ -490,7 +516,7 @@ func (s *SysServ) CheckWechatUserMapping(user map[string]interface{}) (*model.Ta
490 516
 }
491 517
 
492 518
 // initWechatClient 初始化微信客户端
493
-func (s SysServ) initWechatClient(orgID string) error {
519
+func (s *SysServ) initWechatClient(orgID string) error {
494 520
 	conf, err := s.dao.GetWeChatConfig(orgID)
495 521
 	if err != nil {
496 522
 		utils.LogError("获取微信配置失败: " + err.Error())
@@ -514,7 +540,7 @@ func (s SysServ) initWechatClient(orgID string) error {
514 540
 }
515 541
 
516 542
 // SetOrgByID 获取组织
517
-func (s SysServ) SetOrgByID(orgID string) error {
543
+func (s *SysServ) SetOrgByID(orgID string) error {
518 544
 	orgID = utils.DecodeBase64NoTail(orgID)
519 545
 
520 546
 	org, err := s.dao.GetOrg(orgID)