k.zhang 1 year ago
parent
commit
d24e21700a
6 changed files with 74 additions and 1 deletions
  1. 19 1
      apis/shanghu/merchant.card.go
  2. 25 0
      apis/shanghu/models/card.go
  3. 1 0
      go.mod
  4. 2 0
      go.sum
  5. 15 0
      models/shanghu/pay.go
  6. 12 0
      report/shang.hu.ka.go

+ 19 - 1
apis/shanghu/merchant.card.go

@@ -8,6 +8,7 @@ import (
 	"encoding/json"
 	"fmt"
 	"github.com/gin-gonic/gin"
+	"github.com/shopspring/decimal"
 	"strconv"
 	"time"
 )
@@ -165,6 +166,7 @@ func MerchantCardList(c *gin.Context) {
 func MerchantClientCardList(c *gin.Context) {
 	var inData models.MerchantCardListRequest
 	var sqlData shanghu.MerchantCard
+	var outData []models.MerchantCardListReply
 
 	err := c.ShouldBindJSON(&inData)
 	if err != nil {
@@ -187,7 +189,23 @@ func MerchantClientCardList(c *gin.Context) {
 		app.Error(c, 500, err, err.Error())
 		return
 	}
-	app.PageOK(c, merchantCard, count, pageIndex, pageSize, app.Success)
+
+	for i := 0; i < len(merchantCard); i++ {
+		var reply models.MerchantCardListReply
+		reply.RebateRate = merchantCard[i].RebateRate
+		reply.ID = merchantCard[i].ID
+		reply.QuotaNum = merchantCard[i].QuotaNum
+		reply.MerchantCardName = merchantCard[i].MerchantCardName
+		reply.CardPrice = merchantCard[i].CardPrice
+		priceDec, err := decimal.NewFromString(merchantCard[i].CardPrice)
+		if err != nil {
+			app.Error(c, 500, err, err.Error())
+			return
+		}
+		reply.RebateAmount = priceDec.Mul(decimal.NewFromInt(merchantCard[i].RebateRate).Div(decimal.NewFromInt(100))).String()
+		outData = append(outData, reply)
+	}
+	app.PageOK(c, outData, count, pageIndex, pageSize, app.Success)
 
 }
 

+ 25 - 0
apis/shanghu/models/card.go

@@ -1,5 +1,7 @@
 package models
 
+import "time"
+
 type CreateMerchantCardRequest struct {
 	MerchantCardName  string  `json:"merchant_card_name"`  // 商户卡名称
 	MerchantOpenID    string  `json:"open_id"`             // openid
@@ -41,6 +43,29 @@ type MerchantCardListRequest struct {
 	TypeList  int    `json:"type_list"` //1-未开始 2-进行中 3-已结束
 }
 
+type MerchantCardListReply struct {
+	ID                int64     `json:"id"`
+	MerchantCardName  string    `json:"merchant_card_name"`  // 商户卡名称
+	MerchantOpenID    string    `json:"merchant_open_id"`    // openid
+	CardProjectData   string    `json:"card_project_data"`   // 项目
+	CardPrice         string    `json:"card_price"`          // 单价
+	ActivityEndTime   int64     `json:"activity_end_time"`   // 活动结束时间
+	ActivityStartTime int64     `json:"activity_start_time"` // 活动开始时间
+	MerchantCardTime  int64     `json:"merchant_card_time"`  // 商户卡有效期
+	Inventory         int64     `json:"inventory"`           // 库存数量
+	QuotaNum          int64     `json:"quota_num"`           // 限购数量
+	UseRule           string    `json:"use_rule"`            // 使用规则
+	Picture           string    `json:"picture"`             // 图片
+	RebateRate        int64     `json:"rebate_rate"`         // 佣金比例
+	CreateBy          int64     `json:"create_by"`           // 创建者
+	UpdateBy          int64     `json:"update_by"`           // 更新者
+	CreatedAt         time.Time `json:"created_at"`          // 创建时间
+	UpdatedAt         time.Time `json:"updated_at"`          // 最后更新时间
+	DeletedAt         time.Time `json:"deleted_at"`
+	RebateAmount      string    `json:"rebate_amount"` // 佣金
+
+}
+
 type UpdateMerchantCardRequest struct {
 	ID                int64  `json:"id"`
 	ActivityEndTime   int64  `json:"activity_end_time"`   // 活动结束时间

+ 1 - 0
go.mod

@@ -35,6 +35,7 @@ require (
 	github.com/modern-go/reflect2 v1.0.2 // indirect
 	github.com/pelletier/go-toml/v2 v2.0.5 // indirect
 	github.com/pkg/errors v0.9.1 // indirect
+	github.com/robfig/cron v1.2.0 // indirect
 	github.com/smartystreets/goconvey v1.7.2 // indirect
 	github.com/ugorji/go/codec v1.2.7 // indirect
 	golang.org/x/crypto v0.14.0 // indirect

+ 2 - 0
go.sum

@@ -149,6 +149,8 @@ github.com/qiniu/go-sdk/v7 v7.11.1 h1:/LZ9rvFS4p6SnszhGv11FNB1+n4OZvBCwFg7opH5Ov
 github.com/qiniu/go-sdk/v7 v7.11.1/go.mod h1:btsaOc8CA3hdVloULfFdDgDc+g4f3TDZEFsDY0BLE+w=
 github.com/qiniu/x v1.10.5/go.mod h1:03Ni9tj+N2h2aKnAz+6N0Xfl8FwMEDRC2PAlxekASDs=
 github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
+github.com/robfig/cron v1.2.0 h1:ZjScXvvxeQ63Dbyxy76Fj3AT3Ut0aKsyd2/tl3DTMuQ=
+github.com/robfig/cron v1.2.0/go.mod h1:JGuDeoQd7Z6yL4zQhZ3OPEVHB7fL6Ka6skscFHfmt2k=
 github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
 github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUAtL9R8=
 github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE=

+ 15 - 0
models/shanghu/pay.go

@@ -16,6 +16,8 @@ type ClientPayTrans struct {
 	Amount         decimal.Decimal `gorm:"column:amount;type:decimal(10,2)" json:"amount"`                    // 交易金额
 	ThirdTradeNo   string          `gorm:"column:third_trade_no;type:varchar(255)" json:"third_trade_no"`     // 微信交易id
 	PayTime        time.Time       `gorm:"column:pay_time;type:datetime(3);default:null" json:"pay_time"`     // 支付时间
+	InvitationCode string          `gorm:"column:invitation_code;type:varchar(25)" json:"invitation_code"`    // 邀请码
+	AccountStatus  int             `gorm:"column:account_status;type:int(11)" json:"account_status"`          // 分账状态 99-分账成功 2-分账失败 1-未分账
 	CreateBy       int64           `gorm:"column:create_by;type:bigint(20)" json:"create_by"`                 // 创建者
 	UpdateBy       int64           `gorm:"column:update_by;type:bigint(20)" json:"update_by"`                 // 更新者
 	CreatedAt      time.Time       `gorm:"column:created_at;type:datetime(3)" json:"created_at"`              // 创建时间
@@ -74,3 +76,16 @@ func (m *ClientPayTrans) UpdatePayTransByTradeNo() error {
 	}
 	return nil
 }
+
+func (m *ClientPayTrans) GetTransByAccount() (ClientPayTrans, error) {
+	var doc ClientPayTrans
+
+	table := orm.ShMysql.Table(m.TableName())
+	table = table.Where("account_status = ?  ", m.AccountStatus)
+
+	if err := table.Select("*").First(&doc).Error; err != nil {
+		return doc, err
+	}
+
+	return doc, nil
+}

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

@@ -0,0 +1,12 @@
+package report
+
+// C端分账
+// 分账逻辑:
+// 1.获取待分账、分账失败的数据
+// 2.根据商户卡id 将 90%分给商家,剩下的 10% 分给用户
+// 3.一条一条的处理,防止处理数据太多导致重复重复分账 查到数据里面修改成分账中
+
+func ClientAccount() {
+	//
+	//var account m
+}