Pārlūkot izejas kodu

价格驱动详情

hsun 2 gadi atpakaļ
vecāks
revīzija
c4a050e07c

+ 28 - 2
controller/price_driven/price_driven.go

@@ -2,8 +2,34 @@ package price_driven
 
 import (
 	"github.com/gin-gonic/gin"
+	"hongze/hongze_yb/controller/response"
+	"hongze/hongze_yb/models/request"
+	"hongze/hongze_yb/services/price_driven"
+	"hongze/hongze_yb/services/user"
 )
 
-func GetPriceDrivenDetail(c *gin.Context)  {
-
+// PriceDrivenDetail 价格驱动详情
+// @Tags 价格驱动模块
+// @Description 获取价格驱动详情
+// @Param chart_permission_id  query  int  true  "品种ID"
+// @Success 200 {object} response.PriceDrivenItem
+// @failure 400 {string} string "获取失败"
+// @Router /price_driven/detail [get]
+func PriceDrivenDetail(c *gin.Context)  {
+	var req request.PriceDrivenDetailReq
+	if err := c.Bind(&req); err != nil {
+		response.Fail("参数有误", c)
+		return
+	}
+	if req.ChartPermissionId <= 0 {
+		response.Fail("参数有误", c)
+		return
+	}
+	userInfo := user.GetInfoByClaims(c)
+	item, errMsg, err := price_driven.GetPriceDrivenDetail(req.ChartPermissionId, userInfo)
+	if err != nil {
+		response.FailMsg(errMsg, "GetPriceDrivenDetail ErrMsg:"+err.Error(), c)
+		return
+	}
+	response.OkData("获取成功", item, c)
 }

+ 2 - 0
init_serve/router.go

@@ -60,5 +60,7 @@ func InitRouter() (r *gin.Engine) {
 	routers.InitMessage(r)
 	//pc相关路由
 	routers.InitPc(r)
+	// 价格驱动相关路由
+	routers.InitPriceDriven(r)
 	return
 }

+ 5 - 0
models/request/price_driven.go

@@ -0,0 +1,5 @@
+package request
+
+type PriceDrivenDetailReq struct {
+	ChartPermissionId int `json:"chart_permission_id" form:"chart_permission_id"`
+}

+ 15 - 0
models/response/price_driven.go

@@ -0,0 +1,15 @@
+package response
+
+// PriceDrivenItem 价格驱动详情
+type PriceDrivenItem struct {
+	PriceDrivenID       int                 `json:"price_driven_id" description:"价格驱动ID"`
+	ChartPermissionID   int                 `json:"chart_permission_id" description:"品种ID"`
+	MainVariable        string              `json:"main_variable" description:"关键变量"`
+	CoreDrivenType      int                 `json:"core_driven_type" description:"核心驱动类型 0-多 1-空"`
+	CoreDrivenContent   string              `json:"core_driven_content" description:"核心驱动内容"`
+	CoreContent         string              `json:"core_content" description:"核心内容"`
+	CreateTime          string              `json:"create_time" description:"创建时间"`
+	ModifyTime          string              `json:"modify_time" description:"更新时间"`
+	AuthOk              bool                `json:"auth_ok" description:"是否有权限"`
+	PermissionCheckInfo PermissionCheckInfo `json:"permission_check_info" description:"权限信息详情"`
+}

+ 12 - 0
routers/price_driven.go

@@ -0,0 +1,12 @@
+package routers
+
+import (
+	"github.com/gin-gonic/gin"
+	"hongze/hongze_yb/controller/price_driven"
+	"hongze/hongze_yb/middleware"
+)
+
+func InitPriceDriven(r *gin.Engine)  {
+	rGroup := r.Group("api/price_driven").Use(middleware.Token())
+	rGroup.GET("/detail", price_driven.PriceDrivenDetail)
+}

+ 61 - 44
services/company/permission.go

@@ -22,6 +22,12 @@ import (
 	"time"
 )
 
+var (
+	CheckTypeApply   = "apply"
+	CheckTypeContact = "contact"
+	CheckTypeExpire  = "expired"
+)
+
 // GetClassNameListByProductId 根据权限id获取权限分类
 func GetClassNameListByProductId(productId int64) (list []*chart_permission.ChartPermission, err error) {
 	list, err = chart_permission.GetClassNameListByProductId(productId)
@@ -90,59 +96,70 @@ type CustomerInfo struct {
 	HasApply    bool   `json:"has_apply" description:"是否有申请过"`
 }
 
-// CheckPermissionByFicc 权限校验
-func CheckPermissionByFicc(companyId int64, permissionId int) (ok bool, permissionCheckInfo PermissionCheckInfo, err error) {
-	//非潜在客户
-	var productId int64
-	productId = 1
-	if companyId > 1 {
-		//查询是否 开通ficc的客户
-		companyProductInfo, tmpErr := company_product.GetByCompany2ProductId(companyId, productId)
-		if tmpErr != nil {
-			// 没有开通ficc的客户
-			if tmpErr == utils.ErrNoRow {
-				permissionCheckInfo.Type = "apply"
-				return
+// CheckBaseFiccPermission 校验用户基本的FICC权限
+func CheckBaseFiccPermission(companyId int64, userId int) (ok bool, checkInfo response.PermissionCheckInfo, permissionIdArr []int, err error) {
+	defer func() {
+		// 无权限查询是否有申请记录
+		if !ok {
+			if checkInfo.Type == CheckTypeApply {
+				if _, e := yb_apply_record.GetLastNotOpRecordByUserId(userId); e == nil {
+					checkInfo.CustomerInfo.HasApply = true
+				}
 			}
-			err = tmpErr
-			return
 		}
-
-		// 如果客户ficc产品的状态是流失,那么也是让去申请
-		if companyProductInfo.Status == "流失" {
-			permissionCheckInfo.Type = "apply"
+	}()
+	// 潜在用户
+	if companyId == 1 {
+		checkInfo.Type = CheckTypeApply
+		return
+	}
+	// 是否开通FICC
+	productId := int64(1)
+	productInfo, e := company_product.GetByCompany2ProductId(companyId, productId)
+	if e != nil {
+		if e == utils.ErrNoRow {
+			checkInfo.Type = CheckTypeApply
 			return
 		}
-		// 获取有效的权限id列表
-		validPermissionIdList, tmpErr := GetValidPermissionIdListByCompany2ProductId(companyId, productId)
-		if tmpErr != nil {
-			err = tmpErr
+		err = errors.New("获取用户FICC权限失败 Err:" + e.Error())
+		return
+	}
+	// 客户状态是否为流失
+	if productInfo.Status == "流失" {
+		checkInfo.Type = CheckTypeApply
+		return
+	}
+	// 是否为弘则研究已禁用的联系人
+	if companyId == 16 {
+		userInfo, e := wx_user.GetByUserId(userId)
+		if e != nil {
+			err = errors.New("用户信息异常 Err:" + e.Error())
 			return
 		}
-		// 校验在有效的权限id列表中是否存在该权限
-		for _, validPermissionId := range validPermissionIdList {
-			//如果有该权限id,那么直接返回校验通过
-			if validPermissionId == permissionId {
-				ok = true
-				return
-			}
-		}
-		//查找对应客户的销售信息
-
-		adminInfo, tmpErr := admin.GetByAdminId(companyProductInfo.SellerID)
-		if tmpErr != nil {
-			err = tmpErr
+		if userInfo.Enabled != 1 {
+			checkInfo.Type = CheckTypeApply
 			return
 		}
-		permissionCheckInfo = PermissionCheckInfo{
-			Name:   adminInfo.RealName,
-			Mobile: adminInfo.Mobile,
-			Type:   "contact",
-		}
-	} else {
-		permissionCheckInfo.Type = "apply"
 	}
-
+	// 客户对应的销售信息
+	sellerInfo, e := admin.GetByAdminId(productInfo.SellerID)
+	if e != nil {
+		err = errors.New("获取用户销售信息失败 Err:" + e.Error())
+		return
+	}
+	checkInfo.Name = sellerInfo.RealName
+	checkInfo.Mobile = sellerInfo.Mobile
+	if productInfo.Status == "冻结" || (productInfo.Status == "试用" && productInfo.IsSuspend == 1) {
+		checkInfo.Type = CheckTypeContact
+		return
+	}
+	// 正常用户, 获取有效权限
+	permissionIdArr, e = GetValidPermissionIdListByCompany2ProductId(companyId, productId)
+	if e != nil {
+		err = errors.New("获取用户有效权限列表失败 Err:" + e.Error())
+		return
+	}
+	ok = true
 	return
 }
 

+ 51 - 0
services/price_driven/price_driven.go

@@ -0,0 +1,51 @@
+package price_driven
+
+import (
+	"errors"
+	"hongze/hongze_yb/models/response"
+	"hongze/hongze_yb/models/tables/yb_price_driven"
+	"hongze/hongze_yb/services/company"
+	"hongze/hongze_yb/services/user"
+	"hongze/hongze_yb/utils"
+)
+
+// GetPriceDrivenDetail 获取价格驱动详情
+func GetPriceDrivenDetail(chartPermissionId int, userInfo user.UserInfo) (resp *response.PriceDrivenItem, errMsg string, err error) {
+	resp = new(response.PriceDrivenItem)
+	// 获取详情
+	item, e := yb_price_driven.GetPriceDrivenByChartPermissionId(chartPermissionId)
+	if e != nil && e != utils.ErrNoRow {
+		errMsg = "获取失败"
+		err = errors.New("获取价格驱动信息失败, Err:" + e.Error())
+		return
+	}
+	if item != nil {
+		resp.PriceDrivenID = item.PriceDrivenID
+		resp.ChartPermissionID = item.ChartPermissionID
+		resp.MainVariable = item.MainVariable
+		resp.CoreDrivenType = item.CoreDrivenType
+		resp.CoreDrivenContent = item.CoreDrivenContent
+		resp.CoreContent = item.CoreContent
+		resp.CreateTime = item.CreateTime.Format(utils.FormatDateTime)
+		resp.ModifyTime = item.ModifyTime.Format(utils.FormatDateTime)
+	}
+	// 校验权限
+	ok, permissionInfo, permissionIdArr, e := company.CheckBaseFiccPermission(userInfo.CompanyID, int(userInfo.UserID))
+	if e != nil {
+		errMsg = "获取失败"
+		err = errors.New("校验价格驱动详情权限失败, Err:" + e.Error())
+		return
+	}
+	authOk := false
+	// 用户状态正常时校验是否有对应的品种权限, 不正常则默认无权限
+	if ok {
+		for _, v := range permissionIdArr {
+			if chartPermissionId == v {
+				authOk = true
+			}
+		}
+	}
+	resp.AuthOk = authOk
+	resp.PermissionCheckInfo = permissionInfo
+	return
+}