Browse Source

Merge branch 'yun-group-buy' of k.zhang/duoduo into yun-test

k.zhang 4 months ago
parent
commit
82d767be67

+ 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)                         //核销 奖品与拼团
+		//activeV1.POST("")                                                 //拼团购买
+		//待核销金额
 		//
 
 	}

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

@@ -92,6 +92,7 @@ func ActiveConfigCreate(c *gin.Context) {
 	sqlData.GroupBuyUrl = inData.GroupBuyUrl
 	sqlData.GroupBuy = `{}`
 	sqlData.DrawProduct = `{}`
+	sqlData.BackgroundImage = inData.BackgroundImage
 
 	configData, err := sqlData.Create()
 	if err != nil {
@@ -128,6 +129,7 @@ func ActiveConfigInfo(c *gin.Context) {
 	var outData models.ActiveConfigReply
 	var drawInfoSql shanghu.MerchantActiveDrawProduct
 	var groupBuy shanghu.MerchantActiveGroupBuy
+	var merchant shanghu.Merchant
 
 	err := c.ShouldBindJSON(&inData)
 	if err != nil {
@@ -217,6 +219,15 @@ func ActiveConfigInfo(c *gin.Context) {
 
 	}
 
+	merchant.OpenId = inData.MerchantOpenID
+	merchantInfo, err := merchant.GetMerchant()
+	if err != nil {
+		app.Error(c, 500, err, err.Error())
+		return
+	}
+
+	outData.MerchantName = merchantInfo.MerchantName
+
 	app.OK(c, outData, app.Success)
 
 }
@@ -269,6 +280,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 +289,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()

+ 2 - 0
apis/shanghu/models/active.config.go

@@ -13,6 +13,7 @@ type CreateActiveConfigRequest struct {
 	ActivityEndTime   string  `json:"activity_end_time"`   // 活动结束时间
 	ActivityStartTime string  `json:"activity_start_time"` // 活动开始时间
 	ActiveName        string  `json:"active_name"`         // 活动名称
+	BackgroundImage   string  `json:"background_image"`    // 海报
 }
 
 type ActiveConfigRequest struct {
@@ -21,6 +22,7 @@ type ActiveConfigRequest struct {
 }
 
 type ActiveConfigReply struct {
+	MerchantName      string         `json:"merchant_name"` //商家名称
 	DrawOneBiZhong    int64          `json:"draw_one_bi_zhong"`
 	GroupBuyUrl       string         `json:"group_buy_url"`
 	GroupBuyMode      int            `json:"group_buy_mode"`      // 0-不开团 1-虚拟开团 2-真实开团

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

+ 6 - 0
models/shanghu/merchant.active.config.go

@@ -24,6 +24,12 @@ type MerchantActiveConfig struct {
 	ActivityEndTime   int64     `gorm:"column:activity_end_time;type:bigint(20)" json:"activity_end_time"`     // 活动结束时间
 	ActivityStartTime int64     `gorm:"column:activity_start_time;type:bigint(20)" json:"activity_start_time"` // 活动开始时间
 	ActiveName        string    `gorm:"column:active_name;type:varchar(255)" json:"active_name"`               // 活动名称
+	W                 string    `gorm:"column:w;type:varchar(255)" json:"w"`                                   //
+	X                 string    `gorm:"column:x;type:varchar(255)" json:"x"`                                   //
+	Y                 string    `gorm:"column:y;type:varchar(255)" json:"y"`                                   //
+	H                 string    `gorm:"column:h;type:varchar(255)" json:"h"`                                   //
+	BackgroundImage   string    `gorm:"column:background_image;type:varchar(255)" json:"background_image"`     // 背景图
+
 }
 
 func (m *MerchantActiveConfig) TableName() string {