From 4ff974eb8d2475172b206dbaff638645e5923fd0 Mon Sep 17 00:00:00 2001 From: gjs Date: Fri, 11 Sep 2026 17:06:04 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E4=BB=98=E5=9B=9E=E8=B0=83=E4=BB=A5?= =?UTF-8?q?=E5=90=8E=E6=9B=B4=E6=96=B0=E8=AE=A2=E5=8D=95=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- rpc/order/order.pb | Bin 18523 -> 18529 bytes rpc/order/order.proto | 6 +- rpc/order/pb/order.pb.go | 22 +-- rpc/order/pb/order_grpc.pb.go | 26 +-- services/order/internal/dao/order.go | 45 ++--- .../order/internal/logic/getOrderInfoLogic.go | 1 - .../logic/updateOrderDPayStatusLogic.go | 31 --- .../logic/updateOrderDeliverStatusLogic.go | 9 +- .../logic/updateOrderPayStatusLogic.go | 182 ++++++++++++++++++ services/order/internal/server/orderServer.go | 6 +- services/order/orderClient/order.go | 6 +- 11 files changed, 235 insertions(+), 99 deletions(-) delete mode 100644 services/order/internal/logic/updateOrderDPayStatusLogic.go create mode 100644 services/order/internal/logic/updateOrderPayStatusLogic.go diff --git a/rpc/order/order.pb b/rpc/order/order.pb index c1e24fa4b04de913d4d1bce93bd73c7f2467cb29..7e9fe78ba70ea1b5a6768f8b488e82636940467c 100644 GIT binary patch delta 88 zcmcaTf$`x4#tn~+8UJj4Vr;_BxOlRpb(fqZ7e_&2Wqe6xL8=6+0;2|N5Ic|`0^};` ramh@U@sQbk&3X|FkOA9}0kGpU0rs=xGc*SToB;|OlfgR{lQKJTlYll9v%WjQ1OdLYfIwac X4`2!vRd8fsbY)L+WMy(hlk7)zTXq>v diff --git a/rpc/order/order.proto b/rpc/order/order.proto index ac312b7..39fd23f 100644 --- a/rpc/order/order.proto +++ b/rpc/order/order.proto @@ -126,7 +126,7 @@ message UpdateOrderPayStatusRequest { int32 status = 2; double pay_price = 3; string remit_no = 4; - int32 type =5; + int32 pay_type =5; } message UpdateOrderPayStatusResponse { int64 id = 1; @@ -297,6 +297,8 @@ service order { }; }; rpc UpdateOrderDeliverStatus(UpdateOrderDeliverStatusRequest) returns(UpdateOrderDeliverStatusResponse); + //type 1为销售 2为门店 3为个人 rpc GetOrderInfo(GetOrderInfoRequest) returns(OrderInfoResponse); - rpc UpdateOrderDPayStatus(UpdateOrderPayStatusRequest) returns(UpdateOrderPayStatusResponse); + //status 1 为已支付 4 支付失败,其它的返回错误 + rpc UpdateOrderPayStatus(UpdateOrderPayStatusRequest) returns(UpdateOrderPayStatusResponse); } \ No newline at end of file diff --git a/rpc/order/pb/order.pb.go b/rpc/order/pb/order.pb.go index c9e0fa4..5181512 100644 --- a/rpc/order/pb/order.pb.go +++ b/rpc/order/pb/order.pb.go @@ -1164,7 +1164,7 @@ type UpdateOrderPayStatusRequest struct { Status int32 `protobuf:"varint,2,opt,name=status,proto3" json:"status,omitempty"` PayPrice float64 `protobuf:"fixed64,3,opt,name=pay_price,json=payPrice,proto3" json:"pay_price,omitempty"` RemitNo string `protobuf:"bytes,4,opt,name=remit_no,json=remitNo,proto3" json:"remit_no,omitempty"` - Type int32 `protobuf:"varint,5,opt,name=type,proto3" json:"type,omitempty"` + PayType int32 `protobuf:"varint,5,opt,name=pay_type,json=payType,proto3" json:"pay_type,omitempty"` unknownFields protoimpl.UnknownFields sizeCache protoimpl.SizeCache } @@ -1227,9 +1227,9 @@ func (x *UpdateOrderPayStatusRequest) GetRemitNo() string { return "" } -func (x *UpdateOrderPayStatusRequest) GetType() int32 { +func (x *UpdateOrderPayStatusRequest) GetPayType() int32 { if x != nil { - return x.Type + return x.PayType } return 0 } @@ -1807,13 +1807,13 @@ const file_order_order_proto_rawDesc = "" + "\x1fUpdateOrderDeliverStatusRequest\x12\x1b\n" + "\tsign_time\x18\x01 \x01(\tR\bsignTime\x12%\n" + "\x0edeliver_status\x18\x02 \x01(\x05R\rdeliverStatus\x12\x0e\n" + - "\x02id\x18\x03 \x01(\tR\x02id\"\x9c\x01\n" + + "\x02id\x18\x03 \x01(\tR\x02id\"\xa3\x01\n" + "\x1bUpdateOrderPayStatusRequest\x12\x19\n" + "\border_sn\x18\x01 \x01(\tR\aorderSn\x12\x16\n" + "\x06status\x18\x02 \x01(\x05R\x06status\x12\x1b\n" + "\tpay_price\x18\x03 \x01(\x01R\bpayPrice\x12\x19\n" + - "\bremit_no\x18\x04 \x01(\tR\aremitNo\x12\x12\n" + - "\x04type\x18\x05 \x01(\x05R\x04type\".\n" + + "\bremit_no\x18\x04 \x01(\tR\aremitNo\x12\x19\n" + + "\bpay_type\x18\x05 \x01(\x05R\apayType\".\n" + "\x1cUpdateOrderPayStatusResponse\x12\x0e\n" + "\x02id\x18\x01 \x01(\x03R\x02id\"4\n" + " UpdateOrderDeliverStatusResponse\x12\x10\n" + @@ -1864,7 +1864,7 @@ const file_order_order_proto_rawDesc = "" + "product_id\x18\x03 \x01(\x03R\tproductId\x12!\n" + "\fproduct_name\x18\x04 \x01(\tR\vproductName\x12\x14\n" + "\x05price\x18\x05 \x01(\x01R\x05price\x12\x16\n" + - "\x06number\x18\x06 \x01(\x05R\x06number2\xbe\x0f\n" + + "\x06number\x18\x06 \x01(\x05R\x06number2\xbd\x0f\n" + "\x05order\x12T\n" + "\x05Items\x12\x18.order.OrderItemsRequest\x1a\x0f.order.Response\" \x82\xd3\xe4\x93\x02\x1a:\x01*\x12\x15/admin/v3/order/items\x12X\n" + "\tWebCreate\x12\x19.order.CreateOrderRequest\x1a\x0f.order.Response\"\x1f\x82\xd3\xe4\x93\x02\x19:\x01*\"\x14/api/v3/order/create\x12b\n" + @@ -1885,8 +1885,8 @@ const file_order_order_proto_rawDesc = "" + "\tOrderDown\x12\x18.order.OrderItemsRequest\x1a\x1a.order.ExcelExportResponse\"\x1f\x82\xd3\xe4\x93\x02\x19:\x01*\x12\x14/admin/v3/order/down\x12O\n" + "\tOrderInfo\x12\x10.order.IdRequest\x1a\x0f.order.Response\"\x1f\x82\xd3\xe4\x93\x02\x19:\x01*\x12\x14/admin/v3/order/info\x12k\n" + "\x18UpdateOrderDeliverStatus\x12&.order.UpdateOrderDeliverStatusRequest\x1a'.order.UpdateOrderDeliverStatusResponse\x12D\n" + - "\fGetOrderInfo\x12\x1a.order.GetOrderInfoRequest\x1a\x18.order.OrderInfoResponse\x12`\n" + - "\x15UpdateOrderDPayStatus\x12\".order.UpdateOrderPayStatusRequest\x1a#.order.UpdateOrderPayStatusResponseB\x19Z\x17lone-services/rpc/orderb\x06proto3" + "\fGetOrderInfo\x12\x1a.order.GetOrderInfoRequest\x1a\x18.order.OrderInfoResponse\x12_\n" + + "\x14UpdateOrderPayStatus\x12\".order.UpdateOrderPayStatusRequest\x1a#.order.UpdateOrderPayStatusResponseB\x19Z\x17lone-services/rpc/orderb\x06proto3" var ( file_order_order_proto_rawDescOnce sync.Once @@ -1949,7 +1949,7 @@ var file_order_order_proto_depIdxs = []int32{ 9, // 18: order.order.OrderInfo:input_type -> order.IdRequest 17, // 19: order.order.UpdateOrderDeliverStatus:input_type -> order.UpdateOrderDeliverStatusRequest 21, // 20: order.order.GetOrderInfo:input_type -> order.GetOrderInfoRequest - 18, // 21: order.order.UpdateOrderDPayStatus:input_type -> order.UpdateOrderPayStatusRequest + 18, // 21: order.order.UpdateOrderPayStatus:input_type -> order.UpdateOrderPayStatusRequest 1, // 22: order.order.Items:output_type -> order.Response 1, // 23: order.order.WebCreate:output_type -> order.Response 1, // 24: order.order.WebCreateOne:output_type -> order.Response @@ -1970,7 +1970,7 @@ var file_order_order_proto_depIdxs = []int32{ 1, // 39: order.order.OrderInfo:output_type -> order.Response 20, // 40: order.order.UpdateOrderDeliverStatus:output_type -> order.UpdateOrderDeliverStatusResponse 22, // 41: order.order.GetOrderInfo:output_type -> order.OrderInfoResponse - 19, // 42: order.order.UpdateOrderDPayStatus:output_type -> order.UpdateOrderPayStatusResponse + 19, // 42: order.order.UpdateOrderPayStatus:output_type -> order.UpdateOrderPayStatusResponse 22, // [22:43] is the sub-list for method output_type 1, // [1:22] is the sub-list for method input_type 1, // [1:1] is the sub-list for extension type_name diff --git a/rpc/order/pb/order_grpc.pb.go b/rpc/order/pb/order_grpc.pb.go index de0ed70..c39fe5b 100644 --- a/rpc/order/pb/order_grpc.pb.go +++ b/rpc/order/pb/order_grpc.pb.go @@ -39,7 +39,7 @@ const ( Order_OrderInfo_FullMethodName = "/order.order/OrderInfo" Order_UpdateOrderDeliverStatus_FullMethodName = "/order.order/UpdateOrderDeliverStatus" Order_GetOrderInfo_FullMethodName = "/order.order/GetOrderInfo" - Order_UpdateOrderDPayStatus_FullMethodName = "/order.order/UpdateOrderDPayStatus" + Order_UpdateOrderPayStatus_FullMethodName = "/order.order/UpdateOrderPayStatus" ) // OrderClient is the client API for Order service. @@ -66,7 +66,7 @@ type OrderClient interface { OrderInfo(ctx context.Context, in *IdRequest, opts ...grpc.CallOption) (*Response, error) UpdateOrderDeliverStatus(ctx context.Context, in *UpdateOrderDeliverStatusRequest, opts ...grpc.CallOption) (*UpdateOrderDeliverStatusResponse, error) GetOrderInfo(ctx context.Context, in *GetOrderInfoRequest, opts ...grpc.CallOption) (*OrderInfoResponse, error) - UpdateOrderDPayStatus(ctx context.Context, in *UpdateOrderPayStatusRequest, opts ...grpc.CallOption) (*UpdateOrderPayStatusResponse, error) + UpdateOrderPayStatus(ctx context.Context, in *UpdateOrderPayStatusRequest, opts ...grpc.CallOption) (*UpdateOrderPayStatusResponse, error) } type orderClient struct { @@ -277,10 +277,10 @@ func (c *orderClient) GetOrderInfo(ctx context.Context, in *GetOrderInfoRequest, return out, nil } -func (c *orderClient) UpdateOrderDPayStatus(ctx context.Context, in *UpdateOrderPayStatusRequest, opts ...grpc.CallOption) (*UpdateOrderPayStatusResponse, error) { +func (c *orderClient) UpdateOrderPayStatus(ctx context.Context, in *UpdateOrderPayStatusRequest, opts ...grpc.CallOption) (*UpdateOrderPayStatusResponse, error) { cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) out := new(UpdateOrderPayStatusResponse) - err := c.cc.Invoke(ctx, Order_UpdateOrderDPayStatus_FullMethodName, in, out, cOpts...) + err := c.cc.Invoke(ctx, Order_UpdateOrderPayStatus_FullMethodName, in, out, cOpts...) if err != nil { return nil, err } @@ -311,7 +311,7 @@ type OrderServer interface { OrderInfo(context.Context, *IdRequest) (*Response, error) UpdateOrderDeliverStatus(context.Context, *UpdateOrderDeliverStatusRequest) (*UpdateOrderDeliverStatusResponse, error) GetOrderInfo(context.Context, *GetOrderInfoRequest) (*OrderInfoResponse, error) - UpdateOrderDPayStatus(context.Context, *UpdateOrderPayStatusRequest) (*UpdateOrderPayStatusResponse, error) + UpdateOrderPayStatus(context.Context, *UpdateOrderPayStatusRequest) (*UpdateOrderPayStatusResponse, error) mustEmbedUnimplementedOrderServer() } @@ -382,8 +382,8 @@ func (UnimplementedOrderServer) UpdateOrderDeliverStatus(context.Context, *Updat func (UnimplementedOrderServer) GetOrderInfo(context.Context, *GetOrderInfoRequest) (*OrderInfoResponse, error) { return nil, status.Error(codes.Unimplemented, "method GetOrderInfo not implemented") } -func (UnimplementedOrderServer) UpdateOrderDPayStatus(context.Context, *UpdateOrderPayStatusRequest) (*UpdateOrderPayStatusResponse, error) { - return nil, status.Error(codes.Unimplemented, "method UpdateOrderDPayStatus not implemented") +func (UnimplementedOrderServer) UpdateOrderPayStatus(context.Context, *UpdateOrderPayStatusRequest) (*UpdateOrderPayStatusResponse, error) { + return nil, status.Error(codes.Unimplemented, "method UpdateOrderPayStatus not implemented") } func (UnimplementedOrderServer) mustEmbedUnimplementedOrderServer() {} func (UnimplementedOrderServer) testEmbeddedByValue() {} @@ -766,20 +766,20 @@ func _Order_GetOrderInfo_Handler(srv interface{}, ctx context.Context, dec func( return interceptor(ctx, in, info, handler) } -func _Order_UpdateOrderDPayStatus_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { +func _Order_UpdateOrderPayStatus_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(UpdateOrderPayStatusRequest) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(OrderServer).UpdateOrderDPayStatus(ctx, in) + return srv.(OrderServer).UpdateOrderPayStatus(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: Order_UpdateOrderDPayStatus_FullMethodName, + FullMethod: Order_UpdateOrderPayStatus_FullMethodName, } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(OrderServer).UpdateOrderDPayStatus(ctx, req.(*UpdateOrderPayStatusRequest)) + return srv.(OrderServer).UpdateOrderPayStatus(ctx, req.(*UpdateOrderPayStatusRequest)) } return interceptor(ctx, in, info, handler) } @@ -872,8 +872,8 @@ var Order_ServiceDesc = grpc.ServiceDesc{ Handler: _Order_GetOrderInfo_Handler, }, { - MethodName: "UpdateOrderDPayStatus", - Handler: _Order_UpdateOrderDPayStatus_Handler, + MethodName: "UpdateOrderPayStatus", + Handler: _Order_UpdateOrderPayStatus_Handler, }, }, Streams: []grpc.StreamDesc{}, diff --git a/services/order/internal/dao/order.go b/services/order/internal/dao/order.go index 8517bde..8637e94 100644 --- a/services/order/internal/dao/order.go +++ b/services/order/internal/dao/order.go @@ -124,33 +124,6 @@ type OrderPay struct { OutTradeNo string `gorm:"column:out_trade_no;type:varchar(50);comment:支付订单号;NOT NULL" json:"out_trade_no"` } -type OrderDown struct { - Id int64 `gorm:"column:id;type:bigint(20);primary_key;AUTO_INCREMENT" json:"id"` - OrderSn string `gorm:"column:order_sn;type:varchar(100);comment:订单号;NOT NULL" json:"order_sn"` - StoreId int `gorm:"column:store_id;type:int(11);comment:美容院关联ID号" json:"store_id"` - StoreName string `gorm:"column:store_name;type:varchar(50);comment:门店名" json:"store_name"` - SaleName string `gorm:"column:sale_name;type:varchar(50);comment:销售姓名" json:"sale_name"` - SaleMobile string `gorm:"column:sale_mobile;type:char(60);comment:销售电话" json:"sale_mobile"` - SaleId int `gorm:"column:sale_id;type:int(11);comment:销售员ID号" json:"sale_id"` - Mobile string `gorm:"column:mobile;type:char(60);comment:收货人手机号;NOT NULL" json:"mobile"` - Address string `gorm:"column:address;type:varchar(255);comment:收货人地址;NOT NULL" json:"address"` - Addressee string `gorm:"column:addressee;type:varchar(50);comment:收货人姓名;NOT NULL" json:"addressee"` - DistrictIds string `gorm:"column:district_ids;type:varchar(255);comment:地区IDS;NOT NULL" json:"district_ids"` - TotalPrice float64 `gorm:"column:total_price;type:decimal(10,2);comment:总价;NOT NULL" json:"total_price"` - PayPrice float64 `gorm:"column:pay_price;type:decimal(10,2);comment:实际支付金额" json:"pay_price"` - PayType uint8 `gorm:"column:pay_type;type:tinyint(1);default:1;comment:支付类型,1为微信,2为支付宝,3为余额支付" json:"pay_type"` - Status uint8 `gorm:"column:status;type:tinyint(1);default:2;comment:支付状态,1为已支付,2为未支付,3为支付中,4支付失败,5已失效;NOT NULL" json:"status"` - ProductIds string `gorm:"column:product_ids;type:varchar(150);comment:产品IDs" json:"product_ids"` - SignTime utils.CustomTime `gorm:"column:sign_time;type:datetime;comment:签收时间" json:"sign_time"` - CreateType uint8 `gorm:"column:create_type;type:tinyint(1);default:1;comment:下单人类型,1为销售,2为门店,3为个人;NOT NULL" json:"create_type"` - CreateTime utils.CustomTime `gorm:"column:create_time;type:datetime;default:CURRENT_TIMESTAMP;comment:订单创建时间" json:"create_time"` - ProductName string `gorm:"-" json:"product_name"` - TypeName string `gorm:"-" json:"type_name"` - BankInfo string `gorm:"-" json:"bank_info"` - OriginalMobile string `gorm:"-" json:"original_mobile"` - OriginalSaleMobile string `gorm:"-" json:"original_sale_mobile"` -} - type OrderSaleItems struct { Id int64 `gorm:"column:id;type:bigint(20);primary_key;AUTO_INCREMENT" json:"id"` OrderSn string `gorm:"column:order_sn;type:varchar(100);comment:订单号;NOT NULL" json:"order_sn"` @@ -274,6 +247,7 @@ type OrderInfoDetail struct { DeliverStatus int32 `gorm:"column:deliver_status;type:tinyint(1);default:2;comment:发货状态,1为已签收,2为待发货,3为发货中,4为已发货" json:"deliver_status"` Status int32 `gorm:"column:status;type:tinyint(1);default:2;comment:支付状态,1为已支付,2为未支付,3为支付中,4支付失败,5已失效;NOT NULL" json:"status"` IsSupply int32 `gorm:"column:is_supply;type:tinyint(1);default:1;comment:是否补过货,1为没有,2为补过" json:"is_supply"` + RemitNo string `json:"remit_no" gorm:"remit_no"` // 线下汇款单号 Note string `gorm:"column:note;type:varchar(255);comment:备注" json:"note"` ProductIds string `gorm:"column:product_ids;type:varchar(150);comment:产品IDs" json:"product_ids"` OutTradeNo string `gorm:"column:out_trade_no;type:varchar(50);comment:支付订单号" json:"out_trade_no"` @@ -287,3 +261,20 @@ type Items struct { Count int64 `json:"count" default:"0" type:"int"` Items any `json:"items"` } + +type UpPayStatus struct { + Id int64 `gorm:"column:id;type:bigint(20);primary_key;AUTO_INCREMENT" json:"id"` + PayPrice float64 `gorm:"column:pay_price;type:decimal(10,2);comment:实际支付金额" json:"pay_price"` + PayType int32 `gorm:"column:pay_type;type:tinyint(1);default:1;comment:支付类型,1为微信,2为支付宝,3为余额支付" json:"pay_type"` + Status int32 `gorm:"column:status;type:tinyint(1);default:2;comment:支付状态,1为已支付,2为未支付,3为支付中,4支付失败,5已失效;NOT NULL" json:"status"` + RemitNo string `json:"remit_no" gorm:"remit_no"` // 线下汇款单号 + OrderSn string `gorm:"column:order_sn;type:varchar(100);comment:订单号;NOT NULL" json:"order_sn"` + Mobile string `gorm:"column:mobile;type:char(60);comment:收货人手机号;NOT NULL" json:"mobile"` + Address string `gorm:"column:address;type:varchar(255);comment:收货人地址;NOT NULL" json:"address"` + Addressee string `gorm:"column:addressee;type:varchar(50);comment:收货人姓名;NOT NULL" json:"addressee"` + DistrictIds string `gorm:"column:district_ids;type:varchar(255);comment:地区IDS;NOT NULL" json:"district_ids"` + DeliverStatus uint8 `gorm:"column:deliver_status;type:tinyint(1);default:2;comment:发货状态,1为已签收,2为待发货,3为发货中,4为已发货" json:"deliver_status"` + DeliverType uint8 `json:"deliver_type" gorm:"deliver_type"` // 发货类型,1为需要发货,2为不需要发货 + VerifyStatus uint8 `gorm:"column:verify_status;type:tinyint(1);default:0;comment:审核状态,1为通过,2为失败,3为待审核,0为正常订单不需要审核" json:"verify_status"` + ProductIds string `gorm:"column:product_ids;type:varchar(150);comment:产品IDs" json:"product_ids"` +} diff --git a/services/order/internal/logic/getOrderInfoLogic.go b/services/order/internal/logic/getOrderInfoLogic.go index 13e57c2..42f1025 100644 --- a/services/order/internal/logic/getOrderInfoLogic.go +++ b/services/order/internal/logic/getOrderInfoLogic.go @@ -19,7 +19,6 @@ type GetOrderInfoLogic struct { ctx context.Context svcCtx *svc.ServiceContext logx.Logger - BaseLogic } func NewGetOrderInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetOrderInfoLogic { diff --git a/services/order/internal/logic/updateOrderDPayStatusLogic.go b/services/order/internal/logic/updateOrderDPayStatusLogic.go deleted file mode 100644 index cd371a7..0000000 --- a/services/order/internal/logic/updateOrderDPayStatusLogic.go +++ /dev/null @@ -1,31 +0,0 @@ -package logic - -import ( - "context" - - "lone-services/rpc/order/pb" - "lone-services/services/order/internal/svc" - - "github.com/zeromicro/go-zero/core/logx" -) - -type UpdateOrderDPayStatusLogic struct { - ctx context.Context - svcCtx *svc.ServiceContext - logx.Logger - BaseLogic -} - -func NewUpdateOrderDPayStatusLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateOrderDPayStatusLogic { - return &UpdateOrderDPayStatusLogic{ - ctx: ctx, - svcCtx: svcCtx, - Logger: logx.WithContext(ctx), - } -} - -func (l *UpdateOrderDPayStatusLogic) UpdateOrderDPayStatus(in *order.UpdateOrderPayStatusRequest) (*order.UpdateOrderPayStatusResponse, error) { - // todo: add your logic here and delete this line - - return &order.UpdateOrderPayStatusResponse{}, nil -} diff --git a/services/order/internal/logic/updateOrderDeliverStatusLogic.go b/services/order/internal/logic/updateOrderDeliverStatusLogic.go index 89d7af2..63e40aa 100644 --- a/services/order/internal/logic/updateOrderDeliverStatusLogic.go +++ b/services/order/internal/logic/updateOrderDeliverStatusLogic.go @@ -4,11 +4,9 @@ import ( "context" "lone-services/pkg/modelbase" "lone-services/pkg/utils" + "lone-services/rpc/order/pb" "lone-services/services/order/internal/dao" "lone-services/services/order/internal/model" - "lone-services/services/order/validator" - - "lone-services/rpc/order/pb" "lone-services/services/order/internal/svc" "github.com/zeromicro/go-zero/core/logx" @@ -32,11 +30,6 @@ func NewUpdateOrderDeliverStatusLogic(ctx context.Context, svcCtx *svc.ServiceCo } func (l *UpdateOrderDeliverStatusLogic) UpdateOrderDeliverStatus(in *order.UpdateOrderDeliverStatusRequest) (*order.UpdateOrderDeliverStatusResponse, error) { - var v validator.UpdateOrderDeliverStatusValidator - if fail := l.checkParams(in, &v); fail != nil { - return nil, status.Error(codes.InvalidArgument, fail.Msg) - } - data := dao.OrderDeliverGoodsStatus{ DeliverStatus: uint8(in.DeliverStatus), } diff --git a/services/order/internal/logic/updateOrderPayStatusLogic.go b/services/order/internal/logic/updateOrderPayStatusLogic.go new file mode 100644 index 0000000..c1252eb --- /dev/null +++ b/services/order/internal/logic/updateOrderPayStatusLogic.go @@ -0,0 +1,182 @@ +package logic + +import ( + "context" + "lone-services/pkg/modelbase" + "lone-services/pkg/utils" + chore "lone-services/rpc/chore/pb" + express "lone-services/rpc/express/pb" + product "lone-services/rpc/product/pb" + "lone-services/services/order/internal/dao" + "lone-services/services/order/internal/model" + "strconv" + "strings" + + "lone-services/rpc/order/pb" + "lone-services/services/order/internal/svc" + + "github.com/zeromicro/go-zero/core/logx" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" +) + +type UpdateOrderPayStatusLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + logx.Logger +} + +func NewUpdateOrderPayStatusLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateOrderPayStatusLogic { + return &UpdateOrderPayStatusLogic{ + ctx: ctx, + svcCtx: svcCtx, + Logger: logx.WithContext(ctx), + } +} + +func (l *UpdateOrderPayStatusLogic) UpdateOrderPayStatus(in *order.UpdateOrderPayStatusRequest) (*order.UpdateOrderPayStatusResponse, error) { + var info dao.UpPayStatus + w := modelbase.Params{ + Eq: map[string]string{"order_sn": in.OrderSn}, + } + modelObj := model.OrderModel{}.Init() + err := modelObj.GetOne(w, &info) + if err != nil { + return nil, status.Error(codes.Internal, utils.Fail.Msg) + } + if info.Id < utils.NumberOne { + return nil, status.Error(codes.Internal, utils.ErrorNotFund.Msg) + } + + info.PayPrice = utils.RoundMoney(in.PayPrice) + info.PayType = in.PayType + info.RemitNo = in.RemitNo + if in.Status == dao.OrderPayStatusOk { + info.Status = dao.OrderPayStatusOk + } else if in.Status == dao.OrderPayStatusFail { + info.Status = dao.OrderPayStatusFail + } else { + return nil, status.Error(codes.Internal, utils.ErrorParams.Msg) + } + + deliverGoods, s := l.getDeliveryInfo(info) + if s != utils.Ok { + return nil, status.Error(codes.Internal, s.Msg) + } + _, err = modelObj.Edit(w, info) + if err != nil { + return nil, status.Error(codes.Internal, utils.Fail.Msg) + } + + s = l.setDeliverGoods(deliverGoods) + + if s != utils.Ok { + return nil, status.Error(codes.Internal, s.Msg) + } + + return &order.UpdateOrderPayStatusResponse{Id: info.Id}, nil +} + +func (l *UpdateOrderPayStatusLogic) setDeliverGoods(data express.DeliveryOrderCreateRequest) utils.Status { + cli, err := svc.GetRpcClient(l.svcCtx.ExpressSvcName) + if err != nil { + return utils.ErrorInternalServer + } + + client := express.NewExpressClient(cli.Conn()) + _, err = client.DeliveryOrderCreate(l.ctx, &data) + if err != nil { + logx.Errorf("set products err: %v", err) + return utils.ErrorInternalServer + } + return utils.Ok +} + +func (l *UpdateOrderPayStatusLogic) getDeliveryInfo(info dao.UpPayStatus) (express.DeliveryOrderCreateRequest, utils.Status) { + deliverGoods := express.DeliveryOrderCreateRequest{ + ObjId: strconv.FormatInt(info.Id, utils.NumberTen), + Mobile: info.Mobile, + Address: info.Address, + Addressee: info.Addressee, + ObjSn: info.OrderSn, + Type: dao.DeliverTypeOrder, + Status: dao.SendStatusWait, + } + if info.DeliverType == dao.OrderDeliverTypeSend { + deliverGoods.Status = dao.SendStatusOver + } + + w := modelbase.Params{Eq: map[string]string{"order_sn": info.OrderSn}} + var orderProducts []dao.OrderProductInfo + err := model.OrderProductModel{}.Init().Items(w, &orderProducts) + if err != nil || len(orderProducts) < utils.NumberOne { + logx.Errorf("get products err: %v", err) + return deliverGoods, utils.ErrorNotFund + } + var productIds []int64 + idsNumber := make(map[int64]int) + for _, item := range orderProducts { + productIds = append(productIds, item.ProductId) + idsNumber[item.ProductId] = item.Number + } + + cli, err := svc.GetRpcClient(l.svcCtx.ProductSvcName) + if err != nil { + logx.Errorf("get products err: %v", err) + return deliverGoods, utils.ErrorInternalServer + } + + productClient := product.NewProductClient(cli.Conn()) + productItems, err := productClient.ItemsByIds(l.ctx, &product.ItemsByIdsReq{Ids: productIds}) + if err != nil { + logx.Errorf("get products err: %v", err) + return deliverGoods, utils.ErrorInternalServer + } + + for _, item := range productItems.Items { + number := utils.NumberZero + if _, ok := idsNumber[item.Id]; ok { + number = idsNumber[item.Id] + } + deliverGoods.ProductInfo = append(deliverGoods.ProductInfo, &express.DeliverOrderProductInfo{ + ProductId: item.Id, + Number: int32(number), + Type: int32(item.Type), + ProductName: item.Name, + Price: item.Price, + }) + } + + clic, err := svc.GetRpcClient(l.svcCtx.ChoreSvcName) + if err != nil { + logx.Errorf("get region err: %v", err) + return deliverGoods, utils.ErrorInternalServer + } + + var regionIds []int64 + for _, item := range strings.Split(info.DistrictIds, utils.DecollatorComma) { + id, _ := strconv.Atoi(item) + regionIds = append(regionIds, int64(id)) + } + + clicClient := chore.NewChoreClient(clic.Conn()) + regionItems, err := clicClient.RegionsByIds(l.ctx, &chore.RegionsByIdsReq{Ids: regionIds}) + if err != nil { + logx.Errorf("get region err: %v", err) + return deliverGoods, utils.ErrorInternalServer + } + + switch len(regionItems.Items) { + case utils.NumberOne: + deliverGoods.Province = regionItems.Items[utils.NumberZero].Name + case utils.NumberTwo: + deliverGoods.Province = regionItems.Items[utils.NumberZero].Name + deliverGoods.City = regionItems.Items[utils.NumberOne].Name + case utils.NumberThree: + deliverGoods.Province = regionItems.Items[utils.NumberZero].Name + deliverGoods.City = regionItems.Items[utils.NumberOne].Name + deliverGoods.County = regionItems.Items[utils.NumberTwo].Name + } + + return deliverGoods, utils.Ok +} diff --git a/services/order/internal/server/orderServer.go b/services/order/internal/server/orderServer.go index 695e73a..80addda 100644 --- a/services/order/internal/server/orderServer.go +++ b/services/order/internal/server/orderServer.go @@ -123,7 +123,7 @@ func (s *OrderServer) GetOrderInfo(ctx context.Context, in *order.GetOrderInfoRe return l.GetOrderInfo(in) } -func (s *OrderServer) UpdateOrderDPayStatus(ctx context.Context, in *order.UpdateOrderPayStatusRequest) (*order.UpdateOrderPayStatusResponse, error) { - l := logic.NewUpdateOrderDPayStatusLogic(ctx, s.svcCtx) - return l.UpdateOrderDPayStatus(in) +func (s *OrderServer) UpdateOrderPayStatus(ctx context.Context, in *order.UpdateOrderPayStatusRequest) (*order.UpdateOrderPayStatusResponse, error) { + l := logic.NewUpdateOrderPayStatusLogic(ctx, s.svcCtx) + return l.UpdateOrderPayStatus(in) } diff --git a/services/order/orderClient/order.go b/services/order/orderClient/order.go index 26078d1..a51980e 100644 --- a/services/order/orderClient/order.go +++ b/services/order/orderClient/order.go @@ -60,7 +60,7 @@ type ( OrderInfo(ctx context.Context, in *IdRequest, opts ...grpc.CallOption) (*Response, error) UpdateOrderDeliverStatus(ctx context.Context, in *UpdateOrderDeliverStatusRequest, opts ...grpc.CallOption) (*UpdateOrderDeliverStatusResponse, error) GetOrderInfo(ctx context.Context, in *GetOrderInfoRequest, opts ...grpc.CallOption) (*OrderInfoResponse, error) - UpdateOrderDPayStatus(ctx context.Context, in *UpdateOrderPayStatusRequest, opts ...grpc.CallOption) (*UpdateOrderPayStatusResponse, error) + UpdateOrderPayStatus(ctx context.Context, in *UpdateOrderPayStatusRequest, opts ...grpc.CallOption) (*UpdateOrderPayStatusResponse, error) } defaultOrder struct { @@ -174,7 +174,7 @@ func (m *defaultOrder) GetOrderInfo(ctx context.Context, in *GetOrderInfoRequest return client.GetOrderInfo(ctx, in, opts...) } -func (m *defaultOrder) UpdateOrderDPayStatus(ctx context.Context, in *UpdateOrderPayStatusRequest, opts ...grpc.CallOption) (*UpdateOrderPayStatusResponse, error) { +func (m *defaultOrder) UpdateOrderPayStatus(ctx context.Context, in *UpdateOrderPayStatusRequest, opts ...grpc.CallOption) (*UpdateOrderPayStatusResponse, error) { client := order.NewOrderClient(m.cli.Conn()) - return client.UpdateOrderDPayStatus(ctx, in, opts...) + return client.UpdateOrderPayStatus(ctx, in, opts...) }