123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274 |
- package crm
- import (
- "github.com/gin-gonic/gin"
- "github.com/go-playground/validator/v10"
- "hongze/fms_api/controller/resp"
- "hongze/fms_api/global"
- "hongze/fms_api/models/base"
- "hongze/fms_api/models/crm"
- "hongze/fms_api/models/fms"
- crmService "hongze/fms_api/services/crm"
- "hongze/fms_api/utils"
- )
- // ContractController CRM系统合同
- type ContractController struct{}
- // SearchList
- // @Title 搜索合同
- // @Description 搜索合同
- // @Param Keyword query string false "关键词"
- // @Param ProductId query int false "合同类型: 0-全部; 1-FICC; 2-权益"
- // @Success 200 {object} crm.ContractSearchListResp
- // @router /crm/contract/search_list [get]
- func (rg *ContractController) SearchList(c *gin.Context) {
- var req crm.ContractSearchListReq
- if e := c.BindQuery(&req); e != nil {
- err, ok := e.(validator.ValidationErrors)
- if !ok {
- resp.FailData("参数解析失败", "Err:"+e.Error(), c)
- return
- }
- resp.FailData("参数解析失败", err.Translate(global.Trans), c)
- return
- }
- cond := `status IN ('已审批', '已签回') AND contract_type IN ('新签合同', '续约合同', '补充协议')`
- pars := make([]interface{}, 0)
- if req.Keyword != "" {
- kw := "%" + req.Keyword + "%"
- cond += ` AND (company_name LIKE ? OR contract_code LIKE ?)`
- pars = append(pars, kw, kw)
- }
- if req.ProductId > 0 {
- cond += ` AND product_id = ?`
- pars = append(pars, req.ProductId)
- }
- page := new(base.Page)
- page.SetPageSize(req.PageSize)
- page.SetCurrent(req.Current)
- page.AddOrderItem(base.OrderItem{Column: "create_time", Asc: false})
- ob := new(crm.Contract)
- total, list, e := ob.PageList(page, cond, pars)
- if e != nil {
- resp.FailMsg("获取失败", "获取合同列表失败, Err: "+e.Error(), c)
- return
- }
- // 获取代付合同实际使用方
- businessContractIds := make([]int, 0)
- payContractIds := make([]int, 0)
- for i := range list {
- if list[i].ContractBusinessType == crm.ContractTypePayment {
- payContractIds = append(payContractIds, list[i].ContractId)
- } else {
- businessContractIds = append(businessContractIds, list[i].ContractId)
- }
- }
- payCompanyMap := make(map[int]string, 0) // 代付合同实际使用方
- payContractCodeMap := make(map[int]string, 0) // 代付合同实际使用方合同编号
- if len(payContractIds) > 0 {
- payCond := `a.status IN ('已签回', '已审批') AND b.payment_on_behalf_contract_id IN ?`
- payPars := make([]interface{}, 0)
- payPars = append(payPars, payContractIds)
- payList, e := crm.GetPayCompanyByContractIds(payCond, payPars)
- if e != nil {
- resp.FailMsg("获取失败", "获取代付合同实际使用方信息失败, Err: "+e.Error(), c)
- return
- }
- for i := range payList {
- payCompanyMap[payList[i].PaymentOnBehalfContractId] = payList[i].CompanyName
- payContractCodeMap[payList[i].PaymentOnBehalfContractId] = payList[i].ContractCode
- }
- }
- // 获取业务合同的所有代付方信息
- businessPayMap := make(map[int]string, 0)
- if len(businessContractIds) > 0 {
- businessCond := `b.status IN ('已签回', '已审批') AND a.contract_id IN ?`
- businessPars := make([]interface{}, 0)
- businessPars = append(businessPars, businessContractIds)
- businessPayCompanies, e := crm.GetContractActualPayCompaniesByContractIds(businessCond, businessPars)
- if e != nil {
- resp.FailMsg("获取失败", "获取业务合同代付方信息失败, Err: "+e.Error(), c)
- return
- }
- for i := range businessPayCompanies {
- businessPayMap[businessPayCompanies[i].ContractId] = businessPayCompanies[i].ActualPayCompanies
- }
- }
- respList := make([]*crm.ContractSearchListResp, 0)
- for i := range list {
- contractType := list[i].ContractType
- contractTypeKey := crm.ContractTypeFmsMap[list[i].ContractType]
- if list[i].ContractBusinessType == crm.ContractTypePayment {
- contractType = crm.ContractTypePayment
- contractTypeKey = fms.ContractTypeAgentPay
- }
- respItem := &crm.ContractSearchListResp{
- ContractId: list[i].ContractId,
- ContractCode: list[i].ContractCode,
- ProductId: list[i].ProductId,
- CompanyName: list[i].CompanyName,
- RelateContractCode: payContractCodeMap[list[i].ContractId],
- ActualCompanyName: payCompanyMap[list[i].ContractId],
- SellerId: list[i].SellerId,
- SellerName: list[i].SellerName,
- ContractTypeKey: contractTypeKey,
- ContractType: contractType,
- ContractBusinessTypeInt: 0,
- Price: list[i].Price,
- StartDate: utils.TimeTransferString(utils.FormatDate, list[i].StartDate),
- EndDate: utils.TimeTransferString(utils.FormatDate, list[i].EndDate),
- ActualPayCompanies: businessPayMap[list[i].ContractId],
- }
- if list[i].ContractBusinessType == crm.ContractTypePayment {
- respItem.ContractBusinessTypeInt = 2
- } else {
- respItem.ContractBusinessTypeInt = 1
- }
- if list[i].ContractType == "新签合同" {
- respItem.ContractTypeInt = 1
- } else if list[i].ContractType == "续约合同" {
- respItem.ContractTypeInt = 2
- } else if list[i].ContractType == "补充协议" {
- respItem.ContractTypeInt = 3
- }
- respList = append(respList, respItem)
- }
- page.SetTotal(total)
- baseData := new(base.BaseData)
- baseData.SetPage(page)
- baseData.SetList(respList)
- resp.OkData("获取成功", baseData, c)
- }
- // PermissionList
- // @Title 合同品种列表
- // @Description 合同品种列表
- // @Param ProductId query int false "品种类型: 1-FICC(默认); 2-权益"
- // @Success 200 {object} crm.PermissionSetResp
- // @router /crm/contract/permission_list [get]
- func (rg *ContractController) PermissionList(c *gin.Context) {
- var req crm.ContractPermissionListReq
- if e := c.BindQuery(&req); e != nil {
- err, ok := e.(validator.ValidationErrors)
- if !ok {
- resp.FailData("参数解析失败", "Err:"+e.Error(), c)
- return
- }
- resp.FailData("参数解析失败", err.Translate(global.Trans), c)
- return
- }
- // 默认FICC
- productId := req.ProductId
- if productId == 0 {
- productId = 1
- }
- respList := new(crm.PermissionSetResp)
- // FICC
- if productId == 1 {
- // 获取品种分类配置
- // 获取FICC权限
- ficcCond := `enabled = 1 AND permission_type = 0 AND product_id = ? `
- ficcPars := make([]interface{}, 0)
- ficcPars = append(ficcPars, productId)
- items, e := crm.GetPermissionSetItemsByCondition(ficcCond, ficcPars)
- if e != nil {
- resp.FailData("获取失败", "获取FICC权限信息失败, Err: "+e.Error(), c)
- return
- }
- ficcItemMap := make(map[int][]*crm.PermissionSetItem, 0)
- for i := range items {
- if items[i].ParentId > 0 {
- if ficcItemMap[items[i].ParentId] == nil {
- ficcItemMap[items[i].ParentId] = make([]*crm.PermissionSetItem, 0)
- }
- ficcItemMap[items[i].ParentId] = append(ficcItemMap[items[i].ParentId], items[i])
- }
- }
- for i := range items {
- if items[i].ParentId > 0 {
- continue
- }
- if items[i].PermissionName == "市场策略" {
- continue
- }
- checkList := make([]int, 0)
- if items[i].IsPublic == 1 {
- checkList = append(checkList, items[i].ChartPermissionId)
- }
- p := new(crm.PermissionSetList)
- p.ClassifyName = items[i].PermissionName
- tmpItems, ok := ficcItemMap[items[i].ChartPermissionId]
- if ok {
- p.Items = tmpItems
- } else {
- p.Items = make([]*crm.PermissionSetItem, 0)
- }
- p.CheckList = make([]int, 0)
- respList.List = append(respList.List, p)
- }
- }
- // 权益
- if productId == 2 {
- raiCond := `enabled = 1 AND parent_id> 0 AND permission_type = 0 AND product_id = ? AND classify_name = ?`
- raiPars := make([]interface{}, 0)
- raiPars = append(raiPars, productId, crm.CompanyProductRaiName)
- items, e := crm.GetPermissionSetItemsByCondition(raiCond, raiPars)
- if e != nil {
- resp.FailData("获取失败", "获取权益权限信息失败, Err: "+e.Error(), c)
- return
- }
- p := new(crm.PermissionSetList)
- p.ClassifyName = crm.CompanyProductRaiName
- p.Items = items
- p.CheckList = make([]int, 0)
- respList.List = append(respList.List, p)
- }
- resp.OkData("获取成功", respList, c)
- }
- // ServiceDetail
- // @Title 获取合同的套餐及品种权限
- // @Description 获取合同的套餐及品种权限
- // @Param ContractId query int true "合同ID"
- // @Success 200 {object} crm.ContractDetail
- // @router /crm/contract/service_detail [get]
- func (rg *ContractController) ServiceDetail(c *gin.Context) {
- var req crm.ContractServiceDetailReq
- if e := c.BindQuery(&req); e != nil {
- err, ok := e.(validator.ValidationErrors)
- if !ok {
- resp.FailData("参数解析失败", "Err:"+e.Error(), c)
- return
- }
- resp.FailData("参数解析失败", err.Translate(global.Trans), c)
- return
- }
- contractDetail, e := crmService.GetContractDetail(req.ContractId)
- if e != nil {
- global.LOG.Error(e.Error())
- resp.FailMsg("获取失败", "获取合同套餐及品种信息失败, Err: "+e.Error(), c)
- return
- }
- // 获取合同服务中的权限ID, 填充contractDetail.Service.ChartPermissionIds字段
- _, e = crmService.GetServicePermissionMap(contractDetail.Service)
- if e != nil {
- resp.FailMsg("获取失败", "获取合同服务中的权限ID失败, Err: "+e.Error(), c)
- return
- }
- resp.OkData("获取成功", contractDetail, c)
- }
|