123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421 |
- package cygx
- import (
- "github.com/beego/beego/v2/client/orm"
- "hongze/hz_crm_api/utils"
- "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:"占比"`
- Money float64 `description:"金额"`
- RealName string `description:"研究员姓名"`
- ChartPermissionName string `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:"占比"`
- Money float64 `description:"金额"`
- RealName string `description:"研究员姓名"`
- ChartPermissionName string `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:"占比"`
- Money float64 `description:"金额"`
- MoneyAvg float64 `description:"行业所占合同的平均金额"`
- ChartPermissionName string `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:"占比"`
- Money float64 `description:"金额"`
- MoneyAvg float64 `description:"行业所占合同的平均金额"`
- ChartPermissionName string `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.ChartPermissionName = v.ChartPermissionName
- item.Proportion = v.Proportion
- item.Money = v.Money
- 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.Proportion = v.Proportion
- item.Money = v.Money
- item.MoneyAvg = v.MoneyAvg
- 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
- }
- ow := orm.NewOrm()
- sqlW := `UPDATE company_contract SET is_allocation=1 WHERE company_contract_id=? `
- _, err = ow.Raw(sqlW, companyContractId).Exec()
- return
- }
- // 更新派点信息
- func AddAndUpdateCygxAllocationCompanyContractRai(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.ChartPermissionName = v.ChartPermissionName
- item.Proportion = v.Proportion
- item.Money = v.Money
- 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.Proportion = v.Proportion
- item.Money = v.Money
- item.MoneyAvg = v.MoneyAvg
- item.CreateTime = time.Now()
- item.ModifyTime = time.Now()
- itemsPermissionLog = append(itemsPermissionLog, item)
- }
- lenIds := len(companyContractId)
- //删除原有的研究员派点信息
- sql := `DELETE FROM cygx_allocation_company_contract WHERE company_contract_id IN (` + utils.GetOrmInReplace(lenIds) + `)`
- _, err = to.Raw(sql, companyContractId).Exec()
- if err != nil {
- return
- }
- //删除原有的行业派点信息
- sql = ` DELETE FROM cygx_allocation_company_contract_permission WHERE company_contract_id IN (` + utils.GetOrmInReplace(lenIds) + `)`
- _, 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
- }
- ow := orm.NewOrm()
- sqlW := `UPDATE company_contract SET is_allocation=1 ,allocation_type = 1 WHERE company_contract_id IN (` + utils.GetOrmInReplace(lenIds) + `)`
- _, err = ow.Raw(sqlW, companyContractId).Exec()
- return
- }
- type UpdateAllocationCompanyContractReq struct {
- CompanyContractId int `description:"合同ID"`
- List []*AllocationPermissionListResp
- }
- type CygxAllocationCompanyContractDetailResp struct {
- CompanyContractId int `description:"合同ID"`
- Money float64 `description:"金额(单位万)"`
- TotalPointsContent string `description:"总点数描述"`
- IsGray bool `description:"是否置灰"`
- IsXClass bool `description:"是否是X类试用客户"`
- AllocationType int `description:"分配方式,0手动分配,1X录分之后自动分配,默认0"`
- List []*AllocationPermissionListResp
- }
- // 行业
- type AllocationPermissionListResp struct {
- ChartPermissionName string `description:"行业名称"`
- ChartPermissionId int `description:"行业id"`
- Proportion float64 `description:"占比"`
- Money float64 `description:"金额(单位万)"`
- MoneyAvg float64 `description:"行业所占合同的平均金额"`
- CompanyContractId int `description:"合同ID"`
- List []*AllocationRealNameListResp
- }
- // 行业
- type AllocationRealNameListResp struct {
- RealName string `description:"研究员姓名"`
- Proportion float64 `description:"占比"`
- Money float64 `description:"金额(单位万)"`
- ChartPermissionId int `description:"行业id"`
- }
- // 获取数量
- 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
- }
- // 研究员列表
- func GetCygxAllocationCompanyContractListById(companyContractId int) (items []*CygxAllocationCompanyContract, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sql := `SELECT * FROM cygx_allocation_company_contract WHERE company_contract_id = ? `
- _, err = o.Raw(sql, companyContractId).QueryRows(&items)
- return
- }
- // 研究员列表
- func GetCygxAllocationCompanyContractList(condition string, pars []interface{}) (items []*CygxAllocationCompanyContract, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sql := `SELECT * FROM cygx_allocation_company_contract as art WHERE 1= 1 `
- if condition != "" {
- sql += condition
- }
- _, err = o.Raw(sql, pars).QueryRows(&items)
- return
- }
- // 行业列表
- func GetCygxAllocationCompanyContractPermissionListById(companyContractId int) (items []*AllocationPermissionListResp, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sql := ` SELECT * FROM cygx_allocation_company_contract_permission WHERE company_contract_id = ? `
- _, err = o.Raw(sql, companyContractId).QueryRows(&items)
- return
- }
- // 行业列表
- func GetCygxAllocationCompanyContractPermissionList(condition string, pars []interface{}) (items []*AllocationPermissionListResp, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sql := ` SELECT * FROM cygx_allocation_company_contract_permission as art WHERE 1= 1 `
- if condition != "" {
- sql += condition
- }
- _, err = o.Raw(sql, pars).QueryRows(&items)
- return
- }
- type CygxAllocationCompanyContractDetailStatisticsResp struct {
- List []*AllocationPermissionStatisticsListResp
- TotalContract int `description:"关联合同总计"`
- TotalMoney float64 `description:"总派点总计"`
- }
- // 行业
- type AllocationPermissionStatisticsListResp struct {
- ChartPermissionName string `description:"行业名称"`
- List []*AllocationRealNameStatisticsListResp
- }
- // 行业
- type AllocationRealNameStatisticsListResp struct {
- RealName string `description:"研究员姓名"`
- TotalRelatedContract float64 `description:"关联合同"`
- TotalDispatchPoint string `description:"总派点"`
- GroupProportion string `description:"组内占比"`
- DepartmentProportion string `description:"部门占比"`
- }
- // 行业列表
- func GetCygxAllocationCompanyContractPermissionListByIdInitYx(companyContractId int) (items []*CygxAllocationCompanyContractPermission, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sql := ` SELECT * FROM cygx_allocation_company_contract_permission WHERE company_contract_id = ? AND chart_permission_name IN ('研选扣点包','研选订阅','买方研选') `
- _, err = o.Raw(sql, companyContractId).QueryRows(&items)
- return
- }
- // 行业列表
- func GetCygxAllocationCompanyContractPermissionListByIdInit(companyContractId int) (items []*CygxAllocationCompanyContractPermission, err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sql := ` SELECT * FROM cygx_allocation_company_contract_permission WHERE company_contract_id = ? `
- _, err = o.Raw(sql, companyContractId).QueryRows(&items)
- return
- }
- // 更新派点信息
- func AddAndUpdateCygxAllocationCompanyContractInit(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()
- }
- }()
- //删除原有的研究员派点信息
- sql := `DELETE FROM cygx_allocation_company_contract WHERE company_contract_id = ? AND chart_permission_name IN ('研选扣点包','研选订阅','买方研选') `
- _, err = to.Raw(sql, companyContractId).Exec()
- if err != nil {
- return
- }
- //删除原有的行业派点信息
- sql = ` DELETE FROM cygx_allocation_company_contract_permission WHERE company_contract_id = ? AND chart_permission_name IN ('研选扣点包','研选订阅','买方研选') `
- _, err = to.Raw(sql, companyContractId).Exec()
- if err != nil {
- return
- }
- //批量添加研究员派点信息
- _, err = to.InsertMulti(len(items), items)
- if err != nil {
- return
- }
- //批量添加行业派点信息
- _, err = to.InsertMulti(len(itemsPermission), itemsPermission)
- if err != nil {
- return
- }
- return
- }
- // 修改
- func Cygx_allocation_company_contractEdit(proportion float64, allocation_company_contract_id int) (err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sql := `UPDATE cygx_allocation_company_contract SET proportion =? WHERE allocation_company_contract_id=? `
- _, err = o.Raw(sql, proportion, allocation_company_contract_id).Exec()
- return
- }
- // 修改
- func Cygx_allocation_company_contract_permissionEdit(proportion, moneyAvg float64, allocation_company_contract_id int) (err error) {
- o := orm.NewOrmUsingDB("hz_cygx")
- sql := `UPDATE cygx_allocation_company_contract_permission SET proportion =?,money_avg = ? WHERE allocation_company_contract_id=? `
- _, err = o.Raw(sql, proportion, moneyAvg, allocation_company_contract_id).Exec()
- return
- }
|