Browse Source

新用户抢购

胡轶钦 6 years ago
parent
commit
565b614f96

+ 38
- 0
controllers/flashbuy/flashbuy.go View File

@@ -162,3 +162,41 @@ func (c *FlashBuyController) GetFlashModelList() {
162 162
 	}
163 163
 	c.ResponseJSON(model)
164 164
 }
165
+
166
+func (c *FlashBuyController) AddNewFlashBuyCustomer() {
167
+	cust := c.Context.Get("customer").(model.TaCustomer)
168
+	flashBuyId := c.GetString(":flashBuyId")
169
+	err := c.dao.AddNewFlashBuyCustomer(cust, flashBuyId)
170
+	if err != nil {
171
+		c.ResponseError(err)
172
+	}
173
+	c.ResponseJSON("添加成功")
174
+}
175
+
176
+func (c *FlashBuyController) UpdateFlashBuyCustomer() {
177
+	cust := c.Context.Get("customer").(model.TaCustomer)
178
+	flashBuyId := c.GetString(":flashBuyId")
179
+	err := c.dao.UpdateFlashBuyCustomer(cust.CustomerId, flashBuyId)
180
+	if err != nil {
181
+		c.ResponseError(err)
182
+	}
183
+	c.ResponseJSON("修改成功")
184
+}
185
+
186
+func (c *FlashBuyController) IsFlashBuyCustomer() {
187
+	cust := c.Context.Get("customer").(model.TaCustomer)
188
+	flashBuyId := c.GetString(":flashBuyId")
189
+	flag, err := c.dao.IsFlashBuyCustomer(cust.CustomerId, flashBuyId)
190
+	if err != nil {
191
+		c.ResponseError(err)
192
+	}
193
+	c.ResponseJSON(flag)
194
+}
195
+
196
+func (c *FlashBuyController) IsNewCustomer() {
197
+	cust := c.Context.Get("customer").(model.TaCustomer)
198
+	if cust.Phone == "" {
199
+		c.ResponseError(errors.New("不是新用户"))
200
+	}
201
+	c.ResponseJSON("是新用户")
202
+}

+ 35
- 0
models/flashbuy/flashbuy.go View File

@@ -291,3 +291,38 @@ func (m *FlashbuyDAO) GetFlashModelList() ([]model.TdFlashbuyModel, error) {
291 291
 	err := m.db.Sql(sql).Find(&model)
292 292
 	return model, err
293 293
 }
294
+
295
+func (m *FlashbuyDAO) AddNewFlashBuyCustomer(customer model.TaFlashBuyCustomer) error {
296
+	customer.CreateDate = time.Now()
297
+	customer.FlashBuyCustomerId = utils.GetGUID()
298
+	_, err := m.db.Insert(customer)
299
+	return err
300
+}
301
+
302
+func (m *FlashbuyDAO) UpdateFlashBuyCustomer(customerId, flashBuyId string) error {
303
+	var customer = model.TaFlashBuyCustomer{
304
+		CustomerId: customerId,
305
+		IsNew:      0,
306
+	}
307
+	var cols = []string{
308
+		"is_new",
309
+	}
310
+	_, err := m.db.Cols(cols...).Where("customer_id = ?", customer.CustomerId).And("flash_buy_id =?", flashBuyId).Update(customer)
311
+	return err
312
+}
313
+
314
+func (m *FlashbuyDAO) IsFlashBuyCustomer(customerId, flashBuyId string) (*model.TaFlashBuyCustomer, error) {
315
+	var customer []model.TaFlashBuyCustomer
316
+	sql := `SELECT
317
+	* 
318
+FROM
319
+	ta_flash_buy_customer 
320
+WHERE
321
+	customer_id = '` + customerId + `'
322
+	and flash_buy_id = '` + flashBuyId + `'`
323
+	err := m.db.Sql(sql).Find(&customer)
324
+	if len(customer) <= 0 {
325
+		return nil, err
326
+	}
327
+	return &customer[0], err
328
+}

+ 13
- 0
models/model/ta_flash_buy_customer.go View File

@@ -0,0 +1,13 @@
1
+package model
2
+
3
+import (
4
+	"time"
5
+)
6
+
7
+type TaFlashBuyCustomer struct {
8
+	FlashBuyCustomerId string    `xorm:"not null VARCHAR(64)"`
9
+	FlashBuyId         string    `xorm:"VARCHAR(64)"`
10
+	CustomerId         string    `xorm:"VARCHAR(64)"`
11
+	IsNew              int       `xorm:"TINYINT(1)"`
12
+	CreateDate         time.Time `xorm:"DATETIME"`
13
+}

+ 6
- 5
models/model/td_flashbuy_model.go View File

@@ -1,9 +1,10 @@
1 1
 package model
2 2
 
3 3
 type TdFlashbuyModel struct {
4
-	ModelId     string `xorm:"not null pk VARCHAR(64)"`
5
-	ModelName   string `xorm:"VARCHAR(64)"`
6
-	OrgId       string `xorm:"VARCHAR(64)"`
7
-	Status      int    `xorm:"SMALLINT(6)"`
8
-	ModelImgUrl string `xorm:"TEXT"`
4
+	ModelId          string `xorm:"not null pk VARCHAR(64)"`
5
+	ModelName        string `xorm:"VARCHAR(64)"`
6
+	OrgId            string `xorm:"VARCHAR(64)"`
7
+	Status           int    `xorm:"SMALLINT(6)"`
8
+	ModelImgUrl      string `xorm:"TEXT"`
9
+	ModelLargeImgUrl string `xorm:"TEXT"`
9 10
 }

+ 4
- 0
routers/wechat.go View File

@@ -101,6 +101,10 @@ func getWechatRoutes(prefix string) beego.LinkNamespace {
101 101
 		beego.NSRouter("/flashbuy/customer", &flashbuy.FlashBuyController{}, "get:GetCustomerFlashBuyByCustomerId"),
102 102
 		beego.NSRouter("/flashbuy/customerFlash/:customerFlashBuyId", &flashbuy.FlashBuyController{}, "get:GetCustomerFlashBuyId"),
103 103
 		beego.NSRouter("/flashbuy/:id", &flashbuy.FlashBuyController{}, "post:FlashBuy"),
104
+		beego.NSRouter("/flashbuy/customer/:flashBuyId", &flashbuy.FlashBuyController{}, "post:AddNewFlashBuyCustomer"),
105
+		beego.NSRouter("/flashbuy/customer/:flashBuyId", &flashbuy.FlashBuyController{}, "put:UpdateFlashBuyCustomer"),
106
+		beego.NSRouter("/flashbuy/customer/:flashBuyId", &flashbuy.FlashBuyController{}, "get:IsFlashBuyCustomer"),
107
+		beego.NSRouter("/flashbuy/newcustomer", &flashbuy.FlashBuyController{}, "get:IsNewCustomer"),
104 108
 
105 109
 		// 客户备注
106 110
 		beego.NSRouter("/customerremark/record/:salesId/:customerId", &customerremark.CustomerRemarkController{}, "get:GetCustomerReceiveRecord"),

+ 2
- 1
service/events/events.go View File

@@ -17,9 +17,10 @@ var EvtActions = map[string]tinyevent.Action{
17 17
 	// 测试
18 18
 	ActTest: tsAction,
19 19
 
20
-	// 赠送
20
+	// 赠送券
21 21
 	ActGiveCoupon: giveCoupon,
22 22
 
23
+	// 赠送卡
23 24
 	ActGiveCard: giveCard,
24 25
 }
25 26
 

+ 1
- 1
service/events/giveCard.go View File

@@ -12,7 +12,7 @@ import (
12 12
 )
13 13
 
14 14
 var giveCard = func(e tinyevent.Event) error {
15
-	utils.LogInfo("开始卡赠送操作...")
15
+	utils.LogInfo("开始卡赠送操作...")
16 16
 
17 17
 	ctx := NewContext()
18 18
 	defer DestroyContext(ctx, false)

+ 1
- 1
service/events/giveCoupon.go View File

@@ -14,7 +14,7 @@ import (
14 14
 // giveCoupon 赠送卡券
15 15
 // Event.Payload.customer  = model.TaCustomer
16 16
 var giveCoupon = func(e tinyevent.Event) error {
17
-	utils.LogInfo("开始券赠送操作...")
17
+	utils.LogInfo("开始券赠送操作...")
18 18
 
19 19
 	ctx := NewContext()
20 20
 	defer DestroyContext(ctx, false)

+ 38
- 0
service/flashbuy/flashbuy.go View File

@@ -314,3 +314,41 @@ func (s *FlashBuyServ) GetFlashModelList() ([]model.TdFlashbuyModel, error) {
314 314
 	}
315 315
 	return model, nil
316 316
 }
317
+
318
+func (s *FlashBuyServ) AddNewFlashBuyCustomer(customer model.TaCustomer, flashBuyId string) error {
319
+	var flashBuyCustomer = model.TaFlashBuyCustomer{
320
+		FlashBuyId: flashBuyId,
321
+		CustomerId: customer.CustomerId,
322
+	}
323
+	if customer.Phone == "" {
324
+		flashBuyCustomer.IsNew = 1
325
+	} else {
326
+		flashBuyCustomer.IsNew = 0
327
+	}
328
+	err := s.dao.AddNewFlashBuyCustomer(flashBuyCustomer)
329
+	if err != nil {
330
+		utils.LogError("存储用户抢购记录失败: " + err.Error())
331
+		return errors.New("存储用户抢购记录失败")
332
+	}
333
+	return nil
334
+}
335
+func (s *FlashBuyServ) UpdateFlashBuyCustomer(customerId, flashBuyId string) error {
336
+	err := s.dao.UpdateFlashBuyCustomer(customerId, flashBuyId)
337
+	if err != nil {
338
+		utils.LogError("更新用户抢购记录失败: " + err.Error())
339
+		return errors.New("更新用户抢购记录失败")
340
+	}
341
+	return nil
342
+}
343
+
344
+func (s *FlashBuyServ) IsFlashBuyCustomer(customerId, flashBuyId string) (bool, error) {
345
+	flashBuyCustomer, err := s.dao.IsFlashBuyCustomer(customerId, flashBuyId)
346
+	if err != nil {
347
+		utils.LogError("判断是否参与失败: " + err.Error())
348
+		return false, errors.New("判断是否参与失败")
349
+	}
350
+	if flashBuyCustomer != nil || flashBuyCustomer.IsNew == 0 {
351
+		return false, errors.New("客户已参与本次抢购")
352
+	}
353
+	return true, nil
354
+}