company_product_update_log.go 3.1 KB

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