123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258 |
- package controllers
- import (
- "fmt"
- companyContractResp "hongze/hongze_mobile_admin/models/response/company_contract"
- "hongze/hongze_mobile_admin/models/tables/company_contract"
- "hongze/hongze_mobile_admin/models/tables/company_product"
- "hongze/hongze_mobile_admin/models/tables/company_report_permission"
- "hongze/hongze_mobile_admin/services"
- "hongze/hongze_mobile_admin/services/contract"
- "hongze/hongze_mobile_admin/utils"
- "strings"
- )
- // 客户合同模块
- type CompanyContractCommon struct {
- BaseAuth
- }
- // @Title 合同详情详情
- // @Description 合同详情接口
- // @Param CompanyId query int true "客户ID"
- // @Param CompanyContractId query int true "合同id"
- // @Success 200 {object} company_contract.CompanyContractDetailResp
- // @router /detail [get]
- func (c *CompanyContractCommon) ApplyContractDetail() {
- sysUser := c.AdminWx
- companyId, _ := c.GetInt("CompanyId")
- if companyId <= 0 {
- c.FailWithMessage("参数错误", "参数错误,客户id小于等于0")
- return
- }
- companyContractId, _ := c.GetInt("CompanyContractId")
- roleTypeCode := sysUser.RoleTypeCode
- productId := services.GetProductId(roleTypeCode)
- //if productId == 0 {
- // c.FailWithMessage("当前账户类型异常", "客户类型为:"+roleTypeCode)
- // return
- //}
- detail, err := company_contract.GetCompanyContractDetail(companyId, productId, companyContractId)
- if err != nil {
- c.FailWithMessage("获取信息失败", "获取信息失败,Err:"+err.Error())
- return
- }
- if detail.ProductId == utils.COMPANY_PRODUCT_FICC_ID {
- allFiccPermissions, e := company_report_permission.GetPermissionLookItemsByProductId(utils.COMPANY_PRODUCT_FICC_ID)
- if e != nil {
- c.FailWithMessage("获取权限信息失败", "获取权限信息失败,Err:"+err.Error())
- return
- }
- permissionMap := make(map[int][]*company_report_permission.PermissionLookItem, 0)
- for _, v := range allFiccPermissions {
- if v.ParentId > 0 {
- permissionMap[v.ParentId] = append(permissionMap[v.ParentId], v)
- }
- }
- for _, v := range allFiccPermissions {
- if v.ParentId == 0 {
- plist := new(company_report_permission.PermissionLookList)
- plist.Items = make([]*company_report_permission.PermissionLookItem, 0)
- plist.CheckList = make([]int, 0)
- items, ok := permissionMap[v.ChartPermissionId]
- if ok {
- plist.Items = items
- for _, n := range items {
- count, err := company_contract.GetCompanyContractPermissionCheckByContractId(companyId, detail.CompanyContractId, n.ChartPermissionId)
- if err != nil {
- c.FailWithMessage("获取失败", "获取权限信息失败,Err:"+err.Error())
- return
- }
- if count > 0 {
- plist.CheckList = append(plist.CheckList, n.ChartPermissionId)
- }
- }
- }
- plist.ClassifyName = v.PermissionName
- detail.PermissionList = append(detail.PermissionList, plist)
- }
- }
- /*for _, v := range utils.PermissionFiccClassifyArr {
- checkList := make([]int, 0)
- plist := new(company_report_permission.PermissionLookList)
- items, err := company_report_permission.GetPermissionLookItems(detail.ProductId, v)
- if err != nil {
- c.FailWithMessage("获取失败", "获取权限信息失败,Err:"+err.Error())
- return
- }
- for _, n := range items {
- count, err := company_contract.GetCompanyContractPermissionCheckByContractId(companyId, detail.CompanyContractId, n.ChartPermissionId)
- if err != nil {
- c.FailWithMessage("获取失败", "获取权限信息失败,Err:"+err.Error())
- return
- }
- if count > 0 {
- checkList = append(checkList, n.ChartPermissionId)
- }
- }
- plist.Items = items
- plist.ClassifyName = v
- plist.CheckList = checkList
- detail.PermissionList = append(detail.PermissionList, plist)
- }*/
- }
- if detail.ProductId == utils.COMPANY_PRODUCT_RAI_ID {
- classifyName := "权益"
- checkList := make([]int, 0)
- plist := new(company_report_permission.PermissionLookList)
- plist.ClassifyName = classifyName
- items, err := company_report_permission.GetPermissionLookItems(detail.ProductId, classifyName)
- if err != nil {
- c.FailWithMessage("获取失败", "获取权限信息失败,Err:"+err.Error())
- return
- }
- mapExpensive := make(map[int]bool) // 通过合同获取所勾选的买方研选5w
- permissionList, err := company_report_permission.GetCompanyContractPermissionByCompanyContractId(companyContractId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- c.FailWithMessage("获取失败", "获取合同权限信息失败,Err:"+err.Error())
- return
- }
- permissions := make([]int, 0) // 合同权限IDs
- checkItems := make([]*company_report_permission.PermissionLookItem, 0)
- //expMap := map[bool]string{false: "(3w)", true: "(5w)"} // 买方研选价格
- //var expensiveYx int
- // 未选大套餐, 走老逻辑
- var points float64
- if detail.RaiPackageType == 0 {
- mapUpgrade := make(map[int]bool) // 通过合同获取所勾选的升级行业权限
- totalForever, err := company_product.GetCompanyProductRaiForeverCount(companyId) //判断是否是权益的永续客户
- if err != nil {
- c.FailWithMessage("获取失败", "判断是否是权益的永续客户失败,Err:"+err.Error())
- return
- }
- if totalForever > 0 {
- detail.Quarter, err = utils.GetQuarterStrStartDatesInRange(detail.StartDate, detail.EndDate) //通过开始时间,结束时间,获取对应季度的拼接字符串
- if err != nil {
- c.FailWithMessage("获取失败", "获取季度息失败,Err:"+err.Error())
- return
- }
- }
- for _, v := range permissionList {
- if v.IsUpgrade == 1 {
- mapUpgrade[v.ChartPermissionId] = true
- }
- if v.ExpensiveYx > 0 {
- mapExpensive[v.ChartPermissionId] = true
- //expensiveYx = v.ExpensiveYx
- }
- if v.Points > 0 && v.ChartPermissionId == utils.YAN_XUAN_KOU_DIAN_BAO_ID {
- points = v.Points
- }
- permissions = append(permissions, v.ChartPermissionId)
- }
- for _, n := range items {
- if points > 0 && n.ChartPermissionId == utils.YAN_XUAN_KOU_DIAN_BAO_ID {
- n.PermissionName += fmt.Sprint("(", points, "点)")
- }
- if utils.InArrayByInt(permissions, n.ChartPermissionId) {
- checkList = append(checkList, n.ChartPermissionId)
- checkItems = append(checkItems, n)
- }
- }
- plist.Items = checkItems
- plist.CheckList = checkList
- detail.PermissionList = append(detail.PermissionList, plist)
- newPermissionLookList := contract.HandleEquityPermissionLookList(detail.PermissionList)
- for _, cc := range newPermissionLookList {
- if cc.ClassifyName != "权益" {
- continue
- }
- for _, p := range cc.Items {
- // 行业升级
- if mapUpgrade[p.ChartPermissionId] {
- if strings.Contains(p.PermissionName, "主观") {
- p.PermissionName = strings.Replace(p.PermissionName, "主观", "升级", -1)
- continue
- }
- if strings.Contains(p.PermissionName, "客观") {
- p.PermissionName = strings.Replace(p.PermissionName, "客观", "升级", -1)
- continue
- }
- p.PermissionName += "(升级)"
- continue
- }
- // 买方研选
- //if p.ChartPermissionId == utils.CHART_PERMISSION_ID_YANXUAN {
- // if expensiveYx == 1 {
- // p.PermissionName += "(5w)"
- // } else if expensiveYx == 2 {
- // p.PermissionName += "(10w)"
- // }
- // //p.PermissionName += expMap[mapExpensive[p.ChartPermissionId]]
- //}
- }
- }
- detail.PermissionList = newPermissionLookList
- }
- // 如果选择的是大套餐, 那么不再展示每个具体的权限, 除大套餐外还需遍历一下专家和研选3w/5w是否有选(这两个与大套餐不互斥, 可额外选择)
- if detail.RaiPackageType > 0 {
- // 大套餐
- bigPackage := new(company_report_permission.PermissionLookItem)
- if detail.RaiPackageType == 1 {
- bigPackage.PermissionName = utils.CHART_PERMISSION_NAME_70W
- bigPackage.ChartPermissionId = utils.CHART_PERMISSION_ID_70W
- checkList = append(checkList, utils.CHART_PERMISSION_ID_70W)
- }
- if detail.RaiPackageType == 2 {
- bigPackage.PermissionName = utils.CHART_PERMISSION_NAME_45W
- bigPackage.ChartPermissionId = utils.CHART_PERMISSION_ID_45W
- checkList = append(checkList, utils.CHART_PERMISSION_ID_45W)
- }
- checkItems = append(checkItems, bigPackage)
- for _, v := range permissionList {
- if v.ExpensiveYx == 1 {
- mapExpensive[v.ChartPermissionId] = true
- }
- if v.Points > 0 && v.ChartPermissionId == utils.YAN_XUAN_KOU_DIAN_BAO_ID {
- points = v.Points
- }
- permissions = append(permissions, v.ChartPermissionId)
- }
- // 专家、研选订阅、研选扣点包
- for _, n := range items {
- if n.ChartPermissionId != utils.ZHUAN_JIA_ID && n.ChartPermissionId != utils.CHART_PERMISSION_ID_YANXUAN && n.ChartPermissionId != utils.YAN_XUAN_KOU_DIAN_BAO_ID {
- continue
- }
- //if n.ChartPermissionId == utils.CHART_PERMISSION_ID_YANXUAN {
- // n.PermissionName += expMap[mapExpensive[n.ChartPermissionId]]
- //}
- if n.ChartPermissionId == utils.YAN_XUAN_KOU_DIAN_BAO_ID {
- n.PermissionName += fmt.Sprint("(", points, "点)")
- }
- if utils.InArrayByInt(permissions, n.ChartPermissionId) {
- checkList = append(checkList, n.ChartPermissionId)
- checkItems = append(checkItems, n)
- }
- }
- plist.Items = checkItems
- plist.CheckList = checkList
- detail.PermissionList = append(detail.PermissionList, plist)
- }
- }
- resp := companyContractResp.CompanyContractDetailResp{
- detail,
- }
- c.OkDetailed(resp, "获取成功")
- }
|