package cygxService import ( "errors" "fmt" "hongze/hongze_mobile_admin/models/tables/chart_permission" "hongze/hongze_mobile_admin/models/tables/company_contract" "hongze/hongze_mobile_admin/models/tables/company_contract_permission" "hongze/hongze_mobile_admin/models/tables/cygx_allocation_company_contract" "hongze/hongze_mobile_admin/services/alarm_msg" "hongze/hongze_mobile_admin/utils" "time" ) // 如果合同只有研选的时候,自动处理派点 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_permission.GetCompanyContractPermissionList(condition, pars) if e != nil && e.Error() != utils.ErrNoRow() { err = errors.New("GetCompanyContractPermissionList, Err: " + e.Error()) return } //超过两个权限说明还有其他行业,不做自动派点处理 if len(companyContractPermissionList) > 2 { return } var items []*cygx_allocation_company_contract.CygxAllocationCompanyContract var itemsPermission []*cygx_allocation_company_contract.CygxAllocationCompanyContractPermission 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 //} if v.ChartPermissionId != utils.CHART_PERMISSION_ID_YANXUAN && v.ChartPermissionId != utils.YAN_XUAN_KOU_DIAN_BAO_ID { return } if v.ChartPermissionId == utils.CHART_PERMISSION_ID_YANXUAN { expensiveYxmoney = 3 } if v.ChartPermissionId == utils.YAN_XUAN_KOU_DIAN_BAO_ID { expensiveYxmoney = 0.2 * v.Points } itemPermission := new(cygx_allocation_company_contract.CygxAllocationCompanyContractPermission) itemPermission.CompanyContractId = companyContractId //itemPermission.AdminId = sysUser.AdminId //itemPermission.AdminName = sysUser.RealName itemPermission.Proportion = 0 itemPermission.Money = expensiveYxmoney itemPermission.MoneyAvg = 0 itemPermission.ChartPermissionName = v.PermissionName itemPermission.CreateTime = time.Now() itemPermission.ModifyTime = time.Now() itemsPermission = append(itemsPermission, itemPermission) item := new(cygx_allocation_company_contract.CygxAllocationCompanyContract) item.CompanyContractId = companyContractId item.Proportion = 0 item.Money = expensiveYxmoney item.RealName = v.PermissionName item.ChartPermissionName = v.PermissionName item.CreateTime = time.Now() item.ModifyTime = time.Now() items = append(items, item) } if len(items) == 0 { return } e = cygx_allocation_company_contract.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) fmt.Println(packageDifference) 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 := chart_permission.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_permission.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_permission.GetCompanyContractPermissionList(condition, pars) if e != nil && e.Error() != utils.ErrNoRow() { err = errors.New("companyContractPermissionLisThis Err: " + e.Error()) return } var items []*company_contract_permission.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_permission.UpdateCompanyContractPermissionMulti(items) if e != nil { err = errors.New("UpdateCompanyContractPermissionMulti Err: " + e.Error()) return } return }