package roadshow import ( "github.com/beego/beego/v2/client/orm" "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 int, keyWord string) (list []*CompanySearchView, err error) { list = make([]*CompanySearchView, 0) // 中文客户 companies := make([]*CompanySearchView, 0) o := orm.NewOrm() 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 b.status IN ('正式', '试用','永续') AND (b.seller_id = ? OR b.share_seller_id = ?) AND a.company_name LIKE ? GROUP BY b.company_id` _, err = o.Raw(sql, sellerId, sellerId, 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 }