瀏覽代碼

Merge branch 'debug' of http://8.136.199.33:3000/hongze/hz_crm_api into debug

hsun 1 年之前
父節點
當前提交
59bca58857

+ 447 - 98
controllers/cygx/contract_allocation.go

@@ -4,6 +4,7 @@ import (
 	"encoding/json"
 	"fmt"
 	"github.com/rdlucklib/rdluck_tools/paging"
+	"github.com/tealeg/xlsx"
 	"hongze/hz_crm_api/controllers"
 	"hongze/hz_crm_api/models"
 	"hongze/hz_crm_api/models/company"
@@ -12,7 +13,8 @@ import (
 	"hongze/hz_crm_api/models/system"
 	cygxService "hongze/hz_crm_api/services/cygx"
 	"hongze/hz_crm_api/utils"
-	"math"
+	"os"
+	"path/filepath"
 	"strconv"
 	"strings"
 	"time"
@@ -139,9 +141,7 @@ func (this *ContractAllocationController) CompanyContractList() {
 	if startDate == "" {
 		startDate = "2015-01-01"
 	}
-	if endDate == "" {
-		endDate = time.Now().Format(utils.FormatDate)
-	}
+
 	var startSize int
 	if pageSize <= 0 {
 		pageSize = utils.PageSize20
@@ -160,15 +160,28 @@ func (this *ContractAllocationController) CompanyContractList() {
 	var condition string
 	var pars []interface{}
 
+	if endDate != "" {
+		condition += ` AND a.start_date >= ? AND a.start_date <= ? `
+		pars = append(pars, startDate+" 00:00:01", endDate+" 23:59:59")
+	}
+
 	//条件
 	if adminId != "" {
 		condition += ` AND c.seller_id in  (` + adminId + `) `
 		//pars = append(pars, adminId)
-	} else {
-
-		//根据当前角色来获取查询条件
-		condition, pars = getQueryParams(condition, pars, sysUser, "c.")
+	}
 
+	//权益申请销售只能看到自己名下的客户的申请
+	companyIds, err := cygxService.GetAdminLookUserCompanyIdsBySelf(sysUser)
+	if err != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取失败,GetAdminLookUserCompanyIds Err:" + err.Error()
+		return
+	}
+	lencompanyIds := len(companyIds)
+	if lencompanyIds > 0 {
+		condition += ` AND c.company_id IN (` + utils.GetOrmInReplace(lencompanyIds) + `)`
+		pars = append(pars, companyIds)
 	}
 
 	//关键字搜索
@@ -178,7 +191,7 @@ func (this *ContractAllocationController) CompanyContractList() {
 
 	//是否派点
 	if isAllocation != -1 {
-		condition += ` AND a.product_id = ? `
+		condition += ` AND a.is_allocation = ? `
 		pars = append(pars, isAllocation)
 	}
 
@@ -199,7 +212,7 @@ func (this *ContractAllocationController) CompanyContractList() {
 
 	//默认只查询权益 2023-06-01 之后的合同
 	condition += ` AND c.product_id = ?  AND a.start_date > ? `
-	pars = append(pars, 2, "2023-01-01")
+	pars = append(pars, 2, "2023-06-01")
 
 	mapMoneyPoint := make(map[int]float64)
 	//研究员姓名查询
@@ -207,7 +220,7 @@ func (this *ContractAllocationController) CompanyContractList() {
 		var conditionAllocation string
 		var parsAllocation []interface{}
 
-		conditionAllocation = " AND  real_name = ? "
+		conditionAllocation = " AND  real_name = ? AND money != 0 "
 		parsAllocation = append(parsAllocation, researcherRealName)
 		allocationCompanyContractList, err := cygx.GetCygxAllocationCompanyContractList(conditionAllocation, parsAllocation)
 		if err != nil {
@@ -244,13 +257,14 @@ func (this *ContractAllocationController) CompanyContractList() {
 		br.ErrMsg = "获取失败,Err:" + err.Error()
 		return
 	}
-	mapCompamy := make(map[int]string)
+	//mapCompamy := make(map[int]string)
 	listLen := len(list)
 	if listLen == 0 {
 		list = make([]*cygx.CompanyContractResp, 0)
 	} else {
 
 		var contractCodes []string
+		var companyContractIds []int
 		for _, v := range list {
 			switch v.Source {
 			case "系统合同":
@@ -259,40 +273,49 @@ func (this *ContractAllocationController) CompanyContractList() {
 				v.FormalType = "非标"
 			}
 			contractCodes = append(contractCodes, v.ContractCode)
-			mapCompamy[v.CompanyId] = strconv.Itoa(v.CompanyContractId)
-
-			lencontractCodes := len(contractCodes)
-			if lencontractCodes > 0 {
-				//获取标准合同的ID,这里上面的查询已经关联了三张表,拆分吧。。。
-				condition = ""
-				joinStr := ""
-				pars = make([]interface{}, 0)
-				condition = " AND  a.contract_code  IN (" + utils.GetOrmInReplace(lencontractCodes) + ") "
-				pars = append(pars, contractCodes)
-				listContract, err := contract.GetContractList(condition, joinStr, pars, 0, lencontractCodes)
-				if err != nil {
-					br.Msg = "获取合同列表失败!"
-					br.ErrMsg = "获取合同列表失败,Err:" + err.Error()
-					return
-				}
-				mapContractCode := make(map[string]int)
-				for _, v := range listContract {
-					mapContractCode[v.ContractCode] = v.ContractId
-				}
+			companyContractIds = append(companyContractIds, v.CompanyContractId)
+			//mapCompamy[v.CompanyId] = strconv.Itoa(v.CompanyContractId)
+		}
+		lencontractCodes := len(contractCodes)
+		if lencontractCodes > 0 {
+			//获取标准合同的ID,这里上面的查询已经关联了三张表,拆分吧。。。
+			condition = ""
+			joinStr := ""
+			pars = make([]interface{}, 0)
+			condition = " AND  a.contract_code  IN (" + utils.GetOrmInReplace(lencontractCodes) + ") "
+			pars = append(pars, contractCodes)
+			listContract, err := contract.GetContractList(condition, joinStr, pars, 0, lencontractCodes)
+			if err != nil {
+				br.Msg = "获取合同列表失败!"
+				br.ErrMsg = "获取合同列表失败,Err:" + err.Error()
+				return
+			}
 
-				//合并合同所对应的权限
-				mappermissionName, err := cygxService.GetCompanyContractPermissionNameMapById(mapCompamy)
-				if err != nil {
-					br.Msg = "获取失败"
-					br.ErrMsg = "获取失败,Err:" + err.Error()
-					return
-				}
+			mapContractCode := make(map[string]int)
+			for _, v := range listContract {
+				mapContractCode[v.ContractCode] = v.ContractId
+			}
 
-				for _, v := range list {
-					v.ContractId = mapContractCode[v.ContractCode]
-					v.MoneyPoint = mapMoneyPoint[v.CompanyContractId]
-					v.PermissionName = mappermissionName[v.CompanyId]
-				}
+			mapIsGray, err := cygxService.GetMapIsGrayByCompanyContractIds(companyContractIds)
+			if err != nil {
+				br.Msg = "获取合同列表失败!"
+				br.ErrMsg = "获取合同列表失败,GetMapIsGrayByCompanyContractIds Err:" + err.Error()
+				return
+			}
+
+			//合并合同所对应的权限
+			mappermissionName, err := cygxService.GetCompanyContractPermissionNameMapById(companyContractIds)
+			if err != nil {
+				br.Msg = "获取失败"
+				br.ErrMsg = "获取失败,Err:" + err.Error()
+				return
+			}
+
+			for _, v := range list {
+				v.ContractId = mapContractCode[v.ContractCode]
+				v.MoneyPoint = mapMoneyPoint[v.CompanyContractId]
+				v.PermissionName = mappermissionName[v.CompanyContractId]
+				v.IsGray = mapIsGray[v.CompanyContractId]
 			}
 		}
 	}
@@ -302,10 +325,9 @@ func (this *ContractAllocationController) CompanyContractList() {
 		Paging: page,
 		List:   list,
 	}
-
 	//导出excel
 	if isExport {
-		//IncrementalCompanyListExport(this, dataType, resp, br)
+		CompanyContractListExport(this, resp, br)
 		return
 	}
 	br.Ret = 200
@@ -314,6 +336,137 @@ func (this *ContractAllocationController) CompanyContractList() {
 	br.Data = resp
 }
 
+// CompanyContractListExport 导出Excel
+func CompanyContractListExport(this *ContractAllocationController, resp cygx.CompanyContractListResp, br *models.BaseResponse) {
+	dir, err := os.Executable()
+	exPath := filepath.Dir(dir)
+	downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
+	xlsxFile := xlsx.NewFile()
+	if err != nil {
+		br.Msg = "生成文件失败"
+		br.ErrMsg = "生成文件失败"
+		return
+	}
+	style := xlsx.NewStyle()
+	alignment := xlsx.Alignment{
+		Horizontal: "center",
+		Vertical:   "center",
+		WrapText:   true,
+	}
+
+	style.Alignment = alignment
+	style.ApplyAlignment = true
+
+	sheel, err := xlsxFile.AddSheet("派点导出数据")
+	if err != nil {
+		br.Msg = "新增Sheet失败"
+		br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
+		return
+	}
+	sheel.SetColWidth(0, 0, 30)
+	sheel.SetColWidth(1, 1, 15)
+	sheel.SetColWidth(2, 2, 15)
+	sheel.SetColWidth(3, 3, 18)
+
+	titleRow := sheel.AddRow()
+
+	cellA := titleRow.AddCell()
+	cellA.SetStyle(style)
+	cellA.SetValue("合同编号")
+
+	cellB := titleRow.AddCell()
+	cellB.SetStyle(style)
+	cellB.SetValue("转正类型")
+
+	cellC := titleRow.AddCell()
+	cellC.SetStyle(style)
+	cellC.SetValue("合同类型")
+
+	cellD := titleRow.AddCell()
+	cellD.SetStyle(style)
+	cellD.SetValue("公司名称")
+
+	cellE := titleRow.AddCell()
+	cellE.SetStyle(style)
+	cellE.SetValue("所属销售")
+
+	cellF := titleRow.AddCell()
+	cellF.SetStyle(style)
+	cellF.SetValue("合同金额")
+
+	cellG := titleRow.AddCell()
+	cellG.SetStyle(style)
+	cellG.SetValue("合同期限")
+
+	cellH := titleRow.AddCell()
+	cellH.SetStyle(style)
+	cellH.SetValue("签约套餐")
+
+	cellI := titleRow.AddCell()
+	cellI.SetStyle(style)
+	cellI.SetValue("状态")
+
+	for _, v := range resp.List {
+		dataRow := sheel.AddRow()
+		dataRow.SetHeight(20)
+
+		cellA := dataRow.AddCell()
+		cellA.SetStyle(style)
+		cellA.SetValue(v.ContractCode)
+
+		cellB := dataRow.AddCell()
+		cellB.SetStyle(style)
+		cellB.SetValue(v.FormalType)
+
+		cellC := dataRow.AddCell()
+		cellC.SetStyle(style)
+		cellC.SetValue(v.ContractType)
+
+		cellD := dataRow.AddCell()
+		cellD.SetStyle(style)
+		cellD.SetValue(v.CompanyName)
+
+		cellE := dataRow.AddCell()
+		cellE.SetStyle(style)
+		cellE.SetValue(v.SellerName)
+
+		cellF := dataRow.AddCell()
+		cellF.SetStyle(style)
+		cellF.SetValue(v.Money)
+
+		cellG := dataRow.AddCell()
+		cellG.SetStyle(style)
+		cellG.SetValue(fmt.Sprint(v.StartDate, " ~  ", v.EndDate))
+
+		cellH := dataRow.AddCell()
+		cellH.SetStyle(style)
+		cellH.SetValue(v.PermissionName)
+
+		cellI := dataRow.AddCell()
+		cellI.SetStyle(style)
+		if v.IsAllocation == 1 {
+			cellI.SetValue("已派点")
+		} else {
+			cellI.SetValue("未派点")
+		}
+	}
+	err = xlsxFile.Save(downLoadnFilePath)
+	if err != nil {
+		br.Msg = "保存文件失败"
+		br.ErrMsg = "保存文件失败"
+		return
+	}
+	randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
+	downloadFileName := "派点导出数据_" + randStr + ".xlsx"
+	this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
+	defer func() {
+		os.Remove(downLoadnFilePath)
+	}()
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "导出成功"
+}
+
 // @Title  详情
 // @Description 获取详情接口
 // @Param   CompanyContractId   query   int  true       "ID"
@@ -355,10 +508,6 @@ func (this *ContractAllocationController) CompanyContracDetail() {
 
 	//var contractPermissionList []*company.ContractPermissionList
 	expMap := map[int]string{0: "(3w)", 1: "(5w)"} // 买方研选价格
-
-	//classifyName := "权益"
-
-	//plist := new(company.ContractPermissionList)
 	hasPermissions, e := company.GetCompanyContractPermissionByCompanyContractId(companyContractId)
 	if e != nil {
 		br.Msg = "获取失败"
@@ -369,7 +518,7 @@ func (this *ContractAllocationController) CompanyContracDetail() {
 	for _, p := range hasPermissions {
 		hasMap[p.ChartPermissionId] = p
 	}
-	checkItems := make([]*company.PermissionLookItem, 0)
+
 	raiPermissions, e := company.GetPermissionLookItemsExt("2", utils.COMPANY_PRODUCT_RAI_NAME)
 	if e != nil {
 		br.Msg = "获取失败"
@@ -383,21 +532,14 @@ func (this *ContractAllocationController) CompanyContracDetail() {
 		if match == nil {
 			continue
 		}
-		// 升级
-		if match.IsUpgrade == 1 {
-			n.IsUpgrade = 1
-			checkItems = append(checkItems, n)
-			continue
-		}
+
 		mapPermissionNameHave[n.PermissionName] = true
 		// 买方研选(3w/5w)
 		if n.PermissionName == utils.CHART_PERMISSION_NAME_MF_YANXUAN {
 			expensiveYx = match.ExpensiveYx
 			n.PermissionName += expMap[match.ExpensiveYx]
-			checkItems = append(checkItems, n)
 			continue
 		}
-		checkItems = append(checkItems, n)
 	}
 
 	resp.Money = contractItem.Money / 10000
@@ -416,21 +558,19 @@ func (this *ContractAllocationController) CompanyContracDetail() {
 			resp.TotalPointsContent = fmt.Sprint(resp.Money, "W")
 		}
 		resp.Money = resp.Money - moneyYx
-		respItemYx.Proportion = moneyYx
+		respItemYx.Proportion = 0
+		respItemYx.Money = moneyYx
 		respItemYx.ChartPermissionName = utils.CHART_PERMISSION_NAME_MF_YANXUAN
 		respItemYx.List = append(respItemYx.List, &cygx.AllocationRealNameListResp{utils.CHART_PERMISSION_NAME_MF_YANXUAN, 0, moneyYx})
 	} else {
 		resp.TotalPointsContent = fmt.Sprint(resp.Money, "W")
 	}
-
 	sysUserList, err := cygx.GetAskEmailList()
-
 	if err != nil {
 		br.Msg = "获取失败"
 		br.ErrMsg = "获取失败,GetAskEmailList Err: " + err.Error()
 		return
 	}
-
 	mapPermissionUser := make(map[string][]*cygx.AllocationRealNameListResp)
 
 	var respList []*cygx.AllocationPermissionListResp
@@ -488,7 +628,24 @@ func (this *ContractAllocationController) CompanyContracDetail() {
 			respList = append(respList, respItem)
 		}
 	}
-	resp.List = respList
+	//处理是否置灰
+	mapIsGray, err := cygxService.GetMapIsGrayByCompanyContractIds([]int{companyContractId})
+	if err != nil {
+		br.Msg = "获取合同列表失败!"
+		br.ErrMsg = "获取合同列表失败,GetMapIsGrayByCompanyContractIds Err:" + err.Error()
+		return
+	}
+
+	permissionNameArr := []string{"医药", "消费", "科技", "智造", "策略", "买方研选"}
+	for _, v := range permissionNameArr {
+		for _, v2 := range respList {
+			if v2.ChartPermissionName == v {
+				resp.List = append(resp.List, v2)
+			}
+		}
+	}
+	resp.IsGray = mapIsGray[companyContractId]
+	//resp.List = respList
 	resp.CompanyContractId = companyContractId
 	br.Ret = 200
 	br.Success = true
@@ -527,6 +684,17 @@ func (this *ContractAllocationController) CompanyContracUpdate() {
 		br.ErrMsg = "参数错误,id不可为空"
 		return
 	}
+	mapIsGray, err := cygxService.GetMapIsGrayByCompanyContractIds([]int{companyContractId})
+	if err != nil {
+		br.Msg = "获取合同列表失败!"
+		br.ErrMsg = "获取合同列表失败,GetMapIsGrayByCompanyContractIds Err:" + err.Error()
+		return
+	}
+	if mapIsGray[companyContractId] {
+		br.Msg = "超过180天,无法修改!"
+		br.ErrMsg = "超过180天,无法修改,companyContractId :" + strconv.Itoa(companyContractId)
+		return
+	}
 
 	contractItem, err := company.GetCompanyContractById(companyContractId)
 	if err != nil {
@@ -564,7 +732,7 @@ func (this *ContractAllocationController) CompanyContracUpdate() {
 		if match == nil {
 			continue
 		}
-		mapPermissionNameHave[n.PermissionName] = true
+
 		// 买方研选(3w/5w)
 		if n.PermissionName == utils.CHART_PERMISSION_NAME_MF_YANXUAN {
 			if match.ExpensiveYx == 1 {
@@ -572,6 +740,8 @@ func (this *ContractAllocationController) CompanyContracUpdate() {
 			} else {
 				money = money - 3
 			}
+		} else {
+			mapPermissionNameHave[n.PermissionName] = true
 		}
 	}
 
@@ -591,13 +761,26 @@ func (this *ContractAllocationController) CompanyContracUpdate() {
 		itemPermission.AdminName = sysUser.RealName
 		itemPermission.Proportion = v.Proportion
 		itemPermission.Money = v.Money
-		itemPermission.MoneyAvg = moneyAvg
+		if v.ChartPermissionName != utils.CHART_PERMISSION_NAME_MF_YANXUAN {
+			itemPermission.MoneyAvg = moneyAvg
+			if v.Money < moneyAvg/2 {
+				br.Msg = "单行业占比值不得低于平均值的一半"
+				br.ErrMsg = "单行业占比值不得低于平均值的一半,Err:" + fmt.Sprint(proportionSum)
+				return
+			}
+		}
 		itemPermission.ChartPermissionName = v.ChartPermissionName
 		itemPermission.CreateTime = time.Now()
 		itemPermission.ModifyTime = time.Now()
 		itemsPermission = append(itemsPermission, itemPermission)
+		var userProportionSum float64 // 校验前端传过来的占比使用
 
 		for _, v2 := range v.List {
+			if v2.Proportion < -20 {
+				br.Msg = "研究员占比值不得小于总额的-20%"
+				br.ErrMsg = "研究员占比值不得小于总额的20%,Err:" + fmt.Sprint(proportionSum)
+				return
+			}
 			item := new(cygx.CygxAllocationCompanyContract)
 			item.CompanyContractId = companyContractId
 			item.AdminId = sysUser.AdminId
@@ -609,16 +792,21 @@ func (this *ContractAllocationController) CompanyContracUpdate() {
 			item.CreateTime = time.Now()
 			item.ModifyTime = time.Now()
 			items = append(items, item)
+			proportionSum += v2.Proportion
+			userProportionSum += v2.Proportion
 		}
-		if v.ChartPermissionName == utils.CHART_PERMISSION_NAME_MF_YANXUAN {
-			continue
+		//先添加0.2%的精度校验
+		if userProportionSum > (v.Proportion+0.2) || userProportionSum < (v.Proportion-0.2) {
+			br.Msg = "单行业下的研究员比值之和不等于行业占比值"
+			br.ErrMsg = "单行业下的研究员比值之和不等于行业占比值"
+			return
 		}
-		proportionSum += v.Proportion
 	}
 
+	//先添加0.5%的精度校验
 	if proportionSum > 100.5 || proportionSum < 99.5 {
-		br.Msg = "操作失败,派点填写信息错误"
-		br.ErrMsg = "获取合同信息失败,Err:" + fmt.Sprint(proportionSum)
+		br.Msg = "行业总比值相加不等于100%"
+		br.ErrMsg = "行业总比值相加不等于100%,Err:"
 		return
 	}
 
@@ -666,18 +854,31 @@ func (this *ContractAllocationController) CompanyContractStatistics() {
 	if startDate == "" {
 		startDate = "2015-01-01"
 	}
-	if endDate == "" {
-		endDate = time.Now().Format(utils.FormatDate)
-	}
 
 	//是否导出报表
 	isExport, _ := this.GetBool("IsExport")
 
 	var condition string
-	var pars []interface{}
 
+	var pars []interface{}
+	if endDate != "" {
+		condition += ` AND a.start_date >= ? AND a.start_date <= ? `
+		pars = append(pars, startDate+" 00:00:01", endDate+" 23:59:59")
+	}
 	//根据当前角色来获取查询条件
-	condition, pars = getQueryParams(condition, pars, sysUser, "c.")
+	//condition, pars = getQueryParams(condition, pars, sysUser, "c.")
+
+	companyIds, err := cygxService.GetAdminLookUserCompanyIdsBySelf(sysUser)
+	if err != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取失败,GetAdminLookUserCompanyIds Err:" + err.Error()
+		return
+	}
+	lencompanyIds := len(companyIds)
+	if lencompanyIds > 0 {
+		condition += ` AND c.company_id IN (` + utils.GetOrmInReplace(lencompanyIds) + `)`
+		pars = append(pars, companyIds)
+	}
 
 	//关键字搜索
 	if keyword != "" {
@@ -685,7 +886,7 @@ func (this *ContractAllocationController) CompanyContractStatistics() {
 	}
 
 	//默认只查询权益 2023-06-01 之后的合同
-	condition += ` AND c.product_id = ?  AND a.start_date > ? `
+	condition += ` AND c.product_id = ?  AND a.start_date > ?   `
 	pars = append(pars, 2, "2023-01-01")
 
 	//列表页数据
@@ -695,7 +896,9 @@ func (this *ContractAllocationController) CompanyContractStatistics() {
 		br.ErrMsg = "获取失败,Err:" + err.Error()
 		return
 	}
+	//return
 	var companyContractIds []int
+	companyContractIdBool := make(map[int]bool)
 	for _, v := range listContract {
 		companyContractIds = append(companyContractIds, v.CompanyContractId)
 	}
@@ -707,8 +910,8 @@ func (this *ContractAllocationController) CompanyContractStatistics() {
 	mapPermissionMoney := make(map[string]float64)
 	mapPermissionMoneyAvg := make(map[string]float64)
 
-	totalContract := lenArr //所有的关联合同
-	var totalMoney float64  //所有的关联合同的金额 单位万
+	//totalContract := lenArr //所有的关联合同
+	var totalMoney float64 //所有的关联合同的金额 单位万
 	if lenArr > 0 {
 		var conditionAllocation string
 		var parsAllocation []interface{}
@@ -727,13 +930,14 @@ func (this *ContractAllocationController) CompanyContractStatistics() {
 			return
 		}
 		for _, v := range allocationCompanyContractList {
-			if v.Proportion != 0 {
+
+			if v.Proportion != 0 && v.ChartPermissionName != utils.CHART_PERMISSION_NAME_MF_YANXUAN {
 				mapUserAllocation[v.RealName] += 1
 				mapUserMoney[v.RealName] += v.Money
 				mapPermissionAllocation[v.ChartPermissionName] += 1
 				mapPermissionMoney[v.ChartPermissionName] += v.Money
-
 				totalMoney += v.Money
+				companyContractIdBool[v.CompanyContractId] = true
 			}
 		}
 		for _, v := range allocationCompanyContractPermissionList {
@@ -748,19 +952,17 @@ func (this *ContractAllocationController) CompanyContractStatistics() {
 		return
 	}
 
-	mapPermissionUser := make(map[string][]*cygx.AllocationRealNameStatisticsListResp)
+	mapPermissionUser := make(map[string][]*cygx.AllocationRealNameStatisticsListResp) //行业分组 map
 
 	for _, v := range sysUserList {
 		item := new(cygx.AllocationRealNameStatisticsListResp)
 		item.RealName = v.Name
 		item.TotalRelatedContract = mapUserAllocation[v.Name]
-		item.TotalDispatchPoint = fmt.Sprint(mapUserMoney[v.Name])
+		item.TotalDispatchPoint = utils.SubFloatToString(mapUserMoney[v.Name], 2)
 		if item.TotalDispatchPoint == "" {
 			item.TotalDispatchPoint = "0"
 		}
 		//组内占比
-		//utils.SubFloatToString(val, 4)
-		//item.GroupProportion = fmt.Sprint(mapUserMoney[v.Name] / mapPermissionMoney[v.ChartPermissionName] * 100)
 		if mapUserMoney[v.Name] == 0 {
 			item.GroupProportion = ""
 		} else {
@@ -772,7 +974,11 @@ func (this *ContractAllocationController) CompanyContractStatistics() {
 		item.GroupProportion += "%"
 
 		//部门占比
-		item.DepartmentProportion = utils.SubFloatToString(mapUserMoney[v.Name]/totalMoney*100, 2)
+		if totalMoney == 0 {
+			item.DepartmentProportion = ""
+		} else {
+			item.DepartmentProportion = utils.SubFloatToString(mapUserMoney[v.Name]/totalMoney*100, 2)
+		}
 		if item.DepartmentProportion == "" {
 			item.DepartmentProportion = "0"
 		}
@@ -785,29 +991,31 @@ func (this *ContractAllocationController) CompanyContractStatistics() {
 		item := new(cygx.AllocationRealNameStatisticsListResp)
 		item.RealName = "合计"
 		item.TotalRelatedContract = mapPermissionAllocation[k]
-		item.TotalDispatchPoint = fmt.Sprint(mapPermissionMoney[k], "/", mapPermissionMoneyAvg[k])
+		item.TotalDispatchPoint = fmt.Sprint(utils.SubFloatToString(mapPermissionMoney[k], 2), "/", mapPermissionMoneyAvg[k])
 		item.GroupProportion = "100%"
 
-		// 部门占比
-		item.DepartmentProportion = utils.SubFloatToString(mapPermissionMoney[k]/totalMoney*100, 2)
+		//部门占比
+		if totalMoney == 0 {
+			item.DepartmentProportion = ""
+		} else {
+			item.DepartmentProportion = utils.SubFloatToString(mapPermissionMoney[k]/totalMoney*100, 2)
+		}
 		if item.DepartmentProportion == "" {
 			item.DepartmentProportion = "0"
 		}
 		item.DepartmentProportion += "%"
-
 		mapPermissionUser[k] = append(mapPermissionUser[k], item)
-		var ratio float64       // 使用一个变量作为精度范围, 比如 2 位小数时,精度范围应该为 100
-		ratio = math.Pow(10, 2) // 计算精度范围,2 位小数 = 100
+
 		item = new(cygx.AllocationRealNameStatisticsListResp)
 		item.RealName = "平均"
-		item.TotalRelatedContract = math.Round(mapPermissionAllocation[k]/float64(lenUser)) * ratio / ratio
+		item.TotalRelatedContract = utils.SubFloatToFloat(mapPermissionAllocation[k]/float64(lenUser), 2)
 		item.TotalDispatchPoint = utils.SubFloatToString(mapPermissionMoney[k]/float64(lenUser), 2)
 
 		//组内占比
 		if mapPermissionMoney[k] == 0 {
 			item.GroupProportion = ""
 		} else {
-			item.GroupProportion = utils.SubFloatToString(float64(lenUser)/mapPermissionMoney[k]*100, 2)
+			item.GroupProportion = utils.SubFloatToString(1/(float64(len(mapPermissionUser[k])-1))*100, 2)
 		}
 		if item.GroupProportion == "" {
 			item.GroupProportion = "0"
@@ -815,7 +1023,12 @@ func (this *ContractAllocationController) CompanyContractStatistics() {
 		item.GroupProportion += "%"
 
 		// 部门占比
-		item.DepartmentProportion = utils.SubFloatToString(mapPermissionMoney[k]/totalMoney*100/float64(len(mapPermissionUser[k])), 2)
+		if totalMoney == 0 {
+			item.DepartmentProportion = ""
+		} else {
+			item.DepartmentProportion = utils.SubFloatToString(mapPermissionMoney[k]/totalMoney*100/float64(len(mapPermissionUser[k])-1), 2)
+		}
+
 		if item.DepartmentProportion == "" {
 			item.DepartmentProportion = "0"
 		}
@@ -835,11 +1048,11 @@ func (this *ContractAllocationController) CompanyContractStatistics() {
 	resp := cygx.CygxAllocationCompanyContractDetailStatisticsResp{
 		List: list,
 	}
-	resp.TotalContract = totalContract
-	resp.TotalMoney = totalMoney
+	resp.TotalContract = len(companyContractIdBool)
+	resp.TotalMoney = utils.SubFloatToFloat(totalMoney, 2)
 	//导出excel
 	if isExport {
-		//IncrementalCompanyListExport(this, dataType, resp, br)
+		CompanyContractStatisticsExport(this, resp, br)
 		return
 	}
 	br.Ret = 200
@@ -847,3 +1060,139 @@ func (this *ContractAllocationController) CompanyContractStatistics() {
 	br.Msg = "获取成功"
 	br.Data = resp
 }
+
+// CompanyContractStatisticsExport 导出Excel
+func CompanyContractStatisticsExport(this *ContractAllocationController, resp cygx.CygxAllocationCompanyContractDetailStatisticsResp, br *models.BaseResponse) {
+	dir, err := os.Executable()
+	exPath := filepath.Dir(dir)
+	downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
+	xlsxFile := xlsx.NewFile()
+	if err != nil {
+		br.Msg = "生成文件失败"
+		br.ErrMsg = "生成文件失败"
+		return
+	}
+	style := xlsx.NewStyle()
+	alignment := xlsx.Alignment{
+		Horizontal: "center",
+		Vertical:   "center",
+		WrapText:   true,
+	}
+
+	style.Alignment = alignment
+	style.ApplyAlignment = true
+
+	sheel, err := xlsxFile.AddSheet("研究员派点统计")
+	if err != nil {
+		br.Msg = "新增Sheet失败"
+		br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
+		return
+	}
+	sheel.SetColWidth(0, 0, 30)
+	sheel.SetColWidth(1, 1, 15)
+	sheel.SetColWidth(2, 2, 15)
+	sheel.SetColWidth(3, 3, 18)
+
+	titleRow := sheel.AddRow()
+
+	cellA := titleRow.AddCell()
+	cellA.SetStyle(style)
+	cellA.SetValue("组别")
+
+	cellB := titleRow.AddCell()
+	cellB.SetStyle(style)
+	cellB.SetValue("研究员")
+
+	cellC := titleRow.AddCell()
+	cellC.SetStyle(style)
+	cellC.SetValue("关联合同")
+
+	cellD := titleRow.AddCell()
+	cellD.SetStyle(style)
+	cellD.SetValue("总派点")
+
+	cellE := titleRow.AddCell()
+	cellE.SetStyle(style)
+	cellE.SetValue("组内占比")
+
+	cellF := titleRow.AddCell()
+	cellF.SetStyle(style)
+	cellF.SetValue("部门占比")
+
+	for _, v := range resp.List {
+		for k2, v2 := range v.List {
+
+			dataRow := sheel.AddRow()
+			dataRow.SetHeight(20)
+
+			cellA := dataRow.AddCell()
+			cellA.SetStyle(style)
+			cellA.SetValue(v.ChartPermissionName)
+			if k2 < len(v.List)-1 {
+				cellA.VMerge = 1
+			}
+
+			cellB := dataRow.AddCell()
+			cellB.SetStyle(style)
+			cellB.SetValue(v2.RealName)
+
+			cellC := dataRow.AddCell()
+			cellC.SetStyle(style)
+			cellC.SetValue(v2.TotalRelatedContract)
+
+			cellD := dataRow.AddCell()
+			cellD.SetStyle(style)
+			cellD.SetValue(v2.TotalDispatchPoint)
+
+			cellE := dataRow.AddCell()
+			cellE.SetStyle(style)
+			cellE.SetValue(v2.GroupProportion)
+
+			cellF := dataRow.AddCell()
+			cellF.SetStyle(style)
+			cellF.SetValue(v2.DepartmentProportion)
+		}
+	}
+
+	titleRow = sheel.AddRow()
+	cellA = titleRow.AddCell()
+	cellA.HMerge = 1
+	cellA.SetStyle(style)
+	cellA.SetValue("部门合计")
+
+	cellB = titleRow.AddCell()
+	cellB.SetStyle(style)
+	cellB.SetValue("")
+
+	cellC = titleRow.AddCell()
+	cellC.SetStyle(style)
+	cellC.SetValue(resp.TotalContract)
+
+	cellD = titleRow.AddCell()
+	cellD.SetStyle(style)
+	cellD.SetValue(resp.TotalMoney)
+
+	cellE = titleRow.AddCell()
+	cellE.SetStyle(style)
+	cellE.SetValue("-")
+
+	cellF = titleRow.AddCell()
+	cellF.SetStyle(style)
+	cellF.SetValue("100%")
+
+	err = xlsxFile.Save(downLoadnFilePath)
+	if err != nil {
+		br.Msg = "保存文件失败"
+		br.ErrMsg = "保存文件失败"
+		return
+	}
+	randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
+	downloadFileName := "研究员派点统计_" + randStr + ".xlsx"
+	this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
+	defer func() {
+		os.Remove(downLoadnFilePath)
+	}()
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "导出成功"
+}

+ 10 - 7
controllers/english_report/english_video.go

@@ -334,7 +334,7 @@ func (this *EnglishVideoController) List() {
 	}
 	// 查询分类信息
 	var classifyIdSecondSlice []int
-	classifyNameMap := make(map[int]string)
+	classifyNameMap := make(map[int]*models.EnglishClassifyFullName)
 	for _, item := range list {
 		classifyIdSecondSlice = append(classifyIdSecondSlice, item.ClassifyIdSecond)
 	}
@@ -347,11 +347,7 @@ func (this *EnglishVideoController) List() {
 		}
 
 		for _, v := range nameList {
-			if v.RootId == 0 {
-				classifyNameMap[v.Id] = strings.Join([]string{v.ParentName, v.ClassifyName}, "/")
-			} else {
-				classifyNameMap[v.Id] = strings.Join([]string{v.RootName, v.ParentName, v.ClassifyName}, "/")
-			}
+			classifyNameMap[v.Id] = v
 		}
 	}
 
@@ -407,8 +403,15 @@ func (this *EnglishVideoController) List() {
 			item.Pv = 0
 		}
 		//处理分类名
+		//处理分类名
 		if n, ok := classifyNameMap[item.ClassifyIdSecond]; ok {
-			item.FullClassifyName = n
+			if n.RootId == 0 {
+				item.FullClassifyName = strings.Join([]string{n.ParentName, n.ClassifyName}, "/")
+			} else {
+				item.FullClassifyName = strings.Join([]string{n.RootName, n.ParentName, n.ClassifyName}, "/")
+			}
+			item.ClassifyIdRoot = n.RootId
+			item.ClassifyNameRoot = n.RootName
 		}
 	}
 

+ 1 - 1
models/cygx/activity_ask_email.go

@@ -20,7 +20,7 @@ func GetAskEmail() (item []*AskEmailRep, err error) {
 
 func GetAskEmailList() (item []*AskEmailRep, err error) {
 	o := orm.NewOrmUsingDB("hz_cygx")
-	sql := `SELECT * FROM cygx_activity_ask_email WHERE    chart_permission_name != ''  GROUP BY sort  DESC`
+	sql := `SELECT * FROM cygx_activity_ask_email WHERE    chart_permission_name != ''  ORDER BY sort  DESC`
 	_, err = o.Raw(sql).QueryRows(&item)
 	return
 }

+ 43 - 20
models/cygx/company_contract.go

@@ -30,23 +30,30 @@ type CompanyContractResp struct {
 
 // 增量客户统计报表返回类
 type CompanyContractListResp struct {
-	List   []*CompanyContractResp
 	Paging *paging.PagingItem `description:"分页数据"`
+	List   []*CompanyContractResp
 }
 
 // 获取存量客户未续约报表列表统计数据(根据合同来展示)
 func GetCompanyContractCountJoinCompany(condition string, pars []interface{}) (total int, err error) {
 	o := orm.NewOrm()
-
-	sql := `SELECT a.*,b.region_type,c.seller_id,c.seller_name,b.company_name FROM company_contract a
-		 JOIN company b ON a.company_id = b.company_id
-		 JOIN company_product c ON a.company_id = c.company_id and a.product_id=c.product_id WHERE a.status = 1 `
-
-	if condition != "" {
-		sql += condition
-	}
-	//sql += " order by a.start_date desc "
-	sql = `select count(1) count from (` + sql + ` group by company_id) f`
+	sql := ` SELECT
+	count(*) AS count 
+FROM
+	(
+	SELECT
+		COUNT(*) 
+	FROM
+		company_contract a
+		JOIN company b ON a.company_id = b.company_id
+		JOIN company_product c ON a.company_id = c.company_id 
+		AND a.product_id = c.product_id 
+	WHERE
+		a.STATUS = 1 
+		` + condition + `
+	GROUP BY
+	a.company_contract_id 
+	) b`
 	err = o.Raw(sql, pars).QueryRow(&total)
 	return
 }
@@ -54,16 +61,32 @@ func GetCompanyContractCountJoinCompany(condition string, pars []interface{}) (t
 // 获取存量客户未续约报表列表数据(根据合同来展示)
 func GetCompanyContractListJoinCompany(condition string, pars []interface{}, startSize, pageSize int) (items []*CompanyContractResp, err error) {
 	o := orm.NewOrm()
+	//
+	//sql := `SELECT a.*,b.region_type,c.seller_id,c.seller_name,b.company_name FROM company_contract a
+	//	 JOIN company b ON a.company_id = b.company_id
+	//	 JOIN company_product c ON a.company_id = c.company_id and a.product_id=c.product_id WHERE a.status = 1 `
+	//
+	//if condition != "" {
+	//	sql += condition
+	//}
+	//sql += " order by a.start_date desc "
+	//sql = `select *,count(*) count from (` + sql + `) b group by company_id  order by end_date asc,company_id desc limit ?,?`
 
-	sql := `SELECT a.*,b.region_type,c.seller_id,c.seller_name,b.company_name FROM company_contract a
-		 JOIN company b ON a.company_id = b.company_id
-		 JOIN company_product c ON a.company_id = c.company_id and a.product_id=c.product_id WHERE a.status = 1 `
-
-	if condition != "" {
-		sql += condition
-	}
-	sql += " order by a.start_date desc "
-	sql = `select *,count(*) count from (` + sql + `) b group by company_id  order by end_date asc,company_id desc limit ?,?`
+	sql := ` SELECT
+			a.*,
+			b.region_type,
+			c.seller_id,
+			c.seller_name,
+			b.company_name 
+		FROM
+			company_contract a
+			JOIN company b ON a.company_id = b.company_id
+			JOIN company_product c ON a.company_id = c.company_id 
+			AND a.product_id = c.product_id 
+		WHERE
+			a.STATUS = 1`
+	sql += condition
+	sql += `GROUP BY a.company_contract_id ORDER BY a.start_date DESC   , a.company_contract_id DESC  	LIMIT  ?,? `
 	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
 	return
 }

+ 2 - 3
models/english_report.go

@@ -106,8 +106,8 @@ type EnglishClassifyList struct {
 	ClassifyLabel string    `description:"分类标签"`
 	ShowType      int       `description:"展示类型:1-列表 2-专栏"`
 	IsShow        int       `description:"是否在小程序显示:1-显示 0-隐藏"`
-	ClassifyType  int       `description:"分类类型:0英文报告,1英文线上路演"`
-	EnPermissions []int     `description:"英文权限IDs"`
+	//ClassifyType  int       `description:"分类类型:0英文报告,1英文线上路演"`
+	EnPermissions []int `description:"英文权限IDs"`
 	Child         []*EnglishClassifyList
 }
 
@@ -204,7 +204,6 @@ type EnglishClassify struct {
 	ClassifyLabel string    `description:"分类标签"`
 	ShowType      int       `description:"展示类型:1-列表 2-专栏"`
 	IsShow        int       `description:"是否在小程序显示:1-显示 0-隐藏"`
-	ClassifyType  int       `description:"分类类型:0英文报告,1英文线上路演"`
 }
 
 func GetEnglishReportClassifyByIds(classifyIds []int) (list []*EnglishClassify, err error) {

+ 2 - 0
models/english_video.go

@@ -171,6 +171,8 @@ type EnglishVideoList struct {
 	AdminId            int    `description:"上传视频的管理员账号"`
 	AdminRealName      string `description:"上传视频的管理员姓名"`
 	FullClassifyName   string `description:"顶级分类名/父级分类名/当前分类名"`
+	ClassifyIdRoot     int    `description:"顶级分类id"`
+	ClassifyNameRoot   string `description:"顶级分类名称"`
 }
 
 type EnglishVideoListResp struct {

+ 2 - 1
services/company_apply/company_approval.go

@@ -420,8 +420,9 @@ func Approved(approvalRecord *contract.ContractApprovalRecord, opUser *system.Ad
 				//客户研选行业转正时(王芳审批通过),模板消息提醒汪洋
 				services.AddCompanyApprovalMessageWangYang(recordInfo.CompanyId, recordInfo.CompanyContractId, recordInfo.ApplyRealName, companyInfo.CompanyName)
 
-				go cygxService.YanXuanCompanyApproval(recordInfo.CompanyId)                          //研选审批通过的时候研选扣点更新
+				cygxService.YanXuanCompanyApproval(recordInfo.CompanyId)                             //研选审批通过的时候研选扣点更新
 				go services.AddCompanyContractMergeByCompanyContractId(recordInfo.CompanyContractId) //进行合同合并
+				cygxService.HandleAllocationCompanyContractByYanXuan(recordInfo.CompanyContractId)   //如果合同只有研选的时候,自动处理派点
 
 			}
 		}()

+ 163 - 27
services/cygx/contract_allocation.go

@@ -2,35 +2,29 @@ package cygx
 
 import (
 	"errors"
+	"fmt"
 	"hongze/hz_crm_api/models"
 	"hongze/hz_crm_api/models/company"
+	"hongze/hz_crm_api/models/cygx"
+	"hongze/hz_crm_api/services/alarm_msg"
 	"hongze/hz_crm_api/utils"
-	"strconv"
 	"strings"
+	"time"
 )
 
 // GetCompanyContractPermissionNameMapById 获取合并之后的合同所对应的权限种类名称
-func GetCompanyContractPermissionNameMapById(mapCompamy map[int]string) (mapContractResp map[int]string, err error) {
+func GetCompanyContractPermissionNameMapById(companyContractIds []int) (mapContractResp map[int]string, err error) {
 	//return
-	if len(mapCompamy) == 0 {
+	lenArr := len(companyContractIds)
+	if lenArr == 0 {
 		return
 	}
 	var condition string
 	var pars []interface{}
 
-	mapContracIdCompanyId := make(map[string]int) //建立合同ID与公司ID的map对应关系
+	condition += " AND  company_contract_id IN (" + utils.GetOrmInReplace(lenArr) + ")"
+	pars = append(pars, companyContractIds)
 
-	var companyContractIdGroup string //多个合同ID
-	for k, v := range mapCompamy {
-		companyContractIdGroup += v + ","
-		sliceContract := strings.Split(v, ",")
-		for _, compamyContracId := range sliceContract {
-			mapContracIdCompanyId[compamyContracId] = k
-		}
-	}
-
-	companyContractIdGroup = strings.TrimRight(companyContractIdGroup, ",")
-	condition += " AND  company_contract_id IN (" + companyContractIdGroup + ")"
 	companyContractList, e := company.GetCompanyContractList(condition, pars)
 	if e != nil && e.Error() != utils.ErrNoRow() {
 		err = errors.New("GetCompanyContractList, Err: " + e.Error())
@@ -47,13 +41,13 @@ func GetCompanyContractPermissionNameMapById(mapCompamy map[int]string) (mapCont
 		mappermissionName[v.ChartPermissionId] = v.Remark
 	}
 
-	mapContractIdPerssion := make(map[string]string) //单个合同ID所对应的套餐或者权限名称
+	mapContractIdPerssion := make(map[int]string) //单个合同ID所对应的套餐或者权限名称
 	for _, v := range companyContractList {
 		if v.RaiPackageType == 1 {
-			mapContractIdPerssion[strconv.Itoa(v.CompanyContractId)] = "70w套餐"
+			mapContractIdPerssion[v.CompanyContractId] = "70w套餐"
 		}
 		if v.RaiPackageType == 2 {
-			mapContractIdPerssion[strconv.Itoa(v.CompanyContractId)] = "45w套餐"
+			mapContractIdPerssion[v.CompanyContractId] = "45w套餐"
 		}
 	}
 
@@ -62,21 +56,37 @@ func GetCompanyContractPermissionNameMapById(mapCompamy map[int]string) (mapCont
 		err = errors.New("GetCompanyContractPermissionList, Err: " + e.Error())
 		return
 	}
+
+	mapIsUpgrade := make(map[string]bool) //合同ID对应的行业是否有升级
 	for _, v := range companyContractPermissionList {
 		//如果开通的不是整个套餐,那么就做单独的子权限处理
-		if strings.Count(mapContractIdPerssion[strconv.Itoa(v.CompanyContractId)], "w套餐") == 0 {
+		if strings.Count(mapContractIdPerssion[(v.CompanyContractId)], "w套餐") == 0 {
 			if v.ChartPermissionId == utils.CHART_PERMISSION_ID_YANXUAN {
 				if v.ExpensiveYx == 1 {
-					mapContractIdPerssion[strconv.Itoa(v.CompanyContractId)] += utils.CHART_PERMISSION_NAME_MF_YANXUAN + "(5w),"
+					mapContractIdPerssion[(v.CompanyContractId)] += utils.CHART_PERMISSION_NAME_MF_YANXUAN + "(5w),"
 				} else {
-					mapContractIdPerssion[strconv.Itoa(v.CompanyContractId)] += utils.CHART_PERMISSION_NAME_MF_YANXUAN + "(3w),"
+					mapContractIdPerssion[(v.CompanyContractId)] += utils.CHART_PERMISSION_NAME_MF_YANXUAN + "(3w),"
 				}
 			} else {
-				mapContractIdPerssion[strconv.Itoa(v.CompanyContractId)] += mappermissionName[v.ChartPermissionId] + ","
+				mapContractIdPerssion[(v.CompanyContractId)] += mappermissionName[v.ChartPermissionId] + ","
+				if v.IsUpgrade == 1 {
+					//合同ID,权限名称形成唯一的主键索引
+					perssionName := mappermissionName[v.ChartPermissionId]
+					perssionName = strings.Replace(perssionName, "(客观)", "", -1)
+					perssionName = strings.Replace(perssionName, "(主观)", "", -1)
+					mapIsUpgrade[fmt.Sprint(v.CompanyContractId, "perssionName", perssionName)] = true
+				}
+			}
+		} else {
+			if v.ChartPermissionId == utils.CHART_PERMISSION_ID_YANXUAN {
+				if v.ExpensiveYx == 1 {
+					mapContractIdPerssion[(v.CompanyContractId)] += "," + utils.CHART_PERMISSION_NAME_MF_YANXUAN + "(5w)"
+				} else {
+					mapContractIdPerssion[(v.CompanyContractId)] += "," + utils.CHART_PERMISSION_NAME_MF_YANXUAN + "(3w)"
+				}
 			}
 		}
 	}
-
 	//合并客观权限
 	for k, v := range mapContractIdPerssion {
 		perssionName := v
@@ -96,25 +106,151 @@ func GetCompanyContractPermissionNameMapById(mapCompamy map[int]string) (mapCont
 			perssionName = strings.Replace(perssionName, "智造(主观)", "智造", -1)
 			perssionName = strings.Replace(perssionName, "智造(客观)", "", -1)
 		}
+
 		perssionName = strings.TrimRight(perssionName, ",")
 		mapContractIdPerssion[k] = perssionName
 	}
 	mapContractResp = make(map[int]string, 0)
-	for k, v := range mapContractIdPerssion {
-		mapContractResp[mapContracIdCompanyId[k]] += v + ","
-	}
 
 	//过滤多余的","
-	for k, v := range mapContractResp {
+	for k, v := range mapContractIdPerssion {
 		sliceName := strings.Split(v, ",")
 		var nameArr []string
 		for _, vName := range sliceName {
 			if vName == "" {
 				continue
 			}
+			if mapIsUpgrade[fmt.Sprint(k, "perssionName", vName)] {
+				vName += "(升级)"
+			}
 			nameArr = append(nameArr, vName)
 		}
 		mapContractResp[k] = strings.Join(nameArr, ",")
 	}
 	return
 }
+
+// 判断合同审核通过时间是否超过九十天
+func GetMapIsGrayByCompanyContractIds(companyContractIds []int) (mapResp map[int]bool, err error) {
+	lenArr := len(companyContractIds)
+	if lenArr == 0 {
+		return
+	}
+	var condition string
+	var pars []interface{}
+	pars = make([]interface{}, 0)
+	condition = " AND  company_contract_id IN (" + utils.GetOrmInReplace(lenArr) + ")    GROUP BY company_contract_id ORDER BY create_time DESC  "
+	pars = append(pars, companyContractIds)
+	companyContractPermissionList, e := company.GetCompanyContractPermissionList(condition, pars)
+	if e != nil && e.Error() != utils.ErrNoRow() {
+		err = errors.New("GetCompanyContractPermissionList, Err: " + e.Error())
+		return
+	}
+	//超过九十天就置灰
+	timeInit := time.Now().AddDate(0, 0, -180)
+	mapResp = make(map[int]bool, 0)
+	for _, v := range companyContractPermissionList {
+		if v.CreateTime.Before(timeInit) {
+			mapResp[v.CompanyContractId] = true
+		}
+	}
+	return
+}
+
+//func init3() {
+//	var condition string
+//	var pars []interface{}
+//	//默认只查询权益 2023-06-01 之后的合同
+//	condition += ` AND c.product_id = ?  AND a.start_date > ? `
+//	pars = append(pars, 2, "2023-06-01")
+//
+//	//列表页数据
+//	list, err := cygx.GetCompanyContractListJoinCompany(condition, pars, 0, 1000)
+//	if err != nil {
+//		fmt.Println(err)
+//		return
+//	}
+//
+//	for _, v := range list {
+//		fmt.Println(v.CompanyContractId)
+//		HandleAllocationCompanyContractByYanXuan(v.CompanyContractId)
+//	}
+//
+//	fmt.Println(len(list))
+//}
+
+// 如果合同只有研选的时候,自动处理派点
+func HandleAllocationCompanyContractByYanXuan(companyContractId int) (err error) {
+	defer func() {
+		if err != nil {
+			fmt.Println(err)
+			go alarm_msg.SendAlarmMsg(fmt.Sprint("如果合同只有研选的时候,自动处理派点失败,Err:", err.Error(), "companyContractId", companyContractId), 2)
+		}
+	}()
+	var condition string
+	var pars []interface{}
+	pars = make([]interface{}, 0)
+	condition = " AND  company_contract_id = ?  "
+	pars = append(pars, companyContractId)
+	companyContractPermissionList, e := company.GetCompanyContractPermissionList(condition, pars)
+	if e != nil && e.Error() != utils.ErrNoRow() {
+		err = errors.New("GetCompanyContractPermissionList, Err: " + e.Error())
+		return
+	}
+	if e != nil && e.Error() != utils.ErrNoRow() {
+		err = errors.New("GetCygxAllocationCompanyContractPermissionListById, Err: " + e.Error())
+		return
+	}
+
+	if len(companyContractPermissionList) > 1 {
+		return
+	}
+	var expensiveYxmoney float64
+	for _, v := range companyContractPermissionList {
+		if v.ChartPermissionId != utils.CHART_PERMISSION_ID_YANXUAN {
+			err = errors.New("没有发现研选权限: ")
+			return
+		}
+		if v.ExpensiveYx == 1 {
+			expensiveYxmoney = 5
+		} else {
+			expensiveYxmoney = 3
+		}
+	}
+
+	var items []*cygx.CygxAllocationCompanyContract
+	var itemsPermission []*cygx.CygxAllocationCompanyContractPermission
+
+	itemPermission := new(cygx.CygxAllocationCompanyContractPermission)
+	itemPermission.CompanyContractId = companyContractId
+	//itemPermission.AdminId = sysUser.AdminId
+	//itemPermission.AdminName = sysUser.RealName
+	itemPermission.Proportion = 0
+	itemPermission.Money = expensiveYxmoney
+	itemPermission.MoneyAvg = 0
+	itemPermission.ChartPermissionName = utils.CHART_PERMISSION_NAME_MF_YANXUAN
+	itemPermission.CreateTime = time.Now()
+	itemPermission.ModifyTime = time.Now()
+	itemsPermission = append(itemsPermission, itemPermission)
+
+	item := new(cygx.CygxAllocationCompanyContract)
+	item.CompanyContractId = companyContractId
+	//item.AdminId = sysUser.AdminId
+	//item.AdminName = sysUser.RealName
+	item.Proportion = 0
+	item.Money = expensiveYxmoney
+	item.RealName = utils.CHART_PERMISSION_NAME_MF_YANXUAN
+	item.ChartPermissionName = utils.CHART_PERMISSION_NAME_MF_YANXUAN
+	item.CreateTime = time.Now()
+	item.ModifyTime = time.Now()
+	items = append(items, item)
+
+	e = cygx.AddAndUpdateCygxAllocationCompanyContract(items, itemsPermission, companyContractId)
+	if e != nil {
+		err = errors.New("AddAndUpdateCygxAllocationCompanyContract, Err: " + e.Error())
+		return
+	}
+
+	return
+
+}

+ 1 - 1
utils/constants.go

@@ -464,7 +464,7 @@ const (
 	CYGX_YANXUAN_POINTS_KEY              string = "CYGX_YANXUAN_POINTS_KEY"                                       //查研观向研选活动扣点KEY(冲突,先放这里)
 	WX_MSG_PATH_YX_SPECIAL_DETAIL               = "pages-purchaser/noteAndViewpoint/noteAndViewpoint?id="         //研选专栏详情
 	WX_MSG_PATH_YX_SPECIAL_ENABLE_DETAIL        = "pages-purchaser/toExamine/toExamine?id="                       //研选专栏审核详情页面
-	WX_MSG_PATH_YX_SPECIAL_CENTER               = "pages-purchaser/contentAllPage/contentAllPage"                 //研选专栏内容中心
+	WX_MSG_PATH_YX_SPECIAL_CENTER               = "pages-purchaser/contentAllPage/contentAllPage?Status=4"        //研选专栏内容中心
 )
 
 // 图表类型