123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- package models
- import (
- "fmt"
- "github.com/beego/beego/v2/client/orm"
- "strings"
- "time"
- )
- type Company struct {
- CompanyId int `orm:"column(company_id);pk"`
- CompanyName string `description:"客户名称"`
- CompanyType int `orm:"column(type)"`
- CreditCode string `description:"社会统一信用码"`
- CompanyCode string `description:"客户编码"`
- Sort int `description:"优先级"`
- IsFeeCustomer int `description:"是否付费用户"`
- Country string `description:"国家编码"`
- Province string `description:"省"`
- City string `description:"市"`
- Address string `description:"详细地址"`
- Enabled int `description:"用户状态"`
- CreatedTime time.Time `description:"创建时间"`
- LastUpdatedTime time.Time `description:"最后一次阅读时间"`
- Seller string `description:"销售员"`
- SellsId int `description:"销售员id"`
- ShareSeller string `description:"共享销售员"`
- ShareSellerId int `description:"共享销售员id"`
- CompanyBelong string `description:"客户所属,ficc:ficc客户,public_offering:公募客户,partner:合作伙伴"`
- StartDate string `description:"合同开始日期"`
- EndDate string `description:"合同结束日期"`
- LastType int `description:"原客户标签"`
- IsVip int `description:"0:普通用户,1:大客户"`
- IsShare int `description:"0:非共享用户,1:共享客户"`
- FirstStartDate string `description:"首次设置为试用客户开始时间"`
- FirstEndDate string `description:"首次设置为试用客户结束时间"`
- DateType int `description:"设置流失类型,1:1个月,2:2个月,3:3个月"`
- Remark string `description:"备注信息"`
- RegionType string `description:"地区类型,国内,国外"`
- OpenCompanyCode string `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:"阅读总数"`
- }
- 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
- }
- // GetCompanyListByCondition 获取客户列表
- func GetCompanyListByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*Company, err error) {
- o := orm.NewOrm()
- fields := strings.Join(fieldArr, ",")
- if len(fieldArr) == 0 {
- fields = `*`
- }
- order := `ORDER BY created_time DESC`
- if orderRule != "" {
- order = ` ORDER BY ` + orderRule
- }
- sql := fmt.Sprintf(`SELECT %s FROM company WHERE 1=1 %s %s`, fields, condition, order)
- _, err = o.Raw(sql, pars).QueryRows(&items)
- return
- }
|