From 2b199370654bf60a364eb2dc71f9ea8435e7e3bb Mon Sep 17 00:00:00 2001 From: gjs Date: Thu, 17 Sep 2026 16:16:11 +0800 Subject: [PATCH] store and chore --- rpc/chore/chore.pb | Bin 15791 -> 15703 bytes rpc/chore/chore.proto | 13 ++ rpc/chore/pb/chore.pb.go | 178 +++++++++++++-- rpc/chore/pb/chore_grpc.pb.go | 40 +++- rpc/store/pb/store.pb.go | 12 +- rpc/store/store.pb | Bin 19840 -> 19842 bytes rpc/store/store.proto | 2 +- services/chore/choreclient/chore.go | 10 +- services/chore/internal/dao/smsLog.go | 11 + .../chore/internal/logic/sendPasswordLogic.go | 58 +++++ services/chore/internal/model/smsLog.go | 18 ++ services/chore/internal/server/choreServer.go | 7 +- services/sale/run.toml | 57 +++++ .../store/internal/logic/applyEditLogic.go | 27 ++- .../store/internal/logic/applyVerifyLogic.go | 105 ++++++++- .../internal/logic/applyVerifyStatusLogic.go | 202 +++++++++++++++++- services/store/internal/logic/createLogic.go | 84 ++++++-- .../internal/logic/depositBackfillLogic.go | 56 ++++- .../store/internal/logic/depositDoneLogic.go | 71 +++++- .../store/internal/logic/depositDownLogic.go | 108 +++++++++- .../internal/logic/depositIgnoreItemsLogic.go | 53 ++++- .../internal/logic/depositIgnoreLogic.go | 51 ++++- .../store/internal/logic/depositItemsLogic.go | 81 ++++++- .../internal/logic/depositRecoverLogic.go | 50 ++++- .../internal/logic/depositVerifyLogic.go | 77 ++++++- services/store/internal/logic/editLogic.go | 85 +++++++- .../store/internal/logic/getInfoByIdLogic.go | 72 +++++++ .../store/internal/logic/getInfoByIdsLogic.go | 74 +++++++ services/store/internal/logic/toSaleLogic.go | 35 ++- .../store/internal/logic/verifyEditLogic.go | 144 ++++++++++++- .../store/internal/logic/verifyItemsLogic.go | 102 ++++++++- .../store/internal/logic/verifyStatusLogic.go | 159 +++++++++++++- .../internal/logic/webDepositCreateLogic.go | 27 ++- .../internal/logic/webDepositItemsLogic.go | 31 ++- services/store/internal/svc/apply.go | 68 +++--- services/store/internal/svc/servicecontext.go | 7 + 36 files changed, 2037 insertions(+), 138 deletions(-) create mode 100644 services/chore/internal/dao/smsLog.go create mode 100644 services/chore/internal/logic/sendPasswordLogic.go create mode 100644 services/chore/internal/model/smsLog.go create mode 100644 services/sale/run.toml create mode 100644 services/store/internal/logic/getInfoByIdLogic.go create mode 100644 services/store/internal/logic/getInfoByIdsLogic.go diff --git a/rpc/chore/chore.pb b/rpc/chore/chore.pb index eecb0e8fdae2e5c0b28fa65b1369ea34f5a98510..85a1e2776035bea6162ec83a34813c79dd6ba11e 100644 GIT binary patch delta 496 zcmZ2qeZ6YKS|+BBgvslfOc6>}bLu~%KqH9Uyq;M@g=sn0-b4LSs?zKD@ih{Zp^)lcF%J4nfk$#*oeC;Mv3u|jxR zni)VHKsA2;ey(8kK;2=kL7r}ra2+2tlVuh$iU{%hxca$=c*F+;xw?5qfQ^S3QlJ$# z`HGf0#K_IRw4O7vvvIs&7wGoeoTtmp#I%)ZbG5z(BbpB+4K-PqJ_&7hF^ypsRGQ7m z#UGrSmlBXzTwI=ClrlNrLZ)7di=zO_mtaz0)Zh$)^Mw?-c#?|p%ZpQs;xqHo@+FwT z^4w4{PoR(x9~V<*fdmU!0?0zvl9!m9D#41P#SbW?q{bzHaD{A9N>FNXfshavOLBfn zsstlYJ!=q{ZM2GO^J0saERI6DR%#HVHEq{btJTrRZ6P#M&3RA8$ zgLShLv#JWyTJFi2>d|bQ7@0X_TiH;q-hdJ`nAm50_NtX!8@|0tprr<(K3e zN(q73d;wq%Ox5NJ9d0J3dCZ$z^)wjkOHm>!T__bAQQ&C75>dtZrA5i9@yYoqsqvY4 zY57R8q=hAxg2Bq2fvP=$iV;zCfr(4dJvA?N^I?4j7N*w%o1YrTFf$vy chore.RegionItem @@ -859,23 +991,25 @@ var file_chore_chore_proto_depIdxs = []int32{ 2, // 13: chore.Chore.SystemInfo:input_type -> chore.IdReq 1, // 14: chore.Chore.SystemItems:input_type -> chore.EmptyReq 10, // 15: chore.Chore.RegionsByIds:input_type -> chore.RegionsByIdsReq - 0, // 16: chore.Chore.Policy:output_type -> chore.Response - 0, // 17: chore.Chore.Test:output_type -> chore.Response - 0, // 18: chore.Chore.DecryptMobile:output_type -> chore.Response - 0, // 19: chore.Chore.Regions:output_type -> chore.Response - 0, // 20: chore.Chore.SendSms:output_type -> chore.Response - 0, // 21: chore.Chore.AnswerItems:output_type -> chore.Response - 0, // 22: chore.Chore.AnswerStatus:output_type -> chore.Response - 0, // 23: chore.Chore.AnswerInfo:output_type -> chore.Response - 0, // 24: chore.Chore.AnswerCreate:output_type -> chore.Response - 0, // 25: chore.Chore.AnswerEdit:output_type -> chore.Response - 0, // 26: chore.Chore.SystemEdit:output_type -> chore.Response - 0, // 27: chore.Chore.SystemStatus:output_type -> chore.Response - 0, // 28: chore.Chore.SystemInfo:output_type -> chore.Response - 0, // 29: chore.Chore.SystemItems:output_type -> chore.Response - 12, // 30: chore.Chore.RegionsByIds:output_type -> chore.RegionsByIdsData - 16, // [16:31] is the sub-list for method output_type - 1, // [1:16] is the sub-list for method input_type + 14, // 16: chore.Chore.SendPassword:input_type -> chore.SendPasswordReq + 0, // 17: chore.Chore.Policy:output_type -> chore.Response + 0, // 18: chore.Chore.Test:output_type -> chore.Response + 0, // 19: chore.Chore.DecryptMobile:output_type -> chore.Response + 0, // 20: chore.Chore.Regions:output_type -> chore.Response + 0, // 21: chore.Chore.SendSms:output_type -> chore.Response + 0, // 22: chore.Chore.AnswerItems:output_type -> chore.Response + 0, // 23: chore.Chore.AnswerStatus:output_type -> chore.Response + 0, // 24: chore.Chore.AnswerInfo:output_type -> chore.Response + 0, // 25: chore.Chore.AnswerCreate:output_type -> chore.Response + 0, // 26: chore.Chore.AnswerEdit:output_type -> chore.Response + 0, // 27: chore.Chore.SystemEdit:output_type -> chore.Response + 0, // 28: chore.Chore.SystemStatus:output_type -> chore.Response + 0, // 29: chore.Chore.SystemInfo:output_type -> chore.Response + 0, // 30: chore.Chore.SystemItems:output_type -> chore.Response + 12, // 31: chore.Chore.RegionsByIds:output_type -> chore.RegionsByIdsData + 15, // 32: chore.Chore.SendPassword:output_type -> chore.SendPasswordResp + 17, // [17:33] is the sub-list for method output_type + 1, // [1:17] is the sub-list for method input_type 1, // [1:1] is the sub-list for extension type_name 1, // [1:1] is the sub-list for extension extendee 0, // [0:1] is the sub-list for field type_name @@ -892,7 +1026,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: 14, + NumMessages: 16, NumExtensions: 0, NumServices: 1, }, diff --git a/rpc/chore/pb/chore_grpc.pb.go b/rpc/chore/pb/chore_grpc.pb.go index 7c86c7e..b720232 100644 --- a/rpc/chore/pb/chore_grpc.pb.go +++ b/rpc/chore/pb/chore_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 v3.19.4 +// - protoc v4.25.8 // source: chore/chore.proto package chore @@ -34,6 +34,7 @@ const ( Chore_SystemInfo_FullMethodName = "/chore.Chore/SystemInfo" Chore_SystemItems_FullMethodName = "/chore.Chore/SystemItems" Chore_RegionsByIds_FullMethodName = "/chore.Chore/RegionsByIds" + Chore_SendPassword_FullMethodName = "/chore.Chore/SendPassword" ) // ChoreClient is the client API for Chore service. @@ -56,6 +57,7 @@ type ChoreClient interface { SystemItems(ctx context.Context, in *EmptyReq, opts ...grpc.CallOption) (*Response, error) // 按 id 批量查地区名称 RegionsByIds(ctx context.Context, in *RegionsByIdsReq, opts ...grpc.CallOption) (*RegionsByIdsData, error) + SendPassword(ctx context.Context, in *SendPasswordReq, opts ...grpc.CallOption) (*SendPasswordResp, error) } type choreClient struct { @@ -216,6 +218,16 @@ func (c *choreClient) RegionsByIds(ctx context.Context, in *RegionsByIdsReq, opt return out, nil } +func (c *choreClient) SendPassword(ctx context.Context, in *SendPasswordReq, opts ...grpc.CallOption) (*SendPasswordResp, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(SendPasswordResp) + err := c.cc.Invoke(ctx, Chore_SendPassword_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. @@ -236,6 +248,7 @@ type ChoreServer interface { SystemItems(context.Context, *EmptyReq) (*Response, error) // 按 id 批量查地区名称 RegionsByIds(context.Context, *RegionsByIdsReq) (*RegionsByIdsData, error) + SendPassword(context.Context, *SendPasswordReq) (*SendPasswordResp, error) mustEmbedUnimplementedChoreServer() } @@ -291,6 +304,9 @@ func (UnimplementedChoreServer) SystemItems(context.Context, *EmptyReq) (*Respon func (UnimplementedChoreServer) RegionsByIds(context.Context, *RegionsByIdsReq) (*RegionsByIdsData, error) { return nil, status.Error(codes.Unimplemented, "method RegionsByIds not implemented") } +func (UnimplementedChoreServer) SendPassword(context.Context, *SendPasswordReq) (*SendPasswordResp, error) { + return nil, status.Error(codes.Unimplemented, "method SendPassword not implemented") +} func (UnimplementedChoreServer) mustEmbedUnimplementedChoreServer() {} func (UnimplementedChoreServer) testEmbeddedByValue() {} @@ -582,6 +598,24 @@ func _Chore_RegionsByIds_Handler(srv interface{}, ctx context.Context, dec func( return interceptor(ctx, in, info, handler) } +func _Chore_SendPassword_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(SendPasswordReq) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ChoreServer).SendPassword(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: Chore_SendPassword_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ChoreServer).SendPassword(ctx, req.(*SendPasswordReq)) + } + 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) @@ -649,6 +683,10 @@ var Chore_ServiceDesc = grpc.ServiceDesc{ MethodName: "RegionsByIds", Handler: _Chore_RegionsByIds_Handler, }, + { + MethodName: "SendPassword", + Handler: _Chore_SendPassword_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "chore/chore.proto", diff --git a/rpc/store/pb/store.pb.go b/rpc/store/pb/store.pb.go index 757478c..0076f6e 100644 --- a/rpc/store/pb/store.pb.go +++ b/rpc/store/pb/store.pb.go @@ -104,7 +104,7 @@ func (x *IdRequest) GetId() int64 { type IdsRequest struct { state protoimpl.MessageState `protogen:"open.v1"` - Id []int64 `protobuf:"varint,1,rep,packed,name=id,proto3" json:"id,omitempty"` + Ids []int64 `protobuf:"varint,1,rep,packed,name=ids,proto3" json:"ids,omitempty"` unknownFields protoimpl.UnknownFields sizeCache protoimpl.SizeCache } @@ -139,9 +139,9 @@ func (*IdsRequest) Descriptor() ([]byte, []int) { return file_store_store_proto_rawDescGZIP(), []int{2} } -func (x *IdsRequest) GetId() []int64 { +func (x *IdsRequest) GetIds() []int64 { if x != nil { - return x.Id + return x.Ids } return nil } @@ -1893,10 +1893,10 @@ const file_store_store_proto_rawDesc = "" + "\x11store/store.proto\x12\x05store\x1a\x1cgoogle/api/annotations.proto\"\x0e\n" + "\fEmptyRequest\"\x1b\n" + "\tIdRequest\x12\x0e\n" + - "\x02id\x18\x01 \x01(\x03R\x02id\"\x1c\n" + + "\x02id\x18\x01 \x01(\x03R\x02id\"\x1e\n" + "\n" + - "IdsRequest\x12\x0e\n" + - "\x02id\x18\x01 \x03(\x03R\x02id\"O\n" + + "IdsRequest\x12\x10\n" + + "\x03ids\x18\x01 \x03(\x03R\x03ids\"O\n" + "\rStatusRequest\x12\x0e\n" + "\x02id\x18\x01 \x01(\x03R\x02id\x12\x16\n" + "\x06status\x18\x02 \x01(\x05R\x06status\x12\x16\n" + diff --git a/rpc/store/store.pb b/rpc/store/store.pb index c122583c3a2269392eefaaaf956434f013f7fe28..86b05603066286790fbcd7ece72f705809f9c135 100644 GIT binary patch delta 52 zcmZpe&Db=Xal>O{#<`Q97^ln2adCO36bGdimZlb$2nld8XQmWOFe)%>Fb9E{n=?!# FBmvt)5A^^5 delta 50 zcmZpg&Db!Tal>O{#@Umf7^ln1aB+F26bGdimZlb$2=Q?-Wu{0lDlls>2LV}|vrHr; E0k%sI2LJ#7 diff --git a/rpc/store/store.proto b/rpc/store/store.proto index 9cbeb87..5cc5665 100644 --- a/rpc/store/store.proto +++ b/rpc/store/store.proto @@ -11,7 +11,7 @@ message IdRequest { int64 id = 1; } message IdsRequest { - repeated int64 id = 1; + repeated int64 ids = 1; } message StatusRequest { diff --git a/services/chore/choreclient/chore.go b/services/chore/choreclient/chore.go index 992495d..a487c3b 100644 --- a/services/chore/choreclient/chore.go +++ b/services/chore/choreclient/chore.go @@ -1,5 +1,5 @@ // Code generated by goctl. DO NOT EDIT. -// goctl 1.10.1 +// goctl 1.10.2 // Source: chore.proto package choreClient @@ -24,6 +24,8 @@ type ( RegionsByIdsReq = chore.RegionsByIdsReq RegionsReq = chore.RegionsReq Response = chore.Response + SendPasswordReq = chore.SendPasswordReq + SendPasswordResp = chore.SendPasswordResp SendSmsReq = chore.SendSmsReq StatusReq = chore.StatusReq SystemEditReq = chore.SystemEditReq @@ -46,6 +48,7 @@ type ( SystemItems(ctx context.Context, in *EmptyReq, opts ...grpc.CallOption) (*Response, error) // 按 id 批量查地区名称 RegionsByIds(ctx context.Context, in *RegionsByIdsReq, opts ...grpc.CallOption) (*RegionsByIdsData, error) + SendPassword(ctx context.Context, in *SendPasswordReq, opts ...grpc.CallOption) (*SendPasswordResp, error) } defaultChore struct { @@ -134,3 +137,8 @@ func (m *defaultChore) RegionsByIds(ctx context.Context, in *RegionsByIdsReq, op client := chore.NewChoreClient(m.cli.Conn()) return client.RegionsByIds(ctx, in, opts...) } + +func (m *defaultChore) SendPassword(ctx context.Context, in *SendPasswordReq, opts ...grpc.CallOption) (*SendPasswordResp, error) { + client := chore.NewChoreClient(m.cli.Conn()) + return client.SendPassword(ctx, in, opts...) +} diff --git a/services/chore/internal/dao/smsLog.go b/services/chore/internal/dao/smsLog.go new file mode 100644 index 0000000..07bb27d --- /dev/null +++ b/services/chore/internal/dao/smsLog.go @@ -0,0 +1,11 @@ +package dao + +type SmsLogCreate struct { + Id int `gorm:"column:id;type:int(11);primary_key;AUTO_INCREMENT;comment:ID" json:"id"` + Mobile string `gorm:"column:mobile;type:varchar(255)" json:"mobile"` + Content string `gorm:"column:content;type:varchar(255)" json:"content"` + BakContent string `gorm:"column:bak_content;type:varchar(255);comment:内容" json:"bak_content"` + BrowserInfo string `gorm:"column:browser_info;type:varchar(255);comment:浏览器详细信息" json:"browser_info"` + BrowserName string `gorm:"column:browser_name;type:varchar(255);comment:浏览器名称" json:"browser_name"` + Ip string `gorm:"column:ip;type:varchar(20);comment:IP;NOT NULL" json:"ip"` +} diff --git a/services/chore/internal/logic/sendPasswordLogic.go b/services/chore/internal/logic/sendPasswordLogic.go new file mode 100644 index 0000000..0fab9cb --- /dev/null +++ b/services/chore/internal/logic/sendPasswordLogic.go @@ -0,0 +1,58 @@ +package logic + +import ( + "context" + "lone-services/pkg/sms" + "lone-services/pkg/utils" + "lone-services/rpc/chore/pb" + "lone-services/services/chore/internal/dao" + "lone-services/services/chore/internal/model" + "lone-services/services/chore/internal/svc" + + "github.com/zeromicro/go-zero/core/logx" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" +) + +type SendPasswordLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + logx.Logger +} + +func NewSendPasswordLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SendPasswordLogic { + return &SendPasswordLogic{ + ctx: ctx, + svcCtx: svcCtx, + Logger: logx.WithContext(ctx), + } +} + +func (l *SendPasswordLogic) SendPassword(in *chore.SendPasswordReq) (*chore.SendPasswordResp, error) { + if l.svcCtx.SMS == nil { + return nil, status.Error(codes.InvalidArgument, "短信服务未配置") + } + + err := l.svcCtx.SMS.SendByKind(in.Mobile, sms.TemplatePassword, map[string]string{"code": in.Password}) + + log := dao.SmsLogCreate{ + Mobile: in.Mobile, + Content: "您的初始密码为:" + in.Password + ",请尽快登录后修改!", + BakContent: err.Error(), + BrowserInfo: in.BrowserInfo, + BrowserName: in.BrowserName, + Ip: in.Ip, + } + sErr := model.SmsLogModel{}.Init().Create(&log) + if sErr != nil { + l.Errorf("sms log create: %v", sErr) + return nil, status.Error(codes.Internal, "短信日志保存失败") + } + + if err != nil { + l.Errorf("sms send: %v", err) + return nil, status.Error(codes.InvalidArgument, "短信发送失败") + } + + return &chore.SendPasswordResp{Code: utils.NumberOne}, nil +} diff --git a/services/chore/internal/model/smsLog.go b/services/chore/internal/model/smsLog.go new file mode 100644 index 0000000..6aa7c6d --- /dev/null +++ b/services/chore/internal/model/smsLog.go @@ -0,0 +1,18 @@ +package model + +import ( + "lone-services/pkg/modelbase" +) + +type SmsLogModel struct { + modelbase.Base +} + +func (m SmsLogModel) TableName() string { + return modelbase.Prefix() + "sms_log" +} + +func (m SmsLogModel) Init() SmsLogModel { + m.Table = m.TableName() + return m +} diff --git a/services/chore/internal/server/choreServer.go b/services/chore/internal/server/choreServer.go index 5a7d6e0..847295e 100644 --- a/services/chore/internal/server/choreServer.go +++ b/services/chore/internal/server/choreServer.go @@ -1,5 +1,5 @@ // Code generated by goctl. DO NOT EDIT. -// goctl 1.10.1 +// goctl 1.10.2 // Source: chore.proto package server @@ -98,3 +98,8 @@ func (s *ChoreServer) RegionsByIds(ctx context.Context, in *chore.RegionsByIdsRe l := logic.NewRegionsByIdsLogic(ctx, s.svcCtx) return l.RegionsByIds(in) } + +func (s *ChoreServer) SendPassword(ctx context.Context, in *chore.SendPasswordReq) (*chore.SendPasswordResp, error) { + l := logic.NewSendPasswordLogic(ctx, s.svcCtx) + return l.SendPassword(in) +} diff --git a/services/sale/run.toml b/services/sale/run.toml new file mode 100644 index 0000000..26ee240 --- /dev/null +++ b/services/sale/run.toml @@ -0,0 +1,57 @@ +[base] + login_out_time=43200 #api接口超时时间分 + login_refresh_out_time=83200 + name = "sale-service" + listenOn = "0.0.0.0:10700" + mode = "dev" +[log] + path = "logs" + serviceName = "sale-service" + mode = "file" + encoding = "plain" + level = "info" + keepDays = 7 + maxSize = 50 + maxBackups = 5 + compress = false + +[oss] + accessKeyId = "LTAI5t7U8KvxSiPE5auwQUuu" + accessKeySecret = "xjfgbQQRpL4TcIspNuClg6bYADa3pk" + roleArn = "acs:ram::1663896742753915:role/oss-upload" + roleSessionName = "oss-upload" + region = "oss-cn-hangzhou" + bucketName = "lone-images" + endpoint = "https://oss-accelerate.aliyuncs.com" + host = "https://images.ailuowan.com" + dir = "upload/" + expireSeconds = 3600 + +[mysql] + host = '39.106.171.204' + port = 33066 + user = 'root' + password = 'MOLXRZNOU4Y4' + database = 'dms-sale' + charset = 'utf8mb4' + prefix = '' + debug = true +[mysql_read] + host = '39.106.171.204' + port = 33066 + user = 'root' + password = 'MOLXRZNOU4Y4' + database = 'dms-sale' + charset = 'utf8mb4' + prefix = '' + +[redis] + host = '39.106.171.204' + password = 'lLMLcuPpzSj' + port = 6379 + db = 0 + +[encrypt] + data_key = "u2t9T3luZtoRfhBstkFN6TiIMW38BA8a" +[services] + chore = "chore-service" \ No newline at end of file diff --git a/services/store/internal/logic/applyEditLogic.go b/services/store/internal/logic/applyEditLogic.go index 606e6d7..f1cd0d1 100644 --- a/services/store/internal/logic/applyEditLogic.go +++ b/services/store/internal/logic/applyEditLogic.go @@ -2,9 +2,10 @@ package logic import ( "context" - + "lone-services/pkg/utils" "lone-services/rpc/store/pb" "lone-services/services/store/internal/svc" + "lone-services/services/store/validator" "github.com/zeromicro/go-zero/core/logx" ) @@ -25,7 +26,27 @@ func NewApplyEditLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ApplyEd } func (l *ApplyEditLogic) ApplyEdit(in *store.ApplyEditRequest) (*store.Response, error) { - // todo: add your logic here and delete this line + var v validator.ApplyEditValidator + if fail := l.checkParams(in, &v); fail != nil { + return fail, nil + } - return &store.Response{}, nil + adminInfo := utils.GetUserFromCtx(l.ctx) + if adminInfo.ID < utils.NumberOne { + return l.fail(utils.ErrorNoLoginInfo) + } + + obj := svc.ApplySvc{} + info, err := obj.GetActionApply(int(adminInfo.ID), int(in.Id)) + if err != utils.Ok { + return l.fail(err) + } + if info.Status == utils.StatusWaitPass || info.Status == utils.StatusDone { + return l.fail(utils.SetError(utils.Fail, "已经申请过")) + } + err = obj.SetActionApply(int(adminInfo.ID), int(in.Id), utils.EditLogTypeStore, in.Reason) + if err != utils.Ok { + return l.fail(err) + } + return l.ok(utils.NumberTen) } diff --git a/services/store/internal/logic/applyVerifyLogic.go b/services/store/internal/logic/applyVerifyLogic.go index 655e93f..9cf4614 100644 --- a/services/store/internal/logic/applyVerifyLogic.go +++ b/services/store/internal/logic/applyVerifyLogic.go @@ -2,10 +2,18 @@ package logic import ( "context" + "lone-services/pkg/modelbase" + "lone-services/pkg/utils" + sale "lone-services/rpc/sale/pb" + "lone-services/services/store/internal/dao" + "lone-services/services/store/internal/model" + "lone-services/services/store/validator" + "strconv" "lone-services/rpc/store/pb" "lone-services/services/store/internal/svc" + "github.com/samber/lo" "github.com/zeromicro/go-zero/core/logx" ) @@ -25,7 +33,100 @@ func NewApplyVerifyLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Apply } func (l *ApplyVerifyLogic) ApplyVerify(in *store.ItemsRequest) (*store.Response, error) { - // todo: add your logic here and delete this line + var v validator.StoreVerifyItemsValidator + if fail := l.checkParams(in, &v); fail != nil { + return fail, nil + } - return &store.Response{}, nil + adminInfo := utils.GetUserFromCtx(l.ctx) + if adminInfo.ID < utils.NumberOne { + return l.fail(utils.ErrorNoLoginInfo) + } + + var info []dao.StoreInfo + w := modelbase.Params{ + Eq: map[string]string{}, + Like: map[string]string{}, + Page: int(v.Page), + Size: int(v.Size), + Order: "id desc", + } + + if v.Status > utils.NumberZero { + w.Eq["status"] = strconv.Itoa(int(v.Status)) + } else { + w.In = map[string][]string{"status": {strconv.Itoa(utils.StatusFail), strconv.Itoa(utils.StatusWaitPass)}} + } + + if v.SaleId > utils.NumberZero { + w.Eq["sale_id"] = strconv.FormatInt(v.SaleId, utils.NumberTen) + } + + if len(v.Name) > utils.NumberZero { + w.Like["name LIKE ? "] = "%%" + v.Name + "%%" + } + + l.SetWhere(&w, adminInfo) + + items, err := model.StoreModel{}.Init().Page(w, &info) + if err != nil { + l.Logger.Error(err) + return l.fail(utils.Fail) + } + var saleIds []int64 + for key, v := range info { + mobile, aErr := utils.DecryptPhone(v.UserMobile) + if aErr == nil { + info[key].UserMobile = mobile + } + + credentials, aErr := utils.Crypto{}.AESDecryptECB(v.BusinessLicense) + if aErr == nil { + info[key].BusinessLicense = credentials + } + idCard, aErr := utils.Crypto{}.AESDecryptECB(v.IdCard) + if aErr == nil { + info[key].IdCard = idCard + } + saleIds = append(saleIds, v.SaleId) + } + newSaleIds := lo.Uniq(saleIds) + if len(newSaleIds) > utils.NumberZero { + salesMap := make(map[int64]string) + if len(newSaleIds) > utils.NumberZero { + sales, err := l.getSaleInfo(saleIds) + if err == utils.Ok { + for _, val := range sales.Items { + salesMap[val.Id] = val.Name + } + } + } + + for key, item := range info { + if s, ok := salesMap[item.SaleId]; ok { + info[key].SaleName = s + } + } + } + + items.Items = info + + return l.ok(items) +} + +func (l *ApplyVerifyLogic) getSaleInfo(ids []int64) (*sale.NamesByIdsData, utils.Status) { + cli, err := svc.GetRpcClient(l.svcCtx.SaleName) + if err != nil { + logx.Errorf("get order err: %v", err) + return &sale.NamesByIdsData{}, utils.ErrorInternalServer + } + + client := sale.NewSaleClient(cli.Conn()) + w := sale.NamesByIdsReq{Ids: ids} + info, err := client.NamesByIds(context.Background(), &w) + if err != nil { + logx.Errorf("get order err: %v", err) + return &sale.NamesByIdsData{}, utils.ErrorInternalServer + } + return info, utils.Ok } diff --git a/services/store/internal/logic/applyVerifyStatusLogic.go b/services/store/internal/logic/applyVerifyStatusLogic.go index 2210f3f..4ffc086 100644 --- a/services/store/internal/logic/applyVerifyStatusLogic.go +++ b/services/store/internal/logic/applyVerifyStatusLogic.go @@ -2,9 +2,18 @@ package logic import ( "context" - + "lone-services/pkg/modelbase" + "lone-services/pkg/utils" + "lone-services/pkg/validate" + order "lone-services/rpc/order/pb" + sale "lone-services/rpc/sale/pb" "lone-services/rpc/store/pb" + user "lone-services/rpc/user/pb" + "lone-services/services/store/internal/dao" + "lone-services/services/store/internal/model" "lone-services/services/store/internal/svc" + "strconv" + "strings" "github.com/zeromicro/go-zero/core/logx" ) @@ -25,7 +34,194 @@ func NewApplyVerifyStatusLogic(ctx context.Context, svcCtx *svc.ServiceContext) } func (l *ApplyVerifyStatusLogic) ApplyVerifyStatus(in *store.StatusRequest) (*store.Response, error) { - // todo: add your logic here and delete this line - return &store.Response{}, nil + var v validate.StatusValidator + if fail := l.checkParams(in, &v); fail != nil { + return fail, nil + } + + adminInfo := utils.GetUserFromCtx(l.ctx) + if adminInfo.ID < utils.NumberOne { + return l.fail(utils.ErrorNoLoginInfo) + } + + var info dao.StoreStatus + w := modelbase.Params{ + In: map[string][]string{"status": { + strconv.Itoa(utils.StatusAdminFirstVerify), + strconv.Itoa(utils.StatusAdminSecondVerify)}}, + Eq: map[string]string{"id": strconv.FormatInt(in.Id, utils.NumberTen)}} + modelObj := model.StoreModel{}.Init() + err := modelObj.GetOne(w, &info) + + if err != nil { + l.Logger.Error(err) + return l.fail(utils.Fail) + } + if info.Status < utils.NumberOne { + return l.fail(utils.ErrorNotFund) + } + action := utils.ActionAdd{ + OldContent: info, + Type: utils.LogActionTypeEdit, + ModuleName: utils.LogActionModuleStore, + } + info.Reason = in.Reason + info.AdminId = adminInfo.ID + info.AdminName = adminInfo.Name + + status := utils.StatusOk + if info.Status == utils.StatusAdminFirstVerify { + status = utils.StatusAdminSecondVerify + } + content := "已通过。" + if in.Status != utils.StatusOk { + status = utils.StatusAdminSecondRefuse + content = "未通过。理由为: " + in.Reason + } + + content = "门店 '" + info.Name + "'审核: " + content + if status != utils.StatusOk { + info.Status = int32(status) + info.AdminId = adminInfo.ID + info.AdminName = adminInfo.Name + info.Reason = in.Reason + _, err = modelObj.Edit(w, &info) + if err != nil { + l.Logger.Error(err) + return l.fail(utils.Fail) + } + + svc.WeCom(in.Status, utils.StoreFirstReview, info.Id, info.Reason) + action.NewContent = info + utils.SetActionLog(adminInfo, action) + return l.ok(utils.NumberOne) + } + + modelObj.Begin() + if status == utils.StatusOk { + var newData dao.StoreNewCreate + if utils.JsonStringToStruct(info.NewContent, &newData) { + newData.Status = int32(status) + newData.NewContent = utils.StringEmpty + newData.Id = info.Id + groupId, sErr := l.getSaleInfo(newData.SaleId) + if sErr != utils.Ok { + modelObj.Rollback() + return l.fail(sErr) + } + if groupId < utils.NumberOne { + modelObj.Rollback() + return l.fail(utils.ErrorNotFund) + } + + newData.GroupId = groupId + + _, err = modelObj.Edit(w, &newData) + if err != nil { + modelObj.Rollback() + l.Logger.Error(err) + return l.fail(utils.Fail) + } + + if newData.SaleId != info.SaleId { + sErr = l.setAddressSaleInfo(newData) + if sErr != utils.Ok { + modelObj.Rollback() + return l.fail(sErr) + } + } + + if newData.UserMobile != info.UserMobile && newData.UserName != info.UserName { + uErr := l.updateUser(newData) + if uErr != utils.Ok { + modelObj.Rollback() + return l.fail(uErr) + } + } + } else { + modelObj.Rollback() + return l.fail(utils.ErrorFormatDataError) + } + } + + reason := utils.StringEmpty + if in.Reason != utils.StringEmpty { + reason = in.Reason + } + svc.WeCom(in.Status, utils.StoreSecondReview, info.Id, reason) + + modelObj.Commit() + action.NewContent = info + utils.SetActionLog(adminInfo, action) + return l.ok(utils.NumberOne) +} + +func (l *ApplyVerifyStatusLogic) getSaleInfo(id int64) (int64, utils.Status) { + cli, err := svc.GetRpcClient(l.svcCtx.SaleName) + if err != nil { + logx.Errorf("get order err: %v", err) + return utils.NumberZero, utils.ErrorInternalServer + } + + client := sale.NewSaleClient(cli.Conn()) + w := sale.InfoReq{Id: id} + info, err := client.InfoInternal(context.Background(), &w) + if err != nil { + logx.Errorf("get order err: %v", err) + return utils.NumberZero, utils.ErrorInternalServer + } + return info.GroupId, utils.Ok +} + +func (l *ApplyVerifyStatusLogic) setAddressSaleInfo(info dao.StoreNewCreate) utils.Status { + cli, err := svc.GetRpcClient(l.svcCtx.OrderName) + if err != nil { + logx.Errorf("get address err: %v", err) + return utils.ErrorInternalServer + } + + client := order.NewOrderClient(cli.Conn()) + data := order.UpdateAddressSaleInfoRequest{ + Id: info.Id, + SaleId: info.SaleId, + GroupId: info.GroupId, + } + _, err = client.UpdateAddressSaleInfo(context.Background(), &data) + if err != nil { + logx.Errorf("get address err: %v", err) + return utils.ErrorInternalServer + } + return utils.Ok +} + +func (l *ApplyVerifyStatusLogic) updateUser(info dao.StoreNewCreate) utils.Status { + cli, err := svc.GetRpcClient(l.svcCtx.OrderName) + if err != nil { + logx.Errorf("get user err: %v", err) + return utils.ErrorInternalServer + } + + client := user.NewUserClient(cli.Conn()) + + mobile, sErr := utils.EncryptPhone(info.UserMobile) + if sErr != nil { + return utils.ErrorEncryptAesError + } + data := user.InternalUpdateReq{ + BizId: info.Id, + SubjectType: dao.UserTypeName, + Mobile: mobile, + Name: info.UserName, + ClientCode: strings.Split(info.StoreType, utils.DecollatorComma), //哪端 + CredentialType: []string{dao.LoginTypePassword, dao.LoginTypeSms}, + Identifier: mobile, //手机号 + } + _, err = client.InternalUpdate(context.Background(), &data) + if err != nil { + logx.Errorf("get order err: %v", err) + return utils.ErrorInternalServer + } + + return utils.Ok } diff --git a/services/store/internal/logic/createLogic.go b/services/store/internal/logic/createLogic.go index 54f3193..74d925a 100644 --- a/services/store/internal/logic/createLogic.go +++ b/services/store/internal/logic/createLogic.go @@ -5,9 +5,12 @@ import ( "lone-services/pkg/utils" sale "lone-services/rpc/sale/pb" "lone-services/rpc/store/pb" + user "lone-services/rpc/user/pb" "lone-services/services/store/internal/dao" "lone-services/services/store/internal/model" "lone-services/services/store/internal/svc" + "lone-services/services/store/validator" + "strings" "github.com/zeromicro/go-zero/core/logx" ) @@ -28,12 +31,20 @@ func NewCreateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateLogi } func (l *CreateLogic) Create(in *store.CreateRequest) (*store.Response, error) { + var v validator.StoreCreateValidator + if fail := l.checkParams(in, &v); fail != nil { + return fail, nil + } + adminInfo := utils.GetUserFromCtx(l.ctx) if adminInfo.ID < utils.NumberOne { return l.fail(utils.ErrorNoLoginInfo) } - //TODO 调用用户接口-判断是否可以注册 + uErr := l.checkUser(in.UserMobile) + if uErr != utils.Ok { + return l.fail(uErr) + } encryptMobile, cErr := utils.EncryptPhone(in.UserMobile) if cErr != nil { @@ -60,6 +71,7 @@ func (l *CreateLogic) Create(in *store.CreateRequest) (*store.Response, error) { Status: utils.StatusOk, SaleId: in.SaleId, SourceType: model.StoreTypeAdmin, + StoreType: strings.Join(in.StoreType, utils.DecollatorComma), Images: in.Images, Contact: in.Contact, Content: in.Content, @@ -93,20 +105,10 @@ func (l *CreateLogic) Create(in *store.CreateRequest) (*store.Response, error) { data.GroupId = groupId - //TODO 调用用户更新接口-更新手机号 - //err = models.StoreModel{}.Init().Create(&data) - //if err != nil { - // l.Logger.Error(err) - // return l.fail(utils.Fail) - //} - - //TODO 发送短信 - //result := utils.SendPwdSMS(in.UserMobile, in.Password) - //jsonStr, err := json.Marshal(result) - //SmsLogService{}.Add(c, in.UserMobile, "您的初始密码为:"+in.Password+",请尽快登录后修改!", string(jsonStr)) - //if result.Code != dao.NumberZero { - // return check.Id, utils.Fail - //} + uErr = l.updateUser(data) + if uErr != utils.Ok { + return l.fail(uErr) + } return l.ok(utils.NumberOne) } @@ -127,3 +129,55 @@ func (l *CreateLogic) getSaleInfo(id int64) (int64, utils.Status) { } return info.GroupId, utils.Ok } + +func (l *CreateLogic) updateUser(info dao.StoreCreate) utils.Status { + cli, err := svc.GetRpcClient(l.svcCtx.OrderName) + if err != nil { + logx.Errorf("get user err: %v", err) + return utils.ErrorInternalServer + } + + client := user.NewUserClient(cli.Conn()) + + mobile, sErr := utils.EncryptPhone(info.UserMobile) + if sErr != nil { + return utils.ErrorEncryptAesError + } + data := user.InternalUpdateReq{ + BizId: info.Id, + SubjectType: dao.UserTypeName, + Mobile: mobile, + Name: info.UserName, + ClientCode: strings.Split(info.StoreType, utils.DecollatorComma), //哪端 + CredentialType: []string{dao.LoginTypePassword, dao.LoginTypeSms}, + Identifier: mobile, //手机号 + } + _, err = client.InternalUpdate(context.Background(), &data) + if err != nil { + logx.Errorf("get order err: %v", err) + return utils.ErrorInternalServer + } + + return utils.Ok +} + +func (l *CreateLogic) checkUser(mobile string) utils.Status { + cli, err := svc.GetRpcClient(l.svcCtx.OrderName) + if err != nil { + logx.Errorf("get user err: %v", err) + return utils.ErrorInternalServer + } + + client := user.NewUserClient(cli.Conn()) + + data := user.InternalCheckCreateReq{ + Mobile: mobile, + } + _, err = client.InternalCheckCreate(context.Background(), &data) + if err != nil { + logx.Errorf("get order err: %v", err) + return utils.ErrorInternalServer + } + + return utils.Ok +} diff --git a/services/store/internal/logic/depositBackfillLogic.go b/services/store/internal/logic/depositBackfillLogic.go index 4d5f75d..c9bf559 100644 --- a/services/store/internal/logic/depositBackfillLogic.go +++ b/services/store/internal/logic/depositBackfillLogic.go @@ -2,6 +2,12 @@ package logic import ( "context" + "lone-services/pkg/modelbase" + "lone-services/pkg/utils" + "lone-services/services/store/internal/dao" + "lone-services/services/store/internal/model" + "lone-services/services/store/validator" + "strconv" "lone-services/rpc/store/pb" "lone-services/services/store/internal/svc" @@ -25,7 +31,53 @@ func NewDepositBackfillLogic(ctx context.Context, svcCtx *svc.ServiceContext) *D } func (l *DepositBackfillLogic) DepositBackfill(in *store.DepositBackfillRequest) (*store.Response, error) { - // todo: add your logic here and delete this line + var v validator.DepositBackfillValidator + if fail := l.checkParams(in, &v); fail != nil { + return fail, nil + } + adminInfo := utils.GetUserFromCtx(l.ctx) + if adminInfo.ID < utils.NumberOne { + return l.fail(utils.ErrorNoLoginInfo) + } - return &store.Response{}, nil + var info dao.DepositStatus + + w := modelbase.Params{Eq: map[string]string{ + "id": strconv.FormatInt(in.Id, utils.NumberTen), + "status": strconv.Itoa(utils.StatusWaitPass)}} + modelObj := model.DepositModel{}.Init() + err := modelObj.GetOne(w, &info) + if err != nil { + l.Logger.Error(err) + return l.fail(utils.Fail) + } + if info.Id < utils.NumberOne { + return l.fail(utils.ErrorNotFund) + } + + action := utils.ActionAdd{ + OldContent: info, + Type: utils.LogActionTypeEdit, + ModuleName: utils.LogActionModuleStore, + } + + info.Status = utils.StatusBackfill + info.AccountantId = adminInfo.ID + info.AccountantName = adminInfo.Name + info.AffirmAmount = info.Amount + if in.Amount > utils.NumberZero { + info.AffirmAmount = in.Amount + } + + row, err := modelObj.Edit(w, &info) + if err != nil { + l.Logger.Error(err) + return l.fail(utils.Fail) + } + + if row > utils.NumberZero { + action.NewContent = info + utils.SetActionLog(adminInfo, action) + } + return l.ok(utils.NumberOne) } diff --git a/services/store/internal/logic/depositDoneLogic.go b/services/store/internal/logic/depositDoneLogic.go index 635d419..7f88a8b 100644 --- a/services/store/internal/logic/depositDoneLogic.go +++ b/services/store/internal/logic/depositDoneLogic.go @@ -2,6 +2,12 @@ package logic import ( "context" + "lone-services/pkg/modelbase" + "lone-services/pkg/utils" + "lone-services/services/store/internal/dao" + "lone-services/services/store/internal/model" + "lone-services/services/store/validator" + "strconv" "lone-services/rpc/store/pb" "lone-services/services/store/internal/svc" @@ -25,7 +31,68 @@ func NewDepositDoneLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Depos } func (l *DepositDoneLogic) DepositDone(in *store.IdRequest) (*store.Response, error) { - // todo: add your logic here and delete this line + var v validator.DepositDoneValidator + if fail := l.checkParams(in, &v); fail != nil { + return fail, nil + } + adminInfo := utils.GetUserFromCtx(l.ctx) + if adminInfo.ID < utils.NumberOne { + return l.fail(utils.ErrorNoLoginInfo) + } - return &store.Response{}, nil + var info dao.DepositStatus + + w := modelbase.Params{Eq: map[string]string{ + "id": strconv.FormatInt(in.Id, utils.NumberTen), + "status": strconv.Itoa(utils.StatusBackfill)}} + modelObj := model.DepositModel{}.Init() + err := modelObj.GetOne(w, &info) + if err != nil { + l.Logger.Error(err) + return l.fail(utils.Fail) + } + if info.Id < utils.NumberOne { + return l.fail(utils.ErrorNotFund) + } + + action := utils.ActionAdd{ + OldContent: info, + Type: utils.LogActionTypeEdit, + ModuleName: utils.LogActionModuleStore, + } + + info.Status = utils.StatusOk + info.AdminId = adminInfo.ID + info.AdminName = adminInfo.Name + + modelObj.Begin() + _, err = modelObj.Edit(w, &info) + if err != nil { + modelObj.Rollback() + l.Logger.Error(err) + return l.fail(utils.Fail) + } + w = modelbase.Params{Eq: map[string]string{"id": strconv.Itoa(int(info.StoreId))}} + var store dao.StoreDeposit + err = model.StoreModel{}.Init().GetOne(w, &store) + if err != nil { + modelObj.Rollback() + l.Logger.Error(err) + return l.fail(utils.Fail) + } + store.Amount = store.Amount + info.AffirmAmount + row, err := model.StoreModel{}.Init().Edit(w, &store) + if err != nil { + modelObj.Rollback() + l.Logger.Error(err) + return l.fail(utils.Fail) + } + + modelObj.Commit() + if row > utils.NumberZero { + action.NewContent = info + utils.SetActionLog(adminInfo, action) + } + + return l.ok(utils.NumberOne) } diff --git a/services/store/internal/logic/depositDownLogic.go b/services/store/internal/logic/depositDownLogic.go index 064d926..d6be910 100644 --- a/services/store/internal/logic/depositDownLogic.go +++ b/services/store/internal/logic/depositDownLogic.go @@ -2,9 +2,14 @@ package logic import ( "context" - + "lone-services/pkg/modelbase" + "lone-services/pkg/utils" "lone-services/rpc/store/pb" + "lone-services/services/store/internal/dao" + "lone-services/services/store/internal/model" "lone-services/services/store/internal/svc" + "lone-services/services/store/validator" + "strconv" "github.com/zeromicro/go-zero/core/logx" ) @@ -24,8 +29,103 @@ func NewDepositDownLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Depos } } -func (l *DepositDownLogic) DepositDown(in *store.DepositItemsRequest) (*store.Response, error) { - // todo: add your logic here and delete this line +func (l *DepositDownLogic) DepositDown(in *store.DepositItemsRequest) (*store.ExcelExportResponse, error) { + var v validator.DepositItemsValidator + res := &store.ExcelExportResponse{} + if fail := l.checkParams(in, &v); fail != nil { + res.Msg = fail.Msg + return res, nil + } + adminInfo := utils.GetUserFromCtx(l.ctx) - return &store.Response{}, nil + if adminInfo.ID < utils.NumberOne { + res.Msg = utils.ErrorNoLoginInfo.Msg + return res, nil + } + + var info []dao.DepositDown + w := modelbase.Params{ + Page: int(in.Page), + Size: int(in.Size), + Order: "id desc", + } + + w.Eq = make(map[string]string) + + storeMap := make(map[int64]string) + if len(v.Name) > utils.NumberZero { + ww := modelbase.Params{Like: map[string]string{"name LIKE ? ": "%%" + v.Name + "%%"}} + var storeItems []dao.StoreNames + err := model.StoreModel{}.Init().Items(ww, &storeItems) + if err != nil { + l.Logger.Error(err) + res.Msg = utils.Fail.Msg + return res, nil + } + + var ids []string + for _, item := range storeItems { + ids = append(ids, strconv.Itoa(int(item.Id))) + storeMap[item.Id] = item.Name + } + if len(ids) < utils.NumberOne { + res.Msg = utils.ErrorNotFund.Msg + return res, nil + } + + w.In = map[string][]string{"store_id": ids} + } + if v.Status > utils.NumberZero { + w.Eq["status"] = strconv.Itoa(int(v.Status)) + } + err := model.DepositModel{}.Init().Items(w, &info) + if err != nil { + l.Logger.Error(err) + res.Msg = utils.Fail.Msg + return res, nil + } + + if len(storeMap) < utils.NumberOne { + var storeIds []string + for _, values := range info { + storeIds = append(storeIds, strconv.Itoa(int(values.StoreId))) + } + ww := modelbase.Params{In: map[string][]string{"id": storeIds}} + var storeItems []dao.StoreNames + err = model.StoreModel{}.Init().Items(ww, &storeItems) + if err != nil { + l.Logger.Error(err) + res.Msg = utils.Fail.Msg + return res, nil + } + + for _, item := range storeItems { + storeMap[item.Id] = item.Name + } + } + + for key, val := range info { + if name, ok := storeMap[val.StoreId]; ok { + info[key].StoreName = name + } + } + + // 2. 配置导出列:表头 ↔ 结构体字段 + columns := []utils.ExcelColumn{ + {Header: "ID", Field: "Id"}, + {Header: "票据", Field: "Bill"}, + {Header: "金额", Field: "Amount"}, + {Header: "门店名", Field: "StoreName"}, + {Header: "汇款时间", Field: "CreateTime"}, + } + + res.Name = "核对列表" + // 3. 一行导出 + data, err := utils.ExcelExport(columns, info) + if err != nil { + res.Msg = err.Error() + return res, nil + } + res.Data = data + return res, nil } diff --git a/services/store/internal/logic/depositIgnoreItemsLogic.go b/services/store/internal/logic/depositIgnoreItemsLogic.go index beb2284..05322f4 100644 --- a/services/store/internal/logic/depositIgnoreItemsLogic.go +++ b/services/store/internal/logic/depositIgnoreItemsLogic.go @@ -2,9 +2,13 @@ package logic import ( "context" - + "lone-services/pkg/modelbase" + "lone-services/pkg/utils" "lone-services/rpc/store/pb" + "lone-services/services/store/internal/dao" + "lone-services/services/store/internal/model" "lone-services/services/store/internal/svc" + "strconv" "github.com/zeromicro/go-zero/core/logx" ) @@ -25,7 +29,50 @@ func NewDepositIgnoreItemsLogic(ctx context.Context, svcCtx *svc.ServiceContext) } func (l *DepositIgnoreItemsLogic) DepositIgnoreItems(in *store.DepositVerifyRequest) (*store.Response, error) { - // todo: add your logic here and delete this line + adminInfo := utils.GetUserFromCtx(l.ctx) + if adminInfo.ID < utils.NumberOne { + return l.fail(utils.ErrorNoLoginInfo) + } - return &store.Response{}, nil + var info []dao.DepositInfo + w := modelbase.Params{ + Eq: map[string]string{"status": strconv.Itoa(utils.StatusNotPass)}, + Page: int(in.Page), + Size: int(in.Size), + Order: "id desc", + } + + storeMap := make(map[int64]string) + items, err := model.DepositModel{}.Init().Page(w, &info) + if err != nil { + l.Logger.Error(err) + return l.fail(utils.Fail) + } + + if len(storeMap) < utils.NumberOne { + var storeIds []string + for _, values := range info { + storeIds = append(storeIds, strconv.Itoa(int(values.StoreId))) + } + ww := modelbase.Params{In: map[string][]string{"id": storeIds}} + var storeItems []dao.StoreNames + err := model.StoreModel{}.Init().Items(ww, &storeItems) + if err != nil { + l.Logger.Error(err) + return l.fail(utils.Fail) + } + + for _, item := range storeItems { + storeMap[item.Id] = item.Name + } + } + + for key, val := range info { + if name, ok := storeMap[val.StoreId]; ok { + info[key].StoreName = name + } + } + + items.Items = info + return l.ok(items) } diff --git a/services/store/internal/logic/depositIgnoreLogic.go b/services/store/internal/logic/depositIgnoreLogic.go index e4442ee..65e7b7e 100644 --- a/services/store/internal/logic/depositIgnoreLogic.go +++ b/services/store/internal/logic/depositIgnoreLogic.go @@ -2,6 +2,12 @@ package logic import ( "context" + "lone-services/pkg/modelbase" + "lone-services/pkg/utils" + "lone-services/services/store/internal/dao" + "lone-services/services/store/internal/model" + "lone-services/services/store/validator" + "strconv" "lone-services/rpc/store/pb" "lone-services/services/store/internal/svc" @@ -25,7 +31,48 @@ func NewDepositIgnoreLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Dep } func (l *DepositIgnoreLogic) DepositIgnore(in *store.DepositIgnoreRequest) (*store.Response, error) { - // todo: add your logic here and delete this line + var v validator.DepositIgnoreValidator + if fail := l.checkParams(in, &v); fail != nil { + return fail, nil + } + adminInfo := utils.GetUserFromCtx(l.ctx) + if adminInfo.ID < utils.NumberOne { + return l.fail(utils.ErrorNoLoginInfo) + } + + var info dao.DepositStatus + + w := modelbase.Params{Eq: map[string]string{ + "id": strconv.FormatInt(in.Id, utils.NumberTen), + "status": strconv.Itoa(utils.StatusWaitPass)}} + modelObj := model.DepositModel{}.Init() + err := modelObj.GetOne(w, &info) + if err != nil { + l.Logger.Error(err) + return l.fail(utils.Fail) + } + if info.Id < utils.NumberOne { + return l.fail(utils.ErrorNotFund) + } + action := utils.ActionAdd{ + OldContent: info, + Type: utils.LogActionTypeEdit, + ModuleName: utils.LogActionModuleStore, + } + + info.Status = utils.StatusNotPass + info.Reason = v.Reason + + row, err := modelObj.Edit(w, &info) + if err != nil { + l.Logger.Error(err) + return l.fail(utils.Fail) + } + if row > utils.NumberZero { + action.NewContent = info + utils.SetActionLog(adminInfo, action) + } + + return l.ok(utils.NumberOne) - return &store.Response{}, nil } diff --git a/services/store/internal/logic/depositItemsLogic.go b/services/store/internal/logic/depositItemsLogic.go index c6beeee..6a250a2 100644 --- a/services/store/internal/logic/depositItemsLogic.go +++ b/services/store/internal/logic/depositItemsLogic.go @@ -2,6 +2,12 @@ package logic import ( "context" + "lone-services/pkg/modelbase" + "lone-services/pkg/utils" + "lone-services/services/store/internal/dao" + "lone-services/services/store/internal/model" + "lone-services/services/store/validator" + "strconv" "lone-services/rpc/store/pb" "lone-services/services/store/internal/svc" @@ -25,7 +31,78 @@ func NewDepositItemsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Depo } func (l *DepositItemsLogic) DepositItems(in *store.DepositItemsRequest) (*store.Response, error) { - // todo: add your logic here and delete this line + var v validator.DepositItemsValidator + if fail := l.checkParams(in, &v); fail != nil { + return fail, nil + } + adminInfo := utils.GetUserFromCtx(l.ctx) + if adminInfo.ID < utils.NumberOne { + return l.fail(utils.ErrorNoLoginInfo) + } - return &store.Response{}, nil + var info []dao.DepositInfo + w := modelbase.Params{ + Page: int(in.Page), + Size: int(in.Size), + Order: "id desc", + } + + w.Eq = make(map[string]string) + + storeMap := make(map[int64]string) + if len(v.Name) > utils.NumberZero { + ww := modelbase.Params{Like: map[string]string{"name LIKE ? ": "%%" + v.Name + "%%"}} + var storeItems []dao.StoreNames + err := model.StoreModel{}.Init().Items(ww, &storeItems) + if err != nil { + l.Logger.Error(err) + return l.fail(utils.Fail) + } + + var ids []string + for _, item := range storeItems { + ids = append(ids, strconv.Itoa(int(item.Id))) + storeMap[item.Id] = item.Name + } + if len(ids) < utils.NumberOne { + return l.fail(utils.ErrorNotFund) + } + + w.In = map[string][]string{"store_id": ids} + } + if v.Status > utils.NumberZero { + w.Eq["status"] = strconv.Itoa(int(v.Status)) + } + items, err := model.DepositModel{}.Init().Page(w, &info) + if err != nil { + l.Logger.Error(err) + return l.fail(utils.Fail) + } + + if len(storeMap) < utils.NumberOne { + var storeIds []string + for _, values := range info { + storeIds = append(storeIds, strconv.Itoa(int(values.StoreId))) + } + ww := modelbase.Params{In: map[string][]string{"id": storeIds}} + var storeItems []dao.StoreNames + err = model.StoreModel{}.Init().Items(ww, &storeItems) + if err != nil { + l.Logger.Error(err) + return l.fail(utils.Fail) + } + + for _, item := range storeItems { + storeMap[item.Id] = item.Name + } + } + + for key, val := range info { + if name, ok := storeMap[val.StoreId]; ok { + info[key].StoreName = name + } + } + items.Items = info + + return l.ok(items) } diff --git a/services/store/internal/logic/depositRecoverLogic.go b/services/store/internal/logic/depositRecoverLogic.go index 9c3baf2..7f7947f 100644 --- a/services/store/internal/logic/depositRecoverLogic.go +++ b/services/store/internal/logic/depositRecoverLogic.go @@ -2,9 +2,14 @@ package logic import ( "context" - + "lone-services/pkg/modelbase" + "lone-services/pkg/utils" + "lone-services/pkg/validate" "lone-services/rpc/store/pb" + "lone-services/services/store/internal/dao" + "lone-services/services/store/internal/model" "lone-services/services/store/internal/svc" + "strconv" "github.com/zeromicro/go-zero/core/logx" ) @@ -25,7 +30,46 @@ func NewDepositRecoverLogic(ctx context.Context, svcCtx *svc.ServiceContext) *De } func (l *DepositRecoverLogic) DepositRecover(in *store.IdRequest) (*store.Response, error) { - // todo: add your logic here and delete this line + var v validate.InfoValidator + if fail := l.checkParams(in, &v); fail != nil { + return fail, nil + } + adminInfo := utils.GetUserFromCtx(l.ctx) + if adminInfo.ID < utils.NumberOne { + return l.fail(utils.ErrorNoLoginInfo) + } - return &store.Response{}, nil + var info dao.DepositStatus + + w := modelbase.Params{Eq: map[string]string{"id": strconv.FormatInt(in.Id, utils.NumberTen)}, + In: map[string][]string{"status": {strconv.Itoa(utils.StatusNotPass), strconv.Itoa(utils.StatusBackfill)}}} + modelObj := model.DepositModel{}.Init() + err := modelObj.GetOne(w, &info) + if err != nil { + l.Logger.Error(err) + return l.fail(utils.Fail) + } + if info.Id < utils.NumberOne { + return l.fail(utils.ErrorNotFund) + } + + action := utils.ActionAdd{ + OldContent: info, + Type: utils.LogActionTypeEdit, + ModuleName: utils.LogActionModuleStore, + } + + info.Status = utils.StatusWaitPass + info.Reason = utils.StringEmpty + row, err := modelObj.Edit(w, &info) + if err != nil { + l.Logger.Error(err) + return l.fail(utils.Fail) + } + if row > utils.NumberZero { + action.NewContent = info + utils.SetActionLog(adminInfo, action) + } + + return l.ok(utils.NumberOne) } diff --git a/services/store/internal/logic/depositVerifyLogic.go b/services/store/internal/logic/depositVerifyLogic.go index a9e229c..62d0876 100644 --- a/services/store/internal/logic/depositVerifyLogic.go +++ b/services/store/internal/logic/depositVerifyLogic.go @@ -2,6 +2,12 @@ package logic import ( "context" + "lone-services/pkg/modelbase" + "lone-services/pkg/utils" + "lone-services/services/store/internal/dao" + "lone-services/services/store/internal/model" + "lone-services/services/store/validator" + "strconv" "lone-services/rpc/store/pb" "lone-services/services/store/internal/svc" @@ -25,7 +31,74 @@ func NewDepositVerifyLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Dep } func (l *DepositVerifyLogic) DepositVerify(in *store.DepositVerifyRequest) (*store.Response, error) { - // todo: add your logic here and delete this line + var v validator.DepositVerifyItemsValidator + if fail := l.checkParams(in, &v); fail != nil { + return fail, nil + } + adminInfo := utils.GetUserFromCtx(l.ctx) + if adminInfo.ID < utils.NumberOne { + return l.fail(utils.ErrorNoLoginInfo) + } - return &store.Response{}, nil + var info []dao.DepositInfo + w := modelbase.Params{ + Eq: map[string]string{"status": strconv.Itoa(utils.StatusWaitPass)}, + Page: int(in.Page), + Size: int(in.Size), + Order: "id desc", + } + + storeMap := make(map[int64]string) + if len(v.Name) > utils.NumberZero { + ww := modelbase.Params{Like: map[string]string{"name LIKE ? ": "%%" + v.Name + "%%"}} + var storeItems []dao.StoreNames + err := model.StoreModel{}.Init().Items(ww, &storeItems) + if err != nil { + l.Logger.Error(err) + return l.fail(utils.Fail) + } + + var ids []string + for _, item := range storeItems { + ids = append(ids, strconv.Itoa(int(item.Id))) + storeMap[item.Id] = item.Name + } + if len(ids) < utils.NumberOne { + return l.fail(utils.ErrorNotFund) + } + + w.In = map[string][]string{"store_id": ids} + } + items, err := model.DepositModel{}.Init().Page(w, &info) + if err != nil { + l.Logger.Error(err) + return l.fail(utils.Fail) + } + + if len(storeMap) < utils.NumberOne { + var storeIds []string + for _, values := range info { + storeIds = append(storeIds, strconv.Itoa(int(values.StoreId))) + } + ww := modelbase.Params{In: map[string][]string{"id": storeIds}} + var storeItems []dao.StoreNames + err = model.StoreModel{}.Init().Items(ww, &storeItems) + if err != nil { + l.Logger.Error(err) + return l.fail(utils.Fail) + } + + for _, item := range storeItems { + storeMap[item.Id] = item.Name + } + } + + for key, val := range info { + if name, ok := storeMap[val.StoreId]; ok { + info[key].StoreName = name + } + } + + items.Items = info + return l.ok(items) } diff --git a/services/store/internal/logic/editLogic.go b/services/store/internal/logic/editLogic.go index 18001ea..cefff7e 100644 --- a/services/store/internal/logic/editLogic.go +++ b/services/store/internal/logic/editLogic.go @@ -5,10 +5,13 @@ import ( "lone-services/pkg/modelbase" "lone-services/pkg/utils" "lone-services/rpc/store/pb" + user "lone-services/rpc/user/pb" "lone-services/services/store/internal/dao" "lone-services/services/store/internal/model" "lone-services/services/store/internal/svc" + "lone-services/services/store/validator" "strconv" + "strings" "github.com/zeromicro/go-zero/core/logx" ) @@ -29,6 +32,11 @@ func NewEditLogic(ctx context.Context, svcCtx *svc.ServiceContext) *EditLogic { } func (l *EditLogic) Edit(in *store.EditRequest) (*store.Response, error) { + var v validator.StoreEditValidator + if fail := l.checkParams(in, &v); fail != nil { + return fail, nil + } + adminInfo := utils.GetUserFromCtx(l.ctx) if adminInfo.ID < utils.NumberOne { return l.fail(utils.ErrorNoLoginInfo) @@ -55,14 +63,15 @@ func (l *EditLogic) Edit(in *store.EditRequest) (*store.Response, error) { } oldMobile, cErr := utils.DecryptPhone(info.UserMobile) + var oldMobile2 string if cErr == nil { - oldMobile = utils.DecryptPhoneReplace(oldMobile) + oldMobile2 = utils.DecryptPhoneReplace(oldMobile) } encryptMobile, cErr := utils.EncryptPhone(in.UserMobile) if cErr != nil { return l.fail(utils.SetError(utils.Fail, cErr.GetMsg())) } - if oldMobile != in.UserMobile { + if oldMobile != in.UserMobile && oldMobile2 != in.UserMobile { var check dao.StoreStatus ww := modelbase.Params{Eq: map[string]string{"user_mobile": encryptMobile}} err = modelObj.GetOne(ww, &check) @@ -76,8 +85,10 @@ func (l *EditLogic) Edit(in *store.EditRequest) (*store.Response, error) { } } - //TODO 调用用户接口-判断是否可以修改 - //TODO 调用用户更新接口-更新手机号 + uErr := l.checkUser(in.UserMobile, in.Id) + if uErr != utils.Ok { + return l.fail(uErr) + } if in.BusinessLicense != info.BusinessLicense { encryptData, cErr := utils.Crypto{}.AESEncryptECB(in.BusinessLicense) @@ -111,6 +122,8 @@ func (l *EditLogic) Edit(in *store.EditRequest) (*store.Response, error) { info.LongitudeGcj02 = in.LongitudeGcj02 info.LatitudeGcj02 = in.LatitudeGcj02 info.StoreImages = in.StoreImages + info.StoreType = strings.Join(in.StoreType, utils.DecollatorComma) + info.Area = in.Area info.Receipt = in.Receipt info.Type = in.Type @@ -121,9 +134,17 @@ func (l *EditLogic) Edit(in *store.EditRequest) (*store.Response, error) { info.County = in.County info.CountyName = in.CountyName - if oldMobile != in.UserMobile && encryptMobile != info.UserMobile { + if oldMobile != in.UserMobile && oldMobile2 != in.UserMobile { info.UserMobile = encryptMobile } + + if (oldMobile != in.UserMobile && oldMobile2 != in.UserMobile) || in.UserName != info.UserName { + uErr = l.updateUser(info) + if uErr != utils.Ok { + return l.fail(uErr) + } + } + w = modelbase.Params{Eq: map[string]string{"id": strconv.FormatInt(in.Id, utils.NumberTen)}} edit := dao.StoreNewContent{ NewContent: utils.StructToJson(info), @@ -139,3 +160,57 @@ func (l *EditLogic) Edit(in *store.EditRequest) (*store.Response, error) { } return l.ok(utils.NumberOne) } + +func (l *EditLogic) updateUser(info dao.StoreCreate) utils.Status { + cli, err := svc.GetRpcClient(l.svcCtx.OrderName) + if err != nil { + logx.Errorf("get user err: %v", err) + return utils.ErrorInternalServer + } + + client := user.NewUserClient(cli.Conn()) + + mobile, sErr := utils.EncryptPhone(info.UserMobile) + if sErr != nil { + return utils.ErrorEncryptAesError + } + data := user.InternalUpdateReq{ + BizId: info.Id, + SubjectType: dao.UserTypeName, + Mobile: mobile, + Name: info.UserName, + ClientCode: strings.Split(info.StoreType, utils.DecollatorComma), //哪端 + CredentialType: []string{dao.LoginTypePassword, dao.LoginTypeSms}, + Identifier: mobile, //手机号 + } + _, err = client.InternalUpdate(context.Background(), &data) + if err != nil { + logx.Errorf("get order err: %v", err) + return utils.ErrorInternalServer + } + + return utils.Ok +} + +func (l *EditLogic) checkUser(mobile string, id int64) utils.Status { + cli, err := svc.GetRpcClient(l.svcCtx.OrderName) + if err != nil { + logx.Errorf("get user err: %v", err) + return utils.ErrorInternalServer + } + + client := user.NewUserClient(cli.Conn()) + + data := user.InternalCheckUpdateReq{ + Mobile: mobile, + SubjectType: dao.UserTypeName, + BizId: id, + } + _, err = client.InternalCheckUpdate(context.Background(), &data) + if err != nil { + logx.Errorf("get order err: %v", err) + return utils.ErrorInternalServer + } + + return utils.Ok +} diff --git a/services/store/internal/logic/getInfoByIdLogic.go b/services/store/internal/logic/getInfoByIdLogic.go new file mode 100644 index 0000000..2f0a188 --- /dev/null +++ b/services/store/internal/logic/getInfoByIdLogic.go @@ -0,0 +1,72 @@ +package logic + +import ( + "context" + "lone-services/pkg/modelbase" + "lone-services/pkg/utils" + "lone-services/services/store/internal/dao" + "lone-services/services/store/internal/model" + "strconv" + + "lone-services/rpc/store/pb" + "lone-services/services/store/internal/svc" + + "github.com/zeromicro/go-zero/core/logx" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" +) + +type GetInfoByIdLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + logx.Logger +} + +func NewGetInfoByIdLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetInfoByIdLogic { + return &GetInfoByIdLogic{ + ctx: ctx, + svcCtx: svcCtx, + Logger: logx.WithContext(ctx), + } +} + +func (l *GetInfoByIdLogic) GetInfoById(in *store.IdRequest) (*store.InfoResponse, error) { + var info dao.StoreInfo + modelObj := model.StoreModel{}.Init() + w := modelbase.Params{Eq: map[string]string{"id": strconv.FormatInt(in.Id, utils.NumberTen)}} + err := modelObj.GetOne(w, &info) + if err != nil { + l.Logger.Error(err) + return nil, status.Error(codes.Internal, utils.Fail.Msg) + } + + if info.Id < utils.NumberOne { + return nil, status.Error(codes.Internal, utils.ErrorNotFund.Msg) + } + + if info.Id > utils.NumberZero { + mobile, dErr := utils.DecryptPhone(info.UserMobile) + if dErr == nil { + return nil, status.Error(codes.Internal, utils.ErrorEncryptAesError.Msg) + } + info.UserMobile = mobile + } + + return &store.InfoResponse{ + Id: info.Id, + Name: info.Name, + Contact: info.Contact, + UserMobile: info.UserMobile, + IdCard: info.IdCard, + BusinessLicense: info.BusinessLicense, + Images: info.Images, + Content: info.Content, + OpenTime: info.OpenTime, + Address: info.Address, + City: info.City, + County: info.County, + DistrictIds: info.District, + Area: info.Area, + BankInfo: info.BankInfo, + }, nil +} diff --git a/services/store/internal/logic/getInfoByIdsLogic.go b/services/store/internal/logic/getInfoByIdsLogic.go new file mode 100644 index 0000000..7859712 --- /dev/null +++ b/services/store/internal/logic/getInfoByIdsLogic.go @@ -0,0 +1,74 @@ +package logic + +import ( + "context" + "lone-services/pkg/modelbase" + "lone-services/pkg/utils" + "lone-services/rpc/store/pb" + "lone-services/services/store/internal/dao" + "lone-services/services/store/internal/model" + "lone-services/services/store/internal/svc" + "strconv" + + "github.com/zeromicro/go-zero/core/logx" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" +) + +type GetInfoByIdsLogic struct { + ctx context.Context + svcCtx *svc.ServiceContext + logx.Logger +} + +func NewGetInfoByIdsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetInfoByIdsLogic { + return &GetInfoByIdsLogic{ + ctx: ctx, + svcCtx: svcCtx, + Logger: logx.WithContext(ctx), + } +} + +func (l *GetInfoByIdsLogic) GetInfoByIds(in *store.IdsRequest) (*store.ItemsResponse, error) { + var info []dao.StoreInfo + modelObj := model.StoreModel{}.Init() + var ids []string + for _, id := range in.Ids { + ids = append(ids, strconv.FormatInt(id, utils.NumberTen)) + } + w := modelbase.Params{In: map[string][]string{"id": ids}} + err := modelObj.Items(w, &info) + if err != nil { + l.Logger.Error(err) + return nil, status.Error(codes.Internal, utils.Fail.Msg) + } + + if len(info) < utils.NumberOne { + return nil, status.Error(codes.Internal, utils.ErrorNotFund.Msg) + } + + var items []*store.InfoResponse + for _, item := range info { + mobile, _ := utils.DecryptPhone(item.UserMobile) + + items = append(items, &store.InfoResponse{ + Id: item.Id, + Name: item.Name, + Contact: item.Contact, + UserMobile: mobile, + IdCard: item.IdCard, + BusinessLicense: item.BusinessLicense, + Images: item.Images, + Content: item.Content, + OpenTime: item.OpenTime, + Address: item.Address, + City: item.City, + County: item.County, + DistrictIds: item.District, + Area: item.Area, + BankInfo: item.BankInfo, + }) + } + + return &store.ItemsResponse{Items: items}, nil +} diff --git a/services/store/internal/logic/toSaleLogic.go b/services/store/internal/logic/toSaleLogic.go index b154ec1..d756387 100644 --- a/services/store/internal/logic/toSaleLogic.go +++ b/services/store/internal/logic/toSaleLogic.go @@ -8,6 +8,7 @@ import ( sale "lone-services/rpc/sale/pb" "lone-services/services/store/internal/dao" "lone-services/services/store/internal/model" + "lone-services/services/store/validator" "strconv" "lone-services/rpc/store/pb" @@ -32,6 +33,10 @@ func NewToSaleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ToSaleLogi } func (l *ToSaleLogic) ToSale(in *store.ToSaleRequest) (*store.Response, error) { + var v validator.StoreToSaleValidator + if fail := l.checkParams(in, &v); fail != nil { + return fail, nil + } adminInfo := utils.GetUserFromCtx(l.ctx) if adminInfo.ID < utils.NumberOne { return l.fail(utils.ErrorNoLoginInfo) @@ -50,6 +55,9 @@ func (l *ToSaleLogic) ToSale(in *store.ToSaleRequest) (*store.Response, error) { return l.fail(utils.ErrorNotFund) } + if info.SaleId == in.SaleId { + return l.ok(utils.NumberOne) + } info.SaleId = in.SaleId info.AdminId = adminInfo.ID info.AdminName = adminInfo.Name @@ -64,17 +72,34 @@ func (l *ToSaleLogic) ToSale(in *store.ToSaleRequest) (*store.Response, error) { info.GroupId = groupId - sErr = l.setAddressSaleInfo(info) - if sErr != utils.Ok { - return l.fail(sErr) - } - + modelObj.Begin() _, err = modelObj.Edit(w, &info) if err != nil { + modelObj.Rollback() l.Logger.Error(err) return l.fail(utils.Fail) } + history := dao.SaleChangeHistoryCreate{ + StoreId: info.Id, + SaleId: info.SaleId, + AdminId: adminInfo.ID, + } + + err = model.SaleChangeHistoryModel{}.Init().Create(&history) + if err != nil { + modelObj.Rollback() + l.Logger.Error(err) + return l.fail(utils.Fail) + } + + sErr = l.setAddressSaleInfo(info) + if sErr != utils.Ok { + modelObj.Rollback() + return l.fail(sErr) + } + + modelObj.Commit() return l.ok(utils.NumberOne) } diff --git a/services/store/internal/logic/verifyEditLogic.go b/services/store/internal/logic/verifyEditLogic.go index 93614d3..3486e76 100644 --- a/services/store/internal/logic/verifyEditLogic.go +++ b/services/store/internal/logic/verifyEditLogic.go @@ -2,6 +2,14 @@ package logic import ( "context" + "lone-services/pkg/modelbase" + "lone-services/pkg/utils" + user "lone-services/rpc/user/pb" + "lone-services/services/store/internal/dao" + "lone-services/services/store/internal/model" + "lone-services/services/store/validator" + "strconv" + "strings" "lone-services/rpc/store/pb" "lone-services/services/store/internal/svc" @@ -25,7 +33,139 @@ func NewVerifyEditLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Verify } func (l *VerifyEditLogic) VerifyEdit(in *store.EditRequest) (*store.Response, error) { - // todo: add your logic here and delete this line + var v validator.StoreCreateValidator + if fail := l.checkParams(in, &v); fail != nil { + return fail, nil + } + adminInfo := utils.GetUserFromCtx(l.ctx) + if adminInfo.ID < utils.NumberOne { + return l.fail(utils.ErrorNoLoginInfo) + } - return &store.Response{}, nil + var info dao.StoreCreate + w := modelbase.Params{Eq: map[string]string{"id": strconv.Itoa(int(in.Id))}} + modelObj := model.StoreModel{}.Init() + err := modelObj.GetOne(w, &info) + if err != nil || info.Id < utils.NumberOne { + return l.fail(utils.ErrorNotFund) + } + + oldMobile, cErr := utils.DecryptPhone(info.UserMobile) + if cErr != nil { + return l.fail(utils.ErrorEncryptAesError) + } + oldMobile2 := utils.DecryptPhoneReplace(oldMobile) + encryptMobile, cErr := utils.EncryptPhone(in.UserMobile) + if cErr != nil { + return l.fail(utils.ErrorEncryptAesError) + } + if oldMobile != in.UserMobile && oldMobile2 != in.UserName { + var check dao.StoreStatus + ww := modelbase.Params{Eq: map[string]string{"user_mobile": encryptMobile}} + err = modelObj.GetOne(ww, &check) + if err != nil { + l.Logger.Error(err) + return l.fail(utils.Fail) + } + + if check.Id > utils.NumberZero && check.Id != info.Id { + return l.fail(utils.ErrorDataIsExist) + } + } + + if v.BusinessLicense != info.BusinessLicense { + encryptIdCard, cErr := utils.Crypto{}.AESEncryptECB(v.BusinessLicense) + if cErr != nil { + return l.fail(utils.ErrorEncryptAesError) + } + info.BusinessLicense = encryptIdCard + } + + if v.IdCard != info.IdCard { + encryptIdCard, cErr := utils.Crypto{}.AESEncryptECB(v.IdCard) + if cErr != nil { + return l.fail(utils.ErrorEncryptAesError) + } + info.IdCard = encryptIdCard + } + + info.SaleId = v.SaleId + info.UserName = v.UserName + info.Name = v.Name + info.District = v.DistrictIds + info.Address = v.Address + info.Images = v.Images + info.Contact = v.Contact + info.Content = v.Content + info.BankInfo = v.BankInfo + info.AdminId = adminInfo.ID + info.AdminName = adminInfo.Name + info.OpenTime = v.OpenTime + info.LongitudeWgs84 = v.LongitudeWgs84 + info.LatitudeWgs84 = v.LatitudeWgs84 + info.LongitudeGcj02 = v.LongitudeGcj02 + info.LatitudeGcj02 = v.LatitudeGcj02 + info.StoreImages = v.StoreImages + info.Status = utils.StatusOk + info.Area = v.Area + info.Receipt = v.Receipt + info.Type = v.Type + + modelObj.Begin() + if oldMobile != in.UserMobile && encryptMobile != info.UserMobile { + uErr := l.updateUser(info) + if uErr != utils.Ok { + modelObj.Rollback() + return l.fail(uErr) + } + info.UserMobile = encryptMobile + _, err = modelObj.Edit(w, &info) + if err != nil { + modelObj.Rollback() + l.Logger.Error(err) + return l.fail(utils.Fail) + } + + } else { + _, err = modelObj.Edit(w, &info) + if err != nil { + l.Logger.Error(err) + return l.fail(utils.Fail) + } + } + + modelObj.Commit() + + return l.ok(utils.NumberOne) +} + +func (l *VerifyEditLogic) updateUser(info dao.StoreCreate) utils.Status { + cli, err := svc.GetRpcClient(l.svcCtx.OrderName) + if err != nil { + logx.Errorf("get user err: %v", err) + return utils.ErrorInternalServer + } + + client := user.NewUserClient(cli.Conn()) + + mobile, sErr := utils.EncryptPhone(info.UserMobile) + if sErr != nil { + return utils.ErrorEncryptAesError + } + data := user.InternalUpdateReq{ + BizId: info.Id, + SubjectType: dao.UserTypeName, + Mobile: mobile, + Name: info.UserName, + ClientCode: strings.Split(info.StoreType, utils.DecollatorComma), //哪端 + CredentialType: []string{dao.LoginTypePassword, dao.LoginTypeSms}, + Identifier: mobile, //手机号 + } + _, err = client.InternalUpdate(context.Background(), &data) + if err != nil { + logx.Errorf("get order err: %v", err) + return utils.ErrorInternalServer + } + + return utils.Ok } diff --git a/services/store/internal/logic/verifyItemsLogic.go b/services/store/internal/logic/verifyItemsLogic.go index eecad1d..2d4a1c4 100644 --- a/services/store/internal/logic/verifyItemsLogic.go +++ b/services/store/internal/logic/verifyItemsLogic.go @@ -2,10 +2,18 @@ package logic import ( "context" + "lone-services/pkg/modelbase" + "lone-services/pkg/utils" + sale "lone-services/rpc/sale/pb" + "lone-services/services/store/internal/dao" + "lone-services/services/store/internal/model" + "lone-services/services/store/validator" + "strconv" "lone-services/rpc/store/pb" "lone-services/services/store/internal/svc" + "github.com/samber/lo" "github.com/zeromicro/go-zero/core/logx" ) @@ -25,7 +33,97 @@ func NewVerifyItemsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Verif } func (l *VerifyItemsLogic) VerifyItems(in *store.VerifyItemsRequest) (*store.Response, error) { - // todo: add your logic here and delete this line + var v validator.StoreVerifyItemsValidator + if fail := l.checkParams(in, &v); fail != nil { + return fail, nil + } + adminInfo := utils.GetUserFromCtx(l.ctx) + if adminInfo.ID < utils.NumberOne { + return l.fail(utils.ErrorNoLoginInfo) + } + var info []dao.StoreInfo + w := modelbase.Params{ + Eq: map[string]string{}, + Page: int(v.Page), + Size: int(v.Size), + Order: "id desc", + } - return &store.Response{}, nil + if v.Status > utils.NumberZero { + w.Eq["status"] = strconv.Itoa(int(v.Status)) + } else { + w.In = map[string][]string{"status": {utils.StatusFailString, strconv.Itoa(utils.StatusWaitPass)}} + } + + if v.SaleId > utils.NumberZero { + w.Eq["sale_id"] = strconv.FormatInt(v.SaleId, utils.NumberTen) + } + + l.SetWhere(&w, adminInfo) + + w.Like = make(map[string]string) + if len(v.Name) > utils.NumberZero { + w.Like["name LIKE ? "] = "%%" + v.Name + "%%" + } + + items, err := model.StoreModel{}.Init().Page(w, &info) + if err != nil { + l.Logger.Error(err) + return l.fail(utils.Fail) + } + var saleIds []int64 + for key, v := range info { + mobile, aErr := utils.Crypto{}.AESDecryptECB(v.UserMobile) + if aErr == nil { + info[key].UserMobile = mobile + } + + credentials, aErr := utils.Crypto{}.AESDecryptECB(v.BusinessLicense) + if aErr == nil { + info[key].BusinessLicense = credentials + } + idCard, aErr := utils.Crypto{}.AESDecryptECB(v.IdCard) + if aErr == nil { + info[key].IdCard = idCard + } + saleIds = append(saleIds, v.SaleId) + } + newSaleIds := lo.Uniq(saleIds) + if len(newSaleIds) > utils.NumberZero { + salesMap := make(map[int64]string) + if len(newSaleIds) > utils.NumberZero { + sales, err := l.getSaleInfo(saleIds) + if err == utils.Ok { + for _, val := range sales.Items { + salesMap[val.Id] = val.Name + } + } + } + + for key, item := range info { + if s, ok := salesMap[item.SaleId]; ok { + info[key].SaleName = s + } + } + } + + items.Items = info + return l.ok(items) +} + +func (l *VerifyItemsLogic) getSaleInfo(ids []int64) (*sale.NamesByIdsData, utils.Status) { + cli, err := svc.GetRpcClient(l.svcCtx.SaleName) + if err != nil { + logx.Errorf("get order err: %v", err) + return &sale.NamesByIdsData{}, utils.ErrorInternalServer + } + + client := sale.NewSaleClient(cli.Conn()) + w := sale.NamesByIdsReq{Ids: ids} + info, err := client.NamesByIds(context.Background(), &w) + if err != nil { + logx.Errorf("get order err: %v", err) + return &sale.NamesByIdsData{}, utils.ErrorInternalServer + } + return info, utils.Ok } diff --git a/services/store/internal/logic/verifyStatusLogic.go b/services/store/internal/logic/verifyStatusLogic.go index 6015b97..37b426b 100644 --- a/services/store/internal/logic/verifyStatusLogic.go +++ b/services/store/internal/logic/verifyStatusLogic.go @@ -2,6 +2,16 @@ package logic import ( "context" + "fmt" + "lone-services/pkg/modelbase" + "lone-services/pkg/utils" + "lone-services/pkg/validate" + chore "lone-services/rpc/chore/pb" + user "lone-services/rpc/user/pb" + "lone-services/services/store/internal/dao" + "lone-services/services/store/internal/model" + "strconv" + "strings" "lone-services/rpc/store/pb" "lone-services/services/store/internal/svc" @@ -25,7 +35,152 @@ func NewVerifyStatusLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Veri } func (l *VerifyStatusLogic) VerifyStatus(in *store.StatusRequest) (*store.Response, error) { - // todo: add your logic here and delete this line + var v validate.StatusValidator + if fail := l.checkParams(in, &v); fail != nil { + return fail, nil + } - return &store.Response{}, nil + adminInfo := utils.GetUserFromCtx(l.ctx) + if adminInfo.ID < utils.NumberOne { + return l.fail(utils.ErrorNoLoginInfo) + } + + var info dao.StoreStatus + w := modelbase.Params{ + In: map[string][]string{"status": {utils.StatusFailString, strconv.Itoa(utils.StatusWaitPass)}}, + Eq: map[string]string{"id": strconv.FormatInt(v.Id, utils.NumberTen)}} + modelObj := model.StoreModel{}.Init() + err := modelObj.GetOne(w, &info) + + if err != nil { + l.Logger.Error(err) + return l.fail(utils.Fail) + } + if info.Status < utils.NumberOne { + return l.fail(utils.ErrorNotFund) + } + + info.Status = v.Status + info.Reason = v.Reason + info.AdminId = adminInfo.ID + info.AdminName = adminInfo.Name + + status := utils.StatusOk + content := "已通过。" + if v.Status != utils.StatusOk { + status = utils.StatusFail + content = "未通过。理由为: " + v.Reason + } + + content = "门店 '" + info.Name + "'审核: " + content + + salt := utils.GetRandString(utils.NumberFive) + oldPwd := utils.RandString(utils.NumberEight) + pwd := fmt.Sprintf("%s%s", salt, oldPwd) + pwd, _ = utils.EncryptPassword(pwd) + + modelObj.Begin() + _, err = modelObj.Edit(w, &info) + if err != nil { + modelObj.Rollback() + l.Logger.Error(err) + return l.fail(utils.Fail) + } + //TODO 更新登录密码 + //login := dao.LoginStatusPassword{ + // Salt: salt, + // Password: pwd, + // Status: status, + // AdminId: u.Id, + // AdminName: u.Name, + //} + //ww := modelbase.Params{Eq: map[string]string{"obj_id": strconv.Itoa(int(v.Id)), "type": strconv.Itoa(dao.TypeStore)}} + //_, err = model.LoginModel{}.Init().Edit(ww, &login) + //if err != nil { + // modelObj.Rollback() + // l.Logger.Error(err) + // return l.fail(utils.Fail) + //} + + if status == utils.StatusOk { + mobile, cErr := utils.DecryptPhone(info.UserMobile) + if cErr == nil { + l.sendPassword(mobile, oldPwd) + } + + //mobile, cErr := utils.Crypto{}.AESDecryptECB(info.UserMobile) + //if cErr == nil { + //result := utils.SendPwdSMS(mobile, oldPwd) + //jsonStr, err := json.Marshal(result) + //if err == nil { + // SmsLogService{}.Add(string(jsonStr)) + // if result.Code != utils.NumberZero { + // modelObj.Rollback() + // return l.fail(utils.Fail) + // } + //} + //} + } + + //TODO 站内消息 + //mErr := MessageService{}.Add(dao.TargetTypeAgent, dao.ObjTypeStore, status, info.SaleId, info.Id, content) + //if mErr != nil { + // model.Rollback() + // return mErr + //} + modelObj.Commit() + + return l.ok(utils.NumberOne) +} + +func (l *VerifyStatusLogic) updateUserPwd(info dao.StoreCreate) utils.Status { + cli, err := svc.GetRpcClient(l.svcCtx.OrderName) + if err != nil { + logx.Errorf("get user err: %v", err) + return utils.ErrorInternalServer + } + + client := user.NewUserClient(cli.Conn()) + + mobile, sErr := utils.EncryptPhone(info.UserMobile) + if sErr != nil { + return utils.ErrorEncryptAesError + } + data := user.InternalUpdateReq{ + BizId: info.Id, + SubjectType: dao.UserTypeName, + Mobile: mobile, + Name: info.UserName, + ClientCode: strings.Split(info.StoreType, utils.DecollatorComma), //哪端 + CredentialType: []string{dao.LoginTypePassword, dao.LoginTypeSms}, + Identifier: mobile, //手机号 + } + _, err = client.InternalUpdate(context.Background(), &data) + if err != nil { + logx.Errorf("get order err: %v", err) + return utils.ErrorInternalServer + } + + return utils.Ok +} + +func (l *VerifyStatusLogic) sendPassword(mobile, password string) utils.Status { + cli, err := svc.GetRpcClient(l.svcCtx.ChoreName) + if err != nil { + logx.Errorf("get user err: %v", err) + return utils.ErrorInternalServer + } + + client := chore.NewChoreClient(cli.Conn()) + + _, err = client.SendPassword(context.Background(), &chore.SendPasswordReq{ + Mobile: mobile, + Password: password, + }) + if err != nil { + logx.Errorf("get order err: %v", err) + return utils.ErrorInternalServer + } + + return utils.Ok } diff --git a/services/store/internal/logic/webDepositCreateLogic.go b/services/store/internal/logic/webDepositCreateLogic.go index 252f3b1..9422cec 100644 --- a/services/store/internal/logic/webDepositCreateLogic.go +++ b/services/store/internal/logic/webDepositCreateLogic.go @@ -2,6 +2,10 @@ package logic import ( "context" + "lone-services/pkg/utils" + "lone-services/services/store/internal/dao" + "lone-services/services/store/internal/model" + "lone-services/services/store/validator" "lone-services/rpc/store/pb" "lone-services/services/store/internal/svc" @@ -25,7 +29,26 @@ func NewWebDepositCreateLogic(ctx context.Context, svcCtx *svc.ServiceContext) * } func (l *WebDepositCreateLogic) WebDepositCreate(in *store.WebDepositCreateRequest) (*store.Response, error) { - // todo: add your logic here and delete this line + var v validator.DepositCreateValidator + if fail := l.checkParams(in, &v); fail != nil { + return fail, nil + } + adminInfo := utils.GetUserFromCtx(l.ctx) + if adminInfo.ID < utils.NumberOne { + return l.fail(utils.ErrorNoLoginInfo) + } - return &store.Response{}, nil + info := dao.DepositCreate{ + StoreId: adminInfo.ID, + Amount: in.Amount, + Bill: in.Bill, + Status: utils.StatusWaitPass, + } + + err := model.DepositModel{}.Init().Create(&info) + if err != nil { + l.Logger.Error(err) + return l.fail(utils.Fail) + } + return l.ok(utils.NumberOne) } diff --git a/services/store/internal/logic/webDepositItemsLogic.go b/services/store/internal/logic/webDepositItemsLogic.go index 6c3fcd2..a3d858c 100644 --- a/services/store/internal/logic/webDepositItemsLogic.go +++ b/services/store/internal/logic/webDepositItemsLogic.go @@ -2,9 +2,14 @@ package logic import ( "context" - + "lone-services/pkg/modelbase" + "lone-services/pkg/utils" "lone-services/rpc/store/pb" + "lone-services/services/store/internal/dao" + "lone-services/services/store/internal/model" "lone-services/services/store/internal/svc" + "lone-services/services/store/validator" + "strconv" "github.com/zeromicro/go-zero/core/logx" ) @@ -25,7 +30,27 @@ func NewWebDepositItemsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *W } func (l *WebDepositItemsLogic) WebDepositItems(in *store.WebDepositItemsRequest) (*store.Response, error) { - // todo: add your logic here and delete this line + var v validator.DepositWebItemsValidator + if fail := l.checkParams(in, &v); fail != nil { + return fail, nil + } + adminInfo := utils.GetUserFromCtx(l.ctx) + if adminInfo.ID < utils.NumberOne { + return l.fail(utils.ErrorNoLoginInfo) + } - return &store.Response{}, nil + var info []dao.DepositWebInfo + w := modelbase.Params{ + Eq: map[string]string{"store_id": strconv.FormatInt(adminInfo.ID, utils.NumberTen)}, + Page: int(in.Page), + Size: int(in.Size), + Order: "id desc", + } + + items, err := model.DepositModel{}.Init().Page(w, &info) + if err != nil { + l.Logger.Error(err) + return l.fail(utils.Fail) + } + return l.ok(items) } diff --git a/services/store/internal/svc/apply.go b/services/store/internal/svc/apply.go index 0a09f59..55cbd43 100644 --- a/services/store/internal/svc/apply.go +++ b/services/store/internal/svc/apply.go @@ -101,48 +101,32 @@ func (l *ApplySvc) getMd5key(key, key2 string) string { } func (l *ApplySvc) SetActionApply(uId, objId int, Type uint8, reason string) utils.Status { - //data := ApplyData{ - // Uid: uId, - // Id: objId, - // Reason: reason, - // Status: utils.StatusWaitPass, - // Type: Type, - //} - //key, err := l.run(applyStoreEditKey, &data) - //if err == utils.Ok { - //TODO 写入日志 - //add := dao.ActionApplyLogCreate{ - // AdminId: uId, - // ObjId: objId, - // Type: Type, - // Status: utils.StatusWaitPass, - //} - //addErr := model.Create(&add) - //if addErr != nil { - // logx.Error(addErr) - // s.DelActionApply(uId, objId) - // return utils.SetError(utils.Fail, addErr) - //} - - // TODO 调取企业微信发消息 队列类型 - //qErr := QueueService{}.Create(utils.WecomStream, dao.WeComJob{ - // ObjId: data.Id, - // ObjType: Type, - // Type: dao.StoreApplyReview, - // Ext: map[string]any{ - // "reason": reason, - // "key": key, - // }, - //}) - // - //if qErr != nil { - // utils.Logger.Error(qErr) - // return qErr - //} - - //return err - //} - //return err + data := ApplyData{ + Uid: uId, + Id: objId, + Reason: reason, + Status: utils.StatusWaitPass, + Type: Type, + } + key, err := l.run(applyStoreEditKey, &data) + if err == utils.Ok { + // TODO 调取企业微信发消息 队列类型 + //qErr := QueueService{}.Create(utils.WecomStream, dao.WeComJob{ + // ObjId: objId, + // ObjType: Type, + // Type: dao.StoreApplyReview, + // Ext: map[string]any{ + // "reason": reason, + // "key": key, + // }, + //}) + // + //if qErr != nil { + // l.Logger.Error(qErr) + // return utils.Fail + //} + } + logx.Error(key) return utils.Ok } diff --git a/services/store/internal/svc/servicecontext.go b/services/store/internal/svc/servicecontext.go index 40f6130..b8de272 100644 --- a/services/store/internal/svc/servicecontext.go +++ b/services/store/internal/svc/servicecontext.go @@ -78,6 +78,7 @@ type ServiceContext struct { SaleName string OrderName string UserName string + ChoreName string } func NewServiceContext(c config.Config, db *gorm.DB) *ServiceContext { @@ -96,6 +97,11 @@ func NewServiceContext(c config.Config, db *gorm.DB) *ServiceContext { if UserSvc == utils.StringEmpty { logx.Error("config services.user empty") } + //启动仅读取配置,不建立rpc连接 多个服务就多个 + ChoreSvc := utils.GetConfigString("services.chore") + if ChoreSvc == utils.StringEmpty { + logx.Error("config services.chore empty") + } svcCtx := &ServiceContext{ Config: c, @@ -104,6 +110,7 @@ func NewServiceContext(c config.Config, db *gorm.DB) *ServiceContext { SaleName: SaleSvc, OrderName: OrderSvc, UserName: UserSvc, + ChoreName: ChoreSvc, } return svcCtx