فهرست منبع

修改pg方法

jyq 4 سال پیش
والد
کامیت
00f912052a

+ 23 - 0
api/grpc/base.go

@@ -479,6 +479,16 @@ func (a Api) VipHourChgQuery(ctx context.Context, r *pb.StandardRequest) (*pb.St
 	return rst, nil
 }
 
+// VipUserClassQuery 商家会员课程查询
+func (a Api) VipUserClassQuery(ctx context.Context, r *pb.StandardRequest) (*pb.StandardReply, error) {
+	// 获取token,并验证签名函数
+	token, q, sign := a.webToGoVerify(ctx, r)
+
+	rs := service.User{}.VipUserClassQuery(token, q.ShopID, q.JsonStr, sign)
+	rst := a.toWebFunc(rs)
+	return rst, nil
+}
+
 // GetSimpleQiNiuToken 获取七牛简单Token
 func (a Api) GetSimpleQiNiuToken(ctx context.Context, r *pb.DefaultRequest) (*pb.QiNiuTokenReply, error) {
 	token := a.getToken(ctx)
@@ -924,6 +934,19 @@ func (a Api) UnBindHrSensor(ctx context.Context, r *pb.StandardRequest) (*pb.Sta
 
 // ----------------------- 微信管理 ---------------------------------------------
 
+// GenVerifyImageByWinXin 微信登陆获取图片验证码
+func (Api) GenVerifyImageByWinXin(ctx context.Context, q *pb.GenVerifyImageRequest) (*pb.GenVerifyImageReply, error) {
+	height := int(q.Height)
+	width := int(q.Width)
+
+	id, pic := service.VerifyCode{}.GenImage(height, width)
+
+	return &pb.GenVerifyImageReply{
+		CodeId:      id,
+		ImageBase64: pic,
+	}, nil
+}
+
 // VipUserWeiXinLogin 解绑心率带
 func (a Api) VipUserWeiXinLogin(ctx context.Context, r *pb.StandardRequest) (*pb.StandardReply, error) {
 	// 获取token,并验证签名函数

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 652 - 393
api/grpc/base/base.pb.go


+ 110 - 0
api/grpc/base/base_grpc.pb.go

@@ -132,6 +132,10 @@ type ApiClient interface {
 	UnBindHrSensor(ctx context.Context, in *StandardRequest, opts ...grpc.CallOption) (*StandardReply, error)
 	// 评分管理
 	ActionQuery(ctx context.Context, in *StandardRequest, opts ...grpc.CallOption) (*StandardReply, error)
+	// 用户微信登陆
+	GenVerifyImageByWinXin(ctx context.Context, in *GenVerifyImageRequest, opts ...grpc.CallOption) (*GenVerifyImageReply, error)
+	GenPhoneVerifyCode(ctx context.Context, in *GenPhoneVerifyCodeRequest, opts ...grpc.CallOption) (*DefaultReply, error)
+	CheckVerifyCode(ctx context.Context, in *CheckVerifyCodeRequest, opts ...grpc.CallOption) (*DefaultReply, error)
 }
 
 type apiClient struct {
@@ -1087,6 +1091,33 @@ func (c *apiClient) ActionQuery(ctx context.Context, in *StandardRequest, opts .
 	return out, nil
 }
 
+func (c *apiClient) GenVerifyImageByWinXin(ctx context.Context, in *GenVerifyImageRequest, opts ...grpc.CallOption) (*GenVerifyImageReply, error) {
+	out := new(GenVerifyImageReply)
+	err := c.cc.Invoke(ctx, "/base.Api/GenVerifyImageByWinXin", in, out, opts...)
+	if err != nil {
+		return nil, err
+	}
+	return out, nil
+}
+
+func (c *apiClient) GenPhoneVerifyCode(ctx context.Context, in *GenPhoneVerifyCodeRequest, opts ...grpc.CallOption) (*DefaultReply, error) {
+	out := new(DefaultReply)
+	err := c.cc.Invoke(ctx, "/base.Api/GenPhoneVerifyCode", in, out, opts...)
+	if err != nil {
+		return nil, err
+	}
+	return out, nil
+}
+
+func (c *apiClient) CheckVerifyCode(ctx context.Context, in *CheckVerifyCodeRequest, opts ...grpc.CallOption) (*DefaultReply, error) {
+	out := new(DefaultReply)
+	err := c.cc.Invoke(ctx, "/base.Api/CheckVerifyCode", in, out, opts...)
+	if err != nil {
+		return nil, err
+	}
+	return out, nil
+}
+
 // ApiServer is the server API for Api service.
 // All implementations must embed UnimplementedApiServer
 // for forward compatibility
@@ -1205,6 +1236,10 @@ type ApiServer interface {
 	UnBindHrSensor(context.Context, *StandardRequest) (*StandardReply, error)
 	// 评分管理
 	ActionQuery(context.Context, *StandardRequest) (*StandardReply, error)
+	// 用户微信登陆
+	GenVerifyImageByWinXin(context.Context, *GenVerifyImageRequest) (*GenVerifyImageReply, error)
+	GenPhoneVerifyCode(context.Context, *GenPhoneVerifyCodeRequest) (*DefaultReply, error)
+	CheckVerifyCode(context.Context, *CheckVerifyCodeRequest) (*DefaultReply, error)
 	mustEmbedUnimplementedApiServer()
 }
 
@@ -1527,6 +1562,15 @@ func (UnimplementedApiServer) UnBindHrSensor(context.Context, *StandardRequest)
 func (UnimplementedApiServer) ActionQuery(context.Context, *StandardRequest) (*StandardReply, error) {
 	return nil, status.Errorf(codes.Unimplemented, "method ActionQuery not implemented")
 }
+func (UnimplementedApiServer) GenVerifyImageByWinXin(context.Context, *GenVerifyImageRequest) (*GenVerifyImageReply, error) {
+	return nil, status.Errorf(codes.Unimplemented, "method GenVerifyImageByWinXin not implemented")
+}
+func (UnimplementedApiServer) GenPhoneVerifyCode(context.Context, *GenPhoneVerifyCodeRequest) (*DefaultReply, error) {
+	return nil, status.Errorf(codes.Unimplemented, "method GenPhoneVerifyCode not implemented")
+}
+func (UnimplementedApiServer) CheckVerifyCode(context.Context, *CheckVerifyCodeRequest) (*DefaultReply, error) {
+	return nil, status.Errorf(codes.Unimplemented, "method CheckVerifyCode not implemented")
+}
 func (UnimplementedApiServer) mustEmbedUnimplementedApiServer() {}
 
 // UnsafeApiServer may be embedded to opt out of forward compatibility for this service.
@@ -3430,6 +3474,60 @@ func _Api_ActionQuery_Handler(srv interface{}, ctx context.Context, dec func(int
 	return interceptor(ctx, in, info, handler)
 }
 
+func _Api_GenVerifyImageByWinXin_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
+	in := new(GenVerifyImageRequest)
+	if err := dec(in); err != nil {
+		return nil, err
+	}
+	if interceptor == nil {
+		return srv.(ApiServer).GenVerifyImageByWinXin(ctx, in)
+	}
+	info := &grpc.UnaryServerInfo{
+		Server:     srv,
+		FullMethod: "/base.Api/GenVerifyImageByWinXin",
+	}
+	handler := func(ctx context.Context, req interface{}) (interface{}, error) {
+		return srv.(ApiServer).GenVerifyImageByWinXin(ctx, req.(*GenVerifyImageRequest))
+	}
+	return interceptor(ctx, in, info, handler)
+}
+
+func _Api_GenPhoneVerifyCode_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
+	in := new(GenPhoneVerifyCodeRequest)
+	if err := dec(in); err != nil {
+		return nil, err
+	}
+	if interceptor == nil {
+		return srv.(ApiServer).GenPhoneVerifyCode(ctx, in)
+	}
+	info := &grpc.UnaryServerInfo{
+		Server:     srv,
+		FullMethod: "/base.Api/GenPhoneVerifyCode",
+	}
+	handler := func(ctx context.Context, req interface{}) (interface{}, error) {
+		return srv.(ApiServer).GenPhoneVerifyCode(ctx, req.(*GenPhoneVerifyCodeRequest))
+	}
+	return interceptor(ctx, in, info, handler)
+}
+
+func _Api_CheckVerifyCode_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
+	in := new(CheckVerifyCodeRequest)
+	if err := dec(in); err != nil {
+		return nil, err
+	}
+	if interceptor == nil {
+		return srv.(ApiServer).CheckVerifyCode(ctx, in)
+	}
+	info := &grpc.UnaryServerInfo{
+		Server:     srv,
+		FullMethod: "/base.Api/CheckVerifyCode",
+	}
+	handler := func(ctx context.Context, req interface{}) (interface{}, error) {
+		return srv.(ApiServer).CheckVerifyCode(ctx, req.(*CheckVerifyCodeRequest))
+	}
+	return interceptor(ctx, in, info, handler)
+}
+
 // Api_ServiceDesc is the grpc.ServiceDesc for Api service.
 // It's only intended for direct use with grpc.RegisterService,
 // and not to be introspected or modified (even as a copy)
@@ -3857,6 +3955,18 @@ var Api_ServiceDesc = grpc.ServiceDesc{
 			MethodName: "ActionQuery",
 			Handler:    _Api_ActionQuery_Handler,
 		},
+		{
+			MethodName: "GenVerifyImageByWinXin",
+			Handler:    _Api_GenVerifyImageByWinXin_Handler,
+		},
+		{
+			MethodName: "GenPhoneVerifyCode",
+			Handler:    _Api_GenPhoneVerifyCode_Handler,
+		},
+		{
+			MethodName: "CheckVerifyCode",
+			Handler:    _Api_CheckVerifyCode_Handler,
+		},
 	},
 	Streams:  []grpc.StreamDesc{},
 	Metadata: "base.proto",

+ 5 - 5
assembly/base/repository/postgre/order.go

@@ -18,35 +18,35 @@ func (PGOrder) OrderListQuery(optUserId int64, objectShopId int64, jsonStr strin
 }
 
 func (PGOrder) OrderAdd(optUserId int64, objectShopId int64, jsonStr string, verfStr string) (result string, err error) {
-	err = getClient().Raw("select fn_order_add(? ,? ,? )", optUserId, objectShopId, jsonStr, verfStr).
+	err = getClient().Raw("select fn_order_add(? ,? ,?, ? )", optUserId, objectShopId, jsonStr, verfStr).
 		Scan(&result).Error
 
 	return
 }
 
 func (PGOrder) OrderCancel(optUserId int64, objectShopId int64, jsonStr string, verfStr string) (result string, err error) {
-	err = getClient().Raw("select fn_order_cancel(? ,? ,? )", optUserId, objectShopId, jsonStr, verfStr).
+	err = getClient().Raw("select fn_order_cancel(? ,? ,?, ? )", optUserId, objectShopId, jsonStr, verfStr).
 		Scan(&result).Error
 
 	return
 }
 
 func (PGOrder) OrderStatistics(optUserId int64, objectShopId int64, jsonStr string, verfStr string) (result string, err error) {
-	err = getClient().Raw("select fn_order_statistics(? ,? ,? )", optUserId, objectShopId, jsonStr, verfStr).
+	err = getClient().Raw("select fn_order_statistics(? ,? ,?, ? )", optUserId, objectShopId, jsonStr, verfStr).
 		Scan(&result).Error
 
 	return
 }
 
 func (PGOrder) ClassListByOrderDate(optUserId int64, objectShopId int64, jsonStr string, verfStr string) (result string, err error) {
-	err = getClient().Raw("select fn_class_list_by_order_date(? ,? ,? )", optUserId, objectShopId, jsonStr, verfStr).
+	err = getClient().Raw("select fn_class_list_by_order_date(? ,? ,?, ? )", optUserId, objectShopId, jsonStr, verfStr).
 		Scan(&result).Error
 
 	return
 }
 
 func (PGOrder) VipUserOrderQuery(optUserId int64, objectShopId int64, jsonStr string, verfStr string) (result string, err error) {
-	err = getClient().Raw("select fn_vip_user_order_query(? ,? ,? )", optUserId, objectShopId, jsonStr, verfStr).
+	err = getClient().Raw("select fn_vip_user_order_query(? ,? ,?, ? )", optUserId, objectShopId, jsonStr, verfStr).
 		Scan(&result).Error
 
 	return

+ 7 - 0
assembly/base/repository/postgre/shop.go

@@ -268,3 +268,10 @@ func (PGShop) ClassHourChgQuery(optUserId int64, objectShopId int64, jsonStr str
 
 	return
 }
+
+func (PGShop) VipUserClassQuery(optUserId int64, objectShopId int64, jsonStr string, verfStr string) (result string, err error) {
+	err = getClient().Raw("select fn_vip_user_class_query(? ,? ,?, ? )", optUserId, objectShopId, jsonStr, verfStr).
+		Scan(&result).Error
+
+	return
+}

+ 29 - 1
assembly/base/repository/redis/init.go

@@ -1,10 +1,19 @@
 package redis
 
 import (
-	"github.com/go-redis/redis/v8"
+	"context"
 	"sportfitness/base/assembly/base/repository"
+	"sportfitness/base/errors"
+
+	"git.beswell.com/gframe/application"
+
+	"github.com/go-redis/redis/v8"
 )
 
+const prefix = "sportfitness:base"
+
+var ctx = context.Background()
+
 func Init() {
 	err := repository.Repository.InitRedisByConfigCenter(0)
 	if err != nil {
@@ -15,3 +24,22 @@ func Init() {
 func getClient() redis.UniversalClient {
 	return repository.Repository.GetRedisClient()
 }
+
+func handleTokenErr(err error) {
+	if err != nil {
+		if err == redis.Nil {
+			err = application.ErrorBusinessF(errors.ErrCodeToken, "token无效")
+		}
+
+		panic(err)
+	}
+}
+
+func handleErr(err error) {
+	if err != nil {
+		if err == redis.Nil {
+			err = application.ErrorBusinessF(errors.ErrCodeNoRecord, "记录不存在")
+		}
+		panic(err)
+	}
+}

+ 11 - 0
assembly/base/service/user.go

@@ -286,6 +286,17 @@ func (u User) VipHourChgQuery(token string, objectShopId int64, jsonStr string,
 	return rst
 }
 
+// VipUserClassQuery 商家会员消费课时详情查询
+func (u User) VipUserClassQuery(token string, objectShopId int64, jsonStr string, sign string) string {
+	optId := u.checkPermission(token, objectShopId)
+
+	rst, err := postgre.PGShop{}.VipUserClassQuery(optId, objectShopId, jsonStr, sign)
+	if err != nil {
+		panic(errors.PGError)
+	}
+	return rst
+}
+
 // GetSimpleQiNiuToken 获取七牛简单Token
 func (u User) GetSimpleQiNiuToken(token string) *pb.QiNiuTokenReply {
 	_ = u.checkPermission(token, 0)

+ 12 - 3
errors/error.go

@@ -15,9 +15,12 @@ import (
 
 type ErrorCode int
 
-//const (
-//	PGErr ErrorCode = 100
-//)
+const (
+	ErrCodeParam                = application.ErrorCode(pb.ErrorCode_PARAM)
+	ErrCodeToken                = application.ErrorCode(pb.ErrorCode_Token)
+	ErrCodeNoRecord             = application.ErrorCodeNoRecord
+	ErrCodePasswordWrongTooMuch = application.ErrorCode(pb.ErrorCode_PasswordWrongTooMuch)
+)
 
 var (
 	//PGError = NewInternalErr(PGErr, "数据库内部错误")
@@ -29,6 +32,7 @@ var (
 		"状态值转换错误,请检查后提交")
 	ImToWebtatusError = application.Errorf(application.ErrorCode(pb.ErrorCode_ImToWebtatusError),
 		"状态值转换错误,请检查后提交")
+	ErrVerifyCode = application.ErrorBusinessF(application.ErrorCode(pb.ErrorCode_VerifyCode), "验证码错误")
 )
 
 //StandardError 标准错误,包含错误码和错误信息
@@ -53,3 +57,8 @@ func NewServiceErr(code ErrorCode, msg string) *StandardError {
 		ShowMsg: msg,
 	}
 }
+
+// ParamError 参数错误
+func ParamError(paramName, v interface{}) *application.Error {
+	return application.ErrorBusinessF(ErrCodeParam, "[%s]不可为[%v]", paramName, v)
+}

+ 31 - 0
proto/server/base.proto

@@ -12,6 +12,10 @@ enum ErrorCode{
   WebStatusError = 121;
   WebToImStatusError = 122;
   ImToWebtatusError = 123;
+  PARAM = 150;
+  Token = 200;
+  VerifyCode = 201;
+  PasswordWrongTooMuch = 202;
 }
 
 // metadata 中需要字段 tokefrgen n 用作登录验证
@@ -138,6 +142,11 @@ service Api {
   // 评分管理
   rpc ActionQuery (StandardRequest) returns (StandardReply) {}
 
+  // 用户微信登陆
+  rpc GenVerifyImageByWinXin(GenVerifyImageRequest)returns(GenVerifyImageReply){}
+  rpc GenPhoneVerifyCode(GenPhoneVerifyCodeRequest)returns(DefaultReply){}
+  rpc CheckVerifyCode(CheckVerifyCodeRequest)returns(DefaultReply){}
+
 }
 message DefaultRequest{
 }
@@ -296,4 +305,26 @@ message LicenseType{
 
 message LicenseTypeMapReply{
   map<int64, LicenseType> licenseMap = 1;
+}
+
+enum VerifyType{
+  Undefined = 0;
+  SignUp = 1;
+  SignIn = 2;
+  ChangePassword = 3;
+}
+
+message GenPhoneVerifyCodeRequest{
+  VerifyType verifyType = 1;
+  string code = 2;
+  string account = 3;
+  string ip = 4;
+  string templateCode = 5;
+  int64 expireDurationNano = 6;
+}
+
+message CheckVerifyCodeRequest{
+  VerifyType verifyType = 1;
+  string code = 2;
+  string account = 3;
 }

برخی فایل ها در این مقایسه diff نمایش داده نمی شوند زیرا تعداد فایل ها بسیار زیاد است