123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244 |
- package cygxService
- import (
- "errors"
- "fmt"
- "hongze/hongze_mobile_admin/models/cygx"
- company_contract2 "hongze/hongze_mobile_admin/models/response/company_contract"
- "hongze/hongze_mobile_admin/models/tables/chart_permission"
- "hongze/hongze_mobile_admin/models/tables/company_contract_permission"
- "hongze/hongze_mobile_admin/utils"
- "strconv"
- "strings"
- "time"
- )
- // 审批通过的时候专项调研次数更新
- //func ActivitySpecialCompanyApproval(companyId int, companyName string) (err error) {
- // userType, packageType, _, _, _ := GetUserType(companyId)
- // // 获取继承点数
- // inheritList, e := cygx.GetCygxActivitySpecialInheritPointsByCompanyId(companyId)
- // if e != nil && e.Error() != utils.ErrNoRow() {
- // err = errors.New("GetCygxActivitySpecialInheritPointsByCompanyId, Err: " + e.Error())
- // }
- // chartNameMap := map[string]int{utils.YI_YAO_NAME: 0, utils.XIAO_FEI_NAME: 0, utils.KE_JI_NAME: 0, utils.ZHI_ZAO_NAME: 0}
- //
- // itemBill := new(cygx.CygxActivitySpecialTripBill)
- // itemBill.CreateTime = time.Now()
- // itemBill.CompanyId = companyId
- // itemBill.CompanyName = companyName
- // itemBill.Source = 2
- // itemBill.DoType = 2
- // itemBill.Way = 3
- // if userType == 2{
- // packageTypeMap := map[int]int{1: 16, 2: 10}
- // totalTrip := packageTypeMap[packageType]
- // if len(inheritList) > 0 {
- // for _, v := range inheritList {
- // if v.ChartPermissionId == 0 {
- // itemBill.BillDetailed = totalTrip + v.Points
- // } else {
- // itemBill.BillDetailed = totalTrip
- // }
- // }
- // } else {
- // itemBill.BillDetailed = totalTrip
- // }
- //
- // itemBill.Total = strconv.Itoa(itemBill.BillDetailed) + "次"
- // if totalTrip == 10 {
- // itemBill.Content = "45w大套餐转正"
- // } else {
- // itemBill.Content = "70w大套餐转正"
- // }
- // } else {
- // list, e := models.GetCompanyReportPermissionByCompanyIdAndProductId(companyId, 2)
- // if e != nil && e.Error() != utils.ErrNoRow() {
- // err = errors.New("GetCompanyReportPermissionUpgrade, Err: " + e.Error())
- // }
- // if len(list) == 0 {
- // return
- // }
- // var chartPermissionIdSlice []string
- // mapChartName := make(map[string]int)
- // mapUpgradeId := make(map[int]int)
- // mapInheritChartName := make(map[string]int)
- // mapPermissionNameTrip := make(map[string]int)
- // //mapPermissionName := make(map[int]string)
- // for _, v := range list {
- // chartPermissionIdSlice = append(chartPermissionIdSlice, strconv.Itoa(v.ChartPermissionId))
- // //是升级套餐才有点数
- // if v.IsUpgrade == 1 {
- // mapUpgradeId[v.ChartPermissionId] = 1
- // }
- // }
- // chartList := make([]*chart_permission.ChartPermission, 0)
- // if len(chartPermissionIdSlice) > 0 {
- // chartList, e = chart_permission.GetChartPermissionByIds(chartPermissionIdSlice)
- // if e != nil {
- // err = errors.New("获取品种信息失败, Err:" + e.Error())
- // return
- // }
- // }
- // if len(chartList) == 0 {
- // return
- // }
- // for _, v := range chartList {
- // //如果是升级则加点
- // if _, ok := mapUpgradeId[v.ChartPermissionId]; ok {
- // mapChartName[v.PermissionName] = 5 + mapPermissionNameTrip[v.ChartPermissionName]
- // } else {
- // mapChartName[v.PermissionName] = mapPermissionNameTrip[v.ChartPermissionName]
- // }
- // }
- // // 通过继承获得的加点
- // for _, v := range inheritList {
- // mapInheritChartName[v.ChartPermissionName] = v.Points
- // }
- // for k, _ := range chartNameMap {
- // if _, ok := mapChartName[k]; ok {
- // if inherit, ok2 := mapInheritChartName[k]; ok2 {
- // mapChartName[k] += inherit
- // }
- // }
- // }
- // for k, v := range mapChartName {
- // if v > 0 {
- // itemBill.BillDetailed += v
- // itemBill.Total += k + strconv.Itoa(v) + "次+"
- // }
- // }
- // itemBill.Content = "行业升级套餐转正"
- // itemBill.Total = strings.TrimRight(itemBill.Total, "+")
- // }
- // err = cygx.AddCygxActivitySpecialTripBill(itemBill)
- // if err != nil {
- // return
- // }
- // return
- //}
- func ActivitySpecialCompanyApproval(companyId, companyContractId int, companyName string) (err error) {
- //userType, packageType, _, _, _ := GetUserType(companyId)
- // 获取继承点数
- //inheritList, e := cygx.GetCygxActivitySpecialInheritPointsByCompanyId(companyId)
- //if e != nil && e.Error() != utils.ErrNoRow() {
- // err = errors.New("GetCygxActivitySpecialInheritPointsByCompanyId, Err: " + e.Error())
- //}
- //chartNameMap := map[string]int{utils.YI_YAO_NAME: 0, utils.XIAO_FEI_NAME: 0, utils.KE_JI_NAME: 0, utils.ZHI_ZAO_NAME: 0}
- // 获取合同信息-套餐信息
- companyContract, e := company_contract2.GetCompanyContractById(companyContractId)
- if e != nil {
- err = errors.New("GetCompanyContractById, Err: " + e.Error())
- return
- }
- packageType := companyContract.RaiPackageType
- var items []*cygx.CygxActivitySpecialPermissionPoints
- itemBill := new(cygx.CygxActivitySpecialTripBill)
- itemBill.CreateTime = time.Now()
- itemBill.CompanyId = companyId
- itemBill.CompanyName = companyName
- itemBill.Source = 2
- itemBill.DoType = 2
- itemBill.Way = 3
- if packageType > 0 {
- packageTypeMap := map[int]int{1: 16, 2: 12}
- totalTrip := packageTypeMap[packageType]
- itemBill.BillDetailed = totalTrip
- itemBill.Total = strconv.Itoa(itemBill.BillDetailed) + "次"
- if packageType == 2 {
- itemBill.Content = "45w大套餐转正"
- } else {
- itemBill.Content = "70w大套餐转正"
- }
- //记录公司剩余点数
- item := new(cygx.CygxActivitySpecialPermissionPoints)
- item.Points = totalTrip
- item.CompanyId = companyId
- item.CompanyName = companyName
- item.CreateTime = time.Now()
- item.ModifyTime = time.Now()
- items = append(items, item)
- } else {
- var condition string
- var pars []interface{}
- pars = make([]interface{}, 0)
- condition = " AND company_contract_id = ? AND is_upgrade = 1 "
- pars = append(pars, companyContractId)
- list, e := company_contract_permission.GetCompanyContractPermissionList(condition, pars) // 获取带有升级的权限
- if e != nil && e.Error() != utils.ErrNoRow() {
- err = errors.New("GetCompanyContractPermissionList, Err: " + e.Error())
- return
- }
- if len(list) == 0 {
- return
- }
- //获取权益主观权限
- listRaiSubjectivity, e := chart_permission.GetChartPermissionListRaiSubjectivity()
- if e != nil && e.Error() != utils.ErrNoRow() {
- err = errors.New("GetChartPermissionListRaiSubjectivity, Err: " + e.Error())
- }
- mapRaiSubjectivity := make(map[int]bool)
- mapPermissionName := make(map[int]string)
- for _, v := range listRaiSubjectivity {
- mapRaiSubjectivity[v.ChartPermissionId] = true
- mapPermissionName[v.ChartPermissionId] = v.ChartPermissionName
- }
- for _, v := range list {
- //如果是升级则加点
- if v.IsUpgrade == 1 && mapRaiSubjectivity[v.ChartPermissionId] {
- item := new(cygx.CygxActivitySpecialPermissionPoints)
- item.Points = 5
- item.CompanyId = companyId
- item.CompanyName = companyName
- item.ChartPermissionId = v.ChartPermissionId
- item.ChartPermissionName = mapPermissionName[v.ChartPermissionId]
- item.CreateTime = time.Now()
- item.ModifyTime = time.Now()
- items = append(items, item)
- }
- }
- itemBill.Content = "行业升级套餐转正"
- }
- e = cygx.MultiAddCygxActivitySpecialPermissionPoints(items)
- if e != nil {
- err = errors.New("MultiAddCygxActivitySpecialPermissionPoints, Err:" + e.Error())
- return
- }
- if packageType == 0 && len(items) > 0 {
- var condition string
- var pars []interface{}
- pars = make([]interface{}, 0)
- condition = " AND company_id = ? AND points > 0 ORDER BY chart_permission_id DESC "
- pars = append(pars, companyId)
- activitySpecialPermissionPointsList, e := cygx.GetCygxActivitySpecialPermissionPointsList(condition, pars)
- if e != nil && e.Error() != utils.ErrNoRow() {
- err = errors.New("GetCygxActivitySpecialPermissionPointsList, Err:" + e.Error())
- return
- }
- var itemBillTotal []string
- for _, v := range activitySpecialPermissionPointsList {
- itemBillTotal = append(itemBillTotal, fmt.Sprint(v.ChartPermissionName, v.Points, "次"))
- }
- itemBill.BillDetailed = 5 * len(items)
- itemBill.Total = strings.Join(itemBillTotal, "+")
- }
- //如果有升级行业权限,或者大套餐客户就写入流水信息
- if itemBill.Total != "" {
- e := cygx.AddCygxActivitySpecialTripBill(itemBill)
- if e != nil {
- err = errors.New("AddCygxActivitySpecialTripBill, Err:" + e.Error())
- return
- }
- }
- return
- }
|