xingzai 1 rok temu
rodzic
commit
7fb69ba5ce

+ 107 - 0
controllers/company_apply.go

@@ -2306,3 +2306,110 @@ func (this *CompanyApplyController) GetLastContractDetailWithoutDate() {
 	br.Msg = "获取成功"
 	br.Data = contractInfo
 }
+
+// @Title 申请服务更新-签约历史(单个详情)
+// @Description 申请服务更新-签约历史接口(单个详情)
+// @Param   ContractCode   query   string  true       "合同编码"
+// @Success 200 {object} company.CompanyContractHistoryResp
+// @router /apply/contract/history/detail [get]
+func (this *CompanyApplyController) ApplyContractHistoryDetail() {
+	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
+	}
+	contractCode := this.GetString("ContractCode")
+	if contractCode == "" {
+		br.Msg = "参数错误"
+		br.ErrMsg = "参数错误,客户id小于等于0"
+		return
+	}
+	roleTypeCode := sysUser.RoleTypeCode
+	productId := services.GetProductId(roleTypeCode)
+
+	list, err := company.GetCompanyContractHistoryListByContractCode(contractCode)
+	if err != nil {
+		br.Msg = "获取信息失败"
+		br.ErrMsg = "获取信息失败,Err:" + err.Error()
+		return
+	}
+	listLen := len(list)
+	if listLen == 0 {
+		br.Msg = "获取信息失败"
+		br.ErrMsg = "签约信息不存在 contractCode:" + contractCode
+		return
+	}
+	expMap := map[int]string{0: "(3w)", 1: "(5w)"} // 买方研选价格
+	for i := 0; i < listLen; i++ {
+		companyContract := list[i]
+		list[i].ModifyTimeStr = companyContract.ModifyTime.Format(utils.FormatDateTime)
+		productId = list[i].ProductId
+		if productId == utils.COMPANY_PRODUCT_RAI_ID {
+			//classifyName := "权益"
+			checkList := make([]int, 0)
+			plist := new(company.ContractPermissionList)
+			hasPermissions, e := company.GetCompanyContractPermissionByCompanyContractId(companyContract.CompanyContractId)
+			if e != nil {
+				br.Msg = "获取失败"
+				br.ErrMsg = "获取合同权限信息失败,Err:" + e.Error()
+				return
+			}
+			hasMap := make(map[int]*company.CompanyContractPermission)
+			for _, p := range hasPermissions {
+				hasMap[p.ChartPermissionId] = p
+			}
+			checkItems := make([]*company.PermissionLookItem, 0)
+			// PS:本来想把这个移到循环外面去优化一下...但是发现有指针引用变量被改掉的问题, BUG太多了改不完了先这样吧=_=!
+			raiPermissions, e := company.GetPermissionLookItemsExt("2", utils.COMPANY_PRODUCT_RAI_NAME)
+			if e != nil {
+				br.Msg = "获取失败"
+				br.ErrMsg = "获取权益权限列表失败, Err: " + e.Error()
+				return
+			}
+
+			for _, n := range raiPermissions {
+				match := hasMap[n.ChartPermissionId]
+				if match == nil {
+					continue
+				}
+				// 升级
+				if match.IsUpgrade == 1 {
+					n.IsUpgrade = 1
+					checkList = append(checkList, n.ChartPermissionId)
+					checkItems = append(checkItems, n)
+					continue
+				}
+				// 买方研选(3w/5w)
+				if n.PermissionName == utils.CHART_PERMISSION_NAME_MF_YANXUAN {
+					n.PermissionName += expMap[match.ExpensiveYx]
+					checkList = append(checkList, n.ChartPermissionId)
+					checkItems = append(checkItems, n)
+					continue
+				}
+				checkList = append(checkList, n.ChartPermissionId)
+				checkItems = append(checkItems, n)
+			}
+			plist.Items = checkItems
+			plist.ClassifyName = utils.COMPANY_PRODUCT_RAI_NAME
+			plist.CheckList = checkList
+			list[i].PermissionList = append(list[i].PermissionList, plist)
+
+			// CRM8.8-权限主客观合并
+			newPermissionLookList := contractService.HandleEquityContractPermissionList(list[i].PermissionList)
+			list[i].PermissionList = newPermissionLookList
+		}
+	}
+	resp := new(company.CompanyContractHistoryResp)
+	resp.List = list
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = resp
+}

+ 379 - 0
controllers/cygx/contract_allocation.go

@@ -1 +1,380 @@
 package cygx
+
+import (
+	"fmt"
+	"github.com/rdlucklib/rdluck_tools/paging"
+	"hongze/hz_crm_api/controllers"
+	"hongze/hz_crm_api/models"
+	"hongze/hz_crm_api/models/company"
+	"hongze/hz_crm_api/models/contract"
+	"hongze/hz_crm_api/models/cygx"
+	"hongze/hz_crm_api/models/system"
+	contractService "hongze/hz_crm_api/services/contract"
+	"hongze/hz_crm_api/utils"
+	"strconv"
+	"strings"
+	"time"
+)
+
+// ContractAllocationController 权益合同派单
+type ContractAllocationController struct {
+	controllers.BaseAuthController
+}
+
+// getQueryParams 获取基础查询信息
+func getQueryParams(condition string, pars []interface{}, sysUser *system.Admin, tableAlias string) (newCondition string, newPars []interface{}) {
+	if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN {
+		condition += " AND " + tableAlias + "product_id=?"
+		pars = append(pars, 1)
+	} else if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
+		condition += " AND " + tableAlias + "product_id=?"
+		pars = append(pars, 2)
+	} else if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_ADMIN || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FINANCE {
+		//超级管理员账户,不做条件限制
+	} else {
+		//如果不是研究员,那么去找对应的 部门、小组、销售
+		if sysUser.Authority == 0 {
+			//普通用户
+			condition += " AND " + tableAlias + "seller_id=?"
+			pars = append(pars, sysUser.AdminId)
+		} else if sysUser.Authority == 1 {
+			//部门主管
+			condition += " AND " + tableAlias + "department_id=?"
+			pars = append(pars, sysUser.DepartmentId)
+		} else if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
+			//权益小组负责人
+			condition += " AND " + tableAlias + "group_id=?"
+			pars = append(pars, sysUser.GroupId)
+		} else if sysUser.Authority == 2 && sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
+			//ficc销售主管
+			pid, err := company.GetParentIdFromGroup(sysUser.GroupId)
+			if err != nil {
+				fmt.Println(err.Error())
+				return
+			}
+			var ids []*string
+			if pid != nil && *pid != 0 {
+				ids, err = company.GetGroupIdsByParentId(*pid)
+				if err != nil {
+					fmt.Println(err.Error())
+				}
+			} else {
+				ids, err = company.GetGroupIdsByParentId(sysUser.GroupId)
+				if err != nil {
+					fmt.Println(err.Error())
+				}
+			}
+			var idSlice []string
+			var sid string
+			for _, id := range ids {
+				idSlice = append(idSlice, *id)
+			}
+			//加入父级groupId
+			if *pid > 0 {
+				idSlice = append(idSlice, strconv.Itoa(*pid))
+			} else {
+				idSlice = append(idSlice, strconv.Itoa(sysUser.GroupId))
+			}
+			sid = strings.Join(idSlice, ",")
+			condition += " AND " + tableAlias + `group_id IN (` + sid + `) `
+			fmt.Println("condition:", condition)
+			//pars = append(pars, sysUser.GroupId)
+		} else if sysUser.Authority == 4 {
+			//ficc小组负责人
+			condition += " AND " + tableAlias + "group_id=?"
+			pars = append(pars, sysUser.GroupId)
+		} else {
+			//不知道什么类型的用户(后面新增的位置类型客户)
+			condition += " AND " + tableAlias + "seller_id=?"
+			pars = append(pars, sysUser.AdminId)
+		}
+	}
+	newCondition = condition
+	newPars = pars
+	return
+}
+
+// @Title 合同列表
+// @Description 合同列表接口
+// @Param   PageSize   query   int  true       "每页数据条数"
+// @Param   CurrentIndex   query   int  true       "当前页页码,从1开始"
+// @Param   Keyword   query   string  true       "客户名称"
+// @Param   AdminId   query   string  true       "销售id,多个用英文逗号隔开,空字符串为全部"
+// @Param   StartDate   query   string  false       "开始日期"
+// @Param   EndDate   query   string  false       "结束日期"
+// @Param   ContractType   query   string  false       "合同类型,枚举值:“,`新签合同`,`续约合同`,`补充协议`"
+// @Param   FormalType   query   string  false     "转正类型,枚举值:“,`标准`,`非标`"
+// @Param   IsExport   query   bool  false       "是否导出excel,默认是false"
+// @Param   IsAllocation   query   int  false       "派点状态: -1-默认全部; 0-未派点; 1-已派点"
+// @Success 200 {object}  cygx.CompanyContractListResp
+// @router /allocation/company_contract_list [get]
+func (this *ContractAllocationController) CompanyContractList() {
+	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
+	}
+
+	pageSize, _ := this.GetInt("PageSize")
+	currentIndex, _ := this.GetInt("CurrentIndex")
+	adminId := this.GetString("AdminId")
+	formalType := this.GetString("FormalType")
+	contractType := this.GetString("ContractType")
+	keyword := this.GetString("Keyword")
+	startDate := this.GetString("StartDate")
+	endDate := this.GetString("EndDate")
+	isAllocation, _ := this.GetInt("IsAllocation", -1) // CRM 13.9
+	if startDate == "" {
+		startDate = "2015-01-01"
+	}
+	if endDate == "" {
+		endDate = time.Now().Format(utils.FormatDate)
+	}
+	var startSize int
+	if pageSize <= 0 {
+		pageSize = utils.PageSize20
+	}
+	if currentIndex <= 0 {
+		currentIndex = 1
+	}
+	startSize = utils.StartIndex(currentIndex, pageSize)
+	//是否导出报表
+	isExport, _ := this.GetBool("IsExport")
+	if isExport {
+		pageSize = 10000
+		currentIndex = 1
+	}
+
+	var condition string
+	var pars []interface{}
+
+	//条件
+	if adminId != "" {
+		condition += ` AND c.seller_id in  (` + adminId + `) `
+		//pars = append(pars, adminId)
+	} else {
+
+		//根据当前角色来获取查询条件
+		condition, pars = getQueryParams(condition, pars, sysUser, "c.")
+
+	}
+
+	//关键字搜索
+	if keyword != "" {
+		condition += ` and b.company_name like "%` + keyword + `%" `
+	}
+
+	//是否派点
+	if isAllocation != -1 {
+		condition += ` AND a.product_id = ? `
+		pars = append(pars, isAllocation)
+	}
+
+	// 标准非标查询
+	switch formalType {
+	case "标准":
+		condition += ` AND a.source = ? `
+		pars = append(pars, "系统合同")
+	case "非标":
+		condition += ` AND a.source = ? `
+		pars = append(pars, "上传附件")
+	}
+
+	if contractType != "" {
+		condition += ` AND a.contract_type = ? `
+		pars = append(pars, contractType)
+	}
+
+	//默认只查询权益 2023-06-01 之后的合同
+	condition += ` AND c.product_id = ?  AND a.start_date > ? `
+	pars = append(pars, 2, "2023-06-01")
+
+	var list []*cygx.CompanyContractResp
+
+	total, err := cygx.GetCompanyContractCountJoinCompany(condition, pars)
+	if err != nil && err.Error() != utils.ErrNoRow() {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取失败,Err:" + err.Error()
+		return
+	}
+	//列表页数据
+	list, err = cygx.GetCompanyContractListJoinCompany(condition, pars, startSize, pageSize)
+	if err != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取失败,Err:" + err.Error()
+		return
+	}
+	listLen := len(list)
+	if listLen == 0 {
+		list = make([]*cygx.CompanyContractResp, 0)
+	} else {
+
+		var contractCodes []string
+		for _, v := range list {
+			switch v.Source {
+			case "系统合同":
+				v.FormalType = "标准"
+			case "上传附件":
+				v.FormalType = "非标"
+			}
+			contractCodes = append(contractCodes, v.ContractCode)
+		}
+
+		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
+			}
+			for _, v := range list {
+				v.ContractId = mapContractCode[v.ContractCode]
+			}
+		}
+
+	}
+
+	page := paging.GetPaging(currentIndex, pageSize, total)
+	resp := cygx.CompanyContractListResp{
+		Paging: page,
+		List:   list,
+	}
+
+	//导出excel
+	if isExport {
+		//IncrementalCompanyListExport(this, dataType, resp, br)
+		return
+	}
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = resp
+}
+
+// @Title  详情
+// @Description 获取详情接口
+// @Param   CompanyContractId   query   int  true       "ID"
+// @Success Ret=200 {object} cygx.CygxAllocationCompanyContractDetailResp
+// @router /allocation/detail [get]
+func (this *ContractAllocationController) Detail() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	AdminUser := this.SysUser
+	if AdminUser == nil {
+		br.Msg = "请登录"
+		br.ErrMsg = "请登录,用户信息为空"
+		br.Ret = 408
+		return
+	}
+	resp := new(cygx.CygxAllocationCompanyContractDetailResp)
+	companyContractId, _ := this.GetInt("CompanyContractId")
+	if companyContractId < 1 {
+		br.Msg = "请输入详情ID"
+		return
+	}
+	contractItem, err := company.GetCompanyContractById(companyContractId)
+	if err != nil {
+		br.Msg = "获取信息失败"
+		br.ErrMsg = "获取合同信息失败,Err:" + err.Error()
+		return
+	}
+	total, err := cygx.GetCygxAllocationCompanyContractCountByCompanyContractId(companyContractId)
+	if err != nil {
+		br.Msg = "获取信息失败"
+		br.ErrMsg = "获取合同信息失败,GetCygxAllocationCompanyContractCountByCompanyContractId Err:" + err.Error()
+		return
+	}
+
+	if total == 0 {
+
+	}
+	var contractPermissionList []*company.ContractPermissionList
+	expMap := map[int]string{0: "(3w)", 1: "(5w)"} // 买方研选价格
+
+	//classifyName := "权益"
+	checkList := make([]int, 0)
+	plist := new(company.ContractPermissionList)
+	hasPermissions, e := company.GetCompanyContractPermissionByCompanyContractId(companyContractId)
+	if e != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取合同权限信息失败,Err:" + e.Error()
+		return
+	}
+	hasMap := make(map[int]*company.CompanyContractPermission)
+	for _, p := range hasPermissions {
+		hasMap[p.ChartPermissionId] = p
+	}
+	checkItems := make([]*company.PermissionLookItem, 0)
+	// PS:本来想把这个移到循环外面去优化一下...但是发现有指针引用变量被改掉的问题, BUG太多了改不完了先这样吧=_=!
+	raiPermissions, e := company.GetPermissionLookItemsExt("2", utils.COMPANY_PRODUCT_RAI_NAME)
+	if e != nil {
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取权益权限列表失败, Err: " + e.Error()
+		return
+	}
+
+	for _, n := range raiPermissions {
+		match := hasMap[n.ChartPermissionId]
+		if match == nil {
+			continue
+		}
+		// 升级
+		if match.IsUpgrade == 1 {
+			n.IsUpgrade = 1
+			checkList = append(checkList, n.ChartPermissionId)
+			checkItems = append(checkItems, n)
+			continue
+		}
+		// 买方研选(3w/5w)
+		if n.PermissionName == utils.CHART_PERMISSION_NAME_MF_YANXUAN {
+			n.PermissionName += expMap[match.ExpensiveYx]
+			checkList = append(checkList, n.ChartPermissionId)
+			checkItems = append(checkItems, n)
+			continue
+		}
+		checkList = append(checkList, n.ChartPermissionId)
+		checkItems = append(checkItems, n)
+	}
+	plist.Items = checkItems
+	plist.ClassifyName = utils.COMPANY_PRODUCT_RAI_NAME
+	plist.CheckList = checkList
+	contractPermissionList = append(contractPermissionList, plist)
+
+	// CRM8.8-权限主客观合并
+	newPermissionLookList := contractService.HandleEquityContractPermissionList(contractPermissionList)
+	for _, v := range newPermissionLookList {
+		for _, v2 := range v.Items {
+			fmt.Println(v2.PermissionName)
+		}
+	}
+
+	resp.Money = contractItem.Money / 10000
+
+	resp.TotalPointsContent = fmt.Sprint(resp.Money, "W")
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = resp
+}

+ 16 - 0
models/company/company_apply.go

@@ -79,6 +79,22 @@ func GetCompanyContractHistoryList(companyId int, productId string) (items []*Co
 	return
 }
 
+func GetCompanyContractHistoryListByContractCode(contractCode string) (items []*CompanyContractHistory, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT
+				a.*,
+				b.contract_id
+			FROM
+				company_contract AS a
+			LEFT JOIN contract AS b ON a.contract_code = b.contract_code
+			WHERE
+				a.contract_code = ?  AND a.status = 1
+			ORDER BY
+				a.modify_time DESC`
+	_, err = o.Raw(sql, contractCode).QueryRows(&items)
+	return
+}
+
 type CompanyContractDetail struct {
 	CompanyContractId int
 	CompanyId         int       `description:"客户id"`

+ 164 - 0
models/cygx/allocation_company_contract.go

@@ -0,0 +1,164 @@
+package cygx
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+// 研究员派点
+type CygxAllocationCompanyContract struct {
+	AllocationCompanyContractId int       `orm:"column(allocation_company_contract_id);pk"`
+	CompanyContractId           int       `description:"合同id"`
+	CreateTime                  time.Time `description:"创建时间"`
+	ModifyTime                  time.Time `description:"更新时间"`
+	Adminid                     int       `description:"操作人ID"`
+	AdminName                   string    `description:"内容"`
+	Proportion                  float64   `description:"占比"`
+	RealName                    int       `description:"研究员姓名"`
+}
+
+// 研究员派点日志
+type CygxAllocationCompanyContractLog struct {
+	AllocationCompanyContractId int       `orm:"column(allocation_company_contract_id);pk"`
+	CompanyContractId           int       `description:"合同id"`
+	CreateTime                  time.Time `description:"创建时间"`
+	ModifyTime                  time.Time `description:"更新时间"`
+	Adminid                     int       `description:"操作人ID"`
+	AdminName                   string    `description:"内容"`
+	Proportion                  float64   `description:"占比"`
+	RealName                    int       `description:"研究员姓名"`
+}
+
+// 行业派点
+type CygxAllocationCompanyContractPermission struct {
+	AllocationCompanyContractId int       `orm:"column(allocation_company_contract_id);pk"`
+	CompanyContractId           int       `description:"合同id"`
+	CreateTime                  time.Time `description:"创建时间"`
+	ModifyTime                  time.Time `description:"更新时间"`
+	Adminid                     int       `description:"操作人ID"`
+	AdminName                   string    `description:"内容"`
+	Proportion                  float64   `description:"占比"`
+	ChartPermissionName         int       `description:"行业名称"`
+}
+
+// 行业派点日志
+type CygxAllocationCompanyContractPermissionLog struct {
+	AllocationCompanyContractId int       `orm:"column(allocation_company_contract_id);pk"`
+	CompanyContractId           int       `description:"合同id"`
+	CreateTime                  time.Time `description:"创建时间"`
+	ModifyTime                  time.Time `description:"更新时间"`
+	Adminid                     int       `description:"操作人ID"`
+	AdminName                   string    `description:"内容"`
+	Proportion                  float64   `description:"占比"`
+	ChartPermissionName         int       `description:"行业名称"`
+}
+
+// 更新派点信息
+func AddAndUpdateCygxAllocationCompanyContract(items []*CygxAllocationCompanyContract, itemsPermission []*CygxAllocationCompanyContractPermission, companyContractId int) (err error) {
+	o := orm.NewOrmUsingDB("hz_cygx")
+	to, err := o.Begin()
+	if err != nil {
+		return
+	}
+	defer func() {
+		if err != nil {
+			_ = to.Rollback()
+		} else {
+			_ = to.Commit()
+		}
+	}()
+
+	//组合研究员派点日志结构体
+	var itemsLog []*CygxAllocationCompanyContractLog
+	for _, v := range items {
+		item := new(CygxAllocationCompanyContractLog)
+		item.CompanyContractId = v.CompanyContractId
+		item.Adminid = v.Adminid
+		item.CompanyContractId = v.CompanyContractId
+		item.AdminName = v.AdminName
+		item.RealName = v.RealName
+		item.CreateTime = time.Now()
+		item.ModifyTime = time.Now()
+		itemsLog = append(itemsLog, item)
+	}
+
+	//组合行业派点日志结构体
+	var itemsPermissionLog []*CygxAllocationCompanyContractPermissionLog
+	for _, v := range itemsPermission {
+		item := new(CygxAllocationCompanyContractPermissionLog)
+		item.CompanyContractId = v.CompanyContractId
+		item.Adminid = v.Adminid
+		item.CompanyContractId = v.CompanyContractId
+		item.AdminName = v.AdminName
+		item.ChartPermissionName = v.ChartPermissionName
+		item.CreateTime = time.Now()
+		item.ModifyTime = time.Now()
+		itemsPermissionLog = append(itemsPermissionLog, item)
+	}
+
+	//删除原有的研究员派点信息
+	sql := `	DELETE FROM cygx_allocation_company_contract WHERE company_contract_id = ?`
+	_, err = to.Raw(sql, companyContractId).Exec()
+	if err != nil {
+		return
+	}
+	//删除原有的行业派点信息
+	sql = `	DELETE FROM cygx_allocation_company_contract_permission WHERE company_contract_id = ?`
+	_, err = to.Raw(sql, companyContractId).Exec()
+	if err != nil {
+		return
+	}
+
+	//批量添加研究员派点信息
+	_, err = to.InsertMulti(len(items), items)
+	if err != nil {
+		return
+	}
+
+	_, err = to.InsertMulti(len(itemsLog), itemsLog)
+	if err != nil {
+		return
+	}
+
+	//批量添加行业派点信息
+	_, err = to.InsertMulti(len(itemsPermission), itemsPermission)
+	if err != nil {
+		return
+	}
+
+	_, err = to.InsertMulti(len(itemsPermissionLog), itemsPermissionLog)
+	if err != nil {
+		return
+	}
+
+	return
+}
+
+type CygxAllocationCompanyContractDetailResp struct {
+	Money              float64 `description:"金额(单位万)"`
+	TotalPointsContent string  `description:"总点数描述"`
+	List               []*AllocationPermissionListResp
+}
+
+// 行业
+type AllocationPermissionListResp struct {
+	ChartPermissionName int     `description:"行业名称"`
+	Proportion          float64 `description:"占比"`
+	Money               float64 `description:"金额(单位万)"`
+	List                []*AllocationRealNameListResp
+}
+
+// 行业
+type AllocationRealNameListResp struct {
+	RealName   int     `description:"研究员姓名"`
+	Proportion float64 `description:"占比"`
+	Money      float64 `description:"金额(单位万)"`
+}
+
+// 获取数量
+func GetCygxAllocationCompanyContractCountByCompanyContractId(companyContractId int) (count int, err error) {
+	o := orm.NewOrmUsingDB("hz_cygx")
+	sqlCount := ` SELECT COUNT(1) AS count  FROM cygx_allocation_company_contract WHERE company_contract_id = ? `
+	err = o.Raw(sqlCount, companyContractId).QueryRow(&count)
+	return
+}

+ 67 - 0
models/cygx/company_contract.go

@@ -0,0 +1,67 @@
+package cygx
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+	"github.com/rdlucklib/rdluck_tools/paging"
+)
+
+// 增量客户统计报表列表数据结构
+type CompanyContractResp struct {
+	CompanyContractId int     `description:"合同id"`
+	ContractType      string  `description:"合同类型"`
+	CompanyId         int     `description:"企业客户id"`
+	CompanyName       string  `description:"企业客户名称"`
+	ContractCode      string  `description:"合同编码"`
+	StartDate         string  `description:"合同开始日期"`
+	EndDate           string  `description:"合同结束日期"`
+	Money             float64 `description:"合同金额"`
+	CreateTime        string  `description:"合同创建时间"`
+	ModifyTime        string  `description:"合同修改时间"`
+	SellerId          int     `description:"归属销售id"`
+	SellerName        string  `description:"归属销售名称"`
+	IsAllocation      int     `description:"是否派点: 0-未派点; 1-已派点"`
+	Source            string  `description:"合同来源,枚举值:上传附件、系统合同,默认上传附件"`
+	FormalType        string  `description:"转正类型,枚举值: 标准、非标"`
+	IsGray            bool    `description:"是否置灰"`
+	ContractId        int     `description:"合同唯一id"`
+}
+
+// 增量客户统计报表返回类
+type CompanyContractListResp struct {
+	List   []*CompanyContractResp
+	Paging *paging.PagingItem `description:"分页数据"`
+}
+
+// 获取存量客户未续约报表列表统计数据(根据合同来展示)
+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`
+	err = o.Raw(sql, pars).QueryRow(&total)
+	return
+}
+
+// 获取存量客户未续约报表列表数据(根据合同来展示)
+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 ?,?`
+	_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
+	return
+}

+ 4 - 0
models/db.go

@@ -447,6 +447,10 @@ func initCygx() {
 		new(cygx.CygxReportMappingCategoryGroup),
 		new(cygx.CygxResourceDataIndustrialGroupManagement),
 		new(cygx.CygxResourceDataIndustrialGroupSubject),
+		new(cygx.CygxAllocationCompanyContract),
+		new(cygx.CygxAllocationCompanyContractLog),
+		new(cygx.CygxAllocationCompanyContractPermission),
+		new(cygx.CygxAllocationCompanyContractPermissionLog),
 	)
 }
 

+ 27 - 0
routers/commentsRouter.go

@@ -1339,6 +1339,24 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["hongze/hz_crm_api/controllers/cygx:ContractAllocationController"] = append(beego.GlobalControllerRouter["hongze/hz_crm_api/controllers/cygx:ContractAllocationController"],
+        beego.ControllerComments{
+            Method: "CompanyContractList",
+            Router: `/allocation/company_contract_list`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
+    beego.GlobalControllerRouter["hongze/hz_crm_api/controllers/cygx:ContractAllocationController"] = append(beego.GlobalControllerRouter["hongze/hz_crm_api/controllers/cygx:ContractAllocationController"],
+        beego.ControllerComments{
+            Method: "Detail",
+            Router: `/allocation/detail`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["hongze/hz_crm_api/controllers/cygx:IndustrialAnalystController"] = append(beego.GlobalControllerRouter["hongze/hz_crm_api/controllers/cygx:IndustrialAnalystController"],
         beego.ControllerComments{
             Method: "IndustrialAnalystAdd",
@@ -8296,6 +8314,15 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["hongze/hz_crm_api/controllers:CompanyApplyController"] = append(beego.GlobalControllerRouter["hongze/hz_crm_api/controllers:CompanyApplyController"],
+        beego.ControllerComments{
+            Method: "ApplyContractHistoryDetail",
+            Router: `/apply/contract/history/detail`,
+            AllowHTTPMethods: []string{"get"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["hongze/hz_crm_api/controllers:CompanyApplyController"] = append(beego.GlobalControllerRouter["hongze/hz_crm_api/controllers:CompanyApplyController"],
         beego.ControllerComments{
             Method: "ApplyContractHistoryList",

+ 1 - 0
routers/router.go

@@ -151,6 +151,7 @@ func init() {
 				&cygx.ProductInteriorController{},
 				&cygx.BannerCoAntroller{},
 				&cygx.TagManagementController{},
+				&cygx.ContractAllocationController{},
 			),
 		),
 		web.NSNamespace("/advisory",