胡轶钦 6 年前
父节点
当前提交
12e5ed3c47

+ 9
- 0
controllers/card/card.go 查看文件

@@ -266,3 +266,12 @@ func (c *CardController) GetCustomerCardByCustomerAndSale() {
266 266
 	}
267 267
 	c.ResponseJSON(cards)
268 268
 }
269
+
270
+func (c *CardController) GetSysCardList() {
271
+	caseid := c.GetString(":caseId")
272
+	cards, err := c.serv.GetSysCardList(caseid)
273
+	if err != nil {
274
+		c.ResponseError(err)
275
+	}
276
+	c.ResponseJSON(cards)
277
+}

+ 25
- 3
controllers/flashbuy/flashbuy.go 查看文件

@@ -35,9 +35,20 @@ func (c *FlashBuyController) GetFlashBuyList() {
35 35
 	c.ResponseJSON(list)
36 36
 }
37 37
 
38
+func (c *FlashBuyController) GetCustomerFlashBuyByCustomerId() {
39
+	customerId := c.GetString(":customerId")
40
+	page, _ := c.GetInt("page")
41
+	pageSize, _ := c.GetInt("pagesize")
42
+	list, err := c.dao.GetCustomerFlashBuyByCustomerId(customerId, page, pageSize)
43
+	if err != nil {
44
+		c.ResponseError(err)
45
+	}
46
+	c.ResponseJSON(list)
47
+}
48
+
38 49
 func (c *FlashBuyController) GetCustomerFlashBuyList() {
39 50
 	flashBuyId := c.GetString(":flashBuyId")
40
-	phone := c.GetString(":phone")
51
+	phone := c.GetString("phone")
41 52
 	page, _ := c.GetInt("page")
42 53
 	pageSize, _ := c.GetInt("pagesize")
43 54
 	list, err := c.dao.GetCustomerFlashBuyById(flashBuyId, phone, page, pageSize)
@@ -57,6 +68,15 @@ func (c *FlashBuyController) GetFlashBuyById() {
57 68
 	c.ResponseJSON(flashBuy)
58 69
 }
59 70
 
71
+func (c *FlashBuyController) GetCustomerFlashBuyId() {
72
+	flashBuyId := c.GetString(":customerFlashBuyId")
73
+	flashBuy, err := c.dao.GetCustomerFlashBuyId(flashBuyId)
74
+	if err != nil {
75
+		c.ResponseError(err)
76
+	}
77
+	c.ResponseJSON(flashBuy)
78
+}
79
+
60 80
 func (c *FlashBuyController) SaveFlashBuy() {
61 81
 	flashbuy := model.TaFlashBuy{}
62 82
 	if err := c.ParseForm(&flashbuy); err != nil {
@@ -80,7 +100,7 @@ func (c *FlashBuyController) DeleteFlashBuy() {
80 100
 
81 101
 func (c *FlashBuyController) UpdateFlashBuy() {
82 102
 	flashBuyId := c.GetString(":flashBuyId")
83
-	flashBuyStatus := c.GetString("flashBuyStatus")
103
+	flashBuyStatus := c.GetString(":flashBuyStatus")
84 104
 	err := c.dao.UpdateFlashBuy(flashBuyId, flashBuyStatus)
85 105
 	if err != nil {
86 106
 		c.ResponseError(err)
@@ -90,7 +110,9 @@ func (c *FlashBuyController) UpdateFlashBuy() {
90 110
 
91 111
 func (c *FlashBuyController) VerifyCustomerFlashBuyList() {
92 112
 	qrcode := c.GetString(":qrcode")
93
-	customerFlashBuy, err := c.dao.VerifyCustomerFlashBuyList(qrcode)
113
+	cases := c.Context.Get("cases").([]model.SysUserCase)
114
+	caseids := c.GetCaseIDs(cases)
115
+	customerFlashBuy, err := c.dao.VerifyCustomerFlashBuyList(qrcode, caseids)
94 116
 	if err != nil {
95 117
 		c.ResponseError(err)
96 118
 	}

+ 10
- 0
controllers/marketing/marketing.go 查看文件

@@ -116,3 +116,13 @@ func (c *MarketingController) SetMarketingDisable() {
116 116
 	}
117 117
 	c.ResponseJSON("操作成功!")
118 118
 }
119
+
120
+func (c *MarketingController) GetUserCases() {
121
+	cases := c.Context.Get("cases").([]model.SysUserCase)
122
+	caseIDs := c.GetCaseIDs(cases)
123
+	sysCase, err := c.serv.GetUserCases(caseIDs)
124
+	if err != nil {
125
+		c.ResponseError(err)
126
+	}
127
+	c.ResponseJSON(sysCase)
128
+}

+ 15
- 0
models/card/card.go 查看文件

@@ -528,3 +528,18 @@ func (m *CardDAO) SaveCardChannel(channelid, cardid string) error {
528 528
 	_, err := m.db.Insert(&cardChannel)
529 529
 	return err
530 530
 }
531
+
532
+func (m *CardDAO) GetSysCardList(caseid string) ([]model.TaCouponCard, error) {
533
+	var card []model.TaCouponCard
534
+	sql := `SELECT
535
+	* 
536
+FROM
537
+	ta_coupon_card 
538
+WHERE
539
+	send_type = '` + models.GIVE_TYPE_SYSTEM + `'
540
+	and case_id = '` + caseid + `'
541
+	and  a.status > ` + strconv.Itoa(models.STATUS_DEL)
542
+	err := m.db.Sql(sql).Find(&card)
543
+	return card, err
544
+
545
+}

+ 49
- 2
models/flashbuy/flashbuy.go 查看文件

@@ -35,6 +35,14 @@ type CustomerFlashBuy struct {
35 35
 	CustomerName             string
36 36
 	Phone                    string
37 37
 }
38
+type CustomerFlashResult struct {
39
+	model.TaCustomerFlashBuy `xorm:"extends"`
40
+	FlashBuyName             string
41
+}
42
+type CustomerFlashDetail struct {
43
+	model.TaCustomerFlashBuy `xorm:"extends"`
44
+	CustomerQrcode           string
45
+}
38 46
 
39 47
 func (m *FlashbuyDAO) GetFlashBuyList(caseid, flashBuyName, flashBuyStatus string, page, pageSize int) ([]FlashBuy, error) {
40 48
 	var flashBuy []FlashBuy
@@ -183,7 +191,7 @@ WHERE
183 191
 	return len(customerFlashBuy), err
184 192
 }
185 193
 
186
-func (m *FlashbuyDAO) GetCustomerFlashBuyByQr(customerFlashBuyId string) (*CustomerFlashBuy, error) {
194
+func (m *FlashbuyDAO) GetCustomerFlashBuyByQr(customerFlashBuyId, caseId string) (*CustomerFlashBuy, error) {
187 195
 	var customerFlashBuy []CustomerFlashBuy
188 196
 	sql := `SELECT
189 197
 	a.*,
@@ -195,7 +203,7 @@ FROM
195 203
 	INNER JOIN ta_customer b ON a.customer_id = b.customer_id
196 204
 	INNER JOIN sys_case c ON a.case_id = c.case_id 
197 205
 WHERE
198
-	a.customer_flash_buy_id ='` + customerFlashBuyId + `'`
206
+	a.customer_flash_buy_id ='` + customerFlashBuyId + `' and a.case_id = '` + caseId + `'`
199 207
 	sql += ` and a.validate_start <= now() and a.validate_end >= now()`
200 208
 	err := m.db.Sql(sql).Find(&customerFlashBuy)
201 209
 	if len(customerFlashBuy) > 0 {
@@ -204,6 +212,45 @@ WHERE
204 212
 	return nil, nil
205 213
 }
206 214
 
215
+func (m *FlashbuyDAO) GetCustomerFlashBuyByCustomerId(customerId string, page, pageSize int) ([]CustomerFlashResult, error) {
216
+	var customerResult []CustomerFlashResult
217
+	sql := `select a.*,b.flash_buy_name
218
+	 from ta_customer_flash_buy a 
219
+	 inner join ta_flash_buy b 
220
+	 on a.flash_buy_id = b.flash_buy_id
221
+	 where a.customer_id = '` + customerId + `'`
222
+	sql += ` order by a.validate_start desc  limit ` + strconv.Itoa(page-1) + `, ` + strconv.Itoa(pageSize)
223
+	err := m.db.Sql(sql).Find(&customerResult)
224
+	return customerResult, err
225
+
226
+}
227
+
228
+func (m *FlashbuyDAO) GetCustomerFlashBuyByCustomerIdCount(customerId string) (int, error) {
229
+	var customerResult []CustomerFlashResult
230
+	sql := `select a.*,b.flash_buy_name
231
+	 from ta_customer_flash_buy a 
232
+	 inner join ta_flash_buy b 
233
+	 on a.flash_buy_id = b.flash_buy_id
234
+	 where a.customer_id = '` + customerId + `'`
235
+	err := m.db.Sql(sql).Find(&customerResult)
236
+	return len(customerResult), err
237
+
238
+}
239
+
240
+func (m *FlashbuyDAO) GetCustomerFlashBuyId(customerFlashBuyId string) (*CustomerFlashDetail, error) {
241
+	var customerDetail CustomerFlashDetail
242
+	sql := `SELECT
243
+	a.*,
244
+	b.customer_qrcode 
245
+FROM
246
+	ta_customer_flash_buy a
247
+	INNER JOIN ta_customer_course_qrcode b ON a.customer_flash_buy_id = b.customer_course_id
248
+	WHERE a.customer_flash_buy_id = '` + customerFlashBuyId + `'`
249
+	err := m.db.Sql(sql).Find(&customerDetail)
250
+	return &customerDetail, err
251
+
252
+}
253
+
207 254
 // Update
208 255
 
209 256
 // FlashBuy 抢购

+ 11
- 0
models/marketing/marketing.go 查看文件

@@ -136,3 +136,14 @@ func (m *MarketingDAO) UpdateMarketing(activity model.SysActivity) error {
136 136
 	_, err := m.db.Cols(cols...).Where("action_id=?", activity.ActivityId).Update(activity)
137 137
 	return err
138 138
 }
139
+
140
+func (m *MarketingDAO) GetUserCases(caseid string) ([]model.SysCase, error) {
141
+	var cases []model.SysCase
142
+	sql := `SELECT
143
+	* 
144
+FROM
145
+	sys_case 
146
+WHERE case_id in ('` + strings.Replace(caseid, ",", "','", -1) + `')`
147
+	err := m.db.Sql(sql).Find(&cases)
148
+	return cases, err
149
+}

+ 2
- 0
routers/common.go 查看文件

@@ -277,6 +277,7 @@ func getCommonRoutes(prefix string) beego.LinkNamespace {
277 277
 		beego.NSRouter("/card/:id", &card.CardController{}, "get:GetCardByIDForAdmin"),
278 278
 		beego.NSRouter("/card/:id", &card.CardController{}, "put:UpdateCard"),
279 279
 		beego.NSRouter("/card/:id/to/:users", &card.CardController{}, "post:GiveCard"),
280
+		beego.NSRouter("/card/:caseId", &card.CardController{}, "get:GetSysCardList"),
280 281
 		// 赠送记录
281 282
 		beego.NSRouter("/record", &card.RecordController{}, "get:GetRecordList"),
282 283
 
@@ -298,6 +299,7 @@ func getCommonRoutes(prefix string) beego.LinkNamespace {
298 299
 		beego.NSRouter("/marketing/normal/:activityId", &marketing.MarketingController{}, "put:SetMarketingNormal"),
299 300
 		beego.NSRouter("/marketing/disable/:activityId", &marketing.MarketingController{}, "put:SetMarketingDisable"),
300 301
 		beego.NSRouter("/marketing/:activityId", &marketing.MarketingController{}, "delete:DelMarketing"),
302
+		beego.NSRouter("/marketing/case", &marketing.MarketingController{}, "get:GetUserCases"),
301 303
 
302 304
 		// websocket
303 305
 		beego.NSRouter("/websocket/:grps/:id", &controllers.BaseController{}, "get:Ws"),

+ 6
- 0
routers/wechat.go 查看文件

@@ -7,6 +7,7 @@ import (
7 7
 	"spaceofcheng/services/controllers/coupon"
8 8
 	"spaceofcheng/services/controllers/course"
9 9
 	"spaceofcheng/services/controllers/customer"
10
+	"spaceofcheng/services/controllers/flashbuy"
10 11
 	"spaceofcheng/services/controllers/goods"
11 12
 	"spaceofcheng/services/controllers/gymcard"
12 13
 	"spaceofcheng/services/controllers/luckdraw"
@@ -90,5 +91,10 @@ func getWechatRoutes(prefix string) beego.LinkNamespace {
90 91
 		beego.NSRouter("/luckdraw/record", &luckdraw.LuckDrawController{}, "get:GetRecordByLuckDraw"),
91 92
 		beego.NSRouter("/user/luckdraw/record", &luckdraw.LuckDrawController{}, "get:GetUserLuckDraw"),
92 93
 		beego.NSRouter("/user/luckdraw/record/:id", &luckdraw.LuckDrawController{}, "get:GetRecordByID"),
94
+
95
+		// 抢购
96
+		beego.NSRouter("/flashbuy/:flashBuyId", &flashbuy.FlashBuyController{}, "get:GetFlashBuyById"),
97
+		beego.NSRouter("/flashbuy/:customerId", &flashbuy.FlashBuyController{}, "get:GetCustomerFlashBuyByCustomerId"),
98
+		beego.NSRouter("/flashbuy/:customerFlashBuyId", &flashbuy.FlashBuyController{}, "get:GetCustomerFlashBuyId"),
93 99
 	)
94 100
 }

+ 9
- 0
service/card/card.go 查看文件

@@ -392,6 +392,15 @@ func (s *CardServ) GetCustomerCardByID(id string) (*card.CustomerCardWithShare,
392 392
 	return card, nil
393 393
 }
394 394
 
395
+func (s *CardServ) GetSysCardList(caseid string) ([]model.TaCouponCard, error) {
396
+	cards, err := s.dao.GetSysCardList(caseid)
397
+	if err != nil {
398
+		utils.LogError("获取体验卡失败: " + err.Error())
399
+		return nil, errors.New("获取体验卡失败")
400
+	}
401
+	return cards, nil
402
+}
403
+
395 404
 // GetCaseUsableCard 获取案场可用卡
396 405
 func (s *CardServ) GetCaseUsableCard(page, pageSize int) (map[string]interface{}, error) {
397 406
 

+ 1
- 0
service/events/constant.go 查看文件

@@ -13,4 +13,5 @@ const (
13 13
 
14 14
 	// 送券
15 15
 	ActGiveCoupon = "giveCoupon"
16
+	ActGiveCard   = "giveCard"
16 17
 )

+ 33
- 2
service/flashbuy/flashbuy.go 查看文件

@@ -109,7 +109,7 @@ func (s *FlashBuyServ) GetCustomerFlashBuyById(flashBuyId, phone string, page, p
109 109
 	}, nil
110 110
 }
111 111
 
112
-func (s *FlashBuyServ) VerifyCustomerFlashBuyList(qrcode string) (*flashbuy.CustomerFlashBuy, error) {
112
+func (s *FlashBuyServ) VerifyCustomerFlashBuyList(qrcode, caseId string) (*flashbuy.CustomerFlashBuy, error) {
113 113
 	var err error
114 114
 	var customerFlashBuyId string
115 115
 	var customerVerify *flashbuy.CustomerFlashBuy
@@ -118,7 +118,7 @@ func (s *FlashBuyServ) VerifyCustomerFlashBuyList(qrcode string) (*flashbuy.Cust
118 118
 		utils.LogError("获取核销列表失败: " + err.Error())
119 119
 		return nil, errors.New("获取核销列表失败")
120 120
 	}
121
-	customerVerify, err = s.dao.GetCustomerFlashBuyByQr(customerFlashBuyId)
121
+	customerVerify, err = s.dao.GetCustomerFlashBuyByQr(customerFlashBuyId, caseId)
122 122
 	if err != nil {
123 123
 		utils.LogError("获取核销列表失败: " + err.Error())
124 124
 		return nil, errors.New("获取核销列表失败")
@@ -135,3 +135,34 @@ func (s *FlashBuyServ) Verify(customerFlashBuyId string) error {
135 135
 	}
136 136
 	return nil
137 137
 }
138
+
139
+func (s *FlashBuyServ) GetCustomerFlashBuyByCustomerId(customerId string, page, pageSize int) (map[string]interface{}, error) {
140
+	if pageSize == 0 {
141
+		pageSize = service.PAGENUM
142
+	}
143
+	flashbuys, err := s.dao.GetCustomerFlashBuyByCustomerId(customerId, page, pageSize)
144
+	if err != nil {
145
+		utils.LogError("获取抢购活动列表失败: " + err.Error())
146
+		return nil, errors.New("获取抢购活动列表失败")
147
+	}
148
+	total, err := s.dao.GetCustomerFlashBuyByCustomerIdCount(customerId)
149
+	if err != nil {
150
+		utils.LogError("获取抢购活动列表失败: " + err.Error())
151
+		return nil, errors.New("获取抢购活动列表失败")
152
+	}
153
+	return map[string]interface{}{
154
+		"list":     flashbuys,
155
+		"pageSize": pageSize,
156
+		"pagenum":  total,
157
+		"page":     page,
158
+	}, nil
159
+}
160
+
161
+func (s *FlashBuyServ) GetCustomerFlashBuyId(customerFlashBuyId string) (*flashbuy.CustomerFlashDetail, error) {
162
+	flashbuy, err := s.dao.GetCustomerFlashBuyId(customerFlashBuyId)
163
+	if err != nil {
164
+		utils.LogError("获取抢购活动信息失败: " + err.Error())
165
+		return nil, errors.New("获取抢购活动信息失败")
166
+	}
167
+	return flashbuy, nil
168
+}

+ 12
- 0
service/marketing/marketing.go 查看文件

@@ -4,6 +4,7 @@ import (
4 4
 	"encoding/json"
5 5
 	"errors"
6 6
 	"spaceofcheng/services/models"
7
+	"spaceofcheng/services/models/card"
7 8
 	"spaceofcheng/services/models/coupon"
8 9
 	"spaceofcheng/services/models/marketing"
9 10
 	"spaceofcheng/services/models/model"
@@ -22,6 +23,7 @@ type MarketingServ struct {
22 23
 	wdao      *marketing.WorkDAO
23 24
 	userdao   *system.UserDAO
24 25
 	couponDAO *coupon.CouponDAO
26
+	cardDAO   *card.CardDAO
25 27
 }
26 28
 
27 29
 // NewMarketingServ 初始化
@@ -32,6 +34,7 @@ func NewMarketingServ(ctx *utils.Context) *MarketingServ {
32 34
 		wdao:      marketing.NewWorkDAO(ctx),
33 35
 		userdao:   system.NewUserDAO(ctx),
34 36
 		couponDAO: coupon.NewCouponDAO(ctx),
37
+		cardDAO:   card.NewCardDAO(ctx),
35 38
 	}
36 39
 }
37 40
 
@@ -225,3 +228,12 @@ func (s *MarketingServ) UpdateMarketing(activity model.SysActivity) error {
225 228
 	err := s.dao.UpdateMarketing(activity)
226 229
 	return err
227 230
 }
231
+
232
+func (s *MarketingServ) GetUserCases(caseId string) ([]model.SysCase, error) {
233
+	cases, err := s.dao.GetUserCases(caseId)
234
+	if err != nil {
235
+		utils.LogError("获取用户案场失败: " + err.Error())
236
+		return nil, errors.New("获取用户案场失败")
237
+	}
238
+	return cases, nil
239
+}