package cygx import ( "fmt" "hongze/hongze_task/models" "hongze/hongze_task/models/company_contract" "hongze/hongze_task/models/cygx" "hongze/hongze_task/services/alarm_msg" "hongze/hongze_task/utils" "time" "errors" ) // 如果合同只有研选的时候,自动处理派点 func HandleAllocationCompanyContractByYanXuan(companyContractId int) (err error) { defer func() { if err != nil { fmt.Println(err) go alarm_msg.SendAlarmMsg(fmt.Sprint("如果合同只有研选的时候,自动处理派点失败,Err:", err.Error(), "companyContractId", companyContractId), 2) } }() var condition string var pars []interface{} pars = make([]interface{}, 0) condition = " AND company_contract_id = ? " pars = append(pars, companyContractId) companyContractPermissionList, e := company_contract.GetCompanyContractPermissionList(condition, pars) if e != nil && e.Error() != utils.ErrNoRow() { err = errors.New("GetCompanyContractPermissionList, Err: " + e.Error()) return } if e != nil && e.Error() != utils.ErrNoRow() { err = errors.New("GetCygxAllocationCompanyContractPermissionListById, Err: " + e.Error()) return } if len(companyContractPermissionList) > 1 { return } var expensiveYxmoney float64 for _, v := range companyContractPermissionList { if v.ChartPermissionId != utils.CHART_PERMISSION_ID_YANXUAN { err = errors.New("没有发现研选权限: ") return } if v.ExpensiveYx == 1 { expensiveYxmoney = 5 } else if v.ExpensiveYx == 2 { expensiveYxmoney = 10 } else{ expensiveYxmoney = 3 } } var items []*cygx.CygxAllocationCompanyContract var itemsPermission []*cygx.CygxAllocationCompanyContractPermission itemPermission := new(cygx.CygxAllocationCompanyContractPermission) itemPermission.CompanyContractId = companyContractId //itemPermission.AdminId = sysUser.AdminId //itemPermission.AdminName = sysUser.RealName itemPermission.Proportion = 0 itemPermission.Money = expensiveYxmoney itemPermission.MoneyAvg = 0 itemPermission.ChartPermissionName = utils.CHART_PERMISSION_NAME_MF_YANXUAN itemPermission.CreateTime = time.Now() itemPermission.ModifyTime = time.Now() itemsPermission = append(itemsPermission, itemPermission) item := new(cygx.CygxAllocationCompanyContract) item.CompanyContractId = companyContractId //item.AdminId = sysUser.AdminId //item.AdminName = sysUser.RealName item.Proportion = 0 item.Money = expensiveYxmoney item.RealName = utils.CHART_PERMISSION_NAME_MF_YANXUAN item.ChartPermissionName = utils.CHART_PERMISSION_NAME_MF_YANXUAN item.CreateTime = time.Now() item.ModifyTime = time.Now() items = append(items, item) e = cygx.AddAndUpdateCygxAllocationCompanyContract(items, itemsPermission, companyContractId) if e != nil { err = errors.New("AddAndUpdateCygxAllocationCompanyContract, Err: " + e.Error()) return } return } // HandleCompanyContractPackageDifference 更新与上一份合同的金额的对比 '增加套餐','减少套餐','维持套餐' func HandleCompanyContractPackageDifference(companyContractId int) (err error) { defer func() { if err != nil { fmt.Println(err) go alarm_msg.SendAlarmMsg(fmt.Sprint("更新与上一份合同的金额的对比 '增加套餐','减少套餐','维持套餐'失败,Err:", err.Error(), "companyContractId", companyContractId), 2) } }() var condition string var pars []interface{} condition = " AND company_contract_id = ? " pars = append(pars, companyContractId) detail, e := company_contract.GetCompanyContracDetail(condition, pars) if e != nil { err = errors.New("GetCompanyContracDetail,detail Err: " + e.Error()) return } //如果不是续约合同就不做对比处理 if detail.ContractType != "续约合同" { return } //获取前一份合同的信息 pars = make([]interface{}, 0) condition = " AND company_id = ? AND company_contract_id < ? AND status = 1 AND product_id = ? ORDER BY company_contract_id DESC LIMIT 1 " pars = append(pars, detail.CompanyId, companyContractId, detail.ProductId) detailPrevious, e := company_contract.GetCompanyContracDetail(condition, pars) if e != nil { err = errors.New("GetCompanyContracDetail,detailPrevious Err: " + e.Error()) return } var packageDifference string if detail.Money > detailPrevious.Money { packageDifference = "增加套餐" } else if detail.Money < detailPrevious.Money { packageDifference = "减少套餐" } else { packageDifference = "维持套餐" } e = company_contract.UpdateCompanyContractPackageDifference(packageDifference, companyContractId) if e != nil { err = errors.New("UpdateCompanyContractPackageDifference, Err: " + e.Error()) return } return } // HandleCompanyContractPermissionContractType 更新合同权限表中的权限名称,以及对应的行业权限类型(行业新签、行业续约) func HandleCompanyContractPermissionContractType(companyContractId int) (err error) { defer func() { if err != nil { fmt.Println(err) go alarm_msg.SendAlarmMsg(fmt.Sprint("更新合同权限表中的权限名称,以及对应的行业权限类型(行业新签、行业续约)失败,HandleCompanyContractPermissionContractType Err:", err.Error(), "companyContractId", companyContractId), 2) } }() var condition string var pars []interface{} condition = " AND company_contract_id = ? " pars = append(pars, companyContractId) detail, e := company_contract.GetCompanyContracDetail(condition, pars) if e != nil { err = errors.New("GetCompanyContracDetail,detail Err: " + e.Error()) return } //获取权限ID与名称的map映射 permissionList, e := models.GetChartPermissionList() if e != nil && e.Error() != utils.ErrNoRow() { err = errors.New("GetChartPermissionList Err: " + e.Error()) return } mapChartPermission := make(map[int]string) for _, v := range permissionList { mapChartPermission[v.ChartPermissionId] = v.PermissionName } companyId := detail.CompanyId //如果不是续约合同就不做对比处理 pars = make([]interface{}, 0) condition = " AND company_contract_id != ? AND company_id = ? " pars = append(pars, companyContractId, companyId) //获取历史签约信息 companyContractPermissionListHistory, e := company_contract.GetCompanyContractPermissionList(condition, pars) if e != nil && e.Error() != utils.ErrNoRow() { err = errors.New("companyContractPermissionListHistory Err: " + e.Error()) return } var mapHistoryPerssionName []string for _, v := range companyContractPermissionListHistory { mapHistoryPerssionName = append(mapHistoryPerssionName, mapChartPermission[v.ChartPermissionId]) } pars = make([]interface{}, 0) condition = " AND company_contract_id = ? " pars = append(pars, companyContractId) //获取当前签约的合同信息 companyContractPermissionLisThis, e := company_contract.GetCompanyContractPermissionList(condition, pars) if e != nil && e.Error() != utils.ErrNoRow() { err = errors.New("companyContractPermissionLisThis Err: " + e.Error()) return } var items []*company_contract.CompanyContractPermission for _, v := range companyContractPermissionLisThis { v.PermissionName = mapChartPermission[v.ChartPermissionId] if v.PermissionName == "" { continue } //已经存在的属于行业续约、不存在的属于行业新签 if utils.InArrayByStr(mapHistoryPerssionName, v.PermissionName) { v.ContractType = "行业续约" } else { v.ContractType = "行业新签" } items = append(items, v) } //批量更新合同权限表的权限行业名称,以及签约合同时,当前行业类型(行业续约、行业新签) e = company_contract.UpdateCompanyContractPermissionMulti(items) if e != nil { err = errors.New("UpdateCompanyContractPermissionMulti Err: " + e.Error()) return } return }