Prechádzať zdrojové kódy

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

k.zhang 1 mesiac pred
rodič
commit
5e5d6e07b0

+ 64 - 13
apis/shanghu/active.pay.go

@@ -64,17 +64,17 @@ func GetGroupBuyPayList(c *gin.Context) {
 		return
 	}
 
-	// 不是商家也不是c端客户
-	if inData.UserType != 1 && inData.UserType != 2 {
-		app.Error(c, 500, errors.New("用户类型错误"), err.Error())
-		return
-	}
-
-	// 核销类型错误
-	if inData.GroupBuyType != 1 && inData.GroupBuyType != 2 {
-		app.Error(c, 500, errors.New("核销类型错误"), err.Error())
-		return
-	}
+	//// 不是商家也不是c端客户
+	//if inData.UserType != 1 && inData.UserType != 2 {
+	//	app.Error(c, 500, errors.New("用户类型错误"), err.Error())
+	//	return
+	//}
+	//
+	//// 核销类型错误
+	//if inData.GroupBuyType != 1 && inData.GroupBuyType != 2 {
+	//	app.Error(c, 500, errors.New("核销类型错误"), err.Error())
+	//	return
+	//}
 
 	var pageSize = 10
 	var pageIndex = 1
@@ -86,7 +86,7 @@ func GetGroupBuyPayList(c *gin.Context) {
 		pageIndex = inData.PageIndex
 	}
 
-	activeDrawLogList, count, err := sqlData.GetActivePayTransList(pageSize, pageIndex, inData.UserType, inData.GroupBuyType, inData.OpenId)
+	activeDrawLogList, count, err := sqlData.GetActivePayTransList(pageSize, pageIndex, inData.OpenId)
 	if err != nil {
 		app.Error(c, 500, err, err.Error())
 		return
@@ -96,6 +96,8 @@ func GetGroupBuyPayList(c *gin.Context) {
 		var data models.GetGroupBuyPayReply
 		var activeSql shanghu.MerchantActiveConfig
 		var groupBuySql shanghu.MerchantActiveGroupBuy
+		var groupBuyProductSql shanghu.MerchantActiveGroupByProject
+		var groupBuyProductCancel shanghu.ActiveCancelLog
 		data.MerchantAmount = v.MerchantAmount.String()
 		data.Amount = v.Amount.String()
 		data.ClientAmount = v.ClientAmount.String()
@@ -114,9 +116,29 @@ func GetGroupBuyPayList(c *gin.Context) {
 			app.Error(c, 500, err, err.Error())
 			return
 		}
+
+		groupBuyProductSql.GroupBuyID = v.GroupBuyID
+		groupBuyProductList, _, err := groupBuyProductSql.GetGroupBuyProjectList()
+		if err != nil {
+			app.Error(c, 500, err, err.Error())
+			return
+		}
+		totalGroupBuyNum := 0
+		for _, v := range groupBuyProductList {
+			totalGroupBuyNum = totalGroupBuyNum + v.CancelNum
+		}
+
+		groupBuyProductCancel.ClientOpenID = inData.OpenId
+		groupBuyProductCancel.ActiveConfigID = v.ActiveConfigID
+		cancelNum := groupBuyProductCancel.GetActiveCancelNum()
+
 		data.GroupBuyName = groupBuyInfo.GroupBuyName
 		data.PayTime = v.PayTime.Format(time.DateTime)
 		data.TradeNo = v.ThirdTradeNo
+		data.TotalCancelNum = totalGroupBuyNum
+		data.PendingCancelNum = cancelNum
+		data.Url = groupBuyInfo.GroupBuyUrl
+
 		outData = append(outData, data)
 	}
 	app.PageOK(c, outData, count, pageIndex, pageSize, app.Success)
@@ -127,13 +149,42 @@ func GetGroupBuyPayList(c *gin.Context) {
 func GroupBuyPayCode(c *gin.Context) {
 	var inData models.GroupBuyPayCodeRequest
 	var outData models.GroupBuyPayCodeReply
-	//var sqlData shanghu.ClientActivePayTrans
+	var payTransSql shanghu.ClientActivePayTrans
+	var groupBuyProductSql shanghu.MerchantActiveGroupByProject
+	var groupBuyProductCancel shanghu.ActiveCancelLog
 
 	err := c.ShouldBindJSON(&inData)
 	if err != nil {
 		app.Error(c, 400, err, err.Error())
 		return
 	}
+	//校验核销次数
+	payTransSql.ThirdTradeNo = inData.TradeNo
+	payTransInfo, err := payTransSql.GetPayTransByThirdTradeNo()
+	if err != nil {
+		app.Error(c, 500, err, err.Error())
+		return
+	}
+
+	groupBuyProductSql.GroupBuyID = payTransInfo.GroupBuyID
+	groupBuyProductList, _, err := groupBuyProductSql.GetGroupBuyProjectList()
+	if err != nil {
+		app.Error(c, 500, err, err.Error())
+		return
+	}
+	totalGroupBuyNum := 0
+	for _, v := range groupBuyProductList {
+		totalGroupBuyNum = totalGroupBuyNum + v.CancelNum
+	}
+
+	groupBuyProductCancel.ClientOpenID = payTransInfo.ClientOpenID
+	groupBuyProductCancel.ActiveConfigID = payTransInfo.ActiveConfigID
+	cancelNum := groupBuyProductCancel.GetActiveCancelNum()
+
+	if totalGroupBuyNum <= cancelNum {
+		app.Error(c, 500, errors.New("核销次数用完"), "核销次数用完")
+		return
+	}
 
 	outData.Key = "GROU" + tools.MD5(inData.TradeNo+"zhangkun429@")
 	outData.TradeNo = inData.TradeNo

+ 2 - 0
apis/shanghu/client.active.draw.log.go

@@ -55,6 +55,8 @@ func DrawLog(c *gin.Context) {
 		drawLog.DrawProductName = drawProductInfo.DrawProductName
 		drawLog.IsPrize = v.IsPrize
 		drawLog.Id = v.ID
+		drawLog.Url = drawProductInfo.DrawUrl
+		drawLog.DrawTime = v.CreatedAt.Format(time.DateTime)
 		outData = append(outData, drawLog)
 	}
 

+ 1 - 1
apis/shanghu/merchant.active.config.go

@@ -389,7 +389,7 @@ func Draw(c *gin.Context) {
 		return
 	}
 
-	if drawNum+1 < clientDrawNum {
+	if drawNum < clientDrawNum {
 		app.Error(c, 500, errors.New("抽奖次数用完"), "抽奖次数用完")
 		return
 	}

+ 16 - 12
apis/shanghu/models/active.pay.go

@@ -10,21 +10,25 @@ type PendingCancelAmountReply struct {
 }
 
 type GetGroupBuyPayRequest struct {
-	OpenId       string `json:"open_id"`
-	UserType     int    `json:"user_type"`      //1-商家 2-c端客户
-	GroupBuyType int    `json:"group_buy_type"` //1-待核销 2-已核销
-	PageSize     int    `json:"page_size"`
-	PageIndex    int    `json:"page_index"`
+	OpenId    string `json:"open_id"`
+	PageSize  int    `json:"page_size"`
+	PageIndex int    `json:"page_index"`
+	//UserType     int    `json:"user_type"`      //1-商家 2-c端客户
+	//GroupBuyType int    `json:"group_buy_type"` //1-待核销 2-已核销
 }
 
 type GetGroupBuyPayReply struct {
-	ActiveName     string `json:"active_name"`     //活动名称
-	GroupBuyName   string `json:"group_buy_name"`  //拼团名称
-	Amount         string `json:"amount"`          //交易金额
-	MerchantAmount string `json:"merchant_amount"` //商家金额
-	ClientAmount   string `json:"client_amount"`   //客户金额
-	PayTime        string `json:"pay_time"`        //支付时间
-	TradeNo        string `json:"trade_no"`        //交易ID
+	ActiveName       string `json:"active_name"`        //活动名称
+	GroupBuyName     string `json:"group_buy_name"`     //拼团名称
+	Amount           string `json:"amount"`             //交易金额
+	MerchantAmount   string `json:"merchant_amount"`    //商家分账金额
+	ClientAmount     string `json:"client_amount"`      //客户分销金额
+	PayTime          string `json:"pay_time"`           //支付时间
+	TradeNo          string `json:"trade_no"`           //交易ID
+	TotalCancelNum   int    `json:"total_cancel_num"`   //总核销次数
+	PendingCancelNum int    `json:"pending_cancel_num"` //待核销次数
+	Url              string `json:"url"`                //url
+
 }
 
 type GroupBuyPayCodeRequest struct {

+ 2 - 0
apis/shanghu/models/client.active.draw.log.go

@@ -9,7 +9,9 @@ type ClientDrawLogRequest struct {
 type ClientDrawLogReply struct {
 	DrawProductName string `json:"draw_product_name"` //奖品名称
 	IsPrize         int    `json:"is_prize"`          //1-未中奖 2-未兑奖 3-已兑奖
+	Url             string `json:"url"`               //
 	Id              int64  `json:"id"`                //id
+	DrawTime        string `json:"draw_time"`
 }
 
 type DrawLogVerificationCodeRequest struct {

+ 18 - 18
models/shanghu/client.active.pay.trans.go

@@ -2,7 +2,6 @@ package shanghu
 
 import (
 	orm "duoduo/database"
-	"errors"
 	"github.com/shopspring/decimal"
 	"time"
 )
@@ -132,27 +131,28 @@ func (m *ClientActivePayTrans) GetPendingCancelByClient() (ClientActivePayTrans,
 }
 
 // 交易记录
-func (m *ClientActivePayTrans) GetActivePayTransList(pageSize int, pageIndex int, userType int, groupBuyType int, openId string) ([]ClientActivePayTrans, int, error) {
+func (m *ClientActivePayTrans) GetActivePayTransList(pageSize int, pageIndex int, openId string) ([]ClientActivePayTrans, int, error) {
 	var doc []ClientActivePayTrans
 
 	table := orm.ShMysql.Table(m.TableName())
 
-	if userType == 1 { // 商家
-		table = table.Where("merchant_open_id = ?", openId)
-
-	} else if userType == 2 { // c端用户
-		table = table.Where("client_open_id = ?", openId)
-	} else {
-		return doc, 0, errors.New("用户类型错误")
-	}
-
-	if groupBuyType == 1 { // 待核销
-		table = table.Where("status = 2 and account_status in (1,2)")
-	} else if groupBuyType == 2 { //已核销
-		table = table.Where("status = 2 and account_status = 99")
-	} else {
-		return doc, 0, errors.New("核销类型错误")
-	}
+	//if userType == 1 { // 商家
+	//	table = table.Where("merchant_open_id = ?", openId)
+	//
+	//} else if userType == 2 { // c端用户
+	//	table = table.Where("client_open_id = ?", openId)
+	//} else {
+	//	return doc, 0, errors.New("用户类型错误")
+	//}
+	//
+	//if groupBuyType == 1 { // 待核销 核销次数大于0
+	//	table = table.Where("status = 2 and account_status in (1,2)")
+	//} else if groupBuyType == 2 { //已核销
+	//	table = table.Where("status = 2 and account_status = 99")
+	//} else {
+	//	return doc, 0, errors.New("核销类型错误")
+	//}
+	table = table.Where("client_open_id = ? and status = 2 and account_status in (1,2)", openId)
 
 	var count int
 	if err := table.Select("*").Order("id desc").Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&doc).Error; err != nil {