f
This commit is contained in:
@@ -18,6 +18,10 @@ service main {
|
|||||||
@handler AdminGetAgentList
|
@handler AdminGetAgentList
|
||||||
get /list (AdminGetAgentListReq) returns (AdminGetAgentListResp)
|
get /list (AdminGetAgentListReq) returns (AdminGetAgentListResp)
|
||||||
|
|
||||||
|
// 代理编辑
|
||||||
|
@handler AdminUpdateAgent
|
||||||
|
post /update (AdminUpdateAgentReq) returns (AdminUpdateAgentResp)
|
||||||
|
|
||||||
// 代理推广链接分页查询
|
// 代理推广链接分页查询
|
||||||
@handler AdminGetAgentLinkList
|
@handler AdminGetAgentLinkList
|
||||||
get /agent-link/list (AdminGetAgentLinkListReq) returns (AdminGetAgentLinkListResp)
|
get /agent-link/list (AdminGetAgentLinkListReq) returns (AdminGetAgentLinkListResp)
|
||||||
@@ -119,6 +123,8 @@ type (
|
|||||||
PageSize int64 `form:"pageSize"` // 每页数量
|
PageSize int64 `form:"pageSize"` // 每页数量
|
||||||
Mobile *string `form:"mobile,optional"` // 手机号(可选)
|
Mobile *string `form:"mobile,optional"` // 手机号(可选)
|
||||||
Region *string `form:"region,optional"` // 区域(可选)
|
Region *string `form:"region,optional"` // 区域(可选)
|
||||||
|
CreateTimeStart *string `form:"create_time_start,optional"` // 成为代理时间开始(可选)
|
||||||
|
CreateTimeEnd *string `form:"create_time_end,optional"` // 成为代理时间结束(可选)
|
||||||
ParentAgentId *int64 `form:"parent_agent_id,optional"` // 上级代理ID(可选)
|
ParentAgentId *int64 `form:"parent_agent_id,optional"` // 上级代理ID(可选)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -148,6 +154,20 @@ type (
|
|||||||
Items []AgentListItem `json:"items"` // 列表数据
|
Items []AgentListItem `json:"items"` // 列表数据
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 代理编辑请求
|
||||||
|
AdminUpdateAgentReq {
|
||||||
|
Id int64 `json:"id"` // 主键
|
||||||
|
Mobile string `json:"mobile"` // 手机号
|
||||||
|
LevelName string `json:"level_name"` // 等级名称
|
||||||
|
Region string `json:"region"` // 区域
|
||||||
|
MembershipExpiryTime string `json:"membership_expiry_time"` // 会员到期时间(YYYY-MM-DD HH:mm:ss)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 代理编辑响应
|
||||||
|
AdminUpdateAgentResp {
|
||||||
|
Success bool `json:"success"` // 是否成功
|
||||||
|
}
|
||||||
|
|
||||||
// 代理推广链接分页查询请求
|
// 代理推广链接分页查询请求
|
||||||
AdminGetAgentLinkListReq {
|
AdminGetAgentLinkListReq {
|
||||||
Page int64 `form:"page"` // 页码
|
Page int64 `form:"page"` // 页码
|
||||||
|
|||||||
@@ -69,7 +69,6 @@ type (
|
|||||||
PaymentScene string `form:"payment_scene,optional"` // 支付平台
|
PaymentScene string `form:"payment_scene,optional"` // 支付平台
|
||||||
Amount float64 `form:"amount,optional"` // 金额
|
Amount float64 `form:"amount,optional"` // 金额
|
||||||
Status string `form:"status,optional"` // 支付状态:pending-待支付,paid-已支付,refunded-已退款,closed-已关闭,failed-支付失败
|
Status string `form:"status,optional"` // 支付状态:pending-待支付,paid-已支付,refunded-已退款,closed-已关闭,failed-支付失败
|
||||||
IsPromotion int64 `form:"is_promotion,optional,default=-1"` // 是否推广订单:0-否,1-是
|
|
||||||
CreateTimeStart string `form:"create_time_start,optional"` // 创建时间开始
|
CreateTimeStart string `form:"create_time_start,optional"` // 创建时间开始
|
||||||
CreateTimeEnd string `form:"create_time_end,optional"` // 创建时间结束
|
CreateTimeEnd string `form:"create_time_end,optional"` // 创建时间结束
|
||||||
PayTimeStart string `form:"pay_time_start,optional"` // 支付时间开始
|
PayTimeStart string `form:"pay_time_start,optional"` // 支付时间开始
|
||||||
@@ -101,7 +100,6 @@ type (
|
|||||||
CreateTime string `json:"create_time"` // 创建时间
|
CreateTime string `json:"create_time"` // 创建时间
|
||||||
PayTime string `json:"pay_time"` // 支付时间
|
PayTime string `json:"pay_time"` // 支付时间
|
||||||
RefundTime string `json:"refund_time"` // 退款时间
|
RefundTime string `json:"refund_time"` // 退款时间
|
||||||
IsPromotion int64 `json:"is_promotion"` // 是否推广订单:0-否,1-是
|
|
||||||
IsAgentOrder bool `json:"is_agent_order"` // 是否是代理订单
|
IsAgentOrder bool `json:"is_agent_order"` // 是否是代理订单
|
||||||
AgentProcessStatus string `json:"agent_process_status"` // 代理事务处理状态:not_agent-非代理订单,success-处理成功,failed-处理失败,pending-待处理
|
AgentProcessStatus string `json:"agent_process_status"` // 代理事务处理状态:not_agent-非代理订单,success-处理成功,failed-处理失败,pending-待处理
|
||||||
|
|
||||||
@@ -125,7 +123,6 @@ type (
|
|||||||
CreateTime string `json:"create_time"` // 创建时间
|
CreateTime string `json:"create_time"` // 创建时间
|
||||||
PayTime string `json:"pay_time"` // 支付时间
|
PayTime string `json:"pay_time"` // 支付时间
|
||||||
RefundTime string `json:"refund_time"` // 退款时间
|
RefundTime string `json:"refund_time"` // 退款时间
|
||||||
IsPromotion int64 `json:"is_promotion"` // 是否推广订单:0-否,1-是
|
|
||||||
UpdateTime string `json:"update_time"` // 更新时间
|
UpdateTime string `json:"update_time"` // 更新时间
|
||||||
IsAgentOrder bool `json:"is_agent_order"` // 是否是代理订单
|
IsAgentOrder bool `json:"is_agent_order"` // 是否是代理订单
|
||||||
AgentProcessStatus string `json:"agent_process_status"` // 代理事务处理状态:not_agent-非代理订单,success-处理成功,failed-处理失败,pending-待处理
|
AgentProcessStatus string `json:"agent_process_status"` // 代理事务处理状态:not_agent-非代理订单,success-处理成功,failed-处理失败,pending-待处理
|
||||||
@@ -139,7 +136,6 @@ type (
|
|||||||
PaymentScene string `json:"payment_scene"` // 支付平台
|
PaymentScene string `json:"payment_scene"` // 支付平台
|
||||||
Amount float64 `json:"amount"` // 金额
|
Amount float64 `json:"amount"` // 金额
|
||||||
Status string `json:"status,default=pending"` // 支付状态:pending-待支付,paid-已支付,refunded-已退款,closed-已关闭,failed-支付失败
|
Status string `json:"status,default=pending"` // 支付状态:pending-待支付,paid-已支付,refunded-已退款,closed-已关闭,failed-支付失败
|
||||||
IsPromotion int64 `json:"is_promotion,default=0"` // 是否推广订单:0-否,1-是
|
|
||||||
}
|
}
|
||||||
// 创建响应
|
// 创建响应
|
||||||
AdminCreateOrderResp {
|
AdminCreateOrderResp {
|
||||||
@@ -157,7 +153,6 @@ type (
|
|||||||
Status *string `json:"status,optional"` // 支付状态:pending-待支付,paid-已支付,refunded-已退款,closed-已关闭,failed-支付失败
|
Status *string `json:"status,optional"` // 支付状态:pending-待支付,paid-已支付,refunded-已退款,closed-已关闭,failed-支付失败
|
||||||
PayTime *string `json:"pay_time,optional"` // 支付时间
|
PayTime *string `json:"pay_time,optional"` // 支付时间
|
||||||
RefundTime *string `json:"refund_time,optional"` // 退款时间
|
RefundTime *string `json:"refund_time,optional"` // 退款时间
|
||||||
IsPromotion *int64 `json:"is_promotion,optional"` // 是否推广订单:0-否,1-是
|
|
||||||
}
|
}
|
||||||
// 更新响应
|
// 更新响应
|
||||||
AdminUpdateOrderResp {
|
AdminUpdateOrderResp {
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package admin_agent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"bdrp-server/app/main/api/internal/logic/admin_agent"
|
||||||
|
"bdrp-server/app/main/api/internal/svc"
|
||||||
|
"bdrp-server/app/main/api/internal/types"
|
||||||
|
"bdrp-server/common/result"
|
||||||
|
"bdrp-server/pkg/lzkit/validator"
|
||||||
|
"github.com/zeromicro/go-zero/rest/httpx"
|
||||||
|
)
|
||||||
|
|
||||||
|
func AdminUpdateAgentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
var req types.AdminUpdateAgentReq
|
||||||
|
if err := httpx.Parse(r, &req); err != nil {
|
||||||
|
result.ParamErrorResult(r, w, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err := validator.Validate(req); err != nil {
|
||||||
|
result.ParamValidateErrorResult(r, w, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
l := admin_agent.NewAdminUpdateAgentLogic(r.Context(), svcCtx)
|
||||||
|
resp, err := l.AdminUpdateAgent(&req)
|
||||||
|
result.HttpResult(r, w, resp, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -142,6 +142,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
|||||||
Path: "/system-config",
|
Path: "/system-config",
|
||||||
Handler: admin_agent.AdminUpdateSystemConfigHandler(serverCtx),
|
Handler: admin_agent.AdminUpdateSystemConfigHandler(serverCtx),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Method: http.MethodPost,
|
||||||
|
Path: "/update",
|
||||||
|
Handler: admin_agent.AdminUpdateAgentHandler(serverCtx),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Method: http.MethodGet,
|
Method: http.MethodGet,
|
||||||
Path: "/wallet-transaction/list",
|
Path: "/wallet-transaction/list",
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package admin_agent
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"bdrp-server/app/main/api/internal/svc"
|
"bdrp-server/app/main/api/internal/svc"
|
||||||
"bdrp-server/app/main/api/internal/types"
|
"bdrp-server/app/main/api/internal/types"
|
||||||
@@ -38,11 +39,19 @@ func (l *AdminGetAgentCommissionDeductionListLogic) AdminGetAgentCommissionDeduc
|
|||||||
}
|
}
|
||||||
// 产品名筛选需先查product_id
|
// 产品名筛选需先查product_id
|
||||||
if req.ProductName != nil && *req.ProductName != "" {
|
if req.ProductName != nil && *req.ProductName != "" {
|
||||||
products, err := l.svcCtx.ProductModel.FindAll(l.ctx, l.svcCtx.ProductModel.SelectBuilder().Where(squirrel.Eq{"product_name": *req.ProductName}), "")
|
products, err := l.svcCtx.ProductModel.FindAll(
|
||||||
|
l.ctx,
|
||||||
|
l.svcCtx.ProductModel.SelectBuilder().Where(squirrel.Like{"product_name": "%" + strings.TrimSpace(*req.ProductName) + "%"}),
|
||||||
|
"",
|
||||||
|
)
|
||||||
if err != nil || len(products) == 0 {
|
if err != nil || len(products) == 0 {
|
||||||
return &types.AdminGetAgentCommissionDeductionListResp{Total: 0, Items: []types.AgentCommissionDeductionListItem{}}, nil
|
return &types.AdminGetAgentCommissionDeductionListResp{Total: 0, Items: []types.AgentCommissionDeductionListItem{}}, nil
|
||||||
}
|
}
|
||||||
builder = builder.Where("product_id = ?", products[0].Id)
|
productIds := make([]int64, 0, len(products))
|
||||||
|
for _, product := range products {
|
||||||
|
productIds = append(productIds, product.Id)
|
||||||
|
}
|
||||||
|
builder = builder.Where(squirrel.Eq{"product_id": productIds})
|
||||||
}
|
}
|
||||||
|
|
||||||
list, total, err := l.svcCtx.AgentCommissionDeductionModel.FindPageListByPageWithTotal(l.ctx, builder, req.Page, req.PageSize, "create_time DESC")
|
list, total, err := l.svcCtx.AgentCommissionDeductionModel.FindPageListByPageWithTotal(l.ctx, builder, req.Page, req.PageSize, "create_time DESC")
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package admin_agent
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"bdrp-server/app/main/api/internal/svc"
|
"bdrp-server/app/main/api/internal/svc"
|
||||||
"bdrp-server/app/main/api/internal/types"
|
"bdrp-server/app/main/api/internal/types"
|
||||||
@@ -30,19 +31,25 @@ func (l *AdminGetAgentLinkListLogic) AdminGetAgentLinkList(req *types.AdminGetAg
|
|||||||
builder = builder.Where("agent_id = ?", *req.AgentId)
|
builder = builder.Where("agent_id = ?", *req.AgentId)
|
||||||
}
|
}
|
||||||
if req.LinkIdentifier != nil && *req.LinkIdentifier != "" {
|
if req.LinkIdentifier != nil && *req.LinkIdentifier != "" {
|
||||||
builder = builder.Where("link_identifier = ?", *req.LinkIdentifier)
|
builder = builder.Where("link_identifier LIKE ?", "%"+strings.TrimSpace(*req.LinkIdentifier)+"%")
|
||||||
}
|
}
|
||||||
|
|
||||||
// 先查出所有product_id对应的product_name(如有product_name筛选,需反查id)
|
// 先查出所有product_id对应的product_name(如有product_name筛选,需反查id)
|
||||||
var productIdFilter int64
|
|
||||||
if req.ProductName != nil && *req.ProductName != "" {
|
if req.ProductName != nil && *req.ProductName != "" {
|
||||||
// 只支持精确匹配,如需模糊可扩展
|
products, err := l.svcCtx.ProductModel.FindAll(
|
||||||
products, err := l.svcCtx.ProductModel.FindAll(l.ctx, l.svcCtx.ProductModel.SelectBuilder().Where(squirrel.Eq{"product_name": *req.ProductName}), "")
|
l.ctx,
|
||||||
|
l.svcCtx.ProductModel.SelectBuilder().Where("product_name LIKE ?", "%"+strings.TrimSpace(*req.ProductName)+"%"),
|
||||||
|
"",
|
||||||
|
)
|
||||||
if err != nil || len(products) == 0 {
|
if err != nil || len(products) == 0 {
|
||||||
return &types.AdminGetAgentLinkListResp{Total: 0, Items: []types.AgentLinkListItem{}}, nil
|
return &types.AdminGetAgentLinkListResp{Total: 0, Items: []types.AgentLinkListItem{}}, nil
|
||||||
}
|
}
|
||||||
productIdFilter = products[0].Id
|
|
||||||
builder = builder.Where("product_id = ?", productIdFilter)
|
productIds := make([]int64, 0, len(products))
|
||||||
|
for _, product := range products {
|
||||||
|
productIds = append(productIds, product.Id)
|
||||||
|
}
|
||||||
|
builder = builder.Where(squirrel.Eq{"product_id": productIds})
|
||||||
}
|
}
|
||||||
|
|
||||||
links, total, err := l.svcCtx.AgentLinkModel.FindPageListByPageWithTotal(l.ctx, builder, req.Page, req.PageSize, "id DESC")
|
links, total, err := l.svcCtx.AgentLinkModel.FindPageListByPageWithTotal(l.ctx, builder, req.Page, req.PageSize, "id DESC")
|
||||||
|
|||||||
@@ -2,15 +2,14 @@ package admin_agent
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"bdrp-server/app/main/api/internal/svc"
|
"bdrp-server/app/main/api/internal/svc"
|
||||||
"bdrp-server/app/main/api/internal/types"
|
"bdrp-server/app/main/api/internal/types"
|
||||||
"bdrp-server/app/main/model"
|
"bdrp-server/app/main/model"
|
||||||
"bdrp-server/common/tool"
|
"bdrp-server/common/tool"
|
||||||
"bdrp-server/common/xerr"
|
|
||||||
"bdrp-server/pkg/lzkit/crypto"
|
"bdrp-server/pkg/lzkit/crypto"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -30,13 +29,20 @@ func NewAdminGetAgentListLogic(ctx context.Context, svcCtx *svc.ServiceContext)
|
|||||||
|
|
||||||
func (l *AdminGetAgentListLogic) AdminGetAgentList(req *types.AdminGetAgentListReq) (resp *types.AdminGetAgentListResp, err error) {
|
func (l *AdminGetAgentListLogic) AdminGetAgentList(req *types.AdminGetAgentListReq) (resp *types.AdminGetAgentListResp, err error) {
|
||||||
builder := l.svcCtx.AgentModel.SelectBuilder()
|
builder := l.svcCtx.AgentModel.SelectBuilder()
|
||||||
if req.Mobile != nil && *req.Mobile != "" {
|
secretKey := l.svcCtx.Config.Encrypt.SecretKey
|
||||||
builder = builder.Where("mobile = ?", *req.Mobile)
|
mobileKeyword := ""
|
||||||
|
if req.Mobile != nil {
|
||||||
|
mobileKeyword = strings.TrimSpace(*req.Mobile)
|
||||||
}
|
}
|
||||||
if req.Region != nil && *req.Region != "" {
|
if req.Region != nil && *req.Region != "" {
|
||||||
builder = builder.Where("region = ?", *req.Region)
|
builder = builder.Where("region LIKE ?", "%"+strings.TrimSpace(*req.Region)+"%")
|
||||||
|
}
|
||||||
|
if req.CreateTimeStart != nil && *req.CreateTimeStart != "" {
|
||||||
|
builder = builder.Where("create_time >= ?", *req.CreateTimeStart)
|
||||||
|
}
|
||||||
|
if req.CreateTimeEnd != nil && *req.CreateTimeEnd != "" {
|
||||||
|
builder = builder.Where("create_time <= ?", *req.CreateTimeEnd)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 新增:如果传入ParentAgentId,则查找其所有1级下级代理
|
// 新增:如果传入ParentAgentId,则查找其所有1级下级代理
|
||||||
if req.ParentAgentId != nil {
|
if req.ParentAgentId != nil {
|
||||||
closureBuilder := l.svcCtx.AgentClosureModel.SelectBuilder().Where("ancestor_id = ? AND depth = 1", *req.ParentAgentId)
|
closureBuilder := l.svcCtx.AgentClosureModel.SelectBuilder().Where("ancestor_id = ? AND depth = 1", *req.ParentAgentId)
|
||||||
@@ -61,9 +67,49 @@ func (l *AdminGetAgentListLogic) AdminGetAgentList(req *types.AdminGetAgentListR
|
|||||||
builder = builder.Where("id IN ("+tool.InPlaceholders(len(interfaceIds))+")", interfaceIds...)
|
builder = builder.Where("id IN ("+tool.InPlaceholders(len(interfaceIds))+")", interfaceIds...)
|
||||||
}
|
}
|
||||||
|
|
||||||
agents, total, err := l.svcCtx.AgentModel.FindPageListByPageWithTotal(l.ctx, builder, req.Page, req.PageSize, "id DESC")
|
var (
|
||||||
if err != nil {
|
agents []*model.Agent
|
||||||
return nil, err
|
total int64
|
||||||
|
)
|
||||||
|
if mobileKeyword == "" {
|
||||||
|
agents, total, err = l.svcCtx.AgentModel.FindPageListByPageWithTotal(l.ctx, builder, req.Page, req.PageSize, "id DESC")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
allAgents, findErr := l.svcCtx.AgentModel.FindAll(l.ctx, builder, "id DESC")
|
||||||
|
if findErr != nil {
|
||||||
|
return nil, findErr
|
||||||
|
}
|
||||||
|
|
||||||
|
filteredAgents := make([]*model.Agent, 0, len(allAgents))
|
||||||
|
for _, agent := range allAgents {
|
||||||
|
decryptedMobile, decryptErr := crypto.DecryptMobile(agent.Mobile, secretKey)
|
||||||
|
if decryptErr != nil {
|
||||||
|
// 单条手机号异常时忽略该条匹配,避免影响整页结果
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if strings.Contains(decryptedMobile, mobileKeyword) {
|
||||||
|
agent.Mobile = decryptedMobile
|
||||||
|
filteredAgents = append(filteredAgents, agent)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
total = int64(len(filteredAgents))
|
||||||
|
if total > 0 && req.PageSize > 0 {
|
||||||
|
page := req.Page
|
||||||
|
if page < 1 {
|
||||||
|
page = 1
|
||||||
|
}
|
||||||
|
offset := (page - 1) * req.PageSize
|
||||||
|
if offset < total {
|
||||||
|
end := offset + req.PageSize
|
||||||
|
if end > total {
|
||||||
|
end = total
|
||||||
|
}
|
||||||
|
agents = filteredAgents[offset:end]
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
items := make([]types.AgentListItem, 0, len(agents))
|
items := make([]types.AgentListItem, 0, len(agents))
|
||||||
@@ -79,9 +125,13 @@ func (l *AdminGetAgentListLogic) AdminGetAgentList(req *types.AdminGetAgentListR
|
|||||||
if req.ParentAgentId != nil {
|
if req.ParentAgentId != nil {
|
||||||
item.ParentAgentId = *req.ParentAgentId
|
item.ParentAgentId = *req.ParentAgentId
|
||||||
}
|
}
|
||||||
agent.Mobile, err = crypto.DecryptMobile(agent.Mobile, l.svcCtx.Config.Encrypt.SecretKey)
|
if mobileKeyword == "" {
|
||||||
if err != nil {
|
decryptedMobile, decryptErr := crypto.DecryptMobile(agent.Mobile, secretKey)
|
||||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "获取代理信息, 解密手机号失败: %v", err)
|
if decryptErr != nil {
|
||||||
|
agent.Mobile = "-"
|
||||||
|
} else {
|
||||||
|
agent.Mobile = decryptedMobile
|
||||||
|
}
|
||||||
}
|
}
|
||||||
item.Mobile = agent.Mobile
|
item.Mobile = agent.Mobile
|
||||||
if agent.MembershipExpiryTime.Valid {
|
if agent.MembershipExpiryTime.Valid {
|
||||||
|
|||||||
@@ -0,0 +1,65 @@
|
|||||||
|
package admin_agent
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"database/sql"
|
||||||
|
"regexp"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"bdrp-server/app/main/api/internal/svc"
|
||||||
|
"bdrp-server/app/main/api/internal/types"
|
||||||
|
"bdrp-server/common/xerr"
|
||||||
|
"bdrp-server/pkg/lzkit/crypto"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
|
)
|
||||||
|
|
||||||
|
type AdminUpdateAgentLogic struct {
|
||||||
|
logx.Logger
|
||||||
|
ctx context.Context
|
||||||
|
svcCtx *svc.ServiceContext
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewAdminUpdateAgentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AdminUpdateAgentLogic {
|
||||||
|
return &AdminUpdateAgentLogic{
|
||||||
|
Logger: logx.WithContext(ctx),
|
||||||
|
ctx: ctx,
|
||||||
|
svcCtx: svcCtx,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *AdminUpdateAgentLogic) AdminUpdateAgent(req *types.AdminUpdateAgentReq) (resp *types.AdminUpdateAgentResp, err error) {
|
||||||
|
agent, err := l.svcCtx.AgentModel.FindOne(l.ctx, req.Id)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "查询代理失败 err: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if ok, _ := regexp.MatchString(`^1[3-9]\d{9}$`, req.Mobile); !ok {
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.REUQEST_PARAM_ERROR), "手机号格式错误: %s", req.Mobile)
|
||||||
|
}
|
||||||
|
|
||||||
|
encryptedMobile, err := crypto.EncryptMobile(req.Mobile, l.svcCtx.Config.Encrypt.SecretKey)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "加密手机号失败: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
expiryTime, err := time.ParseInLocation("2006-01-02 15:04:05", req.MembershipExpiryTime, time.Local)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.REUQEST_PARAM_ERROR), "会员到期时间格式错误: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
agent.Mobile = encryptedMobile
|
||||||
|
agent.LevelName = req.LevelName
|
||||||
|
agent.Region = req.Region
|
||||||
|
agent.MembershipExpiryTime = sql.NullTime{
|
||||||
|
Time: expiryTime,
|
||||||
|
Valid: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err = l.svcCtx.AgentModel.Update(l.ctx, nil, agent); err != nil {
|
||||||
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "更新代理失败 err: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return &types.AdminUpdateAgentResp{Success: true}, nil
|
||||||
|
}
|
||||||
@@ -72,20 +72,6 @@ func (l *AdminCreateOrderLogic) AdminCreateOrder(req *types.AdminCreateOrderReq)
|
|||||||
return errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "AdminCreateOrder, 获取订单ID失败 err: %v", err)
|
return errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "AdminCreateOrder, 获取订单ID失败 err: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 如果是推广订单,创建推广订单记录
|
|
||||||
if req.IsPromotion == 1 {
|
|
||||||
promotionOrder := &model.AdminPromotionOrder{
|
|
||||||
OrderId: orderId,
|
|
||||||
Version: 1,
|
|
||||||
CreateTime: time.Now(),
|
|
||||||
UpdateTime: time.Now(),
|
|
||||||
}
|
|
||||||
_, err = l.svcCtx.AdminPromotionOrderModel.Insert(ctx, session, promotionOrder)
|
|
||||||
if err != nil {
|
|
||||||
return errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "AdminCreateOrder, 创建推广订单失败 err: %v", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -41,15 +41,6 @@ func (l *AdminDeleteOrderLogic) AdminDeleteOrder(req *types.AdminDeleteOrderReq)
|
|||||||
return errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "AdminDeleteOrder, 删除订单失败 err: %v", err)
|
return errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "AdminDeleteOrder, 删除订单失败 err: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 删除关联的推广订单记录
|
|
||||||
promotionOrder, err := l.svcCtx.AdminPromotionOrderModel.FindOneByOrderId(ctx, order.Id)
|
|
||||||
if err == nil && promotionOrder != nil {
|
|
||||||
err = l.svcCtx.AdminPromotionOrderModel.DeleteSoft(ctx, session, promotionOrder)
|
|
||||||
if err != nil {
|
|
||||||
return errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "AdminDeleteOrder, 删除推广订单失败 err: %v", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -40,13 +40,6 @@ func (l *AdminGetOrderDetailLogic) AdminGetOrderDetail(req *types.AdminGetOrderD
|
|||||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "AdminGetOrderDetail, 查询产品失败 err: %v", err)
|
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "AdminGetOrderDetail, 查询产品失败 err: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 判断是否为推广订单
|
|
||||||
var isPromotion int64
|
|
||||||
promotionOrder, err := l.svcCtx.AdminPromotionOrderModel.FindOneByOrderId(l.ctx, order.Id)
|
|
||||||
if err == nil && promotionOrder != nil {
|
|
||||||
isPromotion = 1
|
|
||||||
}
|
|
||||||
|
|
||||||
// 判断是否为代理订单并获取代理处理状态
|
// 判断是否为代理订单并获取代理处理状态
|
||||||
var isAgentOrder bool
|
var isAgentOrder bool
|
||||||
var agentProcessStatus string
|
var agentProcessStatus string
|
||||||
@@ -119,7 +112,6 @@ func (l *AdminGetOrderDetailLogic) AdminGetOrderDetail(req *types.AdminGetOrderD
|
|||||||
Status: order.Status,
|
Status: order.Status,
|
||||||
CreateTime: order.CreateTime.Format("2006-01-02 15:04:05"),
|
CreateTime: order.CreateTime.Format("2006-01-02 15:04:05"),
|
||||||
UpdateTime: order.UpdateTime.Format("2006-01-02 15:04:05"),
|
UpdateTime: order.UpdateTime.Format("2006-01-02 15:04:05"),
|
||||||
IsPromotion: isPromotion,
|
|
||||||
QueryState: queryState,
|
QueryState: queryState,
|
||||||
IsAgentOrder: isAgentOrder,
|
IsAgentOrder: isAgentOrder,
|
||||||
AgentProcessStatus: agentProcessStatus,
|
AgentProcessStatus: agentProcessStatus,
|
||||||
|
|||||||
@@ -36,11 +36,11 @@ func NewAdminGetOrderListLogic(ctx context.Context, svcCtx *svc.ServiceContext)
|
|||||||
func (l *AdminGetOrderListLogic) AdminGetOrderList(req *types.AdminGetOrderListReq) (resp *types.AdminGetOrderListResp, err error) {
|
func (l *AdminGetOrderListLogic) AdminGetOrderList(req *types.AdminGetOrderListReq) (resp *types.AdminGetOrderListResp, err error) {
|
||||||
// 构建查询条件
|
// 构建查询条件
|
||||||
builder := l.svcCtx.OrderModel.SelectBuilder()
|
builder := l.svcCtx.OrderModel.SelectBuilder()
|
||||||
if req.OrderNo != "" {
|
if keyword := strings.ToLower(strings.TrimSpace(req.OrderNo)); keyword != "" {
|
||||||
builder = builder.Where("order_no = ?", req.OrderNo)
|
builder = builder.Where("LOWER(order_no) LIKE ?", "%"+keyword+"%")
|
||||||
}
|
}
|
||||||
if req.PlatformOrderId != "" {
|
if keyword := strings.ToLower(strings.TrimSpace(req.PlatformOrderId)); keyword != "" {
|
||||||
builder = builder.Where("platform_order_id = ?", req.PlatformOrderId)
|
builder = builder.Where("LOWER(COALESCE(platform_order_id, '')) LIKE ?", "%"+keyword+"%")
|
||||||
}
|
}
|
||||||
if req.ProductName != "" {
|
if req.ProductName != "" {
|
||||||
builder = builder.Where("product_id IN (SELECT id FROM product WHERE product_name LIKE ?)", "%"+req.ProductName+"%")
|
builder = builder.Where("product_id IN (SELECT id FROM product WHERE product_name LIKE ?)", "%"+req.ProductName+"%")
|
||||||
@@ -57,9 +57,6 @@ func (l *AdminGetOrderListLogic) AdminGetOrderList(req *types.AdminGetOrderListR
|
|||||||
if req.Status != "" {
|
if req.Status != "" {
|
||||||
builder = builder.Where("status = ?", req.Status)
|
builder = builder.Where("status = ?", req.Status)
|
||||||
}
|
}
|
||||||
if req.IsPromotion != -1 {
|
|
||||||
builder = builder.Where("id IN (SELECT order_id FROM admin_promotion_order WHERE del_state = 0)")
|
|
||||||
}
|
|
||||||
// 时间范围查询
|
// 时间范围查询
|
||||||
if req.CreateTimeStart != "" {
|
if req.CreateTimeStart != "" {
|
||||||
builder = builder.Where("create_time >= ?", req.CreateTimeStart)
|
builder = builder.Where("create_time >= ?", req.CreateTimeStart)
|
||||||
@@ -291,12 +288,6 @@ func (l *AdminGetOrderListLogic) AdminGetOrderList(req *types.AdminGetOrderListR
|
|||||||
if order.RefundTime.Valid {
|
if order.RefundTime.Valid {
|
||||||
item.RefundTime = order.RefundTime.Time.Format("2006-01-02 15:04:05")
|
item.RefundTime = order.RefundTime.Time.Format("2006-01-02 15:04:05")
|
||||||
}
|
}
|
||||||
// 判断是否为推广订单
|
|
||||||
promotionOrder, err := l.svcCtx.AdminPromotionOrderModel.FindOneByOrderId(l.ctx, order.Id)
|
|
||||||
if err == nil && promotionOrder != nil {
|
|
||||||
item.IsPromotion = 1
|
|
||||||
}
|
|
||||||
|
|
||||||
// 设置代理订单相关字段
|
// 设置代理订单相关字段
|
||||||
if agentOrderMap[order.Id] {
|
if agentOrderMap[order.Id] {
|
||||||
item.IsAgentOrder = true
|
item.IsAgentOrder = true
|
||||||
@@ -353,7 +344,7 @@ func (l *AdminGetOrderListLogic) filterOrderIdsByQueryUserRecord(queryName, quer
|
|||||||
match = false
|
match = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if match && decIdCard != queryIdCard {
|
if match && !strings.Contains(decIdCard, strings.TrimSpace(queryIdCard)) {
|
||||||
match = false
|
match = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -367,7 +358,7 @@ func (l *AdminGetOrderListLogic) filterOrderIdsByQueryUserRecord(queryName, quer
|
|||||||
match = false
|
match = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if match && decMobile != queryMobile {
|
if match && !strings.Contains(decMobile, strings.TrimSpace(queryMobile)) {
|
||||||
match = false
|
match = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import (
|
|||||||
|
|
||||||
"bdrp-server/app/main/api/internal/svc"
|
"bdrp-server/app/main/api/internal/svc"
|
||||||
"bdrp-server/app/main/api/internal/types"
|
"bdrp-server/app/main/api/internal/types"
|
||||||
"bdrp-server/app/main/model"
|
|
||||||
"bdrp-server/common/xerr"
|
"bdrp-server/common/xerr"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
@@ -76,30 +75,6 @@ func (l *AdminUpdateOrderLogic) AdminUpdateOrder(req *types.AdminUpdateOrderReq)
|
|||||||
return errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "AdminUpdateOrder, 更新订单失败 err: %v", err)
|
return errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "AdminUpdateOrder, 更新订单失败 err: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 处理推广订单状态
|
|
||||||
if req.IsPromotion != nil {
|
|
||||||
promotionOrder, err := l.svcCtx.AdminPromotionOrderModel.FindOneByOrderId(ctx, order.Id)
|
|
||||||
if err == nil && promotionOrder != nil {
|
|
||||||
// 如果存在推广订单记录但不需要推广,则删除
|
|
||||||
if *req.IsPromotion == 0 {
|
|
||||||
err = l.svcCtx.AdminPromotionOrderModel.DeleteSoft(ctx, session, promotionOrder)
|
|
||||||
if err != nil {
|
|
||||||
return errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "AdminUpdateOrder, 删除推广订单失败 err: %v", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if *req.IsPromotion == 1 {
|
|
||||||
// 如果需要推广但不存在记录,则创建
|
|
||||||
newPromotionOrder := &model.AdminPromotionOrder{
|
|
||||||
OrderId: order.Id,
|
|
||||||
Version: 1,
|
|
||||||
}
|
|
||||||
_, err = l.svcCtx.AdminPromotionOrderModel.Insert(ctx, session, newPromotionOrder)
|
|
||||||
if err != nil {
|
|
||||||
return errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "AdminUpdateOrder, 创建推广订单失败 err: %v", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -164,7 +164,13 @@ func (l *AlipayCallbackLogic) handleAgentVipOrderPayment(w http.ResponseWriter,
|
|||||||
} else {
|
} else {
|
||||||
logx.Infof("代理会员新购、升级或重新激活成功,会员ID:%d,等级:%s", agentModel.Id, agentModel.LevelName)
|
logx.Infof("代理会员新购、升级或重新激活成功,会员ID:%d,等级:%s", agentModel.Id, agentModel.LevelName)
|
||||||
}
|
}
|
||||||
agentModel.MembershipExpiryTime = lzUtils.RenewMembership(agentModel.MembershipExpiryTime)
|
// VIP 升级到 SVIP 按支付时间重新计算有效期,不叠加旧 VIP 剩余时长。
|
||||||
|
isVipUpgradeToSvip := oldLevel == model.AgentLeveNameVIP && agentOrder.LevelName == model.AgentLeveNameSVIP
|
||||||
|
if isVipUpgradeToSvip {
|
||||||
|
agentModel.MembershipExpiryTime = lzUtils.RenewMembership(lzUtils.TimeToNullTime(time.Now()))
|
||||||
|
} else {
|
||||||
|
agentModel.MembershipExpiryTime = lzUtils.RenewMembership(agentModel.MembershipExpiryTime)
|
||||||
|
}
|
||||||
|
|
||||||
if updateErr := l.svcCtx.AgentModel.UpdateWithVersion(l.ctx, nil, agentModel); updateErr != nil {
|
if updateErr := l.svcCtx.AgentModel.UpdateWithVersion(l.ctx, nil, agentModel); updateErr != nil {
|
||||||
return fmt.Errorf("修改代理信息失败: %+v", updateErr)
|
return fmt.Errorf("修改代理信息失败: %+v", updateErr)
|
||||||
|
|||||||
@@ -34,6 +34,24 @@ type PaymentTypeResp struct {
|
|||||||
orderID int64 // 仅 query 类型有值;agent_vip 为 0
|
orderID int64 // 仅 query 类型有值;agent_vip 为 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (l *PaymentLogic) resolvePaymentScene() string {
|
||||||
|
platform, _ := l.ctx.Value("platform").(string)
|
||||||
|
switch platform {
|
||||||
|
case model.PlatformApp:
|
||||||
|
return "app"
|
||||||
|
case model.PlatformH5:
|
||||||
|
return "h5"
|
||||||
|
case model.PlatformWxMini:
|
||||||
|
return "mini_program"
|
||||||
|
case model.PlatformWxH5:
|
||||||
|
return "public_account"
|
||||||
|
default:
|
||||||
|
// 兜底为 app,避免脏值写入 enum 字段导致下单失败。
|
||||||
|
logx.Infof("支付场景识别失败,使用默认场景 app,platform=%s", platform)
|
||||||
|
return "app"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func NewPaymentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PaymentLogic {
|
func NewPaymentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PaymentLogic {
|
||||||
return &PaymentLogic{
|
return &PaymentLogic{
|
||||||
Logger: logx.WithContext(ctx),
|
Logger: logx.WithContext(ctx),
|
||||||
@@ -192,48 +210,13 @@ func (l *PaymentLogic) QueryOrderPayment(req *types.PaymentReq, session sqlx.Ses
|
|||||||
amount = 0.01
|
amount = 0.01
|
||||||
}
|
}
|
||||||
|
|
||||||
// 检查72小时内身份证查询次数限制
|
|
||||||
secretKey := l.svcCtx.Config.Encrypt.SecretKey
|
|
||||||
key, decodeErr := hex.DecodeString(secretKey)
|
|
||||||
if decodeErr != nil {
|
|
||||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "生成订单, 获取AES密钥失败: %+v", decodeErr)
|
|
||||||
}
|
|
||||||
// 解密缓存中的参数
|
|
||||||
decryptedParams, decryptErr := crypto.AesDecrypt(data.Params, key)
|
|
||||||
if decryptErr != nil {
|
|
||||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "生成订单, 解密缓存参数失败: %v", decryptErr)
|
|
||||||
}
|
|
||||||
var params map[string]interface{}
|
|
||||||
if unmarshalErr := json.Unmarshal(decryptedParams, ¶ms); unmarshalErr != nil {
|
|
||||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "生成订单, 解析解密参数失败: %v", unmarshalErr)
|
|
||||||
}
|
|
||||||
// 获取身份证号
|
|
||||||
idCard, ok := params["id_card"].(string)
|
|
||||||
if !ok || idCard == "" {
|
|
||||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "生成订单, 获取身份证号失败")
|
|
||||||
}
|
|
||||||
// 加密身份证号用于查询
|
|
||||||
encryptedIdCard, encryptErr := crypto.EncryptIDCard(idCard, key)
|
|
||||||
if encryptErr != nil {
|
|
||||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "生成订单, 加密身份证号失败: %v", encryptErr)
|
|
||||||
}
|
|
||||||
// 查询72小时内的查询次数
|
|
||||||
queryCount, countErr := l.svcCtx.QueryUserRecordModel.CountByEncryptedIdCardIn72Hours(l.ctx, encryptedIdCard)
|
|
||||||
if countErr != nil {
|
|
||||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "生成订单, 查询记录失败: %v", countErr)
|
|
||||||
}
|
|
||||||
// 如果72小时内查询次数大于等于2次,禁止支付(当前这次是第3次)
|
|
||||||
if queryCount >= 2 {
|
|
||||||
return nil, errors.Wrapf(xerr.NewErrMsg("查询受限通知:检测到您72小时内已完成2次报告查询,系统已自动暂停服务。如需紧急查询,请联系客服申请临时额度。"), "生成订单, 查询次数超限: %d", queryCount)
|
|
||||||
}
|
|
||||||
|
|
||||||
var orderID int64
|
var orderID int64
|
||||||
order := model.Order{
|
order := model.Order{
|
||||||
OrderNo: outTradeNo,
|
OrderNo: outTradeNo,
|
||||||
UserId: userID,
|
UserId: userID,
|
||||||
ProductId: product.Id,
|
ProductId: product.Id,
|
||||||
PaymentPlatform: req.PayMethod,
|
PaymentPlatform: req.PayMethod,
|
||||||
PaymentScene: "app",
|
PaymentScene: l.resolvePaymentScene(),
|
||||||
Amount: amount,
|
Amount: amount,
|
||||||
Status: "pending",
|
Status: "pending",
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -169,7 +169,13 @@ func (l *WechatPayCallbackLogic) handleAgentVipOrderPayment(w http.ResponseWrite
|
|||||||
} else {
|
} else {
|
||||||
logx.Infof("代理会员新购、升级或重新激活成功,会员ID:%d,等级:%s", agentModel.Id, agentModel.LevelName)
|
logx.Infof("代理会员新购、升级或重新激活成功,会员ID:%d,等级:%s", agentModel.Id, agentModel.LevelName)
|
||||||
}
|
}
|
||||||
agentModel.MembershipExpiryTime = lzUtils.RenewMembership(agentModel.MembershipExpiryTime)
|
// VIP 升级到 SVIP 按支付时间重新计算有效期,不叠加旧 VIP 剩余时长。
|
||||||
|
isVipUpgradeToSvip := oldLevel == model.AgentLeveNameVIP && agentOrder.LevelName == model.AgentLeveNameSVIP
|
||||||
|
if isVipUpgradeToSvip {
|
||||||
|
agentModel.MembershipExpiryTime = lzUtils.RenewMembership(lzUtils.TimeToNullTime(time.Now()))
|
||||||
|
} else {
|
||||||
|
agentModel.MembershipExpiryTime = lzUtils.RenewMembership(agentModel.MembershipExpiryTime)
|
||||||
|
}
|
||||||
|
|
||||||
if updateErr := l.svcCtx.AgentModel.UpdateWithVersion(l.ctx, nil, agentModel); updateErr != nil {
|
if updateErr := l.svcCtx.AgentModel.UpdateWithVersion(l.ctx, nil, agentModel); updateErr != nil {
|
||||||
return fmt.Errorf("修改代理信息失败: %+v", updateErr)
|
return fmt.Errorf("修改代理信息失败: %+v", updateErr)
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
package svc
|
package svc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
|
||||||
"bdrp-server/app/main/api/internal/config"
|
"bdrp-server/app/main/api/internal/config"
|
||||||
"bdrp-server/app/main/api/internal/middleware"
|
"bdrp-server/app/main/api/internal/middleware"
|
||||||
"bdrp-server/app/main/api/internal/service"
|
"bdrp-server/app/main/api/internal/service"
|
||||||
tianyuanapi "bdrp-server/app/main/api/internal/service/tianyuanapi_sdk"
|
tianyuanapi "bdrp-server/app/main/api/internal/service/tianyuanapi_sdk"
|
||||||
"bdrp-server/app/main/model"
|
"bdrp-server/app/main/model"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/hibiken/asynq"
|
"github.com/hibiken/asynq"
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
@@ -79,7 +79,6 @@ type ServiceContext struct {
|
|||||||
AdminPromotionLinkModel model.AdminPromotionLinkModel
|
AdminPromotionLinkModel model.AdminPromotionLinkModel
|
||||||
AdminPromotionLinkStatsTotalModel model.AdminPromotionLinkStatsTotalModel
|
AdminPromotionLinkStatsTotalModel model.AdminPromotionLinkStatsTotalModel
|
||||||
AdminPromotionLinkStatsHistoryModel model.AdminPromotionLinkStatsHistoryModel
|
AdminPromotionLinkStatsHistoryModel model.AdminPromotionLinkStatsHistoryModel
|
||||||
AdminPromotionOrderModel model.AdminPromotionOrderModel
|
|
||||||
|
|
||||||
// 其他模型
|
// 其他模型
|
||||||
ExampleModel model.ExampleModel
|
ExampleModel model.ExampleModel
|
||||||
@@ -169,7 +168,6 @@ func NewServiceContext(c config.Config) *ServiceContext {
|
|||||||
adminPromotionLinkModel := model.NewAdminPromotionLinkModel(db, cacheConf)
|
adminPromotionLinkModel := model.NewAdminPromotionLinkModel(db, cacheConf)
|
||||||
adminPromotionLinkStatsTotalModel := model.NewAdminPromotionLinkStatsTotalModel(db, cacheConf)
|
adminPromotionLinkStatsTotalModel := model.NewAdminPromotionLinkStatsTotalModel(db, cacheConf)
|
||||||
adminPromotionLinkStatsHistoryModel := model.NewAdminPromotionLinkStatsHistoryModel(db, cacheConf)
|
adminPromotionLinkStatsHistoryModel := model.NewAdminPromotionLinkStatsHistoryModel(db, cacheConf)
|
||||||
adminPromotionOrderModel := model.NewAdminPromotionOrderModel(db, cacheConf)
|
|
||||||
|
|
||||||
// ============================== 其他模型 ==============================
|
// ============================== 其他模型 ==============================
|
||||||
exampleModel := model.NewExampleModel(db, cacheConf)
|
exampleModel := model.NewExampleModel(db, cacheConf)
|
||||||
@@ -189,7 +187,7 @@ func NewServiceContext(c config.Config) *ServiceContext {
|
|||||||
|
|
||||||
// ============================== 业务服务初始化 ==============================
|
// ============================== 业务服务初始化 ==============================
|
||||||
alipayService := service.NewAliPayService(c)
|
alipayService := service.NewAliPayService(c)
|
||||||
wechatPayService := service.NewWechatPayService(c, userAuthModel, service.InitTypeWxPayPubKey)
|
wechatPayService := service.NewWechatPayService(c, userAuthModel, service.InitTypePlatformCert)
|
||||||
applePayService := service.NewApplePayService(c)
|
applePayService := service.NewApplePayService(c)
|
||||||
apiRequestService := service.NewApiRequestService(c, featureModel, productFeatureModel, tianyuanapi)
|
apiRequestService := service.NewApiRequestService(c, featureModel, productFeatureModel, tianyuanapi)
|
||||||
verificationService := service.NewVerificationService(c, tianyuanapi, apiRequestService)
|
verificationService := service.NewVerificationService(c, tianyuanapi, apiRequestService)
|
||||||
@@ -281,7 +279,6 @@ func NewServiceContext(c config.Config) *ServiceContext {
|
|||||||
AdminPromotionLinkModel: adminPromotionLinkModel,
|
AdminPromotionLinkModel: adminPromotionLinkModel,
|
||||||
AdminPromotionLinkStatsTotalModel: adminPromotionLinkStatsTotalModel,
|
AdminPromotionLinkStatsTotalModel: adminPromotionLinkStatsTotalModel,
|
||||||
AdminPromotionLinkStatsHistoryModel: adminPromotionLinkStatsHistoryModel,
|
AdminPromotionLinkStatsHistoryModel: adminPromotionLinkStatsHistoryModel,
|
||||||
AdminPromotionOrderModel: adminPromotionOrderModel,
|
|
||||||
|
|
||||||
// 其他模型
|
// 其他模型
|
||||||
ExampleModel: exampleModel,
|
ExampleModel: exampleModel,
|
||||||
|
|||||||
@@ -110,7 +110,6 @@ type AdminCreateOrderReq struct {
|
|||||||
PaymentScene string `json:"payment_scene"` // 支付平台
|
PaymentScene string `json:"payment_scene"` // 支付平台
|
||||||
Amount float64 `json:"amount"` // 金额
|
Amount float64 `json:"amount"` // 金额
|
||||||
Status string `json:"status,default=pending"` // 支付状态:pending-待支付,paid-已支付,refunded-已退款,closed-已关闭,failed-支付失败
|
Status string `json:"status,default=pending"` // 支付状态:pending-待支付,paid-已支付,refunded-已退款,closed-已关闭,failed-支付失败
|
||||||
IsPromotion int64 `json:"is_promotion,default=0"` // 是否推广订单:0-否,1-是
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type AdminCreateOrderResp struct {
|
type AdminCreateOrderResp struct {
|
||||||
@@ -260,11 +259,13 @@ type AdminGetAgentLinkProductStatisticsResp struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type AdminGetAgentListReq struct {
|
type AdminGetAgentListReq struct {
|
||||||
Page int64 `form:"page"` // 页码
|
Page int64 `form:"page"` // 页码
|
||||||
PageSize int64 `form:"pageSize"` // 每页数量
|
PageSize int64 `form:"pageSize"` // 每页数量
|
||||||
Mobile *string `form:"mobile,optional"` // 手机号(可选)
|
Mobile *string `form:"mobile,optional"` // 手机号(可选)
|
||||||
Region *string `form:"region,optional"` // 区域(可选)
|
Region *string `form:"region,optional"` // 区域(可选)
|
||||||
ParentAgentId *int64 `form:"parent_agent_id,optional"` // 上级代理ID(可选)
|
CreateTimeStart *string `form:"create_time_start,optional"` // 成为代理时间开始(可选)
|
||||||
|
CreateTimeEnd *string `form:"create_time_end,optional"` // 成为代理时间结束(可选)
|
||||||
|
ParentAgentId *int64 `form:"parent_agent_id,optional"` // 上级代理ID(可选)
|
||||||
}
|
}
|
||||||
|
|
||||||
type AdminGetAgentListResp struct {
|
type AdminGetAgentListResp struct {
|
||||||
@@ -509,33 +510,31 @@ type AdminGetOrderDetailResp struct {
|
|||||||
CreateTime string `json:"create_time"` // 创建时间
|
CreateTime string `json:"create_time"` // 创建时间
|
||||||
PayTime string `json:"pay_time"` // 支付时间
|
PayTime string `json:"pay_time"` // 支付时间
|
||||||
RefundTime string `json:"refund_time"` // 退款时间
|
RefundTime string `json:"refund_time"` // 退款时间
|
||||||
IsPromotion int64 `json:"is_promotion"` // 是否推广订单:0-否,1-是
|
|
||||||
UpdateTime string `json:"update_time"` // 更新时间
|
UpdateTime string `json:"update_time"` // 更新时间
|
||||||
IsAgentOrder bool `json:"is_agent_order"` // 是否是代理订单
|
IsAgentOrder bool `json:"is_agent_order"` // 是否是代理订单
|
||||||
AgentProcessStatus string `json:"agent_process_status"` // 代理事务处理状态:not_agent-非代理订单,success-处理成功,failed-处理失败,pending-待处理
|
AgentProcessStatus string `json:"agent_process_status"` // 代理事务处理状态:not_agent-非代理订单,success-处理成功,failed-处理失败,pending-待处理
|
||||||
}
|
}
|
||||||
|
|
||||||
type AdminGetOrderListReq struct {
|
type AdminGetOrderListReq struct {
|
||||||
Page int64 `form:"page,default=1"` // 页码
|
Page int64 `form:"page,default=1"` // 页码
|
||||||
PageSize int64 `form:"pageSize,default=20"` // 每页数量
|
PageSize int64 `form:"pageSize,default=20"` // 每页数量
|
||||||
OrderNo string `form:"order_no,optional"` // 商户订单号
|
OrderNo string `form:"order_no,optional"` // 商户订单号
|
||||||
PlatformOrderId string `form:"platform_order_id,optional"` // 支付订单号
|
PlatformOrderId string `form:"platform_order_id,optional"` // 支付订单号
|
||||||
ProductName string `form:"product_name,optional"` // 产品名称
|
ProductName string `form:"product_name,optional"` // 产品名称
|
||||||
PaymentPlatform string `form:"payment_platform,optional"` // 支付方式
|
PaymentPlatform string `form:"payment_platform,optional"` // 支付方式
|
||||||
PaymentScene string `form:"payment_scene,optional"` // 支付平台
|
PaymentScene string `form:"payment_scene,optional"` // 支付平台
|
||||||
Amount float64 `form:"amount,optional"` // 金额
|
Amount float64 `form:"amount,optional"` // 金额
|
||||||
Status string `form:"status,optional"` // 支付状态:pending-待支付,paid-已支付,refunded-已退款,closed-已关闭,failed-支付失败
|
Status string `form:"status,optional"` // 支付状态:pending-待支付,paid-已支付,refunded-已退款,closed-已关闭,failed-支付失败
|
||||||
IsPromotion int64 `form:"is_promotion,optional,default=-1"` // 是否推广订单:0-否,1-是
|
CreateTimeStart string `form:"create_time_start,optional"` // 创建时间开始
|
||||||
CreateTimeStart string `form:"create_time_start,optional"` // 创建时间开始
|
CreateTimeEnd string `form:"create_time_end,optional"` // 创建时间结束
|
||||||
CreateTimeEnd string `form:"create_time_end,optional"` // 创建时间结束
|
PayTimeStart string `form:"pay_time_start,optional"` // 支付时间开始
|
||||||
PayTimeStart string `form:"pay_time_start,optional"` // 支付时间开始
|
PayTimeEnd string `form:"pay_time_end,optional"` // 支付时间结束
|
||||||
PayTimeEnd string `form:"pay_time_end,optional"` // 支付时间结束
|
RefundTimeStart string `form:"refund_time_start,optional"` // 退款时间开始
|
||||||
RefundTimeStart string `form:"refund_time_start,optional"` // 退款时间开始
|
RefundTimeEnd string `form:"refund_time_end,optional"` // 退款时间结束
|
||||||
RefundTimeEnd string `form:"refund_time_end,optional"` // 退款时间结束
|
SalesCost float64 `form:"sales_cost,optional"` // 成本价
|
||||||
SalesCost float64 `form:"sales_cost,optional"` // 成本价
|
QueryName string `form:"query_name,optional"` // 被查询人姓名(通过 query_user_record 表追溯订单)
|
||||||
QueryName string `form:"query_name,optional"` // 被查询人姓名(通过 query_user_record 表追溯订单)
|
QueryIdCard string `form:"query_id_card,optional"` // 被查询人身份证(通过 query_user_record 表追溯订单)
|
||||||
QueryIdCard string `form:"query_id_card,optional"` // 被查询人身份证(通过 query_user_record 表追溯订单)
|
QueryMobile string `form:"query_mobile,optional"` // 被查询人手机号(通过 query_user_record 表追溯订单)
|
||||||
QueryMobile string `form:"query_mobile,optional"` // 被查询人手机号(通过 query_user_record 表追溯订单)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type AdminGetOrderListResp struct {
|
type AdminGetOrderListResp struct {
|
||||||
@@ -876,6 +875,18 @@ type AdminUpdateAgentProductionConfigResp struct {
|
|||||||
Success bool `json:"success"` // 是否成功
|
Success bool `json:"success"` // 是否成功
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type AdminUpdateAgentReq struct {
|
||||||
|
Id int64 `json:"id"` // 主键
|
||||||
|
Mobile string `json:"mobile"` // 手机号
|
||||||
|
LevelName string `json:"level_name"` // 等级名称
|
||||||
|
Region string `json:"region"` // 区域
|
||||||
|
MembershipExpiryTime string `json:"membership_expiry_time"` // 会员到期时间(YYYY-MM-DD HH:mm:ss)
|
||||||
|
}
|
||||||
|
|
||||||
|
type AdminUpdateAgentResp struct {
|
||||||
|
Success bool `json:"success"` // 是否成功
|
||||||
|
}
|
||||||
|
|
||||||
type AdminUpdateAgentWalletBalanceReq struct {
|
type AdminUpdateAgentWalletBalanceReq struct {
|
||||||
AgentId int64 `json:"agent_id"` // 代理ID
|
AgentId int64 `json:"agent_id"` // 代理ID
|
||||||
Amount float64 `json:"amount"` // 修改金额(正数增加,负数减少)
|
Amount float64 `json:"amount"` // 修改金额(正数增加,负数减少)
|
||||||
@@ -938,7 +949,6 @@ type AdminUpdateOrderReq struct {
|
|||||||
Status *string `json:"status,optional"` // 支付状态:pending-待支付,paid-已支付,refunded-已退款,closed-已关闭,failed-支付失败
|
Status *string `json:"status,optional"` // 支付状态:pending-待支付,paid-已支付,refunded-已退款,closed-已关闭,failed-支付失败
|
||||||
PayTime *string `json:"pay_time,optional"` // 支付时间
|
PayTime *string `json:"pay_time,optional"` // 支付时间
|
||||||
RefundTime *string `json:"refund_time,optional"` // 退款时间
|
RefundTime *string `json:"refund_time,optional"` // 退款时间
|
||||||
IsPromotion *int64 `json:"is_promotion,optional"` // 是否推广订单:0-否,1-是
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type AdminUpdateOrderResp struct {
|
type AdminUpdateOrderResp struct {
|
||||||
@@ -1835,7 +1845,6 @@ type OrderListItem struct {
|
|||||||
CreateTime string `json:"create_time"` // 创建时间
|
CreateTime string `json:"create_time"` // 创建时间
|
||||||
PayTime string `json:"pay_time"` // 支付时间
|
PayTime string `json:"pay_time"` // 支付时间
|
||||||
RefundTime string `json:"refund_time"` // 退款时间
|
RefundTime string `json:"refund_time"` // 退款时间
|
||||||
IsPromotion int64 `json:"is_promotion"` // 是否推广订单:0-否,1-是
|
|
||||||
IsAgentOrder bool `json:"is_agent_order"` // 是否是代理订单
|
IsAgentOrder bool `json:"is_agent_order"` // 是否是代理订单
|
||||||
AgentProcessStatus string `json:"agent_process_status"` // 代理事务处理状态:not_agent-非代理订单,success-处理成功,failed-处理失败,pending-待处理
|
AgentProcessStatus string `json:"agent_process_status"` // 代理事务处理状态:not_agent-非代理订单,success-处理成功,failed-处理失败,pending-待处理
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,27 +0,0 @@
|
|||||||
package model
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/zeromicro/go-zero/core/stores/cache"
|
|
||||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
|
||||||
)
|
|
||||||
|
|
||||||
var _ AdminPromotionOrderModel = (*customAdminPromotionOrderModel)(nil)
|
|
||||||
|
|
||||||
type (
|
|
||||||
// AdminPromotionOrderModel is an interface to be customized, add more methods here,
|
|
||||||
// and implement the added methods in customAdminPromotionOrderModel.
|
|
||||||
AdminPromotionOrderModel interface {
|
|
||||||
adminPromotionOrderModel
|
|
||||||
}
|
|
||||||
|
|
||||||
customAdminPromotionOrderModel struct {
|
|
||||||
*defaultAdminPromotionOrderModel
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
// NewAdminPromotionOrderModel returns a model for the database table.
|
|
||||||
func NewAdminPromotionOrderModel(conn sqlx.SqlConn, c cache.CacheConf) AdminPromotionOrderModel {
|
|
||||||
return &customAdminPromotionOrderModel{
|
|
||||||
defaultAdminPromotionOrderModel: newAdminPromotionOrderModel(conn, c),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,410 +0,0 @@
|
|||||||
// Code generated by goctl. DO NOT EDIT!
|
|
||||||
|
|
||||||
package model
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"database/sql"
|
|
||||||
"fmt"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"bdrp-server/common/globalkey"
|
|
||||||
|
|
||||||
"github.com/Masterminds/squirrel"
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
"github.com/zeromicro/go-zero/core/stores/builder"
|
|
||||||
"github.com/zeromicro/go-zero/core/stores/cache"
|
|
||||||
"github.com/zeromicro/go-zero/core/stores/sqlc"
|
|
||||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
|
||||||
"github.com/zeromicro/go-zero/core/stringx"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
adminPromotionOrderFieldNames = builder.RawFieldNames(&AdminPromotionOrder{})
|
|
||||||
adminPromotionOrderRows = strings.Join(adminPromotionOrderFieldNames, ",")
|
|
||||||
adminPromotionOrderRowsExpectAutoSet = strings.Join(stringx.Remove(adminPromotionOrderFieldNames, "`id`", "`create_time`", "`update_time`"), ",")
|
|
||||||
adminPromotionOrderRowsWithPlaceHolder = strings.Join(stringx.Remove(adminPromotionOrderFieldNames, "`id`", "`create_time`", "`update_time`"), "=?,") + "=?"
|
|
||||||
|
|
||||||
cacheHmAdminPromotionOrderIdPrefix = "cache:bdrp:adminPromotionOrder:id:"
|
|
||||||
cacheHmAdminPromotionOrderOrderIdPrefix = "cache:bdrp:adminPromotionOrder:orderId:"
|
|
||||||
)
|
|
||||||
|
|
||||||
type (
|
|
||||||
adminPromotionOrderModel interface {
|
|
||||||
Insert(ctx context.Context, session sqlx.Session, data *AdminPromotionOrder) (sql.Result, error)
|
|
||||||
FindOne(ctx context.Context, id int64) (*AdminPromotionOrder, error)
|
|
||||||
FindOneByOrderId(ctx context.Context, orderId int64) (*AdminPromotionOrder, error)
|
|
||||||
Update(ctx context.Context, session sqlx.Session, data *AdminPromotionOrder) (sql.Result, error)
|
|
||||||
UpdateWithVersion(ctx context.Context, session sqlx.Session, data *AdminPromotionOrder) error
|
|
||||||
Trans(ctx context.Context, fn func(context context.Context, session sqlx.Session) error) error
|
|
||||||
SelectBuilder() squirrel.SelectBuilder
|
|
||||||
DeleteSoft(ctx context.Context, session sqlx.Session, data *AdminPromotionOrder) error
|
|
||||||
FindSum(ctx context.Context, sumBuilder squirrel.SelectBuilder, field string) (float64, error)
|
|
||||||
FindCount(ctx context.Context, countBuilder squirrel.SelectBuilder, field string) (int64, error)
|
|
||||||
FindAll(ctx context.Context, rowBuilder squirrel.SelectBuilder, orderBy string) ([]*AdminPromotionOrder, error)
|
|
||||||
FindPageListByPage(ctx context.Context, rowBuilder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*AdminPromotionOrder, error)
|
|
||||||
FindPageListByPageWithTotal(ctx context.Context, rowBuilder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*AdminPromotionOrder, int64, error)
|
|
||||||
FindPageListByIdDESC(ctx context.Context, rowBuilder squirrel.SelectBuilder, preMinId, pageSize int64) ([]*AdminPromotionOrder, error)
|
|
||||||
FindPageListByIdASC(ctx context.Context, rowBuilder squirrel.SelectBuilder, preMaxId, pageSize int64) ([]*AdminPromotionOrder, error)
|
|
||||||
Delete(ctx context.Context, session sqlx.Session, id int64) error
|
|
||||||
}
|
|
||||||
|
|
||||||
defaultAdminPromotionOrderModel struct {
|
|
||||||
sqlc.CachedConn
|
|
||||||
table string
|
|
||||||
}
|
|
||||||
|
|
||||||
AdminPromotionOrder struct {
|
|
||||||
Id int64 `db:"id"`
|
|
||||||
CreateTime time.Time `db:"create_time"`
|
|
||||||
UpdateTime time.Time `db:"update_time"`
|
|
||||||
DeleteTime sql.NullTime `db:"delete_time"` // 删除时间
|
|
||||||
DelState int64 `db:"del_state"`
|
|
||||||
Version int64 `db:"version"` // 版本号
|
|
||||||
LinkId int64 `db:"link_id"` // 推广链接ID
|
|
||||||
OrderId int64 `db:"order_id"` // 订单ID
|
|
||||||
UserId int64 `db:"user_id"` // 下单用户ID
|
|
||||||
AdminUserId int64 `db:"admin_user_id"` // 推广者账号ID
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
func newAdminPromotionOrderModel(conn sqlx.SqlConn, c cache.CacheConf) *defaultAdminPromotionOrderModel {
|
|
||||||
return &defaultAdminPromotionOrderModel{
|
|
||||||
CachedConn: sqlc.NewConn(conn, c),
|
|
||||||
table: "`admin_promotion_order`",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultAdminPromotionOrderModel) Insert(ctx context.Context, session sqlx.Session, data *AdminPromotionOrder) (sql.Result, error) {
|
|
||||||
data.DelState = globalkey.DelStateNo
|
|
||||||
hmAdminPromotionOrderIdKey := fmt.Sprintf("%s%v", cacheHmAdminPromotionOrderIdPrefix, data.Id)
|
|
||||||
hmAdminPromotionOrderOrderIdKey := fmt.Sprintf("%s%v", cacheHmAdminPromotionOrderOrderIdPrefix, data.OrderId)
|
|
||||||
return m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
|
||||||
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?)", m.table, adminPromotionOrderRowsExpectAutoSet)
|
|
||||||
if session != nil {
|
|
||||||
return session.ExecCtx(ctx, query, data.DeleteTime, data.DelState, data.Version, data.LinkId, data.OrderId, data.UserId, data.AdminUserId)
|
|
||||||
}
|
|
||||||
return conn.ExecCtx(ctx, query, data.DeleteTime, data.DelState, data.Version, data.LinkId, data.OrderId, data.UserId, data.AdminUserId)
|
|
||||||
}, hmAdminPromotionOrderIdKey, hmAdminPromotionOrderOrderIdKey)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultAdminPromotionOrderModel) FindOne(ctx context.Context, id int64) (*AdminPromotionOrder, error) {
|
|
||||||
hmAdminPromotionOrderIdKey := fmt.Sprintf("%s%v", cacheHmAdminPromotionOrderIdPrefix, id)
|
|
||||||
var resp AdminPromotionOrder
|
|
||||||
err := m.QueryRowCtx(ctx, &resp, hmAdminPromotionOrderIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
|
|
||||||
query := fmt.Sprintf("select %s from %s where `id` = ? and del_state = ? limit 1", adminPromotionOrderRows, m.table)
|
|
||||||
return conn.QueryRowCtx(ctx, v, query, id, globalkey.DelStateNo)
|
|
||||||
})
|
|
||||||
switch err {
|
|
||||||
case nil:
|
|
||||||
return &resp, nil
|
|
||||||
case sqlc.ErrNotFound:
|
|
||||||
return nil, ErrNotFound
|
|
||||||
default:
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultAdminPromotionOrderModel) FindOneByOrderId(ctx context.Context, orderId int64) (*AdminPromotionOrder, error) {
|
|
||||||
hmAdminPromotionOrderOrderIdKey := fmt.Sprintf("%s%v", cacheHmAdminPromotionOrderOrderIdPrefix, orderId)
|
|
||||||
var resp AdminPromotionOrder
|
|
||||||
err := m.QueryRowIndexCtx(ctx, &resp, hmAdminPromotionOrderOrderIdKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
|
|
||||||
query := fmt.Sprintf("select %s from %s where `order_id` = ? and del_state = ? limit 1", adminPromotionOrderRows, m.table)
|
|
||||||
if err := conn.QueryRowCtx(ctx, &resp, query, orderId, globalkey.DelStateNo); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return resp.Id, nil
|
|
||||||
}, m.queryPrimary)
|
|
||||||
switch err {
|
|
||||||
case nil:
|
|
||||||
return &resp, nil
|
|
||||||
case sqlc.ErrNotFound:
|
|
||||||
return nil, ErrNotFound
|
|
||||||
default:
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultAdminPromotionOrderModel) Update(ctx context.Context, session sqlx.Session, newData *AdminPromotionOrder) (sql.Result, error) {
|
|
||||||
data, err := m.FindOne(ctx, newData.Id)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
hmAdminPromotionOrderIdKey := fmt.Sprintf("%s%v", cacheHmAdminPromotionOrderIdPrefix, data.Id)
|
|
||||||
hmAdminPromotionOrderOrderIdKey := fmt.Sprintf("%s%v", cacheHmAdminPromotionOrderOrderIdPrefix, data.OrderId)
|
|
||||||
return m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
|
||||||
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, adminPromotionOrderRowsWithPlaceHolder)
|
|
||||||
if session != nil {
|
|
||||||
return session.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.LinkId, newData.OrderId, newData.UserId, newData.AdminUserId, newData.Id)
|
|
||||||
}
|
|
||||||
return conn.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.LinkId, newData.OrderId, newData.UserId, newData.AdminUserId, newData.Id)
|
|
||||||
}, hmAdminPromotionOrderIdKey, hmAdminPromotionOrderOrderIdKey)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultAdminPromotionOrderModel) UpdateWithVersion(ctx context.Context, session sqlx.Session, newData *AdminPromotionOrder) error {
|
|
||||||
|
|
||||||
oldVersion := newData.Version
|
|
||||||
newData.Version += 1
|
|
||||||
|
|
||||||
var sqlResult sql.Result
|
|
||||||
var err error
|
|
||||||
|
|
||||||
data, err := m.FindOne(ctx, newData.Id)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
hmAdminPromotionOrderIdKey := fmt.Sprintf("%s%v", cacheHmAdminPromotionOrderIdPrefix, data.Id)
|
|
||||||
hmAdminPromotionOrderOrderIdKey := fmt.Sprintf("%s%v", cacheHmAdminPromotionOrderOrderIdPrefix, data.OrderId)
|
|
||||||
sqlResult, err = m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
|
||||||
query := fmt.Sprintf("update %s set %s where `id` = ? and version = ? ", m.table, adminPromotionOrderRowsWithPlaceHolder)
|
|
||||||
if session != nil {
|
|
||||||
return session.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.LinkId, newData.OrderId, newData.UserId, newData.AdminUserId, newData.Id, oldVersion)
|
|
||||||
}
|
|
||||||
return conn.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.LinkId, newData.OrderId, newData.UserId, newData.AdminUserId, newData.Id, oldVersion)
|
|
||||||
}, hmAdminPromotionOrderIdKey, hmAdminPromotionOrderOrderIdKey)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
updateCount, err := sqlResult.RowsAffected()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if updateCount == 0 {
|
|
||||||
return ErrNoRowsUpdate
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultAdminPromotionOrderModel) DeleteSoft(ctx context.Context, session sqlx.Session, data *AdminPromotionOrder) error {
|
|
||||||
data.DelState = globalkey.DelStateYes
|
|
||||||
data.DeleteTime = sql.NullTime{Time: time.Now(), Valid: true}
|
|
||||||
if err := m.UpdateWithVersion(ctx, session, data); err != nil {
|
|
||||||
return errors.Wrapf(errors.New("delete soft failed "), "AdminPromotionOrderModel delete err : %+v", err)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultAdminPromotionOrderModel) FindSum(ctx context.Context, builder squirrel.SelectBuilder, field string) (float64, error) {
|
|
||||||
|
|
||||||
if len(field) == 0 {
|
|
||||||
return 0, errors.Wrapf(errors.New("FindSum Least One Field"), "FindSum Least One Field")
|
|
||||||
}
|
|
||||||
|
|
||||||
builder = builder.Columns("IFNULL(SUM(" + field + "),0)")
|
|
||||||
|
|
||||||
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).ToSql()
|
|
||||||
if err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
|
|
||||||
var resp float64
|
|
||||||
err = m.QueryRowNoCacheCtx(ctx, &resp, query, values...)
|
|
||||||
switch err {
|
|
||||||
case nil:
|
|
||||||
return resp, nil
|
|
||||||
default:
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultAdminPromotionOrderModel) FindCount(ctx context.Context, builder squirrel.SelectBuilder, field string) (int64, error) {
|
|
||||||
|
|
||||||
if len(field) == 0 {
|
|
||||||
return 0, errors.Wrapf(errors.New("FindCount Least One Field"), "FindCount Least One Field")
|
|
||||||
}
|
|
||||||
|
|
||||||
builder = builder.Columns("COUNT(" + field + ")")
|
|
||||||
|
|
||||||
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).ToSql()
|
|
||||||
if err != nil {
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
|
|
||||||
var resp int64
|
|
||||||
err = m.QueryRowNoCacheCtx(ctx, &resp, query, values...)
|
|
||||||
switch err {
|
|
||||||
case nil:
|
|
||||||
return resp, nil
|
|
||||||
default:
|
|
||||||
return 0, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultAdminPromotionOrderModel) FindAll(ctx context.Context, builder squirrel.SelectBuilder, orderBy string) ([]*AdminPromotionOrder, error) {
|
|
||||||
|
|
||||||
builder = builder.Columns(adminPromotionOrderRows)
|
|
||||||
|
|
||||||
if orderBy == "" {
|
|
||||||
builder = builder.OrderBy("id DESC")
|
|
||||||
} else {
|
|
||||||
builder = builder.OrderBy(orderBy)
|
|
||||||
}
|
|
||||||
|
|
||||||
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).ToSql()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
var resp []*AdminPromotionOrder
|
|
||||||
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
|
||||||
switch err {
|
|
||||||
case nil:
|
|
||||||
return resp, nil
|
|
||||||
default:
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultAdminPromotionOrderModel) FindPageListByPage(ctx context.Context, builder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*AdminPromotionOrder, error) {
|
|
||||||
|
|
||||||
builder = builder.Columns(adminPromotionOrderRows)
|
|
||||||
|
|
||||||
if orderBy == "" {
|
|
||||||
builder = builder.OrderBy("id DESC")
|
|
||||||
} else {
|
|
||||||
builder = builder.OrderBy(orderBy)
|
|
||||||
}
|
|
||||||
|
|
||||||
if page < 1 {
|
|
||||||
page = 1
|
|
||||||
}
|
|
||||||
offset := (page - 1) * pageSize
|
|
||||||
|
|
||||||
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).Offset(uint64(offset)).Limit(uint64(pageSize)).ToSql()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
var resp []*AdminPromotionOrder
|
|
||||||
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
|
||||||
switch err {
|
|
||||||
case nil:
|
|
||||||
return resp, nil
|
|
||||||
default:
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultAdminPromotionOrderModel) FindPageListByPageWithTotal(ctx context.Context, builder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*AdminPromotionOrder, int64, error) {
|
|
||||||
|
|
||||||
total, err := m.FindCount(ctx, builder, "id")
|
|
||||||
if err != nil {
|
|
||||||
return nil, 0, err
|
|
||||||
}
|
|
||||||
|
|
||||||
builder = builder.Columns(adminPromotionOrderRows)
|
|
||||||
|
|
||||||
if orderBy == "" {
|
|
||||||
builder = builder.OrderBy("id DESC")
|
|
||||||
} else {
|
|
||||||
builder = builder.OrderBy(orderBy)
|
|
||||||
}
|
|
||||||
|
|
||||||
if page < 1 {
|
|
||||||
page = 1
|
|
||||||
}
|
|
||||||
offset := (page - 1) * pageSize
|
|
||||||
|
|
||||||
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).Offset(uint64(offset)).Limit(uint64(pageSize)).ToSql()
|
|
||||||
if err != nil {
|
|
||||||
return nil, total, err
|
|
||||||
}
|
|
||||||
|
|
||||||
var resp []*AdminPromotionOrder
|
|
||||||
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
|
||||||
switch err {
|
|
||||||
case nil:
|
|
||||||
return resp, total, nil
|
|
||||||
default:
|
|
||||||
return nil, total, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultAdminPromotionOrderModel) FindPageListByIdDESC(ctx context.Context, builder squirrel.SelectBuilder, preMinId, pageSize int64) ([]*AdminPromotionOrder, error) {
|
|
||||||
|
|
||||||
builder = builder.Columns(adminPromotionOrderRows)
|
|
||||||
|
|
||||||
if preMinId > 0 {
|
|
||||||
builder = builder.Where(" id < ? ", preMinId)
|
|
||||||
}
|
|
||||||
|
|
||||||
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).OrderBy("id DESC").Limit(uint64(pageSize)).ToSql()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
var resp []*AdminPromotionOrder
|
|
||||||
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
|
||||||
switch err {
|
|
||||||
case nil:
|
|
||||||
return resp, nil
|
|
||||||
default:
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultAdminPromotionOrderModel) FindPageListByIdASC(ctx context.Context, builder squirrel.SelectBuilder, preMaxId, pageSize int64) ([]*AdminPromotionOrder, error) {
|
|
||||||
|
|
||||||
builder = builder.Columns(adminPromotionOrderRows)
|
|
||||||
|
|
||||||
if preMaxId > 0 {
|
|
||||||
builder = builder.Where(" id > ? ", preMaxId)
|
|
||||||
}
|
|
||||||
|
|
||||||
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).OrderBy("id ASC").Limit(uint64(pageSize)).ToSql()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
var resp []*AdminPromotionOrder
|
|
||||||
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
|
||||||
switch err {
|
|
||||||
case nil:
|
|
||||||
return resp, nil
|
|
||||||
default:
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultAdminPromotionOrderModel) Trans(ctx context.Context, fn func(ctx context.Context, session sqlx.Session) error) error {
|
|
||||||
|
|
||||||
return m.TransactCtx(ctx, func(ctx context.Context, session sqlx.Session) error {
|
|
||||||
return fn(ctx, session)
|
|
||||||
})
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultAdminPromotionOrderModel) SelectBuilder() squirrel.SelectBuilder {
|
|
||||||
return squirrel.Select().From(m.table)
|
|
||||||
}
|
|
||||||
func (m *defaultAdminPromotionOrderModel) Delete(ctx context.Context, session sqlx.Session, id int64) error {
|
|
||||||
data, err := m.FindOne(ctx, id)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
hmAdminPromotionOrderIdKey := fmt.Sprintf("%s%v", cacheHmAdminPromotionOrderIdPrefix, id)
|
|
||||||
hmAdminPromotionOrderOrderIdKey := fmt.Sprintf("%s%v", cacheHmAdminPromotionOrderOrderIdPrefix, data.OrderId)
|
|
||||||
_, err = m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
|
||||||
query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
|
|
||||||
if session != nil {
|
|
||||||
return session.ExecCtx(ctx, query, id)
|
|
||||||
}
|
|
||||||
return conn.ExecCtx(ctx, query, id)
|
|
||||||
}, hmAdminPromotionOrderIdKey, hmAdminPromotionOrderOrderIdKey)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
func (m *defaultAdminPromotionOrderModel) formatPrimary(primary interface{}) string {
|
|
||||||
return fmt.Sprintf("%s%v", cacheHmAdminPromotionOrderIdPrefix, primary)
|
|
||||||
}
|
|
||||||
func (m *defaultAdminPromotionOrderModel) queryPrimary(ctx context.Context, conn sqlx.SqlConn, v, primary interface{}) error {
|
|
||||||
query := fmt.Sprintf("select %s from %s where `id` = ? and del_state = ? limit 1", adminPromotionOrderRows, m.table)
|
|
||||||
return conn.QueryRowCtx(ctx, v, query, primary, globalkey.DelStateNo)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *defaultAdminPromotionOrderModel) tableName() string {
|
|
||||||
return m.table
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user