From 7a3823a2a754cf853e116f1490138be22e8e9d5d Mon Sep 17 00:00:00 2001 From: wolter Date: Fri, 2 Aug 2024 10:41:57 +0800 Subject: [PATCH 1/7] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E5=92=8C=E8=AE=A2=E5=8D=95=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/data/order_log.go | 8 +- app/data/orders.go | 20 +++- app/http/controllers/backend/order.go | 51 +++++++++ app/http/entities/backend/order.go | 131 ++++++++++++++++++++++ app/http/requestmapping/backend.go | 3 + app/http/routes/admin.go | 5 + app/models/ordersmodel/orders.go | 8 +- app/models/paychannelmodel/pay_channel.go | 19 ++-- app/services/order.go | 64 +++++++++++ 9 files changed, 290 insertions(+), 19 deletions(-) create mode 100644 app/http/controllers/backend/order.go create mode 100644 app/http/entities/backend/order.go create mode 100644 app/services/order.go diff --git a/app/data/order_log.go b/app/data/order_log.go index 42298d3..36db815 100644 --- a/app/data/order_log.go +++ b/app/data/order_log.go @@ -17,7 +17,7 @@ func NewOrderLogRepo(repo xorm.Interface) *OrderLogRepo { } } -func (m *OrderLogRepo) MerchantList(conn builder.Cond, pageFilter entities.PageRequest, orderLogList *[]orderlogmodel.OrderLogModel) (int64, error) { +func (m *OrderLogRepo) OrderLogList(conn builder.Cond, pageFilter entities.PageRequest, orderLogList *[]orderlogmodel.OrderLog) (int64, error) { repo := m.repo.Where(conn) if pageFilter.Page > 0 { repo = repo.Limit(pageFilter.PageSize, pageFilter.PageSize*(pageFilter.Page-1)) @@ -25,15 +25,15 @@ func (m *OrderLogRepo) MerchantList(conn builder.Cond, pageFilter entities.PageR return repo.Desc("create_time").FindAndCount(orderLogList) } -func (m *OrderLogRepo) MerchantInsertOne(orderLog *orderlogmodel.OrderLogModel) (int64, error) { +func (m *OrderLogRepo) OrderLogInsertOne(orderLog *orderlogmodel.OrderLog) (int64, error) { return m.repo.InsertOne(orderLog) } -func (m *OrderLogRepo) MerchantDelete(orderLog *orderlogmodel.OrderLogModel, conn builder.Cond) (int64, error) { +func (m *OrderLogRepo) OrderLogDelete(orderLog *orderlogmodel.OrderLog, conn builder.Cond) (int64, error) { return m.repo.Where(conn).Delete(orderLog) } // columns 参数为要更新的字段 -func (m *OrderLogRepo) MerchantUpdate(orderLog *orderlogmodel.OrderLogModel, conn builder.Cond, columns ...string) (int64, error) { +func (m *OrderLogRepo) OrderLogUpdate(orderLog *orderlogmodel.OrderLog, conn builder.Cond, columns ...string) (int64, error) { return m.repo.Where(conn).MustCols(columns...).Update(orderLog) } diff --git a/app/data/orders.go b/app/data/orders.go index c04d4ee..c9bd442 100644 --- a/app/data/orders.go +++ b/app/data/orders.go @@ -17,7 +17,7 @@ func NewOrderRepo(repo xorm.Interface) *OrderRepo { } } -func (m *OrderRepo) MerchantList(conn builder.Cond, pageFilter entities.PageRequest, orderList *[]ordersmodel.Orders) (int64, error) { +func (m *OrderRepo) OrderList(conn builder.Cond, pageFilter entities.PageRequest, orderList *[]ordersmodel.Orders) (int64, error) { repo := m.repo.Where(conn) if pageFilter.Page > 0 { repo = repo.Limit(pageFilter.PageSize, pageFilter.PageSize*(pageFilter.Page-1)) @@ -25,15 +25,27 @@ func (m *OrderRepo) MerchantList(conn builder.Cond, pageFilter entities.PageRequ return repo.Desc("create_time").FindAndCount(orderList) } -func (m *OrderRepo) MerchantInsertOne(order *ordersmodel.Orders) (int64, error) { +func (m *OrderRepo) OrderInsertOne(order *ordersmodel.Orders) (int64, error) { return m.repo.InsertOne(order) } -func (m *OrderRepo) MerchantDelete(order *ordersmodel.Orders, conn builder.Cond) (int64, error) { +func (m *OrderRepo) OrderDelete(order *ordersmodel.Orders, conn builder.Cond) (int64, error) { return m.repo.Where(conn).Delete(order) } // columns 参数为要更新的字段 -func (m *OrderRepo) MerchantUpdate(order *ordersmodel.Orders, conn builder.Cond, columns ...string) (int64, error) { +func (m *OrderRepo) OrderUpdate(order *ordersmodel.Orders, conn builder.Cond, columns ...string) (int64, error) { return m.repo.Where(conn).MustCols(columns...).Update(order) } + +func (m *OrderRepo) OrdersBackendList(conn builder.Cond, pageFilter entities.PageRequest, orderList *[]ordersmodel.OrdersBackendList) (int64, error) { + repo := m.repo.Select(`orders.*, merchant.name as merchant_name, app.app_name, pay_channel.pay_name`). + Where(conn) + if pageFilter.Page > 0 { + repo = repo.Limit(pageFilter.PageSize, pageFilter.PageSize*(pageFilter.Page-1)) + } + repo = repo.Join("left", "app", "app.id = orders.app_id"). + Join("left", "merchant", "merchant.id = orders.merchant_id"). + Join("left", "pay_channel", "pay_channel.id = orders.pay_id") + return repo.Desc("create_time").FindAndCount(orderList) +} diff --git a/app/http/controllers/backend/order.go b/app/http/controllers/backend/order.go new file mode 100644 index 0000000..5c577a9 --- /dev/null +++ b/app/http/controllers/backend/order.go @@ -0,0 +1,51 @@ +package backend + +import ( + "PaymentCenter/app/constants/errorcode" + "PaymentCenter/app/http/controllers" + "PaymentCenter/app/http/entities" + "PaymentCenter/app/http/entities/backend" + "PaymentCenter/app/models/orderlogmodel" + "PaymentCenter/app/models/ordersmodel" + "PaymentCenter/app/services" + "github.com/ahmetb/go-linq/v3" + "github.com/gin-gonic/gin" +) + +func OrderList(c *gin.Context) { + req, _ := controllers.GetRequest(c).(*backend.OrderListRequest) + filter, err := req.ValidateRequest() + if err != nil { + controllers.Error(c, errorcode.ParamError, err.Error()) + return + } + orderList, total, code := services.OrderList(filter) + + result := make([]backend.OrdersResponse, 0, len(orderList)) + linq.From(orderList).SelectT(func(in ordersmodel.OrdersBackendList) (out backend.OrdersResponse) { + out.ResponseFromDb(in) + return + }).ToSlice(&result) + data := entities.PageRsp{ + Total: total, + Data: result, + } + controllers.HandCodeRes(c, data, code) +} + +func OrderLogsList(c *gin.Context) { + req, _ := controllers.GetRequest(c).(*backend.OrderLogsListRequest) + req.SetDefault() + orderLogList, total, code := services.OrderLogsList(*req) + + result := make([]backend.OrderLogResponse, 0, len(orderLogList)) + linq.From(orderLogList).SelectT(func(in orderlogmodel.OrderLog) (out backend.OrderLogResponse) { + out.ResponseFromDb(in) + return + }).ToSlice(&result) + data := entities.PageRsp{ + Total: total, + Data: result, + } + controllers.HandCodeRes(c, data, code) +} diff --git a/app/http/entities/backend/order.go b/app/http/entities/backend/order.go new file mode 100644 index 0000000..e154ff8 --- /dev/null +++ b/app/http/entities/backend/order.go @@ -0,0 +1,131 @@ +package backend + +import ( + "PaymentCenter/app/http/entities" + "PaymentCenter/app/models/orderlogmodel" + "PaymentCenter/app/models/ordersmodel" + "PaymentCenter/app/utils" + "github.com/pkg/errors" + + "time" +) + +type OrderListRequest struct { + Id int64 `json:"id" form:"id"` + MerchantId int64 `json:"merchant_id" form:"merchant_id"` + PayId int64 `json:"pay_id" form:"pay_id"` + AppId int64 `json:"app_id" form:"app_id"` + MerchantOrderId string `json:"merchant_order_id" form:"merchant_order_id"` + Status int `json:"status" form:"status"` + OrderType int `json:"order_type" form:"order_type"` + StartTime string `json:"start_time" form:"start_time"` + EndTime string `json:"end_time" form:"end_time"` + entities.PageRequest +} +type OrderList struct { + Id int64 `json:"id"` + MerchantId int64 `json:"merchant_id"` + PayId int64 `json:"pay_id"` + AppId int64 `json:"app_id"` + MerchantOrderId string `json:"merchant_order_id"` + Status int `json:"status"` + OrderType int `json:"order_type"` + StartTime time.Time `json:"start_time"` + EndTime time.Time `json:"end_time"` + entities.PageRequest +} + +func (o *OrderListRequest) ValidateRequest() (r OrderList, err error) { + if o.StartTime != "" { + r.StartTime, err = utils.StrToTimeShanghai(o.StartTime) + if err != nil { + err = errors.Wrap(err, "时间格式错误") + return + } + } + if o.EndTime != "" { + r.EndTime, err = utils.StrToTimeShanghai(o.EndTime) + if err != nil { + err = errors.Wrap(err, "时间格式错误") + return + } + } + + r.Id = o.Id + r.MerchantId = o.MerchantId + r.PayId = o.PayId + r.AppId = o.AppId + r.MerchantOrderId = o.MerchantOrderId + r.Status = o.Status + r.OrderType = o.OrderType + r.PageRequest = o.PageRequest + r.SetDefault() + return +} + +type OrdersResponse struct { + Id int64 `json:"id"` + MerchantId int64 `json:"merchant_id"` + PayId int64 `json:"pay_id"` + AppId int64 `json:"app_id"` + MerchantOrderId string `json:"merchant_order_id"` + Status int `json:"status"` + OrderType int `json:"order_type"` + Amount int `json:"amount"` + IpAddress string `json:"ip_address"` + MerchantRequest string `json:"merchant_request"` + MerchantResponse string `json:"merchant_response"` + OrderResponse string `json:"order_response"` + ExtJson string `json:"ext_json"` + CreateTime string `json:"create_time"` + UpdateTime string `json:"update_time"` + MerchantName string `json:"merchant_name"` + PayName string `json:"pay_name"` + AppName string `json:"app_name"` +} + +func (o *OrdersResponse) ResponseFromDb(db ordersmodel.OrdersBackendList) { + o.Id = db.Id + o.MerchantId = db.MerchantId + o.PayId = db.PayId + o.AppId = db.AppId + o.MerchantOrderId = db.MerchantOrderId + o.Status = db.Status + o.OrderType = db.OrderType + o.Amount = db.Amount + o.IpAddress = db.IpAddress + o.MerchantRequest = db.MerchantRequest + o.MerchantResponse = db.MerchantResponse + o.OrderResponse = db.OrderResponse + o.ExtJson = db.ExtJson + o.CreateTime = db.CreateTime.Format("2006-01-02 15:04:05") + o.UpdateTime = db.UpdateTime.Format("2006-01-02 15:04:05") + o.MerchantName = db.MerchantName + o.PayName = db.PayName + o.AppName = db.AppName +} + +type OrderLogsListRequest struct { + OrderId int64 `json:"order_id" form:"order_id"` + entities.PageRequest +} + +type OrderLogResponse struct { + Id int64 `json:"id"` + OrderId int64 `json:"order_id"` + PayCallback string `json:"pay_callback"` + Status int `json:"status"` + MerchantParam string `json:"merchant_param"` + MerchantCallback string `json:"merchant_callback"` + CreateTime string `json:"create_time"` +} + +func (o *OrderLogResponse) ResponseFromDb(db orderlogmodel.OrderLog) { + o.Id = db.Id + o.OrderId = db.OrderId + o.PayCallback = db.PayCallback + o.Status = db.Status + o.MerchantParam = db.MerchantParam + o.MerchantCallback = db.MerchantCallback + o.CreateTime = db.CreateTime.Format("2006-01-02 15:04:05") +} diff --git a/app/http/requestmapping/backend.go b/app/http/requestmapping/backend.go index d5edcf7..5d76b3f 100644 --- a/app/http/requestmapping/backend.go +++ b/app/http/requestmapping/backend.go @@ -24,4 +24,7 @@ var BackendRequestMap = map[string]func() interface{}{ 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) }, + // 订单 + common.ADMIN_V1 + "/order/list": func() interface{} { return new(backend.OrderListRequest) }, + common.ADMIN_V1 + "/order/log/list": func() interface{} { return new(backend.OrderLogsListRequest) }, } diff --git a/app/http/routes/admin.go b/app/http/routes/admin.go index f9461d9..7b531f8 100644 --- a/app/http/routes/admin.go +++ b/app/http/routes/admin.go @@ -46,6 +46,11 @@ func RegisterAdminRoute(router *gin.Engine) { app.DELETE("/delete", backend.AppDelete) // 应用删除 app.GET("/decrypt", backend.GenerateDecrypt) // 生成密钥对 + // 订单 + order := v1.Group("/order") + order.GET("/list", backend.OrderList) // 订单列表 + order.GET("/log/list", backend.OrderLogsList) // 订单日志列表 + } } diff --git a/app/models/ordersmodel/orders.go b/app/models/ordersmodel/orders.go index 48e9aa3..2d8b1c2 100644 --- a/app/models/ordersmodel/orders.go +++ b/app/models/ordersmodel/orders.go @@ -17,7 +17,7 @@ type Orders struct { MerchantId int64 `xorm:"'merchant_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(32)"` Status int `xorm:"'status' int(11)"` OrderType int `xorm:"'order_type' int(11)"` Amount int `xorm:"'amount' int(11)"` @@ -30,6 +30,12 @@ type Orders struct { UpdateTime time.Time `xorm:"'update_time' timestamp updated"` DeleteTime time.Time `xorm:"'delete_time' timestamp deleted"` } +type OrdersBackendList struct { + Orders `xorm:"extends"` + MerchantName string `xorm:"'merchant_name' varchar(128)"` + PayName string `xorm:"'pay_name' varchar(128)"` + AppName string `xorm:"'app_name' varchar(128)"` +} // 表名 func (m *Orders) TableName() string { diff --git a/app/models/paychannelmodel/pay_channel.go b/app/models/paychannelmodel/pay_channel.go index cede2df..7b65f10 100644 --- a/app/models/paychannelmodel/pay_channel.go +++ b/app/models/paychannelmodel/pay_channel.go @@ -14,16 +14,15 @@ var ( // 实体 type PayChannel struct { Id int64 - PayName string `xorm:"'pay_name' varchar(128)"` - MerchantId int64 `xorm:"'merchant_id' bigint(20)"` - ChannelType int `xorm:"'channel_type' int(11)"` - - AppId string `xorm:"'app_id' varchar(255)"` - ExtJson string `xorm:"'ext_json' JSON"` - ExpireTime time.Time `xorm:"'expire_time' datetime"` - CreateTime time.Time `xorm:"'create_time' datetime created"` - UpdateTime time.Time `xorm:"'update_time' timestamp updated"` - DeleteTime time.Time `xorm:"'delete_time' timestamp deleted"` + PayName string `xorm:"'pay_name' varchar(128)"` + MerchantId int64 `xorm:"'merchant_id' bigint(20)"` + ChannelType int `xorm:"'channel_type' int(11)"` + AppId string `xorm:"'app_id' varchar(255)"` + ExtJson string `xorm:"'ext_json' JSON"` + ExpireTime time.Time `xorm:"'expire_time' datetime"` + CreateTime time.Time `xorm:"'create_time' datetime created"` + UpdateTime time.Time `xorm:"'update_time' timestamp updated"` + DeleteTime time.Time `xorm:"'delete_time' timestamp deleted"` } // 表名 diff --git a/app/services/order.go b/app/services/order.go new file mode 100644 index 0000000..bfc6d8a --- /dev/null +++ b/app/services/order.go @@ -0,0 +1,64 @@ +package services + +import ( + "PaymentCenter/app/data" + "PaymentCenter/app/http/entities/backend" + "PaymentCenter/app/models/orderlogmodel" + "PaymentCenter/app/models/ordersmodel" + "PaymentCenter/app/models/paychannelmodel" + "xorm.io/builder" +) + +// 订单列表,后台查询 +func OrderList(req backend.OrderList) (result []ordersmodel.OrdersBackendList, total int64, code int) { + repo := data.NewOrderRepo(paychannelmodel.GetInstance().GetDb()) + // 拼接查询条件 + conn := builder.NewCond() + if req.Id > 0 { + conn = conn.And(builder.Eq{"id": req.Id}) + } + if req.MerchantId > 0 { + conn = conn.And(builder.Eq{"merchant_id": req.MerchantId}) + } + if req.PayId > 0 { + conn = conn.And(builder.Eq{"pay_id": req.PayId}) + } + if req.AppId > 0 { + conn = conn.And(builder.Eq{"app_id": req.AppId}) + } + if req.MerchantOrderId != "" { + conn = conn.And(builder.Like{"merchant_order_id", req.MerchantOrderId}) + } + if req.Status > 0 { + conn = conn.And(builder.Eq{"status": req.Status}) + } + if req.OrderType > 0 { + conn = conn.And(builder.Eq{"order_type": req.OrderType}) + } + if !req.StartTime.IsZero() { + conn = conn.And(builder.Gte{"start_time": req.StartTime}) + } + if !req.EndTime.IsZero() { + conn = conn.And(builder.Lte{"end_time": req.EndTime}) + } + + // 调用repo + orderList := make([]ordersmodel.OrdersBackendList, 0) + count, err := repo.OrdersBackendList(conn, req.PageRequest, &orderList) + code = handErr(err) + return orderList, count, code +} + +func OrderLogsList(req backend.OrderLogsListRequest) (result []orderlogmodel.OrderLog, total int64, code int) { + repo := data.NewOrderLogRepo(paychannelmodel.GetInstance().GetDb()) + conn := builder.NewCond() + if req.OrderId > 0 { + conn = conn.And(builder.Eq{"order_id": req.OrderId}) + } + // 调用repo + orderLogList := make([]orderlogmodel.OrderLog, 0) + count, err := repo.OrderLogList(conn, req.PageRequest, &orderLogList) + code = handErr(err) + + return orderLogList, count, code +} From f8f0ac29137d9860cbb0f81ec8fe373d1dcc08a9 Mon Sep 17 00:00:00 2001 From: wolter Date: Fri, 2 Aug 2024 13:54:25 +0800 Subject: [PATCH 2/7] =?UTF-8?q?=E5=BA=94=E7=94=A8=E5=92=8C=E6=94=AF?= =?UTF-8?q?=E4=BB=98=E6=96=B9=E5=BC=8F=E4=BF=AE=E6=94=B9=E4=B8=8D=E8=83=BD?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=95=86=E6=88=B7id?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/http/entities/backend/app.go | 14 +++++------ app/http/entities/backend/pay_channel.go | 10 +++++--- app/services/app.go | 32 ++++++++++-------------- app/services/pay_channel.go | 14 +---------- 4 files changed, 27 insertions(+), 43 deletions(-) diff --git a/app/http/entities/backend/app.go b/app/http/entities/backend/app.go index c35bb55..dc4233b 100644 --- a/app/http/entities/backend/app.go +++ b/app/http/entities/backend/app.go @@ -50,7 +50,7 @@ type AppCreateRequest struct { 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"` + NotifyUrl string `json:"notify_url" validate:"required" label:"通知地址"` } func (a *AppCreateRequest) RequestToDb() (db appmodel.App) { @@ -69,13 +69,12 @@ func (a *AppCreateRequest) RequestToDb() (db appmodel.App) { 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:"应用名称"` + AppName string `json:"app_name" 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:"应用私钥"` + Status int `json:"status" label:"应用状态"` + KeyType int `json:"key_type" label:"应用密钥类型"` + PublicKey string `json:"public_key" label:"应用公钥"` + PrivateKey string `json:"private_key" label:"应用私钥"` MerchantPublicKey string `json:"merchant_public_key" label:"商户公钥"` WhiteIp string `json:"white_ip"` NotifyUrl string `json:"notify_url"` @@ -83,7 +82,6 @@ type AppUpdateRequest struct { 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 diff --git a/app/http/entities/backend/pay_channel.go b/app/http/entities/backend/pay_channel.go index 7bbb096..c2260ac 100644 --- a/app/http/entities/backend/pay_channel.go +++ b/app/http/entities/backend/pay_channel.go @@ -91,14 +91,18 @@ type PayChannelListRequest struct { } type PayChannelUpdateRequest struct { - Id int64 `json:"id" validate:"required"` - PayChannelCreateRequest + Id int64 `json:"id" validate:"required"` + PayName string `json:"pay_name" validate:"required" label:"支付渠道名称"` + ChannelType int `json:"channel_type" validate:"required" label:"支付渠道"` //支付渠道枚举,1微信JSAPI,2微信H5,3微信app,4微信Native,5微信小程序,6支付宝网页&移动应用,7支付宝小程序,8支付宝JSAPI + AppId string `json:"app_id" validate:"required" label:"应用appId"` + ExpireTime string `json:"expire_time"` + AliPayPayChannel AliPayPayChannel `json:"ali_pay_pay_channel,omitempty"` + WechatPayChannel WechatPayChannel `json:"wechat_pay_channel,omitempty"` } 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 != "" { diff --git a/app/services/app.go b/app/services/app.go index 90dd740..7777b82 100644 --- a/app/services/app.go +++ b/app/services/app.go @@ -26,13 +26,13 @@ func AppList(req backend.AppListRequest) (result []appmodel.App, total int64, co return appList, count, code } -func AppCreate(App *appmodel.App) (code int) { +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}) + conn = conn.And(builder.Eq{"id": app.MerchantId}) merchant := merchantmodel.Merchant{} has, err := merchantRepo.MerchantDetail(&merchant, conn) if err != nil { @@ -42,31 +42,25 @@ func AppCreate(App *appmodel.App) (code int) { return errorcode.MerchantNotFound } - _, err = repo.AppInsertOne(App) + _, err = repo.AppInsertOne(app) code = handErr(err) return } -func AppUpdate(App *appmodel.App) (code int) { +func AppUpdate(app *appmodel.App) (code int) { + var err error 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") + conn := builder.NewCond() + conn = conn.And(builder.Eq{"Id": app.Id}) + if app.AppName != "" { + // 编辑页面更新,备注和白名单IP可更新为空 + _, err = repo.AppUpdate(app, conn, "app_remark", "white_ip") + } else { + _, err = repo.AppUpdate(app, conn) + } code = handErr(err) return diff --git a/app/services/pay_channel.go b/app/services/pay_channel.go index 0e19da3..3d3b57b 100644 --- a/app/services/pay_channel.go +++ b/app/services/pay_channel.go @@ -49,23 +49,11 @@ func PayChannelCreate(payChannel *paychannelmodel.PayChannel) (code int) { 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") + _, err := repo.PayChannelUpdate(payChannel, uconn, "white_ip") code = handErr(err) return From 92c1a3c230f4b473d786aba66dd4fae0f35a86d6 Mon Sep 17 00:00:00 2001 From: wolter Date: Fri, 2 Aug 2024 14:02:13 +0800 Subject: [PATCH 3/7] =?UTF-8?q?=E6=B7=BB=E5=8A=A0dockerfile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Dockerfile | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..264e9ac --- /dev/null +++ b/Dockerfile @@ -0,0 +1,43 @@ + +## 使用官方Go镜像作为构建环境 +#FROM golang:1.21.0 AS builder +# +## 设置工作目录 +#WORKDIR /app +# +## 复制项目源码 +#COPY . . +# +## 复制go模块依赖文件 +#COPY go.mod go.sum ./ +# +## 安装go模块依赖 +#RUN go env -w GOPROXY=https://goproxy.cn,direct +#RUN go mod tidy +# +## 编译Go应用程序,生成静态链接的二进制文件 +#RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o server . + +# 创建最终镜像,用于运行编译后的Go程序 +FROM alpine + +RUN echo 'http://mirrors.ustc.edu.cn/alpine/v3.5/main' > /etc/apk/repositories \ +&& echo 'http://mirrors.ustc.edu.cn/alpine/v3.5/community' >>/etc/apk/repositories \ +&& apk update && apk add tzdata \ +&& ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \ +&& echo "Asia/Shanghai" > /etc/timezone \ + +ENV server = "admin" + +# 设置工作目录 +WORKDIR /app + +# 将编译好的二进制文件从构建阶段复制到运行阶段 +COPY /server . +#COPY --from=builder /app/server . +COPY .env . + + +ENV TZ=Asia/Shanghai +# 设置容器启动时运行的命令 +ENTRYPOINT ["/app/server", "-a", "$server"] \ No newline at end of file From bf4e24619d23124e55a73e6487efda71489412de Mon Sep 17 00:00:00 2001 From: wolter Date: Fri, 2 Aug 2024 14:32:44 +0800 Subject: [PATCH 4/7] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=90=8E=E5=8F=B0?= =?UTF-8?q?=E8=B7=AF=E7=94=B1=EF=BC=8C=E6=B7=BB=E5=8A=A0auth=E6=A0=A1?= =?UTF-8?q?=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/constants/common/common.go | 7 ++++- app/http/middlewares/base.go | 52 +++++++++++++++++++++++----------- app/http/routes/admin.go | 2 +- app/utils/util.go | 10 +++++++ config/config.go | 1 + 5 files changed, 54 insertions(+), 18 deletions(-) diff --git a/app/constants/common/common.go b/app/constants/common/common.go index 5ddaf65..d763935 100644 --- a/app/constants/common/common.go +++ b/app/constants/common/common.go @@ -3,7 +3,7 @@ package common const ( TOKEN_PRE = "player_token_" TOKEN_Admin = "Admin_token_" - ADMIN_V1 = "/admin/pay/api/v1" + ADMIN_V1 = "/pay/admin/api/v1" // 支付渠道枚举,1微信JSAPI,2微信H5,3微信app,4微信Native,5微信小程序,6支付宝网页&移动应用,7支付宝小程序,8支付宝JSAPI PAY_CHANNEL_UNKNOWN = 0 @@ -15,4 +15,9 @@ const ( PAY_CHANNEL_ALIPAY_WEB = 6 PAY_CHANNEL_ALIPAY_MINI = 7 PAY_CHANNEL_ALIPAY_JSAPI = 8 + + // 统一登陆信息 + ADMIN_USER_ID = "User-Id" + ADMIN_USER_NAME = "User-Name" + ADMIN_USER_INCLUDEUSERS = "Include-Users" ) diff --git a/app/http/middlewares/base.go b/app/http/middlewares/base.go index c13dedd..728350d 100644 --- a/app/http/middlewares/base.go +++ b/app/http/middlewares/base.go @@ -6,10 +6,8 @@ import ( "PaymentCenter/app/http/controllers" "PaymentCenter/app/http/requestmapping" "PaymentCenter/app/utils" - "context" - "errors" + "PaymentCenter/config" "github.com/gin-gonic/gin" - "github.com/qit-team/snow-core/redis" "strings" ) @@ -59,20 +57,42 @@ func Cors() gin.HandlerFunc { func AdminAuth() gin.HandlerFunc { return func(c *gin.Context) { - var token = c.GetHeader("token") - //将token放入redis - var playerId, err = redis.GetRedis().Get(context.Background(), utils.GetRealKey(common.TOKEN_Admin+token)).Result() - if rs, errRedis := redis.GetRedis().SIsMember(context.Background(), "disabled_uids", playerId).Result(); errRedis == nil && rs { - err = errors.New(errorcode.GetMsg(errorcode.NotFound, "")) - redis.GetRedis().SRem(context.Background(), "disabled_uids", playerId) - } - if err == nil { - c.Set("playerId", playerId) - c.Next() - return - } else { - controllers.HandCodeRes(c, nil, errorcode.Forbidden) + ip, _ := c.RemoteIP() + utils.Log(c, "请求地址RemoteIP()", ip.String(), config.GetConf().AdminGate) + clientIp := c.ClientIP() + utils.Log(c, "请求地址clientIp", clientIp) + + if config.GetConf().Debug == false && !utils.SliceInStr(ip.String(), config.GetConf().AdminGate) { c.Abort() + controllers.HandCodeRes(c, nil, errorcode.Forbidden) + return + } + + var userName = c.GetHeader("User-Name") + if userName != "" { + c.Set(common.ADMIN_USER_NAME, userName) + } + var IncludeUsers = c.GetHeader("Include-Users") + if IncludeUsers != "" { + c.Set(common.ADMIN_USER_INCLUDEUSERS, IncludeUsers) + } + + var adminId = c.GetHeader("User-Id") + // 测试环境直接放行 + if config.GetConf().Debug == true { + c.Set(common.ADMIN_USER_ID, adminId) + c.Next() + } else { + utils.Log(c, "请求header信息", "adminId="+adminId, "IncludeUsers="+IncludeUsers) + // 正式环境校验 + if adminId != "" { + c.Set(common.ADMIN_USER_ID, adminId) + c.Next() + } else { + c.Abort() + controllers.HandCodeRes(c, nil, errorcode.NotAuth) + return + } } } } diff --git a/app/http/routes/admin.go b/app/http/routes/admin.go index 7b531f8..9d81e75 100644 --- a/app/http/routes/admin.go +++ b/app/http/routes/admin.go @@ -23,7 +23,7 @@ func RegisterAdminRoute(router *gin.Engine) { } } - v1 := router.Group("/admin/pay/api/v1", middlewares.ValidateRequest()) + v1 := router.Group("/pay/admin/api/v1", middlewares.AdminAuth(), middlewares.ValidateRequest()) { // 商户管理 merchant := v1.Group("/merchant") diff --git a/app/utils/util.go b/app/utils/util.go index 42ef269..0810033 100644 --- a/app/utils/util.go +++ b/app/utils/util.go @@ -410,3 +410,13 @@ func ParseToken(tokenString string) (*jwt.Token, *Claims, error) { }) return token, Claims, err } + +// 判断切片是否包含指定字符串 +func SliceInStr(s string, slice []string) bool { + for _, v := range slice { + if s == v { + return true + } + } + return false +} diff --git a/config/config.go b/config/config.go index 9fdff6f..4db996c 100644 --- a/config/config.go +++ b/config/config.go @@ -36,6 +36,7 @@ type Config struct { OpenApi OpenApi `toml:"OpenApi"` Jwt Jwt `toml:"Jwt"` AliOss AliOss `toml:"AliOss"` + AdminGate []string `toml:"AdminGate"` } type AliOss struct { From 88b95cb67a19d2e9b062099689603cdbdcfd7be3 Mon Sep 17 00:00:00 2001 From: wolter Date: Fri, 2 Aug 2024 17:21:18 +0800 Subject: [PATCH 5/7] =?UTF-8?q?=E5=90=8E=E5=8F=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/console/command.go | 77 ++++++++++++++++++++++++ app/console/kernel.go | 4 +- app/constants/common/common.go | 7 +++ app/data/app.go | 4 ++ app/data/pay_channel.go | 16 +++-- app/http/controllers/backend/merchant.go | 1 + app/http/controllers/base.go | 23 +++++++ app/http/entities/backend/app.go | 3 +- app/http/entities/backend/merchant.go | 9 ++- app/http/entities/backend/pay_channel.go | 3 +- app/models/merchantmodel/merchant.go | 1 + app/services/app.go | 19 ++++++ app/services/merchant.go | 4 ++ app/services/pay_channel.go | 21 +++++++ bootstrap/bootstrap.go | 5 +- 15 files changed, 183 insertions(+), 14 deletions(-) diff --git a/app/console/command.go b/app/console/command.go index e312c14..c77f187 100644 --- a/app/console/command.go +++ b/app/console/command.go @@ -1,9 +1,86 @@ package console import ( + "PaymentCenter/app/constants/common" + "PaymentCenter/app/data" + "PaymentCenter/app/http/entities" + "PaymentCenter/app/models/ordersmodel" + "PaymentCenter/app/utils" "github.com/qit-team/snow-core/command" + "strconv" + "time" + "xorm.io/builder" ) func RegisterCommand(c *command.Command) { c.AddFunc("test", test) + c.AddFunc("closeOrder", closeOrder) +} + +// 关闭长时间支付中的订单 +func closeOrder() { + var now = time.Now().Format(time.DateTime) + utils.Log(nil, "关闭订单", now) + // 查询未支付的订单 + repo := data.NewOrderRepo(ordersmodel.GetInstance().GetDb()) + // 拼接条件 + cond := builder.NewCond() + cond = cond.And(builder.Eq{"status": common.ORDER_STATUS_PAYING}, builder.Lt{"create_time": time.Now().Add(-time.Hour)}) + + order := make([]ordersmodel.Orders, 0) + total, err := repo.OrderList(cond, entities.PageRequest{}, &order) + if err != nil { + utils.Log(nil, "关闭订单,查询未支付订单失败", err) + } else if total > 0 { + orderIds := make([]int64, 0) + for _, v := range order { + orderIds = append(orderIds, v.Id) + } + // 修改订单状态为关闭 + cond = builder.NewCond() + cond = cond.And(builder.In("id", orderIds)) + _, err = repo.OrderUpdate(&ordersmodel.Orders{Status: common.ORDER_STATUS_CLOSE}, cond, "status") + if err != nil { + utils.Log(nil, "关闭订单,修改订单状态失败", err) + return + } + } + utils.Log(nil, "关闭订单,修改订单状态成功", "count="+strconv.Itoa(len(order))) +} + +// 定时查询支付中的订单, 主动查询订单支付状态 +func queryOrder() { + var now = time.Now().Format(time.DateTime) + utils.Log(nil, "主动查询订单支付状态", now) + // 查询未支付的订单 + repo := data.NewOrderRepo(ordersmodel.GetInstance().GetDb()) + // 拼接条件 + cond := builder.NewCond() + cond = cond.And(builder.Eq{"status": common.ORDER_STATUS_PAYING}, builder.Gt{"create_time": time.Now().Add(-time.Second)}) + order := make([]ordersmodel.Orders, 0) + total, err := repo.OrderList(cond, entities.PageRequest{}, &order) + if err != nil { + utils.Log(nil, "主动查询订单支付状态,查询未付中订单失败", err) + return + } else if total > 0 { + // 发起查询上游支付 + for _, v := range order { + go func(order ordersmodel.Orders) { + // 发起查询 + utils.Log(nil, "主动查询订单支付状态,发起查询", order.Id) + // 解析上游结果 + + // 修改订单状态 + }(v) + } + } +} + +// 回调下游 +func callbackOrder() { + var now = time.Now().Format(time.DateTime) + utils.Log(nil, "回调下游", now) + // 查询回调失败的订单 + + // 发起回调 } diff --git a/app/console/kernel.go b/app/console/kernel.go index 23f081d..7ef72d9 100644 --- a/app/console/kernel.go +++ b/app/console/kernel.go @@ -11,5 +11,7 @@ import ( func RegisterSchedule(c *cron.Cron) { //c.AddFunc("0 30 * * * *", test) //c.AddFunc("@hourly", test) - c.AddFunc("@every 10s", test) + //c.AddFunc("@every 10s", test) + c.AddFunc("@every 60s", closeOrder) + c.AddFunc("@every 10s", queryOrder) } diff --git a/app/constants/common/common.go b/app/constants/common/common.go index d763935..9188762 100644 --- a/app/constants/common/common.go +++ b/app/constants/common/common.go @@ -20,4 +20,11 @@ const ( ADMIN_USER_ID = "User-Id" ADMIN_USER_NAME = "User-Name" ADMIN_USER_INCLUDEUSERS = "Include-Users" + + // '订单状态,待支付、支付中、支付成功、支付失败、订单关闭', + ORDER_STATUS_WAITPAY = 1 + ORDER_STATUS_PAYING = 2 + ORDER_STATUS_PAYED = 3 + ORDER_STATUS_FAILED = 4 + ORDER_STATUS_CLOSE = 5 ) diff --git a/app/data/app.go b/app/data/app.go index ff8c0fa..adabe1a 100644 --- a/app/data/app.go +++ b/app/data/app.go @@ -37,3 +37,7 @@ func (m *AppRepo) AppDelete(app *appmodel.App, conn builder.Cond) (int64, error) func (m *AppRepo) AppUpdate(app *appmodel.App, conn builder.Cond, columns ...string) (int64, error) { return m.repo.Where(conn).MustCols(columns...).Update(app) } + +func (m *AppRepo) AppGet(app *appmodel.App, conn builder.Cond) (bool, error) { + return m.repo.Where(conn).Get(app) +} diff --git a/app/data/pay_channel.go b/app/data/pay_channel.go index 5a26f22..8647765 100644 --- a/app/data/pay_channel.go +++ b/app/data/pay_channel.go @@ -25,15 +25,19 @@ func (m *PayChannelRepo) PayChannelList(conn builder.Cond, pageFilter entities.P return repo.Desc("create_time").FindAndCount(payChannelList) } -func (m *PayChannelRepo) PayChannelInsertOne(merchant *paychannelmodel.PayChannel) (int64, error) { - return m.repo.InsertOne(merchant) +func (m *PayChannelRepo) PayChannelInsertOne(payChannel *paychannelmodel.PayChannel) (int64, error) { + return m.repo.InsertOne(payChannel) } -func (m *PayChannelRepo) PayChannelDelete(merchant *paychannelmodel.PayChannel, conn builder.Cond) (int64, error) { - return m.repo.Where(conn).Delete(merchant) +func (m *PayChannelRepo) PayChannelDelete(payChannel *paychannelmodel.PayChannel, conn builder.Cond) (int64, error) { + return m.repo.Where(conn).Delete(payChannel) } // columns 参数为要更新的字段,即使为空 -func (m *PayChannelRepo) PayChannelUpdate(merchant *paychannelmodel.PayChannel, conn builder.Cond, columns ...string) (int64, error) { - return m.repo.Where(conn).MustCols(columns...).Update(merchant) +func (m *PayChannelRepo) PayChannelUpdate(payChannel *paychannelmodel.PayChannel, conn builder.Cond, columns ...string) (int64, error) { + return m.repo.Where(conn).MustCols(columns...).Update(payChannel) +} + +func (m *PayChannelRepo) PayChannelGet(payChannel *paychannelmodel.PayChannel, conn builder.Cond) (bool, error) { + return m.repo.Where(conn).Get(payChannel) } diff --git a/app/http/controllers/backend/merchant.go b/app/http/controllers/backend/merchant.go index 4f1e3cb..6832840 100644 --- a/app/http/controllers/backend/merchant.go +++ b/app/http/controllers/backend/merchant.go @@ -13,6 +13,7 @@ import ( func MerchantList(c *gin.Context) { req, _ := controllers.GetRequest(c).(*backend.MerchantListRequest) req.SetDefault() + req.GroupInfo = controllers.GetAdminUserIncludeUsers(c) merchantList, total, code := services.MerchantList(*req) result := make([]backend.MerchantResponse, 0, len(merchantList)) diff --git a/app/http/controllers/base.go b/app/http/controllers/base.go index 354472c..e097b95 100644 --- a/app/http/controllers/base.go +++ b/app/http/controllers/base.go @@ -1,6 +1,7 @@ package controllers import ( + "PaymentCenter/app/constants/common" "PaymentCenter/app/utils" "PaymentCenter/config" "bytes" @@ -17,6 +18,7 @@ import ( "net/http" "reflect" "regexp" + "strconv" "PaymentCenter/app/constants/errorcode" @@ -207,3 +209,24 @@ func phoneValidation(fl validator.FieldLevel) bool { reg := regexp.MustCompile(phoneRegex) return reg.MatchString(phone) } + +// 管理后台,获取用户id +func GetAdminId(c *gin.Context) int { + userIdStr, _ := c.Get(common.ADMIN_USER_ID) + if userIdStr != nil { + var userId, _ = strconv.Atoi(userIdStr.(string)) + return userId + } + + return 0 +} + +// 获取对应数据权限中拥有用户数据ID +func GetAdminUserIncludeUsers(c *gin.Context) string { + name, _ := c.Get(common.ADMIN_USER_INCLUDEUSERS) + if name != nil { + var temp, _ = name.(string) + return temp + } + return "" +} diff --git a/app/http/entities/backend/app.go b/app/http/entities/backend/app.go index dc4233b..11c0cf1 100644 --- a/app/http/entities/backend/app.go +++ b/app/http/entities/backend/app.go @@ -6,7 +6,8 @@ import ( ) type AppListRequest struct { - MerchantId int64 `json:"merchant_id"` + Id int64 `json:"id" form:"id"` + MerchantId int64 `json:"merchant_id" form:"merchant_id" validate:"required" label:"商户ID"` entities.PageRequest } diff --git a/app/http/entities/backend/merchant.go b/app/http/entities/backend/merchant.go index 1aaaedf..5ad7883 100644 --- a/app/http/entities/backend/merchant.go +++ b/app/http/entities/backend/merchant.go @@ -7,9 +7,10 @@ import ( type MerchantListRequest struct { entities.PageRequest - Name string `form:"name"` - Contact string `form:"contact"` - Phone string `form:"phone"` + Name string `form:"name"` + Contact string `form:"contact"` + Phone string `form:"phone"` + GroupInfo string } type MerchantResponse struct { @@ -35,6 +36,7 @@ type MerchantCreateRequest struct { Contact string `json:"contact" validate:"required" label:"联系人"` Phone string `json:"phone" validate:"required,phoneValidation" label:"联系电话"` Remark string `json:"remark" label:"备注"` + Creator int } func (m *MerchantCreateRequest) RequestToDb() (db merchantmodel.Merchant) { @@ -42,6 +44,7 @@ func (m *MerchantCreateRequest) RequestToDb() (db merchantmodel.Merchant) { db.Contact = m.Contact db.Phone = m.Phone db.Remark = m.Remark + db.Creator = m.Creator return db } diff --git a/app/http/entities/backend/pay_channel.go b/app/http/entities/backend/pay_channel.go index c2260ac..f1ad133 100644 --- a/app/http/entities/backend/pay_channel.go +++ b/app/http/entities/backend/pay_channel.go @@ -86,7 +86,8 @@ func (p *PayChannelCreateRequest) RequestToDb() (db paychannelmodel.PayChannel, } type PayChannelListRequest struct { - MerchantId int64 `json:"merchant_id"` + Id int64 `json:"id" form:"id" ` + MerchantId int64 `json:"merchant_id" form:"merchant_id" validate:"required" label:"商户ID"` entities.PageRequest } diff --git a/app/models/merchantmodel/merchant.go b/app/models/merchantmodel/merchant.go index f66ae6e..5dbb16d 100644 --- a/app/models/merchantmodel/merchant.go +++ b/app/models/merchantmodel/merchant.go @@ -18,6 +18,7 @@ type Merchant struct { Contact string `xorm:"'contact' varchar(128)"` Phone string `xorm:"'phone' varchar(11)"` Remark string `xorm:"'remark' varchar(1024)"` + Creator int `xorm:"'creator' int(10)"` CreateTime time.Time `xorm:"'create_time' datetime created"` UpdateTime time.Time `xorm:"'update_time' timestamp updated"` DeleteTime time.Time `xorm:"'delete_time' timestamp deleted"` diff --git a/app/services/app.go b/app/services/app.go index 7777b82..2c67441 100644 --- a/app/services/app.go +++ b/app/services/app.go @@ -18,6 +18,9 @@ func AppList(req backend.AppListRequest) (result []appmodel.App, total int64, co if req.MerchantId > 0 { conn = conn.And(builder.Eq{"merchant_id": req.MerchantId}) } + if req.Id > 0 { + conn = conn.And(builder.Eq{"id": req.Id}) + } // 调用repo appList := make([]appmodel.App, 0) @@ -78,3 +81,19 @@ func AppDelete(req entities.IdRequest) (code int) { code = handErr(err) return } + +func AppGet(app *appmodel.App) (code int) { + repo := data.NewAppRepo(appmodel.GetInstance().GetDb()) + // 拼接查询条件 + conn := builder.NewCond() + conn = conn.And(builder.Eq{"id": app.Id}) + has, err := repo.AppGet(app, conn) + if err != nil { + return handErr(err) + } + if !has { + return errorcode.AppNotFound + } + code = errorcode.Success + return +} diff --git a/app/services/merchant.go b/app/services/merchant.go index 9b31931..99d80f1 100644 --- a/app/services/merchant.go +++ b/app/services/merchant.go @@ -5,6 +5,7 @@ import ( "PaymentCenter/app/http/entities" "PaymentCenter/app/http/entities/backend" "PaymentCenter/app/models/merchantmodel" + "strings" "xorm.io/builder" ) @@ -22,6 +23,9 @@ func MerchantList(req backend.MerchantListRequest) (result []merchantmodel.Merch if req.Phone != "" { conn = conn.And(builder.Like{"phone", req.Phone}) } + if req.GroupInfo != "" { + conn = conn.And(builder.In("creator", strings.Split(req.GroupInfo, ","))) + } // 调用repo merchantList := make([]merchantmodel.Merchant, 0) diff --git a/app/services/pay_channel.go b/app/services/pay_channel.go index 3d3b57b..6ff06f9 100644 --- a/app/services/pay_channel.go +++ b/app/services/pay_channel.go @@ -17,6 +17,9 @@ func PayChannelList(req backend.PayChannelListRequest) (result []paychannelmodel if req.MerchantId > 0 { conn = conn.And(builder.Eq{"merchant_id": req.MerchantId}) } + if req.Id > 0 { + conn = conn.And(builder.Eq{"id": req.Id}) + } // 调用repo paychannelList := make([]paychannelmodel.PayChannel, 0) @@ -71,3 +74,21 @@ func PayChannelDelete(req entities.IdRequest) (code int) { code = handErr(err) return } + +func PayChannelGet(payChannel *paychannelmodel.PayChannel) (code int) { + repo := data.NewPayChannelRepo(paychannelmodel.GetInstance().GetDb()) + + // 拼接查询条件 + conn := builder.NewCond() + conn = conn.And(builder.Eq{"Id": payChannel.Id}) + has, err := repo.PayChannelGet(payChannel, conn) + if err != nil { + return handErr(err) + } + if !has { + return errorcode.PayChannelNotFound + } + + code = errorcode.Success + return +} diff --git a/bootstrap/bootstrap.go b/bootstrap/bootstrap.go index 499fa77..ef9286c 100644 --- a/bootstrap/bootstrap.go +++ b/bootstrap/bootstrap.go @@ -4,11 +4,10 @@ import ( "PaymentCenter/app/jobs" "PaymentCenter/app/jobs/basejob" "PaymentCenter/config" - "github.com/qit-team/snow-core/log/accesslogger" - "github.com/qit-team/snow-core/db" "github.com/qit-team/snow-core/kernel/close" "github.com/qit-team/snow-core/kernel/container" + "github.com/qit-team/snow-core/log/accesslogger" "github.com/qit-team/snow-core/log/logger" "github.com/qit-team/snow-core/redis" ) @@ -26,6 +25,8 @@ func Bootstrap(conf *config.Config) (err error) { //注册db服务 //第一个参数为注入别名,第二个参数为配置,第三个参数可选为是否懒加载 err = db.Pr.Register(db.SingletonMain, conf.Db) + //cacher := caches.NewLRUCacher2(caches.NewMemoryStore(), time.Hour, 1000) + //db.GetDb().SetDefaultCacher(cacher) if err != nil { return From b8da95788bd8e7590de7e9eaa5d67f2d4218153d Mon Sep 17 00:00:00 2001 From: wolter Date: Fri, 2 Aug 2024 17:23:38 +0800 Subject: [PATCH 6/7] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=94=AF=E4=BB=98?= =?UTF-8?q?=E6=96=B9=E5=BC=8F=E8=AF=B7=E6=B1=82=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/constants/errorcode/error_code.go | 8 +++++++- app/http/entities/backend/pay_channel.go | 15 ++++++++------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/app/constants/errorcode/error_code.go b/app/constants/errorcode/error_code.go index f240f37..5819d91 100644 --- a/app/constants/errorcode/error_code.go +++ b/app/constants/errorcode/error_code.go @@ -24,6 +24,10 @@ const ( // 商户 MerchantNotFound = 1100 + + AppNotFound = 1200 + + PayChannelNotFound = 1300 ) var MsgEN = map[int]string{ @@ -42,7 +46,9 @@ var MsgZH = map[int]string{ NotAuth: "未经授权", NotLogin: "未登录", - MerchantNotFound: "商户不存在", + MerchantNotFound: "商户不存在", + AppNotFound: "应用不存在", + PayChannelNotFound: "支付方式不存在", } var MsgMap map[string]map[int]string = map[string]map[int]string{"en": MsgZH} diff --git a/app/http/entities/backend/pay_channel.go b/app/http/entities/backend/pay_channel.go index f1ad133..e6b3af2 100644 --- a/app/http/entities/backend/pay_channel.go +++ b/app/http/entities/backend/pay_channel.go @@ -49,16 +49,17 @@ type PayChannelCreateRequest struct { } type WechatPayChannel struct { - MchId string `json:"mch_id"` //直连商户号 - MchCertificateSerialNumber string `json:"mch_certificate_serial_number"` //商户证书序列号 - MchAPIv3Key string `json:"mch_APIv3_key"` //商户APIv3密钥 - PrivateKeyPath string `json:"private_key_path"` //商户私钥文件路径 + MchId string `json:"mch_id"` // 商户ID 或者服务商模式的 sp_mchid + SerialNo string `json:"serial_no"` // 商户证书的证书序列号 + ApiV3Key string `json:"api_v_3_key"` // apiV3Key,商户平台获取 + PrivateKey string `json:"private_key"` // 私钥 apiclient_key.pem 读取后的内容 } type AliPayPayChannel struct { - AliPublicKey string `json:"ali_public_key"` //支付宝公钥 - PrivateKeyPath string `json:"private_key_path"` //应用私钥 - SignType string `json:"sign_type"` //商户生成签名字符串所使用的签名算法类型,目前支持RSA2和RSA,推荐使用RSA2 + PrivateKey string `json:"private_key"` // 应用私钥 + AppPublicCert string `json:"app_public_cert"` // 应用公钥 + AlipayRootCert string `json:"alipay_root_cert"` // 支付宝根证书 + AlipayPublicCert string `json:"alipay_public_cert"` // 支付宝公钥 } func (p *PayChannelCreateRequest) RequestToDb() (db paychannelmodel.PayChannel, err error) { From f1bb1ad53ba11c037830daaf9f376f63a64ddcbb Mon Sep 17 00:00:00 2001 From: wolter Date: Fri, 2 Aug 2024 17:32:49 +0800 Subject: [PATCH 7/7] fix --- app/services/pay_channel.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/pay_channel.go b/app/services/pay_channel.go index 6ff06f9..6cfe4f6 100644 --- a/app/services/pay_channel.go +++ b/app/services/pay_channel.go @@ -80,7 +80,7 @@ func PayChannelGet(payChannel *paychannelmodel.PayChannel) (code int) { // 拼接查询条件 conn := builder.NewCond() - conn = conn.And(builder.Eq{"Id": payChannel.Id}) + conn = conn.And(builder.Eq{"id": payChannel.Id}) has, err := repo.PayChannelGet(payChannel, conn) if err != nil { return handErr(err)