zhouxnsz 1 year ago
parent
commit
b0ff351d4d
5 changed files with 109 additions and 16 deletions
  1. 0 1
      .gitignore
  2. 16 0
      .vscode/launch.json
  3. 13 5
      controllers/bank/bank.go
  4. 52 10
      models/bank.go
  5. 28 0
      models/ori.go

+ 0 - 1
.gitignore

@@ -1,5 +1,4 @@
 __debug_bin
-.vscode/launch.json
 /log
 .DS_Store
 mtp2_if

+ 16 - 0
.vscode/launch.json

@@ -0,0 +1,16 @@
+{
+    // 使用 IntelliSense 了解相关属性。 
+    // 悬停以查看现有属性的描述。
+    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
+    "version": "0.2.0",
+    "configurations": [
+        {
+            "name": "Launch Package",
+            "type": "go",
+            "request": "launch",
+            "mode": "auto",
+            "program": "${workspaceFolder}",
+            "output": "__debug_bin_queryservice"
+        }
+    ]
+}

+ 13 - 5
controllers/bank/bank.go

@@ -46,8 +46,9 @@ func QueryBankBranChnumInfo(c *gin.Context) {
 }
 
 type GetAmtInByPaidUrlReq struct {
-	AccountId  int    `form:"accountid" binding:"required"`  // 资金账户
-	Exchticket string `form:"exchticket" binding:"required"` // 银行服务流水号
+	AccountId   int    `form:"accountid" binding:"required"`  // 资金账户
+	Exchticket  string `form:"exchticket" binding:"required"` // 银行服务流水号
+	ChannelMode string `form:"channelmode"`                   // 渠道类型:ChillPay,PayerMax,AsiaPay
 }
 
 // GetAmtInByPaidUrl 获取银行待支付地址
@@ -56,7 +57,8 @@ type GetAmtInByPaidUrlReq struct {
 // @Security ApiKeyAuth
 // @Param    accountid  query    int    true "资金账户"
 // @Param    exchticket query    string true "银行服务流水号"
-// @Success  200        {object} string
+// @Param    channelmode query    string false "渠道类型:ChillPay,PayerMax,AsiaPay"
+// @Success  200        {object} models.GetAmtInByPaidUrlRsp
 // @Failure  500        {object} app.Response
 // @Router   /Bank/GetAmtInByPaidUrl [get]
 // @Tags     银行
@@ -71,8 +73,14 @@ func GetAmtInByPaidUrl(c *gin.Context) {
 		return
 	}
 
-	rec := models.GetAmtInByPaid(req.AccountId, req.Exchticket)
-	if rec == "" {
+	rec, err := models.GetAmtInByPaid(req.AccountId, req.Exchticket, req.ChannelMode)
+	if err != nil {
+		// 查询失败
+		logger.GetLogger().Error("GetAmtInByPaidUrl failed: 获取记录失败")
+		appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
+		return
+	}
+	if rec == nil {
 		// 查询失败
 		logger.GetLogger().Error("GetAmtInByPaidUrl failed: 获取记录失败")
 		appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)

+ 52 - 10
models/bank.go

@@ -96,24 +96,66 @@ func (r *Bankbranchnuminfo) GetDataByPage() (interface{}, error, int, int, int)
 	return sData, err, r.Page, r.PageSize, total
 }
 
-func GetAmtInByPaid(accountId int, exchticket string) string {
+type GetAmtInByPaidUrlRsp struct {
+	ChannelMode string `json:"channelmode"` // 渠道类型:ChillPay,PayerMax,AsiaPay
+	URL         string `json:"url"`         // 支付跳转地址
+	Params      string `json:"params"`      // 支付参数,只有 AsiaPay 渠道需要
+}
+
+func GetAmtInByPaid(accountId int, exchticket string, channelMode string) (rsp *GetAmtInByPaidUrlRsp, err error) {
 	engine := db.GetEngine()
+	var has bool
 
 	// 尝试 ChillPay
-	var rec Chillpayamtinrec
-	has, _ := engine.Where("accountid = ? and exch_seq = ? and deal_status = 2", accountId, exchticket).Get(&rec)
-	if has {
-		return rec.PAYMENTURL
+	if channelMode == "ChillPay" || channelMode == "" {
+		var rec Chillpayamtinrec
+		has, err = engine.Where("accountid = ? and exch_seq = ? and deal_status = 2", accountId, exchticket).Get(&rec)
+		if err != nil {
+			return
+		}
+		if has {
+			rsp = &GetAmtInByPaidUrlRsp{
+				ChannelMode: "ChillPay",
+				URL:         rec.PAYMENTURL,
+			}
+			return
+		}
 	}
 
 	// 尝试 PayerMax
-	var rec1 Payermaxamtinrec
-	has, _ = engine.Where("accountid = ? and exch_seq = ? and deal_status = 2", accountId, exchticket).Get(&rec1)
-	if has {
-		return rec1.REDIRECTURL
+	if channelMode == "PayerMax" || channelMode == "" {
+		var rec Payermaxamtinrec
+		has, err = engine.Where("accountid = ? and exch_seq = ? and deal_status = 2", accountId, exchticket).Get(&rec)
+		if err != nil {
+			return
+		}
+		if has {
+			rsp = &GetAmtInByPaidUrlRsp{
+				ChannelMode: "PayerMax",
+				URL:         rec.REDIRECTURL,
+			}
+			return
+		}
+	}
+
+	// 尝试 Asia Pay
+	if channelMode == "AsiaPay" || channelMode == "" {
+		var rec Asiapayamtinrec
+		has, err = engine.Where("accountid = ? and exch_seq = ? and deal_status = 2", accountId, exchticket).Get(&rec)
+		if err != nil {
+			return
+		}
+		if has {
+			rsp = &GetAmtInByPaidUrlRsp{
+				ChannelMode: "AsiaPay",
+				URL:         rec.REDIRECTURL,
+				Params:      rec.REDIRECTPARAMS,
+			}
+			return
+		}
 	}
 
-	return ""
+	return
 }
 
 func GetCusBankInfos() ([]Bankcusbankinfo, error) {

+ 28 - 0
models/ori.go

@@ -1125,6 +1125,34 @@ func (r *Payermaxamtinrec) TableName() string {
 	return "PAYERMAX_AMT_IN_REC"
 }
 
+// Asiapayamtinrec AsiaPay 入金记录表
+type Asiapayamtinrec struct {
+	ID             int64     `json:"id" xorm:"ID"`                         // 自增ID
+	REC_VERSION    int64     `json:"rec_version" xorm:"REC_VERSION"`       // 乐观锁
+	EXCH_NO        string    `json:"exch_no" xorm:"EXCH_NO"`               // 交易所编号
+	EXCH_DATE      string    `json:"exch_date" xorm:"EXCH_DATE"`           // 交易日
+	EXCH_SEQ       string    `json:"exch_seq" xorm:"EXCH_SEQ"`             // 交易所流水号
+	DEAL_STATUS    int32     `json:"deal_status" xorm:"DEAL_STATUS"`       // 入金状态 0-成功 1-失败 2-已发送 3-初始化
+	DEAL_DESC      string    `json:"deal_desc" xorm:"DEAL_DESC"`           // 状态描述
+	CREATED_AT     time.Time `json:"created_at" xorm:"CREATED_AT"`         // 创建时间
+	UPDATED_AT     time.Time `json:"updated_at" xorm:"UPDATED_AT"`         // 修改时间
+	ACCOUNTID      int64     `json:"accountid" xorm:"ACCOUNTID"`           // 账户ID
+	AMOUNT         float64   `json:"amount" xorm:"AMOUNT"`                 // 入金金额
+	ORDERREF       string    `json:"orderref" xorm:"ORDERREF"`             // 商户订单号
+	ORDERSTATUS    string    `json:"orderstatus" xorm:"ORDERSTATUS"`       // 渠道订单状态
+	REDIRECTURL    string    `json:"redirecturl" xorm:"REDIRECTURL"`       // 渠道支付地址
+	REDIRECTPARAMS string    `json:"redirectparams" xorm:"REDIRECTPARAMS"` // 渠道支付参数
+	SUCCESSCODE    string    `json:"successcode" xorm:"SUCCESSCODE"`       // 渠道支付成功码
+	ERRMSG         string    `json:"errmsg" xorm:"ERRMSG"`                 // 渠道支付错误信息
+	TXTIME         string    `json:"txtime" xorm:"TXTIME"`                 // 渠道支付时间
+	RESPONSEBODY   string    `json:"responsebody" xorm:"RESPONSEBODY"`     // 渠道回复信息,包括主动查询和结果推送
+}
+
+// TableName is ASIAPAY_AMT_IN_REC
+func (r *Asiapayamtinrec) TableName() string {
+	return "ASIAPAY_AMT_IN_REC"
+}
+
 // Bankcusbankinfo 托管银行信息表
 type Bankcusbankinfo struct {
 	CUSBANKID            string `json:"cusbankid" xorm:"CUSBANKID"`                   // 托管银行编号(对应清算中心TRAN_NO)