Compare commits

..

No commits in common. "5a60a92f4b983fdecb578e50af81c6416af26ac1" and "95a050d64e4db49add58b2252e4ebd47da199ef9" have entirely different histories.

22 changed files with 75 additions and 565 deletions

View File

@ -1,28 +0,0 @@
GOHOSTOS:=$(shell go env GOHOSTOS)
GOPATH:=$(shell go env GOPATH)
VERSION=$(shell git describe --tags --always)
ifeq ($(GOHOSTOS), windows)
#the `find.exe` is different from `find` in bash/shell.
#to see https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/find.
#changed to use git-bash.exe to run find cli or other cli friendly, caused of every developer has a Git.
#Git_Bash= $(subst cmd\,bin\bash.exe,$(dir $(shell where git)))
Git_Bash=$(subst \,/,$(subst cmd\,bin\bash.exe,$(dir $(shell where git))))
INTERNAL_PROTO_FILES=$(shell $(Git_Bash) -c "find internal -name *.proto")
API_PROTO_FILES=$(shell $(Git_Bash) -c "find api -name *.proto")
else
INTERNAL_PROTO_FILES=$(shell find internal -name *.proto)
API_PROTO_FILES=$(shell find api -name *.proto)
endif
.PHONY: build
build:
sh build/shell/build.sh
.PHONY: api
api:
sh build/shell/build.sh & build/bin/snow -a api

View File

@ -21,9 +21,6 @@ const (
//未登录 //未登录
NotLogin = 1000 NotLogin = 1000
// 商户
MerchantNotFound = 1100
) )
var MsgEN = map[int]string{ var MsgEN = map[int]string{
@ -41,8 +38,6 @@ var MsgZH = map[int]string{
NotFound: "数据不存在", NotFound: "数据不存在",
NotAuth: "未经授权", NotAuth: "未经授权",
NotLogin: "未登录", NotLogin: "未登录",
MerchantNotFound: "商户不存在",
} }
var MsgMap map[string]map[int]string = map[string]map[int]string{"en": MsgZH} var MsgMap map[string]map[int]string = map[string]map[int]string{"en": MsgZH}

View File

@ -37,7 +37,3 @@ func (m *MerchantRepo) MerchantDelete(merchant *merchantmodel.Merchant, conn bui
func (m *MerchantRepo) MerchantUpdate(merchant *merchantmodel.Merchant, conn builder.Cond, columns ...string) (int64, error) { func (m *MerchantRepo) MerchantUpdate(merchant *merchantmodel.Merchant, conn builder.Cond, columns ...string) (int64, error) {
return m.repo.Where(conn).MustCols(columns...).Update(merchant) return m.repo.Where(conn).MustCols(columns...).Update(merchant)
} }
func (m *MerchantRepo) MerchantDetail(merchant *merchantmodel.Merchant, conn builder.Cond) (bool, error) {
return m.repo.Where(conn).Get(merchant)
}

View File

@ -33,7 +33,7 @@ func (m *PayChannelRepo) PayChannelDelete(merchant *paychannelmodel.PayChannel,
return m.repo.Where(conn).Delete(merchant) return m.repo.Where(conn).Delete(merchant)
} }
// columns 参数为要更新的字段,即使为空 // columns 参数为要更新的字段
func (m *PayChannelRepo) PayChannelUpdate(merchant *paychannelmodel.PayChannel, conn builder.Cond, columns ...string) (int64, error) { func (m *PayChannelRepo) PayChannelUpdate(merchant *paychannelmodel.PayChannel, conn builder.Cond, columns ...string) (int64, error) {
return m.repo.Where(conn).MustCols(columns...).Update(merchant) return m.repo.Where(conn).MustCols(columns...).Update(merchant)
} }

View File

@ -1,75 +0,0 @@
package backend
import (
"PaymentCenter/app/constants/errorcode"
"PaymentCenter/app/http/controllers"
"PaymentCenter/app/http/entities"
"PaymentCenter/app/http/entities/backend"
"PaymentCenter/app/models/appmodel"
"PaymentCenter/app/services"
"PaymentCenter/app/utils/sm2"
"github.com/ahmetb/go-linq/v3"
"github.com/gin-gonic/gin"
)
func AppList(c *gin.Context) {
req, _ := controllers.GetRequest(c).(*backend.AppListRequest)
req.SetDefault()
payChannelList, total, code := services.AppList(*req)
result := make([]backend.AppResponse, 0, len(payChannelList))
linq.From(payChannelList).SelectT(func(in appmodel.App) (out backend.AppResponse) {
out.ResponseFromDb(in)
return
}).ToSlice(&result)
data := entities.PageRsp{
Total: total,
Data: result,
}
controllers.HandCodeRes(c, data, code)
}
func AppCreate(c *gin.Context) {
req, _ := controllers.GetRequest(c).(*backend.AppCreateRequest)
payChannel := req.RequestToDb()
code := services.AppCreate(&payChannel)
data := backend.AppResponse{}
data.ResponseFromDb(payChannel)
controllers.HandCodeRes(c, data, code)
}
func AppUpdate(c *gin.Context) {
req, _ := controllers.GetRequest(c).(*backend.AppUpdateRequest)
payChannel := req.RequestToDb()
code := services.AppUpdate(&payChannel)
data := backend.AppResponse{}
data.ResponseFromDb(payChannel)
controllers.HandCodeRes(c, data, code)
}
func AppDelete(c *gin.Context) {
req, _ := controllers.GetRequest(c).(*entities.IdRequest)
code := services.AppDelete(*req)
controllers.HandCodeRes(c, nil, code)
}
func GenerateDecrypt(c *gin.Context) {
req, _ := controllers.GetRequest(c).(*backend.GenerateDecryptKeyRequest)
var publicKey, privateKey string
var err error
switch req.KeyType {
default:
publicKey, privateKey, err = sm2.GenerateSM2Key()
if err != nil {
controllers.Error(c, errorcode.SystemError, err.Error())
return
}
}
controllers.HandCodeRes(c, map[string]string{
"publicKey": publicKey,
"privateKey": privateKey,
}, errorcode.Success)
}

View File

@ -1,63 +0,0 @@
package backend
import (
"PaymentCenter/app/constants/errorcode"
"PaymentCenter/app/http/controllers"
"PaymentCenter/app/http/entities"
"PaymentCenter/app/http/entities/backend"
"PaymentCenter/app/models/paychannelmodel"
"PaymentCenter/app/services"
"github.com/ahmetb/go-linq/v3"
"github.com/gin-gonic/gin"
)
func PayChannelList(c *gin.Context) {
req, _ := controllers.GetRequest(c).(*backend.PayChannelListRequest)
req.SetDefault()
payChannelList, total, code := services.PayChannelList(*req)
result := make([]backend.PayChannelResponse, 0, len(payChannelList))
linq.From(payChannelList).SelectT(func(in paychannelmodel.PayChannel) (out backend.PayChannelResponse) {
out.ResponseFromDb(in)
return
}).ToSlice(&result)
data := entities.PageRsp{
Total: total,
Data: result,
}
controllers.HandCodeRes(c, data, code)
}
func PayChannelCreate(c *gin.Context) {
req, _ := controllers.GetRequest(c).(*backend.PayChannelCreateRequest)
payChannel, err := req.RequestToDb()
if err != nil {
controllers.Error(c, errorcode.ParamError, err.Error())
return
}
code := services.PayChannelCreate(&payChannel)
data := backend.PayChannelResponse{}
data.ResponseFromDb(payChannel)
controllers.HandCodeRes(c, data, code)
}
func PayChannelUpdate(c *gin.Context) {
req, _ := controllers.GetRequest(c).(*backend.PayChannelUpdateRequest)
payChannel, err := req.RequestToDb()
if err != nil {
controllers.Error(c, errorcode.ParamError, err.Error())
return
}
code := services.PayChannelUpdate(&payChannel)
data := backend.PayChannelResponse{}
data.ResponseFromDb(payChannel)
controllers.HandCodeRes(c, data, code)
}
func PayChannelDelete(c *gin.Context) {
req, _ := controllers.GetRequest(c).(*entities.IdRequest)
code := services.PayChannelDelete(*req)
controllers.HandCodeRes(c, nil, code)
}

View File

@ -26,11 +26,7 @@ import (
/** /**
* 成功时返回 * 成功时返回
*/ */
func Success(c *gin.Context, data interface{}, messageSlice ...string) { func Success(c *gin.Context, data interface{}, message string) {
var message string
if len(messageSlice) > 0 {
message = messageSlice[0]
}
if message == "" { if message == "" {
message = errorcode.GetMsg(errorcode.Success, c.GetHeader("local")) message = errorcode.GetMsg(errorcode.Success, c.GetHeader("local"))
} }

View File

@ -1,10 +0,0 @@
package front
import (
"PaymentCenter/app/http/controllers"
"github.com/gin-gonic/gin"
)
func HelloHandler(c *gin.Context) {
controllers.Success(c, "aaaa")
}

View File

@ -0,0 +1,12 @@
package domains
type Filter struct {
Page int `json:"page"`
PageSize int `json:"page_size"`
}
type ProductFilter struct {
Page int `json:"page" form:"page"`
PageSize int `json:"page_size" form:"page_size"`
ProductName string `json:"product_name" form:"product_name"`
}

View File

@ -0,0 +1,23 @@
package domains
import "time"
type Product struct {
Id int
ProductName string
ProductType int
PacketRule int
ProductKind int
Amount string
CouponType int
IsSuperposition int
TemplateId int
Status int
IsNeedBill int
CreateTime time.Time
SupplierProductId int64
SupplierProductName string
Creator string
UpdateTime time.Time
}

View File

@ -1,101 +0,0 @@
package backend
import (
"PaymentCenter/app/http/entities"
"PaymentCenter/app/models/appmodel"
)
type AppListRequest struct {
MerchantId int64 `json:"merchant_id"`
entities.PageRequest
}
type AppResponse struct {
Id int64 `json:"id"`
MerchantId int64 `json:"merchant_id"`
AppName string `json:"app_name"`
AppRemark string `json:"app_remark"`
Status int `json:"status"`
KeyType int `json:"key_type"`
PublicKey string `json:"public_key"`
PrivateKey string `json:"private_key"`
MerchantPublicKey string `json:"merchant_public_key"`
CreateTime string `json:"create_time"`
WhiteIp string `json:"white_ip"`
NotifyUrl string `json:"notify_url"`
}
func (a *AppResponse) ResponseFromDb(db appmodel.App) {
a.Id = db.Id
a.MerchantId = db.MerchantId
a.AppName = db.AppName
a.AppRemark = db.AppRemark
a.Status = db.Status
a.KeyType = db.KeyType
a.PublicKey = db.PublicKey
a.PrivateKey = db.PrivateKey
a.MerchantPublicKey = db.MerchantPublicKey
a.CreateTime = db.CreateTime.Format("2006-01-02 15:04:05")
a.WhiteIp = db.WhiteIp
a.NotifyUrl = db.NotifyUrl
}
type AppCreateRequest struct {
MerchantId int64 `json:"merchant_id" validate:"required" label:"商户ID"`
AppName string `json:"app_name" validate:"required" label:"应用名称"`
AppRemark string `json:"app_remark" label:"应用备注"`
Status int `json:"status" validate:"oneof=0 1 2" label:"应用状态"`
KeyType int `json:"key_type" validate:"required" label:"应用密钥类型"`
PublicKey string `json:"public_key" validate:"required" label:"应用公钥"`
PrivateKey string `json:"private_key" validate:"required" label:"应用私钥"`
MerchantPublicKey string `json:"merchant_public_key" label:"商户公钥"`
WhiteIp string `json:"white_ip"`
NotifyUrl string `json:"notify_url"`
}
func (a *AppCreateRequest) RequestToDb() (db appmodel.App) {
db.MerchantId = a.MerchantId
db.AppName = a.AppName
db.AppRemark = a.AppRemark
db.Status = a.Status
db.KeyType = a.KeyType
db.PublicKey = a.PublicKey
db.PrivateKey = a.PrivateKey
db.MerchantPublicKey = a.MerchantPublicKey
db.WhiteIp = a.WhiteIp
db.NotifyUrl = a.NotifyUrl
return
}
type AppUpdateRequest struct {
Id int64 `json:"id" validate:"required" label:"应用ID"`
MerchantId int64 `json:"merchant_id" validate:"required" label:"商户ID"`
AppName string `json:"app_name" validate:"required" label:"应用名称"`
AppRemark string `json:"app_remark" label:"应用备注"`
Status int `json:"status" validate:"oneof=0 1 2" label:"应用状态"`
KeyType int `json:"key_type" validate:"required" label:"应用密钥类型"`
PublicKey string `json:"public_key" validate:"required" label:"应用公钥"`
PrivateKey string `json:"private_key" validate:"required" label:"应用私钥"`
MerchantPublicKey string `json:"merchant_public_key" label:"商户公钥"`
WhiteIp string `json:"white_ip"`
NotifyUrl string `json:"notify_url"`
}
func (a *AppUpdateRequest) RequestToDb() (db appmodel.App) {
db.Id = a.Id
db.MerchantId = a.MerchantId
db.AppName = a.AppName
db.AppRemark = a.AppRemark
db.Status = a.Status
db.KeyType = a.KeyType
db.PublicKey = a.PublicKey
db.PrivateKey = a.PrivateKey
db.MerchantPublicKey = a.MerchantPublicKey
db.WhiteIp = a.WhiteIp
db.NotifyUrl = a.NotifyUrl
return
}
type GenerateDecryptKeyRequest struct {
KeyType int `json:"key_type" label:"密钥类型"`
}

View File

@ -2,7 +2,6 @@ package backend
import ( import (
"PaymentCenter/app/constants/common" "PaymentCenter/app/constants/common"
"PaymentCenter/app/http/entities"
"PaymentCenter/app/models/paychannelmodel" "PaymentCenter/app/models/paychannelmodel"
"PaymentCenter/app/utils" "PaymentCenter/app/utils"
"encoding/json" "encoding/json"
@ -10,15 +9,16 @@ import (
) )
type PayChannelResponse struct { type PayChannelResponse struct {
Id int64 `json:"id"` Id int64 `json:"id"`
PayName string `json:"pay_name"` PayName string `json:"pay_name"`
MerchantId int64 `json:"merchant_id"` MerchantId int64 `json:"merchant_id"`
ChannelType int `json:"channel_type"` ChannelType int `json:"channel_type"`
AppId string `json:"app_id"` WhiteIp string `json:"white_ip"`
ExpireTime string `json:"expire_time"` AppId string `json:"app_id"`
CreateTime string `json:"create_time"` ExpireTime string `json:"expire_time"`
AliPayPayChannel *AliPayPayChannel `json:"ali_pay_pay_channel,omitempty"` CreateTime string `json:"create_time"`
WechatPayChannel *WechatPayChannel `json:"wechat_pay_channel,omitempty"` AliPayPayChannel AliPayPayChannel `json:"ali_pay_pay_channel,omitempty"`
WechatPayChannel WechatPayChannel `json:"wechat_pay_channel,omitempty"`
} }
func (p *PayChannelResponse) ResponseFromDb(db paychannelmodel.PayChannel) { func (p *PayChannelResponse) ResponseFromDb(db paychannelmodel.PayChannel) {
@ -26,30 +26,32 @@ func (p *PayChannelResponse) ResponseFromDb(db paychannelmodel.PayChannel) {
p.PayName = db.PayName p.PayName = db.PayName
p.MerchantId = db.MerchantId p.MerchantId = db.MerchantId
p.ChannelType = db.ChannelType p.ChannelType = db.ChannelType
p.WhiteIp = db.WhiteIp
p.AppId = db.AppId p.AppId = db.AppId
p.ExpireTime = db.ExpireTime.Format("2006-01-02 15:04:05") p.ExpireTime = db.ExpireTime.Format("2006-01-02 15:04:05")
p.CreateTime = db.CreateTime.Format("2006-01-02 15:04:05") p.CreateTime = db.CreateTime.Format("2006-01-02 15:04:05")
switch p.ChannelType { switch p.ChannelType {
case common.PAY_CHANNEL_WECHAT_H5, common.PAY_CHANNEL_WECHAT_JSAPI, common.PAY_CHANNEL_WECHAT_NATIVE, common.PAY_CHANNEL_WECHAT_APP, common.PAY_CHANNEL_WECHAT_MINI: case common.PAY_CHANNEL_WECHAT_H5 | common.PAY_CHANNEL_WECHAT_JSAPI | common.PAY_CHANNEL_WECHAT_NATIVE | common.PAY_CHANNEL_WECHAT_APP | common.PAY_CHANNEL_WECHAT_MINI:
_ = json.Unmarshal([]byte(db.ExtJson), &p.WechatPayChannel) _ = json.Unmarshal([]byte(db.ExtJson), &p.WechatPayChannel)
case common.PAY_CHANNEL_ALIPAY_JSAPI, common.PAY_CHANNEL_ALIPAY_WEB, common.PAY_CHANNEL_ALIPAY_MINI: case common.PAY_CHANNEL_ALIPAY_JSAPI | common.PAY_CHANNEL_ALIPAY_WEB | common.PAY_CHANNEL_ALIPAY_MINI:
_ = json.Unmarshal([]byte(db.ExtJson), &p.AliPayPayChannel) _ = json.Unmarshal([]byte(db.ExtJson), &p.AliPayPayChannel)
} }
} }
type PayChannelCreateRequest struct { type PayChannelCreateRequest struct {
PayName string `json:"pay_name" validate:"required" label:"支付渠道名称"` PayName string `json:"pay_name"`
MerchantId int64 `json:"merchant_id" validate:"required" label:"商户ID"` MerchantId int64 `json:"merchant_id"`
ChannelType int `json:"channel_type" validate:"required" label:"支付渠道"` //支付渠道枚举,1微信JSAPI2微信H53微信app4微信Native5微信小程序6支付宝网页&移动应用7支付宝小程序8支付宝JSAPI ChannelType int `json:"channel_type"` //支付渠道枚举,1微信JSAPI2微信H53微信app4微信Native5微信小程序6支付宝网页&移动应用7支付宝小程序8支付宝JSAPI
AppId string `json:"app_id" validate:"required" label:"应用appId"` WhiteIp string `json:"white_ip"`
AppId string `json:"app_id"`
ExpireTime string `json:"expire_time"` ExpireTime string `json:"expire_time"`
AliPayPayChannel AliPayPayChannel `json:"ali_pay_pay_channel,omitempty"` AliPayPayChannel AliPayPayChannel `json:"ali_pay_pay_channel,omitempty"`
WechatPayChannel WechatPayChannel `json:"wechat_pay_channel,omitempty"` WechatPayChannel WechatPayChannel `json:"wechat_pay_channel,omitempty"`
} }
type WechatPayChannel struct { type WechatPayChannel struct {
MchId string `json:"mch_id"` //直连商户号 MchId int `json:"mch_id"` //直连商户号
MchCertificateSerialNumber string `json:"mch_certificate_serial_number"` //商户证书序列号 MchCertificateSerialNumber string `json:"mch_certificate_serial_number"` //商户证书序列号
MchAPIv3Key string `json:"mch_APIv3_key"` //商户APIv3密钥 MchAPIv3Key string `json:"mch_APIv3_key"` //商户APIv3密钥
PrivateKeyPath string `json:"private_key_path"` //商户私钥文件路径 PrivateKeyPath string `json:"private_key_path"` //商户私钥文件路径
@ -65,6 +67,7 @@ func (p *PayChannelCreateRequest) RequestToDb() (db paychannelmodel.PayChannel,
db.PayName = p.PayName db.PayName = p.PayName
db.MerchantId = p.MerchantId db.MerchantId = p.MerchantId
db.ChannelType = p.ChannelType db.ChannelType = p.ChannelType
db.WhiteIp = p.WhiteIp
db.AppId = p.AppId db.AppId = p.AppId
if p.ExpireTime != "" { if p.ExpireTime != "" {
db.ExpireTime, err = utils.StrToTimeShanghai(p.ExpireTime) db.ExpireTime, err = utils.StrToTimeShanghai(p.ExpireTime)
@ -73,49 +76,12 @@ func (p *PayChannelCreateRequest) RequestToDb() (db paychannelmodel.PayChannel,
} }
} }
switch p.ChannelType { switch p.ChannelType {
case common.PAY_CHANNEL_WECHAT_H5, common.PAY_CHANNEL_WECHAT_JSAPI, common.PAY_CHANNEL_WECHAT_NATIVE, common.PAY_CHANNEL_WECHAT_APP, common.PAY_CHANNEL_WECHAT_MINI: case common.PAY_CHANNEL_WECHAT_H5 | common.PAY_CHANNEL_WECHAT_JSAPI | common.PAY_CHANNEL_WECHAT_NATIVE | common.PAY_CHANNEL_WECHAT_APP | common.PAY_CHANNEL_WECHAT_MINI:
b, _ := json.Marshal(p.WechatPayChannel) b, _ := json.Marshal(p.WechatPayChannel)
db.ExtJson = string(b) db.ExtJson = string(b)
case common.PAY_CHANNEL_ALIPAY_JSAPI, common.PAY_CHANNEL_ALIPAY_WEB, common.PAY_CHANNEL_ALIPAY_MINI: case common.PAY_CHANNEL_ALIPAY_JSAPI | common.PAY_CHANNEL_ALIPAY_WEB | common.PAY_CHANNEL_ALIPAY_MINI:
b, _ := json.Marshal(p.AliPayPayChannel) b, _ := json.Marshal(p.AliPayPayChannel)
db.ExtJson = string(b) db.ExtJson = string(b)
default:
err = errors.New("支付渠道类型错误")
}
return
}
type PayChannelListRequest struct {
MerchantId int64 `json:"merchant_id"`
entities.PageRequest
}
type PayChannelUpdateRequest struct {
Id int64 `json:"id" validate:"required"`
PayChannelCreateRequest
}
func (p PayChannelUpdateRequest) RequestToDb() (db paychannelmodel.PayChannel, err error) {
db.Id = p.Id
db.PayName = p.PayName
db.MerchantId = p.MerchantId
db.ChannelType = p.ChannelType
db.AppId = p.AppId
if p.ExpireTime != "" {
db.ExpireTime, err = utils.StrToTimeShanghai(p.ExpireTime)
if err != nil {
err = errors.Wrap(err, "时间格式错误")
}
}
switch p.ChannelType {
case common.PAY_CHANNEL_WECHAT_H5, common.PAY_CHANNEL_WECHAT_JSAPI, common.PAY_CHANNEL_WECHAT_NATIVE, common.PAY_CHANNEL_WECHAT_APP, common.PAY_CHANNEL_WECHAT_MINI:
b, _ := json.Marshal(p.WechatPayChannel)
db.ExtJson = string(b)
case common.PAY_CHANNEL_ALIPAY_JSAPI, common.PAY_CHANNEL_ALIPAY_WEB, common.PAY_CHANNEL_ALIPAY_MINI:
b, _ := json.Marshal(p.AliPayPayChannel)
db.ExtJson = string(b)
default:
err = errors.New("支付渠道类型错误")
} }
return return
} }

View File

@ -13,15 +13,4 @@ var BackendRequestMap = map[string]func() interface{}{
common.ADMIN_V1 + "/merchant/update": func() interface{} { return new(backend.MerchantUpdateRequest) }, common.ADMIN_V1 + "/merchant/update": func() interface{} { return new(backend.MerchantUpdateRequest) },
common.ADMIN_V1 + "/merchant/list": func() interface{} { return new(backend.MerchantListRequest) }, common.ADMIN_V1 + "/merchant/list": func() interface{} { return new(backend.MerchantListRequest) },
common.ADMIN_V1 + "/merchant/delete": func() interface{} { return new(entities.IdRequest) }, common.ADMIN_V1 + "/merchant/delete": func() interface{} { return new(entities.IdRequest) },
// 支付方式
common.ADMIN_V1 + "/paychannel/create": func() interface{} { return new(backend.PayChannelCreateRequest) },
common.ADMIN_V1 + "/paychannel/update": func() interface{} { return new(backend.PayChannelUpdateRequest) },
common.ADMIN_V1 + "/paychannel/list": func() interface{} { return new(backend.PayChannelListRequest) },
common.ADMIN_V1 + "/paychannel/delete": func() interface{} { return new(entities.IdRequest) },
// 应用
common.ADMIN_V1 + "/app/create": func() interface{} { return new(backend.AppCreateRequest) },
common.ADMIN_V1 + "/app/update": func() interface{} { return new(backend.AppUpdateRequest) },
common.ADMIN_V1 + "/app/list": func() interface{} { return new(backend.AppListRequest) },
common.ADMIN_V1 + "/app/delete": func() interface{} { return new(entities.IdRequest) },
common.ADMIN_V1 + "/app/decrypt": func() interface{} { return new(backend.GenerateDecryptKeyRequest) },
} }

View File

@ -31,21 +31,6 @@ func RegisterAdminRoute(router *gin.Engine) {
merchant.POST("/create", backend.MerchantCreate) // 商户创建 merchant.POST("/create", backend.MerchantCreate) // 商户创建
merchant.PUT("/update", backend.MerchantUpdate) // 商户更新 merchant.PUT("/update", backend.MerchantUpdate) // 商户更新
merchant.DELETE("/delete", backend.MerchantDelete) // 商户删除 merchant.DELETE("/delete", backend.MerchantDelete) // 商户删除
// 支付方式
pay := v1.Group("/paychannel")
pay.GET("/list", backend.PayChannelList) // 支付方式列表
pay.POST("/create", backend.PayChannelCreate) // 支付方式创建
pay.PUT("/update", backend.PayChannelUpdate) // 支付方式更新
pay.DELETE("/delete", backend.PayChannelDelete) // 支付方式删除
// 应用管理
app := v1.Group("/app")
app.GET("/list", backend.AppList) // 应用列表
app.POST("/create", backend.AppCreate) // 应用创建
app.PUT("/update", backend.AppUpdate) // 应用更新
app.DELETE("/delete", backend.AppDelete) // 应用删除
app.GET("/decrypt", backend.GenerateDecrypt) // 生成密钥对
} }
} }

View File

@ -13,7 +13,7 @@ var (
// 实体 // 实体
type App struct { type App struct {
Id int64 Id int64 `xorm:"pk autoincr AUTO_RANDOM"`
MerchantId int64 `xorm:"'merchant_id' bigint(20)"` MerchantId int64 `xorm:"'merchant_id' bigint(20)"`
AppName string `xorm:"'app_name' varchar(128)"` AppName string `xorm:"'app_name' varchar(128)"`
AppRemark string `xorm:"'app_remark' varchar(255)"` AppRemark string `xorm:"'app_remark' varchar(255)"`
@ -22,8 +22,6 @@ type App struct {
PublicKey string `xorm:"'public_key' varchar(1024)"` PublicKey string `xorm:"'public_key' varchar(1024)"`
PrivateKey string `xorm:"'private_key' varchar(1024)"` PrivateKey string `xorm:"'private_key' varchar(1024)"`
MerchantPublicKey string `xorm:"'merchant_public_key' varchar(1024)"` MerchantPublicKey string `xorm:"'merchant_public_key' varchar(1024)"`
NotifyUrl string `xorm:"'notify_url' varchar(128)"`
WhiteIp string `xorm:"'white_ip' varchar(128)"`
CreateTime time.Time `xorm:"'create_time' datetime created"` CreateTime time.Time `xorm:"'create_time' datetime created"`
UpdateTime time.Time `xorm:"'update_time' timestamp updated"` UpdateTime time.Time `xorm:"'update_time' timestamp updated"`
DeleteTime time.Time `xorm:"'delete_time' timestamp deleted"` DeleteTime time.Time `xorm:"'delete_time' timestamp deleted"`

View File

@ -16,11 +16,11 @@ type Orders struct {
Id int64 Id int64
MerchantId int64 `xorm:"'merchant_id' bigint(20)"` MerchantId int64 `xorm:"'merchant_id' bigint(20)"`
PayId int64 `xorm:"'pay_id' bigint(20)"` PayId int64 `xorm:"'pay_id' bigint(20)"`
AppId int64 `xorm:"'app_id' bigint(20)"`
MerchantOrderId string `xorm:"'merchant_order_id' varchar(128)"` MerchantOrderId string `xorm:"'merchant_order_id' varchar(128)"`
Status int `xorm:"'status' int(11)"` Status int `xorm:"'status' int(11)"`
OrderType int `xorm:"'order_type' int(11)"` OrderType int `xorm:"'order_type' int(11)"`
Amount int `xorm:"'amount' int(11)"` Amount int `xorm:"'amount' int(11)"`
NotifyUrl string `xorm:"'notify_url' varchar(255)"`
IpAddress string `xorm:"'ip_address' varchar(128)"` IpAddress string `xorm:"'ip_address' varchar(128)"`
MerchantRequest string `xorm:"'merchant_request' varchar(2048)"` MerchantRequest string `xorm:"'merchant_request' varchar(2048)"`
MerchantResponse string `xorm:"'merchant_response' varchar(255)"` MerchantResponse string `xorm:"'merchant_response' varchar(255)"`

View File

@ -14,16 +14,16 @@ var (
// 实体 // 实体
type PayChannel struct { type PayChannel struct {
Id int64 Id int64
PayName string `xorm:"'pay_name' varchar(128)"` PayName string `xorm:"'pay_name' varchar(128)"`
MerchantId int64 `xorm:"'merchant_id' bigint(20)"` MerchantId int64 `xorm:"'merchant_id' bigint(20)"`
ChannelType int `xorm:"'channel_type' int(11)"` ChannelType int `xorm:"'channel_type' int(11)"`
WhiteIp string `xorm:"'white_ip' varchar(1024)"`
AppId string `xorm:"'app_id' varchar(255)"` AppId string `xorm:"'app_id' varchar(255)"`
ExtJson string `xorm:"'ext_json' JSON"` ExtJson string `xorm:"'ext_json' JSON"`
ExpireTime time.Time `xorm:"'expire_time' datetime"` ExpireTime time.Time `xorm:"'expire_time' datetime"`
CreateTime time.Time `xorm:"'create_time' datetime created"` CreateTime time.Time `xorm:"'create_time' datetime created"`
UpdateTime time.Time `xorm:"'update_time' timestamp updated"` UpdateTime time.Time `xorm:"'update_time' timestamp updated"`
DeleteTime time.Time `xorm:"'delete_time' timestamp deleted"` DeleteTime time.Time `xorm:"'delete_time' timestamp deleted"`
} }
// 表名 // 表名

View File

@ -1,86 +0,0 @@
package services
import (
"PaymentCenter/app/constants/errorcode"
"PaymentCenter/app/data"
"PaymentCenter/app/http/entities"
"PaymentCenter/app/http/entities/backend"
"PaymentCenter/app/models/appmodel"
"PaymentCenter/app/models/merchantmodel"
"PaymentCenter/app/models/paychannelmodel"
"xorm.io/builder"
)
func AppList(req backend.AppListRequest) (result []appmodel.App, total int64, code int) {
repo := data.NewAppRepo(paychannelmodel.GetInstance().GetDb())
// 拼接查询条件
conn := builder.NewCond()
if req.MerchantId > 0 {
conn = conn.And(builder.Eq{"merchant_id": req.MerchantId})
}
// 调用repo
appList := make([]appmodel.App, 0)
count, err := repo.AppList(conn, req.PageRequest, &appList)
code = handErr(err)
return appList, count, code
}
func AppCreate(App *appmodel.App) (code int) {
db := paychannelmodel.GetInstance().GetDb()
repo := data.NewAppRepo(db)
merchantRepo := data.NewMerchantRepo(db)
// 拼接查询条件
conn := builder.NewCond()
conn = conn.And(builder.Eq{"id": App.MerchantId})
merchant := merchantmodel.Merchant{}
has, err := merchantRepo.MerchantDetail(&merchant, conn)
if err != nil {
return handErr(err)
}
if !has {
return errorcode.MerchantNotFound
}
_, err = repo.AppInsertOne(App)
code = handErr(err)
return
}
func AppUpdate(App *appmodel.App) (code int) {
db := paychannelmodel.GetInstance().GetDb()
repo := data.NewAppRepo(db)
merchantRepo := data.NewMerchantRepo(db)
// 拼接查询条件
conn := builder.NewCond()
conn = conn.And(builder.Eq{"id": App.MerchantId})
merchant := merchantmodel.Merchant{}
has, err := merchantRepo.MerchantDetail(&merchant, conn)
if err != nil {
return handErr(err)
}
if !has {
return errorcode.MerchantNotFound
}
// 拼接查询条件
uconn := builder.NewCond()
uconn = uconn.And(builder.Eq{"Id": App.Id})
_, err = repo.AppUpdate(App, uconn, "app_remark")
code = handErr(err)
return
}
func AppDelete(req entities.IdRequest) (code int) {
repo := data.NewAppRepo(paychannelmodel.GetInstance().GetDb())
// 拼接查询条件
conn := builder.NewCond()
conn = conn.And(builder.Eq{"Id": req.Id})
m := appmodel.App{Id: req.Id}
_, err := repo.AppDelete(&m, conn)
code = handErr(err)
return
}

View File

@ -1,85 +0,0 @@
package services
import (
"PaymentCenter/app/constants/errorcode"
"PaymentCenter/app/data"
"PaymentCenter/app/http/entities"
"PaymentCenter/app/http/entities/backend"
"PaymentCenter/app/models/merchantmodel"
"PaymentCenter/app/models/paychannelmodel"
"xorm.io/builder"
)
func PayChannelList(req backend.PayChannelListRequest) (result []paychannelmodel.PayChannel, total int64, code int) {
repo := data.NewPayChannelRepo(paychannelmodel.GetInstance().GetDb())
// 拼接查询条件
conn := builder.NewCond()
if req.MerchantId > 0 {
conn = conn.And(builder.Eq{"merchant_id": req.MerchantId})
}
// 调用repo
paychannelList := make([]paychannelmodel.PayChannel, 0)
count, err := repo.PayChannelList(conn, req.PageRequest, &paychannelList)
code = handErr(err)
return paychannelList, count, code
}
func PayChannelCreate(payChannel *paychannelmodel.PayChannel) (code int) {
db := paychannelmodel.GetInstance().GetDb()
repo := data.NewPayChannelRepo(db)
merchantRepo := data.NewMerchantRepo(db)
// 拼接查询条件
conn := builder.NewCond()
conn = conn.And(builder.Eq{"id": payChannel.MerchantId})
merchant := merchantmodel.Merchant{}
has, err := merchantRepo.MerchantDetail(&merchant, conn)
if err != nil {
return handErr(err)
}
if !has {
return errorcode.MerchantNotFound
}
_, err = repo.PayChannelInsertOne(payChannel)
code = handErr(err)
return
}
func PayChannelUpdate(payChannel *paychannelmodel.PayChannel) (code int) {
db := paychannelmodel.GetInstance().GetDb()
repo := data.NewPayChannelRepo(db)
merchantRepo := data.NewMerchantRepo(db)
// 拼接查询条件
conn := builder.NewCond()
conn = conn.And(builder.Eq{"id": payChannel.MerchantId})
merchant := merchantmodel.Merchant{}
has, err := merchantRepo.MerchantDetail(&merchant, conn)
if err != nil {
return handErr(err)
}
if !has {
return errorcode.MerchantNotFound
}
// 拼接查询条件
uconn := builder.NewCond()
uconn = uconn.And(builder.Eq{"Id": payChannel.Id})
_, err = repo.PayChannelUpdate(payChannel, uconn, "white_ip")
code = handErr(err)
return
}
func PayChannelDelete(req entities.IdRequest) (code int) {
repo := data.NewPayChannelRepo(paychannelmodel.GetInstance().GetDb())
// 拼接查询条件
conn := builder.NewCond()
conn = conn.And(builder.Eq{"Id": req.Id})
m := paychannelmodel.PayChannel{Id: req.Id}
_, err := repo.PayChannelDelete(&m, conn)
code = handErr(err)
return
}

7
go.mod
View File

@ -6,7 +6,6 @@ require (
gitee.com/chengdu_blue_brothers/openapi-go-sdk v0.0.2 gitee.com/chengdu_blue_brothers/openapi-go-sdk v0.0.2
github.com/BurntSushi/toml v0.4.1 github.com/BurntSushi/toml v0.4.1
github.com/Shopify/sarama v1.19.0 github.com/Shopify/sarama v1.19.0
github.com/ahmetb/go-linq/v3 v3.2.0
github.com/aliyun/aliyun-oss-go-sdk v3.0.2+incompatible github.com/aliyun/aliyun-oss-go-sdk v3.0.2+incompatible
github.com/forgoer/openssl v1.6.0 github.com/forgoer/openssl v1.6.0
github.com/gin-gonic/gin v1.7.7 github.com/gin-gonic/gin v1.7.7
@ -30,14 +29,13 @@ require (
google.golang.org/grpc v1.56.3 google.golang.org/grpc v1.56.3
google.golang.org/protobuf v1.30.0 google.golang.org/protobuf v1.30.0
gopkg.in/go-playground/validator.v9 v9.31.0 gopkg.in/go-playground/validator.v9 v9.31.0
xorm.io/builder v0.3.9
xorm.io/xorm v1.2.5
) )
require ( require (
github.com/KyleBanks/depth v1.2.1 // indirect github.com/KyleBanks/depth v1.2.1 // indirect
github.com/PuerkitoBio/purell v1.1.1 // indirect github.com/PuerkitoBio/purell v1.1.1 // indirect
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
github.com/ahmetb/go-linq/v3 v3.2.0 // indirect
github.com/alibabacloud-go/debug v0.0.0-20190504072949-9472017b5c68 // indirect github.com/alibabacloud-go/debug v0.0.0-20190504072949-9472017b5c68 // indirect
github.com/alibabacloud-go/tea v1.1.17 // indirect github.com/alibabacloud-go/tea v1.1.17 // indirect
github.com/alibabacloud-go/tea-utils v1.4.4 // indirect github.com/alibabacloud-go/tea-utils v1.4.4 // indirect
@ -55,7 +53,6 @@ require (
github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21 // indirect github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21 // indirect
github.com/eapache/queue v1.1.0 // indirect github.com/eapache/queue v1.1.0 // indirect
github.com/emirpasic/gods v1.12.0 // indirect github.com/emirpasic/gods v1.12.0 // indirect
github.com/fvbock/endless v0.0.0-20170109170031-447134032cb6 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect github.com/gin-contrib/sse v0.1.0 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.19.6 // indirect github.com/go-openapi/jsonreference v0.19.6 // indirect
@ -114,5 +111,7 @@ require (
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect
stathat.com/c/consistent v1.0.0 // indirect stathat.com/c/consistent v1.0.0 // indirect
xorm.io/builder v0.3.9 // indirect
xorm.io/core v0.7.3 // indirect xorm.io/core v0.7.3 // indirect
xorm.io/xorm v1.2.5 // indirect
) )

1
go.sum
View File

@ -175,7 +175,6 @@ github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMo
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
github.com/fsnotify/fsnotify v1.5.1 h1:mZcQUHVQUQWoPXXtuf9yuEXKudkV2sx1E06UadKWpgI= github.com/fsnotify/fsnotify v1.5.1 h1:mZcQUHVQUQWoPXXtuf9yuEXKudkV2sx1E06UadKWpgI=
github.com/fsnotify/fsnotify v1.5.1/go.mod h1:T3375wBYaZdLLcVNkcVbzGHY7f1l/uK5T5Ai1i3InKU= github.com/fsnotify/fsnotify v1.5.1/go.mod h1:T3375wBYaZdLLcVNkcVbzGHY7f1l/uK5T5Ai1i3InKU=
github.com/fvbock/endless v0.0.0-20170109170031-447134032cb6 h1:6VSn3hB5U5GeA6kQw4TwWIWbOhtvR2hmbBJnTOtqTWc=
github.com/fvbock/endless v0.0.0-20170109170031-447134032cb6/go.mod h1:YxOVT5+yHzKvwhsiSIWmbAYM3Dr9AEEbER2dVayfBkg= github.com/fvbock/endless v0.0.0-20170109170031-447134032cb6/go.mod h1:YxOVT5+yHzKvwhsiSIWmbAYM3Dr9AEEbER2dVayfBkg=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/gin-contrib/gzip v0.0.3 h1:etUaeesHhEORpZMp18zoOhepboiWnFtXrBZxszWUn4k= github.com/gin-contrib/gzip v0.0.3 h1:etUaeesHhEORpZMp18zoOhepboiWnFtXrBZxszWUn4k=