celue_article_history_record.go 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. package models
  2. import (
  3. "fmt"
  4. "github.com/beego/beego/v2/client/orm"
  5. "hongze/hongze_cygx/utils"
  6. "strconv"
  7. "time"
  8. )
  9. type CeLueArticleResultApi struct {
  10. Data []CeLueArticleResultApidate `json:"data"`
  11. Code int `json:"code"`
  12. Msg string `json:"msg"`
  13. Pagination *Pagination `json:"pagination"`
  14. }
  15. type CeLueArticleResultApidate struct {
  16. CelueHistoryId int `json:"id"`
  17. Mobile string `json:"phone_number"`
  18. ArticleId string `json:"entity_info"`
  19. CreateDate string `json:"access_time"`
  20. CrmUser *CrmUser `json:"user"`
  21. CompanyName *CrmUser `json:"crm_company"`
  22. }
  23. type CrmUser struct {
  24. RealName string `json:"name"`
  25. }
  26. type CrmCompany struct {
  27. CompanyName string `json:"name"`
  28. }
  29. func GetCeLueArticleCountById(celueHistoryId int) (count int, err error) {
  30. o := orm.NewOrm()
  31. sql := `SELECT COUNT(1) AS count FROM cygx_celue_article_history_record WHERE celue_history_id = ? `
  32. err = o.Raw(sql, celueHistoryId).QueryRow(&count)
  33. return
  34. }
  35. func GetCeLueArticleListByIds(celueHistoryIds []int) (items []*CygxArticleHistoryRecordAll, err error) {
  36. if len(celueHistoryIds) == 0 {
  37. return
  38. }
  39. o := orm.NewOrm()
  40. sql := `SELECT celue_history_id FROM cygx_celue_article_history_record WHERE celue_history_id IN (` + utils.GetOrmInReplace(len(celueHistoryIds)) + `) `
  41. _, err = o.Raw(sql, celueHistoryIds).QueryRows(&items)
  42. return
  43. }
  44. type CygxCelueArticleHistoryRecord struct {
  45. Id int `orm:"column(id);pk"`
  46. ArticleId string `description:"文章ID"`
  47. CelueHistoryId int `description:"策略平台记录的ID"`
  48. CreateTime string `description:"本地创建时间"`
  49. CreateDateApi time.Time `description:"图表创建时间"`
  50. Mobile string `description:"手机号"`
  51. CompanyName string `description:"公司名称"`
  52. RealName string `description:"用户姓名"`
  53. CompanyStatus string `description:"公司状态"`
  54. SellerName string `description:"所属销售"`
  55. }
  56. // 新增
  57. func AddCeLueArticle(item *CygxCelueArticleHistoryRecord, mapMobileArticleId map[string]int) (lastId int64, err error) {
  58. o, err := orm.NewOrm().Begin()
  59. if err != nil {
  60. return
  61. }
  62. defer func() {
  63. if err == nil {
  64. o.Commit()
  65. } else {
  66. o.Rollback()
  67. }
  68. }()
  69. lastId, err = o.Insert(item)
  70. //写入记录到总的统计表
  71. record := new(CygxArticleHistoryRecordAll)
  72. articleId, _ := strconv.Atoi(item.ArticleId)
  73. record.ArticleId = articleId
  74. record.CelueHistoryId = item.CelueHistoryId
  75. record.CreateTime = item.CreateTime
  76. record.ModifyTime = time.Now()
  77. record.CreateDateApi = time.Now()
  78. record.Mobile = item.Mobile
  79. record.CompanyName = item.CompanyName
  80. record.RealName = item.RealName
  81. record.Platfor = 2
  82. record.Source = "CELUE"
  83. if mapMobileArticleId[fmt.Sprint(item.Mobile, "_", item.ArticleId)] == articleId {
  84. record.IsDel = 1
  85. }
  86. lastId, err = o.Insert(record)
  87. return
  88. }