price_driven.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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(varietyTagId int) (resp *response.PriceDrivenItem, errMsg string, err error) {
  13. resp = new(response.PriceDrivenItem)
  14. // 获取详情
  15. item, e := yb_price_driven.GetPriceDrivenByVarietyTagId(varietyTagId)
  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.VarietyTagID = item.VarietyTagID
  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. companyName := "潜在客户"
  42. companyStatus := "潜在"
  43. if companyInfo != nil && companyInfo.CompanyID > 0 {
  44. companyName = companyInfo.CompanyName
  45. companyStatus = companyInfo.Status
  46. }
  47. item, e := yb_price_driven.GetPriceDrivenById(priceDrivenId)
  48. if e != nil && e != utils.ErrNoRow {
  49. errMsg = "保存失败"
  50. err = errors.New("获取价格驱动信息失败, Err:" + e.Error())
  51. return
  52. }
  53. tagId := 0
  54. tagName := ""
  55. if item != nil && item.PriceDrivenID > 0 {
  56. tagId = item.VarietyTagID
  57. tagName = item.VarietyTagName
  58. }
  59. logItem := &yb_price_driven_visit_log.YbPriceDrivenVisitLog{
  60. PriceDrivenID: priceDrivenId,
  61. VarietyTagID: tagId,
  62. VarietyTagName: tagName,
  63. UserID: int(userInfo.UserID),
  64. Mobile: userInfo.Mobile,
  65. RealName: userInfo.RealName,
  66. NickName: userInfo.NickName,
  67. CompanyID: int(userInfo.CompanyID),
  68. CompanyName: companyName,
  69. CompanyStatus: companyStatus,
  70. SourceAgent: sourceAgent,
  71. }
  72. if e := logItem.Create(); e != nil {
  73. errMsg = "保存失败"
  74. err = errors.New("新增价格驱动访问记录失败, Err: " + e.Error())
  75. return
  76. }
  77. return
  78. }