瀏覽代碼

抽奖次数

k.zhang 3 月之前
父節點
當前提交
f235b47fae

+ 2 - 0
apis/shanghu/base.go

@@ -85,6 +85,8 @@ func InitShangHuRouter(engine *gin.RouterGroup) {
 		activeV1.POST("/active/draw/list", DrawLog)                       //中奖列表
 		activeV1.POST("/draw/verification/code", DrawLogVerificationCode) //奖品核销码                                           //中奖核销码
 		activeV1.POST("/draw/cancel", DrawCancel)                         //核销 奖品与拼团
+		//拼团购买
+		//待核销金额
 		//
 
 	}

+ 26 - 0
apis/shanghu/merchant.active.config.go

@@ -269,6 +269,8 @@ func ActiveConfigList(c *gin.Context) {
 func Draw(c *gin.Context) {
 	var inData models.DrawRequest
 	var sqlData shanghu.MerchantActiveConfig
+	var drawNumSql shanghu.ClientActiveDrawNum
+	var draw shanghu.ClientActiveDrawLog
 	var outData models.DrawReply
 
 	err := c.ShouldBindJSON(&inData)
@@ -276,6 +278,30 @@ func Draw(c *gin.Context) {
 		app.Error(c, 400, err, err.Error())
 		return
 	}
+
+	// 校验抽奖次数
+	drawNumSql.ActiveConfigID = inData.ActiveConfigID
+	drawNumSql.ClientOpenID = inData.ClientOpenID
+	drawNum, err := drawNumSql.GetDrawNum()
+	if err != nil {
+		app.Error(c, 500, err, err.Error())
+		return
+	}
+
+	//校验数量
+	draw.ActiveConfigID = inData.ActiveConfigID
+	draw.ClientOpenID = inData.ClientOpenID
+	clientDrawNum, err := draw.GetClientActiveDrawLogNum()
+	if err != nil {
+		app.Error(c, 500, err, err.Error())
+		return
+	}
+
+	if drawNum+1 < clientDrawNum {
+		app.Error(c, 500, errors.New("抽奖次数用完"), "抽奖次数用完")
+		return
+	}
+
 	// 先校验是否有必中抽奖
 	sqlData.ID = inData.ActiveConfigID
 	config, err := sqlData.GetConfigInfoById()

+ 13 - 4
conf/conn_ini__test.go

@@ -1,6 +1,7 @@
 package conf
 
 import (
+	"fmt"
 	"testing"
 )
 
@@ -8,10 +9,18 @@ import (
 
 func Test_ConnIni(t *testing.T) {
 
-	conf, err := ConnIni()
-	if err != nil {
-		t.Error(err)
+	//conf, err := ConnIni()
+	//if err != nil {
+	//	t.Error(err)
+	//} else {
+	//	t.Log(conf.MustValue("ubrSet", "ubr_host"))
+	//}
+
+	fmt.Println("fff")
+	var f bool
+	if f {
+		fmt.Println("t")
 	} else {
-		t.Log(conf.MustValue("ubrSet", "ubr_host"))
+		fmt.Println("f")
 	}
 }

+ 22 - 9
models/shanghu/client.active.draw.log.go

@@ -8,15 +8,15 @@ import (
 
 type ClientActiveDrawLog struct {
 	ID             int64     `gorm:"column:id;type:bigint(20);primary_key;AUTO_INCREMENT" json:"id"`
-	ActiveConfigID int64     `gorm:"column:active_config_id;type:bigint(20)" json:"active_config_id"` // 活动抽奖id
-	ClientOpenID   string    `gorm:"column:client_open_id;type:varchar(255)" json:"client_open_id"`
-	DrawProductID  int64     `gorm:"column:draw_product_id;type:bigint(20)" json:"draw_product_id"` // 中奖商品
-	CreateBy       int64     `gorm:"column:create_by;type:bigint(20)" json:"create_by"`             // 创建者
-	UpdateBy       int64     `gorm:"column:update_by;type:bigint(20)" json:"update_by"`             // 更新者
-	CreatedAt      time.Time `gorm:"column:created_at;type:datetime(3)" json:"created_at"`          // 创建时间
-	UpdatedAt      time.Time `gorm:"column:updated_at;type:datetime(3)" json:"updated_at"`          // 最后更新时间
-	DeletedAt      time.Time `gorm:"column:deleted_at;type:datetime(3)" json:"deleted_at"`          // 删除时间
-	IsPrize        int       `gorm:"column:is_prize;type:int(11)" json:"is_prize"`                  // 1-未中奖 2-未兑奖 3-已兑奖
+	ActiveConfigID int64     `gorm:"column:active_config_id;type:bigint(20)" json:"active_config_id"`   // 活动抽奖id
+	ClientOpenID   string    `gorm:"column:client_open_id;type:varchar(255)" json:"client_open_id"`     //
+	DrawProductID  int64     `gorm:"column:draw_product_id;type:bigint(20)" json:"draw_product_id"`     // 中奖商品
+	CreateBy       int64     `gorm:"column:create_by;type:bigint(20)" json:"create_by"`                 // 创建者
+	UpdateBy       int64     `gorm:"column:update_by;type:bigint(20)" json:"update_by"`                 // 更新者
+	CreatedAt      time.Time `gorm:"column:created_at;type:datetime(3)" json:"created_at"`              // 创建时间
+	UpdatedAt      time.Time `gorm:"column:updated_at;type:datetime(3)" json:"updated_at"`              // 最后更新时间
+	DeletedAt      time.Time `gorm:"column:deleted_at;type:datetime(3);default:null" json:"deleted_at"` // 删除时间
+	IsPrize        int       `gorm:"column:is_prize;type:int(11)" json:"is_prize"`                      // 1-未中奖 2-未兑奖 3-已兑奖
 }
 
 func (m *ClientActiveDrawLog) TableName() string {
@@ -36,6 +36,19 @@ func (m *ClientActiveDrawLog) GetClientActiveDrawLogByBiZHong() (int64, error) {
 
 }
 
+func (m *ClientActiveDrawLog) GetClientActiveDrawLogNum() (int, error) {
+	var count int
+
+	table := orm.ShMysql.Table(m.TableName())
+	table = table.Where("active_config_id = ? and client_open_id = ? ",
+		m.ActiveConfigID, m.ClientOpenID)
+	if err := table.Count(&count).Error; err != nil {
+		return 0, nil
+	}
+	return count, nil
+
+}
+
 func (m *ClientActiveDrawLog) Create() (ClientActiveDrawLog, error) {
 	var doc ClientActiveDrawLog
 	var err error

+ 33 - 0
models/shanghu/client.active.draw.num.go

@@ -0,0 +1,33 @@
+package shanghu
+
+import (
+	orm "duoduo/database"
+	"time"
+)
+
+type ClientActiveDrawNum struct {
+	ID                  int       `gorm:"column:id;type:int(11);primary_key;AUTO_INCREMENT" json:"id"`
+	ActiveConfigID      int64     `gorm:"column:active_config_id;type:bigint(20)" json:"active_config_id"`
+	ClientOpenID        string    `gorm:"column:client_open_id;type:varchar(255)" json:"client_open_id"`                 // 邀请人
+	ClientOpenIDInvited string    `gorm:"column:client_open_id_invited;type:varchar(255)" json:"client_open_id_invited"` // 被邀请人
+	CreateBy            int64     `gorm:"column:create_by;type:bigint(20)" json:"create_by"`                             // 创建者
+	UpdateBy            int64     `gorm:"column:update_by;type:bigint(20)" json:"update_by"`                             // 更新者
+	CreatedAt           time.Time `gorm:"column:created_at;type:datetime(3)" json:"created_at"`                          // 创建时间
+	UpdatedAt           time.Time `gorm:"column:updated_at;type:datetime(3)" json:"updated_at"`                          // 最后更新时间
+	DeletedAt           time.Time `gorm:"column:deleted_at;type:datetime(3);default:null" json:"deleted_at"`             // 删除时间
+}
+
+func (m *ClientActiveDrawNum) TableName() string {
+	return "client_active_draw_num"
+}
+
+// 抽奖次数
+func (m *ClientActiveDrawNum) GetDrawNum() (int, error) {
+
+	table := orm.ShMysql.Table(m.TableName())
+
+	table = table.Where("client_open_id = ? and active_config_id = ? ", m.ClientOpenID, m.ActiveConfigID)
+	var count int
+	table.Count(&count)
+	return count, nil
+}