123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184 |
- package roadshow
- import (
- "github.com/beego/beego/v2/client/orm"
- "hongze/hongze_mobile_admin/utils"
- "time"
- )
- type CompanySearchView struct {
- CompanyId int `orm:"column(company_id);pk"`
- CompanyName string `description:"客户名称"`
- CreditCode string `description:"社会统一信用码"`
- CompanyCode string `description:"客户编码"`
- EnglishCompany int `description:"是否为英文客户"`
- }
- func CompanySearch(sellerId int, keyWord string) (list []*CompanySearchView, err error) {
- o := orm.NewOrm()
- sql := ` SELECT b.company_id,b.company_name FROM company AS a
- INNER JOIN company_product AS b ON a.company_id=b.company_id
- WHERE b.seller_id=?
- AND b.status IN('正式','试用')
- AND b.company_name LIKE '%` + keyWord + `%'
- `
- sql += ` GROUP BY b.company_id `
- _, err = o.Raw(sql, sellerId).QueryRows(&list)
- return
- }
- type CompanyDetailView struct {
- CompanyId int `orm:"column(company_id);pk"`
- CompanyName string `description:"客户名称"`
- Status string `description:"客户状态"`
- IndustryId int `description:"行业id"`
- IndustryName string `description:"行业名称"`
- PermissionName string `description:"开通品种"`
- ReportReadTotal int `description:"累计阅读次数"`
- EnglishCompany int `description:"是否为英文客户: 0-否; 1-是"`
- EnglishCountry string `description:"英文客户-国家"`
- EnglishViewTotal int `description:"英文客户-累计点击量"`
- }
- type CompanyProduct struct {
- CompanyProductId int `orm:"column(company_product_id);pk" description:"客户产品id"`
- CompanyId int `description:"客户id"`
- ProductId int `description:"产品id"`
- ProductName string `description:"产品名称"`
- CompanyName string `description:"客户名称"`
- Source string `description:"来源"`
- Reasons string `description:"新增理由"`
- Status string `description:"客户状态"`
- IndustryId int `description:"行业id"`
- IndustryName string `description:"行业名称"`
- SellerId int `description:"销售id"`
- SellerName string `description:"销售名称"`
- GroupId int `description:"销售分组id"`
- DepartmentId int `description:"销售部门id"`
- IsSuspend int `description:"1:暂停,0:启用"`
- SuspendTime time.Time `description:"暂停启用时间"`
- TryOutTime time.Time `description:"正式转试用时间"`
- RenewalReason string `description:"正式转试用后的续约情况说明"`
- LastDescriptionTime time.Time `description:"上次添加说明时间"`
- RenewalIntention int `description:"是否勾选无续约意向,1:确认,0:未确认"`
- ApproveStatus string `description:"审批状态:'审批中','通过','驳回'"`
- FreezeTime time.Time `description:"冻结时间"`
- FreezeReason time.Time `description:"冻结理由"`
- Remark string `description:"备注信息"`
- CreateTime time.Time `description:"创建时间"`
- ModifyTime time.Time `description:"修改时间"`
- StartDate string `description:"开始日期"`
- EndDate string `description:"结束日期"`
- ContractEndDate time.Time `description:"合同结束日期"`
- LoseReason string `description:"流失原因"`
- LossTime time.Time `description:"流失时间"`
- CompanyType string `description:"客户类型"`
- OpenCode string `description:"开放给第三方的编码,不让第三方定位我们的客户信息"`
- ViewTotal int `description:"总阅读次数"`
- LastViewTime time.Time `description:"最后一次阅读时间"`
- PackageType int `description:"套餐类型"`
- Scale string `description:"管理规模,空不填,1::50亿以下,2:50~100亿,3:100亿以上。"`
- }
- func GetCompanyProductByCompanyIdAndProductId(companyId, productId int) (item *CompanyProduct, err error) {
- o := orm.NewOrm()
- sql := `SELECT b.* FROM company AS a
- INNER JOIN company_product AS b ON a.company_id=b.company_id
- WHERE a.company_id=? AND b.product_id=? LIMIT 1 `
- err = o.Raw(sql, companyId, productId).QueryRow(&item)
- return
- }
- // 客户授权产品结构体(包含产品名称)
- type CompanyReportPermissionAndName struct {
- CompanyReportPermissionId int `description:"客户授权产品id"`
- CompanyId int
- ReportPermissionId int
- CreatedTime time.Time
- LastUpdatedTime time.Time
- ChartPermissionId int
- StartDate string `description:"权限开始日期"`
- EndDate string `description:"权限结束日期"`
- ProductId int `description:"产品id"`
- ProductName string `description:"产品名称"`
- CompanyContractId int `description:"合同id"`
- PermissionName string `description:"客户授权产品的名称"`
- ClassifyName string `description:"客户授权产品的分类名称"`
- Status string `description:"'正式','试用','关闭'"`
- ModifyTime time.Time `description:"修改时间"`
- }
- // 根据企业用户id和产品id获取所有正式的权限
- func GetCompanyProductReportPermissionList(companyId, productId int) (items []*CompanyReportPermissionAndName, err error) {
- o := orm.NewOrm()
- sql := `SELECT a.*,b.permission_name,b.classify_name FROM company_report_permission a left join chart_permission b on a.chart_permission_id=b.chart_permission_id WHERE a.company_id = ? and a.product_id=? `
- _, err = o.Raw(sql, companyId, productId).QueryRows(&items)
- return
- }
- func CompanySearchV2(sellerId, groupId int, keyWord, roleTypeCode string) (list []*CompanySearchView, err error) {
- list = make([]*CompanySearchView, 0)
- // 中文客户
- companies := make([]*CompanySearchView, 0)
- o := orm.NewOrm()
- var sql string
- if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN || roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN { // 权益管理员跟管理员的筛选
- sql = `SELECT
- b.company_id,
- a.company_name,
- 0 AS english_company
- FROM
- company AS a
- INNER JOIN company_product AS b ON a.company_id = b.company_id
- WHERE
- 1=1
- AND IF ( b.product_id = 1 , b.status IN ('正式', '试用', '永续') ,1=1 )
- AND IF ( b.product_id = 2 , b.status IN ('正式', '试用', '永续', '冻结', '流失') ,1=1 )
- AND a.company_name LIKE ?
- GROUP BY
- b.company_id `
- _, err = o.Raw(sql, keyWord).QueryRows(&companies)
- if err != nil {
- return
- }
- } else {
- sql = `SELECT
- b.company_id,
- a.company_name,
- 0 AS english_company
- FROM
- company AS a
- INNER JOIN company_product AS b ON a.company_id = b.company_id
- WHERE
- 1=1
- AND IF ( b.product_id = 1 , b.status IN ('正式', '试用', '永续') ,1=1 )
- AND IF ( b.product_id = 2 , b.status IN ('正式', '试用', '永续', '冻结', '流失') ,1=1 )
- AND (b.seller_id = ? OR b.share_seller_id = ? OR b.group_id = ? OR b.share_group_id = ? ) AND a.company_name LIKE ?
- GROUP BY
- b.company_id `
- _, err = o.Raw(sql, sellerId, sellerId, groupId, groupId, keyWord).QueryRows(&companies)
- if err != nil {
- return
- }
- }
- list = append(list, companies...)
- // 英文客户
- enCompanies := make([]*CompanySearchView, 0)
- o2 := orm.NewOrmUsingDB("rddp")
- sql = `SELECT
- company_id,
- company_name,
- 1 AS english_company
- FROM
- english_company
- WHERE
- is_deleted = 0 AND enabled > 0 AND company_name LIKE ?`
- _, err = o2.Raw(sql, keyWord).QueryRows(&enCompanies)
- if err != nil {
- return
- }
- list = append(list, enCompanies...)
- return
- }
|