WH01243 2 жил өмнө
parent
commit
2a75d083ec

+ 2 - 0
rpc/activity.proto

@@ -291,4 +291,6 @@ service Activity {
   rpc getCommodityList(Request) returns(CommodityResp);
   //用户下所有的奖券(自带领取功能)
   rpc userAllLottery(AllLotteryReq) returns(AllLotteryResp);
+  //商品下所有奖券获取
+  rpc GetAllLottery(Request) returns(ActivityResp);
 }

+ 8 - 0
rpc/activity/activity.go

@@ -44,6 +44,8 @@ type (
 		GetCommodityList(ctx context.Context, in *Request, opts ...grpc.CallOption) (*CommodityResp, error)
 		// 用户下所有的奖券(自带领取功能)
 		UserAllLottery(ctx context.Context, in *AllLotteryReq, opts ...grpc.CallOption) (*AllLotteryResp, error)
+		// 商品下所有奖券获取
+		GetAllLottery(ctx context.Context, in *Request, opts ...grpc.CallOption) (*ActivityResp, error)
 	}
 
 	defaultActivity struct {
@@ -152,3 +154,9 @@ func (m *defaultActivity) UserAllLottery(ctx context.Context, in *AllLotteryReq,
 	client := NewActivityClient(m.cli.Conn())
 	return client.UserAllLottery(ctx, in, opts...)
 }
+
+// 商品下所有奖券获取
+func (m *defaultActivity) GetAllLottery(ctx context.Context, in *Request, opts ...grpc.CallOption) (*ActivityResp, error) {
+	client := NewActivityClient(m.cli.Conn())
+	return client.GetAllLottery(ctx, in, opts...)
+}

+ 27 - 22
rpc/activity/activity.pb.go

@@ -2971,7 +2971,7 @@ var file_activity_proto_rawDesc = []byte{
 	0x74, 0x12, 0x3a, 0x0a, 0x0c, 0x61, 0x63, 0x74, 0x69, 0x76, 0x69, 0x74, 0x79, 0x4a, 0x73, 0x6f,
 	0x6e, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x16, 0x2e, 0x61, 0x63, 0x74, 0x69, 0x76, 0x69,
 	0x74, 0x79, 0x2e, 0x41, 0x63, 0x74, 0x69, 0x76, 0x69, 0x74, 0x79, 0x4a, 0x73, 0x6f, 0x6e, 0x52,
-	0x0c, 0x61, 0x63, 0x74, 0x69, 0x76, 0x69, 0x74, 0x79, 0x4a, 0x73, 0x6f, 0x6e, 0x32, 0x9e, 0x08,
+	0x0c, 0x61, 0x63, 0x74, 0x69, 0x76, 0x69, 0x74, 0x79, 0x4a, 0x73, 0x6f, 0x6e, 0x32, 0xda, 0x08,
 	0x0a, 0x08, 0x41, 0x63, 0x74, 0x69, 0x76, 0x69, 0x74, 0x79, 0x12, 0x43, 0x0a, 0x0f, 0x61, 0x63,
 	0x74, 0x69, 0x76, 0x69, 0x74, 0x79, 0x4c, 0x6f, 0x74, 0x74, 0x65, 0x72, 0x79, 0x12, 0x11, 0x2e,
 	0x61, 0x63, 0x74, 0x69, 0x76, 0x69, 0x74, 0x79, 0x2e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74,
@@ -3037,9 +3037,12 @@ var file_activity_proto_rawDesc = []byte{
 	0x72, 0x41, 0x6c, 0x6c, 0x4c, 0x6f, 0x74, 0x74, 0x65, 0x72, 0x79, 0x12, 0x17, 0x2e, 0x61, 0x63,
 	0x74, 0x69, 0x76, 0x69, 0x74, 0x79, 0x2e, 0x41, 0x6c, 0x6c, 0x4c, 0x6f, 0x74, 0x74, 0x65, 0x72,
 	0x79, 0x52, 0x65, 0x71, 0x1a, 0x18, 0x2e, 0x61, 0x63, 0x74, 0x69, 0x76, 0x69, 0x74, 0x79, 0x2e,
-	0x41, 0x6c, 0x6c, 0x4c, 0x6f, 0x74, 0x74, 0x65, 0x72, 0x79, 0x52, 0x65, 0x73, 0x70, 0x42, 0x0c,
-	0x5a, 0x0a, 0x2e, 0x2f, 0x61, 0x63, 0x74, 0x69, 0x76, 0x69, 0x74, 0x79, 0x62, 0x06, 0x70, 0x72,
-	0x6f, 0x74, 0x6f, 0x33,
+	0x41, 0x6c, 0x6c, 0x4c, 0x6f, 0x74, 0x74, 0x65, 0x72, 0x79, 0x52, 0x65, 0x73, 0x70, 0x12, 0x3a,
+	0x0a, 0x0d, 0x47, 0x65, 0x74, 0x41, 0x6c, 0x6c, 0x4c, 0x6f, 0x74, 0x74, 0x65, 0x72, 0x79, 0x12,
+	0x11, 0x2e, 0x61, 0x63, 0x74, 0x69, 0x76, 0x69, 0x74, 0x79, 0x2e, 0x52, 0x65, 0x71, 0x75, 0x65,
+	0x73, 0x74, 0x1a, 0x16, 0x2e, 0x61, 0x63, 0x74, 0x69, 0x76, 0x69, 0x74, 0x79, 0x2e, 0x41, 0x63,
+	0x74, 0x69, 0x76, 0x69, 0x74, 0x79, 0x52, 0x65, 0x73, 0x70, 0x42, 0x0c, 0x5a, 0x0a, 0x2e, 0x2f,
+	0x61, 0x63, 0x74, 0x69, 0x76, 0x69, 0x74, 0x79, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
 }
 
 var (
@@ -3117,24 +3120,26 @@ var file_activity_proto_depIdxs = []int32{
 	0,  // 29: activity.Activity.userLottery:input_type -> activity.Request
 	0,  // 30: activity.Activity.getCommodityList:input_type -> activity.Request
 	23, // 31: activity.Activity.userAllLottery:input_type -> activity.AllLotteryReq
-	9,  // 32: activity.Activity.activityLottery:output_type -> activity.ActivityLotteryResp
-	3,  // 33: activity.Activity.getLottery:output_type -> activity.GetLotteryRes
-	8,  // 34: activity.Activity.lotteryGrant:output_type -> activity.Response
-	8,  // 35: activity.Activity.activityUse:output_type -> activity.Response
-	13, // 36: activity.Activity.lotteryInfo:output_type -> activity.LotteryResp
-	17, // 37: activity.Activity.giveInfo:output_type -> activity.ActivitygiftResp
-	8,  // 38: activity.Activity.advertisingClick:output_type -> activity.Response
-	8,  // 39: activity.Activity.advertisingExposure:output_type -> activity.Response
-	20, // 40: activity.Activity.findUserLotteryId:output_type -> activity.UserLotteryResp
-	14, // 41: activity.Activity.giveActivity:output_type -> activity.GiveActivityResp
-	8,  // 42: activity.Activity.lotteryReceive:output_type -> activity.Response
-	15, // 43: activity.Activity.getAllActivity:output_type -> activity.ActivityResp
-	8,  // 44: activity.Activity.lotteryStateChange:output_type -> activity.Response
-	9,  // 45: activity.Activity.userLottery:output_type -> activity.ActivityLotteryResp
-	22, // 46: activity.Activity.getCommodityList:output_type -> activity.CommodityResp
-	24, // 47: activity.Activity.userAllLottery:output_type -> activity.AllLotteryResp
-	32, // [32:48] is the sub-list for method output_type
-	16, // [16:32] is the sub-list for method input_type
+	0,  // 32: activity.Activity.GetAllLottery:input_type -> activity.Request
+	9,  // 33: activity.Activity.activityLottery:output_type -> activity.ActivityLotteryResp
+	3,  // 34: activity.Activity.getLottery:output_type -> activity.GetLotteryRes
+	8,  // 35: activity.Activity.lotteryGrant:output_type -> activity.Response
+	8,  // 36: activity.Activity.activityUse:output_type -> activity.Response
+	13, // 37: activity.Activity.lotteryInfo:output_type -> activity.LotteryResp
+	17, // 38: activity.Activity.giveInfo:output_type -> activity.ActivitygiftResp
+	8,  // 39: activity.Activity.advertisingClick:output_type -> activity.Response
+	8,  // 40: activity.Activity.advertisingExposure:output_type -> activity.Response
+	20, // 41: activity.Activity.findUserLotteryId:output_type -> activity.UserLotteryResp
+	14, // 42: activity.Activity.giveActivity:output_type -> activity.GiveActivityResp
+	8,  // 43: activity.Activity.lotteryReceive:output_type -> activity.Response
+	15, // 44: activity.Activity.getAllActivity:output_type -> activity.ActivityResp
+	8,  // 45: activity.Activity.lotteryStateChange:output_type -> activity.Response
+	9,  // 46: activity.Activity.userLottery:output_type -> activity.ActivityLotteryResp
+	22, // 47: activity.Activity.getCommodityList:output_type -> activity.CommodityResp
+	24, // 48: activity.Activity.userAllLottery:output_type -> activity.AllLotteryResp
+	15, // 49: activity.Activity.GetAllLottery:output_type -> activity.ActivityResp
+	33, // [33:50] is the sub-list for method output_type
+	16, // [16:33] is the sub-list for method input_type
 	16, // [16:16] is the sub-list for extension type_name
 	16, // [16:16] is the sub-list for extension extendee
 	0,  // [0:16] is the sub-list for field type_name

+ 38 - 0
rpc/activity/activity_grpc.pb.go

@@ -54,6 +54,8 @@ type ActivityClient interface {
 	GetCommodityList(ctx context.Context, in *Request, opts ...grpc.CallOption) (*CommodityResp, error)
 	//用户下所有的奖券(自带领取功能)
 	UserAllLottery(ctx context.Context, in *AllLotteryReq, opts ...grpc.CallOption) (*AllLotteryResp, error)
+	//商品下所有奖券获取
+	GetAllLottery(ctx context.Context, in *Request, opts ...grpc.CallOption) (*ActivityResp, error)
 }
 
 type activityClient struct {
@@ -208,6 +210,15 @@ func (c *activityClient) UserAllLottery(ctx context.Context, in *AllLotteryReq,
 	return out, nil
 }
 
+func (c *activityClient) GetAllLottery(ctx context.Context, in *Request, opts ...grpc.CallOption) (*ActivityResp, error) {
+	out := new(ActivityResp)
+	err := c.cc.Invoke(ctx, "/activity.Activity/GetAllLottery", in, out, opts...)
+	if err != nil {
+		return nil, err
+	}
+	return out, nil
+}
+
 // ActivityServer is the server API for Activity service.
 // All implementations must embed UnimplementedActivityServer
 // for forward compatibility
@@ -244,6 +255,8 @@ type ActivityServer interface {
 	GetCommodityList(context.Context, *Request) (*CommodityResp, error)
 	//用户下所有的奖券(自带领取功能)
 	UserAllLottery(context.Context, *AllLotteryReq) (*AllLotteryResp, error)
+	//商品下所有奖券获取
+	GetAllLottery(context.Context, *Request) (*ActivityResp, error)
 	mustEmbedUnimplementedActivityServer()
 }
 
@@ -299,6 +312,9 @@ func (UnimplementedActivityServer) GetCommodityList(context.Context, *Request) (
 func (UnimplementedActivityServer) UserAllLottery(context.Context, *AllLotteryReq) (*AllLotteryResp, error) {
 	return nil, status.Errorf(codes.Unimplemented, "method UserAllLottery not implemented")
 }
+func (UnimplementedActivityServer) GetAllLottery(context.Context, *Request) (*ActivityResp, error) {
+	return nil, status.Errorf(codes.Unimplemented, "method GetAllLottery not implemented")
+}
 func (UnimplementedActivityServer) mustEmbedUnimplementedActivityServer() {}
 
 // UnsafeActivityServer may be embedded to opt out of forward compatibility for this service.
@@ -600,6 +616,24 @@ func _Activity_UserAllLottery_Handler(srv interface{}, ctx context.Context, dec
 	return interceptor(ctx, in, info, handler)
 }
 
+func _Activity_GetAllLottery_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
+	in := new(Request)
+	if err := dec(in); err != nil {
+		return nil, err
+	}
+	if interceptor == nil {
+		return srv.(ActivityServer).GetAllLottery(ctx, in)
+	}
+	info := &grpc.UnaryServerInfo{
+		Server:     srv,
+		FullMethod: "/activity.Activity/GetAllLottery",
+	}
+	handler := func(ctx context.Context, req interface{}) (interface{}, error) {
+		return srv.(ActivityServer).GetAllLottery(ctx, req.(*Request))
+	}
+	return interceptor(ctx, in, info, handler)
+}
+
 // Activity_ServiceDesc is the grpc.ServiceDesc for Activity service.
 // It's only intended for direct use with grpc.RegisterService,
 // and not to be introspected or modified (even as a copy)
@@ -671,6 +705,10 @@ var Activity_ServiceDesc = grpc.ServiceDesc{
 			MethodName: "userAllLottery",
 			Handler:    _Activity_UserAllLottery_Handler,
 		},
+		{
+			MethodName: "GetAllLottery",
+			Handler:    _Activity_GetAllLottery_Handler,
+		},
 	},
 	Streams:  []grpc.StreamDesc{},
 	Metadata: "activity.proto",

+ 31 - 0
rpc/internal/logic/getalllotterylogic.go

@@ -0,0 +1,31 @@
+package logic
+
+import (
+	"context"
+
+	"app.yhyue.com/moapp/jyMarketing/rpc/activity"
+	"app.yhyue.com/moapp/jyMarketing/rpc/internal/svc"
+
+	"github.com/zeromicro/go-zero/core/logx"
+)
+
+type GetAllLotteryLogic struct {
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+	logx.Logger
+}
+
+func NewGetAllLotteryLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetAllLotteryLogic {
+	return &GetAllLotteryLogic{
+		ctx:    ctx,
+		svcCtx: svcCtx,
+		Logger: logx.WithContext(ctx),
+	}
+}
+
+// 商品下所有奖券获取
+func (l *GetAllLotteryLogic) GetAllLottery(in *activity.Request) (*activity.ActivityResp, error) {
+	// todo: add your logic here and delete this line
+
+	return &activity.ActivityResp{}, nil
+}

+ 6 - 0
rpc/internal/server/activityserver.go

@@ -117,3 +117,9 @@ func (s *ActivityServer) UserAllLottery(ctx context.Context, in *activity.AllLot
 	l := logic.NewUserAllLotteryLogic(ctx, s.svcCtx)
 	return l.UserAllLottery(in)
 }
+
+// 商品下所有奖券获取
+func (s *ActivityServer) GetAllLottery(ctx context.Context, in *activity.Request) (*activity.ActivityResp, error) {
+	l := logic.NewGetAllLotteryLogic(ctx, s.svcCtx)
+	return l.GetAllLottery(in)
+}

+ 1 - 1
service/activityService.go

@@ -177,7 +177,7 @@ func (service *ActivityService) ActivityLottery(in *activity.Request) (int64, st
 		err = orm.Table("activity").Alias("a").Select(" DISTINCT a.*").
 			Join("left", "discount d", "d.activityId = a.id").
 			Join("left", "product p", "FIND_IN_SET(p.productCode,d.useProductList)").
-			Where("a.activityType < 2 and a.state=1  and if ( (a.preheatingTime IS NULL or a.preheatingTime='')  , a.beginDate<now() ,a.preheatingTime<now())  and a.endDate>=now() and p.productCode=?", in.ProductCode).Find(&activityList)
+			Where("a.activityType < 2 and a.state=1  and if ( (a.preheatingTime IS NULL or a.preheatingTime='')  , a.beginDate<now() ,a.preheatingTime<now())  and a.endDate>=now() and (p.productCode=? or p.productCode=?)", in.ProductCode, in.ProductCode).Find(&activityList)
 		var lotteryJsonList []entity.LotteryJson
 		if len(activityList) == 0 {
 			return entity.ErrorCode, "当前时段没有活动可以参加", lotteryJsonList, entity.Activity{}

+ 57 - 0
service/activityServiceNew.go

@@ -444,3 +444,60 @@ func lotteryWaitHandle(orm *xorm.Engine, lotteryIdArr, userId, appId string, act
 	}
 	return nil
 }
+
+//商品下所有奖券查询
+func (service *ActivityServiceNew) GetAllLottery(in *activity.Request) (int64, string, []entity.Activity) {
+	//1、查找活动信息
+	orm := entity.Engine
+	activityArr := []entity.Activity{}
+	var err error
+	var activityList = []entity.Activity{}
+	//有券的活动获取
+	err = orm.Table("activity").Alias("a").Select(" DISTINCT a.*").
+		Join("left", "discount d", "d.activityId = a.id").
+		Join("left", "product p", "FIND_IN_SET(p.productCode,d.useProductList)").
+		Where(" a.state=1  and if ( (a.preheatingTime IS NULL or a.preheatingTime='' )  , a.beginDate<now() ,a.preheatingTime<now())  and a.endDate>=now() and (p.productCode=? or p.parentCode=?)", in.ProductCode, in.ProductCode).Find(&activityList)
+	if len(activityList) == 0 {
+		return entity.ErrorCode, "当前时段没有活动可以参加", []entity.Activity{}
+	}
+	for _, activityEntity := range activityList {
+		activityId := activityEntity.Id
+		activityType := activityEntity.ActivityType
+		receivingLocation := activityEntity.ReceivingLocation
+		logx.Info(receivingLocation)
+		//判断是否返回数据
+		if activityType < 2 {
+			var lotteryJsonList []entity.LotteryJson
+			//赠品、限时活动之外的活动
+			//2、先查找活动下的奖品Id
+			err = orm.Table("activity").Alias("a").
+				Select("a.activityType,l.full,l.reducel,l.discount,d.useProductList").
+				Join("left", "discount d", "d.activityId=a.id and  d.state=1").
+				Join("left", "lottery l", " l.id = d.lotteryId  ").
+				Where("a.id = ?  and a.appId=?  ", activityId, in.AppId).Find(&lotteryJsonList)
+			if err != nil {
+				logx.Info("用户下的奖券查询失败:", err)
+				continue
+			}
+			activityEntity.LotteryData = lotteryJsonList
+		} else {
+			//限时、赠品活动处理
+			orm := entity.Engine
+			//先查找产品参与的活动
+			var lotteryJsonList = []entity.LotteryJson{}
+			err = orm.Table("activity").Alias("a").Select(""+
+				"DISTINCT a.activityType, d.promotionalPrice,d.discount,d.reduce,d.useProductList").
+				Join("left", " discount d", "d.activityId = a.id ").
+				Join("left", "product p", "FIND_IN_SET(p.ProductCode,d.useProductList)").
+				Where("  a.id=?  and d.state=1", activityEntity.Id).
+				Find(&lotteryJsonList)
+			if err != nil {
+				logx.Info("用户下的奖券查询失败:", err)
+				continue
+			}
+			activityEntity.LotteryData = lotteryJsonList
+		}
+		activityArr = append(activityArr, activityEntity)
+	}
+	return entity.SuccessCode, "活动下的奖券", activityArr
+}