company_product_update_log.go 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. package models
  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. IsFormal int `description:"是否已经转正式,0是没有转正式,1是已经转过正式"`
  15. Source string `description:"来源"`
  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. return
  26. }
  27. // GetCompanyProductUpdateLogList 获取客户产品变更日志列表
  28. func GetCompanyProductUpdateLogList(createTime string) (total int64, list []*CompanyProductUpdateLog, err error) {
  29. o := orm.NewOrm()
  30. //那就三种情况了:新增试用、冻结转试用、流失转试用
  31. //新增:add
  32. //领取:receive
  33. //试用转正式:turn_positive
  34. //冻结转试用:thaw
  35. //试用延期:delay
  36. //原销售申请领取流失客户:apply_receive
  37. //正式客户申请续约:service_update
  38. //正式客户新增补充协议:add_agreement
  39. sql := `SELECT * FROM company_product_update_log where create_time >= ? AND source in ("add","receive","thaw","apply_receive") `
  40. total, err = o.Raw(sql, createTime).QueryRows(&list)
  41. return
  42. }
  43. // IncrementCompanyProductUpdateLog 增量客户产品变更日志表
  44. type IncrementCompanyProductUpdateLog struct {
  45. Id int `orm:"column(id);pk"`
  46. CompanyId int `description:"客户id"`
  47. ProductId int `description:"产品id"`
  48. Status string `description:"变更后的状态"`
  49. Source string `description:"来源"`
  50. CreateTime time.Time `description:"创建时间"`
  51. CompanyName string `description:"客户名称"`
  52. CreditCode string `description:"社会信用码"`
  53. SellerName string `description:"销售名称"`
  54. CurrStatus string `description:"当前产品状态"`
  55. }
  56. // GetIncrementCompanyProductUpdateLogList 获取客户产品变更日志列表
  57. func GetIncrementCompanyProductUpdateLogList(startCreateTime, endCreateTime string) (total int64, list []*IncrementCompanyProductUpdateLog, err error) {
  58. o := orm.NewOrm()
  59. //那就三种情况了:新增试用、冻结转试用、流失转试用
  60. //新增:add
  61. //领取:receive
  62. //试用转正式:turn_positive
  63. //冻结转试用:thaw
  64. //试用延期:delay
  65. //原销售申请领取流失客户:apply_receive
  66. //正式客户申请续约:service_update
  67. //正式客户新增补充协议:add_agreement
  68. sql := `SELECT a.*,b.company_name,b.credit_code,c.status curr_status,c.seller_name FROM company_product_update_log a
  69. join company b on a.company_id=b.company_id
  70. join company_product c on a.company_id=c.company_id and c.product_id=a.product_id
  71. where a.create_time >= ? AND a.create_time < ? AND a.source in ("add","receive","thaw","apply_receive") `
  72. total, err = o.Raw(sql, startCreateTime, endCreateTime).QueryRows(&list)
  73. return
  74. }