wangfei 6 年前
父节点
当前提交
0a8b65845d
共有 3 个文件被更改,包括 28 次插入10 次删除
  1. 1
    1
      conf/app.conf
  2. 1
    1
      conf/log.conf
  3. 26
    8
      models/luckdraw/luckdraw.go

+ 1
- 1
conf/app.conf 查看文件

5
 copyrequestbody = true
5
 copyrequestbody = true
6
 EnableDocs = true
6
 EnableDocs = true
7
 excelpath = ./
7
 excelpath = ./
8
-clienturl = http://dev.ycjcjy.com/c-v2
8
+clienturl = http://dev.ycjcjy.com/
9
 
9
 
10
 postwechatInfo = http://testapi.chioy.com.cn/api/network/postwechatInfo
10
 postwechatInfo = http://testapi.chioy.com.cn/api/network/postwechatInfo
11
 qrcodePrefix = bodycheck_
11
 qrcodePrefix = bodycheck_

+ 1
- 1
conf/log.conf 查看文件

1
 [common]
1
 [common]
2
-filename="E:\\GoProjects\\src\\spaceofcheng\\services\\log\\common.log"
2
+filename="E:\\GoProject\\src\\spaceofcheng\\services\\log\\common.log"
3
 # log level "emergency", "alert", "critical", "error", "warning", "notice", "info", "debug"
3
 # log level "emergency", "alert", "critical", "error", "warning", "notice", "info", "debug"
4
 level="debug"
4
 level="debug"

+ 26
- 8
models/luckdraw/luckdraw.go 查看文件

277
 			prizes[inx].Status = models.STATUS_NORMAL
277
 			prizes[inx].Status = models.STATUS_NORMAL
278
 		}
278
 		}
279
 		if prize.PrizeType == models.PRIZE_TYPE_COUPONCARD {
279
 		if prize.PrizeType == models.PRIZE_TYPE_COUPONCARD {
280
-			err := m.SavePrizeDetail(prizes[inx].TaLuckdrawPrize)
280
+			valid, err := m.SavePrizeDetail(prizes[inx].TaLuckdrawPrize)
281
 			if err != nil {
281
 			if err != nil {
282
 				return err
282
 				return err
283
 			}
283
 			}
284
+			prizes[inx].ValidDays = valid.ValidDays
285
+			prizes[inx].VerificationStart = valid.VerificationStart
286
+			prizes[inx].VerificationEnd = valid.VerificationEnd
284
 		}
287
 		}
285
 		saveprizes = append(saveprizes, prizes[inx].TaLuckdrawPrize)
288
 		saveprizes = append(saveprizes, prizes[inx].TaLuckdrawPrize)
286
 		// 保存内定信息
289
 		// 保存内定信息
298
 	return err
301
 	return err
299
 }
302
 }
300
 
303
 
304
+// Verification 有效期
305
+type Verification struct {
306
+	ValidDays         int
307
+	VerificationStart time.Time
308
+	VerificationEnd   time.Time
309
+}
310
+
301
 // SavePrizeDetail 保存奖品明细
311
 // SavePrizeDetail 保存奖品明细
302
-func (m *LuckDrawDao) SavePrizeDetail(prize model.TaLuckdrawPrize) error {
312
+func (m *LuckDrawDao) SavePrizeDetail(prize model.TaLuckdrawPrize) (*Verification, error) {
313
+	var verification = Verification{}
303
 	if prize.CouponCardType == models.PRIZE_TYPE_COUPON {
314
 	if prize.CouponCardType == models.PRIZE_TYPE_COUPON {
304
 		var coupon model.TaCoupon
315
 		var coupon model.TaCoupon
305
 		_, err := m.db.Where("coupon_id=?", prize.CouponCardId).Get(&coupon)
316
 		_, err := m.db.Where("coupon_id=?", prize.CouponCardId).Get(&coupon)
306
 		if err != nil {
317
 		if err != nil {
307
-			return err
318
+			return nil, err
308
 		}
319
 		}
309
 		if coupon.UsedCount > 0 {
320
 		if coupon.UsedCount > 0 {
310
-			return errors.New("卡券已被使用!不允许保存!")
321
+			return nil, errors.New("卡券已被使用!不允许保存!")
311
 		}
322
 		}
323
+		verification.ValidDays = coupon.ValidDays
324
+		verification.VerificationStart = coupon.StartDate
325
+		verification.VerificationEnd = coupon.EndDate
312
 		var details []model.TaPrizeDetail
326
 		var details []model.TaPrizeDetail
313
 		i := 0
327
 		i := 0
314
 		for i < coupon.TotalCount {
328
 		for i < coupon.TotalCount {
329
 		var card model.TaCouponCard
343
 		var card model.TaCouponCard
330
 		_, err := m.db.Where("card_id=?", prize.CouponCardId).Get(&card)
344
 		_, err := m.db.Where("card_id=?", prize.CouponCardId).Get(&card)
331
 		if err != nil {
345
 		if err != nil {
332
-			return err
346
+			return nil, err
333
 		}
347
 		}
334
 		if card.UsedCount > 0 {
348
 		if card.UsedCount > 0 {
335
-			return errors.New("卡券已被使用!不允许保存!")
349
+			return nil, errors.New("卡券已被使用!不允许保存!")
336
 		}
350
 		}
351
+		verification.ValidDays = 0
352
+		verification.VerificationStart = card.StartDate
353
+		verification.VerificationEnd = card.EndDate
337
 		var details []model.TaPrizeDetail
354
 		var details []model.TaPrizeDetail
338
 		i := 0
355
 		i := 0
339
 		for i < card.TotalCount {
356
 		for i < card.TotalCount {
352
 		m.db.Insert(details)
369
 		m.db.Insert(details)
353
 	}
370
 	}
354
 
371
 
355
-	return nil
372
+	return &verification, nil
356
 }
373
 }
357
 
374
 
358
 // UpdateLuckDraw 修改抽奖
375
 // UpdateLuckDraw 修改抽奖
677
 
694
 
678
 	for _, prize := range prizes {
695
 	for _, prize := range prizes {
679
 		// 有剩余的 并且 未过期的
696
 		// 有剩余的 并且 未过期的
680
-		if prize.Remainder > 0 && now.Before(prize.VerificationEnd) {
697
+		if prize.Remainder > 0 && (now.Before(prize.VerificationEnd) || prize.ValidDays > 0) {
681
 			p := map[string]interface{}{
698
 			p := map[string]interface{}{
682
 				"prize": prize,
699
 				"prize": prize,
683
 				"prob":  prize.Probability,
700
 				"prob":  prize.Probability,
687
 		}
704
 		}
688
 	}
705
 	}
689
 
706
 
707
+	utils.LogError(pList)
690
 	if len(pList) == 0 {
708
 	if len(pList) == 0 {
691
 		return nil, errors.New("所有奖品已抽完")
709
 		return nil, errors.New("所有奖品已抽完")
692
 	}
710
 	}