price_driven.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. package price_driven
  2. import (
  3. "errors"
  4. "hongze/hongze_yb/models/response"
  5. "hongze/hongze_yb/models/tables/company_product"
  6. "hongze/hongze_yb/models/tables/yb_price_driven"
  7. "hongze/hongze_yb/models/tables/yb_price_driven_visit_log"
  8. "hongze/hongze_yb/services/user"
  9. "hongze/hongze_yb/utils"
  10. )
  11. // GetPriceDrivenDetail 获取价格驱动详情
  12. func GetPriceDrivenDetail(chartPermissionId int) (resp *response.PriceDrivenItem, errMsg string, err error) {
  13. resp = new(response.PriceDrivenItem)
  14. // 获取详情
  15. item, e := yb_price_driven.GetPriceDrivenByChartPermissionId(chartPermissionId)
  16. if e != nil && e != utils.ErrNoRow {
  17. errMsg = "获取失败"
  18. err = errors.New("获取价格驱动信息失败, Err:" + e.Error())
  19. return
  20. }
  21. if item != nil {
  22. resp.PriceDrivenID = item.PriceDrivenID
  23. resp.ChartPermissionID = item.ChartPermissionID
  24. resp.MainVariable = item.MainVariable
  25. resp.CoreDrivenType = item.CoreDrivenType
  26. resp.CoreDrivenContent = item.CoreDrivenContent
  27. resp.CoreContent = item.CoreContent
  28. resp.CreateTime = item.CreateTime.Format(utils.FormatDateTime)
  29. resp.ModifyTime = item.ModifyTime.Format(utils.FormatDateTime)
  30. }
  31. return
  32. }
  33. // SavePriceDrivenVisitLog 保存价格驱动访问记录
  34. func SavePriceDrivenVisitLog(priceDrivenId, sourceAgent int, userInfo user.UserInfo) (errMsg string, err error) {
  35. companyInfo, e := company_product.GetByCompany2ProductId(userInfo.CompanyID, 1)
  36. if e != nil && e != utils.ErrNoRow {
  37. errMsg = "保存失败"
  38. err = errors.New("获取客户信息失败, Err: " + e.Error())
  39. return
  40. }
  41. var companyName, companyStatus string
  42. if companyInfo != nil {
  43. companyName = companyInfo.CompanyName
  44. companyStatus = companyInfo.Status
  45. } else {
  46. // 是否是权益用户-视作潜在用户
  47. equityCompany, e := company_product.GetByCompany2ProductId(userInfo.CompanyID, 2)
  48. if e != nil && e != utils.ErrNoRow {
  49. errMsg = "保存失败"
  50. err = errors.New("获取客户权益信息失败, Err: " + e.Error())
  51. return
  52. }
  53. if equityCompany != nil {
  54. companyName = equityCompany.CompanyName
  55. companyStatus = "潜在"
  56. }
  57. }
  58. logItem := &yb_price_driven_visit_log.YbPriceDrivenVisitLog{
  59. PriceDrivenID: priceDrivenId,
  60. UserID: int(userInfo.UserID),
  61. Mobile: userInfo.Mobile,
  62. RealName: userInfo.RealName,
  63. NickName: userInfo.NickName,
  64. CompanyID: int(userInfo.CompanyID),
  65. CompanyName: companyName,
  66. CompanyStatus: companyStatus,
  67. SourceAgent: sourceAgent,
  68. }
  69. if e := logItem.Create(); e != nil {
  70. errMsg = "保存失败"
  71. err = errors.New("新增价格驱动访问记录失败, Err: " + e.Error())
  72. return
  73. }
  74. return
  75. }