k.zhang před 1 rokem
rodič
revize
25369bc92e

binární
apiclient_cert.p12


+ 1 - 0
apis/shanghu/base.go

@@ -37,5 +37,6 @@ func InitShangHuRouter(engine *gin.RouterGroup) {
 		v1.POST("/merchant/user/code", MerchantUserCode)                    //
 		v1.POST("/account/amount", GetAccountAmount)                        //获取金额
 		v1.POST("/cash/out", PayCashOut)                                    //提现
+		v1.POST("/cash.out/list", CashOutList)                              //提现列表
 	}
 }

+ 60 - 0
apis/shanghu/cash.out.go

@@ -0,0 +1,60 @@
+package shanghu
+
+import (
+	"duoduo/apis/shanghu/models"
+	"duoduo/models/shanghu"
+	"duoduo/tools/app"
+	"fmt"
+	"github.com/gin-gonic/gin"
+	"time"
+)
+
+func CashOutList(c *gin.Context) {
+	var inData models.CashOutListRequest
+	var sqlData shanghu.CashOut
+	var outData []models.CashOutListReply
+
+	err := c.ShouldBindJSON(&inData)
+	if err != nil {
+		app.Error(c, 400, err, err.Error())
+		return
+	}
+
+	var pageSize = 10
+	var pageIndex = 1
+
+	if inData.PageSize != 0 {
+		pageSize = inData.PageSize
+	}
+	if inData.PageIndex != 0 {
+		pageIndex = inData.PageIndex
+	}
+	fmt.Println(inData.OpenId)
+	sqlData.OpenID = inData.OpenId
+	sqlData.AppID = inData.Appid
+
+	cashOutList, count, err := sqlData.GetCashOutList(pageSize, pageIndex)
+	if err != nil {
+		app.Error(c, 500, err, err.Error())
+		return
+	}
+	for i := 0; i < len(cashOutList); i++ {
+		var cashOut models.CashOutListReply
+		cashOut.Amount = cashOutList[i].Amount.Sub(cashOutList[i].Fee)
+		cashOut.TotalAmount = cashOutList[i].Amount
+		cashOut.CreateAt = cashOutList[i].CreatedAt.Format(time.DateTime)
+		cashOut.Fee = cashOutList[i].Fee
+		if cashOutList[i].Status == 1 {
+			cashOut.Des = "提现中"
+		} else if cashOutList[i].Status == 2 {
+			cashOut.Des = "提现失败"
+		} else if cashOutList[i].Status == 3 {
+			cashOut.Des = "提现成功"
+		} else if cashOutList[i].Status == 4 {
+			cashOut.Des = "提现完成"
+		}
+		outData = append(outData, cashOut)
+	}
+	app.PageOK(c, outData, count, pageIndex, pageSize, app.Success)
+
+}

+ 18 - 0
apis/shanghu/models/cash.out.go

@@ -0,0 +1,18 @@
+package models
+
+import "github.com/shopspring/decimal"
+
+type CashOutListRequest struct {
+	OpenId    string `json:"open_id"`
+	Appid     string `json:"appid"`
+	PageSize  int    `json:"page_size"`
+	PageIndex int    `json:"page_index"`
+}
+
+type CashOutListReply struct {
+	TotalAmount decimal.Decimal `json:"total_amount"` //总金额
+	CreateAt    string          `json:"create_at"`    //创建时间
+	Fee         decimal.Decimal `json:"fee"`          //手续费
+	Amount      decimal.Decimal `json:"amount"`       //实际到账金额
+	Des         string          `json:"des"`
+}

+ 15 - 0
models/shanghu/cash.out.go

@@ -127,3 +127,18 @@ func (m *CashOut) GetCashOutByStatus() (CashOut, error) {
 	return doc, nil
 
 }
+
+// list 接口使用
+func (m *CashOut) GetCashOutList(pageSize int, pageIndex int) ([]CashOut, int, error) {
+	var doc []CashOut
+
+	table := orm.ShMysql.Table(m.TableName())
+
+	table = table.Where("open_id = ? and app_id = ? ", m.OpenID, m.AppID)
+	var count int
+	if err := table.Select("*").Order("id desc").Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&doc).Error; err != nil {
+		return nil, 0, err
+	}
+	table.Count(&count)
+	return doc, count, nil
+}