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