Browse Source

bug修改

wangfei 6 years ago
parent
commit
889cb3c234
6 changed files with 92 additions and 31 deletions
  1. 16
    0
      log/common.log
  2. 50
    10
      models/card/record.go
  3. 1
    6
      routers/common.go
  4. 12
    15
      service/card/record.go
  5. 7
    0
      service/course/order.go
  6. 6
    0
      service/goods/orders.go

+ 16
- 0
log/common.log View File

@@ -148,3 +148,19 @@
148 148
 2018/09/20 17:09:00 [E] User-Agent: mozilla/5.0 (windows nt 10.0; win64; x64) applewebkit/537.36 (khtml, like gecko) chrome/68.0.3440.106 safari/537.36
149 149
 2018/09/20 17:09:01 [E] User-Agent: mozilla/5.0 (windows nt 10.0; win64; x64) applewebkit/537.36 (khtml, like gecko) chrome/68.0.3440.106 safari/537.36
150 150
 2018/09/20 17:17:38 [E] User-Agent: mozilla/5.0 (windows nt 10.0; win64; x64) applewebkit/537.36 (khtml, like gecko) chrome/68.0.3440.106 safari/537.36
151
+2018/09/20 17:18:01 [E] User-Agent: mozilla/5.0 (windows nt 10.0; win64; x64) applewebkit/537.36 (khtml, like gecko) chrome/68.0.3440.106 safari/537.36
152
+2018/09/20 17:18:13 [E] User-Agent: mozilla/5.0 (windows nt 10.0; win64; x64) applewebkit/537.36 (khtml, like gecko) chrome/68.0.3440.106 safari/537.36
153
+2018/09/20 17:18:16 [E] User-Agent: mozilla/5.0 (windows nt 10.0; win64; x64) applewebkit/537.36 (khtml, like gecko) chrome/68.0.3440.106 safari/537.36
154
+2018/09/20 17:18:18 [E] User-Agent: mozilla/5.0 (windows nt 10.0; win64; x64) applewebkit/537.36 (khtml, like gecko) chrome/68.0.3440.106 safari/537.36
155
+2018/09/20 17:18:34 [E] User-Agent: mozilla/5.0 (windows nt 10.0; win64; x64) applewebkit/537.36 (khtml, like gecko) chrome/68.0.3440.106 safari/537.36
156
+2018/09/20 17:18:35 [E] User-Agent: mozilla/5.0 (windows nt 10.0; win64; x64) applewebkit/537.36 (khtml, like gecko) chrome/68.0.3440.106 safari/537.36
157
+2018/09/20 17:18:36 [E] User-Agent: mozilla/5.0 (windows nt 10.0; win64; x64) applewebkit/537.36 (khtml, like gecko) chrome/68.0.3440.106 safari/537.36
158
+2018/09/20 17:18:37 [E] User-Agent: mozilla/5.0 (windows nt 10.0; win64; x64) applewebkit/537.36 (khtml, like gecko) chrome/68.0.3440.106 safari/537.36
159
+2018/09/20 17:18:44 [E] User-Agent: mozilla/5.0 (windows nt 10.0; win64; x64) applewebkit/537.36 (khtml, like gecko) chrome/68.0.3440.106 safari/537.36
160
+2018/09/20 17:18:54 [E] User-Agent: mozilla/5.0 (windows nt 10.0; win64; x64) applewebkit/537.36 (khtml, like gecko) chrome/68.0.3440.106 safari/537.36
161
+2018/09/20 17:18:54 [E] User-Agent: mozilla/5.0 (windows nt 10.0; win64; x64) applewebkit/537.36 (khtml, like gecko) chrome/68.0.3440.106 safari/537.36
162
+2018/09/20 17:30:29 [E] User-Agent: mozilla/5.0 (windows nt 10.0; win64; x64) applewebkit/537.36 (khtml, like gecko) chrome/68.0.3440.106 safari/537.36
163
+2018/09/20 17:30:31 [E] User-Agent: mozilla/5.0 (windows nt 10.0; win64; x64) applewebkit/537.36 (khtml, like gecko) chrome/68.0.3440.106 safari/537.36
164
+2018/09/20 17:30:45 [E] User-Agent: mozilla/5.0 (windows nt 10.0; win64; x64) applewebkit/537.36 (khtml, like gecko) chrome/68.0.3440.106 safari/537.36
165
+2018/09/20 17:30:45 [E] User-Agent: mozilla/5.0 (windows nt 10.0; win64; x64) applewebkit/537.36 (khtml, like gecko) chrome/68.0.3440.106 safari/537.36
166
+2018/09/20 17:30:48 [E] User-Agent: mozilla/5.0 (windows nt 10.0; win64; x64) applewebkit/537.36 (khtml, like gecko) chrome/68.0.3440.106 safari/537.36

+ 50
- 10
models/card/record.go View File

@@ -2,11 +2,11 @@ package card
2 2
 
3 3
 import (
4 4
 	"spaceofcheng/services/models/model"
5
-	"github.com/go-xorm/xorm"
6 5
 	"spaceofcheng/services/utils"
7 6
 	"strconv"
8
-)
9 7
 
8
+	"github.com/go-xorm/xorm"
9
+)
10 10
 
11 11
 // RecordDAO 当前数据库操作对象
12 12
 type RecordDAO struct {
@@ -25,17 +25,17 @@ func NewRecordDAO(ctx *utils.Context) *RecordDAO {
25 25
 // RecordInfo 卡
26 26
 type RecordInfo struct {
27 27
 	model.TaCouponGiveRecord `xorm:"extends"`
28
-	CustomerName string
29
-	Phone string
30
-	RecommendName string
28
+	CustomerName             string
29
+	Phone                    string
30
+	RecommendName            string
31 31
 }
32 32
 
33 33
 // getRecordList 根据条件查询赠送记录
34
-func (c *RecordDAO) GetRecordList(startDate string, endDate string, person string,page int,pageSize int) ([]RecordInfo, error) {
34
+func (c *RecordDAO) GetRecordList(startDate string, endDate string, person string, page int, pageSize int) ([]RecordInfo, error) {
35 35
 	var info []RecordInfo
36 36
 
37 37
 	sql := "select tc.customer_name,tc.phone,tc.recommend_name,tgr.* from ta_coupon_give_record tgr LEFT JOIN ta_customer tc on tgr.to_id = tc.customer_id"
38
-	
38
+
39 39
 	if startDate != "" || endDate != "" || person != "" {
40 40
 		sql = sql + ` WHERE`
41 41
 	}
@@ -52,7 +52,7 @@ func (c *RecordDAO) GetRecordList(startDate string, endDate string, person strin
52 52
 		}
53 53
 		sql = sql + ` DATE_FORMAT(tgr.create_date,'%Y-%m-%d') <= DATE_FORMAT('` + endDate + `','%Y-%m-%d')`
54 54
 	}
55
-	
55
+
56 56
 	if person != "" {
57 57
 		// 传入了 开始时间 或者 结束时间 的时候,添加 and
58 58
 		if startDate != "" || endDate != "" {
@@ -65,9 +65,49 @@ func (c *RecordDAO) GetRecordList(startDate string, endDate string, person strin
65 65
 
66 66
 	err := c.db.SQL(sql).Find(&info)
67 67
 	if err != nil {
68
-		return nil,err
68
+		return nil, err
69
+	}
70
+
71
+	return info, err
72
+
73
+}
74
+
75
+// GetRecordCount 获取count
76
+func (c *RecordDAO) GetRecordCount(startDate string, endDate string, person string) (int, error) {
77
+	var info []RecordInfo
78
+
79
+	sql := "select tc.customer_name,tc.phone,tc.recommend_name,tgr.* from ta_coupon_give_record tgr LEFT JOIN ta_customer tc on tgr.to_id = tc.customer_id"
80
+
81
+	if startDate != "" || endDate != "" || person != "" {
82
+		sql = sql + ` WHERE`
83
+	}
84
+
85
+	// 传入了开始时间的时候
86
+	if startDate != "" {
87
+		sql = sql + ` DATE_FORMAT(tgr.create_date,'%Y-%m-%d') >= DATE_FORMAT('` + startDate + `','%Y-%m-%d')`
88
+	}
89
+	// 传入了结束时间的时候
90
+	if endDate != "" {
91
+		// 传入了开始时间的时候,添加 and
92
+		if startDate != "" {
93
+			sql = sql + ` and`
94
+		}
95
+		sql = sql + ` DATE_FORMAT(tgr.create_date,'%Y-%m-%d') <= DATE_FORMAT('` + endDate + `','%Y-%m-%d')`
96
+	}
97
+
98
+	if person != "" {
99
+		// 传入了 开始时间 或者 结束时间 的时候,添加 and
100
+		if startDate != "" || endDate != "" {
101
+			sql = sql + ` and`
102
+		}
103
+		sql = sql + ` tc.recommend_name like '%` + person + `%'`
104
+	}
105
+
106
+	err := c.db.SQL(sql).Find(&info)
107
+	if err != nil {
108
+		return 0, err
69 109
 	}
70 110
 
71
-	return info,err
111
+	return len(info), err
72 112
 
73 113
 }

+ 1
- 6
routers/common.go View File

@@ -175,7 +175,6 @@ func getCommonRoutes() beego.LinkNamespace {
175 175
 		beego.NSRouter("/vipcard", &vipcard.VipcardController{}, "post:AddVipCard"),
176 176
 		beego.NSRouter("/vipcard/:vipCardChildCode", &vipcard.VipcardController{}, "put:UserCharge"),
177 177
 		beego.NSRouter("/vipcard/excel", &vipcard.VipcardController{}, "get:GetVipListExcel"),
178
-		
179 178
 
180 179
 		// courseVerify 核销课程
181 180
 		beego.NSRouter("/verify/course/code/:customerCourseId", &verify.VerifyController{}, "get:GetCustomerCourseDetailListById"),
@@ -264,7 +263,7 @@ func getCommonRoutes() beego.LinkNamespace {
264 263
 		beego.NSRouter("/card/:id", &card.CardController{}, "put:UpdateCard"),
265 264
 		beego.NSRouter("/card/:id/to/:users", &card.CardController{}, "post:GiveCard"),
266 265
 		// 赠送记录
267
-		beego.NSRouter("/card/record", &card.RecordController{}, "get:GetRecordList"),
266
+		beego.NSRouter("/record", &card.RecordController{}, "get:GetRecordList"),
268 267
 
269 268
 		// 文件
270 269
 		beego.NSRouter("/file", &controllers.BaseController{}, "post:FileUpload"),
@@ -308,9 +307,5 @@ func getCommonRoutes() beego.LinkNamespace {
308 307
 		beego.NSRouter("/statistics/cardcouponused/excel", &statistics.StatisticsController{}, "get:CardCouponUsedStatisticsExcel"),
309 308
 		beego.NSRouter("/statistics/cardcouponverify", &statistics.StatisticsController{}, "get:CardCouponVerifyStatistics"),
310 309
 		beego.NSRouter("/statistics/cardcouponverify/excel", &statistics.StatisticsController{}, "get:CardCouponVerifyStatisticsExcel"),
311
-
312
-		
313
-
314
-
315 310
 	)
316 311
 }

+ 12
- 15
service/card/record.go View File

@@ -7,31 +7,30 @@ import (
7 7
 
8 8
 // RecordServ 系统处理
9 9
 type RecordServ struct {
10
-	ctx       *utils.Context
11
-	dao       *card.RecordDAO
10
+	ctx *utils.Context
11
+	dao *card.RecordDAO
12 12
 }
13 13
 
14 14
 // NewRecordServ 初始化
15 15
 func NewRecordServ(ctx *utils.Context) *RecordServ {
16 16
 	return &RecordServ{
17
-		ctx:       ctx,
18
-		dao:       card.NewRecordDAO(ctx),
17
+		ctx: ctx,
18
+		dao: card.NewRecordDAO(ctx),
19 19
 	}
20 20
 }
21 21
 
22 22
 // 查询赠送记录
23
-func (s *RecordServ) GetRecordList(startDate string, endDate string, person string,page int,pageSize int) (map[string]interface{}, error) {
23
+func (s *RecordServ) GetRecordList(startDate string, endDate string, person string, page int, pageSize int) (map[string]interface{}, error) {
24 24
 
25
-	 info,err := s.dao.GetRecordList(startDate, endDate, person, page, pageSize)
26
-	 var total int
27
-	 if err != nil {
28
-		 return nil,err
29
-	 }
30
-
31
-	 if len(info) > 0 {
32
-		total = len(info)
25
+	info, err := s.dao.GetRecordList(startDate, endDate, person, page, pageSize)
26
+	if err != nil {
27
+		return nil, err
33 28
 	}
34 29
 
30
+	total, err := s.dao.GetRecordCount(startDate, endDate, person)
31
+	if err != nil {
32
+		return nil, err
33
+	}
35 34
 	return map[string]interface{}{
36 35
 		"list":     info,
37 36
 		"pagesize": pageSize,
@@ -40,5 +39,3 @@ func (s *RecordServ) GetRecordList(startDate string, endDate string, person stri
40 39
 	}, err
41 40
 
42 41
 }
43
-
44
-

+ 7
- 0
service/course/order.go View File

@@ -96,6 +96,13 @@ func (s *CourseServ) Orders(
96 96
 			return errors.New("查询优惠券信息失败")
97 97
 		}
98 98
 
99
+		if coupon.StartDate.After(time.Now().Local()) {
100
+			return errors.New("该优惠券还未到有效期,不允许下单!")
101
+		}
102
+		if coupon.EndDate.Before(time.Now().Local()) {
103
+			return errors.New("优惠券已失效,不允许下单!")
104
+		}
105
+
99 106
 		// 判断优惠券是否可以抵用商品
100 107
 		var isdy = false
101 108
 		if coupon.IsAll == 1 {

+ 6
- 0
service/goods/orders.go View File

@@ -71,6 +71,12 @@ func (s *GoodsServ) Orders(
71 71
 				return errors.New("优惠券已被使用!请重新选择优惠券!")
72 72
 			}
73 73
 
74
+			if customerCoupon.StartDate.After(time.Now().Local()) {
75
+				return errors.New("该优惠券还未到有效期,不允许下单!")
76
+			}
77
+			if customerCoupon.EndDate.Before(time.Now().Local()) {
78
+				return errors.New("优惠券已失效,不允许下单!")
79
+			}
74 80
 			// 根据id获取优惠券信息
75 81
 			coupon, err := s.couponDAO.GetCouponInfoByCustomerCouponID(customercouponid)
76 82
 			if err != nil {