WH01243 4 years ago
parent
commit
bb4509e632

+ 29 - 0
api/internal/handler/integralconsumehandler.go

@@ -0,0 +1,29 @@
+package handler
+
+import (
+	"net/http"
+
+	"points_service/api/internal/logic"
+	"points_service/api/internal/svc"
+	"points_service/api/internal/types"
+
+	"github.com/tal-tech/go-zero/rest/httpx"
+)
+
+func IntegralConsumeHandler(ctx *svc.ServiceContext) http.HandlerFunc {
+	return func(w http.ResponseWriter, r *http.Request) {
+		var req types.ConsumeReq
+		if err := httpx.Parse(r, &req); err != nil {
+			httpx.Error(w, err)
+			return
+		}
+
+		l := logic.NewIntegralConsumeLogic(r.Context(), ctx)
+		resp, err := l.IntegralConsume(req)
+		if err != nil {
+			httpx.Error(w, err)
+		} else {
+			httpx.OkJson(w, resp)
+		}
+	}
+}

+ 29 - 0
api/internal/handler/integraldetailedcheckhandler.go

@@ -0,0 +1,29 @@
+package handler
+
+import (
+	"net/http"
+
+	"points_service/api/internal/logic"
+	"points_service/api/internal/svc"
+	"points_service/api/internal/types"
+
+	"github.com/tal-tech/go-zero/rest/httpx"
+)
+
+func IntegralDetailedCheckHandler(ctx *svc.ServiceContext) http.HandlerFunc {
+	return func(w http.ResponseWriter, r *http.Request) {
+		var req types.DetailedReq
+		if err := httpx.Parse(r, &req); err != nil {
+			httpx.Error(w, err)
+			return
+		}
+
+		l := logic.NewIntegralDetailedCheckLogic(r.Context(), ctx)
+		resp, err := l.IntegralDetailedCheck(req)
+		if err != nil {
+			httpx.Error(w, err)
+		} else {
+			httpx.OkJson(w, resp)
+		}
+	}
+}

+ 29 - 0
api/internal/handler/integralharvesthandler.go

@@ -0,0 +1,29 @@
+package handler
+
+import (
+	"net/http"
+
+	"points_service/api/internal/logic"
+	"points_service/api/internal/svc"
+	"points_service/api/internal/types"
+
+	"github.com/tal-tech/go-zero/rest/httpx"
+)
+
+func IntegralHarvestHandler(ctx *svc.ServiceContext) http.HandlerFunc {
+	return func(w http.ResponseWriter, r *http.Request) {
+		var req types.AddReq
+		if err := httpx.Parse(r, &req); err != nil {
+			httpx.Error(w, err)
+			return
+		}
+
+		l := logic.NewIntegralHarvestLogic(r.Context(), ctx)
+		resp, err := l.IntegralHarvest(req)
+		if err != nil {
+			httpx.Error(w, err)
+		} else {
+			httpx.OkJson(w, resp)
+		}
+	}
+}

+ 15 - 0
api/internal/handler/routes.go

@@ -22,6 +22,21 @@ func RegisterHandlers(engine *rest.Server, serverCtx *svc.ServiceContext) {
 				Path:    "/integralExpireCheck",
 				Handler: IntegralExpireCheckHandler(serverCtx),
 			},
+			{
+				Method:  http.MethodPost,
+				Path:    "/integralHarvest",
+				Handler: IntegralHarvestHandler(serverCtx),
+			},
+			{
+				Method:  http.MethodPost,
+				Path:    "/integralConsume",
+				Handler: IntegralConsumeHandler(serverCtx),
+			},
+			{
+				Method:  http.MethodGet,
+				Path:    "/integralDetailedCheck",
+				Handler: IntegralDetailedCheckHandler(serverCtx),
+			},
 		},
 	)
 }

+ 1 - 1
api/internal/logic/integralbalancechecklogic.go

@@ -23,7 +23,7 @@ func NewIntegralBalanceCheckLogic(ctx context.Context, svcCtx *svc.ServiceContex
 		svcCtx: svcCtx,
 	}
 }
-
+//查询积分余额
 func (l *IntegralBalanceCheckLogic) IntegralBalanceCheck(req types.CheckReq) (*types.Response, error) {
 	// todo: add your logic here and delete this line
 	result := &types.Response{}

+ 47 - 0
api/internal/logic/integralconsumelogic.go

@@ -0,0 +1,47 @@
+package logic
+
+import (
+	"context"
+	"points_service/rpc/integral"
+
+	"points_service/api/internal/svc"
+	"points_service/api/internal/types"
+
+	"github.com/tal-tech/go-zero/core/logx"
+)
+
+type IntegralConsumeLogic struct {
+	logx.Logger
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+}
+
+func NewIntegralConsumeLogic(ctx context.Context, svcCtx *svc.ServiceContext) IntegralConsumeLogic {
+	return IntegralConsumeLogic{
+		Logger: logx.WithContext(ctx),
+		ctx:    ctx,
+		svcCtx: svcCtx,
+	}
+}
+
+//积分消耗
+func (l *IntegralConsumeLogic) IntegralConsume(req types.ConsumeReq) (*types.ConsumeResp, error) {
+	// todo: add your logic here and delete this line
+	result := &types.ConsumeResp{}
+	lsi := l.svcCtx.Integral
+	resp, err := lsi.IntegralConsume(l.ctx, &integral.Req{
+		UserId:         req.UserId,
+		AppId:          req.AppId,
+		EndDate:        req.EndDate,
+		BusinessType:   req.BusinessType,
+		BusinessTypeId: req.BusinessTypeId,
+		Point:          req.Point,
+		PointType:      req.PointType,
+	})
+	if err != nil {
+		return nil, err
+	}
+	result.Code = resp.Code
+	result.Message = resp.Message
+	return result, nil
+}

+ 60 - 0
api/internal/logic/integraldetailedchecklogic.go

@@ -0,0 +1,60 @@
+package logic
+
+import (
+	"context"
+	"points_service/rpc/integral"
+
+	"points_service/api/internal/svc"
+	"points_service/api/internal/types"
+
+	"github.com/tal-tech/go-zero/core/logx"
+)
+
+type IntegralDetailedCheckLogic struct {
+	logx.Logger
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+}
+
+func NewIntegralDetailedCheckLogic(ctx context.Context, svcCtx *svc.ServiceContext) IntegralDetailedCheckLogic {
+	return IntegralDetailedCheckLogic{
+		Logger: logx.WithContext(ctx),
+		ctx:    ctx,
+		svcCtx: svcCtx,
+	}
+}
+
+//当月积分明细
+func (l *IntegralDetailedCheckLogic) IntegralDetailedCheck(req types.DetailedReq) (*types.RespList, error) {
+	// todo: add your logic here and delete this line
+	result := &types.RespList{}
+	lsi := l.svcCtx.Integral
+	resp, err := lsi.IntegralDetailedCheck(l.ctx, &integral.Req{
+		UserId:   req.UserId,
+		AppId:    req.AppId,
+		PageSize: req.PageSize,
+		Page:     req.Page,
+		EndDate:  req.EndDate,
+	})
+	if err != nil {
+		return nil, err
+	}
+	result.Count=resp.Count
+	for _, value := range resp.Data {
+		point:=types.Point{}
+		point.EndDate=value.EndDate
+		point.Sort=value.Sort
+		point.Point= value.Point
+		point.CreateTime=value.CreateTime
+		point.PointType=value.PointType
+		point.BusinessTypeId=value.BusinessTypeId
+		point.BusinessType=value.BusinessType
+		point.Name=value.Name
+		point.UserId=value.UserId
+		point.AppId=value.AppId
+		result.Data=append(result.Data,&point )
+	}
+	result.Code = resp.Code
+	result.Message = resp.Message
+	return result, nil
+}

+ 48 - 0
api/internal/logic/integralharvestlogic.go

@@ -0,0 +1,48 @@
+package logic
+
+import (
+	"context"
+	"points_service/rpc/integral"
+
+	"points_service/api/internal/svc"
+	"points_service/api/internal/types"
+
+	"github.com/tal-tech/go-zero/core/logx"
+)
+
+type IntegralHarvestLogic struct {
+	logx.Logger
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+}
+
+func NewIntegralHarvestLogic(ctx context.Context, svcCtx *svc.ServiceContext) IntegralHarvestLogic {
+	return IntegralHarvestLogic{
+		Logger: logx.WithContext(ctx),
+		ctx:    ctx,
+		svcCtx: svcCtx,
+	}
+}
+
+//新增积分
+func (l *IntegralHarvestLogic) IntegralHarvest(req types.AddReq) (*types.AddResp, error) {
+	// todo: add your logic here and delete this line
+	result := &types.AddResp{}
+	lsi := l.svcCtx.Integral
+	resp, err := lsi.IntegralHarvest(l.ctx, &integral.Req{
+		UserId:         req.UserId,
+		AppId:          req.AppId,
+		EndDate:        req.EndDate,
+		BusinessType:   req.BusinessType,
+		BusinessTypeId: req.BusinessTypeId,
+		Point:          req.Point,
+		PointType:      req.PointType,
+		OperationType:  req.OperationType,
+	})
+	if err != nil {
+		return nil, err
+	}
+	result.Code = resp.Code
+	result.Message = resp.Message
+	return result, nil
+}

+ 52 - 5
api/internal/types/types.go

@@ -1,17 +1,33 @@
 // Code generated by goctl. DO NOT EDIT.
 package types
 
-type Request struct {
+type DetailedReq struct {
+	UserId   string `form:"userId"`
+	AppId    int64  `form:"appId"`
+	EndDate  string `form:"endDate"`
+	Page     int64  `form:"page"`
+	PageSize int64  `form:"pageSize"`
+}
+
+type RespList struct {
+	Code    int64    `form:"code"`
+	Message string   `form:"message"`
+	Count   int64    `form:"count"`
+	Data    []*Point `form:"data"`
+}
+
+type Point struct {
+	Id             int64  `form:"id"`
 	UserId         string `form:"userId"`
-	AppId          int64  `form:"appId"`
 	PointType      int64  `form:"pointType"`
 	BusinessTypeId int64  `form:"businessTypeId"`
 	BusinessType   string `form:"businessType"`
 	Point          int64  `form:"point"`
+	CreateTime     string `form:"createTime"`
 	EndDate        string `form:"endDate"`
-	Page           int64  `form:"page"`
-	PageSize       int64  `form:"pageSize"`
-	OperationType  bool   `form:"operationType"`
+	AppId          int64  `form:"appId"`
+	Sort           int64  `form:"sort"`
+	Name           string `form:"name"`
 }
 
 type Response struct {
@@ -30,3 +46,34 @@ type ExpireReq struct {
 	AppId   int64  `form:"appId"`
 	EndDate string `form:"endDate"`
 }
+
+type AddReq struct {
+	UserId         string `form:"userId"`
+	AppId          int64  `form:"appId"`
+	PointType      int64  `form:"pointType"`
+	BusinessTypeId int64  `form:"businessTypeId"`
+	BusinessType   string `form:"businessType"`
+	Point          int64  `form:"point"`
+	EndDate        string `form:"endDate"`
+	OperationType  bool   `form:"operationType"`
+}
+
+type AddResp struct {
+	Code    int64  `form:"code"`
+	Message string `form:"message"`
+}
+
+type ConsumeReq struct {
+	UserId         string `form:"userId"`
+	AppId          int64  `form:"appId"`
+	PointType      int64  `form:"pointType"`
+	BusinessTypeId int64  `form:"businessTypeId"`
+	BusinessType   string `form:"businessType"`
+	Point          int64  `form:"point"`
+	EndDate        string `form:"endDate"`
+}
+
+type ConsumeResp struct {
+	Code    int64  `form:"code"`
+	Message string `form:"message"`
+}

+ 14 - 13
service/integralService.go

@@ -20,21 +20,19 @@ func (service *IntegralService) IntegralAddService(data entity.FlowJSON) (int64,
 	flow.PointType = data.PointType
 	flow.Point = data.Point
 	flow.CreateTime = time.Now().Format("2006-01-02 15:04:05")
-	flow.EndDate = data.EndDate
 	flow.AppId = data.AppId
 	flow.Sort = entity.AddCode
 	var err error
 	var numb = int64(0)
 	numb, err = orm.Table("integral_flow").Insert(flow)
 	if err != nil && numb == 0 {
-		log.Print("新增流水失败")
+		log.Print("新增流水失败:",err)
 		return entity.ErrorCode, "新增流水失败"
 	}
 	//结存修改
 	solde := entity.Solde{}
 	solde.AppId = data.AppId
 	solde.UserId = data.UserId
-	solde.EndDate = data.EndDate
 	if data.OperationType {
 		//永久积分
 		//先查看是否有EndDate的积分
@@ -44,7 +42,7 @@ func (service *IntegralService) IntegralAddService(data entity.FlowJSON) (int64,
 			soldelist[0].PerManEntPoints += data.Point
 			numb, err = orm.Table("integral_solde").ID(soldelist[0].Id).Cols("perManEntPoints").Update(soldelist[0])
 			if err != nil && numb == 0 {
-				log.Print("修改时效积分失败")
+				log.Print("修改时效积分失败:",err)
 				return entity.ErrorCode, "修改时效积分失败"
 			}
 		} else {
@@ -57,6 +55,7 @@ func (service *IntegralService) IntegralAddService(data entity.FlowJSON) (int64,
 		}
 
 	} else {
+		solde.EndDate = data.EndDate
 		//先查看是否有EndDate的积分
 		soldelist := []entity.Solde{}
 		err = orm.Table("integral_solde").Where("appId=? and  userId=? and endDate=? and ( perManEntPoints = 0 AND timePoints != 0) or (perManEntPoints = 0 AND timePoints = 0 ) ", data.AppId, data.UserId, data.EndDate).Find(&soldelist)
@@ -64,14 +63,14 @@ func (service *IntegralService) IntegralAddService(data entity.FlowJSON) (int64,
 			soldelist[0].TimePoints += data.Point
 			numb, err = orm.Table("integral_solde").ID(soldelist[0].Id).Cols("timePoints").Update(soldelist[0])
 			if err != nil && numb == 0 {
-				log.Print("修改时效积分失败")
+				log.Print("修改时效积分失败:",err)
 				return entity.ErrorCode, "修改时效积分失败"
 			}
 		} else {
 			solde.TimePoints = data.Point
 			numb, err = orm.Table("integral_solde").Insert(&solde)
 			if err != nil && numb == 0 {
-				log.Print("新增时效积分失败")
+				log.Print("新增时效积分失败:",err)
 				return entity.ErrorCode, "新增时效积分失败"
 			}
 		}
@@ -87,7 +86,7 @@ func (service *IntegralService) IntegralAddService(data entity.FlowJSON) (int64,
 		balance.CountPoints = data.Point
 		numb, err = entity.Engine.Table("integral_balance").Insert(&balance)
 		if err != nil && numb == 0 {
-			log.Print("新增余额失败")
+			log.Print("新增余额失败:",err)
 			return entity.ErrorCode, "新增余额失败"
 		}
 	} else {
@@ -95,7 +94,7 @@ func (service *IntegralService) IntegralAddService(data entity.FlowJSON) (int64,
 		balanceList[0].CountPoints = balanceList[0].CountPoints + data.Point
 		numb, err = entity.Engine.Table("integral_balance").ID(balanceList[0].Id).Cols("countPoints").Update(balanceList[0])
 		if err != nil && numb == 0 {
-			log.Print("余额新增失败")
+			log.Print("余额新增失败:",err)
 			return entity.ErrorCode, "余额新增失败"
 		}
 	}
@@ -132,7 +131,7 @@ func (service *IntegralService) IntegralConsumeService(data entity.FlowJSON) (in
 	//结存消耗
 	soldelist := []entity.Solde{}
 	err = entity.Engine.Table("integral_solde").
-		Where("appId=? and  userId=? and endDate>= ? and( 	( perManEntPoints != 0 AND timePoints = 0 ) OR ( perManEntPoints = 0 AND timePoints != 0 ))", data.AppId, data.UserId, time.Now().Format("2006-01-02")).
+		Where("appId=? and  userId=? and(endDate =‘’ or endDate>= ?) and( 	( perManEntPoints != 0 AND timePoints = 0 ) OR ( perManEntPoints = 0 AND timePoints != 0 ))", data.AppId, data.UserId, time.Now().Format("2006-01-02")).
 		Desc("endDate").
 		Desc("timePoints").Find(&soldelist)
 	if len(soldelist) == 0 {
@@ -154,7 +153,7 @@ func (service *IntegralService) IntegralConsumeService(data entity.FlowJSON) (in
 					Cols("perManEntPoints").
 					Update(solde)
 				if err != nil && af == 0 {
-					log.Print("消耗永久积分失败")
+					log.Print("消耗永久积分失败:",err)
 					return entity.ErrorCode, "消耗永久积分失败"
 				}
 			}
@@ -169,7 +168,7 @@ func (service *IntegralService) IntegralConsumeService(data entity.FlowJSON) (in
 					Cols("timePoints").
 					Update(solde)
 				if err != nil && af == 0 {
-					log.Print("消耗时效积分失败")
+					log.Print("消耗时效积分失败:",err)
 					return entity.ErrorCode, "消耗时效积分失败"
 				}
 				break
@@ -182,7 +181,7 @@ func (service *IntegralService) IntegralConsumeService(data entity.FlowJSON) (in
 				Cols("timePoints").
 				Update(solde)
 			if err != nil && af == 0 {
-				log.Print("消耗时效积分失败")
+				log.Print("消耗时效积分失败:",err)
 				return entity.ErrorCode, "消耗时效积分失败"
 			}
 		}
@@ -196,7 +195,7 @@ func (service *IntegralService) IntegralConsumeService(data entity.FlowJSON) (in
 		Cols("countPoints").
 		Update(balance)
 	if err != nil && af == 0 {
-		log.Print("余额扣除失败")
+		log.Print("余额扣除失败:",err)
 		return entity.ErrorCode, "余额扣除失败"
 	}
 	return entity.SuccessCode, "积分消耗成功"
@@ -457,6 +456,8 @@ func (service *IntegralService) IntegralDetailedCheck(data entity.FlowJSON) ([]*
 		point.BusinessTypeId=value.BusinessTypeId
 		point.BusinessType=value.BusinessType
 		point.Name=value.Name
+		point.UserId=value.UserId
+		point.AppId=value.AppId
 		flowReq=append(flowReq,&point )
 	}
 	fmt.Println(flowList)