company.go 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. package models
  2. import (
  3. "fmt"
  4. "github.com/beego/beego/v2/client/orm"
  5. "strings"
  6. "time"
  7. )
  8. type Company struct {
  9. CompanyId int `orm:"column(company_id);pk"`
  10. CompanyName string `description:"客户名称"`
  11. CompanyType int `orm:"column(type)"`
  12. CreditCode string `description:"社会统一信用码"`
  13. CompanyCode string `description:"客户编码"`
  14. Sort int `description:"优先级"`
  15. IsFeeCustomer int `description:"是否付费用户"`
  16. Country string `description:"国家编码"`
  17. Province string `description:"省"`
  18. City string `description:"市"`
  19. Address string `description:"详细地址"`
  20. Enabled int `description:"用户状态"`
  21. CreatedTime time.Time `description:"创建时间"`
  22. LastUpdatedTime time.Time `description:"最后一次阅读时间"`
  23. Seller string `description:"销售员"`
  24. SellsId int `description:"销售员id"`
  25. ShareSeller string `description:"共享销售员"`
  26. ShareSellerId int `description:"共享销售员id"`
  27. CompanyBelong string `description:"客户所属,ficc:ficc客户,public_offering:公募客户,partner:合作伙伴"`
  28. StartDate string `description:"合同开始日期"`
  29. EndDate string `description:"合同结束日期"`
  30. LastType int `description:"原客户标签"`
  31. IsVip int `description:"0:普通用户,1:大客户"`
  32. IsShare int `description:"0:非共享用户,1:共享客户"`
  33. FirstStartDate string `description:"首次设置为试用客户开始时间"`
  34. FirstEndDate string `description:"首次设置为试用客户结束时间"`
  35. DateType int `description:"设置流失类型,1:1个月,2:2个月,3:3个月"`
  36. Remark string `description:"备注信息"`
  37. RegionType string `description:"地区类型,国内,国外"`
  38. OpenCompanyCode string `description:"开放给第三方的客户编码,不让第三方定位我们的客户信息"`
  39. }
  40. type CompanyProduct struct {
  41. CompanyProductId int `orm:"column(company_product_id);pk" description:"客户产品id"`
  42. CompanyId int `description:"客户id"`
  43. ProductId int `description:"产品id"`
  44. ProductName string `description:"产品名称"`
  45. CompanyName string `description:"客户名称"`
  46. Source string `description:"来源"`
  47. Reasons string `description:"新增理由"`
  48. Status string `description:"客户状态"`
  49. IndustryId int `description:"行业id"`
  50. IndustryName string `description:"行业名称"`
  51. SellerId int `description:"销售id"`
  52. SellerName string `description:"销售名称"`
  53. GroupId int `description:"销售分组id"`
  54. DepartmentId int `description:"销售部门id"`
  55. IsSuspend int `description:"1:暂停,0:启用"`
  56. SuspendTime time.Time `description:"暂停启用时间"`
  57. TryOutTime time.Time `description:"正式转试用时间"`
  58. RenewalReason string `description:"正式转试用后的续约情况说明"`
  59. LastDescriptionTime time.Time `description:"上次添加说明时间"`
  60. RenewalIntention int `description:"是否勾选无续约意向,1:确认,0:未确认"`
  61. ApproveStatus string `description:"审批状态:'审批中','通过','驳回'"`
  62. FreezeTime time.Time `description:"冻结时间"`
  63. FreezeReason time.Time `description:"冻结理由"`
  64. Remark string `description:"备注信息"`
  65. CreateTime time.Time `description:"创建时间"`
  66. ModifyTime time.Time `description:"修改时间"`
  67. StartDate string `description:"开始日期"`
  68. EndDate string `description:"结束日期"`
  69. ContractEndDate time.Time `description:"合同结束日期"`
  70. LoseReason string `description:"流失原因"`
  71. LossTime time.Time `description:"流失时间"`
  72. CompanyType string `description:"客户类型"`
  73. OpenCode string `description:"开放给第三方的编码,不让第三方定位我们的客户信息"`
  74. ViewTotal int `description:"阅读总数"`
  75. }
  76. func GetCompanyProductByCompanyIdAndProductId(companyId, productId int) (item *CompanyProduct, err error) {
  77. o := orm.NewOrm()
  78. sql := `SELECT b.* FROM company AS a
  79. INNER JOIN company_product AS b ON a.company_id=b.company_id
  80. WHERE a.company_id=? AND b.product_id=? LIMIT 1 `
  81. err = o.Raw(sql, companyId, productId).QueryRow(&item)
  82. return
  83. }
  84. // 客户授权产品结构体(包含产品名称)
  85. type CompanyReportPermissionAndName struct {
  86. CompanyReportPermissionId int `description:"客户授权产品id"`
  87. CompanyId int
  88. ReportPermissionId int
  89. CreatedTime time.Time
  90. LastUpdatedTime time.Time
  91. ChartPermissionId int
  92. StartDate string `description:"权限开始日期"`
  93. EndDate string `description:"权限结束日期"`
  94. ProductId int `description:"产品id"`
  95. ProductName string `description:"产品名称"`
  96. CompanyContractId int `description:"合同id"`
  97. PermissionName string `description:"客户授权产品的名称"`
  98. ClassifyName string `description:"客户授权产品的分类名称"`
  99. Status string `description:"'正式','试用','关闭'"`
  100. ModifyTime time.Time `description:"修改时间"`
  101. }
  102. // 根据企业用户id和产品id获取所有正式的权限
  103. func GetCompanyProductReportPermissionList(companyId, productId int) (items []*CompanyReportPermissionAndName, err error) {
  104. o := orm.NewOrm()
  105. 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=? `
  106. _, err = o.Raw(sql, companyId, productId).QueryRows(&items)
  107. return
  108. }
  109. // GetCompanyListByCondition 获取客户列表
  110. func GetCompanyListByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*Company, err error) {
  111. o := orm.NewOrm()
  112. fields := strings.Join(fieldArr, ",")
  113. if len(fieldArr) == 0 {
  114. fields = `*`
  115. }
  116. order := `ORDER BY created_time DESC`
  117. if orderRule != "" {
  118. order = ` ORDER BY ` + orderRule
  119. }
  120. sql := fmt.Sprintf(`SELECT %s FROM company WHERE 1=1 %s %s`, fields, condition, order)
  121. _, err = o.Raw(sql, pars).QueryRows(&items)
  122. return
  123. }