diff --git a/.buddy/go-admin.fixed.yml b/.buddy/go-admin.fixed.yml new file mode 100644 index 000000000..c9c9bcbca --- /dev/null +++ b/.buddy/go-admin.fixed.yml @@ -0,0 +1,31 @@ +- pipeline: "go-admin-1" + events: + - type: "PUSH" + refs: + - "refs/heads/master" + fail_on_prepare_env_warning: true + actions: + - action: "go build" + type: "BUILD" + docker_image_name: "library/golang" + docker_image_tag: "1.21.10" + execute_commands: + - "go mod tidy" + - "go build" + services: + - type: "MARIADB" + connection: + host: "mariadb" + user: "goadmin" + password: "goadmin" + db: "go-admin" + volume_mappings: [] + volume_mappings: + - "/:/src/github.com/asoft41/go-admin" + shell: "BASH" + - action: "Transfer to a sandbox: lvgang-sandbox" + type: "DEPLOY_TO_SANDBOX" + remote_path: "/" + sandbox_references: + - "BY_ID" + sandbox_id: "jfptrteah6pgh" diff --git a/app/admin/apis/sys_user.go b/app/admin/apis/sys_user.go index 64eb50138..304ac080f 100644 --- a/app/admin/apis/sys_user.go +++ b/app/admin/apis/sys_user.go @@ -1,11 +1,12 @@ package apis import ( - "github.com/gin-gonic/gin/binding" "go-admin/app/admin/models" - "golang.org/x/crypto/bcrypt" "net/http" + "github.com/gin-gonic/gin/binding" + "golang.org/x/crypto/bcrypt" + "github.com/gin-gonic/gin" "github.com/go-admin-team/go-admin-core/sdk/api" "github.com/go-admin-team/go-admin-core/sdk/pkg/jwtauth/user" @@ -90,6 +91,21 @@ func (e SysUser) Get(c *gin.Context) { e.OK(object, "查询成功") } +// ImportTemplate +// @Summary 下载用户导入模板 +// @Description 获取JSON +// @Tags 用户 +// @Success 200 {object} response.Response "{"code": 200, "data": [...]}" +// @Router /api/v1/sys-user/{userId} [get] +// @Security Bearer +func (e SysUser) ImportTemplate(c *gin.Context) { + file := "D:\\data\\rhhy\\0801\\aliapy-2402190717.xlsx" + c.Header("Content-Description", "File Transfer") + c.Header("Content-Disposition", "attachment; filename="+file) + c.Header("Content-Type", "application/octet-stream") + c.File(file) +} + // Insert // @Summary 创建用户 // @Description 获取JSON diff --git a/app/admin/apis/t_api_zl.go b/app/admin/apis/t_api_zl.go new file mode 100644 index 000000000..0896df1db --- /dev/null +++ b/app/admin/apis/t_api_zl.go @@ -0,0 +1,191 @@ +package apis + +import ( + "fmt" + + "github.com/gin-gonic/gin" + "github.com/go-admin-team/go-admin-core/sdk/api" + "github.com/go-admin-team/go-admin-core/sdk/pkg/jwtauth/user" + _ "github.com/go-admin-team/go-admin-core/sdk/pkg/response" + + "go-admin/app/admin/models" + "go-admin/app/admin/service" + "go-admin/app/admin/service/dto" + "go-admin/common/actions" +) + +type TApiZl struct { + api.Api +} + +// GetPage 获取TApiZl列表 +// @Summary 获取TApiZl列表 +// @Description 获取TApiZl列表 +// @Tags TApiZl +// @Param pageSize query int false "页条数" +// @Param pageIndex query int false "页码" +// @Success 200 {object} response.Response{data=response.Page{list=[]models.TApiZl}} "{"code": 200, "data": [...]}" +// @Router /api/v1/t-api-zl [get] +// @Security Bearer +func (e TApiZl) GetPage(c *gin.Context) { + req := dto.TApiZlGetPageReq{} + s := service.TApiZl{} + err := e.MakeContext(c). + MakeOrm(). + Bind(&req). + MakeService(&s.Service). + Errors + if err != nil { + e.Logger.Error(err) + e.Error(500, err, err.Error()) + return + } + + p := actions.GetPermissionFromContext(c) + list := make([]models.TApiZl, 0) + var count int64 + + err = s.GetPage(&req, p, &list, &count) + if err != nil { + e.Error(500, err, fmt.Sprintf("获取TApiZl失败,\r\n失败信息 %s", err.Error())) + return + } + + e.PageOK(list, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功") +} + +// Get 获取TApiZl +// @Summary 获取TApiZl +// @Description 获取TApiZl +// @Tags TApiZl +// @Param id path int false "id" +// @Success 200 {object} response.Response{data=models.TApiZl} "{"code": 200, "data": [...]}" +// @Router /api/v1/t-api-zl/{id} [get] +// @Security Bearer +func (e TApiZl) Get(c *gin.Context) { + req := dto.TApiZlGetReq{} + s := service.TApiZl{} + err := e.MakeContext(c). + MakeOrm(). + Bind(&req). + MakeService(&s.Service). + Errors + if err != nil { + e.Logger.Error(err) + e.Error(500, err, err.Error()) + return + } + var object models.TApiZl + + p := actions.GetPermissionFromContext(c) + err = s.Get(&req, p, &object) + if err != nil { + e.Error(500, err, fmt.Sprintf("获取TApiZl失败,\r\n失败信息 %s", err.Error())) + return + } + + e.OK( object, "查询成功") +} + +// Insert 创建TApiZl +// @Summary 创建TApiZl +// @Description 创建TApiZl +// @Tags TApiZl +// @Accept application/json +// @Product application/json +// @Param data body dto.TApiZlInsertReq true "data" +// @Success 200 {object} response.Response "{"code": 200, "message": "添加成功"}" +// @Router /api/v1/t-api-zl [post] +// @Security Bearer +func (e TApiZl) Insert(c *gin.Context) { + req := dto.TApiZlInsertReq{} + s := service.TApiZl{} + err := e.MakeContext(c). + MakeOrm(). + Bind(&req). + MakeService(&s.Service). + Errors + if err != nil { + e.Logger.Error(err) + e.Error(500, err, err.Error()) + return + } + // 设置创建人 + req.SetCreateBy(user.GetUserId(c)) + + err = s.Insert(&req) + if err != nil { + e.Error(500, err, fmt.Sprintf("创建TApiZl失败,\r\n失败信息 %s", err.Error())) + return + } + + e.OK(req.GetId(), "创建成功") +} + +// Update 修改TApiZl +// @Summary 修改TApiZl +// @Description 修改TApiZl +// @Tags TApiZl +// @Accept application/json +// @Product application/json +// @Param id path int true "id" +// @Param data body dto.TApiZlUpdateReq true "body" +// @Success 200 {object} response.Response "{"code": 200, "message": "修改成功"}" +// @Router /api/v1/t-api-zl/{id} [put] +// @Security Bearer +func (e TApiZl) Update(c *gin.Context) { + req := dto.TApiZlUpdateReq{} + s := service.TApiZl{} + err := e.MakeContext(c). + MakeOrm(). + Bind(&req). + MakeService(&s.Service). + Errors + if err != nil { + e.Logger.Error(err) + e.Error(500, err, err.Error()) + return + } + req.SetUpdateBy(user.GetUserId(c)) + p := actions.GetPermissionFromContext(c) + + err = s.Update(&req, p) + if err != nil { + e.Error(500, err, fmt.Sprintf("修改TApiZl失败,\r\n失败信息 %s", err.Error())) + return + } + e.OK( req.GetId(), "修改成功") +} + +// Delete 删除TApiZl +// @Summary 删除TApiZl +// @Description 删除TApiZl +// @Tags TApiZl +// @Param data body dto.TApiZlDeleteReq true "body" +// @Success 200 {object} response.Response "{"code": 200, "message": "删除成功"}" +// @Router /api/v1/t-api-zl [delete] +// @Security Bearer +func (e TApiZl) Delete(c *gin.Context) { + s := service.TApiZl{} + req := dto.TApiZlDeleteReq{} + err := e.MakeContext(c). + MakeOrm(). + Bind(&req). + MakeService(&s.Service). + Errors + if err != nil { + e.Logger.Error(err) + e.Error(500, err, err.Error()) + return + } + + // req.SetUpdateBy(user.GetUserId(c)) + p := actions.GetPermissionFromContext(c) + + err = s.Remove(&req, p) + if err != nil { + e.Error(500, err, fmt.Sprintf("删除TApiZl失败,\r\n失败信息 %s", err.Error())) + return + } + e.OK( req.GetId(), "删除成功") +} diff --git a/app/admin/apis/t_order_reconciliation.go b/app/admin/apis/t_order_reconciliation.go new file mode 100644 index 000000000..c1c7f0c7e --- /dev/null +++ b/app/admin/apis/t_order_reconciliation.go @@ -0,0 +1,288 @@ +package apis + +import ( + "fmt" + + "github.com/gin-gonic/gin" + "github.com/go-admin-team/go-admin-core/sdk/api" + "github.com/go-admin-team/go-admin-core/sdk/pkg/jwtauth/user" + _ "github.com/go-admin-team/go-admin-core/sdk/pkg/response" + + "go-admin/app/admin/models" + "go-admin/app/admin/service" + "go-admin/app/admin/service/dto" + "go-admin/common/actions" +) + +type OrderReconciliation struct { + api.Api +} + +// GetPage 获取对账订单表,用于记录订单的对账信息列表 +// @Summary 获取对账订单表,用于记录订单的对账信息列表 +// @Description 获取对账订单表,用于记录订单的对账信息列表 +// @Tags 对账订单表,用于记录订单的对账信息 +// @Param pageSize query int false "页条数" +// @Param pageIndex query int false "页码" +// @Success 200 {object} response.Response{data=response.Page{list=[]models.OrderReconciliation}} "{"code": 200, "data": [...]}" +// @Router /api/v1/order-reconciliation [get] +// @Security Bearer +func (e OrderReconciliation) GetPage(c *gin.Context) { + req := dto.OrderReconciliationGetPageReq{} + s := service.OrderReconciliation{} + err := e.MakeContext(c). + MakeOrm(). + Bind(&req). + MakeService(&s.Service). + Errors + if err != nil { + e.Logger.Error(err) + e.Error(500, err, err.Error()) + return + } + + p := actions.GetPermissionFromContext(c) + list := make([]models.OrderReconciliation, 0) + var count int64 + + err = s.GetPage(&req, p, &list, &count) + if err != nil { + e.Error(500, err, fmt.Sprintf("获取对账订单表,用于记录订单的对账信息失败,\r\n失败信息 %s", err.Error())) + return + } + + e.PageOK(list, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功") +} + +// Get 获取对账订单表,用于记录订单的对账信息 +// @Summary 获取对账订单表,用于记录订单的对账信息 +// @Description 获取对账订单表,用于记录订单的对账信息 +// @Tags 对账订单表,用于记录订单的对账信息 +// @Param id path int false "id" +// @Success 200 {object} response.Response{data=models.OrderReconciliation} "{"code": 200, "data": [...]}" +// @Router /api/v1/order-reconciliation/{id} [get] +// @Security Bearer +func (e OrderReconciliation) Get(c *gin.Context) { + req := dto.OrderReconciliationGetReq{} + s := service.OrderReconciliation{} + err := e.MakeContext(c). + MakeOrm(). + Bind(&req). + MakeService(&s.Service). + Errors + if err != nil { + e.Logger.Error(err) + e.Error(500, err, err.Error()) + return + } + var object models.OrderReconciliation + + p := actions.GetPermissionFromContext(c) + err = s.Get(&req, p, &object) + if err != nil { + e.Error(500, err, fmt.Sprintf("获取对账订单表,用于记录订单的对账信息失败,\r\n失败信息 %s", err.Error())) + return + } + + e.OK(object, "查询成功") +} + +// Insert 创建对账订单表,用于记录订单的对账信息 +// @Summary 创建对账订单表,用于记录订单的对账信息 +// @Description 创建对账订单表,用于记录订单的对账信息 +// @Tags 对账订单表,用于记录订单的对账信息 +// @Accept application/json +// @Product application/json +// @Param data body dto.OrderReconciliationInsertReq true "data" +// @Success 200 {object} response.Response "{"code": 200, "message": "添加成功"}" +// @Router /api/v1/order-reconciliation [post] +// @Security Bearer +func (e OrderReconciliation) Insert(c *gin.Context) { + req := dto.OrderReconciliationInsertReq{} + s := service.OrderReconciliation{} + err := e.MakeContext(c). + MakeOrm(). + Bind(&req). + MakeService(&s.Service). + Errors + if err != nil { + e.Logger.Error(err) + e.Error(500, err, err.Error()) + return + } + // 设置创建人 + req.SetCreateBy(user.GetUserId(c)) + + err = s.Insert(&req) + if err != nil { + e.Error(500, err, fmt.Sprintf("创建对账订单表,用于记录订单的对账信息失败,\r\n失败信息 %s", err.Error())) + return + } + + e.OK(req.GetId(), "创建成功") +} + +// Merge 合并对账订单表,用于记录订单的对账信息(支付宝) +// @Summary 创建对账订单表,用于记录订单的对账信息(支付宝) +// @Description 创建对账订单表,用于记录订单的对账信息(支付宝) +// @Tags 对账订单表,用于记录订单的对账信息 +// @Accept application/json +// @Product application/json +// @Param data body dto.OrderReconciliationInsertReq true "data" +// @Success 200 {object} response.Response "{"code": 200, "message": "添加成功"}" +// @Router /api/v1/order-reconciliation [post] +// @Security Bearer +func (e OrderReconciliation) Merge(c *gin.Context) { + req := dto.OrderReconciliationInsertReq{} + s := service.OrderReconciliation{} + s.InitDB() + err := e.MakeContext(c). + MakeOrm(). + Bind(&req). + MakeService(&s.Service). + Errors + if err != nil { + e.Logger.Error(err) + e.Error(500, err, err.Error()) + return + } + req.Id = 1 + logNotify, err1 := s.MergeData() + if err1 != nil { + e.Error(500, err, fmt.Sprintf("(支付宝)合并对账订单表,用于记录订单的对账信息失败,\r\n失败信息 %s", err1.Error())) + return + } + + e.OK(logNotify, "创建成功") +} + +// MergeWx 合并对账订单表,用于记录订单的对账信息(微信) +// @Summary 创建对账订单表,用于记录订单的对账信息(微信) +// @Description 创建对账订单表,用于记录订单的对账信息(微信) +// @Tags 对账订单表,用于记录订单的对账信息 +// @Accept application/json +// @Product application/json +// @Param data body dto.OrderReconciliationInsertReq true "data" +// @Success 200 {object} response.Response "{"code": 200, "message": "添加成功"}" +// @Router /api/v1/order-reconciliation [post] +// @Security Bearer +func (e OrderReconciliation) MergeWx(c *gin.Context) { + req := dto.OrderReconciliationInsertReq{} + s := service.OrderReconciliation{} + //s.InitDB() + err := e.MakeContext(c). + MakeOrm(). + Bind(&req). + MakeService(&s.Service). + Errors + if err != nil { + e.Logger.Error(err) + e.Error(500, err, err.Error()) + return + } + err1 := s.MergeDataWx(c) + if err1 != nil { + e.Error(500, err1, fmt.Sprintf("(微信)合并对账订单表,用于记录订单的对账信息失败,\r\n失败信息 %s", err1.Error())) + return + } + e.OK("", "创建成功") +} + +// ScanWx 微信扫码(微信) +// @Summary 微信扫码(微信) +// @Description 创微信扫码(微信) +// @Tags 微信扫码 +// @Accept application/json +// @Product application/json +// @Param data body dto.OrderReconciliationInsertReq true "data" +// @Success 200 {object} response.Response "{"code": 200, "message": "添加成功"}" +// @Router /api/v1/order-reconciliation [post] +// @Security Bearer +func (e OrderReconciliation) ScanWx(c *gin.Context) { + req := dto.OrderReconciliationInsertReq{} + s := service.OrderReconciliation{} + err := e.MakeContext(c). + MakeOrm(). + Bind(&req). + MakeService(&s.Service). + Errors + if err != nil { + e.Logger.Error(err) + e.Error(500, err, err.Error()) + return + } + err1 := s.MergeDataWx(c) + if err1 != nil { + e.Error(500, err1, fmt.Sprintf("获取微信扫码信息失败,\r\n失败信息 %s", err1.Error())) + return + } + e.OK("", "创建成功") +} + +// Update 修改对账订单表,用于记录订单的对账信息 +// @Summary 修改对账订单表,用于记录订单的对账信息 +// @Description 修改对账订单表,用于记录订单的对账信息 +// @Tags 对账订单表,用于记录订单的对账信息 +// @Accept application/json +// @Product application/json +// @Param id path int true "id" +// @Param data body dto.OrderReconciliationUpdateReq true "body" +// @Success 200 {object} response.Response "{"code": 200, "message": "修改成功"}" +// @Router /api/v1/order-reconciliation/{id} [put] +// @Security Bearer +func (e OrderReconciliation) Update(c *gin.Context) { + req := dto.OrderReconciliationUpdateReq{} + s := service.OrderReconciliation{} + err := e.MakeContext(c). + MakeOrm(). + Bind(&req). + MakeService(&s.Service). + Errors + if err != nil { + e.Logger.Error(err) + e.Error(500, err, err.Error()) + return + } + req.SetUpdateBy(user.GetUserId(c)) + p := actions.GetPermissionFromContext(c) + + err = s.Update(&req, p) + if err != nil { + e.Error(500, err, fmt.Sprintf("修改对账订单表,用于记录订单的对账信息失败,\r\n失败信息 %s", err.Error())) + return + } + e.OK(req.GetId(), "修改成功") +} + +// Delete 删除对账订单表,用于记录订单的对账信息 +// @Summary 删除对账订单表,用于记录订单的对账信息 +// @Description 删除对账订单表,用于记录订单的对账信息 +// @Tags 对账订单表,用于记录订单的对账信息 +// @Param data body dto.OrderReconciliationDeleteReq true "body" +// @Success 200 {object} response.Response "{"code": 200, "message": "删除成功"}" +// @Router /api/v1/order-reconciliation [delete] +// @Security Bearer +func (e OrderReconciliation) Delete(c *gin.Context) { + s := service.OrderReconciliation{} + req := dto.OrderReconciliationDeleteReq{} + err := e.MakeContext(c). + MakeOrm(). + Bind(&req). + MakeService(&s.Service). + Errors + if err != nil { + e.Logger.Error(err) + e.Error(500, err, err.Error()) + return + } + + // req.SetUpdateBy(user.GetUserId(c)) + p := actions.GetPermissionFromContext(c) + + err = s.Remove(&req, p) + if err != nil { + e.Error(500, err, fmt.Sprintf("删除对账订单表,用于记录订单的对账信息失败,\r\n失败信息 %s", err.Error())) + return + } + e.OK(req.GetId(), "删除成功") +} diff --git a/app/admin/models/m_alipay_notify.go b/app/admin/models/m_alipay_notify.go new file mode 100644 index 000000000..5b2c739c4 --- /dev/null +++ b/app/admin/models/m_alipay_notify.go @@ -0,0 +1,98 @@ +package models + +import ( + "go-admin/common/models" + "time" +) + +// AlipayNotify 支付宝支付通知 +type AlipayNotify struct { + models.Model + + // GmtCreate 代表交易创建的时间 + GmtCreate time.Time `json:"gmt_create" gorm:"column:gmt_create;comment:交易创建的时间" mapstructure:"gmt_create"` + + //将以下字段都加入tag为map + + // Charset 指定字符集编码 + Charset string `json:"charset" gorm:"column:charset;type:varchar(10);comment:字符集编码" mapstructure:"charset"` + + // SellerEmail 是卖家的电子邮件地址 + SellerEmail string `json:"seller_email" gorm:"column:seller_email;type:varchar(100);comment:卖家的电子邮件地址" mapstructure:"seller_email"` + + // Subject 描述交易的主题或商品描述 + Subject string `json:"subject" gorm:"column:subject;type:varchar(255);comment:交易的主题或商品描述" mapstructure:"subject"` + + // Sign 用于验证消息真实性的签名 + Sign string `json:"sign" gorm:"column:sign;type:text;comment:用于验证消息真实性的签名" mapstructure:"sign"` + + // BuyerOpenID 是买家的支付宝Open ID + BuyerOpenID string `json:"buyer_open_id" gorm:"column:buyer_open_id;type:varchar(100);comment:买家的支付宝Open ID" mapstructure:"buyer_open_id"` + + // InvoiceAmount 是发票金额 + InvoiceAmount float64 `json:"invoice_amount" gorm:"column:invoice_amount;type:decimal(10,2);comment:发票金额" mapstructure:"invoice_amount"` + + // NotifyID 是支付宝分配给此次通知的唯一ID + NotifyID string `json:"notify_id" gorm:"column:notify_id;type:varchar(100);comment:支付宝分配给此次通知的唯一ID" mapstructure:"notify_id"` + + // FundBillList 包含资金账单的列表,列出支付方式和金额 + FundBillList string `json:"fund_bill_list" gorm:"column:fund_bill_list;type:json;comment:包含资金账单的列表,列出支付方式和金额" mapstructure:"fund_bill_list"` + + // NotifyType 表示通知的类型 + NotifyType string `json:"notify_type" gorm:"column:notify_type;type:varchar(50);comment:表示通知的类型" mapstructure:"notify_type"` + + // TradeStatus 显示当前交易的状态 + TradeStatus string `json:"trade_status" gorm:"column:trade_status;type:varchar(50);comment:显示当前交易的状态" mapstructure:"trade_status"` + + // ReceiptAmount 是实际收款金额 + ReceiptAmount float64 `json:"receipt_amount" gorm:"column:receipt_amount;type:decimal(10,2);comment:实际收款金额" mapstructure:"receipt_amount"` + + // BuyerPayAmount 是买家实际支付的金额 + BuyerPayAmount float64 `json:"buyer_pay_amount" gorm:"column:buyer_pay_amount;type:decimal(10,2);comment:买家实际支付的金额" mapstructure:"buyer_pay_amount"` + + // AppID 是商户的应用ID + AppID string `json:"app_id" gorm:"column:app_id;type:varchar(50);comment:商户的应用ID" mapstructure:"app_id` + + // SignType 是签名算法类型 + SignType string `json:"sign_type" gorm:"column:sign_type;type:varchar(10);comment:签名算法类型" mapstructure:"sign_type"` + + // SellerID 是卖家的支付宝用户ID + SellerID string `json:"seller_id" gorm:"column:seller_id;type:varchar(50);comment:卖家的支付宝用户ID" mapstructure:"seller_id"` + + // GmtPayment 是实际支付发生的时间 + GmtPayment time.Time `json:"gmt_payment" gorm:"column:gmt_payment;comment:实际支付发生的时间" mapstructure:"gmt_payment"` + + // NotifyTime 是支付宝发送此通知的时间 + NotifyTime time.Time `json:"notify_time" gorm:"column:notify_time;comment:支付宝发送此通知的时间" mapstructure:"notify_time"` + + // MerchantAppID 是商户应用ID,与 AppID 相同 + MerchantAppID string `json:"merchant_app_id" gorm:"column:merchant_app_id;type:varchar(50);comment:商户应用ID,与 AppID 相同" mapstructure:"merchant_app_id"` + + // Version 是接口版本号 + Version string `json:"version" gorm:"column:version;type:varchar(10);comment:接口版本号" mapstructure:"version"` + + // OutTradeNo 是商户系统内部的订单号 + OutTradeNo string `json:"out_trade_no" gorm:"column:out_trade_no;type:varchar(100);comment:商户系统内部的订单号" mapstructure:"out_trade_no"` + + // TotalAmount 是订单总金额 + TotalAmount float64 `json:"total_amount" gorm:"column:total_amount;type:decimal(10,2);comment:订单总金额" mapstructure:"total_amount"` + + // TradeNo 是支付宝交易号,用于唯一识别一笔交易 + TradeNo string `json:"trade_no" gorm:"column:trade_no;type:varchar(100);comment:支付宝交易号,用于唯一识别一笔交易" mapstructure:"trade_no"` + + // AuthAppID 是授权应用ID,通常与 AppID 相同 + AuthAppID string `json:"auth_app_id" gorm:"column:auth_app_id;type:varchar(50);comment:授权应用ID,通常与 AppID 相同" mapstructure:"auth_app_id"` + + // BuyerLogonID 是买家的登录ID,部分信息可能被屏蔽以保护隐私 + BuyerLogonID string `json:"buyer_logon_id" gorm:"column:buyer_logon_id;type:varchar(50);comment:买家的登录ID,部分信息可能被屏蔽以保护隐私" mapstructure:"buyer_logon_id"` + + // TypeName 业务类型 + TypeName string `json:"type_name" gorm:"column:type_name;type:varchar(50);comment:业务类型" mapstructure:"type_name"` + + // PointAmount 是积分抵扣的金额 + PointAmount float64 `json:"point_amount" gorm:"column:point_amount;type:decimal(10,2);comment:积分抵扣的金额" mapstructure:"point_amount"` +} + +func (*AlipayNotify) TableName() string { + return "m_alipay_notify" +} diff --git a/app/admin/models/m_alipay_refund_notify.go b/app/admin/models/m_alipay_refund_notify.go new file mode 100644 index 000000000..b073c89c3 --- /dev/null +++ b/app/admin/models/m_alipay_refund_notify.go @@ -0,0 +1,28 @@ +package models + +import ( + "go-admin/common/models" + "time" +) + +// AlipayRefundNotify 支付宝应退款通知 +type AlipayRefundNotify struct { + models.Model + Code string `json:"code" gorm:"column:code;type:varchar(20);not null;comment:'业务状态码,10000表示成功';" mapstructure:"code"` + Msg string `json:"msg" gorm:"type:varchar(255);not null;comment:'描述性消息,进一步确认请求状态';column:msg" mapstructure:"msg"` + BuyerLogonID string `json:"buyer_logon_id" gorm:"type:varchar(20);not null;comment:'买家登录ID,部分信息可能被屏蔽';column:buyer_logon_id" mapstructure:"buyer_logon_id"` + FundChange string `json:"fund_change" gorm:"type:char(1);not null;comment:'是否涉及资金变化,Y表示有资金变化';column:fund_change" mapstructure:"fund_change"` + GmtRefundPay time.Time `json:"gmt_refund_pay" gorm:"type:datetime;not null;comment:'退款发生的具体时间';column:gmt_refund_pay" mapstructure:"gmt_refund_pay"` + OutTradeNo string `json:"out_trade_no" gorm:"type:varchar(50);not null;comment:'商户系统内部的订单号';column:out_trade_no" mapstructure:"out_trade_no"` + RefundFee float64 `json:"refund_fee" gorm:"type:decimal(10,2);not null;comment:'退款的总金额';column:refund_fee" mapstructure:"refund_fee"` + SendBackFee float64 `json:"send_back_fee" gorm:"type:decimal(10,2);not null;comment:'退回给买家的金额,通常与退款金额相同';column:send_back_fee" mapstructure:"send_back_fee"` + TradeNo string `json:"trade_no" gorm:"type:varchar(50);not null;comment:'支付宝交易号,用于唯一识别这笔退款交易';column:trade_no" mapstructure:"trade_no"` + BuyerOpenID string `json:"buyer_open_id" gorm:"type:varchar(100);not null;comment:'买家的支付宝Open ID';column:buyer_open_id" mapstructure:"buyer_open_id"` + RefundDetails string `json:"refund_details" gorm:"type:longtext;not null;comment:'退款详情列表,包含退款金额和资金渠道';column:refund_details" mapstructure:"refund_details"` + TypeName string `json:"type_name" gorm:"column:type_name;type:varchar(50);comment:业务类型" mapstructure:"type_name"` +} + +// TableName 设置表名 +func (*AlipayRefundNotify) TableName() string { + return "m_alipay_refund_notify" +} diff --git a/app/admin/models/m_log_notify.go b/app/admin/models/m_log_notify.go new file mode 100644 index 000000000..ab23025e8 --- /dev/null +++ b/app/admin/models/m_log_notify.go @@ -0,0 +1,86 @@ +package models + +import ( + "encoding/json" + "go-admin/common/models" + "time" +) + +type LogNotify struct { + models.Model + + Data string `json:"data" gorm:"type:longtext;comment:解析后的数据"` + Parm string `json:"parm" gorm:"type:longtext;comment:请求参数"` + ParmMap map[string]interface{} `json:"parm_map" gorm:"-"` + DataMap map[string]interface{} `json:"data_map" gorm:"-"` + Time time.Time `json:"time" gorm:"type:datetime;comment:订单通知时间"` + Type string `json:"type" gorm:"type:varchar(255);comment:回调名称"` +} + +type LogZfbNotify struct { + LogNotify +} + +func (*LogZfbNotify) TableName() string { + return "m_log_zfb_notify" +} + +func (ln *LogZfbNotify) ParseParm() (m map[string]interface{}, e error) { + var parmMap map[string]interface{} + if err := json.Unmarshal([]byte(ln.Parm), &parmMap); err != nil { + return nil, err + } + return parmMap, nil +} + +type LogWxNotify struct { + LogNotify +} + +func (*LogWxNotify) TableName() string { + return "m_log_wx_notify" +} + +func (ln *LogWxNotify) ParseParm() (m map[string]interface{}, e error) { + var parmMap map[string]interface{} + if err := json.Unmarshal([]byte(ln.Parm), &parmMap); err != nil { + return nil, err + } + return parmMap, nil +} + +type LogWxScanNotify struct { + LogNotify + Result string `json:"result" gorm:"type:varchar(255);comment:微信支付扫码返回结果"` + ResultMap map[string]interface{} `json:"result_map" gorm:"-"` + ResultSuccessMap map[string]interface{} `json:"result_success_map" gorm:"-"` + DataMap map[string]interface{} `json:"data_map" gorm:"-"` +} + +func (*LogWxScanNotify) TableName() string { + return "m_log_wx_scan" +} + +func (ln *LogWxScanNotify) ParseForResult() (m map[string]interface{}, e error) { + var parmMap map[string]interface{} + if err := json.Unmarshal([]byte(ln.Result), &parmMap); err != nil { + return nil, err + } + return parmMap, nil +} + +func (ln *LogWxScanNotify) ParseParm() (m map[string]interface{}, e error) { + var parmMap map[string]interface{} + if err := json.Unmarshal([]byte(ln.Parm), &parmMap); err != nil { + return nil, err + } + return parmMap, nil +} + +func (ln *LogWxScanNotify) ParseForData() (m map[string]interface{}, e error) { + var parmMap map[string]interface{} + if err := json.Unmarshal([]byte(ln.Data), &parmMap); err != nil { + return nil, err + } + return parmMap, nil +} diff --git a/app/admin/models/m_wx_notify.go b/app/admin/models/m_wx_notify.go new file mode 100644 index 000000000..a09854bce --- /dev/null +++ b/app/admin/models/m_wx_notify.go @@ -0,0 +1,31 @@ +package models + +import ( + "go-admin/common/models" + "time" +) + +// WxNotify 结构体用于接收和处理微信支付回调的数据 +type WxNotify struct { + models.Model + Mchid string `json:"mchid" gorm:"column:mchid;comment:商户号;type:varchar(20)" mapstructure:"mchid"` + Appid string `json:"appid" gorm:"column:appid;comment:应用ID;type:varchar(30)" mapstructure:"appid"` + OutTradeNo string `json:"out_trade_no" gorm:"column:out_trade_no;comment:商户订单号;type:varchar(64)" mapstructure:"out_trade_no"` + TransactionID string `json:"transaction_id" gorm:"column:transaction_id;comment:微信支付订单号;type:varchar(64)" mapstructure:"transaction_id"` + TradeType string `json:"trade_type" gorm:"column:trade_type;comment:交易类型;type:varchar(10)" mapstructure:"trade_type"` + TradeState string `json:"trade_state" gorm:"column:trade_state;comment:交易状态;type:varchar(10)" mapstructure:"trade_state"` + TradeStateDesc string `json:"trade_state_desc" gorm:"column:trade_state_desc;comment:交易状态描述;type:varchar(255)" mapstructure:"trade_state_desc"` + BankType string `json:"bank_type" gorm:"column:bank_type;comment:银行类型;type:varchar(20)" mapstructure:"bank_type"` + Attach string `json:"attach" gorm:"column:attach;comment:自定义数据;type:varchar(255)" mapstructure:"attach"` + SuccessTime time.Time `json:"success_time" gorm:"column:success_time;comment:成功时间;type:datetime" mapstructure:"success_time"` + Openid string `json:"openid" gorm:"column:openid;comment:用户标识;type:varchar(64)" mapstructure:"openid"` + Total int `json:"total" gorm:"column:total;comment:订单金额(单位:分);type:int(11)" mapstructure:"total"` + PayerTotal int `json:"payer_total" gorm:"column:payer_total;comment:付款金额(单位:分);type:int(11)" mapstructure:"payer_total"` + Currency string `json:"currency" gorm:"column:currency;comment:货币种类;type:varchar(10)" mapstructure:"currency"` + PayerCurrency string `json:"payer_currency" gorm:"column:payer_currency;comment:付款货币种类;type:varchar(10)" mapstructure:"payer_currency"` + TypeName string `json:"type_name" gorm:"column:type_name;type:varchar(50);comment:业务类型" mapstructure:"type_name"` +} + +func (*WxNotify) TableName() string { + return "m_wx_notify" +} diff --git a/app/admin/models/m_wx_refund_notify.go b/app/admin/models/m_wx_refund_notify.go new file mode 100644 index 000000000..924557d1c --- /dev/null +++ b/app/admin/models/m_wx_refund_notify.go @@ -0,0 +1,28 @@ +package models + +import ( + "go-admin/common/models" + "time" +) + +// WxRefundNotify 结构体用于接收和处理微信支付退款回调的数据 +type WxRefundNotify struct { + models.Model + Mchid string `json:"mchid" gorm:"column:mchid;comment:商户号;type:varchar(20)" mapstructure:"mchid"` + OutTradeNo string `json:"out_trade_no" gorm:"column:out_trade_no;comment:商户订单号;type:varchar(64)" mapstructure:"out_trade_no"` + TransactionID string `json:"transaction_id" gorm:"column:transaction_id;comment:微信支付订单号;type:varchar(64)" mapstructure:"transaction_id"` + OutRefundNo string `json:"out_refund_no" gorm:"column:out_refund_no;comment:商户退款单号;type:varchar(64)" mapstructure:"out_refund_no"` + RefundID string `json:"refund_id" gorm:"column:refund_id;comment:微信退款单号;type:varchar(64)" mapstructure:"refund_id"` + RefundStatus string `json:"refund_status" gorm:"column:refund_status;comment:退款状态;type:varchar(10)" mapstructure:"refund_status"` + SuccessTime time.Time `json:"success_time" gorm:"column:success_time;comment:退款成功时间;type:datetime" mapstructure:"success_time"` + Total int `json:"total" gorm:"column:total;comment:订单金额(单位:分);type:int(11)" mapstructure:"total"` + Refund int `json:"refund" gorm:"column:refund;comment:退款金额(单位:分);type:int(11)" mapstructure:"refund"` + PayerTotal int `json:"payer_total" gorm:"column:payer_total;comment:付款金额(单位:分);type:int(11)" mapstructure:"payer_total"` + PayerRefund int `json:"payer_refund" gorm:"column:payer_refund;comment:付款方退款金额(单位:分);type:int(11)" mapstructure:"payer_refund"` + UserReceivedAccount string `json:"user_received_account" gorm:"column:user_received_account;comment:收款账户;type:varchar(255)" mapstructure:"user_received_account"` + TypeName string `json:"type_name" gorm:"column:type_name;type:varchar(50);comment:业务类型" mapstructure:"type_name"` +} + +func (*WxRefundNotify) TableName() string { + return "m_wx_refund_notify" +} diff --git a/app/admin/models/m_wx_scan.go b/app/admin/models/m_wx_scan.go new file mode 100644 index 000000000..115ab6d3f --- /dev/null +++ b/app/admin/models/m_wx_scan.go @@ -0,0 +1,26 @@ +package models + +import ( + "go-admin/common/models" + "time" +) + +type WxScan struct { + models.Model + Time time.Time `json:"time" gorm:"type:datetime;comment:请求时间"` + Appid string `json:"appid" gorm:"column:appid;comment:微信分配的公众账号ID;type:varchar(32);not null" mapstructure:"appid"` + MchID string `json:"mch_id" gorm:"column:mch_id;comment:微信支付分配的商户号;type:varchar(32);not null" mapstructure:"mch_id"` + DeviceInfo string `json:"device_info" gorm:"column:device_info;comment:终端设备号;type:varchar(16)" mapstructure:"device_info"` + NonceStr string `json:"nonce_str" gorm:"column:nonce_str;comment:随机字符串;type:varchar(64);not null" mapstructure:"nonce_str"` + Body string `json:"body" gorm:"column:body;comment:商品描述;type:varchar(128);not null" mapstructure:"body"` + Attach string `json:"attach" gorm:"column:attach;comment:附加数据;type:varchar(128)" mapstructure:"attach"` + OutTradeNo string `json:"out_trade_no" gorm:"column:out_trade_no;comment:商户订单号;type:varchar(64);not null;unique_index:uniq_out_trade_no" mapstructure:"out_trade_no"` + TotalFee int `json:"total_fee" gorm:"column:total_fee;comment:订单金额,单位为分;type:int;not null" mapstructure:"total_fee"` + SpbillCreateIP string `json:"spbill_create_ip" gorm:"column:spbill_create_ip;comment:APP和网页支付提交用户端ip;type:varchar(15);not null" mapstructure:"spbill_create_ip"` + AuthCode string `json:"auth_code" gorm:"column:auth_code;comment:扫码支付授权码;type:varchar(64);not null" mapstructure:"auth_code"` + Sign string `json:"sign" gorm:"column:sign;comment:签名;type:varchar(64);not null" mapstructure:"sign"` +} + +func (*WxScan) TableName() string { + return "m_wx_scan" +} diff --git a/app/admin/models/m_wx_scan_parm.go b/app/admin/models/m_wx_scan_parm.go new file mode 100644 index 000000000..bdf69b8f9 --- /dev/null +++ b/app/admin/models/m_wx_scan_parm.go @@ -0,0 +1,23 @@ +package models + +import ( + "go-admin/common/models" + "time" +) + +// WxScanParm 代表微信扫码支付-第三方传来的参数模型 +type WxScanParm struct { + models.Model + AuthCode string `json:"auth_code" gorm:"column:auth_code;type:varchar(255);not null;comment:'付款码'" mapstructure:"auth_code"` + Body string `json:"body" gorm:"column:body;type:varchar(255);not null;comment:'商品描述'" mapstructure:"body"` + OrderID string `json:"order_id" gorm:"column:order_id;type:varchar(255);not null;comment:'订单号'" mapstructure:"order_id"` + PayType int8 `json:"pay_type" gorm:"column:pay_type;type:tinyint;not null;comment:'扫码类型: 1-微信, 2-支付宝'" mapstructure:"pay_type"` + Total float64 `json:"total" gorm:"column:total;type:decimal(10,2);not null;comment:'总金额'" mapstructure:"total"` + UserID string `json:"user_id" gorm:"column:user_id;type:varchar(255);not null;comment:'设备信息'" mapstructure:"user_id"` + Time time.Time `json:"time" gorm:"type:datetime;comment:通知时间"` +} + +// TableName 返回表名 +func (WxScanParm) TableName() string { + return "m_wx_scan_parm" +} diff --git a/app/admin/models/m_wx_scan_result.go b/app/admin/models/m_wx_scan_result.go new file mode 100644 index 000000000..cc0ab49da --- /dev/null +++ b/app/admin/models/m_wx_scan_result.go @@ -0,0 +1,48 @@ +package models + +import ( + "go-admin/common/models" + "time" +) + +// WxScanResult represents the structure for storing WeChat scan payment results. +type WxScanResult struct { + models.Model + ReturnCode string `gorm:"column:return_code;type:varchar(16);not null;comment:'返回状态码'" json:"return_code" mapstructure:"return_code"` + ReturnMsg string `gorm:"column:return_msg;type:varchar(128);not null;comment:'返回信息'" json:"return_msg" mapstructure:"return_msg"` + ResultCode string `gorm:"column:result_code;type:varchar(16);not null;comment:'业务结果'" json:"result_code" mapstructure:"result_code"` + MchID string `gorm:"column:mch_id;type:varchar(32);not null;comment:'商户号'" json:"mch_id" mapstructure:"mch_id"` + AppID string `gorm:"column:appid;type:varchar(32);not null;comment:'应用ID'" json:"appid" mapstructure:"appid"` + DeviceInfo string `gorm:"column:device_info;type:varchar(32);not null;comment:'设备号'" json:"device_info" mapstructure:"device_info"` + NonceStr string `gorm:"column:nonce_str;type:varchar(64);not null;comment:'随机字符串'" json:"nonce_str" mapstructure:"nonce_str"` + Sign string `gorm:"column:sign;type:varchar(64);not null;comment:'签名'" json:"sign" mapstructure:"sign"` + OpenID string `gorm:"column:openid;type:varchar(128);not null;comment:'用户标识'" json:"openid" mapstructure:"openid"` + IsSubscribe string `gorm:"column:is_subscribe;type:char(1);not null;comment:'是否关注公众号'" json:"is_subscribe" mapstructure:"is_subscribe"` + TradeType string `gorm:"column:trade_type;type:varchar(32);not null;comment:'交易类型'" json:"trade_type" mapstructure:"trade_type"` + BankType string `gorm:"column:bank_type;type:varchar(32);not null;comment:'付款银行'" json:"bank_type" mapstructure:"bank_type"` + FeeType string `gorm:"column:fee_type;type:varchar(16);not null;comment:'货币种类'" json:"fee_type" mapstructure:"fee_type"` + TotalFee int `gorm:"column:total_fee;type:int;not null;comment:'总金额'" json:"total_fee" mapstructure:"total_fee"` + CashFeeType string `gorm:"column:cash_fee_type;type:varchar(16);not null;comment:'现金支付货币类型'" json:"cash_fee_type" mapstructure:"cash_fee_type"` + CashFee int `gorm:"column:cash_fee;type:int;not null;comment:'现金支付金额'" json:"cash_fee" mapstructure:"cash_fee"` + TransactionID string `gorm:"column:transaction_id;type:varchar(64);not null;comment:'微信支付订单号'" json:"transaction_id" mapstructure:"transaction_id"` + OutTradeNo string `gorm:"column:out_trade_no;type:varchar(64);not null;comment:'商户订单号'" json:"out_trade_no" mapstructure:"out_trade_no"` + Attach string `gorm:"column:attach;type:varchar(256);not null;comment:'附加数据'" json:"attach" mapstructure:"attach"` + TimeEnd time.Time `gorm:"column:time_end;type:datetime;not null;comment:'交易结束时间'" json:"time_end" mapstructure:"time_end"` +} + +// TableName sets the insert table name for this struct type +func (WxScanResult) TableName() string { + return "m_wx_scan_result" +} + +// BeforeCreate hook to parse time_end field if needed. +// func (w *WxScanResult) BeforeCreate(tx *gorm.DB) (err error) { +// if w.TimeEnd.IsZero() && w.TimeEnd.String() != "" { +// t, err := time.Parse("2006-01-02 15:04:05", w.TimeEnd.String()) +// if err != nil { +// return err +// } +// w.TimeEnd = t +// } +// return +// } diff --git a/app/admin/models/t_api_zl.go b/app/admin/models/t_api_zl.go new file mode 100644 index 000000000..2975f23f2 --- /dev/null +++ b/app/admin/models/t_api_zl.go @@ -0,0 +1,36 @@ +package models + +import ( + + "go-admin/common/models" + +) + +type TApiZl struct { + models.Model + + Code string `json:"code" gorm:"type:varchar(50);comment:业务编码"` + Handle string `json:"handle" gorm:"type:varchar(128);comment:handle"` + Title string `json:"title" gorm:"type:varchar(128);comment:标题"` + Path string `json:"path" gorm:"type:varchar(128);comment:地址"` + Type string `json:"type" gorm:"type:varchar(16);comment:接口类型"` + Action string `json:"action" gorm:"type:varchar(16);comment:请求类型"` + Req string `json:"req" gorm:"type:longtext;comment:请求入参"` + Res string `json:"res" gorm:"type:longtext;comment:响应参数"` + ResError string `json:"resError" gorm:"type:longtext;comment:错误返回"` + models.ModelTime + models.ControlBy +} + +func (TApiZl) TableName() string { + return "t_api_zl" +} + +func (e *TApiZl) Generate() models.ActiveRecord { + o := *e + return &o +} + +func (e *TApiZl) GetId() interface{} { + return e.Id +} \ No newline at end of file diff --git a/app/admin/models/t_order_reconciliation.go b/app/admin/models/t_order_reconciliation.go new file mode 100644 index 000000000..fdd5dbc68 --- /dev/null +++ b/app/admin/models/t_order_reconciliation.go @@ -0,0 +1,59 @@ +package models + +import ( + "time" + + "go-admin/common/models" +) + +type OrderReconciliation struct { + models.Model + + ProductName string `json:"productName" gorm:"type:varchar(255);comment:商品名称"` + ProductCategoryId string `json:"productCategoryId" gorm:"type:int(11);comment:商品分类ID"` + ProductCategoryName string `json:"productCategoryName" gorm:"type:varchar(255);comment:商品分类名称"` + PaymentTypeId string `json:"paymentTypeId" gorm:"type:int(11);comment:支付类型ID"` + PaymentTypeName string `json:"paymentTypeName" gorm:"type:varchar(255);comment:支付类型名称"` + TransactionSceneId string `json:"transactionSceneId" gorm:"type:int(11);comment:交易场景ID"` + TransactionSceneName string `json:"transactionSceneName" gorm:"type:varchar(255);comment:交易场景名称"` + OrderNumber string `json:"orderNumber" gorm:"type:varchar(100);comment:订单号"` + TransactionSerialNumber string `json:"transactionSerialNumber" gorm:"type:varchar(100);comment:交易流水号"` + CentralSettlementNumber string `json:"centralSettlementNumber" gorm:"type:varchar(100);comment:中联结算号"` + BankOrderNumber string `json:"bankOrderNumber" gorm:"type:varchar(100);comment:银行订单号"` + UserId string `json:"userId" gorm:"type:int(11);comment:用户ID"` + UserName string `json:"userName" gorm:"type:varchar(255);comment:用户名称"` + Openid string `json:"openid" gorm:"type:varchar(100);comment:OpenID"` + UserAccount string `json:"userAccount" gorm:"type:varchar(100);comment:用户账户"` + SystemOrderAmount string `json:"systemOrderAmount" gorm:"type:decimal(10,2);comment:系统订单金额"` + MerchantOrderAmount string `json:"merchantOrderAmount" gorm:"type:decimal(10,2);comment:商家订单金额"` + CentralAmount string `json:"centralAmount" gorm:"type:decimal(10,2);comment:中联金额"` + SystemRefundAmount string `json:"systemRefundAmount" gorm:"type:decimal(10,2);comment:系统退款金额"` + MerchantRefundAmount string `json:"merchantRefundAmount" gorm:"type:decimal(10,2);comment:商家退款金额"` + MerchantActualRefundAmount string `json:"merchantActualRefundAmount" gorm:"type:decimal(10,2);comment:商家实退金额"` + MerchantTransactionStatusId string `json:"merchantTransactionStatusId" gorm:"type:int(11);comment:商家交易状态ID"` + MerchantTransactionStatusName string `json:"merchantTransactionStatusName" gorm:"type:varchar(255);comment:商家交易状态名称"` + SystemTransactionStatusId string `json:"systemTransactionStatusId" gorm:"type:int(11);comment:系统交易状态ID"` + SystemTransactionStatusName string `json:"systemTransactionStatusName" gorm:"type:varchar(255);comment:系统交易状态名称"` + CentralTransactionStatusId string `json:"centralTransactionStatusId" gorm:"type:int(11);comment:中联交易状态ID"` + CentralTransactionStatusName string `json:"centralTransactionStatusName" gorm:"type:varchar(255);comment:中联交易状态名称"` + CentralSettlementMethodId string `json:"centralSettlementMethodId" gorm:"type:int(11);comment:中联结算方式ID"` + CentralSettlementMethodName string `json:"centralSettlementMethodName" gorm:"type:varchar(255);comment:中联结算方式名称"` + OrderCreationTime time.Time `json:"orderCreationTime" gorm:"type:datetime;comment:订单创建时间"` + TransactionTime time.Time `json:"transactionTime" gorm:"type:datetime;comment:交易时间"` + OperatorName string `json:"operatorName" gorm:"type:varchar(255);comment:操作员姓名"` + models.ModelTime + models.ControlBy +} + +func (OrderReconciliation) TableName() string { + return "t_order_reconciliation" +} + +func (e *OrderReconciliation) Generate() models.ActiveRecord { + o := *e + return &o +} + +func (e *OrderReconciliation) GetId() interface{} { + return e.Id +} diff --git a/app/admin/router/sys_user.go b/app/admin/router/sys_user.go index 4a545a699..77779f6d3 100644 --- a/app/admin/router/sys_user.go +++ b/app/admin/router/sys_user.go @@ -1,11 +1,12 @@ package router import ( - "github.com/gin-gonic/gin" - jwt "github.com/go-admin-team/go-admin-core/sdk/pkg/jwtauth" "go-admin/app/admin/apis" "go-admin/common/actions" "go-admin/common/middleware" + + "github.com/gin-gonic/gin" + jwt "github.com/go-admin-team/go-admin-core/sdk/pkg/jwtauth" ) func init() { @@ -22,6 +23,7 @@ func registerSysUserRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddle r.POST("", api.Insert) r.PUT("", api.Update) r.DELETE("", api.Delete) + r.GET("/importTemplate", api.ImportTemplate) } user := v1.Group("/user").Use(authMiddleware.MiddlewareFunc()).Use(middleware.AuthCheckRole()).Use(actions.PermissionAction()) @@ -36,4 +38,4 @@ func registerSysUserRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddle { v1auth.GET("/getinfo", api.GetInfo) } -} \ No newline at end of file +} diff --git a/app/admin/router/t_api_zl.go b/app/admin/router/t_api_zl.go new file mode 100644 index 000000000..500396660 --- /dev/null +++ b/app/admin/router/t_api_zl.go @@ -0,0 +1,27 @@ +package router + +import ( + "github.com/gin-gonic/gin" + jwt "github.com/go-admin-team/go-admin-core/sdk/pkg/jwtauth" + + "go-admin/app/admin/apis" + "go-admin/common/middleware" + "go-admin/common/actions" +) + +func init() { + routerCheckRole = append(routerCheckRole, registerTApiZlRouter) +} + +// registerTApiZlRouter +func registerTApiZlRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) { + api := apis.TApiZl{} + r := v1.Group("/t-api-zl").Use(authMiddleware.MiddlewareFunc()).Use(middleware.AuthCheckRole()) + { + r.GET("", actions.PermissionAction(), api.GetPage) + r.GET("/:id", actions.PermissionAction(), api.Get) + r.POST("", api.Insert) + r.PUT("/:id", actions.PermissionAction(), api.Update) + r.DELETE("", api.Delete) + } +} \ No newline at end of file diff --git a/app/admin/router/t_order_reconciliation.go b/app/admin/router/t_order_reconciliation.go new file mode 100644 index 000000000..778121277 --- /dev/null +++ b/app/admin/router/t_order_reconciliation.go @@ -0,0 +1,30 @@ +package router + +import ( + "github.com/gin-gonic/gin" + jwt "github.com/go-admin-team/go-admin-core/sdk/pkg/jwtauth" + + "go-admin/app/admin/apis" + "go-admin/common/actions" + "go-admin/common/middleware" +) + +func init() { + routerCheckRole = append(routerCheckRole, registerOrderReconciliationRouter) +} + +// registerOrderReconciliationRouter +func registerOrderReconciliationRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) { + api := apis.OrderReconciliation{} + r := v1.Group("/order-reconciliation").Use(authMiddleware.MiddlewareFunc()).Use(middleware.AuthCheckRole()) + { + r.GET("", actions.PermissionAction(), api.GetPage) + r.GET("/:id", actions.PermissionAction(), api.Get) + r.POST("", api.Insert) + r.PUT("/:id", actions.PermissionAction(), api.Update) + r.DELETE("", api.Delete) + r.POST("/merge", api.Merge) + r.POST("/merge_wx", api.MergeWx) + r.POST("/scan_wx", api.ScanWx) + } +} diff --git a/app/admin/service/dto/t_api_zl.go b/app/admin/service/dto/t_api_zl.go new file mode 100644 index 000000000..7435878bc --- /dev/null +++ b/app/admin/service/dto/t_api_zl.go @@ -0,0 +1,121 @@ +package dto + +import ( + + "go-admin/app/admin/models" + "go-admin/common/dto" + common "go-admin/common/models" +) + +type TApiZlGetPageReq struct { + dto.Pagination `search:"-"` + TApiZlOrder +} + +type TApiZlOrder struct { + Id string `form:"idOrder" search:"type:order;column:id;table:t_api_zl"` + Code string `form:"codeOrder" search:"type:order;column:code;table:t_api_zl"` + Handle string `form:"handleOrder" search:"type:order;column:handle;table:t_api_zl"` + Title string `form:"titleOrder" search:"type:order;column:title;table:t_api_zl"` + Path string `form:"pathOrder" search:"type:order;column:path;table:t_api_zl"` + Type string `form:"typeOrder" search:"type:order;column:type;table:t_api_zl"` + Action string `form:"actionOrder" search:"type:order;column:action;table:t_api_zl"` + Req string `form:"reqOrder" search:"type:order;column:req;table:t_api_zl"` + Res string `form:"resOrder" search:"type:order;column:res;table:t_api_zl"` + ResError string `form:"resErrorOrder" search:"type:order;column:res_error;table:t_api_zl"` + CreatedAt string `form:"createdAtOrder" search:"type:order;column:created_at;table:t_api_zl"` + UpdatedAt string `form:"updatedAtOrder" search:"type:order;column:updated_at;table:t_api_zl"` + DeletedAt string `form:"deletedAtOrder" search:"type:order;column:deleted_at;table:t_api_zl"` + CreateBy string `form:"createByOrder" search:"type:order;column:create_by;table:t_api_zl"` + UpdateBy string `form:"updateByOrder" search:"type:order;column:update_by;table:t_api_zl"` + +} + +func (m *TApiZlGetPageReq) GetNeedSearch() interface{} { + return *m +} + +type TApiZlInsertReq struct { + Id int `json:"-" comment:"主键编码"` // 主键编码 + Code string `json:"code" comment:"业务编码"` + Handle string `json:"handle" comment:"handle"` + Title string `json:"title" comment:"标题"` + Path string `json:"path" comment:"地址"` + Type string `json:"type" comment:"接口类型"` + Action string `json:"action" comment:"请求类型"` + Req string `json:"req" comment:"请求入参"` + Res string `json:"res" comment:"响应参数"` + ResError string `json:"resError" comment:"错误返回"` + common.ControlBy +} + +func (s *TApiZlInsertReq) Generate(model *models.TApiZl) { + if s.Id == 0 { + model.Model = common.Model{ Id: s.Id } + } + model.Code = s.Code + model.Handle = s.Handle + model.Title = s.Title + model.Path = s.Path + model.Type = s.Type + model.Action = s.Action + model.Req = s.Req + model.Res = s.Res + model.ResError = s.ResError + model.CreateBy = s.CreateBy // 添加这而,需要记录是被谁创建的 +} + +func (s *TApiZlInsertReq) GetId() interface{} { + return s.Id +} + +type TApiZlUpdateReq struct { + Id int `uri:"id" comment:"主键编码"` // 主键编码 + Code string `json:"code" comment:"业务编码"` + Handle string `json:"handle" comment:"handle"` + Title string `json:"title" comment:"标题"` + Path string `json:"path" comment:"地址"` + Type string `json:"type" comment:"接口类型"` + Action string `json:"action" comment:"请求类型"` + Req string `json:"req" comment:"请求入参"` + Res string `json:"res" comment:"响应参数"` + ResError string `json:"resError" comment:"错误返回"` + common.ControlBy +} + +func (s *TApiZlUpdateReq) Generate(model *models.TApiZl) { + if s.Id == 0 { + model.Model = common.Model{ Id: s.Id } + } + model.Code = s.Code + model.Handle = s.Handle + model.Title = s.Title + model.Path = s.Path + model.Type = s.Type + model.Action = s.Action + model.Req = s.Req + model.Res = s.Res + model.ResError = s.ResError + model.UpdateBy = s.UpdateBy // 添加这而,需要记录是被谁更新的 +} + +func (s *TApiZlUpdateReq) GetId() interface{} { + return s.Id +} + +// TApiZlGetReq 功能获取请求参数 +type TApiZlGetReq struct { + Id int `uri:"id"` +} +func (s *TApiZlGetReq) GetId() interface{} { + return s.Id +} + +// TApiZlDeleteReq 功能删除请求参数 +type TApiZlDeleteReq struct { + Ids []int `json:"ids"` +} + +func (s *TApiZlDeleteReq) GetId() interface{} { + return s.Ids +} diff --git a/app/admin/service/dto/t_order_reconciliation.go b/app/admin/service/dto/t_order_reconciliation.go new file mode 100644 index 000000000..a32e2243f --- /dev/null +++ b/app/admin/service/dto/t_order_reconciliation.go @@ -0,0 +1,230 @@ +package dto + +import ( + "time" + + "go-admin/app/admin/models" + "go-admin/common/dto" + common "go-admin/common/models" +) + +type OrderReconciliationGetPageReq struct { + dto.Pagination `search:"-"` + OrderReconciliationOrder +} + +type OrderReconciliationOrder struct { + Id string `form:"idOrder" search:"type:order;column:id;table:t_order_reconciliation"` + ProductName string `form:"productNameOrder" search:"type:order;column:product_name;table:t_order_reconciliation"` + ProductCategoryId string `form:"productCategoryIdOrder" search:"type:order;column:product_category_id;table:t_order_reconciliation"` + ProductCategoryName string `form:"productCategoryNameOrder" search:"type:order;column:product_category_name;table:t_order_reconciliation"` + PaymentTypeId string `form:"paymentTypeIdOrder" search:"type:order;column:payment_type_id;table:t_order_reconciliation"` + PaymentTypeName string `form:"paymentTypeNameOrder" search:"type:order;column:payment_type_name;table:t_order_reconciliation"` + TransactionSceneId string `form:"transactionSceneIdOrder" search:"type:order;column:transaction_scene_id;table:t_order_reconciliation"` + TransactionSceneName string `form:"transactionSceneNameOrder" search:"type:order;column:transaction_scene_name;table:t_order_reconciliation"` + OrderNumber string `form:"orderNumberOrder" search:"type:order;column:order_number;table:t_order_reconciliation"` + TransactionSerialNumber string `form:"transactionSerialNumberOrder" search:"type:order;column:transaction_serial_number;table:t_order_reconciliation"` + CentralSettlementNumber string `form:"centralSettlementNumberOrder" search:"type:order;column:central_settlement_number;table:t_order_reconciliation"` + BankOrderNumber string `form:"bankOrderNumberOrder" search:"type:order;column:bank_order_number;table:t_order_reconciliation"` + UserId string `form:"userIdOrder" search:"type:order;column:user_id;table:t_order_reconciliation"` + UserName string `form:"userNameOrder" search:"type:order;column:user_name;table:t_order_reconciliation"` + Openid string `form:"openidOrder" search:"type:order;column:openid;table:t_order_reconciliation"` + UserAccount string `form:"userAccountOrder" search:"type:order;column:user_account;table:t_order_reconciliation"` + SystemOrderAmount string `form:"systemOrderAmountOrder" search:"type:order;column:system_order_amount;table:t_order_reconciliation"` + MerchantOrderAmount string `form:"merchantOrderAmountOrder" search:"type:order;column:merchant_order_amount;table:t_order_reconciliation"` + CentralAmount string `form:"centralAmountOrder" search:"type:order;column:central_amount;table:t_order_reconciliation"` + SystemRefundAmount string `form:"systemRefundAmountOrder" search:"type:order;column:system_refund_amount;table:t_order_reconciliation"` + MerchantRefundAmount string `form:"merchantRefundAmountOrder" search:"type:order;column:merchant_refund_amount;table:t_order_reconciliation"` + MerchantActualRefundAmount string `form:"merchantActualRefundAmountOrder" search:"type:order;column:merchant_actual_refund_amount;table:t_order_reconciliation"` + MerchantTransactionStatusId string `form:"merchantTransactionStatusIdOrder" search:"type:order;column:merchant_transaction_status_id;table:t_order_reconciliation"` + MerchantTransactionStatusName string `form:"merchantTransactionStatusNameOrder" search:"type:order;column:merchant_transaction_status_name;table:t_order_reconciliation"` + SystemTransactionStatusId string `form:"systemTransactionStatusIdOrder" search:"type:order;column:system_transaction_status_id;table:t_order_reconciliation"` + SystemTransactionStatusName string `form:"systemTransactionStatusNameOrder" search:"type:order;column:system_transaction_status_name;table:t_order_reconciliation"` + CentralTransactionStatusId string `form:"centralTransactionStatusIdOrder" search:"type:order;column:central_transaction_status_id;table:t_order_reconciliation"` + CentralTransactionStatusName string `form:"centralTransactionStatusNameOrder" search:"type:order;column:central_transaction_status_name;table:t_order_reconciliation"` + CentralSettlementMethodId string `form:"centralSettlementMethodIdOrder" search:"type:order;column:central_settlement_method_id;table:t_order_reconciliation"` + CentralSettlementMethodName string `form:"centralSettlementMethodNameOrder" search:"type:order;column:central_settlement_method_name;table:t_order_reconciliation"` + OrderCreationTime string `form:"orderCreationTimeOrder" search:"type:order;column:order_creation_time;table:t_order_reconciliation"` + TransactionTime string `form:"transactionTimeOrder" search:"type:order;column:transaction_time;table:t_order_reconciliation"` + OperatorName string `form:"operatorNameOrder" search:"type:order;column:operator_name;table:t_order_reconciliation"` +} + +func (m *OrderReconciliationGetPageReq) GetNeedSearch() interface{} { + return *m +} + +type OrderReconciliationInsertReq struct { + Id int `json:"-" comment:"主键ID"` // 主键ID + ProductName string `json:"productName" comment:"商品名称"` + ProductCategoryId string `json:"productCategoryId" comment:"商品分类ID"` + ProductCategoryName string `json:"productCategoryName" comment:"商品分类名称"` + PaymentTypeId string `json:"paymentTypeId" comment:"支付类型ID"` + PaymentTypeName string `json:"paymentTypeName" comment:"支付类型名称"` + TransactionSceneId string `json:"transactionSceneId" comment:"交易场景ID"` + TransactionSceneName string `json:"transactionSceneName" comment:"交易场景名称"` + OrderNumber string `json:"orderNumber" comment:"订单号"` + TransactionSerialNumber string `json:"transactionSerialNumber" comment:"交易流水号"` + CentralSettlementNumber string `json:"centralSettlementNumber" comment:"中联结算号"` + BankOrderNumber string `json:"bankOrderNumber" comment:"银行订单号"` + UserId string `json:"userId" comment:"用户ID"` + UserName string `json:"userName" comment:"用户名称"` + Openid string `json:"openid" comment:"OpenID"` + UserAccount string `json:"userAccount" comment:"用户账户"` + SystemOrderAmount string `json:"systemOrderAmount" comment:"系统订单金额"` + MerchantOrderAmount string `json:"merchantOrderAmount" comment:"商家订单金额"` + CentralAmount string `json:"centralAmount" comment:"中联金额"` + SystemRefundAmount string `json:"systemRefundAmount" comment:"系统退款金额"` + MerchantRefundAmount string `json:"merchantRefundAmount" comment:"商家退款金额"` + MerchantActualRefundAmount string `json:"merchantActualRefundAmount" comment:"商家实退金额"` + MerchantTransactionStatusId string `json:"merchantTransactionStatusId" comment:"商家交易状态ID"` + MerchantTransactionStatusName string `json:"merchantTransactionStatusName" comment:"商家交易状态名称"` + SystemTransactionStatusId string `json:"systemTransactionStatusId" comment:"系统交易状态ID"` + SystemTransactionStatusName string `json:"systemTransactionStatusName" comment:"系统交易状态名称"` + CentralTransactionStatusId string `json:"centralTransactionStatusId" comment:"中联交易状态ID"` + CentralTransactionStatusName string `json:"centralTransactionStatusName" comment:"中联交易状态名称"` + CentralSettlementMethodId string `json:"centralSettlementMethodId" comment:"中联结算方式ID"` + CentralSettlementMethodName string `json:"centralSettlementMethodName" comment:"中联结算方式名称"` + OrderCreationTime time.Time `json:"orderCreationTime" comment:"订单创建时间"` + TransactionTime time.Time `json:"transactionTime" comment:"交易时间"` + OperatorName string `json:"operatorName" comment:"操作员姓名"` + common.ControlBy +} + +func (s *OrderReconciliationInsertReq) Generate(model *models.OrderReconciliation) { + if s.Id == 0 { + model.Model = common.Model{Id: s.Id} + } + model.ProductName = s.ProductName + model.ProductCategoryId = s.ProductCategoryId + model.ProductCategoryName = s.ProductCategoryName + model.PaymentTypeId = s.PaymentTypeId + model.PaymentTypeName = s.PaymentTypeName + model.TransactionSceneId = s.TransactionSceneId + model.TransactionSceneName = s.TransactionSceneName + model.OrderNumber = s.OrderNumber + model.TransactionSerialNumber = s.TransactionSerialNumber + model.CentralSettlementNumber = s.CentralSettlementNumber + model.BankOrderNumber = s.BankOrderNumber + model.UserId = s.UserId + model.UserName = s.UserName + model.Openid = s.Openid + model.UserAccount = s.UserAccount + model.SystemOrderAmount = s.SystemOrderAmount + model.MerchantOrderAmount = s.MerchantOrderAmount + model.CentralAmount = s.CentralAmount + model.SystemRefundAmount = s.SystemRefundAmount + model.MerchantRefundAmount = s.MerchantRefundAmount + model.MerchantActualRefundAmount = s.MerchantActualRefundAmount + model.MerchantTransactionStatusId = s.MerchantTransactionStatusId + model.MerchantTransactionStatusName = s.MerchantTransactionStatusName + model.SystemTransactionStatusId = s.SystemTransactionStatusId + model.SystemTransactionStatusName = s.SystemTransactionStatusName + model.CentralTransactionStatusId = s.CentralTransactionStatusId + model.CentralTransactionStatusName = s.CentralTransactionStatusName + model.CentralSettlementMethodId = s.CentralSettlementMethodId + model.CentralSettlementMethodName = s.CentralSettlementMethodName + model.OrderCreationTime = s.OrderCreationTime + model.TransactionTime = s.TransactionTime + model.OperatorName = s.OperatorName +} + +func (s *OrderReconciliationInsertReq) GetId() interface{} { + return s.Id +} + +type OrderReconciliationUpdateReq struct { + Id int `uri:"id" comment:"主键ID"` // 主键ID + ProductName string `json:"productName" comment:"商品名称"` + ProductCategoryId string `json:"productCategoryId" comment:"商品分类ID"` + ProductCategoryName string `json:"productCategoryName" comment:"商品分类名称"` + PaymentTypeId string `json:"paymentTypeId" comment:"支付类型ID"` + PaymentTypeName string `json:"paymentTypeName" comment:"支付类型名称"` + TransactionSceneId string `json:"transactionSceneId" comment:"交易场景ID"` + TransactionSceneName string `json:"transactionSceneName" comment:"交易场景名称"` + OrderNumber string `json:"orderNumber" comment:"订单号"` + TransactionSerialNumber string `json:"transactionSerialNumber" comment:"交易流水号"` + CentralSettlementNumber string `json:"centralSettlementNumber" comment:"中联结算号"` + BankOrderNumber string `json:"bankOrderNumber" comment:"银行订单号"` + UserId string `json:"userId" comment:"用户ID"` + UserName string `json:"userName" comment:"用户名称"` + Openid string `json:"openid" comment:"OpenID"` + UserAccount string `json:"userAccount" comment:"用户账户"` + SystemOrderAmount string `json:"systemOrderAmount" comment:"系统订单金额"` + MerchantOrderAmount string `json:"merchantOrderAmount" comment:"商家订单金额"` + CentralAmount string `json:"centralAmount" comment:"中联金额"` + SystemRefundAmount string `json:"systemRefundAmount" comment:"系统退款金额"` + MerchantRefundAmount string `json:"merchantRefundAmount" comment:"商家退款金额"` + MerchantActualRefundAmount string `json:"merchantActualRefundAmount" comment:"商家实退金额"` + MerchantTransactionStatusId string `json:"merchantTransactionStatusId" comment:"商家交易状态ID"` + MerchantTransactionStatusName string `json:"merchantTransactionStatusName" comment:"商家交易状态名称"` + SystemTransactionStatusId string `json:"systemTransactionStatusId" comment:"系统交易状态ID"` + SystemTransactionStatusName string `json:"systemTransactionStatusName" comment:"系统交易状态名称"` + CentralTransactionStatusId string `json:"centralTransactionStatusId" comment:"中联交易状态ID"` + CentralTransactionStatusName string `json:"centralTransactionStatusName" comment:"中联交易状态名称"` + CentralSettlementMethodId string `json:"centralSettlementMethodId" comment:"中联结算方式ID"` + CentralSettlementMethodName string `json:"centralSettlementMethodName" comment:"中联结算方式名称"` + OrderCreationTime time.Time `json:"orderCreationTime" comment:"订单创建时间"` + TransactionTime time.Time `json:"transactionTime" comment:"交易时间"` + OperatorName string `json:"operatorName" comment:"操作员姓名"` + common.ControlBy +} + +func (s *OrderReconciliationUpdateReq) Generate(model *models.OrderReconciliation) { + if s.Id == 0 { + model.Model = common.Model{Id: s.Id} + } + model.ProductName = s.ProductName + model.ProductCategoryId = s.ProductCategoryId + model.ProductCategoryName = s.ProductCategoryName + model.PaymentTypeId = s.PaymentTypeId + model.PaymentTypeName = s.PaymentTypeName + model.TransactionSceneId = s.TransactionSceneId + model.TransactionSceneName = s.TransactionSceneName + model.OrderNumber = s.OrderNumber + model.TransactionSerialNumber = s.TransactionSerialNumber + model.CentralSettlementNumber = s.CentralSettlementNumber + model.BankOrderNumber = s.BankOrderNumber + model.UserId = s.UserId + model.UserName = s.UserName + model.Openid = s.Openid + model.UserAccount = s.UserAccount + model.SystemOrderAmount = s.SystemOrderAmount + model.MerchantOrderAmount = s.MerchantOrderAmount + model.CentralAmount = s.CentralAmount + model.SystemRefundAmount = s.SystemRefundAmount + model.MerchantRefundAmount = s.MerchantRefundAmount + model.MerchantActualRefundAmount = s.MerchantActualRefundAmount + model.MerchantTransactionStatusId = s.MerchantTransactionStatusId + model.MerchantTransactionStatusName = s.MerchantTransactionStatusName + model.SystemTransactionStatusId = s.SystemTransactionStatusId + model.SystemTransactionStatusName = s.SystemTransactionStatusName + model.CentralTransactionStatusId = s.CentralTransactionStatusId + model.CentralTransactionStatusName = s.CentralTransactionStatusName + model.CentralSettlementMethodId = s.CentralSettlementMethodId + model.CentralSettlementMethodName = s.CentralSettlementMethodName + model.OrderCreationTime = s.OrderCreationTime + model.TransactionTime = s.TransactionTime + model.OperatorName = s.OperatorName +} + +func (s *OrderReconciliationUpdateReq) GetId() interface{} { + return s.Id +} + +// OrderReconciliationGetReq 功能获取请求参数 +type OrderReconciliationGetReq struct { + Id int `uri:"id"` +} + +func (s *OrderReconciliationGetReq) GetId() interface{} { + return s.Id +} + +// OrderReconciliationDeleteReq 功能删除请求参数 +type OrderReconciliationDeleteReq struct { + Ids []int `json:"ids"` +} + +func (s *OrderReconciliationDeleteReq) GetId() interface{} { + return s.Ids +} diff --git a/app/admin/service/t_api_zl.go b/app/admin/service/t_api_zl.go new file mode 100644 index 000000000..a22a1a54b --- /dev/null +++ b/app/admin/service/t_api_zl.go @@ -0,0 +1,109 @@ +package service + +import ( + "errors" + + "github.com/go-admin-team/go-admin-core/sdk/service" + "gorm.io/gorm" + + "go-admin/app/admin/models" + "go-admin/app/admin/service/dto" + "go-admin/common/actions" + cDto "go-admin/common/dto" +) + +type TApiZl struct { + service.Service +} + +// GetPage 获取TApiZl列表 +func (e *TApiZl) GetPage(c *dto.TApiZlGetPageReq, p *actions.DataPermission, list *[]models.TApiZl, count *int64) error { + var err error + var data models.TApiZl + + err = e.Orm.Model(&data). + Scopes( + cDto.MakeCondition(c.GetNeedSearch()), + cDto.Paginate(c.GetPageSize(), c.GetPageIndex()), + actions.Permission(data.TableName(), p), + ). + Find(list).Limit(-1).Offset(-1). + Count(count).Error + if err != nil { + e.Log.Errorf("TApiZlService GetPage error:%s \r\n", err) + return err + } + return nil +} + +// Get 获取TApiZl对象 +func (e *TApiZl) Get(d *dto.TApiZlGetReq, p *actions.DataPermission, model *models.TApiZl) error { + var data models.TApiZl + + err := e.Orm.Model(&data). + Scopes( + actions.Permission(data.TableName(), p), + ). + First(model, d.GetId()).Error + if err != nil && errors.Is(err, gorm.ErrRecordNotFound) { + err = errors.New("查看对象不存在或无权查看") + e.Log.Errorf("Service GetTApiZl error:%s \r\n", err) + return err + } + if err != nil { + e.Log.Errorf("db error:%s", err) + return err + } + return nil +} + +// Insert 创建TApiZl对象 +func (e *TApiZl) Insert(c *dto.TApiZlInsertReq) error { + var err error + var data models.TApiZl + c.Generate(&data) + err = e.Orm.Create(&data).Error + if err != nil { + e.Log.Errorf("TApiZlService Insert error:%s \r\n", err) + return err + } + return nil +} + +// Update 修改TApiZl对象 +func (e *TApiZl) Update(c *dto.TApiZlUpdateReq, p *actions.DataPermission) error { + var err error + var data = models.TApiZl{} + e.Orm.Scopes( + actions.Permission(data.TableName(), p), + ).First(&data, c.GetId()) + c.Generate(&data) + + db := e.Orm.Save(&data) + if err = db.Error; err != nil { + e.Log.Errorf("TApiZlService Save error:%s \r\n", err) + return err + } + if db.RowsAffected == 0 { + return errors.New("无权更新该数据") + } + return nil +} + +// Remove 删除TApiZl +func (e *TApiZl) Remove(d *dto.TApiZlDeleteReq, p *actions.DataPermission) error { + var data models.TApiZl + + db := e.Orm.Model(&data). + Scopes( + actions.Permission(data.TableName(), p), + ).Delete(&data, d.GetId()) + if err := db.Error; err != nil { + e.Log.Errorf("Service RemoveTApiZl error:%s \r\n", err) + return err + } + if db.RowsAffected == 0 { + return errors.New("无权删除该数据") + } + return nil +} diff --git a/app/admin/service/t_order_reconciliation.go b/app/admin/service/t_order_reconciliation.go new file mode 100644 index 000000000..93fdee84d --- /dev/null +++ b/app/admin/service/t_order_reconciliation.go @@ -0,0 +1,552 @@ +package service + +import ( + "encoding/json" + "errors" + "fmt" + "log" + "os" + "sync" + "time" + + "github.com/gin-gonic/gin" + "github.com/go-admin-team/go-admin-core/sdk" + "github.com/go-admin-team/go-admin-core/sdk/service" + "github.com/go-admin-team/go-admin-core/storage" + "gorm.io/driver/mysql" + "gorm.io/gorm" + "gorm.io/gorm/logger" + + "go-admin/app/admin/models" + "go-admin/app/admin/service/dto" + "go-admin/common/actions" + cDto "go-admin/common/dto" + "go-admin/common/global" + + adminLogger "github.com/go-admin-team/go-admin-core/logger" + "github.com/mitchellh/mapstructure" +) + +type OrderReconciliation struct { + service.Service + OrderDB *gorm.DB +} + +func (e *OrderReconciliation) InitDB() { + if err := e.InitOrderDB(); err != nil { + log.Fatalf("Failed to initialize database: %v", err) + } + log.Println("Database initialized.") +} + +// GetPage 获取OrderReconciliation列表 +func (e *OrderReconciliation) GetPage(c *dto.OrderReconciliationGetPageReq, p *actions.DataPermission, list *[]models.OrderReconciliation, count *int64) error { + var err error + var data models.OrderReconciliation + + err = e.Orm.Model(&data). + Scopes( + cDto.MakeCondition(c.GetNeedSearch()), + cDto.Paginate(c.GetPageSize(), c.GetPageIndex()), + actions.Permission(data.TableName(), p), + ). + Find(list).Limit(-1).Offset(-1). + Count(count).Error + if err != nil { + e.Log.Errorf("OrderReconciliationService GetPage error:%s \r\n", err) + return err + } + return nil +} + +// Get 获取OrderReconciliation对象 +func (e *OrderReconciliation) Get(d *dto.OrderReconciliationGetReq, p *actions.DataPermission, model *models.OrderReconciliation) error { + var data models.OrderReconciliation + + err := e.Orm.Model(&data). + Scopes( + actions.Permission(data.TableName(), p), + ). + First(model, d.GetId()).Error + if err != nil && errors.Is(err, gorm.ErrRecordNotFound) { + err = errors.New("查看对象不存在或无权查看") + e.Log.Errorf("Service GetOrderReconciliation error:%s \r\n", err) + return err + } + if err != nil { + e.Log.Errorf("db error:%s", err) + return err + } + return nil +} + +// Insert 创建OrderReconciliation对象 +func (e *OrderReconciliation) Insert(c *dto.OrderReconciliationInsertReq) error { + var err error + var data models.OrderReconciliation + c.Generate(&data) + err = e.Orm.Create(&data).Error + if err != nil { + e.Log.Errorf("OrderReconciliationService Insert error:%s \r\n", err) + return err + } + return nil +} + +// Update 修改OrderReconciliation对象 +func (e *OrderReconciliation) Update(c *dto.OrderReconciliationUpdateReq, p *actions.DataPermission) error { + var err error + var data = models.OrderReconciliation{} + e.Orm.Scopes( + actions.Permission(data.TableName(), p), + ).First(&data, c.GetId()) + c.Generate(&data) + + db := e.Orm.Save(&data) + if err = db.Error; err != nil { + e.Log.Errorf("OrderReconciliationService Save error:%s \r\n", err) + return err + } + if db.RowsAffected == 0 { + return errors.New("无权更新该数据") + } + return nil +} + +// Remove 删除OrderReconciliation +func (e *OrderReconciliation) Remove(d *dto.OrderReconciliationDeleteReq, p *actions.DataPermission) error { + var data models.OrderReconciliation + + db := e.Orm.Model(&data). + Scopes( + actions.Permission(data.TableName(), p), + ).Delete(&data, d.GetId()) + if err := db.Error; err != nil { + e.Log.Errorf("Service RemoveOrderReconciliation error:%s \r\n", err) + return err + } + if db.RowsAffected == 0 { + return errors.New("无权删除该数据") + } + return nil +} + +func (e *OrderReconciliation) MergeData() (logZfbNotify []*models.LogZfbNotify, err error) { + err = e.OrderDB.Find(&logZfbNotify).Error + + for _, l := range logZfbNotify { + l.ParmMap, err = l.ParseParm() + if err != nil { + continue + } + if msg, ok := l.ParmMap["msg"]; ok && msg.(string) == "退款成功" { + if data, ok1 := l.ParmMap["data"]; ok1 { + l.ParmMap = data.(map[string]interface{}) + } + + } + //l.ParmMap中map key为gmt_create,gmt_payment,notify_time转成time.Time类型 + for k, v := range l.ParmMap { + if l.Type == "挂号退款" || l.Type == "门诊缴费退款" || l.Type == "住院预缴退费" || l.Type == "挂号医保退款" { + if k == "gmt_refund_pay" { + t, err := time.Parse("2006-01-02 15:04:05", v.(string)) + if err != nil { + continue + } + l.ParmMap[k] = t + } + } else { + if k == "gmt_create" || k == "gmt_payment" || k == "notify_time" { + t, err := time.Parse("2006-01-02 15:04:05", v.(string)) + if err != nil { + continue + } + l.ParmMap[k] = t + } + } + + } + } + + //把logZfbNotify中的ParmMap中的数据批量并发插入到AlipayNotify表中 + var wg sync.WaitGroup + wg.Add(len(logZfbNotify)) + for _, l := range logZfbNotify { + go func(l *models.LogZfbNotify) { + defer wg.Done() + tx := e.OrderDB.Begin() + //l.Type == "挂号医保退款" 暂不支持 + if l.Type == "挂号退款" || l.Type == "门诊缴费退款" || l.Type == "住院预缴退费" || l.Type == "挂号医保退款" { + var AlipayRefundNotify models.AlipayRefundNotify + //l.ParmMap["refund_detail_item_list"]转成json字符串 + if details, ok := l.ParmMap["refund_detail_item_list"]; ok { + l.ParmMap["refund_details"], _ = json.Marshal(details) + //删除refund_detail_item_list + delete(l.ParmMap, "refund_detail_item_list") + } + // 将map中的数据存储到AlipayNotify结构体中 + err := mapstructure.WeakDecode(l.ParmMap, &AlipayRefundNotify) + if err != nil { + return + } + if AlipayRefundNotify.OutTradeNo == "" { + return + } + AlipayRefundNotify.TypeName = l.Type + err = tx.Create(&AlipayRefundNotify).Error + if err != nil { + tx.Rollback() + } + } else { + var AlipayNotify models.AlipayNotify + + // 将map中的数据存储到AlipayNotify结构体中 + err := mapstructure.WeakDecode(l.ParmMap, &AlipayNotify) + if err != nil { + return + } + if AlipayNotify.OutTradeNo == "" { + return + } + AlipayNotify.TypeName = l.Type + err = tx.Create(&AlipayNotify).Error + if err != nil { + tx.Rollback() + } + } + + tx.Commit() + }(l) + } + wg.Wait() + + return logZfbNotify, err +} + +func (e *OrderReconciliation) MergeDataWx(c *gin.Context) error { + l := make(map[string]interface{}) + l["pageIndex"] = 2 + l["pageSize"] = 30 + q := sdk.Runtime.GetMemoryQueue(c.Request.Host) + message, err := sdk.Runtime.GetStreamMessage("", global.RhOrder, l) + if err != nil { + adminLogger.Errorf("GetStreamMessage error, %s", err.Error()) + //报错错误,不中断请求 + } else { + err = q.Append(message) + if err != nil { + adminLogger.Errorf("Append message error, %s", err.Error()) + } + } + return err +} + +func (e *OrderReconciliation) MergeDataWxQueue() (logWxNotify []*models.LogWxNotify, err error) { + + err = e.OrderDB.Find(&logWxNotify).Error + + for _, l := range logWxNotify { + l.ParmMap, err = l.ParseParm() + if err != nil { + continue + } + for k, v := range l.ParmMap { + if k == "success_time" { + t, err := time.Parse(time.RFC3339, v.(string)) + if err != nil { + continue + } + l.ParmMap[k] = t + } + } + } + + //把logWxNotify中的ParmMap中的数据批量并发插入到WechatNotify表中 + // var wg sync.WaitGroup + // wg.Add(len(logWxNotify)) + var WechatRefundNotifys []models.WxRefundNotify + var WechatNotifys []models.WxNotify + tx := e.OrderDB.Session(&gorm.Session{}) + refoundSize := 0 + paySize := 0 + payIds := make([]int, 0) + for _, l := range logWxNotify { + // go func(l *models.LogWxNotify) { + //defer wg.Done() + if outRefundNo, ok := l.ParmMap["out_refund_no"]; ok { + outRefundNo = outRefundNo.(string) + var WechatRefundNotify models.WxRefundNotify + if outRefundNo == "" { + refoundSize++ + continue + //adminLogger.Errorf("rollback err, %s", err.Error()) + } + amount := l.ParmMap["amount"].(map[string]interface{}) + WechatRefundNotify.Total = int(amount["total"].(float64)) + WechatRefundNotify.Refund = int(amount["refund"].(float64)) + WechatRefundNotify.PayerTotal = int(amount["payer_total"].(float64)) + WechatRefundNotify.PayerRefund = int(amount["payer_refund"].(float64)) + + //l.ParmMap["refund_detail_item_list"]转成json字符串 + // if details, ok := l.ParmMap["refund_detail_item_list"]; ok { + // l.ParmMap["refund_details"], _ = json.Marshal(details) + // //删除refund_detail_item_list + // delete(l.ParmMap, "refund_detail_item_list") + // } + // 将map中的数据存储到WechatNotify结构体中 + err := mapstructure.WeakDecode(l.ParmMap, &WechatRefundNotify) + if err != nil { + refoundSize++ + adminLogger.Errorf("WeakDecode err, %s", err.Error()) + continue + } + typeName := l.Type + if l.Type == "微信回调" { + typeName = "微信退款回调" + } + WechatRefundNotify.TypeName = typeName + WechatRefundNotifys = append(WechatRefundNotifys, WechatRefundNotify) + } else { + var WechatNotify models.WxNotify + + // 将map中的数据存储到WechatNotify结构体中 + err := mapstructure.WeakDecode(l.ParmMap, &WechatNotify) + if err != nil { + paySize++ + adminLogger.Errorf("WeakDecode err, %s", err.Error()) + continue + } + if WechatNotify.OutTradeNo == "" { + paySize++ + payIds = append(payIds, l.Id) + //adminLogger.Errorf("OutTradeNo err, %s", err.Error()) + continue + } + + amount := l.ParmMap["amount"].(map[string]interface{}) + WechatNotify.Total = int(amount["total"].(float64)) + WechatNotify.Currency = amount["currency"].(string) + WechatNotify.PayerTotal = int(amount["payer_total"].(float64)) + WechatNotify.PayerCurrency = amount["payer_currency"].(string) + + WechatNotify.TypeName = l.Type + WechatNotifys = append(WechatNotifys, WechatNotify) + } + //}(l) + } + //循环每次插入100条数据 + batchSize := 100 + var wg sync.WaitGroup + errCh := make(chan error, 2) // Channel to receive errors + + // Batch creation for WechatRefundNotifys + for i := 0; i < len(WechatRefundNotifys); i += batchSize { + end := i + batchSize + if end > len(WechatRefundNotifys) { + end = len(WechatRefundNotifys) + } + wg.Add(1) + go func(start, end int) { + defer wg.Done() + err := tx.CreateInBatches(WechatRefundNotifys[start:end], len(WechatRefundNotifys[start:end])).Error + if err != nil { + errCh <- err + } + }(i, end) + time.Sleep(500 * time.Millisecond) + } + + // Batch creation for WechatNotifys + for i := 0; i < len(WechatNotifys); i += batchSize { + end := i + batchSize + if end > len(WechatNotifys) { + end = len(WechatNotifys) + } + // if i > 12000 { + // adminLogger.Errorf("12000") + // } + wg.Add(1) + go func(start, end int) { + defer wg.Done() + err := tx.CreateInBatches(WechatNotifys[start:end], len(WechatNotifys[start:end])).Error + if err != nil { + errCh <- err + } + }(i, end) + time.Sleep(500 * time.Millisecond) + } + + // Wait for all goroutines to finish + wg.Wait() + + // Check for errors + select { + case err := <-errCh: + adminLogger.Errorf("Batch creation failed, %s", err.Error()) + tx.Rollback() + default: + // No errors, commit the transaction + adminLogger.Info("refoundSize: %d, paySize: %d, payIds: %v", refoundSize, paySize, payIds) + tx.Commit() + } + + return logWxNotify, err +} + +func (e *OrderReconciliation) ScanWx() (logWxNotify []*models.LogWxScanNotify, err error) { + if err = e.OrderDB.Find(&logWxNotify).Error; err != nil { + return nil, err + } + + for _, l := range logWxNotify { + l.ResultMap, err = l.ParseForResult() + if err != nil { + continue + } + l.ParmMap, err = l.ParseParm() + if err != nil { + continue + } + l.DataMap, err = l.ParseForData() + if err != nil { + continue + } + if returnCode, ok := l.ResultMap["return_code"]; ok && returnCode.(string) == "SUCCESS" { + if resultCode, ok1 := l.ResultMap["result_code"]; ok1 && resultCode.(string) == "SUCCESS" { + l.ResultSuccessMap = l.ResultMap + for k, v := range l.ResultSuccessMap { + if k == "time_end" { + t, err := time.Parse("20060102150405", v.(string)) + if err != nil { + fmt.Println("Failed to parse time:", err) + continue + } + l.ResultSuccessMap[k] = t + } + } + for _, _ = range l.ParmMap { + l.ParmMap["time"] = l.Time + } + for _, _ = range l.DataMap { + l.DataMap["time"] = l.Time + } + } + } + } + + var wg sync.WaitGroup + tx := e.OrderDB.Session(&gorm.Session{}) + tx.Begin() + defer func() { + if r := recover(); r != nil { + tx.Rollback() + } + if err != nil { + tx.Rollback() + } else { + tx.Commit() + } + }() + + wg.Add(len(logWxNotify)) + for _, l := range logWxNotify { + go func(l *models.LogWxScanNotify) { + defer wg.Done() + if l.ResultSuccessMap != nil { + var result models.WxScanResult + if err := mapstructure.WeakDecode(l.ResultSuccessMap, &result); err != nil { + fmt.Printf("Decode ResultSuccessMap failed: %v\n", err) + return + } + if err := tx.Create(&result).Error; err != nil { + fmt.Printf("Create models.WxScanResult failed: %v\n", err) + return + } + var parm models.WxScanParm + if err := mapstructure.WeakDecode(l.ParmMap, &parm); err != nil { + fmt.Printf("Decode WxScanParm failed: %v\n", err) + return + } + parm.AuthCode = l.ParmMap["AuthCode"].(string) + parm.OrderID = l.ParmMap["OrderId"].(string) + parm.PayType = int8(l.ParmMap["PayType"].(float64)) + parm.UserID = l.ParmMap["UserID"].(string) + if err := tx.Create(&parm).Error; err != nil { + fmt.Printf("Create models.WxScanParm failed: %v\n", err) + return + } + var data models.WxScan + if err := mapstructure.WeakDecode(l.DataMap, &data); err != nil { + fmt.Printf("Decode WxScanData failed: %v\n", err) + return + } + if err := tx.Create(&data).Error; err != nil { + fmt.Printf("Create models.WxScanData failed: %v\n", err) + return + } + } + }(l) + time.Sleep(100 * time.Millisecond) // 避免 goroutine 并行执行导致数据插入顺序不一致 + } + wg.Wait() + + return logWxNotify, nil +} + +func (e *OrderReconciliation) InitOrderDB() error { + dsn := "root:lg87516@tcp(127.0.0.1:3306)/rhhy_recon?charset=utf8mb4&parseTime=True&loc=Local" + db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{ + Logger: logger.New( + log.New(os.Stdout, "\r\n", log.LstdFlags), // io writer(日志输出的目标,前缀和日志包含的内容——译者注) + logger.Config{ + SlowThreshold: time.Second, // 慢 SQL 阈值 + LogLevel: logger.Info, // 日志级别 + IgnoreRecordNotFoundError: true, // 忽略ErrRecordNotFound(记录未找到)错误 + Colorful: false, // 禁用彩色打印 + }, + ), + }) + if err != nil { + panic("failed to connect database") + } + //db.AutoMigrate(&models.LogZfbNotify{}) + e.OrderDB = db + return nil +} + +func SaveRhOrder(message storage.Messager) (err error) { + //准备db + // db := sdk.Runtime.GetDbByKey(message.GetPrefix()) + // if db == nil { + // err = errors.New("db not exist") + // log.Errorf("host[%s]'s %s", message.GetPrefix(), err.Error()) + // // Log writing to the database ignores error + // return nil + // } + var rb []byte + rb, err = json.Marshal(message.GetValues()) + if err != nil { + adminLogger.Errorf("json Marshal error, %s", err.Error()) + return err + } + var l dto.OrderReconciliationGetPageReq + err = json.Unmarshal(rb, &l) + if err != nil { + adminLogger.Errorf("json Unmarshal error, %s", err.Error()) + return err + } + s := OrderReconciliation{} + s.InitDB() + _, err = s.ScanWx() //微信扫码支付订单 + if err != nil { + adminLogger.Errorf("test error, %s", err.Error()) + return err + } + // _, err = s.MergeDataWxQueue() //微信支付回调订单 + // if err != nil { + // adminLogger.Errorf("test error, %s", err.Error()) + // return err + // } + + return nil +} diff --git a/cmd/api/server.go b/cmd/api/server.go index e1cb0a932..238538d93 100644 --- a/cmd/api/server.go +++ b/cmd/api/server.go @@ -3,13 +3,14 @@ package api import ( "context" "fmt" - "github.com/pkg/errors" "log" "net/http" "os" "os/signal" "time" + "github.com/pkg/errors" + "github.com/gin-gonic/gin" "github.com/go-admin-team/go-admin-core/config/source/file" "github.com/go-admin-team/go-admin-core/sdk" @@ -20,6 +21,7 @@ import ( "go-admin/app/admin/models" "go-admin/app/admin/router" + "go-admin/app/admin/service" "go-admin/app/jobs" "go-admin/common/database" "go-admin/common/global" @@ -70,6 +72,7 @@ func setup() { queue.Register(global.LoginLog, models.SaveLoginLog) queue.Register(global.OperateLog, models.SaveOperaLog) queue.Register(global.ApiCheck, models.SaveSysApi) + queue.Register(global.RhOrder, service.SaveRhOrder) go queue.Run() usageStr := `starting api server...` @@ -126,6 +129,7 @@ func run() error { } } }() + fmt.Println(pkg.Red(string(global.LogoContent))) tip() fmt.Println(pkg.Green("Server run at:")) diff --git a/cmd/migrate/migration/version-local/doc.go b/cmd/migrate/migration/version-local/doc.go index 2cec8bc41..f13c65da7 100644 --- a/cmd/migrate/migration/version-local/doc.go +++ b/cmd/migrate/migration/version-local/doc.go @@ -1,8 +1,41 @@ package version_local +import ( + "go-admin/app/admin/models" + common "go-admin/common/models" + "runtime" + + "github.com/go-admin-team/go-admin-core/sdk/config" + "gorm.io/gorm" + + "go-admin/cmd/migrate/migration" +) + func init() { + _, fileName, _, _ := runtime.Caller(0) + migration.Migrate.SetVersion(migration.GetFilename(fileName), _1653638869132Test) } -/** +/* +* 开发者项目的迁移脚本放在这个目录里,init写法参考version目录里的migrate或者自动生成 */ +func _1653638869132Test(db *gorm.DB, version string) error { + return db.Transaction(func(tx *gorm.DB) error { + if config.DatabaseConfig.Driver == "mysql" { + tx = tx.Set("gorm:table_options", "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4") + } + err := tx.Migrator().AutoMigrate( + new(models.TApiZl), + ) + if err != nil { + return err + } + // if err := models.InitDb(tx); err != nil { + // return err + // } + return tx.Create(&common.Migration{ + Version: version, + }).Error + }) +} diff --git a/cmd/migrate/server.go b/cmd/migrate/server.go index b1667ca67..563da2dcf 100644 --- a/cmd/migrate/server.go +++ b/cmd/migrate/server.go @@ -3,19 +3,22 @@ package migrate import ( "bytes" "fmt" - "github.com/go-admin-team/go-admin-core/sdk" - "github.com/go-admin-team/go-admin-core/sdk/pkg" "strconv" "text/template" "time" + "github.com/go-admin-team/go-admin-core/sdk" + "github.com/go-admin-team/go-admin-core/sdk/pkg" + "github.com/go-admin-team/go-admin-core/config/source/file" "github.com/spf13/cobra" - "github.com/go-admin-team/go-admin-core/sdk/config" "go-admin/cmd/migrate/migration" - _ "go-admin/cmd/migrate/migration/version" - _ "go-admin/cmd/migrate/migration/version-local" + + "github.com/go-admin-team/go-admin-core/sdk/config" + + // _ "go-admin/cmd/migrate/migration/version" + // _ "go-admin/cmd/migrate/migration/version-local" "go-admin/common/database" "go-admin/common/models" ) diff --git a/common/database/open.go b/common/database/open.go index de02868e4..1254e221a 100644 --- a/common/database/open.go +++ b/common/database/open.go @@ -3,6 +3,7 @@ package database import ( + "github.com/glebarez/sqlite" "gorm.io/driver/mysql" "gorm.io/driver/postgres" "gorm.io/driver/sqlserver" @@ -13,4 +14,5 @@ var opens = map[string]func(string) gorm.Dialector{ "mysql": mysql.Open, "postgres": postgres.Open, "sqlserver": sqlserver.Open, + "sqllite3": sqlite.Open, } diff --git a/common/global/topic.go b/common/global/topic.go index 60e1d34bf..63325972f 100644 --- a/common/global/topic.go +++ b/common/global/topic.go @@ -4,4 +4,5 @@ const ( LoginLog = "login_log_queue" OperateLog = "operate_log_queue" ApiCheck = "api_check_queue" + RhOrder = "rh_order_queue" ) diff --git a/common/middleware/customerror.go b/common/middleware/customerror.go index 1f9262879..7a928354e 100644 --- a/common/middleware/customerror.go +++ b/common/middleware/customerror.go @@ -4,6 +4,7 @@ import ( "fmt" "net/http" "runtime" + "runtime/debug" "strconv" "strings" "time" @@ -48,6 +49,9 @@ func CustomError(c *gin.Context) { }) } case runtime.Error: + // 打印错误堆栈 + fmt.Println("Stack trace:") + fmt.Println(string(debug.Stack())) c.JSON(http.StatusOK, gin.H{ "code": 500, "msg": errStr.Error(), diff --git a/config/settings.prod.yml b/config/settings.prod.yml new file mode 100644 index 000000000..4ced42b59 --- /dev/null +++ b/config/settings.prod.yml @@ -0,0 +1,75 @@ +settings: + application: + # dev开发环境 test测试环境 prod线上环境 + mode: prod + # 服务器ip,默认使用 0.0.0.0 + host: 0.0.0.0 + # 服务名称 + name: go-admin + # 端口号 + port: 8081 # 服务端口号 + readtimeout: 1 + writertimeout: 2 + # 数据权限功能开关 + enabledp: false + logger: + # 日志存放路径 + path: /www/log/go-admin + # 日志输出,file:文件,default:命令行,其他:命令行 + stdout: '' #控制台日志,启用后,不输出到文件 + # 日志等级, trace, debug, info, warn, error, fatal + level: trace + # 数据库日志开关 + enableddb: false + jwt: + # token 密钥,生产环境时及的修改 + secret: go-admin + # token 过期时间 单位:秒 + timeout: 3600 + database: + # 数据库类型 mysql, sqlite3, postgres, sqlserver + # sqlserver: sqlserver://用户名:密码@地址?database=数据库名 + driver: mysql + # 数据库连接字符串 mysql 缺省信息 charset=utf8&parseTime=True&loc=Local&timeout=1000ms + source: go-admin:d6XZzkspcw5i8s3B@tcp(47.119.129.191:3306)/go-admin?charset=utf8&parseTime=True&loc=Local&timeout=1000ms + # source: go-admin-db.db +# databases: +# 'locaohost:8000': +# driver: mysql +# # 数据库连接字符串 mysql 缺省信息 charset=utf8&parseTime=True&loc=Local&timeout=1000ms +# source: user:password@tcp(127.0.0.1:3306)/dbname?charset=utf8&parseTime=True&loc=Local&timeout=1000ms +# registers: +# - sources: +# - user:password@tcp(127.0.0.1:3306)/dbname?charset=utf8&parseTime=True&loc=Local&timeout=1000ms + gen: + # 代码生成读取的数据库名称 + dbname: go-admin + # 代码生成是使用前端代码存放位置,需要指定到src文件夹,相对路径 + frontpath: ../go-admin-ui/src + extend: # 扩展项使用说明 + demo: + name: data + cache: +# redis: +# addr: 127.0.0.1:6379 +# password: xxxxxx +# db: 2 + # key存在即可 + memory: '' + queue: + memory: + poolSize: 100 +# redis: +# addr: 127.0.0.1:6379 +# password: xxxxxx +# producer: +# streamMaxLength: 100 +# approximateMaxLength: true +# consumer: +# visibilityTimeout: 60 +# bufferSize: 100 +# concurrency: 10 +# blockingTimeout: 5 +# reclaimInterval: 1 + locker: + redis: \ No newline at end of file diff --git a/config/settings.sqlite.win.yml b/config/settings.sqlite.win.yml new file mode 100644 index 000000000..db88ee716 --- /dev/null +++ b/config/settings.sqlite.win.yml @@ -0,0 +1,38 @@ +settings: + application: + # dev开发环境 test测试环境 prod线上环境 + mode: dev + # 服务器ip,默认使用 0.0.0.0 + host: 0.0.0.0 + # 服务名称 + name: testApp + # 端口号 + port: 8000 # 服务端口号 + readtimeout: 3000 + writertimeout: 2000 + # 数据权限功能开关 + enabledp: false + logger: + # 日志存放路径 + path: D:\log\go-admin + # 日志输出,file:文件,default:命令行,其他:命令行 + stdout: '' #控制台日志,启用后,不输出到文件 + # 日志等级, trace, debug, info, warn, error, fatal + level: trace + # 数据库日志开关 + enableddb: false + jwt: + # token 密钥,生产环境时及的修改 + secret: go-admin + # token 过期时间 单位:秒 + timeout: 3600 + database: + # 数据库类型 mysql,sqlite3, postgres + driver: sqlite3 + # 数据库连接sqlite3数据文件的路径 + source: go-admin-db.db + gen: + # 代码生成读取的数据库名称 + dbname: dbname + # 代码生成是使用前端代码存放位置,需要指定到src文件夹,相对路径 + frontpath: ../go-admin-ui/src diff --git a/config/settings.test.yml b/config/settings.test.yml new file mode 100644 index 000000000..1e7e52910 --- /dev/null +++ b/config/settings.test.yml @@ -0,0 +1,75 @@ +settings: + application: + # dev开发环境 test测试环境 prod线上环境 + mode: test + # 服务器ip,默认使用 0.0.0.0 + host: 0.0.0.0 + # 服务名称 + name: lvgang-sandbox.buddy.cloud + # 端口号 + port: 80 # 服务端口号 + readtimeout: 1 + writertimeout: 2 + # 数据权限功能开关 + enabledp: false + logger: + # 日志存放路径 + path: /www/log/go-admin + # 日志输出,file:文件,default:命令行,其他:命令行 + stdout: '' #控制台日志,启用后,不输出到文件 + # 日志等级, trace, debug, info, warn, error, fatal + level: trace + # 数据库日志开关 + enableddb: false + jwt: + # token 密钥,生产环境时及的修改 + secret: go-admin + # token 过期时间 单位:秒 + timeout: 3600 + database: + # 数据库类型 mysql, sqlite3, postgres, sqlserver + # sqlserver: sqlserver://用户名:密码@地址?database=数据库名 + driver: mysql + # 数据库连接字符串 mysql 缺省信息 charset=utf8&parseTime=True&loc=Local&timeout=1000ms + source: goadmin:goadmin@tcp(127.0.0.1:3306)/go-admin?charset=utf8&parseTime=True&loc=Local&timeout=1000ms + # source: go-admin-db.db +# databases: +# 'locaohost:8000': +# driver: mysql +# # 数据库连接字符串 mysql 缺省信息 charset=utf8&parseTime=True&loc=Local&timeout=1000ms +# source: user:password@tcp(127.0.0.1:3306)/dbname?charset=utf8&parseTime=True&loc=Local&timeout=1000ms +# registers: +# - sources: +# - user:password@tcp(127.0.0.1:3306)/dbname?charset=utf8&parseTime=True&loc=Local&timeout=1000ms + gen: + # 代码生成读取的数据库名称 + dbname: go-admin + # 代码生成是使用前端代码存放位置,需要指定到src文件夹,相对路径 + frontpath: ../go-admin-ui/src + extend: # 扩展项使用说明 + demo: + name: data + cache: +# redis: +# addr: 127.0.0.1:6379 +# password: xxxxxx +# db: 2 + # key存在即可 + memory: '' + queue: + memory: + poolSize: 100 +# redis: +# addr: 127.0.0.1:6379 +# password: xxxxxx +# producer: +# streamMaxLength: 100 +# approximateMaxLength: true +# consumer: +# visibilityTimeout: 60 +# bufferSize: 100 +# concurrency: 10 +# blockingTimeout: 5 +# reclaimInterval: 1 + locker: + redis: \ No newline at end of file diff --git a/config/settings.yml b/config/settings.yml index 8e7ed8708..1e7e52910 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -1,20 +1,20 @@ settings: application: # dev开发环境 test测试环境 prod线上环境 - mode: dev + mode: test # 服务器ip,默认使用 0.0.0.0 host: 0.0.0.0 # 服务名称 - name: testApp + name: lvgang-sandbox.buddy.cloud # 端口号 - port: 8000 # 服务端口号 + port: 80 # 服务端口号 readtimeout: 1 writertimeout: 2 # 数据权限功能开关 enabledp: false logger: # 日志存放路径 - path: temp/logs + path: /www/log/go-admin # 日志输出,file:文件,default:命令行,其他:命令行 stdout: '' #控制台日志,启用后,不输出到文件 # 日志等级, trace, debug, info, warn, error, fatal @@ -31,7 +31,8 @@ settings: # sqlserver: sqlserver://用户名:密码@地址?database=数据库名 driver: mysql # 数据库连接字符串 mysql 缺省信息 charset=utf8&parseTime=True&loc=Local&timeout=1000ms - source: user:password@tcp(127.0.0.1:3306)/dbname?charset=utf8&parseTime=True&loc=Local&timeout=1000ms + source: goadmin:goadmin@tcp(127.0.0.1:3306)/go-admin?charset=utf8&parseTime=True&loc=Local&timeout=1000ms + # source: go-admin-db.db # databases: # 'locaohost:8000': # driver: mysql @@ -42,7 +43,7 @@ settings: # - user:password@tcp(127.0.0.1:3306)/dbname?charset=utf8&parseTime=True&loc=Local&timeout=1000ms gen: # 代码生成读取的数据库名称 - dbname: dbname + dbname: go-admin # 代码生成是使用前端代码存放位置,需要指定到src文件夹,相对路径 frontpath: ../go-admin-ui/src extend: # 扩展项使用说明 diff --git a/go.mod b/go.mod index c8820b76c..5f88d7426 100644 --- a/go.mod +++ b/go.mod @@ -29,9 +29,19 @@ require ( golang.org/x/crypto v0.14.0 gorm.io/driver/mysql v1.5.2 gorm.io/driver/postgres v1.5.4 - gorm.io/driver/sqlite v1.5.4 + gorm.io/driver/sqlite v1.4.3 gorm.io/driver/sqlserver v1.5.2 - gorm.io/gorm v1.25.5 + gorm.io/gorm v1.25.7 +) + +require ( + github.com/dustin/go-humanize v1.0.1 // indirect + github.com/glebarez/go-sqlite v1.21.2 // indirect + github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect + modernc.org/libc v1.22.5 // indirect + modernc.org/mathutil v1.5.0 // indirect + modernc.org/memory v1.5.0 // indirect + modernc.org/sqlite v1.23.1 // indirect ) require ( @@ -66,6 +76,7 @@ require ( github.com/ghodss/yaml v1.0.0 // indirect github.com/gin-contrib/sse v0.1.0 // indirect github.com/git-chglog/git-chglog v0.15.4 // indirect + github.com/glebarez/sqlite v1.11.0 github.com/go-admin-team/go-admin-core/plugins/logger/zap v1.3.5-rc.0.0.20231103105142-2d9e40ec6f71 // indirect github.com/go-admin-team/gorm-adapter/v3 v3.7.8-0.20220809100335-eaf9f67b3d21 // indirect github.com/go-admin-team/redis-watcher/v2 v2.0.0-20231102130416-bfe327cac940 // indirect @@ -112,6 +123,7 @@ require ( github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b // indirect github.com/microsoft/go-mssqldb v1.6.0 // indirect github.com/mitchellh/copystructure v1.0.0 // indirect + github.com/mitchellh/mapstructure v1.5.0 github.com/mitchellh/reflectwalk v1.0.0 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect diff --git a/main b/main new file mode 100644 index 000000000..d18c454a9 Binary files /dev/null and b/main differ