Parcourir la source

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

胡轶钦 il y a 6 ans
Parent
révision
3924ca9aa7
4 fichiers modifiés avec 162 ajouts et 0 suppressions
  1. 39
    0
      controllers/card/record.go
  2. 73
    0
      models/card/record.go
  3. 6
    0
      routers/common.go
  4. 44
    0
      service/card/record.go

+ 39
- 0
controllers/card/record.go Voir le fichier

@@ -0,0 +1,39 @@
1
+package card
2
+
3
+import (
4
+	"spaceofcheng/services/service/card"
5
+	"spaceofcheng/services/controllers"
6
+)
7
+
8
+
9
+// RecordController 商品
10
+type RecordController struct {
11
+	serv *card.RecordServ
12
+	controllers.BaseController
13
+}
14
+
15
+// Constructor 初始化 Controller
16
+// @Title Constructor
17
+// @Description 初始化 Controller, 系统自动调用
18
+func (c *RecordController) Constructor() {
19
+	c.serv = card.NewRecordServ(c.Context)
20
+}
21
+
22
+// ListByCase 获取卡列表
23
+func (c *RecordController) GetRecordList() {
24
+
25
+	person := c.GetString("referrer")
26
+	startDate := c.GetString("startDate")
27
+	endDate := c.GetString("endDate")
28
+	page, _ := c.GetInt("page")
29
+	pagesize, _ := c.GetInt("pagesize")
30
+
31
+	res,err := c.serv.GetRecordList(startDate,endDate,person,page,pagesize)
32
+
33
+	if err != nil {
34
+		c.ResponseError(err)
35
+	}
36
+	c.ResponseJSON(res)
37
+
38
+}
39
+

+ 73
- 0
models/card/record.go Voir le fichier

@@ -0,0 +1,73 @@
1
+package card
2
+
3
+import (
4
+	"spaceofcheng/services/models/model"
5
+	"github.com/go-xorm/xorm"
6
+	"spaceofcheng/services/utils"
7
+	"strconv"
8
+)
9
+
10
+
11
+// RecordDAO 当前数据库操作对象
12
+type RecordDAO struct {
13
+	ctx *utils.Context
14
+	db  *xorm.Session
15
+}
16
+
17
+// NewRecordDAO New Inst
18
+func NewRecordDAO(ctx *utils.Context) *RecordDAO {
19
+	return &RecordDAO{
20
+		ctx: ctx,
21
+		db:  ctx.DB,
22
+	}
23
+}
24
+
25
+// RecordInfo 卡
26
+type RecordInfo struct {
27
+	model.TaCouponGiveRecord `xorm:"extends"`
28
+	CustomerName string
29
+	Phone string
30
+	RecommendName string
31
+}
32
+
33
+// getRecordList 根据条件查询赠送记录
34
+func (c *RecordDAO) GetRecordList(startDate string, endDate string, person string,page int,pageSize int) ([]RecordInfo, error) {
35
+	var info []RecordInfo
36
+
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
+	
39
+	if startDate != "" || endDate != "" || person != "" {
40
+		sql = sql + ` WHERE`
41
+	}
42
+
43
+	// 传入了开始时间的时候
44
+	if startDate != "" {
45
+		sql = sql + ` DATE_FORMAT(tgr.create_date,'%Y-%m-%d') >= DATE_FORMAT('` + startDate + `','%Y-%m-%d')`
46
+	}
47
+	// 传入了结束时间的时候
48
+	if endDate != "" {
49
+		// 传入了开始时间的时候,添加 and
50
+		if startDate != "" {
51
+			sql = sql + ` and`
52
+		}
53
+		sql = sql + ` DATE_FORMAT(tgr.create_date,'%Y-%m-%d') <= DATE_FORMAT('` + endDate + `','%Y-%m-%d')`
54
+	}
55
+	
56
+	if person != "" {
57
+		// 传入了 开始时间 或者 结束时间 的时候,添加 and
58
+		if startDate != "" || endDate != "" {
59
+			sql = sql + ` and`
60
+		}
61
+		sql = sql + ` tc.recommend_name like '%` + person + `%'`
62
+	}
63
+
64
+	sql = sql + ` ORDER BY tgr.create_date desc limit ` + strconv.Itoa((page-1)*pageSize) + `, ` + strconv.Itoa(pageSize)
65
+
66
+	err := c.db.SQL(sql).Find(&info)
67
+	if err != nil {
68
+		return nil,err
69
+	}
70
+
71
+	return info,err
72
+
73
+}

+ 6
- 0
routers/common.go Voir le fichier

@@ -260,6 +260,8 @@ func getCommonRoutes() beego.LinkNamespace {
260 260
 		beego.NSRouter("/card/:id", &card.CardController{}, "get:GetCardByIDForAdmin"),
261 261
 		beego.NSRouter("/card/:id", &card.CardController{}, "put:UpdateCard"),
262 262
 		beego.NSRouter("/card/:id/to/:users", &card.CardController{}, "post:GiveCard"),
263
+		// 赠送记录
264
+		beego.NSRouter("/card/record", &card.RecordController{}, "get:GetRecordList"),
263 265
 
264 266
 		// 文件
265 267
 		beego.NSRouter("/file", &controllers.BaseController{}, "post:FileUpload"),
@@ -303,5 +305,9 @@ func getCommonRoutes() beego.LinkNamespace {
303 305
 		beego.NSRouter("/statistics/cardcouponused/excel", &statistics.StatisticsController{}, "get:CardCouponUsedStatisticsExcel"),
304 306
 		beego.NSRouter("/statistics/cardcouponverify", &statistics.StatisticsController{}, "get:CardCouponVerifyStatistics"),
305 307
 		beego.NSRouter("/statistics/cardcouponverify/excel", &statistics.StatisticsController{}, "get:CardCouponVerifyStatisticsExcel"),
308
+
309
+		
310
+
311
+
306 312
 	)
307 313
 }

+ 44
- 0
service/card/record.go Voir le fichier

@@ -0,0 +1,44 @@
1
+package card
2
+
3
+import (
4
+	"spaceofcheng/services/models/card"
5
+	"spaceofcheng/services/utils"
6
+)
7
+
8
+// RecordServ 系统处理
9
+type RecordServ struct {
10
+	ctx       *utils.Context
11
+	dao       *card.RecordDAO
12
+}
13
+
14
+// NewRecordServ 初始化
15
+func NewRecordServ(ctx *utils.Context) *RecordServ {
16
+	return &RecordServ{
17
+		ctx:       ctx,
18
+		dao:       card.NewRecordDAO(ctx),
19
+	}
20
+}
21
+
22
+// 查询赠送记录
23
+func (s *RecordServ) GetRecordList(startDate string, endDate string, person string,page int,pageSize int) (map[string]interface{}, error) {
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)
33
+	}
34
+
35
+	return map[string]interface{}{
36
+		"list":     info,
37
+		"pagesize": pageSize,
38
+		"pagenum":  total,
39
+		"page":     page,
40
+	}, err
41
+
42
+}
43
+
44
+