Browse Source

核销购买

k.zhang 2 tháng trước cách đây
mục cha
commit
b1a7ccd60e

+ 271 - 1
apis/shanghu/active.pay.go

@@ -3,9 +3,13 @@ package shanghu
 import (
 	"duoduo/apis/shanghu/models"
 	"duoduo/models/shanghu"
+	"duoduo/tools"
 	"duoduo/tools/app"
+	"encoding/base64"
+	"encoding/json"
 	"errors"
 	"github.com/gin-gonic/gin"
+	"github.com/skip2/go-qrcode"
 	"time"
 )
 
@@ -49,7 +53,7 @@ func PendingCancelAmount(c *gin.Context) {
 }
 
 // 拼团购买
-func GetGroupBuyPay(c *gin.Context) {
+func GetGroupBuyPayList(c *gin.Context) {
 	var inData models.GetGroupBuyPayRequest
 	var sqlData shanghu.ClientActivePayTrans
 	var outData []models.GetGroupBuyPayReply
@@ -112,8 +116,274 @@ func GetGroupBuyPay(c *gin.Context) {
 		}
 		data.GroupBuyName = groupBuyInfo.GroupBuyName
 		data.PayTime = v.PayTime.Format(time.DateTime)
+		data.TradeNo = v.ThirdTradeNo
 		outData = append(outData, data)
 	}
 	app.PageOK(c, outData, count, pageIndex, pageSize, app.Success)
 
 }
+
+// 拼团核销码
+func GroupBuyPayCode(c *gin.Context) {
+	var inData models.GroupBuyPayCodeRequest
+	var outData models.GroupBuyPayCodeReply
+	//var sqlData shanghu.ClientActivePayTrans
+
+	err := c.ShouldBindJSON(&inData)
+	if err != nil {
+		app.Error(c, 400, err, err.Error())
+		return
+	}
+
+	outData.Key = "GROU" + tools.MD5(inData.TradeNo+"zhangkun429@")
+	outData.TradeNo = inData.TradeNo
+
+	str, err := json.Marshal(&outData)
+	if err != nil {
+		app.Error(c, 500, err, err.Error())
+		return
+	}
+	qr, err := qrcode.Encode(string(str), qrcode.High, 200)
+	if err != nil {
+		app.Error(c, 500, err, err.Error())
+		return
+	}
+	encodedData := base64.StdEncoding.EncodeToString(qr)
+
+	app.OK(c, encodedData, app.Success)
+}
+
+// 拼团核销详情
+func GroupBuyCancelInfo(c *gin.Context) {
+	var inData models.GroupBuyCancelInfoRequest
+	var outData models.GroupBuyCancelInfoReply
+	var sqlData shanghu.ClientActivePayTrans
+	var activeConfigSql shanghu.MerchantActiveConfig
+	var groupBuySql shanghu.MerchantActiveGroupBuy
+	var groupBuyProjectSql shanghu.MerchantActiveGroupByProject
+
+	err := c.ShouldBindJSON(&inData)
+	if err != nil {
+		app.Error(c, 400, err, err.Error())
+		return
+	}
+
+	key := "GROU" + tools.MD5(inData.TradeNo+"zhangkun429@")
+	if inData.Key != key {
+		app.Error(c, 500, errors.New("数据错误"), "数据错误")
+		return
+	}
+	sqlData.ThirdTradeNo = inData.TradeNo
+	payTransInfo, err := sqlData.GetPayTransByThirdTradeNo()
+	if err != nil {
+		app.Error(c, 500, err, err.Error())
+		return
+	}
+
+	//校验分账类型
+	//if payTransInfo.AccountStatus != shanghu.ClientActivePayTransAccountStatusUnSettle && payTransInfo.AccountStatus != shanghu.ClientActivePayTransAccountStatusSettleFail {
+	//	app.Error(c, 500, errors.New("核销已完成"), "核销已完成")
+	//	return
+	//}
+	// 校验支付类型
+	if payTransInfo.Status != shanghu.ClientActivePayTransStatusPaySuccess {
+		app.Error(c, 500, errors.New("未支付交易不准核销"), "未支付交易不准核销")
+		return
+	}
+
+	// 返回拼团信息
+	outData.Amount = payTransInfo.Amount.String()
+	outData.TradeNo = inData.TradeNo
+	outData.PayTime = payTransInfo.PayTime.Format(time.DateTime)
+	outData.MerchantAmount = payTransInfo.MerchantAmount.String()
+	outData.ClientAmount = payTransInfo.ClientAmount.String()
+
+	activeConfigSql.ID = payTransInfo.ActiveConfigID
+	activeConfigInfo, err := activeConfigSql.GetConfigInfoById()
+	if err != nil {
+		app.Error(c, 500, err, err.Error())
+		return
+	}
+	outData.ActiveName = activeConfigInfo.ActiveName
+	groupBuySql.ID = payTransInfo.GroupBuyID
+	groupBuyInfo, err := groupBuySql.GetMerchantActiveGroupBuyById()
+	if err != nil {
+		app.Error(c, 500, err, err.Error())
+		return
+	}
+
+	outData.GroupBuyName = groupBuyInfo.GroupBuyName
+	groupBuyProjectSql.GroupBuyID = payTransInfo.GroupBuyID
+	project, _, err := groupBuyProjectSql.GetGroupBuyProjectList()
+	if err != nil {
+		app.Error(c, 500, err, err.Error())
+		return
+	}
+
+	for _, v := range project {
+		var projectInfo models.CancelGroupBuyProject
+		var activeCancelSql shanghu.ActiveCancelLog
+		activeCancelSql.ClientOpenID = payTransInfo.ClientOpenID
+		activeCancelSql.ActiveConfigID = payTransInfo.ActiveConfigID
+		num := activeCancelSql.GetActiveCancelNum()
+		projectInfo.ProjectName = v.ProjectName
+		projectInfo.TotalCancelNum = v.CancelNum
+		projectInfo.PendingCancelNum = v.CancelNum - num
+		projectInfo.ID = v.ID
+		outData.GroupBuyProject = append(outData.GroupBuyProject, projectInfo)
+	}
+
+	app.OK(c, outData, app.Success)
+}
+
+// 拼团核销
+func GroupBuyCancel(c *gin.Context) {
+	var inData models.GroupBuyCancelRequest
+	var payTrans shanghu.ClientActivePayTrans
+	var activeCancelLogList []shanghu.ActiveCancelLog
+
+	err := c.ShouldBindJSON(&inData)
+	if err != nil {
+		app.Error(c, 400, err, err.Error())
+		return
+	}
+
+	key := "GROU" + tools.MD5(inData.TradeNo+"zhangkun429@")
+	if inData.Key != key {
+		app.Error(c, 500, errors.New("数据错误"), "数据错误")
+		return
+	}
+
+	//查交易
+	payTrans.ThirdTradeNo = inData.TradeNo
+
+	transInfo, err := payTrans.GetPayTransByThirdTradeNo()
+	if err != nil {
+		app.Error(c, 500, err, err.Error())
+		return
+	}
+
+	//校验分账类型
+	//if transInfo.AccountStatus != shanghu.ClientActivePayTransAccountStatusUnSettle && transInfo.AccountStatus != shanghu.ClientActivePayTransAccountStatusSettleFail {
+	//	app.Error(c, 500, errors.New("核销已完成"), "核销已完成")
+	//	return
+	//}
+
+	// 校验支付类型
+	if transInfo.Status != shanghu.ClientActivePayTransStatusPaySuccess {
+		app.Error(c, 500, errors.New("未支付交易不准核销"), "未支付交易不准核销")
+		return
+	}
+
+	//查看核销次数
+	//是否可以核销,默认不可以核销,只要有一个可以核销就为true
+	isCancel := false
+	for _, v := range inData.GroupBuyProject {
+		var projectSql shanghu.MerchantActiveGroupByProject
+		var activeCancel shanghu.ActiveCancelLog
+
+		projectSql.ID = v.ID
+		projectInfo, err := projectSql.GetMerchantActiveGroupBuyProjectByID()
+		if err != nil {
+			app.Error(c, 500, err, err.Error())
+			return
+		}
+
+		cancelNum := activeCancel.GetActiveCancelNum()
+		if projectInfo.CancelNum >= cancelNum+v.CancelNum && v.CancelNum > 0 {
+			isCancel = true
+			for i := 0; i < projectInfo.CancelNum; i++ {
+				var activeCancelLogInfo shanghu.ActiveCancelLog
+				activeCancelLogInfo.ActiveConfigID = payTrans.ActiveConfigID
+				activeCancelLogInfo.ClientOpenID = payTrans.ClientOpenID
+				activeCancelLogInfo.MerchantOpenID = inData.OpenId
+				activeCancelLogInfo.GroupByProjectID = v.ID
+				activeCancelLogInfo.CreatedAt = time.Now()
+				activeCancelLogInfo.UpdatedAt = time.Now()
+
+				activeCancelLogList = append(activeCancelLogList, activeCancelLogInfo)
+			}
+		}
+
+	}
+
+	if !isCancel {
+		app.Error(c, 500, errors.New("核销次数不够"), "核销次数不够")
+		return
+	}
+
+	// 分账
+	if transInfo.AccountStatus != shanghu.ClientActivePayTransAccountStatusUnSettle && transInfo.AccountStatus != shanghu.ClientActivePayTransAccountStatusSettleFail {
+		//不需要分账
+		var activeCancel shanghu.ActiveCancelLog
+		err = activeCancel.TXActiveCancelLogCreate(activeCancelLogList)
+		if err != nil {
+			app.Error(c, 500, err, err.Error())
+			return
+		}
+	} else { // 需要分账
+		//校验是否被分过,分过后不再分账
+		var merchantAccountLog shanghu.MerchantAccountLog
+		merchantAccountLog.PayTransId = payTrans.ID
+		merchantAccountLog.TransType = shanghu.MerchantAccountLogTransTypeGroupBuy
+		num := merchantAccountLog.GetAccountLogNum()
+		if num > 0 { //交易已经分过账
+			app.Error(c, 500, errors.New("交易已分过账"), "交易已分过账")
+			return
+		}
+		//分账校验账号
+		var merchantAccount shanghu.MerchantAccount
+		merchantAccount.MerchantOpenID = payTrans.MerchantOpenID
+		merchantAccountInfo, err := merchantAccount.GetMerchantAccount()
+		if err != nil && err.Error() != "record not found" {
+			app.Error(c, 500, err, err.Error())
+			return
+		}
+		if merchantAccountInfo.ID == 0 { //需要创建新账号
+			merchantAccount.MerchantOpenID = payTrans.MerchantOpenID
+			merchantAccount.Version = 1
+			merchantAccount.CreatedAt = time.Now()
+			merchantAccount.UpdatedAt = time.Now()
+			_, err = merchantAccount.Create()
+			if err != nil {
+				app.Error(c, 500, err, err.Error())
+				return
+			}
+
+		}
+		if payTrans.InvitationCode != shanghu.YuanShiMa { //校验c端客户
+			var activeUser shanghu.ActiveUser
+			var clientAccount shanghu.ActiveClientAccount
+			activeUser.Code = payTrans.InvitationCode
+			activeUserInfo, err := activeUser.GetUserInfoByCode()
+			if err != nil {
+				app.Error(c, 500, err, err.Error())
+				return
+			}
+			clientAccount.ClientOpenID = activeUserInfo.OpenID
+			clientAccountInfo, err := clientAccount.GetMerchantAccount()
+			if err != nil && err.Error() != "record not found" {
+				app.Error(c, 500, err, err.Error())
+				return
+			}
+
+			if clientAccountInfo.ID == 0 { //需要创建新账号
+				clientAccount.ClientOpenID = activeUserInfo.OpenID
+				clientAccount.Version = 1
+				clientAccount.CreatedAt = time.Now()
+				clientAccount.UpdatedAt = time.Now()
+				_, err = clientAccount.Create()
+				if err != nil {
+					app.Error(c, 500, err, err.Error())
+					return
+				}
+
+			}
+
+		}
+
+		//分账 根据merchant-openid + activeUserInfo.openid 进行分账
+
+	}
+
+}

+ 5 - 3
apis/shanghu/base.go

@@ -85,6 +85,7 @@ func InitShangHuRouter(engine *gin.RouterGroup) {
 		activeV1.POST("/active/draw/list", DrawLog)                         //中奖列表
 		activeV1.POST("/draw/verification/code", DrawLogVerificationCode)   //奖品核销码                                           //中奖核销码
 		activeV1.POST("/draw/cancel", DrawCancel)                           //核销 奖品与拼团
+		activeV1.POST("/draw/info", DrawCancelInfo)                         //奖品详情
 		activeV1.POST("/active/config/whxy", UpdateActiveConfigWHXY)        //二维码坐标
 		activeV1.POST("/active/qr", GetClientActiveQR)                      //获取二维码
 		activeV1.POST("/active/unified/order", GroupByUnifiedOrder)         //拼团购买
@@ -92,9 +93,10 @@ func InitShangHuRouter(engine *gin.RouterGroup) {
 		activeV1.POST("/active/draw/num", InvitedDrawNum)                   //邀请次数
 		activeV1.POST("/client/user/set", ActiveOpenIdSet)                  //活动 创建用户
 		activeV1.POST("/active/pending.cancel/amount", PendingCancelAmount) //待核销金额  从交易记录里面求和, 扫码后核销,进入可提现余额
-		//拼团核销
-		//拼团核销码
-		activeV1.POST("/active/group.buy/pay", GetGroupBuyPay) //购买拼团列表
+		activeV1.POST("/active/group.buy/cancel", GroupBuyCancel)           //拼团核销&分账,只要核销了一件就分账。根据id核销
+		activeV1.POST("/active/group.buy.cancel/info", GroupBuyCancelInfo)  //核销详情
+		activeV1.POST("/active/group.buy/code", GroupBuyPayCode)            //拼团核销码
+		activeV1.POST("/active/group.buy/pay", GetGroupBuyPayList)          //购买拼团列表
 		//提现
 		activeV1.POST("/active/draw/count", ActiveDrawCount) //邀请客户数量统计
 

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

@@ -11,6 +11,7 @@ import (
 	"github.com/gin-gonic/gin"
 	"github.com/skip2/go-qrcode"
 	"strconv"
+	"time"
 )
 
 func DrawLog(c *gin.Context) {
@@ -139,3 +140,56 @@ func DrawCancel(c *gin.Context) {
 	app.OK(c, nil, app.Success)
 
 }
+
+func DrawCancelInfo(c *gin.Context) {
+	var inData models.DrawCancelInfoRequest
+	var sqlData shanghu.ClientActiveDrawLog
+	var activeConfigSql shanghu.MerchantActiveConfig
+	var drawProductSql shanghu.MerchantActiveDrawProduct
+	var outData models.DrawCancelInfoReply
+
+	err := c.ShouldBindJSON(&inData)
+	if err != nil {
+		app.Error(c, 400, err, err.Error())
+		return
+	}
+
+	key := "DRAW" + tools.MD5(strconv.FormatInt(inData.DrawLogId, 10)+"zhangkun429@")
+	if key != inData.Key {
+		app.Error(c, 500, errors.New("数据错误"), "数据错误")
+		return
+	}
+
+	sqlData.ID = inData.DrawLogId
+	drawLog, err := sqlData.GetClientActiveDrawLogListById()
+	if err != nil {
+		app.Error(c, 500, err, err.Error())
+		return
+	}
+	if drawLog.IsPrize != 2 {
+		app.Error(c, 500, errors.New("未中奖或已兑奖"), "未中奖或已兑奖")
+		return
+	}
+
+	activeConfigSql.ID = drawLog.ActiveConfigID
+	activeInfo, err := activeConfigSql.GetConfigInfoById()
+	if err != nil {
+		app.Error(c, 500, err, err.Error())
+		return
+	}
+	drawProductSql.ID = drawLog.DrawProductID
+	drawProduct, err := drawProductSql.GetDrawProductById()
+	if err != nil {
+		app.Error(c, 500, err, err.Error())
+		return
+	}
+
+	outData.DrawUrl = drawProduct.DrawUrl
+	outData.DrawProductName = drawProduct.DrawProductName
+	outData.ActiveConfigName = activeInfo.ActiveName
+	outData.DrawLogId = inData.DrawLogId
+	outData.DrawTime = drawLog.CreatedAt.Format(time.DateTime)
+
+	app.OK(c, outData, app.Success)
+
+}

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

@@ -759,7 +759,7 @@ func GroupByUnifiedOrder(c *gin.Context) {
 		app.Error(c, 400, err, err.Error())
 		return
 	}
-	if activeConfigInfo.DrawMode != 1 { //虚拟开团
+	if activeConfigInfo.GroupBuyMode != 1 { //虚拟开团
 		app.Error(c, 500, errors.New("非虚拟开团,不允许下单"), "非虚拟开团,不允许下单.")
 		return
 	}

+ 47 - 0
apis/shanghu/models/active.pay.go

@@ -24,5 +24,52 @@ type GetGroupBuyPayReply struct {
 	MerchantAmount string `json:"merchant_amount"` //商家金额
 	ClientAmount   string `json:"client_amount"`   //客户金额
 	PayTime        string `json:"pay_time"`        //支付时间
+	TradeNo        string `json:"trade_no"`        //交易ID
+}
+
+type GroupBuyPayCodeRequest struct {
+	TradeNo string `json:"trade_no"` //交易ID
+}
+
+type GroupBuyPayCodeReply struct {
+	Key     string `json:"key"`      //key
+	TradeNo string `json:"trade_no"` //交易ID
+}
+
+type GroupBuyCancelInfoRequest struct {
+	Key     string `json:"key"`      //key
+	TradeNo string `json:"trade_no"` //交易ID
+}
+
+type GroupBuyCancelInfoReply 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
+	GroupBuyProject []CancelGroupBuyProject `json:"group_buy_project"` //拼团项目
+}
+
+type CancelGroupBuyProject struct {
+	ProjectName      string `json:"project_name"`
+	TotalCancelNum   int    `json:"total_cancel_num"`   //总核销数量
+	PendingCancelNum int    `json:"pending_cancel_num"` //待核销数量
+	ID               int64  `json:"id"`
+}
+
+type GroupBuyCancelRequest struct {
+	Key             string                         `json:"key"`               //key
+	TradeNo         string                         `json:"trade_no"`          //交易ID
+	GroupBuyProject []PendingCancelGroupBuyProject `json:"group_buy_project"` //拼团项目
+	OpenId          string                         `json:"open_id"`           //核销人员
+}
+
+type GroupBuyCancelReply struct {
+}
 
+type PendingCancelGroupBuyProject struct {
+	CancelNum int   `json:"cancel_num"` //数量
+	ID        int64 `json:"id"`
 }

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

@@ -25,3 +25,17 @@ type DrawCancelRequest struct {
 	DrawLogId int64  `json:"draw_log_id"`
 	Key       string `json:"key"`
 }
+
+type DrawCancelInfoRequest struct {
+	DrawLogId int64  `json:"draw_log_id"`
+	Key       string `json:"key"`
+}
+
+// 返回
+type DrawCancelInfoReply struct {
+	ActiveConfigName string `json:"active_config_name"` //配置名称
+	DrawProductName  string `json:"draw_product_name"`  //奖品名称
+	DrawUrl          string `json:"draw_url"`           //图片URL
+	DrawLogId        int64  `json:"draw_log_id"`        //抽奖id
+	DrawTime         string `json:"draw_time"`          //中奖时间
+}

+ 56 - 0
models/shanghu/active.cancel.log.go

@@ -0,0 +1,56 @@
+package shanghu
+
+import (
+	orm "duoduo/database"
+	"time"
+)
+
+type ActiveCancelLog struct {
+	ID               int64     `gorm:"column:id;type:bigint(20);primary_key;AUTO_INCREMENT" json:"id"` // 主键
+	ClientOpenID     string    `gorm:"column:client_open_id;type:varchar(255)" json:"client_open_id"`
+	MerchantOpenID   string    `gorm:"column:merchant_open_id;type:varchar(255)" json:"merchant_open_id"`
+	ActiveConfigID   int64     `gorm:"column:active_config_id;type:bigint(20)" json:"active_config_id"`       // 活动id
+	GroupByProjectID int64     `gorm:"column:group_by_project_id;type:bigint(20)" json:"group_by_project_id"` // 拼团商品id
+	SeckillID        int64     `gorm:"column:seckill_id;type:bigint(20)" json:"seckill_id"`                   // 秒杀id
+	UpdateBy         int64     `gorm:"column:update_by;type:bigint(20)" json:"update_by"`
+	CreateBy         int64     `gorm:"column:create_by;type:bigint(20)" json:"create_by"`
+	CreatedAt        time.Time `gorm:"column:created_at;type:datetime" json:"created_at"`
+	UpdatedAt        time.Time `gorm:"column:updated_at;type:datetime" json:"updated_at"`
+	DeletedAt        time.Time `gorm:"column:deleted_at;type:datetime;default:null" json:"deleted_at"`
+}
+
+func (m *ActiveCancelLog) TableName() string {
+	return "active_cancel_log"
+}
+
+// 统计cancel数量
+func (m *ActiveCancelLog) GetActiveCancelNum() int {
+	var count int
+
+	tableCount := orm.ShMysql.Table(m.TableName()).Where("active_config_id = ? and client_open_id = ?", m.ActiveConfigID, m.ClientOpenID)
+	tableCount.Count(&count)
+	return count
+}
+
+func (m *ActiveCancelLog) TXActiveCancelLogCreate(log []ActiveCancelLog) error {
+
+	var err error
+	tx := orm.ShMysql.Begin()
+	defer func() {
+		if err != nil {
+			tx.Rollback()
+		} else {
+			tx.Commit()
+		}
+	}()
+
+	for i := 0; i < len(log); i++ {
+		err = tx.Table(log[i].TableName()).Create(&log[i]).Error
+		if err != nil {
+			return err
+		}
+	}
+
+	return nil
+
+}

+ 13 - 0
models/shanghu/active.user.go

@@ -70,3 +70,16 @@ func (m *ActiveUser) GetUserInfo() (ActiveUser, error) {
 	return doc, nil
 
 }
+
+func (m *ActiveUser) GetUserInfoByCode() (ActiveUser, error) {
+	var doc ActiveUser
+
+	table := orm.ShMysql.Table(m.TableName())
+	table = table.Where("code = ?  ", m.Code)
+
+	if err := table.Select("*").First(&doc).Error; err != nil {
+		return doc, err
+	}
+
+	return doc, nil
+}

+ 31 - 1
models/shanghu/actvie.client.account.go

@@ -1,6 +1,9 @@
 package shanghu
 
-import "time"
+import (
+	orm "duoduo/database"
+	"time"
+)
 
 type ActiveClientAccount struct {
 	ID           int64     `gorm:"column:id;type:bigint(20);primary_key;AUTO_INCREMENT" json:"id"`    // 主键
@@ -18,3 +21,30 @@ type ActiveClientAccount struct {
 func (m *ActiveClientAccount) TableName() string {
 	return "active_client_account"
 }
+
+func (m *ActiveClientAccount) GetMerchantAccount() (ActiveClientAccount, error) {
+	var doc ActiveClientAccount
+
+	table := orm.ShMysql.Table(m.TableName())
+	table = table.Where("client_open_id = ?  ", m.ClientOpenID)
+
+	if err := table.Select("*").First(&doc).Error; err != nil {
+		return doc, err
+	}
+
+	return doc, nil
+
+}
+
+func (m *ActiveClientAccount) Create() (ActiveClientAccount, error) {
+	var doc ActiveClientAccount
+	var err error
+
+	doc = *m
+	err = orm.ShMysql.Table(m.TableName()).Create(&doc).Error
+	if err != nil {
+		return doc, err
+	}
+
+	return doc, nil
+}

+ 50 - 0
models/shanghu/client.active.pay.trans.go

@@ -33,6 +33,25 @@ type ClientActivePayTrans struct {
 
 }
 
+const (
+	ClientActivePayTransAccountStatusDef           = 0
+	ClientActivePayTransAccountStatusUnSettle      = 1  //未分账
+	ClientActivePayTransAccountStatusSettleFail    = 2  //分账失败
+	ClientActivePayTransAccountStatusSettlePending = 3  //分账中
+	ClientActivePayTransAccountStatusSettleSuccess = 99 //分账成功
+)
+const (
+	ClientActivePayTransStatusDef        = 0
+	ClientActivePayTransStatusUnPay      = 1 // 未支付
+	ClientActivePayTransStatusPaySuccess = 2 //支付成功
+	ClientActivePayTransStatusPayCancel  = 3 //取消支付
+	ClientActivePayTransStatusRefund     = 4 // 退款
+)
+
+const (
+	YuanShiMa = "yuanshima" //
+)
+
 func (m *ClientActivePayTrans) TableName() string {
 	return "client_active_pay_trans"
 }
@@ -142,3 +161,34 @@ func (m *ClientActivePayTrans) GetActivePayTransList(pageSize int, pageIndex int
 	table.Count(&count)
 	return doc, count, nil
 }
+
+func (m *ClientActivePayTrans) GetPayTransByThirdTradeNo() (ClientActivePayTrans, error) {
+	var doc ClientActivePayTrans
+
+	table := orm.ShMysql.Table(m.TableName())
+	table = table.Where("third_trade_no = ?  ", m.ThirdTradeNo)
+
+	if err := table.Select("*").First(&doc).Error; err != nil {
+		return doc, err
+	}
+
+	return doc, nil
+}
+
+// 分账
+func (m *ClientActivePayTrans) TXSettle(payInfo ClientActivePayTrans) error {
+	var err error
+
+	tx := orm.ShMysql.Begin()
+	defer func() {
+		if err != nil {
+			tx.Rollback()
+		} else {
+			tx.Commit()
+		}
+	}()
+	//判断是否有这个商家账号,c端用户账号,没有用户需要创建
+
+	//商家加款 c端用户加款
+	return nil
+}

+ 13 - 0
models/shanghu/merchant.account.go

@@ -36,3 +36,16 @@ func (m *MerchantAccount) GetMerchantAccount() (MerchantAccount, error) {
 	return doc, nil
 
 }
+
+func (m *MerchantAccount) Create() (MerchantAccount, error) {
+	var doc MerchantAccount
+	var err error
+
+	doc = *m
+	err = orm.ShMysql.Table(m.TableName()).Create(&doc).Error
+	if err != nil {
+		return doc, err
+	}
+
+	return doc, nil
+}

+ 17 - 1
models/shanghu/merchant.account.log.go

@@ -1,6 +1,7 @@
 package shanghu
 
 import (
+	orm "duoduo/database"
 	"github.com/shopspring/decimal"
 	"time"
 )
@@ -11,7 +12,7 @@ type MerchantAccountLog struct {
 	ReviewAmountPre   decimal.Decimal `gorm:"column:review_amount_pre;type:decimal(10,2)" json:"review_amount_pre"`     // 审核资金 交易前
 	AmountPre         decimal.Decimal `gorm:"column:amount_pre;type:decimal(10,2)" json:"amount_pre"`                   // 交易前
 	AmountAfter       decimal.Decimal `gorm:"column:amount_after;type:decimal(10,2)" json:"amount_after"`               // 交易后
-	TransType         int             `gorm:"column:trans_type;type:int(11)" json:"trans_type"`                         // 交易类型  0-买卡入账  2-提现
+	TransType         int             `gorm:"column:trans_type;type:int(11)" json:"trans_type"`                         // 交易类型  0-买卡入账 1-拼团入账  2-提现
 	MerchantOpenID    string          `gorm:"column:merchant_open_id;type:varchar(255)" json:"merchant_open_id"`        // 商户openid
 	CreateBy          int64           `gorm:"column:create_by;type:bigint(20)" json:"create_by"`                        // 创建者
 	UpdateBy          int64           `gorm:"column:update_by;type:bigint(20)" json:"update_by"`                        // 更新者
@@ -25,3 +26,18 @@ type MerchantAccountLog struct {
 func (m *MerchantAccountLog) TableName() string {
 	return "merchant_account_log"
 }
+
+const (
+	MerchantAccountLogTransTypeCard     = 0 //霸王卡入账
+	MerchantAccountLogTransTypeGroupBuy = 1 //拼团入账
+	MerchantAccountLogTransTypeCashOut  = 2 //提现
+)
+
+// 获取
+func (m *MerchantAccountLog) GetAccountLogNum() int {
+	var count int
+
+	tableCount := orm.ShMysql.Table(m.TableName()).Where("trans_type = ? and pay_trans_id = ?", m.TransType, m.PayTransId)
+	tableCount.Count(&count)
+	return count
+}

+ 12 - 0
models/shanghu/merchant.active.group.buy.project.go

@@ -49,3 +49,15 @@ func (m *MerchantActiveGroupByProject) GetGroupBuyProjectList() ([]MerchantActiv
 	table.Count(&count)
 	return doc, count, nil
 }
+
+func (m *MerchantActiveGroupByProject) GetMerchantActiveGroupBuyProjectByID() (MerchantActiveGroupByProject, error) {
+	var doc MerchantActiveGroupByProject
+
+	table := orm.ShMysql.Table(m.TableName())
+	table = table.Where("id = ?  ", m.ID)
+	if err := table.Select("*").First(&doc).Error; err != nil {
+		return doc, err
+	}
+
+	return doc, nil
+}