k.zhang 1 rok temu
rodzic
commit
4644ae4f41

+ 18 - 3
apis/shanghu/merchant.card.go

@@ -268,12 +268,27 @@ func GetMerchantCanvasCard(c *gin.Context) {
 
 	//返回邀请码
 
-	if inData.Code == "原始码" { //可以分享
+	if inData.Code == "yuanshima" { //可以分享
 		outData.IsShare = true
 		outData.InvitationCode = "7jb6"
 	} else { //查询购买记录,没有购买过不让分享
+		var payTrans shanghu.ClientPayTrans
+		var userInfo shanghu.MerchantClientUser
+
+		payTrans.MerchantCardID = inData.MerchantId
+		payTrans.ClientOpenID = inData.Code
+		payInfo, _ := payTrans.GetPayTransByOpenid()
+		if payInfo.ID <= 0 {
+			outData.IsShare = false
+		} else {
+			outData.IsShare = true
+		}
+
+		userInfo.ClientOpenID = inData.Code
+		userInfoReply, _ := userInfo.GetUserInfo()
+
+		outData.InvitationCode = userInfoReply.Code
 
-		outData.IsShare = false
 	}
 
 	//点击购买的时候把code给进去把 原始码购买属于平台
@@ -281,7 +296,7 @@ func GetMerchantCanvasCard(c *gin.Context) {
 	qr.CheckPath = true
 	qr.Page = "pages/home/home"
 	qr.EnvVersion = "release"
-	qr.Scene = "id-" + strconv.FormatInt(inData.MerchantId, 10) + "-c-" + inData.Code
+	qr.Scene = "id-" + strconv.FormatInt(inData.MerchantId, 10) + "-c-" + outData.InvitationCode
 
 	fmt.Println(qr.Scene)
 	data, err := json.Marshal(&qr)

+ 1 - 1
apis/shanghu/models/pay.go

@@ -8,7 +8,7 @@ type UnifiedOrderRequest struct {
 	MerchantCardId int64           `json:"merchant_card_id"` //商户卡id
 	ClientOpenId   string          `json:"client_open_id"`   //openid
 	Amount         decimal.Decimal `json:"amount"`           // 交易金额
-
+	InvitationCode string          `json:"invitation_code"`  //邀请码
 }
 
 type UnifiedOrderReply struct {

+ 1 - 0
apis/shanghu/pay.go

@@ -71,6 +71,7 @@ func UnifiedOrder(c *gin.Context) {
 	sqlData.OutTradeNo = strconv.FormatInt(inData.MerchantCardId, 10) + strconv.FormatInt(time.Now().UnixNano(), 10)
 	sqlData.Status = 1 //未支付
 	sqlData.MerchantCardID = inData.MerchantCardId
+	sqlData.InvitationCode = inData.InvitationCode
 	_, err = sqlData.Create()
 	if err != nil {
 		app.Error(c, 400, err, "创建支付失败")

+ 13 - 0
models/shanghu/pay.go

@@ -39,6 +39,19 @@ func (m *ClientPayTrans) GetRequestNum() int {
 
 }
 
+func (m *ClientPayTrans) GetPayTransByOpenid() (ClientPayTrans, error) {
+	var doc ClientPayTrans
+
+	table := orm.ShMysql.Table(m.TableName())
+	table = table.Where("merchant_card_id = ? and  client_open_id = ? ", m.MerchantCardID, m.ClientOpenID)
+
+	if err := table.Select("*").First(&doc).Error; err != nil {
+		return doc, err
+	}
+
+	return doc, nil
+}
+
 func (m *ClientPayTrans) GetPayTransByTradeNo() (ClientPayTrans, error) {
 	var doc ClientPayTrans