company_product_update_log.go 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. package company
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. // CompanyProductUpdateLog 客户产品变更日志表
  7. type CompanyProductUpdateLog struct {
  8. Id int `orm:"column(id);pk"`
  9. CompanyId int `description:"客户id"`
  10. ProductId int `description:"产品id"`
  11. Status string `description:"变更后的状态"`
  12. SellerId int `description:"销售id"`
  13. SellerName string `description:"销售名称"`
  14. Source string `description:"来源"`
  15. IsFormal int `description:"是否已经转正式,0是没有转正式,1是已经转过正式"`
  16. StartDate time.Time `description:"开始日期"`
  17. EndDate time.Time `description:"结束日期"`
  18. RealEndDate time.Time `description:"实际结束日期"`
  19. CreateTime time.Time `description:"创建时间"`
  20. }
  21. // AddCompanyProductUpdateLog 新增客户产品变更日志
  22. func AddCompanyProductUpdateLog(item *CompanyProductUpdateLog) (lastId int64, err error) {
  23. o := orm.NewOrm()
  24. lastId, err = o.Insert(item)
  25. if err != nil {
  26. return
  27. }
  28. item.Id = int(lastId)
  29. return
  30. }
  31. type CompanyReportRecordGroup struct {
  32. AdminId int `description:"所属销售id"`
  33. //AdminName string `description:"所属销售名称"`
  34. Num int `description:"汇总次数"`
  35. CompanyIds string `description:"客户id字符串"`
  36. }
  37. // GetGroupCompanyReportRecordGroupList 获取销售分组数据
  38. func GetGroupCompanyReportRecordGroupList(condition string, pars []interface{}) (list []*CompanyReportRecordGroup, err error) {
  39. o := orm.NewOrm()
  40. sql := ` SELECT seller_id as admin_id,count(DISTINCT(company_id)) num,GROUP_CONCAT(DISTINCT company_id SEPARATOR ',') AS company_ids
  41. FROM company_product_update_log
  42. WHERE 1=1
  43. `
  44. if condition != "" {
  45. sql += condition
  46. }
  47. sql += ` GROUP BY seller_id`
  48. _, err = o.Raw(sql, pars).QueryRows(&list)
  49. return
  50. }
  51. // GetCompanyProductUpdateLogList 获取客户变更试用的数据
  52. func GetCompanyProductUpdateLogList() (list []*CompanyProductUpdateLog, err error) {
  53. o := orm.NewOrm()
  54. //add
  55. //receive
  56. //thaw
  57. //apply_receive
  58. //delay
  59. sql := ` select * from company_product_update_log where source in("add","receive","thaw","apply_receive");`
  60. _, err = o.Raw(sql).QueryRows(&list)
  61. return
  62. }
  63. // GetCompanyProductLogItem 获取客户变更试用的数据
  64. func GetCompanyProductLogItem(companyId, productId int, createTime time.Time) (item *CompanyProductUpdateLog, err error) {
  65. o := orm.NewOrm()
  66. sql := ` select * from company_product_log where company_id=? and product_id=? and create_time >= ? and create_time <=?`
  67. err = o.Raw(sql, companyId, productId, createTime.Add(-2*60*time.Second), createTime.Add(2*60*time.Second)).QueryRow(&item)
  68. return
  69. }