浏览代码

Merge branch 'develop' of k.zhang/duoduo into master

k.zhang 1 年之前
父节点
当前提交
c66fff3331

+ 6 - 0
apis/shanghu/models/pay.go

@@ -18,3 +18,9 @@ type UnifiedOrderReply struct {
 	PaySign   string `json:"pay_sign"`  // 签名
 	SignType  string `json:"sign_type"` // 签名类型
 }
+
+type PayCashOutRequest struct {
+	OpenId   string `json:"open_id"`
+	UserName string `json:"user_name"` //收款人姓名
+	CashType string `json:"cash_type"`
+}

+ 99 - 0
apis/shanghu/pay.go

@@ -12,6 +12,7 @@ import (
 	"github.com/gin-gonic/gin"
 	"github.com/go-pay/gopay"
 	"github.com/go-pay/gopay/wechat"
+	wechatV3 "github.com/go-pay/gopay/wechat/v3"
 	"github.com/shopspring/decimal"
 	"net/http"
 	"strconv"
@@ -126,6 +127,58 @@ func UnifiedOrder(c *gin.Context) {
 
 }
 
+func PayCashOut(c *gin.Context) {
+	var inData models.PayCashOutRequest
+	//var sqlData
+
+	if inData.CashType == "client" {
+		//先设置账户状态 为提现中,提现中不允许再操作,提现金额默认全部
+
+	} else if inData.CashType == "merchant" {
+
+	} else {
+		app.Error(c, 400, errors.New("类型错误"), "类型错误")
+		return
+	}
+
+	client := NewWechatService()
+
+	err := client.AddCertPkcs12FilePath("./apiclient_cert.p12")
+	if err != nil {
+		app.Error(c, 400, err, err.Error())
+		return
+	}
+
+	bm := make(gopay.BodyMap)
+
+	partnerTradeNo := common.GetRandomString(32)
+
+	bm.Set("nonce_str", common.GetRandomString(32))
+	bm.Set("partner_trade_no", partnerTradeNo)
+	bm.Set("openid", inData.OpenId)
+	bm.Set("check_name", "FORCE_CHECK")
+	bm.Set("re_user_name", inData.UserName)
+	bm.Set("amount", 30)   // 企业付款金额,单位为分
+	bm.Set("desc", "测试转账") // 企业付款备注,必填。注意:备注中的敏感词会被转成字符*
+	bm.Set("spbill_create_ip", "127.0.0.1")
+
+	wxResp, err := client.Transfer(c, bm)
+	if err != nil {
+		app.Error(c, 400, err, "提现失败")
+		return
+	}
+
+	if wxResp.ReturnCode != "SUCCESS" {
+		app.Error(c, 400, errors.New(wxResp.ReturnMsg), "提现")
+		return
+	}
+	if wxResp.ResultCode != "SUCCESS" {
+		app.Error(c, 400, errors.New(wxResp.ErrCode+"--"+wxResp.ErrCodeDes), "提现")
+		return
+	}
+
+}
+
 func PayCallBack(c *gin.Context) {
 	var payLog shanghu.PayCallbackLog
 	var payTrans shanghu.ClientPayTrans
@@ -212,3 +265,49 @@ func NewWechatService() *wechat.Client {
 
 	return client
 }
+
+func NewWechatServiceV3() (*wechatV3.ClientV3, error) {
+
+	key := `MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQD/RTrS1Tycrskr
+SkuzdLNmOic4UklFtoyKtKDIeklbQFvynJBC1wYaitoOqFkdGWagkcuqRqJOcgEQ
+T8DRDD/rnVKTrnntevUSW3vZYwMscomK3dgjRRui5GLY5wYHuKhp02bldLrhPKNy
+wT5IYhoDwQLmf5IrURbtT8bKpdC+NyEEfw+d/mHMK56w80YKfzFtSmjoB9SkWDLg
+YFBlw91C78E73uqhCKnArN7p2iJe+tsp7EGpDVcdowqcMKjY2YiNPY6ABZaI9YJx
+nRQs5Sjm6YSsJujMR5rQVZ3HCfLlzxLpPyHfqffbJ+vviend1PJ/ugJeM2hehn1d
+LrpKuWyHAgMBAAECggEAIbow6nhYGM+TLtATLnPF3ETkt7FPkxFqgk0ZTUOy+4aG
+X4jGGr60RL+Bzhv6Ijkf8SkyQp4whbLUZyZScIxwyZ2wsmiEHZd4V+OUeoV1fuLn
+P1zOWOKhoyUP1l630j9YqRrQZpLEuku7wMa9huzHSSWwT2odkvGU2OgIeO/to6P7
+gIE4Q+3pNmTdaXJweUlVoz6sdqsSWAZ729SxzY34zcRyXI+feBQb9n/C1hr9+Ge4
+KbBsvrECy0eUNiAT9f5dPwgwjyRpR9gJ8xxaezIYfxdpTTW3EB1Gf+xPX4X7ml2B
+zObPN2HEwLHhrwbOXLFP8F/62TK4fIGe2yXPIKIe8QKBgQD/t4Xy9pTFrmNhDLMe
+ZMHdj9XMoM/izcquI6rq4pGWLtnyxIcFuXiqvPszbJL+urCc1+HqfPAVScryEg5W
+b6AvLENVhC5E3GcZA50ciAr+PUrB1UXH0vbbc7HP/Mofsz61kxEW2SvKaPoKhW8M
+IavoVWDJkcLHnjM20Gt7tioEXwKBgQD/jZR7FDSB8VCRp687QcH4s0HyAWaRVhmC
+qId2xVbPFVlbm4BWcQVWPdsUei29sPPtcvzREFStKwTmu2FSUfoDv3uM4Nl2+h/Y
+pbhfuYfHd79UZa0OtT9njJHZcYPwKRmZQIVBVHSJFSZy2HSGLe9AdI7gAsNMx/Mm
+eqZDU79I2QKBgQCBSNoSIpTI9QgNkwwkO7DAQe5IDK3N71mffSz2oCIXGgza7n2N
+aV4WhIFEWIpg+yY7xfHUSeJgAPT4OiTBkqIb93b7j16NNhlxzh/qwuU78OUQ5rDm
+/EQOY4nsq9PM/ySfTIGBWb8IENcJ5rhkG8n8Jt5OSsF9hwBBoFIXM9w+ZQKBgQD1
+rArw43Sy8uTskZKA2e96ggHEgBo1X9s4Y4GO6ZlRjQmRaoVPFGn4BZEGN4qfkGx/
+egqXhSaSLwgQNFUUCWDbl4pT3ZjRqxVQdcgwpjBkzratkO10dUOV7WoM6vbWuvwz
++vXf3ywE2MNUpsgmciROB3+O1LkhqBsVg9UwZmM+yQKBgQD6yBvxOaHXBSZncz+m
+3SpdbcRjK82i3IUJ3sl18J7YEPer0FclsUcQOluqBbHTOAr8letWPrKnjZGuyFfg
+gAjwa8uLSyfEEcWb9WcObvud2GNxS/LiI0GnW9ittvT29JvOhmUUtnty5/TiWIsi
+slm2kO53RSw9brymV8PAX2+SXg==`
+
+	client, err := wechatV3.NewClientV3("wx25357518f710b8ce", "219B3AF3B5F17D4C2F145EE318188708318DD7BD", "9x9ydkdk0nzsa4mr2ucq75grlvt9n8l3", key)
+	if err != nil {
+		return nil, err
+	}
+
+	// 启用自动同步返回验签,并定时更新微信平台API证书(开启自动验签时,无需单独设置微信平台API证书和序列号)
+	err = client.AutoVerifySign()
+	if err != nil {
+		return nil, err
+	}
+
+	// 打开Debug开关,输出日志,默认是关闭的
+	//client.DebugSwitch = gopay.DebugOn
+
+	return client, nil
+}

+ 1 - 0
models/shanghu/client.account.log.go

@@ -18,6 +18,7 @@ type MerchantClientAccountLog struct {
 	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"`        // 删除时间
+	Amount            decimal.Decimal `gorm:"column:amount;type:decimal(10,2)" json:"amount"`                           // 交易金额
 }
 
 func (m *MerchantClientAccountLog) TableName() string {

+ 2 - 0
models/shanghu/merchant.account.log.go

@@ -18,6 +18,8 @@ type MerchantAccountLog struct {
 	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"`        // 删除时间
+	Amount            decimal.Decimal `gorm:"column:amount;type:decimal(10,2)" json:"amount"`                           // 交易金额
+
 }
 
 func (m *MerchantAccountLog) TableName() string {

+ 2 - 0
models/shanghu/pay.go

@@ -246,6 +246,7 @@ func (m *ClientPayTrans) SettleAdd(merchantAmount, clientAmount decimal.Decimal,
 	merchantAccountLog.AmountAfter = merchantAmountAdd
 	merchantAccountLog.ReviewAmountAfter = merchantAccount.ReviewAmount
 	merchantAccountLog.ReviewAmountPre = merchantAccount.ReviewAmount
+	merchantAccountLog.Amount = merchantAmount
 
 	err = tx.Table("merchant_account_log").Create(&merchantAccountLog).Error
 	if err != nil {
@@ -270,6 +271,7 @@ func (m *ClientPayTrans) SettleAdd(merchantAmount, clientAmount decimal.Decimal,
 	clientAccountLog.AmountAfter = clientAmountAdd
 	clientAccountLog.ReviewAmountAfter = clientAccount.ReviewAmount
 	clientAccountLog.ReviewAmountPre = clientAccount.ReviewAmount
+	clientAccountLog.Amount = clientAmount
 
 	err = tx.Table("merchant_client_account_log").Create(&clientAccountLog).Error
 	if err != nil {

+ 3 - 0
report/shang.hu.ka.go

@@ -22,6 +22,7 @@ func ClientAccount() {
 		account.Status = 2        //支付成功
 		clientTrans, err := account.GetPayTransByStatus()
 		if err != nil {
+			fmt.Println("GetPayTransByStatus err ", err.Error())
 			break
 		}
 		data := make(map[string]interface{})
@@ -29,6 +30,7 @@ func ClientAccount() {
 		data["updated_at"] = time.Now()
 		err = clientTrans.UpdateById(data)
 		if err != nil {
+			fmt.Println("UpdateById err ", err.Error())
 			break
 		}
 
@@ -43,6 +45,7 @@ func ClientAccount() {
 			dataErr["updated_at"] = time.Now()
 			err = clientTrans.UpdateById(dataErr)
 			if err != nil {
+				fmt.Println("GetMerchantCard err ", err.Error())
 				break
 			}
 			continue