WH01243 4 năm trước cách đây
mục cha
commit
b4fa5abfc8

+ 6 - 1
api/integral.api

@@ -82,7 +82,9 @@ type (
 		Message string `form:"message"`
 	}
 )
-
+type guardReq {
+	EndDate string `form:"endDate"`
+}
 service integral-api {
 	//积分余额查询
 	@handler IntegralBalanceCheckHandler // TODO: set handler name and delete this comment
@@ -99,4 +101,7 @@ service integral-api {
 	//查询某月积分明细
 	@handler IntegralDetailedCheckHandler // TODO: set handler name and delete this comment
 	get /integralDetailedCheck (DetailedReq) returns(RespList)
+	//积分守护
+    @handler IntegralGuardHandler // TODO: set handler name and delete this comment
+    post /integralGuard (guardReq) returns(response)
 }

+ 29 - 0
api/internal/handler/integralguardhandler.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 IntegralGuardHandler(ctx *svc.ServiceContext) http.HandlerFunc {
+	return func(w http.ResponseWriter, r *http.Request) {
+		var req types.GuardReq
+		if err := httpx.Parse(r, &req); err != nil {
+			httpx.Error(w, err)
+			return
+		}
+
+		l := logic.NewIntegralGuardLogic(r.Context(), ctx)
+		resp, err := l.IntegralGuard(req)
+		if err != nil {
+			httpx.Error(w, err)
+		} else {
+			httpx.OkJson(w, resp)
+		}
+	}
+}

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

@@ -37,6 +37,11 @@ func RegisterHandlers(engine *rest.Server, serverCtx *svc.ServiceContext) {
 				Path:    "/integralDetailedCheck",
 				Handler: IntegralDetailedCheckHandler(serverCtx),
 			},
+			{
+				Method:  http.MethodPost,
+				Path:    "/integralGuard",
+				Handler: IntegralGuardHandler(serverCtx),
+			},
 		},
 	)
 }

+ 2 - 1
api/internal/logic/integralconsumelogic.go

@@ -24,6 +24,7 @@ func NewIntegralConsumeLogic(ctx context.Context, svcCtx *svc.ServiceContext) In
 	}
 }
 
+
 //积分消耗
 func (l *IntegralConsumeLogic) IntegralConsume(req types.ConsumeReq) (*types.ConsumeResp, error) {
 	// todo: add your logic here and delete this line
@@ -35,8 +36,8 @@ func (l *IntegralConsumeLogic) IntegralConsume(req types.ConsumeReq) (*types.Con
 		EndDate:        req.EndDate,
 		BusinessType:   req.BusinessType,
 		BusinessTypeId: req.BusinessTypeId,
-		Point:          req.Point,
 		PointType:      req.PointType,
+		Point:          req.Point,
 	})
 	if err != nil {
 		return nil, err

+ 40 - 0
api/internal/logic/integralguardlogic.go

@@ -0,0 +1,40 @@
+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 IntegralGuardLogic struct {
+	logx.Logger
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+}
+
+func NewIntegralGuardLogic(ctx context.Context, svcCtx *svc.ServiceContext) IntegralGuardLogic {
+	return IntegralGuardLogic{
+		Logger: logx.WithContext(ctx),
+		ctx:    ctx,
+		svcCtx: svcCtx,
+	}
+}
+
+func (l *IntegralGuardLogic) IntegralGuard(req types.GuardReq) (*types.Response, error) {
+	// todo: add your logic here and delete this line
+	result := &types.Response{}
+	lsi := l.svcCtx.Integral
+	resp, err := lsi.IntegralGuard(l.ctx, &integral.Req{
+		EndDate:        req.EndDate,
+	})
+	if err != nil {
+		return nil, err
+	}
+	result.Code = resp.Code
+	result.Message = resp.Message
+	return result, nil
+}

+ 1 - 1
api/internal/types/types.go

@@ -62,7 +62,6 @@ type AddResp struct {
 	Code    int64  `form:"code"`
 	Message string `form:"message"`
 }
-
 type ConsumeReq struct {
 	UserId         string `form:"userId"`
 	AppId          int64  `form:"appId"`
@@ -73,6 +72,7 @@ type ConsumeReq struct {
 	EndDate        string `form:"endDate"`
 }
 
+
 type ConsumeResp struct {
 	Code    int64  `form:"code"`
 	Message string `form:"message"`

+ 20 - 12
service/integralService.go

@@ -105,16 +105,6 @@ func (service *IntegralService) IntegralAddService(data entity.FlowJSON) (int64,
 func (service *IntegralService) IntegralConsumeService(data entity.FlowJSON) (int64, string) {
 	var af = int64(0)
 	orm := entity.Engine
-	flow := entity.Flow{}
-	flow.UserId = data.UserId
-	flow.PointType = data.PointType
-	flow.BusinessTypeId = data.BusinessTypeId
-	flow.BusinessType = data.BusinessType
-	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.ReduceCode
 	balance := entity.Balance{}
 	//查询积分余额是否充足
 	b, err := orm.Table("integral_balance").Select("countPoints,id").
@@ -131,7 +121,7 @@ func (service *IntegralService) IntegralConsumeService(data entity.FlowJSON) (in
 	//结存消耗
 	soldelist := []entity.Solde{}
 	err = entity.Engine.Table("integral_solde").
-		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")).
+		Where("appId=? and  userId=? and (endDate ='' or endDate is NULL 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 {
@@ -198,6 +188,23 @@ func (service *IntegralService) IntegralConsumeService(data entity.FlowJSON) (in
 		log.Print("余额扣除失败:",err)
 		return entity.ErrorCode, "余额扣除失败"
 	}
+
+	//消耗积分流水记录
+	flow := entity.Flow{}
+	flow.UserId = data.UserId
+	flow.PointType = data.PointType
+	flow.BusinessTypeId = data.BusinessTypeId
+	flow.BusinessType = data.BusinessType
+	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.ReduceCode
+	af, err = orm.Table("integral_flow").Insert(&flow)
+		if err != nil && af == 0 {
+			log.Print("积分记录失败")
+			return entity.ErrorCode, "积分记录失败"
+		}
 	return entity.SuccessCode, "积分消耗成功"
 }
 
@@ -391,13 +398,14 @@ func (service *IntegralService) IntegralGuardService(endDate string) bool {
 		//积分过期流水记录
 		flow := entity.Flow{}
 		flow.UserId = solde.UserId
-		flow.PointType = 9
+		flow.PointType = 2004
 		flow.BusinessTypeId = 0
 		flow.BusinessType = "0"
 		flow.Point = solde.TimePoints
 		flow.CreateTime = time.Now().Format("2006-01-02 15:04:05")
 		flow.EndDate = solde.EndDate
 		flow.AppId = solde.AppId
+		flow.Sort = entity.ReduceCode
 		af, err := orm.Table("integral_flow").Insert(&flow)
 		if err != nil && af == 0 {
 			log.Print("积分记录失败")