Browse Source

Merge remote-tracking branch 'origin/debug' into debug

Roc 1 year ago
parent
commit
65390d059d

+ 140 - 1
controllers/company_renewal.go

@@ -349,7 +349,146 @@ func (this *CompanyRenewalController) CompanyNoRenewedAscribeAddDetail() {
 		return
 	}
 	resp := new(company.CompanyNoRenewedAscribeDetailResp)
-	detail, err := company.GetCygxProductInteriorDetail(companyId, productId)
+	detail, err := company.GetCompanyNoRenewedAscribeDetail(companyId, productId)
+	if err != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取失败,Err:" + err.Error()
+		return
+	}
+	resp.Detail = detail
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = resp
+}
+
+// @Title 合同通过归因添加确认不续约
+// @Description 合同通过归因添加确认不续约接口
+// @Param	request	body company.CompanyNoRenewedNoteReq true "type json string"
+// @Success 200 {object} "保存成功"
+// @router /company_contract_no_renewed_ascribe/add [post]
+func (this *CompanyRenewalController) CompanyContractNoRenewedAscribeAdd() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	sysUser := this.SysUser
+	if sysUser == nil {
+		br.Msg = "请登录"
+		br.ErrMsg = "请登录,SysUser Is Empty"
+		br.Ret = 408
+		return
+	}
+
+	//内容仅权益管理员账号可以修改
+	if sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_ADMIN && sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_RAI_ADMIN {
+		br.Msg = "仅管理员可修改!"
+		return
+	}
+	var req company.CompanyContractNoRenewedAscribeReq
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+	content := req.Content
+	companyAscribeId := req.CompanyAscribeId
+	companyContractId := req.CompanyContractId
+
+	if content == "" {
+		br.Msg = "内容不能为空!"
+		return
+	}
+
+	contractInfo, err := company.GetCompanyContractDetailByCompanyContractId(companyContractId)
+	if err != nil {
+		br.Msg = "获取合同失败"
+		br.ErrMsg = "获取合同失败,Err:" + err.Error()
+		return
+	}
+	companyId := contractInfo.CompanyId //公司ID
+	productId := contractInfo.ProductId //权益还是FICC
+
+	detail, err := company.GetCompanyAscribeDetail(companyAscribeId)
+	if err != nil {
+		br.Msg = "新建失败"
+		br.ErrMsg = "新建失败,GetCompanyAscribeDetail Err:" + err.Error()
+		return
+	}
+	var condition string
+	var pars []interface{}
+	condition += ` AND  company_id  = ?  AND product_id = ? AND company_contract_id = ?  `
+	pars = append(pars, companyId, productId, companyContractId)
+
+	total, err := company.GetCompanyContractNoRenewedAscribeCount(condition, pars)
+	if err != nil {
+		br.Msg = "新建失败"
+		br.ErrMsg = "新建失败,GetCompanyContractNoRenewedAscribeCount Err:" + err.Error()
+		return
+	}
+	item := new(company.CompanyContractNoRenewedAscribe)
+	item.CompanyAscribeId = companyAscribeId
+	item.AscribeContent = detail.AscribeContent
+	item.Content = content
+	item.ProductId = productId
+	item.CompanyId = companyId
+	item.CompanyContractId = companyContractId
+	item.AdminId = sysUser.AdminId
+	item.CreateTime = time.Now()
+	item.ModifyTime = time.Now()
+
+	itemLog := new(company.CompanyContractNoRenewedAscribeLog)
+	itemLog.CompanyAscribeId = companyAscribeId
+	itemLog.AscribeContent = detail.AscribeContent
+	itemLog.Content = content
+	itemLog.ProductId = productId
+	itemLog.CompanyId = companyId
+	itemLog.CompanyContractId = companyContractId
+	itemLog.AdminId = sysUser.AdminId
+	itemLog.CreateTime = time.Now()
+	itemLog.ModifyTime = time.Now()
+	if total == 0 {
+		err = company.AddCompanyContractNoRenewedAscribe(item, itemLog)
+	} else {
+		err = company.UpdateCompanyContractNoRenewedAscribe(item, itemLog)
+	}
+	if err != nil {
+		br.Msg = "新建失败"
+		br.ErrMsg = "新建失败,Err:" + err.Error()
+		return
+	}
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "新建成功"
+}
+
+// @Title 合同确认归因不续约详情接口
+// @Description 合同确认归因不续约详情接口
+// @Param   CompanyContractId   query   int  true       "合同ID"
+// @Success 200 {object} company.CompanyAscribeListResp
+// @router /company_contract_no_renewed_ascribe/detail [get]
+func (this *CompanyRenewalController) CompanyContractNoRenewedAscribeAddDetail() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	sysUser := this.SysUser
+	if sysUser == nil {
+		br.Msg = "请登录"
+		br.ErrMsg = "请登录,SysUser Is Empty"
+		return
+	}
+	companyContractId, _ := this.GetInt("CompanyContractId")
+	if companyContractId < 1 {
+		br.Msg = "合同ID错误!"
+		return
+	}
+
+	resp := new(company.CompanyContractNoRenewedAscribeDetailResp)
+	detail, err := company.GetCompanyContractNoRenewedAscribeDetail(companyContractId)
 	if err != nil {
 		br.Msg = "获取失败"
 		br.ErrMsg = "获取失败,Err:" + err.Error()

+ 2 - 2
controllers/company_user.go

@@ -5973,8 +5973,8 @@ func (this *CompanyUserController) Follow() {
 		return
 	}
 	if count == 3 && req.Type == 1 {
-		br.Msg = "关注失败,公司已达到关注上限 "
-		br.ErrMsg = "关注失败,公司已达到关注上限"
+		br.Msg = "关注失败,特别关注已达上限(上限三个)"
+		br.ErrMsg = "关注失败,特别关注已达上限(上限三个)"
 		return
 	}
 

+ 22 - 3
controllers/cygx/tag_management.go

@@ -27,6 +27,8 @@ type TagManagementController struct {
 // @Param   CurrentIndex   query   int  true       "当前页码"
 // @Param   PageSize   query   int  true       "每页数据数"
 // @Param   Status   query   string  false       "发布状态,1,上线,0下线"
+// @Param   SortParam   query   string  false       "排序字段参数,用来排序的字段, 枚举值: 'pv':总Pv/Uv "
+// @Param   SortType   query   string  true       "如何排序,是正序还是倒序,枚举值:`asc 正序`,`desc 倒叙`"
 // @Success 200 {object} cygx.ChartPermissionResp
 // @router /tag/list [get]
 func (this *TagManagementController) TagList() {
@@ -46,6 +48,9 @@ func (this *TagManagementController) TagList() {
 	pageSize, _ := this.GetInt("PageSize")
 	currentIndex, _ := this.GetInt("CurrentIndex")
 	status, _ := this.GetInt("Status", 1)
+	//排序参数
+	sortParam := this.GetString("SortParam")
+	sortType := this.GetString("SortType")
 
 	var condition string
 	var startSize int
@@ -58,9 +63,9 @@ func (this *TagManagementController) TagList() {
 	startSize = utils.StartIndex(currentIndex, pageSize)
 
 	if status == 1 {
-		condition += ` AND status=1 ORDER BY online_time DESC  `
+		condition += ` AND status=1 `
 	} else {
-		condition += ` AND status=0 ORDER BY online_time DESC  `
+		condition += ` AND status=0  `
 	}
 
 	total, err := cygx.GetCygxTagListCount(condition)
@@ -71,6 +76,20 @@ func (this *TagManagementController) TagList() {
 	}
 	page := paging.GetPaging(currentIndex, pageSize, total)
 
+	//排序字段以及排序方式处理
+	var sortStr string
+	if sortParam != "" && sortType != "" {
+		if sortParam == "pv" {
+			if sortType == "asc" {
+				sortStr = " ORDER BY pv ASC,  online_time DESC "
+			} else {
+				sortStr = " ORDER BY pv  DESC,  online_time DESC "
+			}
+		}
+	} else {
+		sortStr = "  ORDER BY online_time DESC "
+	}
+	condition += sortStr
 	list, err := cygx.GetCygxTagListPage(condition, startSize, pageSize)
 	if err != nil {
 		br.Msg = "获取标签失败"
@@ -433,7 +452,7 @@ func (this *TagManagementController) PvExport() {
 	}
 	var condition string
 	var pars []interface{}
-	condition = ` AND tag_id = ? `
+	condition = ` AND tag_id = ? AND  company_id != 16  `
 	pars = append(pars, tagId)
 	var respList []*cygx.CygxTagHistory
 	//respList := new(cygx.CygxTacticsTimeLineHistory)

+ 24 - 91
controllers/statistic_company_merge.go

@@ -77,11 +77,7 @@ func (this *StatisticCompanyMergerController) MergeCompanyList() {
 	if dataType != "续约客户" {
 		packageDifference = "" // 只有续约客户才会有值,过滤前端传过来的脏数据
 	}
-	//if startDate == "" || endDate == "" {
-	//	br.Msg = "获取失败,开始日期或结束日期未传"
-	//	br.ErrMsg = "获取失败,开始日期或结束日期未传"
-	//	return
-	//}
+
 	if startDate == "" {
 		startDate = "2015-01-01"
 	}
@@ -137,58 +133,57 @@ func (this *StatisticCompanyMergerController) MergeCompanyList() {
 	var conditionConfirm string
 	var parsConfirm []interface{}
 
-	companyConfirmList, err := company.GetCompanyNoRenewedAscribeList(conditionConfirm, parsConfirm, 0, 0)
+	companyConfirmList, err := company.GetCompanyContractNoRenewedAscribeList(conditionConfirm, parsConfirm, 0, 0)
 	if err != nil && err.Error() != utils.ErrNoRow() {
 		br.Msg = "获取失败"
 		br.ErrMsg = "获取失败,GetCompanyNoRenewedAscribeList Err:" + err.Error()
 		return
 	}
-	var noRenewedcompanyIds []int //已经确定未续约的公司ID
+	var noRenewedcompanyContractIds []int //已经确定未续约的公司ID
 	if len(companyConfirmList) == 0 {
-		noRenewedcompanyIds = append(noRenewedcompanyIds, 0) // 给一个不存在的ID
+		noRenewedcompanyContractIds = append(noRenewedcompanyContractIds, 0) // 给一个不存在的ID
 	} else {
 		for _, v := range companyConfirmList {
-			noRenewedcompanyIds = append(noRenewedcompanyIds, v.CompanyId)
+			noRenewedcompanyContractIds = append(noRenewedcompanyContractIds, v.CompanyContractId)
 		}
 	}
 	//是否确认续约 CRM 13.9
-	conditionAscribRaiTotal += ` AND  c.company_id IN (` + utils.GetOrmInReplace(len(noRenewedcompanyIds)) + `)  ` // 已确认
-	parsAscribeRaiTotal = append(parsAscribeRaiTotal, noRenewedcompanyIds)
+	conditionAscribRaiTotal += ` AND  a.company_contract_id IN (` + utils.GetOrmInReplace(len(noRenewedcompanyContractIds)) + `)  ` // 已确认
+	parsAscribeRaiTotal = append(parsAscribeRaiTotal, noRenewedcompanyContractIds)
 
-	conditionAscribRaiToBeTotal += ` AND c.company_id NOT IN (` + utils.GetOrmInReplace(len(noRenewedcompanyIds)) + `)   ` // 待确认
-	parsAscribeRaiTobeTotal = append(parsAscribeRaiTobeTotal, noRenewedcompanyIds)
+	conditionAscribRaiToBeTotal += ` AND a.company_contract_id NOT IN (` + utils.GetOrmInReplace(len(noRenewedcompanyContractIds)) + `)   ` // 待确认
+	parsAscribeRaiTobeTotal = append(parsAscribeRaiTobeTotal, noRenewedcompanyContractIds)
 
 	if isConfirm != -1 {
 		if isConfirm == 0 {
-			conditionAscribRai += ` AND  c.company_id NOT IN (` + utils.GetOrmInReplace(len(noRenewedcompanyIds)) + `)  ` // 待确认
+			conditionAscribRai += ` AND  a.company_contract_id NOT IN (` + utils.GetOrmInReplace(len(noRenewedcompanyContractIds)) + `)  ` // 待确认
 		} else {
-			conditionAscribRai += ` AND  c.company_id IN (` + utils.GetOrmInReplace(len(noRenewedcompanyIds)) + `)    ` // 已确认
+			conditionAscribRai += ` AND  a.company_contract_id IN (` + utils.GetOrmInReplace(len(noRenewedcompanyContractIds)) + `)    ` // 已确认
 		}
-		parsAscribeRai = append(parsAscribeRai, noRenewedcompanyIds)
+		parsAscribeRai = append(parsAscribeRai, noRenewedcompanyContractIds)
 	}
-
 	//归因ID CRM 13.9
 	if companyAscribeId > 0 {
 		var conditionAscribe string
 		var parsAscribe []interface{}
 		conditionAscribe = "  AND  company_ascribe_id = ? "
 		parsAscribe = append(parsAscribe, companyAscribeId)
-		companyNoRenewedAscribeList, err := company.GetCompanyNoRenewedAscribeList(conditionAscribe, parsAscribe, 0, 0)
+		companyNoRenewedAscribeList, err := company.GetCompanyContractNoRenewedAscribeList(conditionAscribe, parsAscribe, 0, 0)
 		if err != nil && err.Error() != utils.ErrNoRow() {
 			br.Msg = "获取失败"
 			br.ErrMsg = "获取失败,GetCompanyNoRenewedAscribeList Err:" + err.Error()
 			return
 		}
-		var companyIds []int
+		var noRenewedcompanyContractIds []int
 		if len(companyNoRenewedAscribeList) == 0 {
-			companyIds = append(companyIds, 0) // 给一个不存在的ID
+			noRenewedcompanyContractIds = append(noRenewedcompanyContractIds, 0) // 给一个不存在的ID
 		} else {
 			for _, v := range companyNoRenewedAscribeList {
-				companyIds = append(companyIds, v.CompanyId)
+				noRenewedcompanyContractIds = append(noRenewedcompanyContractIds, v.CompanyContractId)
 			}
 		}
-		conditionAscribRai += ` AND c.company_id IN (` + utils.GetOrmInReplace(len(companyIds)) + `)`
-		parsAscribeRai = append(parsAscribeRai, companyIds)
+		conditionAscribRai += ` AND a.company_contract_id IN (` + utils.GetOrmInReplace(len(noRenewedcompanyContractIds)) + `)`
+		parsAscribeRai = append(parsAscribeRai, noRenewedcompanyContractIds)
 	}
 
 	condition += ` AND c.product_id = ?   AND  a.status = 1 `
@@ -290,15 +285,6 @@ func (this *StatisticCompanyMergerController) MergeCompanyList() {
 		condition1 := condition
 		pars1 := pars
 
-		//endDateTime, err := time.Parse(utils.FormatDate, endDate)
-		//if err != nil {
-		//	br.Msg = "结束时间异常"
-		//	br.ErrMsg = "获取失败,Err:" + err.Error()
-		//	return
-		//}
-		////选择的日期加一天的原因是因为:筛选条件是截止到时分秒的,如果要把选择的这一天也统计进去,那么需要在选择的结束日期基础上加上一天
-		//tryOutEndDate := endDateTime.AddDate(0, 0, 1).Format(utils.FormatDate)
-
 		condition1 += ` AND a.end_date >= ? AND a.end_date  <= ? `
 		pars1 = append(pars1, startDate, endDate)
 		//condition1 += ` AND a.operation = ? `
@@ -368,13 +354,6 @@ func (this *StatisticCompanyMergerController) MergeCompanyList() {
 				total = notRenewalNotTryOut
 			}
 
-			//total, err := models.GetIncrementalCompanyProductCountByOperationRecord(condition1, pars1)
-			//if err != nil && err.Error() != utils.ErrNoRow() {
-			//	br.Msg = "获取失败"
-			//	br.ErrMsg = "获取失败,Err:" + err.Error()
-			//	return
-			//}
-
 			//分页total单独计算
 			total, err = company.GetIncrementalRenewalCompanyProductMergeCount(condition1, pars1)
 			if err != nil && err.Error() != utils.ErrNoRow() {
@@ -392,18 +371,20 @@ func (this *StatisticCompanyMergerController) MergeCompanyList() {
 			}
 
 			var ascribecompanyIds []int
+			var companyContractIds []int
 			for _, item := range tmpList {
 				//endDateTime, _ := time.Parse(utils.FormatDateTime, item.CreateTime)
 				//item.EndDate = endDateTime.Format(utils.FormatDate)
 				ascribecompanyIds = append(ascribecompanyIds, item.CompanyId)
+				companyContractIds = append(companyContractIds, item.CompanyContractId)
 			}
-			//归因标签
-			mapGetCompanyAscribeContent, mapContent := services.GetCompanyAscribeContentMap(ascribecompanyIds)
+			//合同归因标签
+			mapGetCompanyAscribeContent, mapContent := services.GetCompanyContractAscribeContentMap(companyContractIds)
 			mapNoRenewedNote := services.GetCompanyNoRenewedNoteMap(ascribecompanyIds)
 
 			for _, item := range tmpList {
-				item.AscribeContent = mapGetCompanyAscribeContent[fmt.Sprint("CID_", item.CompanyId, "PID_", item.ProductId)]
-				item.Content = mapContent[fmt.Sprint("CID_", item.CompanyId, "PID_", item.ProductId)]
+				item.AscribeContent = mapGetCompanyAscribeContent[item.CompanyContractId]
+				item.Content = mapContent[item.CompanyContractId]
 				item.IsShowNoRenewedNote = mapNoRenewedNote[fmt.Sprint("CID_", item.CompanyId, "PID_", item.ProductId)]
 			}
 
@@ -536,58 +517,10 @@ func MergeCompanyListListExport(this *StatisticCompanyMergerController, dataType
 	cellSellerName.SetStyle(style)
 	cellSellerName.SetValue("所属销售")
 
-	//permissionMap := make(map[int][]string)
-	//tmpPermissionMap := make(map[int]map[string][]string)
-	//companyContractIdList := make([]string, 0)
-	//for _, v := range resp.List {
-	//	companyContractIdList = append(companyContractIdList, fmt.Sprint(v.CompanyContractId))
-	//}
-	//if dataType == "新签客户" || dataType == "续约客户" {
 	cellMoney := titleRow.AddCell()
 	cellMoney.SetStyle(style)
 	cellMoney.SetValue("合同金额")
 
-	//这么大费周章的目的是为了:权益的品种存在主观、客观的区分,如果一个品种既存在主观,又存在客观,那么就展示品种名称,否则就要列出品种名称+主、客观类型
-	//if len(companyContractIdList) > 0 {
-	//	list, tmpErr := company.GetCompanyContractPermissionListByContractIds(strings.Join(companyContractIdList, ","))
-	//	if tmpErr != nil {
-	//		err = tmpErr
-	//		return
-	//	}
-	//	for _, v := range list {
-	//		tmpPermissionNameMap, ok := tmpPermissionMap[v.CompanyContractId]
-	//		if ok {
-	//			tmpPermissionNameList, ok2 := tmpPermissionNameMap[v.ChartPermissionName]
-	//			if ok2 {
-	//				tmpPermissionNameList = append(tmpPermissionNameList, v.PermissionRemark)
-	//			} else {
-	//				tmpPermissionNameList = []string{v.PermissionRemark}
-	//			}
-	//			tmpPermissionNameMap[v.ChartPermissionName] = tmpPermissionNameList
-	//		} else {
-	//			tmpPermissionNameMap = make(map[string][]string)
-	//			tmpPermissionNameMap[v.ChartPermissionName] = []string{v.PermissionRemark}
-	//		}
-	//		tmpPermissionMap[v.CompanyContractId] = tmpPermissionNameMap
-	//	}
-	//}
-	//}
-
-	//for companyContractId, tmpPermissionNameMap := range tmpPermissionMap {
-	//	tmpPermissionName := ``
-	//	tmpPermissionList := []string{}
-	//	for tmpChartPermissionName, tmpChartPermissionNameList := range tmpPermissionNameMap {
-	//		if len(tmpChartPermissionNameList) > 1 {
-	//			tmpPermissionName = tmpChartPermissionName
-	//		} else {
-	//			tmpPermissionName = tmpChartPermissionNameList[0]
-	//		}
-	//		tmpPermissionList = append(tmpPermissionList, tmpPermissionName)
-	//	}
-	//
-	//	permissionMap[companyContractId] = tmpPermissionList
-	//}
-
 	cellTime := titleRow.AddCell()
 	cellTime.SetStyle(style)
 	switch dataType {

+ 151 - 0
models/company/company_contract_no_renewed_ascribe.go

@@ -0,0 +1,151 @@
+package company
+
+//合同未续约说明
+import (
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+type CompanyContractNoRenewedAscribe struct {
+	NoRenewedAscribeId int       `orm:"column(no_renewed_ascribe_id);pk" description:"主键ID"`
+	CompanyAscribeId   int       `description:"归因ID"`
+	AscribeContent     string    `description:"归因说明"`
+	Content            string    `description:"内容说明"`
+	AdminId            int       `description:"管理员ID"`
+	CompanyId          int       `description:"公司ID"`
+	CompanyContractId  int       `description:"合同id"`
+	ProductId          int       `description:"产品id"`
+	CreateTime         time.Time `description:"创建时间"`
+	ModifyTime         time.Time `description:"更新时间"`
+}
+
+type CompanyContractNoRenewedAscribeLog struct {
+	NoRenewedAscribeId int       `orm:"column(no_renewed_ascribe_id);pk" description:"主键ID"`
+	CompanyAscribeId   int       `description:"归因ID"`
+	AscribeContent     string    `description:"归因说明"`
+	Content            string    `description:"内容说明"`
+	AdminId            int       `description:"管理员ID"`
+	CompanyId          int       `description:"公司ID"`
+	CompanyContractId  int       `description:"合同id"`
+	ProductId          int       `description:"产品id"`
+	CreateTime         time.Time `description:"创建时间"`
+	ModifyTime         time.Time `description:"更新时间"`
+}
+
+type CompanyContractNoRenewedAscribeResp struct {
+	NoRenewedAscribeId int    `description:"主键ID"`
+	CompanyAscribeId   int    `description:"归因ID"`
+	AscribeContent     string `description:"归因说明"`
+	ProductId          int    `description:"产品id"`
+	Content            string `description:"内容说明"`
+	AdminId            int    `description:"管理员ID"`
+	CompanyId          int    `description:"公司ID"`
+	CompanyContractId  int    `description:"合同id"`
+	CreateTime         string `description:"创建时间"`
+	ModifyTime         string `description:"更新时间"`
+}
+type CompanyContractNoRenewedAscribeListResp struct {
+	List []*CompanyContractNoRenewedAscribeResp
+}
+
+type CompanyContractNoRenewedAscribeDetailResp struct {
+	Detail *CompanyContractNoRenewedAscribeResp
+}
+
+type CompanyContractNoRenewedAscribeReq struct {
+	CompanyAscribeId  int    `description:"归因ID"`
+	ProductId         int    `description:"产品id"`
+	Content           string `description:"内容说明"`
+	CompanyId         int    `description:"公司ID"`
+	CompanyContractId int    `description:"合同id"`
+}
+
+// 添加
+func AddCompanyContractNoRenewedAscribe(item *CompanyContractNoRenewedAscribe, itemLog *CompanyContractNoRenewedAscribeLog) (err error) {
+	o := orm.NewOrm()
+	to, err := o.Begin()
+	if err != nil {
+		return
+	}
+	defer func() {
+		if err != nil {
+			_ = to.Rollback()
+		} else {
+			_ = to.Commit()
+		}
+	}()
+	_, err = to.Insert(item)
+	if err != nil {
+		return
+	}
+
+	_, err = to.Insert(itemLog)
+	return
+}
+
+// 修改
+func UpdateCompanyContractNoRenewedAscribe(item *CompanyContractNoRenewedAscribe, itemLog *CompanyContractNoRenewedAscribeLog) (err error) {
+	o := orm.NewOrm()
+	to, err := o.Begin()
+	if err != nil {
+		return
+	}
+	defer func() {
+		if err != nil {
+			_ = to.Rollback()
+		} else {
+			_ = to.Commit()
+		}
+	}()
+	updateParams := make(map[string]interface{})
+	updateParams["CompanyAscribeId"] = item.CompanyAscribeId
+	updateParams["ModifyTime"] = item.ModifyTime
+	updateParams["Content"] = item.Content
+	updateParams["AscribeContent"] = item.AscribeContent
+	ptrStructOrTableName := "company_contract_no_renewed_ascribe"
+	whereParam := map[string]interface{}{"company_id": item.CompanyId, "company_contract_id": item.CompanyContractId}
+	qs := to.QueryTable(ptrStructOrTableName)
+	for expr, exprV := range whereParam {
+		qs = qs.Filter(expr, exprV)
+	}
+	_, err = qs.Update(updateParams)
+	if err != nil {
+		return
+	}
+	_, err = to.Insert(itemLog)
+	return
+}
+
+// 获取数量
+func GetCompanyContractNoRenewedAscribeCount(condition string, pars []interface{}) (count int, err error) {
+	sqlCount := ` SELECT COUNT(1) AS count  FROM company_contract_no_renewed_ascribe as a WHERE 1= 1  `
+	if condition != "" {
+		sqlCount += condition
+	}
+	o := orm.NewOrm()
+	err = o.Raw(sqlCount, pars).QueryRow(&count)
+	return
+}
+
+// 通过ID获取详情
+func GetCompanyContractNoRenewedAscribeDetail(companyContractId int) (item *CompanyContractNoRenewedAscribeResp, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM company_contract_no_renewed_ascribe   WHERE company_contract_id=?  `
+	err = o.Raw(sql, companyContractId).QueryRow(&item)
+	return
+}
+
+// 列表
+func GetCompanyContractNoRenewedAscribeList(condition string, pars []interface{}, startSize, pageSize int) (items []*CompanyContractNoRenewedAscribeResp, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM company_contract_no_renewed_ascribe as a  WHERE 1= 1 `
+	if condition != "" {
+		sql += condition
+	}
+	if startSize+pageSize > 0 {
+		sql += ` LIMIT ?,?  `
+		_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
+	}
+	_, err = o.Raw(sql, pars).QueryRows(&items)
+	return
+}

+ 1 - 1
models/company/company_no_renewed_ascribe.go

@@ -123,7 +123,7 @@ func GetCompanyNoRenewedAscribeCount(condition string, pars []interface{}) (coun
 }
 
 // 通过ID获取详情
-func GetCygxProductInteriorDetail(companyId, productId int) (item *CompanyNoRenewedAscribeResp, err error) {
+func GetCompanyNoRenewedAscribeDetail(companyId, productId int) (item *CompanyNoRenewedAscribeResp, err error) {
 	o := orm.NewOrm()
 	sql := `SELECT * FROM company_no_renewed_ascribe   WHERE company_id=?  AND product_id = ? `
 	err = o.Raw(sql, companyId, productId).QueryRow(&item)

+ 1 - 1
models/company/company_user.go

@@ -141,7 +141,7 @@ func GetCompanyUserListV2(condition string, pars []interface{}, companyId, start
 		sql += condition
 	}
 	//sql += ` group by a.user_id ORDER BY a.is_register desc,a.report_last_view_time desc,a.last_updated_time DESC LIMIT ?,? `
-	sql += ` group by a.user_id ORDER BY CASE WHEN is_follow = 1 AND report_last_view_time < NOW()  - INTERVAL 7 DAY THEN 0 ELSE 1 END,a.is_register desc,a.report_last_view_time desc,a.last_updated_time DESC  LIMIT ?,? `
+	sql += ` group by a.user_id ORDER BY CASE WHEN is_follow = 1 AND (report_last_view_time < NOW()  - INTERVAL 7 DAY or report_last_view_time is NULL ) THEN 0 ELSE 1 END,a.is_register desc,a.report_last_view_time ASC,a.last_updated_time  ASC LIMIT ?,? `
 	_, err = o.Raw(sql, companyId, pars, startSize, pageSize).QueryRows(&items)
 	return
 }

+ 13 - 13
models/cygx/cygx_tag.go

@@ -43,17 +43,17 @@ func (m *CygxTag) Update(cols []string) (err error) {
 
 type CygxTagList struct {
 	TagId         int64  `orm:"column(tag_id);pk"`
-	TagName       string `orm:"column(tag_name);NOT NULL"`       // 标签名
-	ArticleTypes  string `orm:"column(article_types);NOT NULL"`  // 报告系列
-	ActivityTypes string `orm:"column(activity_types);NOT NULL"` // 活动类型
-	Industries    string `orm:"column(industries);NOT NULL"`     // 产业
-	SubjectNames  string `orm:"column(subject_names);NOT NULL"`  // 标的
-	Sort          int    `orm:"column(sort);"`                   // 优先级
-	ModifyTime    string `orm:"column(modify_time)"`             // 修改时间
-	CreateTime    string `orm:"column(create_time)"`             // 创建时间
-	OnlineTime    string `orm:"column(online_time)"`             // 上线时间
-	OfflineTime   string `orm:"column(offline_time)"`            // 下线时间
-	Status        int    `orm:"column(status);NOT NULL"`         // 状态:0-禁用 1-启用
+	TagName       string `orm:"column(tag_name);"`       // 标签名
+	ArticleTypes  string `orm:"column(article_types);"`  // 报告系列
+	ActivityTypes string `orm:"column(activity_types);"` // 活动类型
+	Industries    string `orm:"column(industries);"`     // 产业
+	SubjectNames  string `orm:"column(subject_names);"`  // 标的
+	Sort          int    `orm:"column(sort);"`           // 优先级
+	ModifyTime    string `orm:"column(modify_time)"`     // 修改时间
+	CreateTime    string `orm:"column(create_time)"`     // 创建时间
+	OnlineTime    string `orm:"column(online_time)"`     // 上线时间
+	OfflineTime   string `orm:"column(offline_time)"`    // 下线时间
+	Status        int    `orm:"column(status);"`         // 状态:0-禁用 1-启用
 	Pv            int    `description:"PV"`
 	Uv            int    `description:"UV"`
 	TagType       int    `description:"1:热门活动、2:海外研究、3:路演回放、4:语音问答"`
@@ -98,8 +98,8 @@ func GetCygxTagListCountByCondition(condition string, pars []interface{}) (count
 func GetCygxTagListPage(cond string, startSize, pageSize int) (items []*CygxTagList, err error) {
 	o := orm.NewOrmUsingDB("hz_cygx")
 	sql := `SELECT *,
-		(SELECT COUNT(1) FROM cygx_tag_history AS avr WHERE avr.tag_id=cygx_tag.tag_id) AS pv,
-        (SELECT COUNT(DISTINCT user_id) FROM cygx_tag_history AS avr WHERE avr.tag_id=cygx_tag.tag_id) AS uv
+		(SELECT COUNT(1) FROM cygx_tag_history AS avr WHERE avr.tag_id=cygx_tag.tag_id AND avr.company_id != 16  ) AS pv,
+        (SELECT COUNT(DISTINCT user_id) FROM cygx_tag_history AS avr WHERE avr.tag_id=cygx_tag.tag_id AND avr.company_id != 16 ) AS uv
 		FROM cygx_tag  WHERE 1=1 `
 	if cond != "" {
 		sql += cond

+ 3 - 3
models/cygx/cygx_user.go

@@ -4,6 +4,7 @@ import (
 	"github.com/beego/beego/v2/client/orm"
 	"github.com/rdlucklib/rdluck_tools/paging"
 	"hongze/hz_crm_api/models/company"
+	"hongze/hz_crm_api/utils"
 	"strconv"
 	"strings"
 	"time"
@@ -183,7 +184,7 @@ func GetCygxCompanyUserListByNoLoss() (items []*CygxCompanyUserAndSellerResp, er
 
 // 对于上面的SQL的拆分优化查询速度
 func GetCygxCompanyUserListSplit(userIds string) (items []*CygxCompanyUser, err error) {
-
+	databaseName := utils.GetWeeklyDatabase()
 	o := orm.NewOrmUsingDB("hz_cygx")
 	sql := `SELECT
 			u.user_id,
@@ -202,8 +203,7 @@ func GetCygxCompanyUserListSplit(userIds string) (items []*CygxCompanyUser, err
 			( SELECT COUNT( 1 ) FROM cygx_activity_video_history AS h  INNER JOIN cygx_activity_video as v ON v.video_id = h.video_id WHERE  h.mobile = u.mobile  ) AS activity_video_num,
 			( SELECT COUNT( 1 ) FROM cygx_activity_voice_history AS h  INNER JOIN cygx_activity_voice as v ON v.activity_voice_id = h.activity_voice_id WHERE  h.mobile = u.mobile  ) AS activity_voice_num,
 			( SELECT COUNT( 1 ) FROM cygx_yanxuan_special_record AS h  INNER JOIN cygx_yanxuan_special as v ON v.id = h.yanxuan_special_id WHERE  h.mobile = u.mobile  ) AS yanxuanspecial_num
-		FROM
-			cygx_user_label AS u WHERE  u.user_id IN (` + userIds + `)  AND u.mobile != ''	GROUP BY u.user_id  `
+		FROM ` + databaseName + `.wx_user AS u WHERE  u.user_id IN (` + userIds + `)  AND u.mobile != ''	GROUP BY u.user_id  `
 	_, err = o.Raw(sql).QueryRows(&items)
 	return
 }

+ 2 - 0
models/db.go

@@ -260,6 +260,8 @@ func initCompany() {
 		new(company.CompanyNoRenewedNote),                    // 客户未续约记录
 		new(company.CompanyNoRenewedAscribe),                 // 确认不续约记录
 		new(company.CompanyNoRenewedAscribeLog),              // 确认不续约记录日志
+		new(company.CompanyContractNoRenewedAscribe),         // 合同确认不续约记录
+		new(company.CompanyContractNoRenewedAscribeLog),      // 合同确认不续约记录日志
 		new(company.CrmConfig),                               // 管理后台基本配置表
 		new(company.CompanyRenewalRecord),                    // 客户续约状态记录表
 	)

+ 18 - 0
routers/commentsRouter.go

@@ -9466,6 +9466,24 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["hongze/hz_crm_api/controllers:CompanyRenewalController"] = append(beego.GlobalControllerRouter["hongze/hz_crm_api/controllers:CompanyRenewalController"],
+        beego.ControllerComments{
+            Method: "CompanyContractNoRenewedAscribeAdd",
+            Router: `/company_contract_no_renewed_ascribe/add`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["hongze/hz_crm_api/controllers:CompanyRenewalController"] = append(beego.GlobalControllerRouter["hongze/hz_crm_api/controllers:CompanyRenewalController"],
+        beego.ControllerComments{
+            Method: "CompanyContractNoRenewedAscribeAddDetail",
+            Router: `/company_contract_no_renewed_ascribe/detail`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["hongze/hz_crm_api/controllers:CompanyRenewalController"] = append(beego.GlobalControllerRouter["hongze/hz_crm_api/controllers:CompanyRenewalController"],
         beego.ControllerComments{
             Method: "CompanyNoRenewedAscribeAdd",

+ 31 - 0
services/company_ascribe.go

@@ -67,3 +67,34 @@ func GetCompanyNoRenewedNoteMap(companyIds []int) (mapResp map[string]bool) {
 	}
 	return
 }
+
+// 处理公司合同归因展示
+func GetCompanyContractAscribeContentMap(companyContractIds []int) (mapResp map[int]string, mapCountResp map[int]string) {
+	var err error
+	defer func() {
+		if err != nil {
+			fmt.Println("err:", err)
+			go alarm_msg.SendAlarmMsg(" 处理公司归因展示失败 GetCompanyContractAscribeContentMap,Err:"+err.Error(), 3)
+		}
+	}()
+	lenArr := len(companyContractIds)
+	if lenArr == 0 {
+		return
+	}
+	var condition string
+	var pars []interface{}
+	condition = ` AND company_contract_id IN (` + utils.GetOrmInReplace(len(companyContractIds)) + `)`
+	pars = append(pars, companyContractIds)
+	list, e := company.GetCompanyContractNoRenewedAscribeList(condition, pars, 0, 0)
+	if e != nil && e.Error() != utils.ErrNoRow() {
+		err = errors.New("GetCompanyNoRenewedAscribeList, Err: " + e.Error())
+		return
+	}
+	mapResp = make(map[int]string, 0)
+	mapCountResp = make(map[int]string, 0)
+	for _, v := range list {
+		mapResp[v.CompanyContractId] = v.AscribeContent
+		mapCountResp[v.CompanyContractId] = v.Content
+	}
+	return
+}