Эх сурвалжийг харах

Merge branch 'crm/crm_need_p1_879' of http://8.136.199.33:3000/hongze/hz_crm_api

xingzai 1 жил өмнө
parent
commit
82bcb84b8f

+ 223 - 1
controllers/company_renewal.go

@@ -2,6 +2,7 @@ package controllers
 
 import (
 	"encoding/json"
+	"fmt"
 	"hongze/hz_crm_api/models"
 	"hongze/hz_crm_api/models/company"
 	"hongze/hz_crm_api/utils"
@@ -349,7 +350,7 @@ 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()
@@ -361,3 +362,224 @@ func (this *CompanyRenewalController) CompanyNoRenewedAscribeAddDetail() {
 	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()
+		return
+	}
+	resp.Detail = detail
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = resp
+}
+
+func init12123() {
+	var condition string
+	var pars []interface{}
+	list, e := company.GetCompanyNoRenewedAscribeList(condition, pars, 0, 0)
+	if e != nil && e.Error() != utils.ErrNoRow() {
+		fmt.Println(e)
+		return
+	}
+
+	for _, v := range list {
+		pars = make([]interface{}, 0)
+		condition = " AND  company_id = ? "
+		pars = append(pars, v.CompanyId)
+
+		companyContractList, e := company.GetCompanyContractList(condition, pars)
+		if e != nil && e.Error() != utils.ErrNoRow() {
+			fmt.Println(e)
+			return
+		}
+		for _, vC := range companyContractList {
+			item := new(company.CompanyContractNoRenewedAscribe)
+			item.CompanyAscribeId = v.CompanyAscribeId
+			item.AscribeContent = v.AscribeContent
+			item.Content = v.Content
+			item.ProductId = v.ProductId
+			item.CompanyId = v.CompanyId
+			item.CompanyContractId = vC.CompanyContractId
+			item.AdminId = v.AdminId
+			item.CreateTime = utils.StrTimeToTime(v.CreateTime)
+			item.ModifyTime = utils.StrTimeToTime(v.CreateTime)
+
+			itemLog := new(company.CompanyContractNoRenewedAscribeLog)
+			itemLog.CompanyAscribeId = v.CompanyAscribeId
+			itemLog.AscribeContent = v.AscribeContent
+			itemLog.Content = v.Content
+			itemLog.ProductId = v.ProductId
+			itemLog.CompanyId = v.CompanyId
+			itemLog.CompanyContractId = vC.CompanyContractId
+			itemLog.AdminId = v.AdminId
+			itemLog.CreateTime = utils.StrTimeToTime(v.CreateTime)
+			itemLog.ModifyTime = utils.StrTimeToTime(v.CreateTime)
+
+			err := company.AddCompanyContractNoRenewedAscribe(item, itemLog)
+			fmt.Println(err)
+		}
+	}
+	return
+}
+
+func init879() {
+
+	companyContractList, e := models.GetIncrementalCompanyListByOperationRecordMerge879()
+	if e != nil && e.Error() != utils.ErrNoRow() {
+		fmt.Println(e)
+		return
+	}
+	fmt.Println(len(companyContractList))
+	//return
+	for _, v := range companyContractList {
+		item := new(company.CompanyContractNoRenewedAscribe)
+		item.CompanyContractId = v.CompanyContractId
+		item.ProductId = v.ProductId
+		item.CompanyId = v.CompanyId
+		item.CreateTime = time.Now()
+		item.ModifyTime = time.Now()
+
+		itemLog := new(company.CompanyContractNoRenewedAscribeLog)
+		itemLog.AscribeContent = v.AscribeContent
+		itemLog.Content = v.Content
+		itemLog.ProductId = v.ProductId
+		itemLog.CompanyId = v.CompanyId
+		itemLog.CompanyContractId = v.CompanyContractId
+		itemLog.CreateTime = time.Now()
+		itemLog.ModifyTime = time.Now()
+
+		err := company.AddCompanyContractNoRenewedAscribe(item, itemLog)
+		fmt.Println(err)
+	}
+
+	return
+}

+ 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)

+ 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),                               // 管理后台基本配置表
 	)
 }

+ 49 - 0
models/statistic_report.go

@@ -893,3 +893,52 @@ func GetIncrementalCompanyListByOperationRecordMerge(condition string, pars []in
 	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
 	return
 }
+
+// GetIncrementalCompanyListByOperationRecordMerge 未续约合同
+func GetIncrementalCompanyListByOperationRecordMerge879() (items []*IncrementalList, err error) {
+	o := orm.NewOrm()
+	//查询真正的数据
+	sql := `SELECT
+	a.company_contract_id,
+	a.contract_type,
+	a.company_product_id,
+	a.contract_code,
+	a.pay_method,
+	a.pay_channel,
+	a.package_difference,
+	a.company_id,
+	a.start_date,
+	a.end_date,
+	a.money,
+	b.company_name,
+	c.seller_id,
+	c.seller_name,
+	a.product_id,
+	a.product_name,
+	a.create_time,
+	b.region_type,
+	c.renewal_reason,
+	c.renewal_todo,
+	c.STATUS 
+FROM
+	company_contract a
+	RIGHT JOIN company b ON a.company_id = b.company_id
+	JOIN company_product c ON b.company_id = c.company_id 
+	AND a.product_id = c.product_id 
+WHERE
+	1 = 1 
+	AND c.product_id = 2
+	AND a.STATUS = 1 
+	AND a.end_date >= '2017-09-05'
+	AND a.end_date <= '2022-12-31'
+	AND c.STATUS NOT IN ( "永续", "正式", "关闭" ) 
+	AND a.company_contract_id NOT IN (SELECT company_contract_id FROM company_contract_no_renewed_ascribe ) 
+GROUP BY
+	a.company_contract_id 
+ORDER BY
+	end_date DESC,
+	company_id DESC  limit	 10
+`
+	_, err = o.Raw(sql).QueryRows(&items)
+	return
+}

+ 18 - 0
routers/commentsRouter.go

@@ -9457,6 +9457,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
+}