Jelajahi Sumber

feat:新增api

wangchuanjin 3 tahun lalu
induk
melakukan
fa867663e9

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

@@ -22,6 +22,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
 				Path:    "/resourceCenter/haspowers",
 				Handler: haspowersHandler(serverCtx),
 			},
+			{
+				Method:  http.MethodPost,
+				Path:    "/resourceCenter/waitEmpowerDetail",
+				Handler: waitEmpowerDetailHandler(serverCtx),
+			},
 		},
 	)
 }

+ 28 - 0
api/internal/handler/waitempowerdetailhandler.go

@@ -0,0 +1,28 @@
+package handler
+
+import (
+	"net/http"
+
+	"bp.jydev.jianyu360.cn/BaseService/resourceCenter/api/internal/logic"
+	"bp.jydev.jianyu360.cn/BaseService/resourceCenter/api/internal/svc"
+	"bp.jydev.jianyu360.cn/BaseService/resourceCenter/api/internal/types"
+	"github.com/zeromicro/go-zero/rest/httpx"
+)
+
+func waitEmpowerDetailHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
+	return func(w http.ResponseWriter, r *http.Request) {
+		var req types.Req
+		if err := httpx.Parse(r, &req); err != nil {
+			httpx.Error(w, err)
+			return
+		}
+
+		l := logic.NewWaitEmpowerDetailLogic(r.Context(), svcCtx)
+		resp, err := l.WaitEmpowerDetail(&req)
+		if err != nil {
+			httpx.Error(w, err)
+		} else {
+			httpx.OkJson(w, resp)
+		}
+	}
+}

+ 3 - 1
api/internal/logic/surplusdetaillogic.go

@@ -6,7 +6,9 @@ import (
 
 	"bp.jydev.jianyu360.cn/BaseService/resourceCenter/api/internal/svc"
 	"bp.jydev.jianyu360.cn/BaseService/resourceCenter/api/internal/types"
+	. "bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/entity"
 	. "bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/service"
+
 	"github.com/zeromicro/go-zero/core/logx"
 )
 
@@ -46,7 +48,7 @@ func (l *SurplusDetailLogic) SurplusDetail(req *types.Req) (resp *types.Reply, e
 		l.Error(fmt.Sprintf("%+v", req), resp.Error_msg)
 	}
 	resp.Error_code = status
-	resp.Data = &types.SurplusData{
+	resp.Data = &SurplusData{
 		Total:   total,
 		Surplus: surplus,
 	}

+ 46 - 0
api/internal/logic/waitempowerdetaillogic.go

@@ -0,0 +1,46 @@
+package logic
+
+import (
+	"context"
+	"fmt"
+
+	"bp.jydev.jianyu360.cn/BaseService/resourceCenter/api/internal/svc"
+	"bp.jydev.jianyu360.cn/BaseService/resourceCenter/api/internal/types"
+	. "bp.jydev.jianyu360.cn/BaseService/resourceCenter/public/service"
+
+	"github.com/zeromicro/go-zero/core/logx"
+)
+
+type WaitEmpowerDetailLogic struct {
+	logx.Logger
+	ctx    context.Context
+	svcCtx *svc.ServiceContext
+}
+
+func NewWaitEmpowerDetailLogic(ctx context.Context, svcCtx *svc.ServiceContext) *WaitEmpowerDetailLogic {
+	return &WaitEmpowerDetailLogic{
+		Logger: logx.WithContext(ctx),
+		ctx:    ctx,
+		svcCtx: svcCtx,
+	}
+}
+
+func (l *WaitEmpowerDetailLogic) WaitEmpowerDetail(req *types.Req) (resp *types.Reply, err error) {
+	resp = &types.Reply{}
+	if req.AppId == "" {
+		resp.Error_msg = "无效的参数appid"
+		l.Error(fmt.Sprintf("%+v", req), resp.Error_msg)
+		return resp, nil
+	} else if req.Function_code == "" {
+		resp.Error_msg = "无效的参数function_code"
+		l.Error(fmt.Sprintf("%+v", req), resp.Error_msg)
+		return resp, nil
+	} else if req.Ent_id == 0 {
+		resp.Error_msg = "无效的参数ent_id"
+		l.Error(fmt.Sprintf("%+v", req), resp.Error_msg)
+		return resp, nil
+	}
+	resp.Error_code = 0
+	resp.Data = WaitEmpowerDetail(req.AppId, req.Function_code, req.Ent_id)
+	return
+}

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

@@ -9,11 +9,6 @@ type Req struct {
 	Ent_user_id   int64  `header:"entUserId,optional"`
 }
 
-type SurplusData struct {
-	Surplus int64 `json:"surplus"`
-	Total   int64 `json:"total"`
-}
-
 type Reply struct {
 	Error_code int64       `json:"error_code"`
 	Error_msg  string      `json:"error_msg"`

+ 3 - 5
api/resource.api

@@ -15,11 +15,6 @@ type (
 		Ent_user_id   int64  `header:"entUserId,optional"`
 	}
 
-	surplusData {
-		Surplus int64 `json:"surplus"`
-		Total   int64 `json:"total"`
-	}
-
 	Reply {
 		Error_code int64       `json:"error_code"`
 		Error_msg  string      `json:"error_msg"`
@@ -34,4 +29,7 @@ service resource {
 	@doc "获取所有的权益"
 	@handler haspowers
 	post /resourceCenter/haspowers (Req) returns (Reply)
+	@doc "获取待授权详情"
+	@handler waitEmpowerDetail
+	post /resourceCenter/waitEmpowerDetail (Req) returns (Reply)
 }

+ 14 - 0
public/entity/entity.go

@@ -0,0 +1,14 @@
+package entity
+
+type SurplusData struct {
+	Surplus int64 `json:"surplus"`
+	Total   int64 `json:"total"`
+}
+
+type WaitEmpowerData struct {
+	Start_time     string `json:"start_time"`
+	End_time       string `json:"end_time"`
+	Empower_count  int    `json:"empower_count"`
+	Use_count      int    `json:"use_count"`
+	Limit_strategy string `json:"limit_strategy"`
+}

+ 24 - 1
public/service/power.go

@@ -6,11 +6,34 @@ import (
 )
 
 /*
- * 获取已有的权益
+ * 获取待授权详情
  * @param appid
  * @param function_code 功能代码
+ * @param ent_id 企业id
+ * @return 待授权详情
+ */
+func WaitEmpowerDetail(appid, function_code string, ent_id int64) *WaitEmpowerData {
+	bewes := Base_ent_wait_empower.WaitEmpowers(appid, function_code, ent_id)
+	result := &WaitEmpowerData{}
+	if bewes != nil {
+		for _, v := range *bewes {
+			result.Empower_count = v.Empower_count
+			result.Limit_strategy = v.Limit_strategy
+			result.Start_time = v.Start_time
+			result.End_time = v.End_time
+			result.Use_count = v.Use_count
+			break
+		}
+	}
+	return result
+}
+
+/*
+ * 获取已有的权益
+ * @param appid
  * @param user_id 用户id
  * @param ent_id 企业id
+ * @param ent_user_id 企业用户id
  * @return 所有已开通的权益
  */
 func HasPowers(appid string, user_id, ent_id, ent_user_id int64) []string {

+ 5 - 0
public/service/power_test.go

@@ -36,3 +36,8 @@ func TestEmpowerList(t *testing.T) {
 	count, list := EmpowerList("10000", "znsj_kf_use", 14184, 2, 1)
 	t.Log(count, list)
 }
+
+func TestWaitEmpowerDetail(t *testing.T) {
+	r := WaitEmpowerDetail("10000", "znsj_kf_use", 14184)
+	t.Log(r)
+}