diff --git a/.gitea/workflows/cd-test.yml b/.gitea/workflows/cd-test.yml index 8f4e2db..9e2614c 100644 --- a/.gitea/workflows/cd-test.yml +++ b/.gitea/workflows/cd-test.yml @@ -26,6 +26,12 @@ jobs: -u "${{ vars.REGISTRY_USERNAME }}" \ --password-stdin + - name: Sync Host Repo + working-directory: /data/www/lone-services + run: | + git fetch origin develop + git pull origin develop + - name: Pull and Deploy working-directory: /data/www/lone-services/deploy run: | diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index a1315b5..9b0ffaf 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -10,10 +10,12 @@ on: - "services/admin/**" - "services/user/**" - "services/ad/**" + - "services/chore/**" - "rpc/product/**" - "rpc/admin/**" - "rpc/user/**" - "rpc/ad/**" + - "rpc/chore/**" - "pkg/**" - ".gitea/workflows/ci.yml" workflow_dispatch: @@ -27,6 +29,7 @@ jobs: admin: ${{ steps.filter.outputs.admin }} user: ${{ steps.filter.outputs.user }} ad: ${{ steps.filter.outputs.ad }} + chore: ${{ steps.filter.outputs.chore }} steps: - name: Checkout uses: https://git.ailuowan.com/deploy/checkout@v4 @@ -41,6 +44,7 @@ jobs: admin=false user=false ad=false + chore=false if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then bff=true @@ -48,6 +52,7 @@ jobs: admin=true user=true ad=true + chore=true else before="${{ github.event.before }}" if [ -z "$before" ] || [ "$before" = "0000000000000000000000000000000000000000" ]; then @@ -64,6 +69,7 @@ jobs: echo "$changed" | grep -qE '^(services/admin|rpc/admin|pkg)/|^\.gitea/workflows/ci\.yml$' && admin=true || true echo "$changed" | grep -qE '^(services/user|rpc/user|pkg)/|^\.gitea/workflows/ci\.yml$' && user=true || true echo "$changed" | grep -qE '^(services/ad|rpc/ad|pkg)/|^\.gitea/workflows/ci\.yml$' && ad=true || true + echo "$changed" | grep -qE '^(services/chore|rpc/chore|pkg)/|^\.gitea/workflows/ci\.yml$' && chore=true || true fi echo "bff=$bff" >> "$GITHUB_OUTPUT" @@ -71,7 +77,8 @@ jobs: echo "admin=$admin" >> "$GITHUB_OUTPUT" echo "user=$user" >> "$GITHUB_OUTPUT" echo "ad=$ad" >> "$GITHUB_OUTPUT" - echo "bff=$bff product=$product admin=$admin user=$user ad=$ad" + echo "chore=$chore" >> "$GITHUB_OUTPUT" + echo "bff=$bff product=$product admin=$admin user=$user ad=$ad chore=$chore" docker-bff: needs: changes @@ -89,7 +96,8 @@ jobs: - name: Docker build run: | - docker buildx build --load \ + docker buildx use default + docker buildx build --builder default --load \ -f bff/Dockerfile \ -t ${{ vars.REGISTRY }}/$NAME:latest \ . @@ -114,7 +122,8 @@ jobs: - name: Docker build run: | - docker buildx build --load \ + docker buildx use default + docker buildx build --builder default --load \ -f services/product/Dockerfile \ -t ${{ vars.REGISTRY }}/$NAME:latest \ . @@ -139,7 +148,8 @@ jobs: - name: Docker build run: | - docker buildx build --load \ + docker buildx use default + docker buildx build --builder default --load \ -f services/admin/Dockerfile \ -t ${{ vars.REGISTRY }}/$NAME:latest \ . @@ -164,7 +174,8 @@ jobs: - name: Docker build run: | - docker buildx build --load \ + docker buildx use default + docker buildx build --builder default --load \ -f services/user/Dockerfile \ -t ${{ vars.REGISTRY }}/$NAME:latest \ . @@ -189,7 +200,8 @@ jobs: - name: Docker build run: | - docker buildx build --load \ + docker buildx use default + docker buildx build --builder default --load \ -f services/ad/Dockerfile \ -t ${{ vars.REGISTRY }}/$NAME:latest \ . @@ -197,3 +209,29 @@ jobs: - name: Docker push run: | docker push ${{ vars.REGISTRY }}/$NAME:latest + + docker-chore: + needs: changes + if: needs.changes.outputs.chore == 'true' + runs-on: runner + env: + NAME: lone/chore + steps: + - name: Checkout + uses: https://git.ailuowan.com/deploy/checkout@v4 + + - name: Login Registry + run: | + echo "${{ secrets.REGISTRY_PASSWORD }}" | docker login ${{ vars.REGISTRY }} -u "${{ vars.REGISTRY_USERNAME }}" --password-stdin + + - name: Docker build + run: | + docker buildx use default + docker buildx build --builder default --load \ + -f services/chore/Dockerfile \ + -t ${{ vars.REGISTRY }}/$NAME:latest \ + . + + - name: Docker push + run: | + docker push ${{ vars.REGISTRY }}/$NAME:latest \ No newline at end of file diff --git a/README.md b/README.md index 1c13dc6..5e8ba58 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,8 @@ D:\Git\bin\bash.exe rpc/scripts/gen-rpc.sh order rpc/scripts/gen-rpc.sh order ``` +加一个服务需要在bff/etc/bff.yaml 加 Upstreams ,docker.compose.prod.yaml 加服务,nacos 加配置 + ## 如何加一个新服务 以加 `order` 为例(对标现有 `product`)。 diff --git a/pkg/rpcclient/client.go b/pkg/rpcclient/client.go new file mode 100644 index 0000000..92c7b1e --- /dev/null +++ b/pkg/rpcclient/client.go @@ -0,0 +1,69 @@ +package rpcclient + +import ( + "fmt" + "net" + "strconv" + "sync" + "time" + + "lone-services/pkg/discovery" + "lone-services/pkg/utils" + + "github.com/zeromicro/go-zero/core/logx" + "github.com/zeromicro/go-zero/zrpc" +) + +type cacheEntry struct { + cli zrpc.Client + target string + expireAt time.Time +} + +const cacheTTL = 30 * time.Second + +var ( + cacheLock sync.Mutex + cache = make(map[string]*cacheEntry) +) + +func Get(serviceName string) (zrpc.Client, error) { + if serviceName == utils.StringEmpty { + err := fmt.Errorf("rpc serviceName is empty") + logx.Error(err) + return nil, err + } + + cacheLock.Lock() + entry, ok := cache[serviceName] + if ok && time.Now().Before(entry.expireAt) { + cacheLock.Unlock() + return entry.cli, nil + } + delete(cache, serviceName) + cacheLock.Unlock() + + inst, err := discovery.Pick(serviceName) + if err != nil { + err = fmt.Errorf("discovery pick %s failed: %w", serviceName, err) + logx.Error(err) + return nil, err + } + + target := net.JoinHostPort(inst.IP, strconv.FormatUint(inst.Port, utils.NumberTen)) + + cli := zrpc.MustNewClient(zrpc.RpcClientConf{ + Target: target, + Timeout: utils.RpcTimeOut, + }) + + cacheLock.Lock() + cache[serviceName] = &cacheEntry{ + cli: cli, + target: target, + expireAt: time.Now().Add(cacheTTL), + } + cacheLock.Unlock() + + return cli, nil +} diff --git a/pkg/utils/status.go b/pkg/utils/status.go index 82ce699..8c8a6ff 100644 --- a/pkg/utils/status.go +++ b/pkg/utils/status.go @@ -107,6 +107,7 @@ var ( // ErrorNotFund 数据类 ErrorFormatDataError = Status{Code: 11010, Msg: "格式化数据出错"} + ErrorStockNotEnough = Status{Code: 11014, Msg: "库存不足"} // —————————————————————————————————————————————————————————————————————————————————————— diff --git a/rpc/chore/chore.pb b/rpc/chore/chore.pb index 0a2e9f5..896cfa5 100644 Binary files a/rpc/chore/chore.pb and b/rpc/chore/chore.pb differ diff --git a/rpc/chore/chore.proto b/rpc/chore/chore.proto index 20f4c88..66de98d 100644 --- a/rpc/chore/chore.proto +++ b/rpc/chore/chore.proto @@ -11,6 +11,12 @@ service Chore { body: "*" }; } + rpc Test(TestReq) returns (Response) { + option (google.api.http) = { + post: "/api/v3/chore/test" + body: "*" + }; + } } message Response { @@ -21,4 +27,10 @@ message Response { message PolicyReq { string key = 1; +} + +message TestReq { + int32 id = 1; + repeated int64 ids = 2; + uint32 number = 3; } \ No newline at end of file diff --git a/rpc/chore/pb/chore.pb.go b/rpc/chore/pb/chore.pb.go index a8629a9..b688f13 100644 --- a/rpc/chore/pb/chore.pb.go +++ b/rpc/chore/pb/chore.pb.go @@ -126,6 +126,66 @@ func (x *PolicyReq) GetKey() string { return "" } +type TestReq struct { + state protoimpl.MessageState `protogen:"open.v1"` + Id int32 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` + Ids []int64 `protobuf:"varint,2,rep,packed,name=ids,proto3" json:"ids,omitempty"` + Number uint32 `protobuf:"varint,3,opt,name=number,proto3" json:"number,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *TestReq) Reset() { + *x = TestReq{} + mi := &file_chore_chore_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *TestReq) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*TestReq) ProtoMessage() {} + +func (x *TestReq) ProtoReflect() protoreflect.Message { + mi := &file_chore_chore_proto_msgTypes[2] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use TestReq.ProtoReflect.Descriptor instead. +func (*TestReq) Descriptor() ([]byte, []int) { + return file_chore_chore_proto_rawDescGZIP(), []int{2} +} + +func (x *TestReq) GetId() int32 { + if x != nil { + return x.Id + } + return 0 +} + +func (x *TestReq) GetIds() []int64 { + if x != nil { + return x.Ids + } + return nil +} + +func (x *TestReq) GetNumber() uint32 { + if x != nil { + return x.Number + } + return 0 +} + var File_chore_chore_proto protoreflect.FileDescriptor const file_chore_chore_proto_rawDesc = "" + @@ -136,9 +196,14 @@ const file_chore_chore_proto_rawDesc = "" + "\x03msg\x18\x02 \x01(\tR\x03msg\x12\x12\n" + "\x04data\x18\x03 \x01(\tR\x04data\"\x1d\n" + "\tPolicyReq\x12\x10\n" + - "\x03key\x18\x01 \x01(\tR\x03key2Y\n" + + "\x03key\x18\x01 \x01(\tR\x03key\"C\n" + + "\aTestReq\x12\x0e\n" + + "\x02id\x18\x01 \x01(\x05R\x02id\x12\x10\n" + + "\x03ids\x18\x02 \x03(\x03R\x03ids\x12\x16\n" + + "\x06number\x18\x03 \x01(\rR\x06number2\xa1\x01\n" + "\x05Chore\x12P\n" + - "\x06Policy\x12\x10.chore.PolicyReq\x1a\x0f.chore.Response\"#\x82\xd3\xe4\x93\x02\x1d:\x01*\x12\x18/api/v3/chore/oss/policyB\x19Z\x17lone-services/rpc/choreb\x06proto3" + "\x06Policy\x12\x10.chore.PolicyReq\x1a\x0f.chore.Response\"#\x82\xd3\xe4\x93\x02\x1d:\x01*\x12\x18/api/v3/chore/oss/policy\x12F\n" + + "\x04Test\x12\x0e.chore.TestReq\x1a\x0f.chore.Response\"\x1d\x82\xd3\xe4\x93\x02\x17:\x01*\"\x12/api/v3/chore/testB\x19Z\x17lone-services/rpc/choreb\x06proto3" var ( file_chore_chore_proto_rawDescOnce sync.Once @@ -152,16 +217,19 @@ func file_chore_chore_proto_rawDescGZIP() []byte { return file_chore_chore_proto_rawDescData } -var file_chore_chore_proto_msgTypes = make([]protoimpl.MessageInfo, 2) +var file_chore_chore_proto_msgTypes = make([]protoimpl.MessageInfo, 3) var file_chore_chore_proto_goTypes = []any{ (*Response)(nil), // 0: chore.Response (*PolicyReq)(nil), // 1: chore.PolicyReq + (*TestReq)(nil), // 2: chore.TestReq } var file_chore_chore_proto_depIdxs = []int32{ 1, // 0: chore.Chore.Policy:input_type -> chore.PolicyReq - 0, // 1: chore.Chore.Policy:output_type -> chore.Response - 1, // [1:2] is the sub-list for method output_type - 0, // [0:1] is the sub-list for method input_type + 2, // 1: chore.Chore.Test:input_type -> chore.TestReq + 0, // 2: chore.Chore.Policy:output_type -> chore.Response + 0, // 3: chore.Chore.Test:output_type -> chore.Response + 2, // [2:4] is the sub-list for method output_type + 0, // [0:2] is the sub-list for method input_type 0, // [0:0] is the sub-list for extension type_name 0, // [0:0] is the sub-list for extension extendee 0, // [0:0] is the sub-list for field type_name @@ -178,7 +246,7 @@ func file_chore_chore_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: unsafe.Slice(unsafe.StringData(file_chore_chore_proto_rawDesc), len(file_chore_chore_proto_rawDesc)), NumEnums: 0, - NumMessages: 2, + NumMessages: 3, NumExtensions: 0, NumServices: 1, }, diff --git a/rpc/chore/pb/chore_grpc.pb.go b/rpc/chore/pb/chore_grpc.pb.go index 43ebb1c..6b84e16 100644 --- a/rpc/chore/pb/chore_grpc.pb.go +++ b/rpc/chore/pb/chore_grpc.pb.go @@ -20,6 +20,7 @@ const _ = grpc.SupportPackageIsVersion9 const ( Chore_Policy_FullMethodName = "/chore.Chore/Policy" + Chore_Test_FullMethodName = "/chore.Chore/Test" ) // ChoreClient is the client API for Chore service. @@ -27,6 +28,7 @@ const ( // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. type ChoreClient interface { Policy(ctx context.Context, in *PolicyReq, opts ...grpc.CallOption) (*Response, error) + Test(ctx context.Context, in *TestReq, opts ...grpc.CallOption) (*Response, error) } type choreClient struct { @@ -47,11 +49,22 @@ func (c *choreClient) Policy(ctx context.Context, in *PolicyReq, opts ...grpc.Ca return out, nil } +func (c *choreClient) Test(ctx context.Context, in *TestReq, opts ...grpc.CallOption) (*Response, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(Response) + err := c.cc.Invoke(ctx, Chore_Test_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + // ChoreServer is the server API for Chore service. // All implementations must embed UnimplementedChoreServer // for forward compatibility. type ChoreServer interface { Policy(context.Context, *PolicyReq) (*Response, error) + Test(context.Context, *TestReq) (*Response, error) mustEmbedUnimplementedChoreServer() } @@ -65,6 +78,9 @@ type UnimplementedChoreServer struct{} func (UnimplementedChoreServer) Policy(context.Context, *PolicyReq) (*Response, error) { return nil, status.Error(codes.Unimplemented, "method Policy not implemented") } +func (UnimplementedChoreServer) Test(context.Context, *TestReq) (*Response, error) { + return nil, status.Error(codes.Unimplemented, "method Test not implemented") +} func (UnimplementedChoreServer) mustEmbedUnimplementedChoreServer() {} func (UnimplementedChoreServer) testEmbeddedByValue() {} @@ -104,6 +120,24 @@ func _Chore_Policy_Handler(srv interface{}, ctx context.Context, dec func(interf return interceptor(ctx, in, info, handler) } +func _Chore_Test_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(TestReq) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ChoreServer).Test(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Chore_Test_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ChoreServer).Test(ctx, req.(*TestReq)) + } + return interceptor(ctx, in, info, handler) +} + // Chore_ServiceDesc is the grpc.ServiceDesc for Chore service. // It's only intended for direct use with grpc.RegisterService, // and not to be introspected or modified (even as a copy) @@ -115,6 +149,10 @@ var Chore_ServiceDesc = grpc.ServiceDesc{ MethodName: "Policy", Handler: _Chore_Policy_Handler, }, + { + MethodName: "Test", + Handler: _Chore_Test_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "chore/chore.proto", diff --git a/rpc/product/pb/product.pb.go b/rpc/product/pb/product.pb.go index f01256a..075acd7 100644 --- a/rpc/product/pb/product.pb.go +++ b/rpc/product/pb/product.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: // protoc-gen-go v1.36.11 -// protoc v4.25.8 +// protoc v3.19.4 // source: product/product.proto package product @@ -10,6 +10,7 @@ import ( _ "google.golang.org/genproto/googleapis/api/annotations" protoreflect "google.golang.org/protobuf/reflect/protoreflect" protoimpl "google.golang.org/protobuf/runtime/protoimpl" + emptypb "google.golang.org/protobuf/types/known/emptypb" reflect "reflect" sync "sync" unsafe "unsafe" @@ -82,6 +83,138 @@ func (x *Response) GetData() string { return "" } +type InfoByIdReq struct { + state protoimpl.MessageState `protogen:"open.v1"` + Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *InfoByIdReq) Reset() { + *x = InfoByIdReq{} + mi := &file_product_product_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *InfoByIdReq) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*InfoByIdReq) ProtoMessage() {} + +func (x *InfoByIdReq) ProtoReflect() protoreflect.Message { + mi := &file_product_product_proto_msgTypes[1] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use InfoByIdReq.ProtoReflect.Descriptor instead. +func (*InfoByIdReq) Descriptor() ([]byte, []int) { + return file_product_product_proto_rawDescGZIP(), []int{1} +} + +func (x *InfoByIdReq) GetId() int64 { + if x != nil { + return x.Id + } + return 0 +} + +type ItemsByIdsReq struct { + state protoimpl.MessageState `protogen:"open.v1"` + Ids []int64 `protobuf:"varint,1,rep,packed,name=ids,proto3" json:"ids,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *ItemsByIdsReq) Reset() { + *x = ItemsByIdsReq{} + mi := &file_product_product_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *ItemsByIdsReq) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ItemsByIdsReq) ProtoMessage() {} + +func (x *ItemsByIdsReq) ProtoReflect() protoreflect.Message { + mi := &file_product_product_proto_msgTypes[2] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ItemsByIdsReq.ProtoReflect.Descriptor instead. +func (*ItemsByIdsReq) Descriptor() ([]byte, []int) { + return file_product_product_proto_rawDescGZIP(), []int{2} +} + +func (x *ItemsByIdsReq) GetIds() []int64 { + if x != nil { + return x.Ids + } + return nil +} + +type ItemsByIdsData struct { + state protoimpl.MessageState `protogen:"open.v1"` + Items []*Item `protobuf:"bytes,1,rep,name=items,proto3" json:"items,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *ItemsByIdsData) Reset() { + *x = ItemsByIdsData{} + mi := &file_product_product_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *ItemsByIdsData) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ItemsByIdsData) ProtoMessage() {} + +func (x *ItemsByIdsData) ProtoReflect() protoreflect.Message { + mi := &file_product_product_proto_msgTypes[3] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ItemsByIdsData.ProtoReflect.Descriptor instead. +func (*ItemsByIdsData) Descriptor() ([]byte, []int) { + return file_product_product_proto_rawDescGZIP(), []int{3} +} + +func (x *ItemsByIdsData) GetItems() []*Item { + if x != nil { + return x.Items + } + return nil +} + type CreateReq struct { state protoimpl.MessageState `protogen:"open.v1"` Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` @@ -95,7 +228,7 @@ type CreateReq struct { SharePrice float64 `protobuf:"fixed64,9,opt,name=share_price,json=sharePrice,proto3" json:"share_price,omitempty"` AgentPrice float64 `protobuf:"fixed64,10,opt,name=agent_price,json=agentPrice,proto3" json:"agent_price,omitempty"` SaleReward string `protobuf:"bytes,11,opt,name=sale_reward,json=saleReward,proto3" json:"sale_reward,omitempty"` - Images string `protobuf:"bytes,12,opt,name=images,proto3" json:"images,omitempty"` + Images []string `protobuf:"bytes,12,rep,name=images,proto3" json:"images,omitempty"` Weight float64 `protobuf:"fixed64,13,opt,name=weight,proto3" json:"weight,omitempty"` Cubage string `protobuf:"bytes,14,opt,name=cubage,proto3" json:"cubage,omitempty"` Waybill string `protobuf:"bytes,15,opt,name=waybill,proto3" json:"waybill,omitempty"` @@ -116,7 +249,7 @@ type CreateReq struct { func (x *CreateReq) Reset() { *x = CreateReq{} - mi := &file_product_product_proto_msgTypes[1] + mi := &file_product_product_proto_msgTypes[4] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -128,7 +261,7 @@ func (x *CreateReq) String() string { func (*CreateReq) ProtoMessage() {} func (x *CreateReq) ProtoReflect() protoreflect.Message { - mi := &file_product_product_proto_msgTypes[1] + mi := &file_product_product_proto_msgTypes[4] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -141,7 +274,7 @@ func (x *CreateReq) ProtoReflect() protoreflect.Message { // Deprecated: Use CreateReq.ProtoReflect.Descriptor instead. func (*CreateReq) Descriptor() ([]byte, []int) { - return file_product_product_proto_rawDescGZIP(), []int{1} + return file_product_product_proto_rawDescGZIP(), []int{4} } func (x *CreateReq) GetName() string { @@ -221,11 +354,11 @@ func (x *CreateReq) GetSaleReward() string { return "" } -func (x *CreateReq) GetImages() string { +func (x *CreateReq) GetImages() []string { if x != nil { return x.Images } - return "" + return nil } func (x *CreateReq) GetWeight() float64 { @@ -335,7 +468,7 @@ type InfoReq struct { func (x *InfoReq) Reset() { *x = InfoReq{} - mi := &file_product_product_proto_msgTypes[2] + mi := &file_product_product_proto_msgTypes[5] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -347,7 +480,7 @@ func (x *InfoReq) String() string { func (*InfoReq) ProtoMessage() {} func (x *InfoReq) ProtoReflect() protoreflect.Message { - mi := &file_product_product_proto_msgTypes[2] + mi := &file_product_product_proto_msgTypes[5] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -360,7 +493,7 @@ func (x *InfoReq) ProtoReflect() protoreflect.Message { // Deprecated: Use InfoReq.ProtoReflect.Descriptor instead. func (*InfoReq) Descriptor() ([]byte, []int) { - return file_product_product_proto_rawDescGZIP(), []int{2} + return file_product_product_proto_rawDescGZIP(), []int{5} } func (x *InfoReq) GetId() int64 { @@ -381,7 +514,7 @@ type ItemsReq struct { func (x *ItemsReq) Reset() { *x = ItemsReq{} - mi := &file_product_product_proto_msgTypes[3] + mi := &file_product_product_proto_msgTypes[6] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -393,7 +526,7 @@ func (x *ItemsReq) String() string { func (*ItemsReq) ProtoMessage() {} func (x *ItemsReq) ProtoReflect() protoreflect.Message { - mi := &file_product_product_proto_msgTypes[3] + mi := &file_product_product_proto_msgTypes[6] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -406,7 +539,7 @@ func (x *ItemsReq) ProtoReflect() protoreflect.Message { // Deprecated: Use ItemsReq.ProtoReflect.Descriptor instead. func (*ItemsReq) Descriptor() ([]byte, []int) { - return file_product_product_proto_rawDescGZIP(), []int{3} + return file_product_product_proto_rawDescGZIP(), []int{6} } func (x *ItemsReq) GetName() string { @@ -438,7 +571,7 @@ type NamesReq struct { func (x *NamesReq) Reset() { *x = NamesReq{} - mi := &file_product_product_proto_msgTypes[4] + mi := &file_product_product_proto_msgTypes[7] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -450,7 +583,7 @@ func (x *NamesReq) String() string { func (*NamesReq) ProtoMessage() {} func (x *NamesReq) ProtoReflect() protoreflect.Message { - mi := &file_product_product_proto_msgTypes[4] + mi := &file_product_product_proto_msgTypes[7] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -463,7 +596,7 @@ func (x *NamesReq) ProtoReflect() protoreflect.Message { // Deprecated: Use NamesReq.ProtoReflect.Descriptor instead. func (*NamesReq) Descriptor() ([]byte, []int) { - return file_product_product_proto_rawDescGZIP(), []int{4} + return file_product_product_proto_rawDescGZIP(), []int{7} } type StatusReq struct { @@ -477,7 +610,7 @@ type StatusReq struct { func (x *StatusReq) Reset() { *x = StatusReq{} - mi := &file_product_product_proto_msgTypes[5] + mi := &file_product_product_proto_msgTypes[8] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -489,7 +622,7 @@ func (x *StatusReq) String() string { func (*StatusReq) ProtoMessage() {} func (x *StatusReq) ProtoReflect() protoreflect.Message { - mi := &file_product_product_proto_msgTypes[5] + mi := &file_product_product_proto_msgTypes[8] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -502,7 +635,7 @@ func (x *StatusReq) ProtoReflect() protoreflect.Message { // Deprecated: Use StatusReq.ProtoReflect.Descriptor instead. func (*StatusReq) Descriptor() ([]byte, []int) { - return file_product_product_proto_rawDescGZIP(), []int{5} + return file_product_product_proto_rawDescGZIP(), []int{8} } func (x *StatusReq) GetId() int64 { @@ -536,7 +669,7 @@ type SortReq struct { func (x *SortReq) Reset() { *x = SortReq{} - mi := &file_product_product_proto_msgTypes[6] + mi := &file_product_product_proto_msgTypes[9] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -548,7 +681,7 @@ func (x *SortReq) String() string { func (*SortReq) ProtoMessage() {} func (x *SortReq) ProtoReflect() protoreflect.Message { - mi := &file_product_product_proto_msgTypes[6] + mi := &file_product_product_proto_msgTypes[9] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -561,7 +694,7 @@ func (x *SortReq) ProtoReflect() protoreflect.Message { // Deprecated: Use SortReq.ProtoReflect.Descriptor instead. func (*SortReq) Descriptor() ([]byte, []int) { - return file_product_product_proto_rawDescGZIP(), []int{6} + return file_product_product_proto_rawDescGZIP(), []int{9} } func (x *SortReq) GetId() int64 { @@ -590,7 +723,7 @@ type VerifyReq struct { func (x *VerifyReq) Reset() { *x = VerifyReq{} - mi := &file_product_product_proto_msgTypes[7] + mi := &file_product_product_proto_msgTypes[10] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -602,7 +735,7 @@ func (x *VerifyReq) String() string { func (*VerifyReq) ProtoMessage() {} func (x *VerifyReq) ProtoReflect() protoreflect.Message { - mi := &file_product_product_proto_msgTypes[7] + mi := &file_product_product_proto_msgTypes[10] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -615,7 +748,7 @@ func (x *VerifyReq) ProtoReflect() protoreflect.Message { // Deprecated: Use VerifyReq.ProtoReflect.Descriptor instead. func (*VerifyReq) Descriptor() ([]byte, []int) { - return file_product_product_proto_rawDescGZIP(), []int{7} + return file_product_product_proto_rawDescGZIP(), []int{10} } func (x *VerifyReq) GetStatus() uint32 { @@ -651,7 +784,7 @@ type VerifyStatusReq struct { func (x *VerifyStatusReq) Reset() { *x = VerifyStatusReq{} - mi := &file_product_product_proto_msgTypes[8] + mi := &file_product_product_proto_msgTypes[11] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -663,7 +796,7 @@ func (x *VerifyStatusReq) String() string { func (*VerifyStatusReq) ProtoMessage() {} func (x *VerifyStatusReq) ProtoReflect() protoreflect.Message { - mi := &file_product_product_proto_msgTypes[8] + mi := &file_product_product_proto_msgTypes[11] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -676,7 +809,7 @@ func (x *VerifyStatusReq) ProtoReflect() protoreflect.Message { // Deprecated: Use VerifyStatusReq.ProtoReflect.Descriptor instead. func (*VerifyStatusReq) Descriptor() ([]byte, []int) { - return file_product_product_proto_rawDescGZIP(), []int{8} + return file_product_product_proto_rawDescGZIP(), []int{11} } func (x *VerifyStatusReq) GetId() int64 { @@ -710,7 +843,7 @@ type EditApplyReq struct { func (x *EditApplyReq) Reset() { *x = EditApplyReq{} - mi := &file_product_product_proto_msgTypes[9] + mi := &file_product_product_proto_msgTypes[12] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -722,7 +855,7 @@ func (x *EditApplyReq) String() string { func (*EditApplyReq) ProtoMessage() {} func (x *EditApplyReq) ProtoReflect() protoreflect.Message { - mi := &file_product_product_proto_msgTypes[9] + mi := &file_product_product_proto_msgTypes[12] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -735,7 +868,7 @@ func (x *EditApplyReq) ProtoReflect() protoreflect.Message { // Deprecated: Use EditApplyReq.ProtoReflect.Descriptor instead. func (*EditApplyReq) Descriptor() ([]byte, []int) { - return file_product_product_proto_rawDescGZIP(), []int{9} + return file_product_product_proto_rawDescGZIP(), []int{12} } func (x *EditApplyReq) GetId() int64 { @@ -762,7 +895,7 @@ type EditApplyPassReq struct { func (x *EditApplyPassReq) Reset() { *x = EditApplyPassReq{} - mi := &file_product_product_proto_msgTypes[10] + mi := &file_product_product_proto_msgTypes[13] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -774,7 +907,7 @@ func (x *EditApplyPassReq) String() string { func (*EditApplyPassReq) ProtoMessage() {} func (x *EditApplyPassReq) ProtoReflect() protoreflect.Message { - mi := &file_product_product_proto_msgTypes[10] + mi := &file_product_product_proto_msgTypes[13] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -787,7 +920,7 @@ func (x *EditApplyPassReq) ProtoReflect() protoreflect.Message { // Deprecated: Use EditApplyPassReq.ProtoReflect.Descriptor instead. func (*EditApplyPassReq) Descriptor() ([]byte, []int) { - return file_product_product_proto_rawDescGZIP(), []int{10} + return file_product_product_proto_rawDescGZIP(), []int{13} } func (x *EditApplyPassReq) GetId() int64 { @@ -806,7 +939,7 @@ type EditBaseReq struct { Waybill string `protobuf:"bytes,5,opt,name=waybill,proto3" json:"waybill,omitempty"` Weight float64 `protobuf:"fixed64,6,opt,name=weight,proto3" json:"weight,omitempty"` Cubage string `protobuf:"bytes,7,opt,name=cubage,proto3" json:"cubage,omitempty"` - Images string `protobuf:"bytes,8,opt,name=images,proto3" json:"images,omitempty"` + Images []string `protobuf:"bytes,8,rep,name=images,proto3" json:"images,omitempty"` PeriodValidity int32 `protobuf:"varint,9,opt,name=period_validity,json=periodValidity,proto3" json:"period_validity,omitempty"` PublishTime string `protobuf:"bytes,10,opt,name=publish_time,json=publishTime,proto3" json:"publish_time,omitempty"` Label string `protobuf:"bytes,11,opt,name=label,proto3" json:"label,omitempty"` @@ -819,7 +952,7 @@ type EditBaseReq struct { func (x *EditBaseReq) Reset() { *x = EditBaseReq{} - mi := &file_product_product_proto_msgTypes[11] + mi := &file_product_product_proto_msgTypes[14] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -831,7 +964,7 @@ func (x *EditBaseReq) String() string { func (*EditBaseReq) ProtoMessage() {} func (x *EditBaseReq) ProtoReflect() protoreflect.Message { - mi := &file_product_product_proto_msgTypes[11] + mi := &file_product_product_proto_msgTypes[14] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -844,7 +977,7 @@ func (x *EditBaseReq) ProtoReflect() protoreflect.Message { // Deprecated: Use EditBaseReq.ProtoReflect.Descriptor instead. func (*EditBaseReq) Descriptor() ([]byte, []int) { - return file_product_product_proto_rawDescGZIP(), []int{11} + return file_product_product_proto_rawDescGZIP(), []int{14} } func (x *EditBaseReq) GetId() int64 { @@ -896,11 +1029,11 @@ func (x *EditBaseReq) GetCubage() string { return "" } -func (x *EditBaseReq) GetImages() string { +func (x *EditBaseReq) GetImages() []string { if x != nil { return x.Images } - return "" + return nil } func (x *EditBaseReq) GetPeriodValidity() int32 { @@ -964,7 +1097,7 @@ type EditSusceptibleReq struct { func (x *EditSusceptibleReq) Reset() { *x = EditSusceptibleReq{} - mi := &file_product_product_proto_msgTypes[12] + mi := &file_product_product_proto_msgTypes[15] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -976,7 +1109,7 @@ func (x *EditSusceptibleReq) String() string { func (*EditSusceptibleReq) ProtoMessage() {} func (x *EditSusceptibleReq) ProtoReflect() protoreflect.Message { - mi := &file_product_product_proto_msgTypes[12] + mi := &file_product_product_proto_msgTypes[15] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -989,7 +1122,7 @@ func (x *EditSusceptibleReq) ProtoReflect() protoreflect.Message { // Deprecated: Use EditSusceptibleReq.ProtoReflect.Descriptor instead. func (*EditSusceptibleReq) Descriptor() ([]byte, []int) { - return file_product_product_proto_rawDescGZIP(), []int{12} + return file_product_product_proto_rawDescGZIP(), []int{15} } func (x *EditSusceptibleReq) GetId() int64 { @@ -1069,6 +1202,119 @@ func (x *EditSusceptibleReq) GetType() uint32 { return 0 } +// type: 1 增加, 2 减少;number 为变更数量 +type NumberReq struct { + state protoimpl.MessageState `protogen:"open.v1"` + Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` + Type uint32 `protobuf:"varint,2,opt,name=type,proto3" json:"type,omitempty"` + Number uint32 `protobuf:"varint,3,opt,name=number,proto3" json:"number,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *NumberReq) Reset() { + *x = NumberReq{} + mi := &file_product_product_proto_msgTypes[16] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *NumberReq) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*NumberReq) ProtoMessage() {} + +func (x *NumberReq) ProtoReflect() protoreflect.Message { + mi := &file_product_product_proto_msgTypes[16] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use NumberReq.ProtoReflect.Descriptor instead. +func (*NumberReq) Descriptor() ([]byte, []int) { + return file_product_product_proto_rawDescGZIP(), []int{16} +} + +func (x *NumberReq) GetId() int64 { + if x != nil { + return x.Id + } + return 0 +} + +func (x *NumberReq) GetType() uint32 { + if x != nil { + return x.Type + } + return 0 +} + +func (x *NumberReq) GetNumber() uint32 { + if x != nil { + return x.Number + } + return 0 +} + +type NumberAddReq struct { + state protoimpl.MessageState `protogen:"open.v1"` + Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` + Number uint32 `protobuf:"varint,2,opt,name=number,proto3" json:"number,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *NumberAddReq) Reset() { + *x = NumberAddReq{} + mi := &file_product_product_proto_msgTypes[17] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *NumberAddReq) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*NumberAddReq) ProtoMessage() {} + +func (x *NumberAddReq) ProtoReflect() protoreflect.Message { + mi := &file_product_product_proto_msgTypes[17] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use NumberAddReq.ProtoReflect.Descriptor instead. +func (*NumberAddReq) Descriptor() ([]byte, []int) { + return file_product_product_proto_rawDescGZIP(), []int{17} +} + +func (x *NumberAddReq) GetId() int64 { + if x != nil { + return x.Id + } + return 0 +} + +func (x *NumberAddReq) GetNumber() uint32 { + if x != nil { + return x.Number + } + return 0 +} + type ItemsData struct { state protoimpl.MessageState `protogen:"open.v1"` Count int64 `protobuf:"varint,1,opt,name=count,proto3" json:"count,omitempty"` @@ -1079,7 +1325,7 @@ type ItemsData struct { func (x *ItemsData) Reset() { *x = ItemsData{} - mi := &file_product_product_proto_msgTypes[13] + mi := &file_product_product_proto_msgTypes[18] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1091,7 +1337,7 @@ func (x *ItemsData) String() string { func (*ItemsData) ProtoMessage() {} func (x *ItemsData) ProtoReflect() protoreflect.Message { - mi := &file_product_product_proto_msgTypes[13] + mi := &file_product_product_proto_msgTypes[18] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1104,7 +1350,7 @@ func (x *ItemsData) ProtoReflect() protoreflect.Message { // Deprecated: Use ItemsData.ProtoReflect.Descriptor instead. func (*ItemsData) Descriptor() ([]byte, []int) { - return file_product_product_proto_rawDescGZIP(), []int{13} + return file_product_product_proto_rawDescGZIP(), []int{18} } func (x *ItemsData) GetCount() int64 { @@ -1131,7 +1377,7 @@ type VerifyItemsData struct { func (x *VerifyItemsData) Reset() { *x = VerifyItemsData{} - mi := &file_product_product_proto_msgTypes[14] + mi := &file_product_product_proto_msgTypes[19] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1143,7 +1389,7 @@ func (x *VerifyItemsData) String() string { func (*VerifyItemsData) ProtoMessage() {} func (x *VerifyItemsData) ProtoReflect() protoreflect.Message { - mi := &file_product_product_proto_msgTypes[14] + mi := &file_product_product_proto_msgTypes[19] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1156,7 +1402,7 @@ func (x *VerifyItemsData) ProtoReflect() protoreflect.Message { // Deprecated: Use VerifyItemsData.ProtoReflect.Descriptor instead. func (*VerifyItemsData) Descriptor() ([]byte, []int) { - return file_product_product_proto_rawDescGZIP(), []int{14} + return file_product_product_proto_rawDescGZIP(), []int{19} } func (x *VerifyItemsData) GetCount() int64 { @@ -1193,7 +1439,7 @@ type VerifyParams struct { func (x *VerifyParams) Reset() { *x = VerifyParams{} - mi := &file_product_product_proto_msgTypes[15] + mi := &file_product_product_proto_msgTypes[20] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1205,7 +1451,7 @@ func (x *VerifyParams) String() string { func (*VerifyParams) ProtoMessage() {} func (x *VerifyParams) ProtoReflect() protoreflect.Message { - mi := &file_product_product_proto_msgTypes[15] + mi := &file_product_product_proto_msgTypes[20] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1218,7 +1464,7 @@ func (x *VerifyParams) ProtoReflect() protoreflect.Message { // Deprecated: Use VerifyParams.ProtoReflect.Descriptor instead. func (*VerifyParams) Descriptor() ([]byte, []int) { - return file_product_product_proto_rawDescGZIP(), []int{15} + return file_product_product_proto_rawDescGZIP(), []int{20} } func (x *VerifyParams) GetId() int64 { @@ -1317,7 +1563,7 @@ type VerifyItem struct { func (x *VerifyItem) Reset() { *x = VerifyItem{} - mi := &file_product_product_proto_msgTypes[16] + mi := &file_product_product_proto_msgTypes[21] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1329,7 +1575,7 @@ func (x *VerifyItem) String() string { func (*VerifyItem) ProtoMessage() {} func (x *VerifyItem) ProtoReflect() protoreflect.Message { - mi := &file_product_product_proto_msgTypes[16] + mi := &file_product_product_proto_msgTypes[21] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1342,7 +1588,7 @@ func (x *VerifyItem) ProtoReflect() protoreflect.Message { // Deprecated: Use VerifyItem.ProtoReflect.Descriptor instead. func (*VerifyItem) Descriptor() ([]byte, []int) { - return file_product_product_proto_rawDescGZIP(), []int{16} + return file_product_product_proto_rawDescGZIP(), []int{21} } func (x *VerifyItem) GetName() string { @@ -1383,7 +1629,7 @@ type NameItem struct { func (x *NameItem) Reset() { *x = NameItem{} - mi := &file_product_product_proto_msgTypes[17] + mi := &file_product_product_proto_msgTypes[22] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1395,7 +1641,7 @@ func (x *NameItem) String() string { func (*NameItem) ProtoMessage() {} func (x *NameItem) ProtoReflect() protoreflect.Message { - mi := &file_product_product_proto_msgTypes[17] + mi := &file_product_product_proto_msgTypes[22] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1408,7 +1654,7 @@ func (x *NameItem) ProtoReflect() protoreflect.Message { // Deprecated: Use NameItem.ProtoReflect.Descriptor instead. func (*NameItem) Descriptor() ([]byte, []int) { - return file_product_product_proto_rawDescGZIP(), []int{17} + return file_product_product_proto_rawDescGZIP(), []int{22} } func (x *NameItem) GetId() int64 { @@ -1446,7 +1692,7 @@ type Item struct { IndexImage string `protobuf:"bytes,17,opt,name=index_image,json=indexImage,proto3" json:"index_image,omitempty"` Cubage string `protobuf:"bytes,18,opt,name=cubage,proto3" json:"cubage,omitempty"` Label string `protobuf:"bytes,19,opt,name=label,proto3" json:"label,omitempty"` - Images string `protobuf:"bytes,20,opt,name=images,proto3" json:"images,omitempty"` + Images []string `protobuf:"bytes,20,rep,name=images,proto3" json:"images,omitempty"` IsBuy uint32 `protobuf:"varint,21,opt,name=is_buy,json=isBuy,proto3" json:"is_buy,omitempty"` PeriodValidity int32 `protobuf:"varint,22,opt,name=period_validity,json=periodValidity,proto3" json:"period_validity,omitempty"` PublishTime string `protobuf:"bytes,23,opt,name=publish_time,json=publishTime,proto3" json:"publish_time,omitempty"` @@ -1469,7 +1715,7 @@ type Item struct { func (x *Item) Reset() { *x = Item{} - mi := &file_product_product_proto_msgTypes[18] + mi := &file_product_product_proto_msgTypes[23] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -1481,7 +1727,7 @@ func (x *Item) String() string { func (*Item) ProtoMessage() {} func (x *Item) ProtoReflect() protoreflect.Message { - mi := &file_product_product_proto_msgTypes[18] + mi := &file_product_product_proto_msgTypes[23] if x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -1494,7 +1740,7 @@ func (x *Item) ProtoReflect() protoreflect.Message { // Deprecated: Use Item.ProtoReflect.Descriptor instead. func (*Item) Descriptor() ([]byte, []int) { - return file_product_product_proto_rawDescGZIP(), []int{18} + return file_product_product_proto_rawDescGZIP(), []int{23} } func (x *Item) GetId() int64 { @@ -1630,11 +1876,11 @@ func (x *Item) GetLabel() string { return "" } -func (x *Item) GetImages() string { +func (x *Item) GetImages() []string { if x != nil { return x.Images } - return "" + return nil } func (x *Item) GetIsBuy() uint32 { @@ -1753,11 +1999,17 @@ var File_product_product_proto protoreflect.FileDescriptor const file_product_product_proto_rawDesc = "" + "\n" + - "\x15product/product.proto\x12\aproduct\x1a\x1cgoogle/api/annotations.proto\"D\n" + + "\x15product/product.proto\x12\aproduct\x1a\x1cgoogle/api/annotations.proto\x1a\x1bgoogle/protobuf/empty.proto\"D\n" + "\bResponse\x12\x12\n" + "\x04code\x18\x01 \x01(\x05R\x04code\x12\x10\n" + "\x03msg\x18\x02 \x01(\tR\x03msg\x12\x12\n" + - "\x04data\x18\x03 \x01(\tR\x04data\"\xf0\x05\n" + + "\x04data\x18\x03 \x01(\tR\x04data\"\x1d\n" + + "\vInfoByIdReq\x12\x0e\n" + + "\x02id\x18\x01 \x01(\x03R\x02id\"!\n" + + "\rItemsByIdsReq\x12\x10\n" + + "\x03ids\x18\x01 \x03(\x03R\x03ids\"5\n" + + "\x0eItemsByIdsData\x12#\n" + + "\x05items\x18\x01 \x03(\v2\r.product.ItemR\x05items\"\xf0\x05\n" + "\tCreateReq\x12\x12\n" + "\x04name\x18\x01 \x01(\tR\x04name\x12\x18\n" + "\asubhead\x18\x02 \x01(\tR\asubhead\x12\x18\n" + @@ -1778,7 +2030,7 @@ const file_product_product_proto_rawDesc = "" + "agentPrice\x12\x1f\n" + "\vsale_reward\x18\v \x01(\tR\n" + "saleReward\x12\x16\n" + - "\x06images\x18\f \x01(\tR\x06images\x12\x16\n" + + "\x06images\x18\f \x03(\tR\x06images\x12\x16\n" + "\x06weight\x18\r \x01(\x01R\x06weight\x12\x16\n" + "\x06cubage\x18\x0e \x01(\tR\x06cubage\x12\x18\n" + "\awaybill\x18\x0f \x01(\tR\awaybill\x12'\n" + @@ -1832,7 +2084,7 @@ const file_product_product_proto_rawDesc = "" + "\awaybill\x18\x05 \x01(\tR\awaybill\x12\x16\n" + "\x06weight\x18\x06 \x01(\x01R\x06weight\x12\x16\n" + "\x06cubage\x18\a \x01(\tR\x06cubage\x12\x16\n" + - "\x06images\x18\b \x01(\tR\x06images\x12'\n" + + "\x06images\x18\b \x03(\tR\x06images\x12'\n" + "\x0fperiod_validity\x18\t \x01(\x05R\x0eperiodValidity\x12!\n" + "\fpublish_time\x18\n" + " \x01(\tR\vpublishTime\x12\x14\n" + @@ -1860,7 +2112,14 @@ const file_product_product_proto_rawDesc = "" + "\n" + "box_number\x18\n" + " \x01(\x01R\tboxNumber\x12\x12\n" + - "\x04type\x18\v \x01(\rR\x04type\"F\n" + + "\x04type\x18\v \x01(\rR\x04type\"G\n" + + "\tNumberReq\x12\x0e\n" + + "\x02id\x18\x01 \x01(\x03R\x02id\x12\x12\n" + + "\x04type\x18\x02 \x01(\rR\x04type\x12\x16\n" + + "\x06number\x18\x03 \x01(\rR\x06number\"6\n" + + "\fNumberAddReq\x12\x0e\n" + + "\x02id\x18\x01 \x01(\x03R\x02id\x12\x16\n" + + "\x06number\x18\x02 \x01(\rR\x06number\"F\n" + "\tItemsData\x12\x14\n" + "\x05count\x18\x01 \x01(\x03R\x05count\x12#\n" + "\x05items\x18\x02 \x03(\v2\r.product.ItemR\x05items\"R\n" + @@ -1927,7 +2186,7 @@ const file_product_product_proto_rawDesc = "" + "indexImage\x12\x16\n" + "\x06cubage\x18\x12 \x01(\tR\x06cubage\x12\x14\n" + "\x05label\x18\x13 \x01(\tR\x05label\x12\x16\n" + - "\x06images\x18\x14 \x01(\tR\x06images\x12\x15\n" + + "\x06images\x18\x14 \x03(\tR\x06images\x12\x15\n" + "\x06is_buy\x18\x15 \x01(\rR\x05isBuy\x12'\n" + "\x0fperiod_validity\x18\x16 \x01(\x05R\x0eperiodValidity\x12!\n" + "\fpublish_time\x18\x17 \x01(\tR\vpublishTime\x12\x12\n" + @@ -1946,7 +2205,7 @@ const file_product_product_proto_rawDesc = "" + "\x06reason\x18\" \x01(\tR\x06reason\x12\x1d\n" + "\n" + "admin_name\x18# \x01(\tR\tadminName\x12\x12\n" + - "\x04edit\x18$ \x01(\rR\x04edit2\xa6\t\n" + + "\x04edit\x18$ \x01(\rR\x04edit2\xa8\v\n" + "\aProduct\x12M\n" + "\x06Create\x12\x12.product.CreateReq\x1a\x11.product.Response\"\x1c\x82\xd3\xe4\x93\x02\x16:\x01*\"\x11/admin/v3/product\x12N\n" + "\x04Info\x12\x10.product.InfoReq\x1a\x11.product.Response\"!\x82\xd3\xe4\x93\x02\x1b:\x01*\x12\x16/admin/v3/product/info\x12K\n" + @@ -1960,7 +2219,12 @@ const file_product_product_proto_rawDesc = "" + "\tEditApply\x12\x15.product.EditApplyReq\x1a\x11.product.Response\"'\x82\xd3\xe4\x93\x02!:\x01*\"\x1c/admin/v3/product/edit/apply\x12V\n" + "\bEditBase\x12\x14.product.EditBaseReq\x1a\x11.product.Response\"!\x82\xd3\xe4\x93\x02\x1b:\x01*\x1a\x16/admin/v3/product/base\x12k\n" + "\x0fEditSusceptible\x12\x1b.product.EditSusceptibleReq\x1a\x11.product.Response\"(\x82\xd3\xe4\x93\x02\":\x01*\x1a\x1d/admin/v3/product/susceptible\x12k\n" + - "\rEditApplyPass\x12\x19.product.EditApplyPassReq\x1a\x11.product.Response\",\x82\xd3\xe4\x93\x02&:\x01*\x1a!/admin/v3/product/edit/apply/passB\x1bZ\x19lone-services/rpc/productb\x06proto3" + "\rEditApplyPass\x12\x19.product.EditApplyPassReq\x1a\x11.product.Response\",\x82\xd3\xe4\x93\x02&:\x01*\x1a!/admin/v3/product/edit/apply/pass\x124\n" + + "\x06Number\x12\x12.product.NumberReq\x1a\x16.google.protobuf.Empty\x12/\n" + + "\bInfoById\x12\x14.product.InfoByIdReq\x1a\r.product.Item\x12=\n" + + "\n" + + "ItemsByIds\x12\x16.product.ItemsByIdsReq\x1a\x17.product.ItemsByIdsData\x12Z\n" + + "\tNumberAdd\x12\x15.product.NumberAddReq\x1a\x11.product.Response\"#\x82\xd3\xe4\x93\x02\x1d:\x01*\x1a\x18/admin/v3/product/numberB\x1bZ\x19lone-services/rpc/productb\x06proto3" var ( file_product_product_proto_rawDescOnce sync.Once @@ -1974,64 +2238,79 @@ func file_product_product_proto_rawDescGZIP() []byte { return file_product_product_proto_rawDescData } -var file_product_product_proto_msgTypes = make([]protoimpl.MessageInfo, 19) +var file_product_product_proto_msgTypes = make([]protoimpl.MessageInfo, 24) var file_product_product_proto_goTypes = []any{ (*Response)(nil), // 0: product.Response - (*CreateReq)(nil), // 1: product.CreateReq - (*InfoReq)(nil), // 2: product.InfoReq - (*ItemsReq)(nil), // 3: product.ItemsReq - (*NamesReq)(nil), // 4: product.NamesReq - (*StatusReq)(nil), // 5: product.StatusReq - (*SortReq)(nil), // 6: product.SortReq - (*VerifyReq)(nil), // 7: product.VerifyReq - (*VerifyStatusReq)(nil), // 8: product.VerifyStatusReq - (*EditApplyReq)(nil), // 9: product.EditApplyReq - (*EditApplyPassReq)(nil), // 10: product.EditApplyPassReq - (*EditBaseReq)(nil), // 11: product.EditBaseReq - (*EditSusceptibleReq)(nil), // 12: product.EditSusceptibleReq - (*ItemsData)(nil), // 13: product.ItemsData - (*VerifyItemsData)(nil), // 14: product.VerifyItemsData - (*VerifyParams)(nil), // 15: product.VerifyParams - (*VerifyItem)(nil), // 16: product.VerifyItem - (*NameItem)(nil), // 17: product.NameItem - (*Item)(nil), // 18: product.Item + (*InfoByIdReq)(nil), // 1: product.InfoByIdReq + (*ItemsByIdsReq)(nil), // 2: product.ItemsByIdsReq + (*ItemsByIdsData)(nil), // 3: product.ItemsByIdsData + (*CreateReq)(nil), // 4: product.CreateReq + (*InfoReq)(nil), // 5: product.InfoReq + (*ItemsReq)(nil), // 6: product.ItemsReq + (*NamesReq)(nil), // 7: product.NamesReq + (*StatusReq)(nil), // 8: product.StatusReq + (*SortReq)(nil), // 9: product.SortReq + (*VerifyReq)(nil), // 10: product.VerifyReq + (*VerifyStatusReq)(nil), // 11: product.VerifyStatusReq + (*EditApplyReq)(nil), // 12: product.EditApplyReq + (*EditApplyPassReq)(nil), // 13: product.EditApplyPassReq + (*EditBaseReq)(nil), // 14: product.EditBaseReq + (*EditSusceptibleReq)(nil), // 15: product.EditSusceptibleReq + (*NumberReq)(nil), // 16: product.NumberReq + (*NumberAddReq)(nil), // 17: product.NumberAddReq + (*ItemsData)(nil), // 18: product.ItemsData + (*VerifyItemsData)(nil), // 19: product.VerifyItemsData + (*VerifyParams)(nil), // 20: product.VerifyParams + (*VerifyItem)(nil), // 21: product.VerifyItem + (*NameItem)(nil), // 22: product.NameItem + (*Item)(nil), // 23: product.Item + (*emptypb.Empty)(nil), // 24: google.protobuf.Empty } var file_product_product_proto_depIdxs = []int32{ - 18, // 0: product.ItemsData.items:type_name -> product.Item - 16, // 1: product.VerifyItemsData.items:type_name -> product.VerifyItem - 15, // 2: product.VerifyItem.new:type_name -> product.VerifyParams - 15, // 3: product.VerifyItem.old:type_name -> product.VerifyParams - 1, // 4: product.Product.Create:input_type -> product.CreateReq - 2, // 5: product.Product.Info:input_type -> product.InfoReq - 3, // 6: product.Product.Items:input_type -> product.ItemsReq - 4, // 7: product.Product.Names:input_type -> product.NamesReq - 5, // 8: product.Product.Status:input_type -> product.StatusReq - 6, // 9: product.Product.Sort:input_type -> product.SortReq - 7, // 10: product.Product.Verify:input_type -> product.VerifyReq - 8, // 11: product.Product.VerifyFirst:input_type -> product.VerifyStatusReq - 8, // 12: product.Product.VerifySecond:input_type -> product.VerifyStatusReq - 9, // 13: product.Product.EditApply:input_type -> product.EditApplyReq - 11, // 14: product.Product.EditBase:input_type -> product.EditBaseReq - 12, // 15: product.Product.EditSusceptible:input_type -> product.EditSusceptibleReq - 10, // 16: product.Product.EditApplyPass:input_type -> product.EditApplyPassReq - 0, // 17: product.Product.Create:output_type -> product.Response - 0, // 18: product.Product.Info:output_type -> product.Response - 0, // 19: product.Product.Items:output_type -> product.Response - 0, // 20: product.Product.Names:output_type -> product.Response - 0, // 21: product.Product.Status:output_type -> product.Response - 0, // 22: product.Product.Sort:output_type -> product.Response - 0, // 23: product.Product.Verify:output_type -> product.Response - 0, // 24: product.Product.VerifyFirst:output_type -> product.Response - 0, // 25: product.Product.VerifySecond:output_type -> product.Response - 0, // 26: product.Product.EditApply:output_type -> product.Response - 0, // 27: product.Product.EditBase:output_type -> product.Response - 0, // 28: product.Product.EditSusceptible:output_type -> product.Response - 0, // 29: product.Product.EditApplyPass:output_type -> product.Response - 17, // [17:30] is the sub-list for method output_type - 4, // [4:17] is the sub-list for method input_type - 4, // [4:4] is the sub-list for extension type_name - 4, // [4:4] is the sub-list for extension extendee - 0, // [0:4] is the sub-list for field type_name + 23, // 0: product.ItemsByIdsData.items:type_name -> product.Item + 23, // 1: product.ItemsData.items:type_name -> product.Item + 21, // 2: product.VerifyItemsData.items:type_name -> product.VerifyItem + 20, // 3: product.VerifyItem.new:type_name -> product.VerifyParams + 20, // 4: product.VerifyItem.old:type_name -> product.VerifyParams + 4, // 5: product.Product.Create:input_type -> product.CreateReq + 5, // 6: product.Product.Info:input_type -> product.InfoReq + 6, // 7: product.Product.Items:input_type -> product.ItemsReq + 7, // 8: product.Product.Names:input_type -> product.NamesReq + 8, // 9: product.Product.Status:input_type -> product.StatusReq + 9, // 10: product.Product.Sort:input_type -> product.SortReq + 10, // 11: product.Product.Verify:input_type -> product.VerifyReq + 11, // 12: product.Product.VerifyFirst:input_type -> product.VerifyStatusReq + 11, // 13: product.Product.VerifySecond:input_type -> product.VerifyStatusReq + 12, // 14: product.Product.EditApply:input_type -> product.EditApplyReq + 14, // 15: product.Product.EditBase:input_type -> product.EditBaseReq + 15, // 16: product.Product.EditSusceptible:input_type -> product.EditSusceptibleReq + 13, // 17: product.Product.EditApplyPass:input_type -> product.EditApplyPassReq + 16, // 18: product.Product.Number:input_type -> product.NumberReq + 1, // 19: product.Product.InfoById:input_type -> product.InfoByIdReq + 2, // 20: product.Product.ItemsByIds:input_type -> product.ItemsByIdsReq + 17, // 21: product.Product.NumberAdd:input_type -> product.NumberAddReq + 0, // 22: product.Product.Create:output_type -> product.Response + 0, // 23: product.Product.Info:output_type -> product.Response + 0, // 24: product.Product.Items:output_type -> product.Response + 0, // 25: product.Product.Names:output_type -> product.Response + 0, // 26: product.Product.Status:output_type -> product.Response + 0, // 27: product.Product.Sort:output_type -> product.Response + 0, // 28: product.Product.Verify:output_type -> product.Response + 0, // 29: product.Product.VerifyFirst:output_type -> product.Response + 0, // 30: product.Product.VerifySecond:output_type -> product.Response + 0, // 31: product.Product.EditApply:output_type -> product.Response + 0, // 32: product.Product.EditBase:output_type -> product.Response + 0, // 33: product.Product.EditSusceptible:output_type -> product.Response + 0, // 34: product.Product.EditApplyPass:output_type -> product.Response + 24, // 35: product.Product.Number:output_type -> google.protobuf.Empty + 23, // 36: product.Product.InfoById:output_type -> product.Item + 3, // 37: product.Product.ItemsByIds:output_type -> product.ItemsByIdsData + 0, // 38: product.Product.NumberAdd:output_type -> product.Response + 22, // [22:39] is the sub-list for method output_type + 5, // [5:22] is the sub-list for method input_type + 5, // [5:5] is the sub-list for extension type_name + 5, // [5:5] is the sub-list for extension extendee + 0, // [0:5] is the sub-list for field type_name } func init() { file_product_product_proto_init() } @@ -2045,7 +2324,7 @@ func file_product_product_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: unsafe.Slice(unsafe.StringData(file_product_product_proto_rawDesc), len(file_product_product_proto_rawDesc)), NumEnums: 0, - NumMessages: 19, + NumMessages: 24, NumExtensions: 0, NumServices: 1, }, diff --git a/rpc/product/pb/product_grpc.pb.go b/rpc/product/pb/product_grpc.pb.go index 0599a4c..9aec8d9 100644 --- a/rpc/product/pb/product_grpc.pb.go +++ b/rpc/product/pb/product_grpc.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go-grpc. DO NOT EDIT. // versions: // - protoc-gen-go-grpc v1.6.2 -// - protoc v4.25.8 +// - protoc v3.19.4 // source: product/product.proto package product @@ -11,6 +11,7 @@ import ( grpc "google.golang.org/grpc" codes "google.golang.org/grpc/codes" status "google.golang.org/grpc/status" + emptypb "google.golang.org/protobuf/types/known/emptypb" ) // This is a compile-time assertion to ensure that this generated file @@ -32,6 +33,10 @@ const ( Product_EditBase_FullMethodName = "/product.Product/EditBase" Product_EditSusceptible_FullMethodName = "/product.Product/EditSusceptible" Product_EditApplyPass_FullMethodName = "/product.Product/EditApplyPass" + Product_Number_FullMethodName = "/product.Product/Number" + Product_InfoById_FullMethodName = "/product.Product/InfoById" + Product_ItemsByIds_FullMethodName = "/product.Product/ItemsByIds" + Product_NumberAdd_FullMethodName = "/product.Product/NumberAdd" ) // ProductClient is the client API for Product service. @@ -58,6 +63,13 @@ type ProductClient interface { EditSusceptible(ctx context.Context, in *EditSusceptibleReq, opts ...grpc.CallOption) (*Response, error) // TODO: 临时接口,企微编辑申请审批对接后删除 EditApplyPass(ctx context.Context, in *EditApplyPassReq, opts ...grpc.CallOption) (*Response, error) + // 增减库存 + // type: 1 增加, 2 减少 + Number(ctx context.Context, in *NumberReq, opts ...grpc.CallOption) (*emptypb.Empty, error) + InfoById(ctx context.Context, in *InfoByIdReq, opts ...grpc.CallOption) (*Item, error) + ItemsByIds(ctx context.Context, in *ItemsByIdsReq, opts ...grpc.CallOption) (*ItemsByIdsData, error) + // 增加库存 + NumberAdd(ctx context.Context, in *NumberAddReq, opts ...grpc.CallOption) (*Response, error) } type productClient struct { @@ -198,6 +210,46 @@ func (c *productClient) EditApplyPass(ctx context.Context, in *EditApplyPassReq, return out, nil } +func (c *productClient) Number(ctx context.Context, in *NumberReq, opts ...grpc.CallOption) (*emptypb.Empty, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(emptypb.Empty) + err := c.cc.Invoke(ctx, Product_Number_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *productClient) InfoById(ctx context.Context, in *InfoByIdReq, opts ...grpc.CallOption) (*Item, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(Item) + err := c.cc.Invoke(ctx, Product_InfoById_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *productClient) ItemsByIds(ctx context.Context, in *ItemsByIdsReq, opts ...grpc.CallOption) (*ItemsByIdsData, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(ItemsByIdsData) + err := c.cc.Invoke(ctx, Product_ItemsByIds_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *productClient) NumberAdd(ctx context.Context, in *NumberAddReq, opts ...grpc.CallOption) (*Response, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(Response) + err := c.cc.Invoke(ctx, Product_NumberAdd_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + // ProductServer is the server API for Product service. // All implementations must embed UnimplementedProductServer // for forward compatibility. @@ -222,6 +274,13 @@ type ProductServer interface { EditSusceptible(context.Context, *EditSusceptibleReq) (*Response, error) // TODO: 临时接口,企微编辑申请审批对接后删除 EditApplyPass(context.Context, *EditApplyPassReq) (*Response, error) + // 增减库存 + // type: 1 增加, 2 减少 + Number(context.Context, *NumberReq) (*emptypb.Empty, error) + InfoById(context.Context, *InfoByIdReq) (*Item, error) + ItemsByIds(context.Context, *ItemsByIdsReq) (*ItemsByIdsData, error) + // 增加库存 + NumberAdd(context.Context, *NumberAddReq) (*Response, error) mustEmbedUnimplementedProductServer() } @@ -271,6 +330,18 @@ func (UnimplementedProductServer) EditSusceptible(context.Context, *EditSuscepti func (UnimplementedProductServer) EditApplyPass(context.Context, *EditApplyPassReq) (*Response, error) { return nil, status.Error(codes.Unimplemented, "method EditApplyPass not implemented") } +func (UnimplementedProductServer) Number(context.Context, *NumberReq) (*emptypb.Empty, error) { + return nil, status.Error(codes.Unimplemented, "method Number not implemented") +} +func (UnimplementedProductServer) InfoById(context.Context, *InfoByIdReq) (*Item, error) { + return nil, status.Error(codes.Unimplemented, "method InfoById not implemented") +} +func (UnimplementedProductServer) ItemsByIds(context.Context, *ItemsByIdsReq) (*ItemsByIdsData, error) { + return nil, status.Error(codes.Unimplemented, "method ItemsByIds not implemented") +} +func (UnimplementedProductServer) NumberAdd(context.Context, *NumberAddReq) (*Response, error) { + return nil, status.Error(codes.Unimplemented, "method NumberAdd not implemented") +} func (UnimplementedProductServer) mustEmbedUnimplementedProductServer() {} func (UnimplementedProductServer) testEmbeddedByValue() {} @@ -526,6 +597,78 @@ func _Product_EditApplyPass_Handler(srv interface{}, ctx context.Context, dec fu return interceptor(ctx, in, info, handler) } +func _Product_Number_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(NumberReq) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ProductServer).Number(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Product_Number_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ProductServer).Number(ctx, req.(*NumberReq)) + } + return interceptor(ctx, in, info, handler) +} + +func _Product_InfoById_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(InfoByIdReq) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ProductServer).InfoById(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Product_InfoById_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ProductServer).InfoById(ctx, req.(*InfoByIdReq)) + } + return interceptor(ctx, in, info, handler) +} + +func _Product_ItemsByIds_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ItemsByIdsReq) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ProductServer).ItemsByIds(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Product_ItemsByIds_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ProductServer).ItemsByIds(ctx, req.(*ItemsByIdsReq)) + } + return interceptor(ctx, in, info, handler) +} + +func _Product_NumberAdd_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(NumberAddReq) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ProductServer).NumberAdd(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Product_NumberAdd_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ProductServer).NumberAdd(ctx, req.(*NumberAddReq)) + } + return interceptor(ctx, in, info, handler) +} + // Product_ServiceDesc is the grpc.ServiceDesc for Product service. // It's only intended for direct use with grpc.RegisterService, // and not to be introspected or modified (even as a copy) @@ -585,6 +728,22 @@ var Product_ServiceDesc = grpc.ServiceDesc{ MethodName: "EditApplyPass", Handler: _Product_EditApplyPass_Handler, }, + { + MethodName: "Number", + Handler: _Product_Number_Handler, + }, + { + MethodName: "InfoById", + Handler: _Product_InfoById_Handler, + }, + { + MethodName: "ItemsByIds", + Handler: _Product_ItemsByIds_Handler, + }, + { + MethodName: "NumberAdd", + Handler: _Product_NumberAdd_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "product/product.proto", diff --git a/rpc/product/product.pb b/rpc/product/product.pb index 04602bc..38d091a 100644 Binary files a/rpc/product/product.pb and b/rpc/product/product.pb differ diff --git a/rpc/product/product.proto b/rpc/product/product.proto index 82766d9..ff186c8 100644 --- a/rpc/product/product.proto +++ b/rpc/product/product.proto @@ -4,6 +4,7 @@ package product; option go_package="lone-services/rpc/product"; import "google/api/annotations.proto"; +import "google/protobuf/empty.proto"; service Product { rpc Create(CreateReq) returns (Response) { @@ -92,6 +93,21 @@ service Product { body: "*" }; } + + // 增减库存 + // type: 1 增加, 2 减少 + rpc Number(NumberReq) returns (google.protobuf.Empty); + rpc InfoById(InfoByIdReq) returns (Item); + rpc ItemsByIds(ItemsByIdsReq) returns (ItemsByIdsData); + + + // 增加库存 + rpc NumberAdd(NumberAddReq) returns (Response) { + option (google.api.http) = { + put: "/admin/v3/product/number" + body: "*" + }; + } } message Response { @@ -100,6 +116,18 @@ message Response { string data = 3; } +message InfoByIdReq { + int64 id = 1; +} + +message ItemsByIdsReq { + repeated int64 ids = 1; +} + +message ItemsByIdsData { + repeated Item items = 1; +} + message CreateReq { string name = 1; string subhead = 2; @@ -112,7 +140,7 @@ message CreateReq { double share_price = 9; double agent_price = 10; string sale_reward = 11; - string images = 12; + repeated string images = 12; double weight = 13; string cubage = 14; string waybill = 15; @@ -184,7 +212,7 @@ message EditBaseReq { string waybill = 5; double weight = 6; string cubage = 7; - string images = 8; + repeated string images = 8; int32 period_validity = 9; string publish_time = 10; string label = 11; @@ -207,6 +235,18 @@ message EditSusceptibleReq { uint32 type = 11; } +// type: 1 增加, 2 减少;number 为变更数量 +message NumberReq { + int64 id = 1; + uint32 type = 2; + uint32 number = 3; +} + +message NumberAddReq { + int64 id = 1; + uint32 number = 2; +} + message ItemsData { int64 count = 1; repeated Item items = 2; @@ -264,7 +304,7 @@ message Item { string index_image = 17; string cubage = 18; string label = 19; - string images = 20; + repeated string images = 20; uint32 is_buy = 21; int32 period_validity = 22; string publish_time = 23; diff --git a/services/chore/Dockerfile b/services/chore/Dockerfile new file mode 100644 index 0000000..8614291 --- /dev/null +++ b/services/chore/Dockerfile @@ -0,0 +1,39 @@ +FROM golang:1.26.5-alpine AS builder + +WORKDIR /src + +ENV GOPROXY=https://goproxy.cn,direct \ + CGO_ENABLED=0 \ + GOOS=linux \ + GOARCH=amd64 + +COPY pkg ./pkg +COPY go.mod go.sum ./ + +RUN --mount=type=cache,target=/go/pkg/mod \ + go mod download + +COPY rpc/chore/ ./rpc/chore/ +COPY services/chore/ ./services/chore/ + +WORKDIR /src/services/chore + +RUN --mount=type=cache,target=/go/pkg/mod \ + --mount=type=cache,target=/root/.cache/go-build \ + go build -ldflags="-s -w" -o /out/main ./ + +FROM alpine:3.22 + +WORKDIR /app + +ENV TZ=Asia/Shanghai + +RUN apk add --no-cache tzdata \ + && cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \ + && echo "Asia/Shanghai" > /etc/timezone + +COPY --from=builder /out/main . + +EXPOSE 10500 + +CMD ["./main", "-f", "etc/chore.yaml"] diff --git a/services/chore/chore.go b/services/chore/chore.go index 60e4d7e..7382b33 100644 --- a/services/chore/chore.go +++ b/services/chore/chore.go @@ -117,7 +117,7 @@ func main() { os.Exit(1) } - // debug := utils.GetConfigBool("mysql.debug") + // debug := utils.GetConfigBool("mysql.debug")test // modelbase.Init(db, modelbase.Config{Prefix: utils.GetConfigString("mysql.prefix"), Debug: debug}) rpcConf := zrpc.RpcServerConf{ diff --git a/services/chore/choreclient/chore.go b/services/chore/choreclient/chore.go index 918c5b1..2c5ae83 100644 --- a/services/chore/choreclient/chore.go +++ b/services/chore/choreclient/chore.go @@ -16,9 +16,11 @@ import ( type ( PolicyReq = chore.PolicyReq Response = chore.Response + TestReq = chore.TestReq Chore interface { Policy(ctx context.Context, in *PolicyReq, opts ...grpc.CallOption) (*Response, error) + Test(ctx context.Context, in *TestReq, opts ...grpc.CallOption) (*Response, error) } defaultChore struct { @@ -36,3 +38,8 @@ func (m *defaultChore) Policy(ctx context.Context, in *PolicyReq, opts ...grpc.C client := chore.NewChoreClient(m.cli.Conn()) return client.Policy(ctx, in, opts...) } + +func (m *defaultChore) Test(ctx context.Context, in *TestReq, opts ...grpc.CallOption) (*Response, error) { + client := chore.NewChoreClient(m.cli.Conn()) + return client.Test(ctx, in, opts...) +} diff --git a/services/chore/internal/logic/policyLogic.go b/services/chore/internal/logic/policyLogic.go index 997e944..b880765 100644 --- a/services/chore/internal/logic/policyLogic.go +++ b/services/chore/internal/logic/policyLogic.go @@ -3,6 +3,7 @@ package logic import ( "context" "strings" + "time" "lone-services/pkg/utils" chore "lone-services/rpc/chore/pb" @@ -21,12 +22,12 @@ type PolicyLogic struct { logx.Logger } -// StsToken 对齐阿里云 STS 返回字段,并附带前端上传所需信息 +// StsToken 对齐阿里云 STS Credentials,并附带前端上传所需信息 type StsToken struct { - AccessKeyId string `json:"AccessKeyId"` - AccessKeySecret string `json:"AccessKeySecret"` - SecurityToken string `json:"SecurityToken"` - Expiration string `json:"Expiration"` + AccessKeyId string `json:"access_key_id"` + AccessKeySecret string `json:"access_key_secret"` + SecurityToken string `json:"security_token"` + Expiration string `json:"expiration"` Bucket string `json:"bucket"` Region string `json:"region"` Endpoint string `json:"endpoint"` @@ -34,6 +35,17 @@ type StsToken struct { Dir string `json:"dir"` } +func formatExpiration(raw string) string { + if raw == "" { + return raw + } + t, err := time.Parse(time.RFC3339, raw) + if err != nil { + return raw + } + return t.Local().Format(utils.YMDHIS) +} + func NewPolicyLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PolicyLogic { return &PolicyLogic{ ctx: ctx, @@ -42,6 +54,24 @@ func NewPolicyLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PolicyLogi } } +func CreateClient(accessKeyId, accessKeySecret, endpoint *string) (*sts20150401.Client, error) { + config := &openapi.Config{ + AccessKeyId: accessKeyId, + AccessKeySecret: accessKeySecret, + } + config.Endpoint = endpoint + return sts20150401.NewClient(config) +} + +func AssumeRole(client *sts20150401.Client, roleArn, roleSessionName string, durationSeconds int64) (*sts20150401.AssumeRoleResponse, error) { + assumeRoleRequest := &sts20150401.AssumeRoleRequest{ + DurationSeconds: tea.Int64(durationSeconds), + RoleArn: tea.String(roleArn), + RoleSessionName: tea.String(roleSessionName), + } + return client.AssumeRoleWithOptions(assumeRoleRequest, &util.RuntimeOptions{}) +} + func (l *PolicyLogic) Policy(in *chore.PolicyReq) (*chore.Response, error) { accessKeyId := utils.GetConfigString("oss.accessKeyId") accessKeySecret := utils.GetConfigString("oss.accessKeySecret") @@ -71,7 +101,7 @@ func (l *PolicyLogic) Policy(in *chore.PolicyReq) (*chore.Response, error) { region = "oss-cn-hangzhou" } if endpoint == utils.StringEmpty { - endpoint = "https://lone-images.oss-accelerate.aliyuncs.com" + endpoint = "https://oss-accelerate.aliyuncs.com" } if host == utils.StringEmpty { host = "https://images.ailuowan.com" @@ -88,18 +118,13 @@ func (l *PolicyLogic) Policy(in *chore.PolicyReq) (*chore.Response, error) { expire = 3600 } - client, err := createStsClient(accessKeyId, accessKeySecret, stsEndpoint) + client, err := CreateClient(tea.String(accessKeyId), tea.String(accessKeySecret), tea.String(stsEndpoint)) if err != nil { l.Errorf("create STS client: %v", err) return failResponse(utils.Fail), nil } - assumeRoleRequest := &sts20150401.AssumeRoleRequest{ - DurationSeconds: tea.Int64(expire), - RoleArn: tea.String(roleArn), - RoleSessionName: tea.String(roleSessionName), - } - resp, err := client.AssumeRoleWithOptions(assumeRoleRequest, &util.RuntimeOptions{}) + resp, err := AssumeRole(client, roleArn, roleSessionName, expire) if err != nil { l.Errorf("AssumeRole: %v", err) return failResponse(utils.Fail), nil @@ -114,7 +139,7 @@ func (l *PolicyLogic) Policy(in *chore.PolicyReq) (*chore.Response, error) { AccessKeyId: tea.StringValue(cred.AccessKeyId), AccessKeySecret: tea.StringValue(cred.AccessKeySecret), SecurityToken: tea.StringValue(cred.SecurityToken), - Expiration: tea.StringValue(cred.Expiration), + Expiration: formatExpiration(tea.StringValue(cred.Expiration)), Bucket: bucket, Region: region, Endpoint: endpoint, @@ -123,12 +148,3 @@ func (l *PolicyLogic) Policy(in *chore.PolicyReq) (*chore.Response, error) { } return okResponse(token), nil } - -func createStsClient(accessKeyId, accessKeySecret, endpoint string) (*sts20150401.Client, error) { - config := &openapi.Config{ - AccessKeyId: tea.String(accessKeyId), - AccessKeySecret: tea.String(accessKeySecret), - Endpoint: tea.String(endpoint), - } - return sts20150401.NewClient(config) -} diff --git a/services/chore/internal/logic/testLogic.go b/services/chore/internal/logic/testLogic.go new file mode 100644 index 0000000..b83397b --- /dev/null +++ b/services/chore/internal/logic/testLogic.go @@ -0,0 +1,73 @@ +package logic + +import ( + "context" + "fmt" + + "lone-services/pkg/rpcclient" + "lone-services/pkg/utils" + chore "lone-services/rpc/chore/pb" + product "lone-services/rpc/product/pb" + "lone-services/services/chore/internal/svc" + + "github.com/zeromicro/go-zero/core/logx" +) + +// product 库存变更:1 增加 2 减少 +const productNumberTypeIncr uint32 = 1 +const productNumberTypeDecr uint32 = 2 + +type TestLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + logx.Logger +} + +func NewTestLogic(ctx context.Context, svcCtx *svc.ServiceContext) *TestLogic { + return &TestLogic{ + ctx: ctx, + svcCtx: svcCtx, + Logger: logx.WithContext(ctx), + } +} + +func (l *TestLogic) Test(in *chore.TestReq) (*chore.Response, error) { + cli, err := rpcclient.Get(l.svcCtx.ProductSvcName) + if err != nil { + l.Errorf("get product rpc: %v", err) + return failResponse(utils.ErrorInternalServer), nil + } + + // 产品库存更变 + // _, err = product.NewProductClient(cli.Conn()).Number(l.ctx, &product.NumberReq{ + // Id: in.GetId(), + // Type: productNumberTypeDecr, + // Number: in.GetNumber(), + // }) + + // 获取单个产品详情 + // res, err := product.NewProductClient(cli.Conn()).InfoById(l.ctx, &product.InfoByIdReq{ + // Id: int64(in.GetId()), + // }) + + // fmt.Println(res.GetName()) + + // 获取多个产品详情 + res, err := product.NewProductClient(cli.Conn()).ItemsByIds(l.ctx, &product.ItemsByIdsReq{ + Ids: in.GetIds(), + }) + for _, item := range res.GetItems() { + fmt.Println(item.GetName()) + } + + if err != nil { + l.Errorf("错误信息: %v", err) + return failResponse(utils.ErrorInternalServer), nil + } + + if res == nil { + l.Errorf("res为空") + return failResponse(utils.Fail), nil + } + return okResponse(res), nil +} diff --git a/services/chore/internal/server/choreServer.go b/services/chore/internal/server/choreServer.go index 97513c6..a115572 100644 --- a/services/chore/internal/server/choreServer.go +++ b/services/chore/internal/server/choreServer.go @@ -27,3 +27,8 @@ func (s *ChoreServer) Policy(ctx context.Context, in *chore.PolicyReq) (*chore.R l := logic.NewPolicyLogic(ctx, s.svcCtx) return l.Policy(in) } + +func (s *ChoreServer) Test(ctx context.Context, in *chore.TestReq) (*chore.Response, error) { + l := logic.NewTestLogic(ctx, s.svcCtx) + return l.Test(in) +} diff --git a/services/chore/internal/svc/servicecontext.go b/services/chore/internal/svc/servicecontext.go index 9268b21..ecfa91d 100644 --- a/services/chore/internal/svc/servicecontext.go +++ b/services/chore/internal/svc/servicecontext.go @@ -1,15 +1,25 @@ package svc import ( + "lone-services/pkg/utils" "lone-services/services/chore/internal/config" + + "github.com/zeromicro/go-zero/core/logx" ) type ServiceContext struct { - Config config.Config + Config config.Config + ProductSvcName string } func NewServiceContext(c config.Config) *ServiceContext { + productSvc := utils.GetConfigString("services.product") + if productSvc == utils.StringEmpty { + logx.Error("config services.product empty") + } + return &ServiceContext{ - Config: c, + Config: c, + ProductSvcName: productSvc, } } diff --git a/services/chore/run.toml b/services/chore/run.toml index c9bd19a..e56c906 100644 --- a/services/chore/run.toml +++ b/services/chore/run.toml @@ -2,7 +2,7 @@ login_out_time=43200 #api接口超时时间分 login_refresh_out_time=83200 name = "chore-service" - listenOn = "0.0.0.0:10500" + listenOn = "0.0.0.0:10300" mode = "dev" [log] path = "logs" @@ -16,16 +16,16 @@ compress = false [oss] - accessKeyId = "LTAI5t7U8KvxSiPE5auwQUuu" - accessKeySecret = "xjfgbQQRpL4TcIspNuClg6bYADa3pk" - roleArn = "acs:ram::你的账号ID:role/你的角色名" - roleSessionName = "chore-oss-upload" - region = "oss-cn-hangzhou" - bucketName = "lone-images" - endpoint = "https://lone-images.oss-accelerate.aliyuncs.com" - host = "https://images.ailuowan.com" - dir = "upload/" - expireSeconds = 3600 + accessKeyId = "LTAI5t7U8KvxSiPE5auwQUuu" + accessKeySecret = "xjfgbQQRpL4TcIspNuClg6bYADa3pk" + roleArn = "acs:ram::1663896742753915:role/oss-upload" + roleSessionName = "oss-upload" + region = "oss-cn-hangzhou" + bucketName = "lone-images" + endpoint = "https://lone-images.oss-accelerate.aliyuncs.com" + host = "https://images.ailuowan.com" + dir = "upload/" + expireSeconds = 3600 [redis] host = '39.106.171.204' @@ -35,3 +35,6 @@ [encrypt] data_key = "u2t9T3luZtoRfhBstkFN6TiIMW38BA8a" + +[services] + product = "product-service" \ No newline at end of file diff --git a/services/order/internal/server/orderServer.go b/services/order/internal/server/orderServer.go deleted file mode 100644 index 04ae1a8..0000000 --- a/services/order/internal/server/orderServer.go +++ /dev/null @@ -1,99 +0,0 @@ -// Code generated by goctl. DO NOT EDIT. -// goctl 1.10.2 -// Source: order.proto - -package server - -import ( - "context" - - "lone-services/rpc/order/pb" - "lone-services/services/order/internal/logic" - "lone-services/services/order/internal/svc" -) - -type OrderServer struct { - svcCtx *svc.ServiceContext - order.UnimplementedOrderServer -} - -func NewOrderServer(svcCtx *svc.ServiceContext) *OrderServer { - return &OrderServer{ - svcCtx: svcCtx, - } -} - -func (s *OrderServer) Items(ctx context.Context, in *order.OrderItemsRequest) (*order.Response, error) { - l := logic.NewItemsLogic(ctx, s.svcCtx) - return l.Items(in) -} - -func (s *OrderServer) WebCreate(ctx context.Context, in *order.CreateOrderRequest) (*order.Response, error) { - l := logic.NewWebCreateLogic(ctx, s.svcCtx) - return l.WebCreate(in) -} - -func (s *OrderServer) WebCreateOne(ctx context.Context, in *order.CreateOrderOneRequest) (*order.Response, error) { - l := logic.NewWebCreateOneLogic(ctx, s.svcCtx) - return l.WebCreateOne(in) -} - -func (s *OrderServer) WebAddressCreate(ctx context.Context, in *order.EditAddressRequest) (*order.Response, error) { - l := logic.NewWebAddressCreateLogic(ctx, s.svcCtx) - return l.WebAddressCreate(in) -} - -func (s *OrderServer) WebAddressEdit(ctx context.Context, in *order.EditAddressRequest) (*order.Response, error) { - l := logic.NewWebAddressEditLogic(ctx, s.svcCtx) - return l.WebAddressEdit(in) -} - -func (s *OrderServer) WebAddressDel(ctx context.Context, in *order.IdAndTypeRequest) (*order.Response, error) { - l := logic.NewWebAddressDelLogic(ctx, s.svcCtx) - return l.WebAddressDel(in) -} - -func (s *OrderServer) WebAddressDef(ctx context.Context, in *order.IdAndTypeRequest) (*order.Response, error) { - l := logic.NewWebAddressDefLogic(ctx, s.svcCtx) - return l.WebAddressDef(in) -} - -func (s *OrderServer) WebAddressInfo(ctx context.Context, in *order.IdAndTypeRequest) (*order.Response, error) { - l := logic.NewWebAddressInfoLogic(ctx, s.svcCtx) - return l.WebAddressInfo(in) -} - -func (s *OrderServer) WebAddressItems(ctx context.Context, in *order.TypeRequest) (*order.Response, error) { - l := logic.NewWebAddressItemsLogic(ctx, s.svcCtx) - return l.WebAddressItems(in) -} - -func (s *OrderServer) WebCart(ctx context.Context, in *order.CartRequest) (*order.Response, error) { - l := logic.NewWebCartLogic(ctx, s.svcCtx) - return l.WebCart(in) -} - -func (s *OrderServer) WebCartEdit(ctx context.Context, in *order.EditCartRequest) (*order.Response, error) { - l := logic.NewWebCartEditLogic(ctx, s.svcCtx) - return l.WebCartEdit(in) -} - -func (s *OrderServer) AddressItem(ctx context.Context, in *order.AddressItemsRequest) (*order.Response, error) { - l := logic.NewAddressItemLogic(ctx, s.svcCtx) - return l.AddressItem(in) -} - -func (s *OrderServer) OrderAuditingItems(ctx context.Context, in *order.OrderAuditingItemsRequest) (*order.Response, error) { - l := logic.NewOrderAuditingItemsLogic(ctx, s.svcCtx) - return l.OrderAuditingItems(in) -} - -func (s *OrderServer) OrderAuditing(ctx context.Context, in *order.OrderAuditingRequest) (*order.Response, error) { - l := logic.NewOrderAuditingLogic(ctx, s.svcCtx) - return l.OrderAuditing(in) -} - -func (s *OrderServer) OrderCreate(ctx context.Context, in *order.AdminCreateOrderRequest) (*order.Response, error) { - l := logic.NewOrderCreateLogic(ctx, s.svcCtx) - return l.OrderCreate(in) -} diff --git a/services/product/internal/dao/product.go b/services/product/internal/dao/product.go index ac63779..176f797 100644 --- a/services/product/internal/dao/product.go +++ b/services/product/internal/dao/product.go @@ -11,6 +11,12 @@ const ( ProductTryName = "多次试用" ) +// 库存变更类型(服务间 Number 接口) +const ( + NumberTypeAdd uint32 = 1 // 增加 + NumberTypeSub uint32 = 2 // 减少 +) + // 销售模式 const ( ProductSalesModelOffline = 1 // 线下 @@ -43,7 +49,7 @@ type Product struct { Waybill string `gorm:"column:waybill;type:varchar(255)"` AgentPrice float32 `gorm:"column:agent_price;type:decimal(10,2)"` SaleReward string `gorm:"column:sale_reward;type:varchar(255)"` - Images string `gorm:"column:images;type:varchar(512);not null"` + Images string `gorm:"column:images;type:json;not null"` Weight float32 `gorm:"column:weight;type:double"` Cubage string `gorm:"column:cubage;type:varchar(255)"` IsIndex uint8 `gorm:"column:is_index;type:tinyint(4);default:2"` @@ -69,7 +75,7 @@ type Product struct { AdminId int `gorm:"column:admin_id;type:int(11);not null"` } -type ProductCreate struct { +type Create struct { Id int `gorm:"column:id;primaryKey;autoIncrement"` Name string `gorm:"column:name"` Subhead string `gorm:"column:subhead"` @@ -102,14 +108,19 @@ type ProductCreate struct { AdminId int `gorm:"column:admin_id"` } -type ProductCheckExist struct { +type CheckExist struct { Id int `gorm:"column:id"` Name string `gorm:"column:name"` ModelCode string `gorm:"column:model_code"` Status uint8 `gorm:"column:status"` } -type ProductVerify struct { +type NumberInfo struct { + Id int `gorm:"column:id"` + Number uint `gorm:"column:number"` +} + +type VerifyContent struct { Id int `json:"id"` Name string `json:"name,omitempty"` ModelCode string `json:"model_code"` @@ -129,7 +140,7 @@ type ProductVerify struct { IndexImage string `json:"index_image,omitempty"` } -type ProductEditBase struct { +type EditBase struct { Id int `gorm:"column:id;primaryKey" json:"id"` Name string `gorm:"column:name" json:"name"` Subhead string `gorm:"column:subhead" json:"subhead"` @@ -149,8 +160,8 @@ type ProductEditBase struct { AdminId int `gorm:"column:admin_id" json:"admin_id"` } -// ProductEditSusceptible 敏感字段(查询旧值 / 写入 verify 快照) -type ProductEditSusceptible struct { +// EditSusceptible 敏感字段(查询旧值 / 写入 verify 快照) +type EditSusceptible struct { Id int `gorm:"column:id" json:"id"` ModelCode string `gorm:"column:model_code" json:"model_code"` Price float32 `gorm:"column:price" json:"price"` @@ -166,13 +177,13 @@ type ProductEditSusceptible struct { AdminId int `gorm:"column:admin_id" json:"admin_id"` } -// ProductVerifyFirstEditStatus 敏感编辑提交后置为一审中(Edit 走 json→map,必须带 json tag) -type ProductVerifyFirstEditStatus struct { +// VerifyFirstEditStatus 敏感编辑提交后置为一审中(Edit 走 json→map,必须带 json tag) +type VerifyFirstEditStatus struct { VerifyStatus uint8 `gorm:"column:verify_status" json:"verify_status"` } -// ProductInfo 列表/详情查询投影 -type ProductInfo struct { +// Info 列表/详情查询投影 +type Info struct { Id int `gorm:"column:id"` Name string `gorm:"column:name"` Subhead string `gorm:"column:subhead"` @@ -211,27 +222,27 @@ type ProductInfo struct { Edit uint8 `gorm:"-"` } -type ProductNames struct { +type Names struct { Id int `gorm:"column:id"` Name string `gorm:"column:name"` } -type ProductStatusUpdate struct { +type StatusUpdate struct { Status uint8 `gorm:"column:status" json:"status"` Reason string `gorm:"column:reason" json:"reason"` AdminName string `gorm:"column:admin_name" json:"admin_name"` AdminId int `gorm:"column:admin_id" json:"admin_id"` } -type ProductSort struct { +type Sort struct { Id int `gorm:"column:id" json:"id"` Sort uint16 `gorm:"column:sort" json:"sort"` AdminName string `gorm:"column:admin_name" json:"admin_name"` AdminId int `gorm:"column:admin_id" json:"admin_id"` } -// ProductVerifyListRow 审核列表产品侧字段 -type ProductVerifyListRow struct { +// VerifyListRow 审核列表产品侧字段 +type VerifyListRow struct { Id int `gorm:"column:id"` Name string `gorm:"column:name"` ModelCode string `gorm:"column:model_code"` @@ -247,24 +258,24 @@ type ProductVerifyListRow struct { BoxNumber float64 `gorm:"column:box_number"` } -// ProductVerifyFirstStatus 一审后回写产品审核状态(Edit 走 json→map,必须带 json tag) -type ProductVerifyFirstStatus struct { +// VerifyFirstStatus 一审后回写产品审核状态(Edit 走 json→map,必须带 json tag) +type VerifyFirstStatus struct { VerifyStatus uint8 `gorm:"column:verify_status" json:"verify_status"` VerifyId int `gorm:"column:verify_id" json:"verify_id"` VerifyName string `gorm:"column:verify_name" json:"verify_name"` Reason string `gorm:"column:reason" json:"reason"` } -// ProductVerifySecondStatus 二审驳回回写(Edit 走 json→map,必须带 json tag) -type ProductVerifySecondStatus struct { +// VerifySecondStatus 二审驳回回写(Edit 走 json→map,必须带 json tag) +type VerifySecondStatus struct { VerifyStatus uint8 `gorm:"column:verify_status" json:"verify_status"` VerifySecondId int `gorm:"column:verify_second_id" json:"verify_second_id"` VerifySecondName string `gorm:"column:verify_second_name" json:"verify_second_name"` Reason string `gorm:"column:reason" json:"reason"` } -// ProductVerifySecondOkStatus 二审通过:应用快照并回写审核人(Edit 走 json→map,必须带 json tag) -type ProductVerifySecondOkStatus struct { +// VerifySecondOkStatus 二审通过:应用快照并回写审核人(Edit 走 json→map,必须带 json tag) +type VerifySecondOkStatus struct { ModelCode string `gorm:"column:model_code" json:"model_code"` Price float32 `gorm:"column:price" json:"price"` StorePrice float32 `gorm:"column:store_price" json:"store_price"` diff --git a/services/product/internal/logic/convert.go b/services/product/internal/logic/convert.go index 3ad5455..177434d 100644 --- a/services/product/internal/logic/convert.go +++ b/services/product/internal/logic/convert.go @@ -1,12 +1,17 @@ package logic import ( + "strings" + "time" + + "lone-services/pkg/utils" product "lone-services/rpc/product/pb" "lone-services/services/product/internal/dao" - "time" + + jsoniter "github.com/json-iterator/go" ) -func toProductItem(row dao.ProductInfo) *product.Item { +func toProductItem(row dao.Info) *product.Item { publishTime := "" if !row.PublishTime.IsZero() { publishTime = row.PublishTime.Format(time.DateTime) @@ -31,7 +36,7 @@ func toProductItem(row dao.ProductInfo) *product.Item { IndexImage: row.IndexImage, Cubage: row.Cubage, Label: row.Label, - Images: row.Images, + Images: splitImages(row.Images), IsBuy: uint32(row.IsBuy), PeriodValidity: int32(row.PeriodValidity), PublishTime: publishTime, @@ -50,3 +55,38 @@ func toProductItem(row dao.ProductInfo) *product.Item { Edit: uint32(row.Edit), } } + +func joinImages(images []string) string { + list := cleanImages(images) + if len(list) == 0 { + return "[]" + } + buf, err := jsoniter.Marshal(list) + if err != nil { + return "[]" + } + return string(buf) +} + +func splitImages(images string) []string { + images = strings.TrimSpace(images) + if images == utils.StringEmpty { + return []string{} + } + var list []string + if err := jsoniter.Unmarshal([]byte(images), &list); err != nil { + return []string{} + } + return cleanImages(list) +} + +func cleanImages(images []string) []string { + out := make([]string, 0, len(images)) + for _, img := range images { + img = strings.TrimSpace(img) + if img != utils.StringEmpty { + out = append(out, img) + } + } + return out +} diff --git a/services/product/internal/logic/createlogic.go b/services/product/internal/logic/createlogic.go index 04a0aed..df25005 100644 --- a/services/product/internal/logic/createlogic.go +++ b/services/product/internal/logic/createlogic.go @@ -57,7 +57,7 @@ func (l *CreateLogic) Create(in *product.CreateReq) (*product.Response, error) { publishTime = t } - var check dao.ProductCheckExist + var check dao.CheckExist err := model.ProductModel{}.Init().GetOne(modelbase.Params{ Eq: map[string]string{"name": req.Name}, }, &check) @@ -73,7 +73,11 @@ func (l *CreateLogic) Create(in *product.CreateReq) (*product.Response, error) { if adminInfo.ID < utils.NumberOne { return failResponse(utils.ErrorNoLoginInfo), nil } - data := dao.ProductCreate{ + images := joinImages(req.Images) + if images == "[]" { + return outResponse(utils.ErrorParams, "图片不能为空"), nil + } + data := dao.Create{ Name: req.Name, Subhead: req.Subhead, Content: req.Content, @@ -87,7 +91,7 @@ func (l *CreateLogic) Create(in *product.CreateReq) (*product.Response, error) { Waybill: req.Waybill, SalesModel: uint8(req.SalesModel), Weight: float32(req.Weight), - Images: req.Images, + Images: images, PeriodValidity: int16(req.PeriodValidity), Type: uint8(req.Type), NormsNumber: uint8(req.NormsNumber), @@ -119,7 +123,7 @@ func (l *CreateLogic) Create(in *product.CreateReq) (*product.Response, error) { return err } - content := dao.ProductVerify{ + content := dao.VerifyContent{ Id: data.Id, ModelCode: data.ModelCode, Price: data.Price, diff --git a/services/product/internal/logic/editApplyPassLogic.go b/services/product/internal/logic/editApplyPassLogic.go new file mode 100644 index 0000000..e3d9413 --- /dev/null +++ b/services/product/internal/logic/editApplyPassLogic.go @@ -0,0 +1,31 @@ +package logic + +import ( + "context" + + "lone-services/rpc/product/pb" + "lone-services/services/product/internal/svc" + + "github.com/zeromicro/go-zero/core/logx" +) + +type EditApplyPassLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + logx.Logger +} + +func NewEditApplyPassLogic(ctx context.Context, svcCtx *svc.ServiceContext) *EditApplyPassLogic { + return &EditApplyPassLogic{ + ctx: ctx, + svcCtx: svcCtx, + Logger: logx.WithContext(ctx), + } +} + +// TODO: 临时接口,企微编辑申请审批对接后删除 +func (l *EditApplyPassLogic) EditApplyPass(in *product.EditApplyPassReq) (*product.Response, error) { + // todo: add your logic here and delete this line + + return &product.Response{}, nil +} diff --git a/services/product/internal/logic/editapplylogic.go b/services/product/internal/logic/editapplylogic.go index 6fd2739..8089f23 100644 --- a/services/product/internal/logic/editapplylogic.go +++ b/services/product/internal/logic/editapplylogic.go @@ -36,7 +36,7 @@ func (l *EditApplyLogic) EditApply(in *product.EditApplyReq) (*product.Response, return outResponse(utils.ErrorParams, msg), nil } - var exist dao.ProductCheckExist + var exist dao.CheckExist err := model.ProductModel{}.Init().GetOne(modelbase.Params{ Eq: map[string]string{"id": strconv.FormatInt(req.Id, 10)}, }, &exist) @@ -78,7 +78,7 @@ func (l *EditApplyLogic) EditApplyPass(in *product.EditApplyPassReq) (*product.R return outResponse(utils.ErrorParams, msg), nil } - var exist dao.ProductCheckExist + var exist dao.CheckExist err := model.ProductModel{}.Init().GetOne(modelbase.Params{ Eq: map[string]string{"id": strconv.FormatInt(req.Id, 10)}, }, &exist) diff --git a/services/product/internal/logic/editbaselogic.go b/services/product/internal/logic/editbaselogic.go index 6804935..064f3a8 100644 --- a/services/product/internal/logic/editbaselogic.go +++ b/services/product/internal/logic/editbaselogic.go @@ -50,7 +50,7 @@ func (l *EditBaseLogic) EditBase(in *product.EditBaseReq) (*product.Response, er } w := modelbase.Params{Eq: map[string]string{"id": strconv.FormatInt(req.Id, 10)}} - var old dao.ProductEditBase + var old dao.EditBase m := model.ProductModel{}.Init() err := m.GetOne(w, &old) if err != nil { @@ -61,7 +61,7 @@ func (l *EditBaseLogic) EditBase(in *product.EditBaseReq) (*product.Response, er return failResponse(utils.ErrorNotFund), nil } - var nameCheck dao.ProductCheckExist + var nameCheck dao.CheckExist err = m.GetOne(modelbase.Params{Eq: map[string]string{"name": req.Name}}, &nameCheck) if err != nil { l.Errorf("edit base name check: %v", err) @@ -80,12 +80,17 @@ func (l *EditBaseLogic) EditBase(in *product.EditBaseReq) (*product.Response, er publishTime = t } - data := dao.ProductEditBase{ + images := joinImages(req.Images) + if images == "[]" { + return outResponse(utils.ErrorParams, "图片不能为空"), nil + } + + data := dao.EditBase{ Id: old.Id, Name: req.Name, Subhead: req.Subhead, Content: req.Content, - Images: req.Images, + Images: images, PeriodValidity: int16(req.PeriodValidity), Waybill: req.Waybill, Weight: float32(req.Weight), diff --git a/services/product/internal/logic/editsusceptiblelogic.go b/services/product/internal/logic/editsusceptiblelogic.go index 8bd8cc3..d482959 100644 --- a/services/product/internal/logic/editsusceptiblelogic.go +++ b/services/product/internal/logic/editsusceptiblelogic.go @@ -68,7 +68,7 @@ func (l *EditSusceptibleLogic) EditSusceptible(in *product.EditSusceptibleReq) ( }, }, } - var old dao.ProductEditSusceptible + var old dao.EditSusceptible err := model.ProductModel{}.Init().GetOne(w, &old) if err != nil { l.Errorf("edit susceptible get: %v", err) @@ -78,7 +78,7 @@ func (l *EditSusceptibleLogic) EditSusceptible(in *product.EditSusceptibleReq) ( return failResponse(utils.ErrorNotFund), nil } - data := dao.ProductEditSusceptible{ + data := dao.EditSusceptible{ Id: int(req.Id), ModelCode: req.ModelCode, Price: float32(req.Price), @@ -102,7 +102,7 @@ func (l *EditSusceptibleLogic) EditSusceptible(in *product.EditSusceptibleReq) ( err = l.svcCtx.DB.WithContext(l.ctx).Transaction(func(tx *gorm.DB) error { pm := model.ProductModel{}.Init().WithTX(tx) - if _, err := pm.Edit(w, &dao.ProductVerifyFirstEditStatus{ + if _, err := pm.Edit(w, &dao.VerifyFirstEditStatus{ VerifyStatus: dao.VerifyStatusChecking, }); err != nil { return err diff --git a/services/product/internal/logic/infoByIdLogic.go b/services/product/internal/logic/infoByIdLogic.go new file mode 100644 index 0000000..524a99e --- /dev/null +++ b/services/product/internal/logic/infoByIdLogic.go @@ -0,0 +1,54 @@ +package logic + +import ( + "context" + "strconv" + + "lone-services/pkg/modelbase" + "lone-services/pkg/utils" + "lone-services/pkg/validate" + product "lone-services/rpc/product/pb" + "lone-services/services/product/internal/dao" + "lone-services/services/product/internal/model" + "lone-services/services/product/internal/svc" + "lone-services/services/product/validator" + + "github.com/zeromicro/go-zero/core/logx" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" +) + +type InfoByIdLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + logx.Logger +} + +func NewInfoByIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *InfoByIdLogic { + return &InfoByIdLogic{ + ctx: ctx, + svcCtx: svcCtx, + Logger: logx.WithContext(ctx), + } +} + +func (l *InfoByIdLogic) InfoById(in *product.InfoByIdReq) (*product.Item, error) { + var req validator.ProductInfoValidator + if msg := validate.ValidateFromProto(in, &req); msg != utils.StringEmpty { + return nil, status.Error(codes.InvalidArgument, msg) + } + + var info dao.Info + err := model.ProductModel{}.Init().GetOne(modelbase.Params{ + Eq: map[string]string{"id": strconv.FormatInt(req.Id, 10)}, + }, &info) + if err != nil { + l.Errorf("product InfoById: %v", err) + return nil, status.Error(codes.Internal, utils.Fail.Msg) + } + if info.Id < 1 { + return nil, status.Error(codes.NotFound, utils.ErrorNotFund.Msg) + } + + return toProductItem(info), nil +} diff --git a/services/product/internal/logic/infologic.go b/services/product/internal/logic/infologic.go index 2ba4b80..6aaa9df 100644 --- a/services/product/internal/logic/infologic.go +++ b/services/product/internal/logic/infologic.go @@ -36,7 +36,7 @@ func (l *InfoLogic) Info(in *product.InfoReq) (*product.Response, error) { return outResponse(utils.ErrorParams, msg), nil } - var info dao.ProductInfo + var info dao.Info err := model.ProductModel{}.Init().GetOne(modelbase.Params{ Eq: map[string]string{"id": strconv.FormatInt(req.Id, 10)}, }, &info) diff --git a/services/product/internal/logic/itemsByIdsLogic.go b/services/product/internal/logic/itemsByIdsLogic.go new file mode 100644 index 0000000..fe8bfa4 --- /dev/null +++ b/services/product/internal/logic/itemsByIdsLogic.go @@ -0,0 +1,60 @@ +package logic + +import ( + "context" + "strconv" + + "lone-services/pkg/modelbase" + "lone-services/pkg/utils" + "lone-services/pkg/validate" + product "lone-services/rpc/product/pb" + "lone-services/services/product/internal/dao" + "lone-services/services/product/internal/model" + "lone-services/services/product/internal/svc" + "lone-services/services/product/validator" + + "github.com/zeromicro/go-zero/core/logx" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" +) + +type ItemsByIdsLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + logx.Logger +} + +func NewItemsByIdsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ItemsByIdsLogic { + return &ItemsByIdsLogic{ + ctx: ctx, + svcCtx: svcCtx, + Logger: logx.WithContext(ctx), + } +} + +func (l *ItemsByIdsLogic) ItemsByIds(in *product.ItemsByIdsReq) (*product.ItemsByIdsData, error) { + var req validator.ProductItemsByIdsValidator + if msg := validate.ValidateFromProto(in, &req); msg != utils.StringEmpty { + return nil, status.Error(codes.InvalidArgument, msg) + } + + ids := make([]string, 0, len(req.Ids)) + for _, id := range req.Ids { + ids = append(ids, strconv.FormatInt(id, 10)) + } + + var infos []dao.Info + err := model.ProductModel{}.Init().Items(modelbase.Params{ + In: map[string][]string{"id in ?": ids}, + }, &infos) + if err != nil { + l.Errorf("product ItemsByIds: %v", err) + return nil, status.Error(codes.Internal, utils.Fail.Msg) + } + + items := make([]*product.Item, 0, len(infos)) + for _, row := range infos { + items = append(items, toProductItem(row)) + } + return &product.ItemsByIdsData{Items: items}, nil +} diff --git a/services/product/internal/logic/itemslogic.go b/services/product/internal/logic/itemslogic.go index 49fd705..66615c2 100644 --- a/services/product/internal/logic/itemslogic.go +++ b/services/product/internal/logic/itemslogic.go @@ -55,7 +55,7 @@ func (l *ItemsLogic) Items(in *product.ItemsReq) (*product.Response, error) { } } - var info []dao.ProductInfo + var info []dao.Info result, err := model.ProductModel{}.Init().Page(w, &info) if err != nil { l.Errorf("product items: %v", err) diff --git a/services/product/internal/logic/nameslogic.go b/services/product/internal/logic/nameslogic.go index c7b8aac..2ce916e 100644 --- a/services/product/internal/logic/nameslogic.go +++ b/services/product/internal/logic/nameslogic.go @@ -28,7 +28,7 @@ func NewNamesLogic(ctx context.Context, svcCtx *svc.ServiceContext) *NamesLogic } func (l *NamesLogic) Names(_ *product.NamesReq) (*product.Response, error) { - var info []dao.ProductNames + var info []dao.Names err := model.ProductModel{}.Init().Items(modelbase.Params{ Eq: map[string]string{"status": strconv.Itoa(int(dao.ProductStatusNormal))}, }, &info) diff --git a/services/product/internal/logic/numberAddLogic.go b/services/product/internal/logic/numberAddLogic.go new file mode 100644 index 0000000..9f8b3fa --- /dev/null +++ b/services/product/internal/logic/numberAddLogic.go @@ -0,0 +1,64 @@ +package logic + +import ( + "context" + + "lone-services/pkg/utils" + "lone-services/pkg/validate" + product "lone-services/rpc/product/pb" + "lone-services/services/product/internal/dao" + "lone-services/services/product/internal/svc" + "lone-services/services/product/validator" + + "github.com/zeromicro/go-zero/core/logx" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" +) + +type NumberAddLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + logx.Logger +} + +func NewNumberAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *NumberAddLogic { + return &NumberAddLogic{ + ctx: ctx, + svcCtx: svcCtx, + Logger: logx.WithContext(ctx), + } +} + +func (l *NumberAddLogic) NumberAdd(in *product.NumberAddReq) (*product.Response, error) { + var req validator.ProductNumberAddValidator + if msg := validate.ValidateFromProto(in, &req); msg != utils.StringEmpty { + return outResponse(utils.ErrorParams, msg), nil + } + + adminInfo := utils.GetUserFromCtx(l.ctx) + if adminInfo.ID < utils.NumberOne { + return failResponse(utils.ErrorNoLoginInfo), nil + } + + if err := changeProductNumber(l.Logger, req.Id, dao.NumberTypeAdd, req.Number); err != nil { + return mapNumberErr(err), nil + } + return okResponse(utils.StringEmpty), nil +} + +func mapNumberErr(err error) *product.Response { + st, ok := status.FromError(err) + if !ok { + return failResponse(utils.Fail) + } + switch st.Code() { + case codes.InvalidArgument: + return outResponse(utils.ErrorParams, st.Message()) + case codes.NotFound: + return failResponse(utils.ErrorNotFund) + case codes.FailedPrecondition: + return failResponse(utils.ErrorStockNotEnough) + default: + return failResponse(utils.Fail) + } +} diff --git a/services/product/internal/logic/numberLogic.go b/services/product/internal/logic/numberLogic.go new file mode 100644 index 0000000..bdc42e8 --- /dev/null +++ b/services/product/internal/logic/numberLogic.go @@ -0,0 +1,86 @@ +package logic + +import ( + "context" + "strconv" + + "lone-services/pkg/modelbase" + "lone-services/pkg/utils" + "lone-services/pkg/validate" + product "lone-services/rpc/product/pb" + "lone-services/services/product/internal/dao" + "lone-services/services/product/internal/model" + "lone-services/services/product/internal/svc" + "lone-services/services/product/validator" + + "github.com/zeromicro/go-zero/core/logx" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + "google.golang.org/protobuf/types/known/emptypb" +) + +type NumberLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + logx.Logger +} + +func NewNumberLogic(ctx context.Context, svcCtx *svc.ServiceContext) *NumberLogic { + return &NumberLogic{ + ctx: ctx, + svcCtx: svcCtx, + Logger: logx.WithContext(ctx), + } +} + +// Number 服务间增减库存:type=1 增加,type=2 减少 +func (l *NumberLogic) Number(in *product.NumberReq) (*emptypb.Empty, error) { + var req validator.ProductNumberValidator + if msg := validate.ValidateFromProto(in, &req); msg != utils.StringEmpty { + return nil, status.Error(codes.InvalidArgument, msg) + } + + if err := changeProductNumber(l.Logger, req.Id, req.Type, req.Number); err != nil { + return nil, err + } + return &emptypb.Empty{}, nil +} + +func changeProductNumber(logger logx.Logger, id int64, typ uint32, number uint32) error { + var info dao.NumberInfo + w := modelbase.Params{ + Eq: map[string]string{"id": strconv.FormatInt(id, 10)}, + } + m := model.ProductModel{}.Init() + if err := m.GetOne(w, &info); err != nil { + logger.Errorf("product number get: %v", err) + return status.Error(codes.Internal, utils.Fail.Msg) + } + if info.Id < 1 { + return status.Error(codes.NotFound, utils.ErrorNotFund.Msg) + } + + var ( + rows int64 + err error + ) + switch typ { + case dao.NumberTypeAdd: + rows, err = m.IncrNumber(id, number) + case dao.NumberTypeSub: + rows, err = m.DecrNumber(id, number) + default: + return status.Error(codes.InvalidArgument, utils.ErrorParams.Msg) + } + if err != nil { + logger.Errorf("product number change: %v", err) + return status.Error(codes.Internal, utils.Fail.Msg) + } + if rows < 1 { + if typ == dao.NumberTypeSub { + return status.Error(codes.FailedPrecondition, utils.ErrorStockNotEnough.Msg) + } + return status.Error(codes.Internal, utils.Fail.Msg) + } + return nil +} diff --git a/services/product/internal/logic/sortlogic.go b/services/product/internal/logic/sortlogic.go index 639005a..9418471 100644 --- a/services/product/internal/logic/sortlogic.go +++ b/services/product/internal/logic/sortlogic.go @@ -35,7 +35,7 @@ func (l *SortLogic) Sort(in *product.SortReq) (*product.Response, error) { return outResponse(utils.ErrorParams, msg), nil } - var info dao.ProductSort + var info dao.Sort w := modelbase.Params{ Eq: map[string]string{"id": strconv.FormatInt(req.Id, 10)}, } diff --git a/services/product/internal/logic/statuslogic.go b/services/product/internal/logic/statuslogic.go index 7f774e1..a1a17f8 100644 --- a/services/product/internal/logic/statuslogic.go +++ b/services/product/internal/logic/statuslogic.go @@ -39,7 +39,7 @@ func (l *StatusLogic) Status(in *product.StatusReq) (*product.Response, error) { return failResponse(utils.ErrorReasonParams), nil } - var info dao.ProductCheckExist + var info dao.CheckExist w := modelbase.Params{ Eq: map[string]string{ "id": strconv.FormatInt(req.Id, 10), @@ -61,7 +61,7 @@ func (l *StatusLogic) Status(in *product.StatusReq) (*product.Response, error) { return failResponse(utils.ErrorNoLoginInfo), nil } - update := dao.ProductStatusUpdate{ + update := dao.StatusUpdate{ Status: uint8(req.Status), Reason: req.Reason, AdminName: adminInfo.Name, diff --git a/services/product/internal/logic/verifyFirstLogic.go b/services/product/internal/logic/verifyFirstLogic.go new file mode 100644 index 0000000..0ea364e --- /dev/null +++ b/services/product/internal/logic/verifyFirstLogic.go @@ -0,0 +1,31 @@ +package logic + +import ( + "context" + + "lone-services/rpc/product/pb" + "lone-services/services/product/internal/svc" + + "github.com/zeromicro/go-zero/core/logx" +) + +type VerifyFirstLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + logx.Logger +} + +func NewVerifyFirstLogic(ctx context.Context, svcCtx *svc.ServiceContext) *VerifyFirstLogic { + return &VerifyFirstLogic{ + ctx: ctx, + svcCtx: svcCtx, + Logger: logx.WithContext(ctx), + } +} + +// 一审通过/驳回 +func (l *VerifyFirstLogic) VerifyFirst(in *product.VerifyStatusReq) (*product.Response, error) { + // todo: add your logic here and delete this line + + return &product.Response{}, nil +} diff --git a/services/product/internal/logic/verifySecondLogic.go b/services/product/internal/logic/verifySecondLogic.go new file mode 100644 index 0000000..0cc2e3c --- /dev/null +++ b/services/product/internal/logic/verifySecondLogic.go @@ -0,0 +1,31 @@ +package logic + +import ( + "context" + + "lone-services/rpc/product/pb" + "lone-services/services/product/internal/svc" + + "github.com/zeromicro/go-zero/core/logx" +) + +type VerifySecondLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + logx.Logger +} + +func NewVerifySecondLogic(ctx context.Context, svcCtx *svc.ServiceContext) *VerifySecondLogic { + return &VerifySecondLogic{ + ctx: ctx, + svcCtx: svcCtx, + Logger: logx.WithContext(ctx), + } +} + +// 二审通过/驳回 +func (l *VerifySecondLogic) VerifySecond(in *product.VerifyStatusReq) (*product.Response, error) { + // todo: add your logic here and delete this line + + return &product.Response{}, nil +} diff --git a/services/product/internal/logic/verifylogic.go b/services/product/internal/logic/verifylogic.go index 7e98829..d9d57bb 100644 --- a/services/product/internal/logic/verifylogic.go +++ b/services/product/internal/logic/verifylogic.go @@ -58,7 +58,7 @@ func (l *VerifyLogic) Verify(in *product.VerifyReq) (*product.Response, error) { Order: "id desc", } - var rows []dao.ProductVerifyListRow + var rows []dao.VerifyListRow result, err := model.ProductModel{}.Init().Page(w, &rows) if err != nil { l.Errorf("product verify list: %v", err) @@ -102,7 +102,7 @@ func (l *VerifyLogic) Verify(in *product.VerifyReq) (*product.Response, error) { if !ok || len(v.Content) <= utils.NumberTen { continue } - var content dao.ProductVerify + var content dao.VerifyContent err = jsoniter.Unmarshal([]byte(v.Content), &content) if err != nil { l.Errorf("product verify content json: %v", err) diff --git a/services/product/internal/logic/verifystatuslogic.go b/services/product/internal/logic/verifystatuslogic.go index 5989dd6..b8479d7 100644 --- a/services/product/internal/logic/verifystatuslogic.go +++ b/services/product/internal/logic/verifystatuslogic.go @@ -85,7 +85,7 @@ func (l *VerifyStatusLogic) verifyStatus(expectStatus uint8, in *product.VerifyS } productWhere := modelbase.Params{Eq: map[string]string{"id": info.VerifyId}} - var productExist dao.ProductCheckExist + var productExist dao.CheckExist err = model.ProductModel{}.Init().GetOne(productWhere, &productExist) if err != nil { l.Errorf("verify product get: %v", err) @@ -110,7 +110,7 @@ func (l *VerifyStatusLogic) verifyStatus(expectStatus uint8, in *product.VerifyS }); err != nil { return err } - _, err := pm.Edit(productWhere, &dao.ProductVerifyFirstStatus{ + _, err := pm.Edit(productWhere, &dao.VerifyFirstStatus{ VerifyStatus: nextStatus, VerifyId: adminId, VerifyName: adminName, @@ -130,12 +130,12 @@ func (l *VerifyStatusLogic) verifyStatus(expectStatus uint8, in *product.VerifyS } if nextStatus == dao.VerifyStatusPass { - var content dao.ProductVerify + var content dao.VerifyContent if err := jsoniter.Unmarshal([]byte(info.Content), &content); err != nil { l.Errorf("product verify content json: %v content=%s", err, info.Content) return err } - _, err := pm.Edit(productWhere, &dao.ProductVerifySecondOkStatus{ + _, err := pm.Edit(productWhere, &dao.VerifySecondOkStatus{ ModelCode: content.ModelCode, Price: content.Price, StorePrice: content.StorePrice, @@ -154,7 +154,7 @@ func (l *VerifyStatusLogic) verifyStatus(expectStatus uint8, in *product.VerifyS return err } - _, err := pm.Edit(productWhere, &dao.ProductVerifySecondStatus{ + _, err := pm.Edit(productWhere, &dao.VerifySecondStatus{ VerifyStatus: nextStatus, VerifySecondId: adminId, VerifySecondName: adminName, diff --git a/services/product/internal/model/product_model.go b/services/product/internal/model/product_model.go index 8c31198..ba50dd4 100644 --- a/services/product/internal/model/product_model.go +++ b/services/product/internal/model/product_model.go @@ -3,6 +3,8 @@ package model import ( "lone-services/pkg/modelbase" "lone-services/services/product/internal/dao" + + "gorm.io/gorm" ) type ProductModel struct { @@ -18,6 +20,20 @@ func (m ProductModel) Init() ProductModel { return m } -func (m ProductModel) Create(data *dao.ProductCreate) error { +func (m ProductModel) Create(data *dao.Create) error { return m.Base.Create(data) } + +func (m ProductModel) IncrNumber(id int64, n uint32) (int64, error) { + ret := modelbase.DB().Table(m.TableName()). + Where("id = ?", id). + Update("number", gorm.Expr("number + ?", n)) + return ret.RowsAffected, ret.Error +} + +func (m ProductModel) DecrNumber(id int64, n uint32) (int64, error) { + ret := modelbase.DB().Table(m.TableName()). + Where("id = ? AND number >= ?", id, n). + Update("number", gorm.Expr("number - ?", n)) + return ret.RowsAffected, ret.Error +} diff --git a/services/product/internal/server/productserver.go b/services/product/internal/server/productserver.go index f93ca51..eae7bcc 100644 --- a/services/product/internal/server/productserver.go +++ b/services/product/internal/server/productserver.go @@ -1,11 +1,14 @@ // Code generated by goctl. DO NOT EDIT. +// goctl 1.10.1 // Source: product.proto package server import ( "context" - product "lone-services/rpc/product/pb" + + "google.golang.org/protobuf/types/known/emptypb" + "lone-services/rpc/product/pb" "lone-services/services/product/internal/logic" "lone-services/services/product/internal/svc" ) @@ -51,37 +54,66 @@ func (s *ProductServer) Sort(ctx context.Context, in *product.SortReq) (*product return l.Sort(in) } +// 审核列表: status: 1: 一审, 2: 二审 func (s *ProductServer) Verify(ctx context.Context, in *product.VerifyReq) (*product.Response, error) { l := logic.NewVerifyLogic(ctx, s.svcCtx) return l.Verify(in) } +// 一审通过/驳回 func (s *ProductServer) VerifyFirst(ctx context.Context, in *product.VerifyStatusReq) (*product.Response, error) { - l := logic.NewVerifyStatusLogic(ctx, s.svcCtx) + l := logic.NewVerifyFirstLogic(ctx, s.svcCtx) return l.VerifyFirst(in) } +// 二审通过/驳回 func (s *ProductServer) VerifySecond(ctx context.Context, in *product.VerifyStatusReq) (*product.Response, error) { - l := logic.NewVerifyStatusLogic(ctx, s.svcCtx) + l := logic.NewVerifySecondLogic(ctx, s.svcCtx) return l.VerifySecond(in) } +// 编辑申请 func (s *ProductServer) EditApply(ctx context.Context, in *product.EditApplyReq) (*product.Response, error) { l := logic.NewEditApplyLogic(ctx, s.svcCtx) return l.EditApply(in) } -func (s *ProductServer) EditApplyPass(ctx context.Context, in *product.EditApplyPassReq) (*product.Response, error) { - l := logic.NewEditApplyLogic(ctx, s.svcCtx) - return l.EditApplyPass(in) -} - +// 编辑基础信息 func (s *ProductServer) EditBase(ctx context.Context, in *product.EditBaseReq) (*product.Response, error) { l := logic.NewEditBaseLogic(ctx, s.svcCtx) return l.EditBase(in) } +// 编辑敏感信息(进入一审) func (s *ProductServer) EditSusceptible(ctx context.Context, in *product.EditSusceptibleReq) (*product.Response, error) { l := logic.NewEditSusceptibleLogic(ctx, s.svcCtx) return l.EditSusceptible(in) } + +// TODO: 临时接口,企微编辑申请审批对接后删除 +func (s *ProductServer) EditApplyPass(ctx context.Context, in *product.EditApplyPassReq) (*product.Response, error) { + l := logic.NewEditApplyPassLogic(ctx, s.svcCtx) + return l.EditApplyPass(in) +} + +// 增减库存 +func (s *ProductServer) Number(ctx context.Context, in *product.NumberReq) (*emptypb.Empty, error) { + l := logic.NewNumberLogic(ctx, s.svcCtx) + return l.Number(in) +} + +func (s *ProductServer) InfoById(ctx context.Context, in *product.InfoByIdReq) (*product.Item, error) { + l := logic.NewInfoByIdLogic(ctx, s.svcCtx) + return l.InfoById(in) +} + +func (s *ProductServer) ItemsByIds(ctx context.Context, in *product.ItemsByIdsReq) (*product.ItemsByIdsData, error) { + l := logic.NewItemsByIdsLogic(ctx, s.svcCtx) + return l.ItemsByIds(in) +} + +// 增加库存 +func (s *ProductServer) NumberAdd(ctx context.Context, in *product.NumberAddReq) (*product.Response, error) { + l := logic.NewNumberAddLogic(ctx, s.svcCtx) + return l.NumberAdd(in) +} diff --git a/services/product/productClient/product.go b/services/product/productClient/product.go new file mode 100644 index 0000000..4c1ac92 --- /dev/null +++ b/services/product/productClient/product.go @@ -0,0 +1,176 @@ +// Code generated by goctl. DO NOT EDIT. +// goctl 1.10.1 +// Source: product.proto + +package productClient + +import ( + "context" + + "lone-services/rpc/product/pb" + + "google.golang.org/protobuf/types/known/emptypb" + + "github.com/zeromicro/go-zero/zrpc" + "google.golang.org/grpc" +) + +type ( + CreateReq = product.CreateReq + EditApplyPassReq = product.EditApplyPassReq + EditApplyReq = product.EditApplyReq + EditBaseReq = product.EditBaseReq + EditSusceptibleReq = product.EditSusceptibleReq + InfoByIdReq = product.InfoByIdReq + InfoReq = product.InfoReq + Item = product.Item + ItemsByIdsData = product.ItemsByIdsData + ItemsByIdsReq = product.ItemsByIdsReq + ItemsData = product.ItemsData + ItemsReq = product.ItemsReq + NameItem = product.NameItem + NamesReq = product.NamesReq + NumberAddReq = product.NumberAddReq + NumberReq = product.NumberReq + Response = product.Response + SortReq = product.SortReq + StatusReq = product.StatusReq + VerifyItem = product.VerifyItem + VerifyItemsData = product.VerifyItemsData + VerifyParams = product.VerifyParams + VerifyReq = product.VerifyReq + VerifyStatusReq = product.VerifyStatusReq + + Product interface { + Create(ctx context.Context, in *CreateReq, opts ...grpc.CallOption) (*Response, error) + Info(ctx context.Context, in *InfoReq, opts ...grpc.CallOption) (*Response, error) + Items(ctx context.Context, in *ItemsReq, opts ...grpc.CallOption) (*Response, error) + Names(ctx context.Context, in *NamesReq, opts ...grpc.CallOption) (*Response, error) + Status(ctx context.Context, in *StatusReq, opts ...grpc.CallOption) (*Response, error) + Sort(ctx context.Context, in *SortReq, opts ...grpc.CallOption) (*Response, error) + // 审核列表: status: 1: 一审, 2: 二审 + Verify(ctx context.Context, in *VerifyReq, opts ...grpc.CallOption) (*Response, error) + // 一审通过/驳回 + VerifyFirst(ctx context.Context, in *VerifyStatusReq, opts ...grpc.CallOption) (*Response, error) + // 二审通过/驳回 + VerifySecond(ctx context.Context, in *VerifyStatusReq, opts ...grpc.CallOption) (*Response, error) + // 编辑申请 + EditApply(ctx context.Context, in *EditApplyReq, opts ...grpc.CallOption) (*Response, error) + // 编辑基础信息 + EditBase(ctx context.Context, in *EditBaseReq, opts ...grpc.CallOption) (*Response, error) + // 编辑敏感信息(进入一审) + EditSusceptible(ctx context.Context, in *EditSusceptibleReq, opts ...grpc.CallOption) (*Response, error) + // TODO: 临时接口,企微编辑申请审批对接后删除 + EditApplyPass(ctx context.Context, in *EditApplyPassReq, opts ...grpc.CallOption) (*Response, error) + // 增减库存 + Number(ctx context.Context, in *NumberReq, opts ...grpc.CallOption) (*emptypb.Empty, error) + InfoById(ctx context.Context, in *InfoByIdReq, opts ...grpc.CallOption) (*Item, error) + ItemsByIds(ctx context.Context, in *ItemsByIdsReq, opts ...grpc.CallOption) (*ItemsByIdsData, error) + // 增加库存 + NumberAdd(ctx context.Context, in *NumberAddReq, opts ...grpc.CallOption) (*Response, error) + } + + defaultProduct struct { + cli zrpc.Client + } +) + +func NewProduct(cli zrpc.Client) Product { + return &defaultProduct{ + cli: cli, + } +} + +func (m *defaultProduct) Create(ctx context.Context, in *CreateReq, opts ...grpc.CallOption) (*Response, error) { + client := product.NewProductClient(m.cli.Conn()) + return client.Create(ctx, in, opts...) +} + +func (m *defaultProduct) Info(ctx context.Context, in *InfoReq, opts ...grpc.CallOption) (*Response, error) { + client := product.NewProductClient(m.cli.Conn()) + return client.Info(ctx, in, opts...) +} + +func (m *defaultProduct) Items(ctx context.Context, in *ItemsReq, opts ...grpc.CallOption) (*Response, error) { + client := product.NewProductClient(m.cli.Conn()) + return client.Items(ctx, in, opts...) +} + +func (m *defaultProduct) Names(ctx context.Context, in *NamesReq, opts ...grpc.CallOption) (*Response, error) { + client := product.NewProductClient(m.cli.Conn()) + return client.Names(ctx, in, opts...) +} + +func (m *defaultProduct) Status(ctx context.Context, in *StatusReq, opts ...grpc.CallOption) (*Response, error) { + client := product.NewProductClient(m.cli.Conn()) + return client.Status(ctx, in, opts...) +} + +func (m *defaultProduct) Sort(ctx context.Context, in *SortReq, opts ...grpc.CallOption) (*Response, error) { + client := product.NewProductClient(m.cli.Conn()) + return client.Sort(ctx, in, opts...) +} + +// 审核列表: status: 1: 一审, 2: 二审 +func (m *defaultProduct) Verify(ctx context.Context, in *VerifyReq, opts ...grpc.CallOption) (*Response, error) { + client := product.NewProductClient(m.cli.Conn()) + return client.Verify(ctx, in, opts...) +} + +// 一审通过/驳回 +func (m *defaultProduct) VerifyFirst(ctx context.Context, in *VerifyStatusReq, opts ...grpc.CallOption) (*Response, error) { + client := product.NewProductClient(m.cli.Conn()) + return client.VerifyFirst(ctx, in, opts...) +} + +// 二审通过/驳回 +func (m *defaultProduct) VerifySecond(ctx context.Context, in *VerifyStatusReq, opts ...grpc.CallOption) (*Response, error) { + client := product.NewProductClient(m.cli.Conn()) + return client.VerifySecond(ctx, in, opts...) +} + +// 编辑申请 +func (m *defaultProduct) EditApply(ctx context.Context, in *EditApplyReq, opts ...grpc.CallOption) (*Response, error) { + client := product.NewProductClient(m.cli.Conn()) + return client.EditApply(ctx, in, opts...) +} + +// 编辑基础信息 +func (m *defaultProduct) EditBase(ctx context.Context, in *EditBaseReq, opts ...grpc.CallOption) (*Response, error) { + client := product.NewProductClient(m.cli.Conn()) + return client.EditBase(ctx, in, opts...) +} + +// 编辑敏感信息(进入一审) +func (m *defaultProduct) EditSusceptible(ctx context.Context, in *EditSusceptibleReq, opts ...grpc.CallOption) (*Response, error) { + client := product.NewProductClient(m.cli.Conn()) + return client.EditSusceptible(ctx, in, opts...) +} + +// TODO: 临时接口,企微编辑申请审批对接后删除 +func (m *defaultProduct) EditApplyPass(ctx context.Context, in *EditApplyPassReq, opts ...grpc.CallOption) (*Response, error) { + client := product.NewProductClient(m.cli.Conn()) + return client.EditApplyPass(ctx, in, opts...) +} + +// 增减库存 +func (m *defaultProduct) Number(ctx context.Context, in *NumberReq, opts ...grpc.CallOption) (*emptypb.Empty, error) { + client := product.NewProductClient(m.cli.Conn()) + return client.Number(ctx, in, opts...) +} + +func (m *defaultProduct) InfoById(ctx context.Context, in *InfoByIdReq, opts ...grpc.CallOption) (*Item, error) { + client := product.NewProductClient(m.cli.Conn()) + return client.InfoById(ctx, in, opts...) +} + +func (m *defaultProduct) ItemsByIds(ctx context.Context, in *ItemsByIdsReq, opts ...grpc.CallOption) (*ItemsByIdsData, error) { + client := product.NewProductClient(m.cli.Conn()) + return client.ItemsByIds(ctx, in, opts...) +} + +// 增加库存 +func (m *defaultProduct) NumberAdd(ctx context.Context, in *NumberAddReq, opts ...grpc.CallOption) (*Response, error) { + client := product.NewProductClient(m.cli.Conn()) + return client.NumberAdd(ctx, in, opts...) +} diff --git a/services/product/validator/validator.go b/services/product/validator/validator.go index 4975930..e4bdc8c 100644 --- a/services/product/validator/validator.go +++ b/services/product/validator/validator.go @@ -13,13 +13,13 @@ type ProductCreateValidator struct { SalePrice float64 SharePrice float64 AgentPrice float64 - SaleReward string `validate:"max=255"` - Images string `validate:"required,max=512"` - Weight float64 `validate:"required"` - Cubage string `validate:"required,max=255"` - Waybill string `validate:"required,max=255"` - PeriodValidity int32 `validate:"required"` - NormsNumber uint32 `validate:"required,min=1"` + SaleReward string `validate:"max=255"` + Images []string `validate:"required,min=1,dive,required"` + Weight float64 `validate:"required"` + Cubage string `validate:"required,max=255"` + Waybill string `validate:"required,max=255"` + PeriodValidity int32 `validate:"required"` + NormsNumber uint32 `validate:"required,min=1"` BoxNumber float64 Type uint32 `validate:"required,oneof=1 2 3"` Number uint32 @@ -42,6 +42,7 @@ func (p ProductCreateValidator) GetMessage() validate.ValidatorMessages { "ModelCode.required": "请输入机器码", "Price.required": "价格不能为空", "Images.required": "图片不能为空", + "Images.min": "图片不能为空", "Weight.required": "重量不能为空", "Cubage.required": "体积不能为空", "Waybill.required": "运货单图片不能为空", @@ -168,14 +169,14 @@ type ProductEditBaseValidator struct { Content string `validate:"required"` Waybill string `validate:"required,max=255"` Weight float64 `validate:"required"` - Cubage string `validate:"required,max=255"` - Images string `validate:"required,max=512"` - PeriodValidity int32 `validate:"required"` - PublishTime string `validate:"max=32"` - Label string `validate:"max=255"` - IsBuy uint32 `validate:"omitempty,oneof=1 2"` - IsIndex uint32 `validate:"omitempty,oneof=1 2"` - IndexImage string `validate:"max=255"` + Cubage string `validate:"required,max=255"` + Images []string `validate:"required,min=1,dive,required"` + PeriodValidity int32 `validate:"required"` + PublishTime string `validate:"max=32"` + Label string `validate:"max=255"` + IsBuy uint32 `validate:"omitempty,oneof=1 2"` + IsIndex uint32 `validate:"omitempty,oneof=1 2"` + IndexImage string `validate:"max=255"` } func (p ProductEditBaseValidator) GetMessage() validate.ValidatorMessages { @@ -186,6 +187,7 @@ func (p ProductEditBaseValidator) GetMessage() validate.ValidatorMessages { "Subhead.required": "副标题不能为空", "Content.required": "内容不能为空", "Images.required": "图片不能为空", + "Images.min": "图片不能为空", "PeriodValidity.required": "有效期不能为空", "Waybill.required": "运货单图片不能为空", "Weight.required": "重量不能为空", @@ -218,3 +220,45 @@ func (p ProductEditSusceptibleValidator) GetMessage() validate.ValidatorMessages "Type.oneof": "类型不对", } } + +type ProductNumberValidator struct { + Id int64 `validate:"required,gt=0"` + Type uint32 `validate:"required,oneof=1 2"` + Number uint32 `validate:"required,gt=0"` +} + +func (p ProductNumberValidator) GetMessage() validate.ValidatorMessages { + return validate.ValidatorMessages{ + "Id.required": "ID不能为空", + "Id.gt": "ID必须大于0", + "Type.required": "类型不能为空", + "Type.oneof": "类型不对", + "Number.required": "数量不能为空", + "Number.gt": "数量必须大于0", + } +} + +type ProductNumberAddValidator struct { + Id int64 `validate:"required,gt=0"` + Number uint32 `validate:"required,gt=0"` +} + +func (p ProductNumberAddValidator) GetMessage() validate.ValidatorMessages { + return validate.ValidatorMessages{ + "Id.required": "ID不能为空", + "Id.gt": "ID必须大于0", + "Number.required": "数量不能为空", + "Number.gt": "数量必须大于0", + } +} + +type ProductItemsByIdsValidator struct { + Ids []int64 `validate:"required,min=1"` +} + +func (p ProductItemsByIdsValidator) GetMessage() validate.ValidatorMessages { + return validate.ValidatorMessages{ + "Ids.required": "ID列表不能为空", + "Ids.min": "ID列表不能为空", + } +} diff --git a/services/user/internal/dao/user.go b/services/user/internal/dao/user.go index 8e8d857..e4c7350 100644 --- a/services/user/internal/dao/user.go +++ b/services/user/internal/dao/user.go @@ -89,6 +89,7 @@ type UserListRow struct { OnTrialNum int `gorm:"column:on_trial_num" json:"on_trial_num"` Gender int `gorm:"column:gender" json:"gender"` Birthday string `gorm:"column:birthday" json:"birthday"` + Status uint8 `gorm:"column:status" json:"status"` CreatedAt utils.CustomTime `gorm:"column:created_at" json:"created_at"` UpdatedAt utils.CustomTime `gorm:"column:updated_at" json:"updated_at"` } @@ -102,6 +103,7 @@ type UserListItem struct { OnTrialNum int `json:"on_trial_num"` Gender int `json:"gender"` Birthday string `json:"birthday"` + Status uint8 `json:"status"` CreatedAt utils.CustomTime `json:"created_at"` UpdatedAt utils.CustomTime `json:"updated_at"` } diff --git a/services/user/internal/logic/userItemsLogic.go b/services/user/internal/logic/userItemsLogic.go index db3b341..3be1045 100644 --- a/services/user/internal/logic/userItemsLogic.go +++ b/services/user/internal/logic/userItemsLogic.go @@ -83,6 +83,7 @@ func (l *UserItemsLogic) UserItems(in *user.UserItemsReq) (*user.Response, error OnTrialNum: row.OnTrialNum, Gender: row.Gender, Birthday: row.Birthday, + Status: row.Status, CreatedAt: row.CreatedAt, UpdatedAt: row.UpdatedAt, })