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