فهرست منبع

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

k.zhang 1 سال پیش
والد
کامیت
7367b8453a

+ 2 - 0
apis/shanghu/base.go

@@ -32,5 +32,7 @@ func InitShangHuRouter(engine *gin.RouterGroup) {
 		v1.POST("/client/pay/list", GetPayTransList)                        //交易列表
 		v1.POST("/verification/code", GetVerificationCode)                  //核销码
 		v1.POST("/merchant/sale/list", GetMerchantPayTransList)             //销售记录
+		v1.POST("/merchant/cancel", CancelNumber)                           //核销
+		v1.POST("/merchant/update/whxy", UpdateMerchantCardWXYZ)            //xyz                               //更新坐标
 	}
 }

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 31 - 2
apis/shanghu/client.trans.go


+ 111 - 3
apis/shanghu/merchant.card.go

@@ -9,6 +9,7 @@ import (
 	"duoduo/tools/app"
 	"encoding/base64"
 	"encoding/json"
+	"errors"
 	"fmt"
 	"github.com/gin-gonic/gin"
 	"github.com/shopspring/decimal"
@@ -33,9 +34,6 @@ func CreateMerchantCard(c *gin.Context) {
 		return
 	}
 
-	//"json: cannot unmarshal string into Go struct field CreateMerchantCardRequest.inventory of type int64"
-	//"json: cannot unmarshal bool into Go struct field CreateMerchantCardRequest.merchant_card_time of type string"
-	//"json: cannot unmarshal string into Go struct field CreateMerchantCardRequest.inventory of type int64"
 	sqlData.CardProjectData = string(jsStr)
 	sqlData.CardPrice = inData.CardPrice
 	sqlData.ActivityEndTime, err = tools.TimeToInt64(inData.ActivityEndTime, "2006-01-02")
@@ -73,6 +71,13 @@ func CreateMerchantCard(c *gin.Context) {
 	sqlData.UseRule = inData.UseRule
 	sqlData.MerchantCardName = inData.MerchantCardName
 
+	sqlData.CancelNumber, err = strconv.Atoi(inData.CancelNumber)
+	if err != nil {
+		app.Error(c, 400, err, err.Error())
+		return
+	}
+	sqlData.BackgroundImage = inData.BackgroundImage
+
 	_, err = sqlData.Create()
 	if err != nil {
 		app.Error(c, 500, err, err.Error())
@@ -445,3 +450,106 @@ func UpdateMerchantCard(c *gin.Context) {
 
 	app.OK(c, nil, app.Success)
 }
+
+func UpdateMerchantCardWXYZ(c *gin.Context) {
+	var inData models.UpdateMerchantCardWHXYRequest
+	var sqlData shanghu.MerchantCard
+	var whxy []models.WHXYStr
+
+	err := c.ShouldBindJSON(&inData)
+	if err != nil {
+		app.Error(c, 400, err, err.Error())
+		return
+	}
+
+	err = json.Unmarshal([]byte(inData.Whxy), &whxy)
+	if err != nil {
+		app.Error(c, 400, err, err.Error())
+		return
+	}
+	for i := 0; i < len(whxy); i++ {
+		if !whxy[i].Y.IsZero() {
+			sqlData.W = whxy[i].W
+			sqlData.X = whxy[i].X
+			sqlData.Y = whxy[i].Y
+			sqlData.H = whxy[i].H
+		}
+	}
+	sqlData.ID = inData.MerchantCardId
+
+	err = sqlData.UpdateMerchantWHXY()
+	if err != nil {
+		app.Error(c, 400, err, err.Error())
+		return
+	}
+
+	app.OK(c, nil, app.Success)
+}
+
+// 核销次数
+func CancelNumber(c *gin.Context) {
+	var inData models.CancelCardRequest
+	var sqlData shanghu.MerchantCard
+	var log shanghu.CancelLog
+	var qrMessage models.QRData
+	var clientPay shanghu.ClientPayTrans
+
+	err := c.ShouldBindJSON(&inData)
+	if err != nil {
+		app.Error(c, 400, err, err.Error())
+		return
+	}
+
+	err = json.Unmarshal([]byte(inData.QRMessage), &qrMessage)
+	if err != nil {
+		app.Error(c, 400, err, err.Error())
+		return
+	}
+
+	clientPay.MerchantCardID = qrMessage.MerchantId
+	clientPay.ClientOpenID = qrMessage.ClientOpenId
+	clientInfo, err := clientPay.GetPayTransByOpenid()
+	if err != nil {
+		app.Error(c, 400, err, err.Error())
+		return
+	}
+
+	if clientInfo.ID == 0 {
+		app.Error(c, 200, errors.New("用户未购买此卡"), "用户未购买此卡")
+		return
+	}
+
+	sqlData.ID = qrMessage.MerchantId
+	merchantInfo, err := sqlData.GetMerchantCard()
+	if err != nil {
+		app.Error(c, 500, err, err.Error())
+		return
+	}
+
+	log.MerchantID = qrMessage.MerchantId
+	log.ClientOpenID = qrMessage.ClientOpenId
+	if log.GetNumber() >= merchantInfo.CancelNumber {
+		app.Error(c, 200, errors.New("卡已使用完,请重新购买"), "卡已使用完,请重新购买")
+		return
+	}
+
+	if merchantInfo.MerchantOpenID != inData.MerchantOpenId {
+		app.Error(c, 200, errors.New("核销商家与发卡商家不一致"), "核销商家与发卡商家不一致")
+		return
+	}
+
+	log.MerchantID = qrMessage.MerchantId
+	log.ClientOpenID = qrMessage.ClientOpenId
+	log.MerchantOpenID = inData.MerchantOpenId
+	log.CreatedAt = time.Now()
+	log.UpdatedAt = time.Now()
+
+	_, err = log.Create()
+	if err != nil {
+		app.Error(c, 500, err, err.Error())
+		return
+	}
+
+	app.OK(c, nil, "核销成功")
+
+}

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

@@ -18,6 +18,8 @@ type CreateMerchantCardRequest struct {
 	UseRule           string  `json:"use_rule"`            // 使用规则
 	Picture           string  `json:"picture"`             // 图片
 	RebateRate        string  `json:"rebate_rate"`         // 佣金比例
+	CancelNumber      string  `json:"cancel_number"`       //核销次数
+	BackgroundImage   string  `json:"background_image"`    //背景图
 }
 
 type GetMerchantCardRequest struct {
@@ -123,3 +125,19 @@ type UpdateMerchantCardRequest struct {
 	UseRule           string `json:"use_rule"`            // 使用规则
 	Picture           string `json:"picture"`             // 图片
 }
+
+type UpdateMerchantCardWHXYRequest struct {
+	Whxy           string `json:"whxy"` //坐标
+	MerchantCardId int64  `json:"merchant_card_id"`
+}
+
+type WHXYStr struct {
+	Type     string          `json:"type"`
+	URL      string          `json:"url"`
+	Y        decimal.Decimal `json:"y,omitempty"`
+	X        decimal.Decimal `json:"x,omitempty"`
+	W        decimal.Decimal `json:"w,omitempty"`
+	H        decimal.Decimal `json:"h,omitempty"`
+	Rotate   int             `json:"rotate,omitempty"`
+	SourceID any             `json:"sourceId,omitempty"`
+}

+ 6 - 0
apis/shanghu/models/client.trans.go

@@ -24,6 +24,12 @@ type VerificationCodeRequest struct {
 	TransId int64 `json:"trans_id"`
 }
 
+type QRData struct {
+	MerchantId   int64  `json:"merchant_id"`
+	Key          string `json:"key"`
+	ClientOpenId string `json:"client_open_id"`
+}
+
 type VerificationCodeReply struct {
 	QR string `json:"qr"`
 }

+ 5 - 0
apis/shanghu/models/merchant.go

@@ -42,3 +42,8 @@ type UpdateMerchantRequest struct {
 	BusinessLicenseUrl string `json:"business_license_url"` // 营业执照 url
 	DoorHeaderUrl      string `json:"door_header_url"`      // 门头照 url
 }
+
+type CancelCardRequest struct {
+	MerchantOpenId string `json:"merchant_open_id"`
+	QRMessage      string `json:"qr_message"`
+}

+ 1 - 0
go.mod

@@ -36,6 +36,7 @@ require (
 	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/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e // 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

@@ -159,6 +159,8 @@ github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFR
 github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
 github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4=
 github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
+github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e h1:MRM5ITcdelLK2j1vwZ3Je0FKVCfqOLp5zO6trqMLYs0=
+github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e/go.mod h1:XV66xRDqSt+GTGFMVlhk3ULuV0y9ZmzeVGR4mloJI3M=
 github.com/smartystreets/assertions v1.2.0 h1:42S6lae5dvLc7BrLu/0ugRtcFVjoJNMC/N3yZFZkDFs=
 github.com/smartystreets/assertions v1.2.0/go.mod h1:tcbTF8ujkAEcZ8TElKY+i30BzYlVhC/LOxJk7iOWnoo=
 github.com/smartystreets/go-aws-auth v0.0.0-20180515143844-0c1422d1fdb9/go.mod h1:SnhjPscd9TpLiy1LpzGSKh3bXCfxxXuqd9xmQJy3slM=

+ 43 - 0
models/shanghu/cancel_log.go

@@ -0,0 +1,43 @@
+package shanghu
+
+import (
+	orm "duoduo/database"
+	"time"
+)
+
+type CancelLog struct {
+	ID             int64     `gorm:"column:id;type:bigint(20)" 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"`
+	MerchantID     int64     `gorm:"column:merchant_id;type:bigint(20)" json:"merchant_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 *CancelLog) TableName() string {
+	return "cancel_log"
+}
+
+func (u *CancelLog) Create() (CancelLog, error) {
+	var doc CancelLog
+	var err error
+
+	doc = *u
+	err = orm.ShMysql.Table(u.TableName()).Create(&doc).Error
+	if err != nil {
+		return doc, err
+	}
+
+	return doc, nil
+}
+
+func (u *CancelLog) GetNumber() int {
+	var count int
+
+	tableCount := orm.ShMysql.Table(u.TableName()).Where("client_open_id = ? and merchant_id = ?", u.ClientOpenID, u.MerchantID)
+	tableCount.Count(&count)
+	return count
+}

+ 41 - 19
models/shanghu/merchant_card.go

@@ -3,28 +3,35 @@ package shanghu
 import (
 	orm "duoduo/database"
 	"duoduo/tools"
+	"github.com/shopspring/decimal"
 	"time"
 )
 
 type MerchantCard struct {
-	ID                int64     `gorm:"column:id;type:bigint(20);primary_key;AUTO_INCREMENT" json:"id"`
-	MerchantCardName  string    `gorm:"column:merchant_card_name;type:varchar(255)" json:"merchant_card_name"`      // 商户卡名称
-	MerchantOpenID    string    `gorm:"column:merchant_open_id;type:varchar(255);NOT NULL" json:"merchant_open_id"` // openid
-	CardProjectData   string    `gorm:"column:card_project_data;type:json" json:"card_project_data"`                // 项目
-	CardPrice         string    `gorm:"column:card_price;type:decimal(10,2)" json:"card_price"`                     // 单价
-	ActivityEndTime   int64     `gorm:"column:activity_end_time;type:bigint(20)" json:"activity_end_time"`          // 活动结束时间
-	ActivityStartTime int64     `gorm:"column:activity_start_time;type:bigint(20)" json:"activity_start_time"`      // 活动开始时间
-	MerchantCardTime  int64     `gorm:"column:merchant_card_time;type:bigint(20)" json:"merchant_card_time"`        // 商户卡有效期
-	Inventory         int64     `gorm:"column:inventory;type:bigint(20)" json:"inventory"`                          // 库存数量
-	QuotaNum          int64     `gorm:"column:quota_num;type:int(11)" json:"quota_num"`                             // 限购数量
-	UseRule           string    `gorm:"column:use_rule;type:varchar(255)" json:"use_rule"`                          // 使用规则
-	Picture           string    `gorm:"column:picture;type:varchar(255)" json:"picture"`                            // 图片
-	RebateRate        int64     `gorm:"column:rebate_rate;type:int(11)" json:"rebate_rate"`                         // 佣金比例
-	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"`                       // 创建时间
-	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"`          // 删除时间
+	ID                int64           `gorm:"column:id;type:bigint(20);primary_key;AUTO_INCREMENT" json:"id"`
+	MerchantCardName  string          `gorm:"column:merchant_card_name;type:varchar(255)" json:"merchant_card_name"`      // 商户卡名称
+	MerchantOpenID    string          `gorm:"column:merchant_open_id;type:varchar(255);NOT NULL" json:"merchant_open_id"` // openid
+	CardProjectData   string          `gorm:"column:card_project_data;type:json" json:"card_project_data"`                // 项目
+	CardPrice         string          `gorm:"column:card_price;type:decimal(10,2)" json:"card_price"`                     // 单价
+	ActivityEndTime   int64           `gorm:"column:activity_end_time;type:bigint(20)" json:"activity_end_time"`          // 活动结束时间
+	ActivityStartTime int64           `gorm:"column:activity_start_time;type:bigint(20)" json:"activity_start_time"`      // 活动开始时间
+	MerchantCardTime  int64           `gorm:"column:merchant_card_time;type:bigint(20)" json:"merchant_card_time"`        // 商户卡有效期
+	Inventory         int64           `gorm:"column:inventory;type:bigint(20)" json:"inventory"`                          // 库存数量
+	QuotaNum          int64           `gorm:"column:quota_num;type:int(11)" json:"quota_num"`                             // 限购数量
+	UseRule           string          `gorm:"column:use_rule;type:varchar(255)" json:"use_rule"`                          // 使用规则
+	Picture           string          `gorm:"column:picture;type:varchar(255)" json:"picture"`                            // 图片
+	RebateRate        int64           `gorm:"column:rebate_rate;type:int(11)" json:"rebate_rate"`                         // 佣金比例
+	CancelNumber      int             `gorm:"column:cancel_number;type:int(11)" json:"cancel_number"`                     //
+	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"`                       // 创建时间
+	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"`          // 删除时间
+	BackgroundImage   string          `gorm:"column:background_image;type:varchar(255)" json:"background_image"`          //背景图
+	W                 decimal.Decimal `gorm:"column:w;type:decimal(16,2);default:null" json:"w"`                          // w
+	H                 decimal.Decimal `gorm:"column:h;type:decimal(16,2);default:null" json:"h"`                          // h
+	X                 decimal.Decimal `gorm:"column:x;type:decimal(16,2);default:null" json:"x"`                          // x
+	Y                 decimal.Decimal `gorm:"column:y;type:decimal(16,2);default:null" json:"y"`                          // y
 }
 
 func (m *MerchantCard) TableName() string {
@@ -129,7 +136,22 @@ func (m *MerchantCard) UpdateMerchantCard() error {
 			"quota_num":           m.QuotaNum,
 			"use_rule":            m.UseRule,
 			"picture":             m.Picture,
-			"update_time":         tools.GetCurrntTimeStr()}).Error; err != nil {
+			"updated_at":          tools.GetCurrntTimeStr()}).Error; err != nil {
+		return err
+	}
+
+	return nil
+}
+
+func (m *MerchantCard) UpdateMerchantWHXY() error {
+
+	if err := orm.ShMysql.Table(m.TableName()).Model(&m).Where("id = ? ", m.ID).Updates(
+		map[string]interface{}{
+			"w":          m.W,
+			"h":          m.H,
+			"x":          m.X,
+			"y":          m.Y,
+			"updated_at": tools.GetCurrntTimeStr()}).Error; err != nil {
 		return err
 	}
 

+ 13 - 0
models/shanghu/pay.go

@@ -52,6 +52,19 @@ func (m *ClientPayTrans) GetPayTransByOpenid() (ClientPayTrans, error) {
 	return doc, nil
 }
 
+func (m *ClientPayTrans) GetPayTransById() (ClientPayTrans, error) {
+	var doc ClientPayTrans
+
+	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
+}
+
 func (m *ClientPayTrans) GetPayTransByTradeNo() (ClientPayTrans, error) {
 	var doc ClientPayTrans