Skip to content

Commit

Permalink
feat: add GetRefundPage
Browse files Browse the repository at this point in the history
  • Loading branch information
agui-coder committed Dec 16, 2023
1 parent e3cca13 commit aa5b333
Show file tree
Hide file tree
Showing 7 changed files with 1,884 additions and 2,108 deletions.
16 changes: 1 addition & 15 deletions desc/refund.proto
Original file line number Diff line number Diff line change
Expand Up @@ -45,28 +45,14 @@ message RefundPageReq {
optional string merchantRefundId = 6;
optional string channelOrderNo = 7;
optional string channelRefundNo = 8;
optional string status = 9;
optional uint32 status = 9;
repeated int64 createTime = 10;

}

message RefundCountResp {
uint64 count = 1;
}

message RefundListResp {
uint64 total = 1;
repeated RefundInfo data = 2;
}

message RefundListReq {
uint64 page = 1;
uint64 page_size = 2;
optional string no = 3;
optional string channel_code = 4;
optional string order_no = 5;
}

message NotifyRefundReq {
uint32 Status = 1;
string OutRefundNo = 2;
Expand Down
2 changes: 1 addition & 1 deletion internal/logic/refund/create_refund_logic.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (l *CreateRefundLogic) CreateRefund(in *pay.RefundCreateReq) (*pay.BaseIDRe
NotifyUrl: l.svcCtx.Config.PayProperties.RefundNotifyUrl + "/" + refundInfo.ChannelCode,
})
if err != nil {
logx.Errorf("[RefundApproved][退款 id:%d err:%s", refundInfo.ID, err.Error())
logx.Errorf("[CreateRefund][退款 id:%d err:%s", refundInfo.ID, err.Error())
}
err = NewNotifyRefundLogic(newCtx, l.svcCtx).ProcessRefundStatus(refundUnifiedResp)
if err != nil {
Expand Down
76 changes: 0 additions & 76 deletions internal/logic/refund/get_refund_list_logic.go

This file was deleted.

64 changes: 62 additions & 2 deletions internal/logic/refund/get_refund_page_logic.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ package refund

import (
"context"
"github.com/agui-coder/simple-admin-pay-rpc/ent/predicate"
"github.com/agui-coder/simple-admin-pay-rpc/ent/refund"
"github.com/agui-coder/simple-admin-pay-rpc/pay"
"github.com/agui-coder/simple-admin-pay-rpc/utils/errorhandler"
"github.com/suyuan32/simple-admin-common/utils/pointy"

"github.com/agui-coder/simple-admin-pay-rpc/internal/svc"

Expand All @@ -24,7 +28,63 @@ func NewGetRefundPageLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Get
}

func (l *GetRefundPageLogic) GetRefundPage(in *pay.RefundPageReq) (*pay.RefundPageResp, error) {
// todo: add your logic here and delete this line
var predicates []predicate.Refund
if in.ChannelCode != nil {
predicates = append(predicates, refund.ChannelCodeEQ(*in.ChannelCode))
}
if in.MerchantOrderId != nil {
predicates = append(predicates, refund.MerchantOrderIDContains(*in.MerchantOrderId))
}
if in.MerchantRefundId != nil {
predicates = append(predicates, refund.MerchantRefundIDContains(*in.MerchantRefundId))

}
if in.ChannelOrderNo != nil {
predicates = append(predicates, refund.ChannelOrderNoContains(*in.ChannelOrderNo))
}
if in.ChannelRefundNo != nil {
predicates = append(predicates, refund.ChannelRefundNoContains(*in.ChannelRefundNo))
}
if in.Status != nil {
predicates = append(predicates, refund.StatusEQ(*pointy.GetStatusPointer(in.Status)))
}
if in.CreateTime != nil {
predicates = append(predicates, refund.CreatedAtGT(*pointy.GetTimePointer(&in.CreateTime[0], 0)))
predicates = append(predicates, refund.CreatedAtLT(*pointy.GetTimePointer(&in.CreateTime[1], 0)))
}
result, err := l.svcCtx.DB.Refund.Query().Where(predicates...).Page(l.ctx, in.Page, in.PageSize)

if err != nil {
return nil, errorhandler.DefaultEntError(l.Logger, err, in)
}

resp := &pay.RefundPageResp{}
resp.Total = result.PageDetails.Total

for _, v := range result.List {
resp.Data = append(resp.Data, &pay.RefundInfo{
Id: &v.ID,
CreatedAt: pointy.GetPointer(v.CreatedAt.UnixMilli()),
UpdatedAt: pointy.GetPointer(v.UpdatedAt.UnixMilli()),
Status: pointy.GetPointer(uint32(v.Status)),
No: &v.No,
ChannelCode: &v.ChannelCode,
OrderId: &v.OrderID,
OrderNo: &v.OrderNo,
MerchantOrderId: &v.MerchantOrderID,
MerchantRefundId: &v.MerchantRefundID,
PayPrice: &v.PayPrice,
RefundPrice: &v.RefundPrice,
Reason: &v.Reason,
UserIp: &v.UserIP,
ChannelOrderNo: &v.ChannelOrderNo,
ChannelRefundNo: &v.ChannelRefundNo,
SuccessTime: pointy.GetPointer(v.SuccessTime.UnixMilli()),
ChannelErrorCode: &v.ChannelErrorCode,
ChannelErrorMsg: &v.ChannelErrorMsg,
ChannelNotifyData: &v.ChannelNotifyData,
})
}

return &pay.RefundPageResp{}, nil
return resp, nil
}
Loading

0 comments on commit aa5b333

Please sign in to comment.