company_contract.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. package contract
  2. import (
  3. "errors"
  4. "fmt"
  5. "hongze/hongze_mobile_admin/models/tables/company_contract"
  6. "hongze/hongze_mobile_admin/models/tables/company_product"
  7. "hongze/hongze_mobile_admin/services/alarm_msg"
  8. "hongze/hongze_mobile_admin/utils"
  9. "strconv"
  10. "time"
  11. )
  12. // 权益客户创建新的有效合同之后,更新所关联的销售信息
  13. func UpdateCompanyProductSellerMove(companyId, productId int) {
  14. if productId != utils.COMPANY_PRODUCT_RAI_ID {
  15. return
  16. }
  17. time.Sleep(1 * time.Second) // 延迟1秒
  18. var err error
  19. defer func() {
  20. if err != nil {
  21. fmt.Println(err)
  22. go alarm_msg.SendAlarmMsg("权益客户创建新的有效合同之后,更新所关联的销售信息,UpdateCompanyProductSellerMove "+fmt.Sprint("companyId:", companyId, ";err:", err), 3)
  23. }
  24. }()
  25. cp, e := company_product.GetCompanyProductByCompanyIdAndProductId(companyId, productId)
  26. if e != nil {
  27. err = errors.New("GetCompanyProductByCompanyIdAndProductId Err: " + e.Error())
  28. return
  29. }
  30. e = company_product.UpdateCompanyProductSellerUnexpired(cp.SellerId, cp.ShareSellerId, cp.SellerName, cp.ShareSeller, cp.CompanyId)
  31. if e != nil {
  32. err = errors.New("UpdateCompanyProductSellerUnexpired, Err: " + e.Error())
  33. return
  34. }
  35. return
  36. }
  37. // 权益客户创建新的有效合同之后,对相关合同进行隐藏
  38. func UpdateCompanyContracthideBycompanyId(companyId, productId int) {
  39. if productId != utils.COMPANY_PRODUCT_RAI_ID {
  40. return
  41. }
  42. var err error
  43. defer func() {
  44. if err != nil {
  45. fmt.Println(err)
  46. go alarm_msg.SendAlarmMsg("权益客户创建新的有效合同之后,对相关合同进行隐藏,UpdateCompanyContracthideBycompanyId "+fmt.Sprint("companyId:", companyId, ";err:", err), 3)
  47. }
  48. }()
  49. var condition string
  50. var pars []interface{}
  51. if companyId > 0 {
  52. condition = ` AND a.company_id = ? `
  53. pars = append(pars, companyId)
  54. }
  55. listContractMax, e := company_contract.GetCompanyContracListMaxStartDate(condition, pars)
  56. if e != nil {
  57. err = errors.New("GetCompanyContracListMaxStartDate, Err: " + e.Error())
  58. return
  59. }
  60. //如果合同结束时间,早于最新一份合同的开始时间,这份合同就隐藏
  61. maxId := make(map[int]time.Time)
  62. for _, v := range listContractMax {
  63. maxId[v.CompanyId] = v.MaxStartDate
  64. }
  65. listContract, e := company_contract.GetCompanyContracListInit_CRM_16_1(condition, pars)
  66. if e != nil {
  67. err = errors.New("GetCompanyContracListInit_CRM_16_1, Err: " + e.Error())
  68. return
  69. }
  70. var updateId []string
  71. for _, v := range listContract {
  72. if v.EndDate.After(maxId[v.CompanyId]) {
  73. continue
  74. }
  75. updateId = append(updateId, strconv.Itoa(v.CompanyContractId))
  76. }
  77. if len(updateId) == 0 {
  78. return
  79. }
  80. e = company_contract.UpdateCompanyContracthide(updateId)
  81. if e != nil {
  82. err = errors.New("UpdateCompanyContracthide, Err: " + e.Error())
  83. return
  84. }
  85. fmt.Println((updateId))
  86. return
  87. }