eta_business.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. package eta_business
  2. import (
  3. "fmt"
  4. "hongze/hz_crm_api/models/company"
  5. "hongze/hz_crm_api/models/eta_business"
  6. "hongze/hz_crm_api/services/alarm_msg"
  7. "hongze/hz_crm_api/utils"
  8. "strings"
  9. "time"
  10. )
  11. // CheckEtaBusinessOperateAuth 校验ETA商家操作权限
  12. func CheckEtaBusinessOperateAuth(roleCode string) (ok bool, err error) {
  13. confKey := "eta_business_auth_role"
  14. conf, e := company.GetConfigDetailByCode(confKey)
  15. if e != nil {
  16. err = fmt.Errorf("获取权限配置失败, Err: %s", e.Error())
  17. return
  18. }
  19. if conf.ConfigValue == "" {
  20. err = fmt.Errorf("权限配置信息有误")
  21. return
  22. }
  23. authArr := strings.Split(conf.ConfigValue, ",")
  24. if utils.InArrayByStr(authArr, roleCode) {
  25. ok = true
  26. }
  27. return
  28. }
  29. // UpdateEtaBusinessAfterSigning 签约后的后置操作
  30. func UpdateEtaBusinessAfterSigning(businessId int) (err error) {
  31. if businessId <= 0 {
  32. return
  33. }
  34. defer func() {
  35. if err != nil {
  36. tips := "签约后更新商家信息失败, Err: " + err.Error()
  37. utils.FileLog.Info("%s", tips)
  38. go alarm_msg.SendAlarmMsg(tips, 3)
  39. }
  40. }()
  41. businessOb := new(eta_business.EtaBusiness)
  42. business, e := businessOb.GetItemById(businessId)
  43. if e != nil {
  44. err = fmt.Errorf("获取商家信息失败, Err: %s", e.Error())
  45. return
  46. }
  47. contracts := make([]*eta_business.EtaBusinessContract, 0)
  48. {
  49. ob := new(eta_business.EtaBusinessContract)
  50. cond := fmt.Sprintf(` AND %s = ?`, eta_business.EtaBusinessContractColumns.EtaBusinessId)
  51. pars := make([]interface{}, 0)
  52. pars = append(pars, businessId)
  53. list, e := ob.GetItemsByCondition(cond, pars, []string{}, "")
  54. if e != nil {
  55. err = fmt.Errorf("获取商家合同列表失败, Err: " + e.Error())
  56. return
  57. }
  58. contracts = list
  59. }
  60. if len(contracts) == 0 {
  61. return
  62. }
  63. strToday := time.Now().Format(utils.FormatDate)
  64. today, _ := time.ParseInLocation(utils.FormatDate, strToday, time.Local)
  65. using := false // 是否在任一存续期内
  66. for _, c := range contracts {
  67. // 当前合约
  68. if today.Equal(c.SigningTime) || today.Equal(c.ExpiredTime) || (today.After(c.SigningTime) && today.Before(c.ExpiredTime)) {
  69. business.ContractId = c.EtaBusinessContractId
  70. business.SigningTime = c.SigningTime
  71. business.ExpiredTime = c.ExpiredTime
  72. business.ModifyTime = time.Now().Local()
  73. // 是否为首次签约
  74. if c.IsFirst == 1 {
  75. business.SigningStatus = eta_business.EtaBusinessSigningStatusFirst
  76. } else {
  77. business.SigningStatus = eta_business.EtaBusinessSigningStatusContinue
  78. }
  79. using = true
  80. break
  81. }
  82. }
  83. // 不存在任一合同期内, 当前合同不变, 更新状态
  84. if !using {
  85. business.SigningStatus = eta_business.EtaBusinessSigningStatusTerminate
  86. business.ModifyTime = time.Now().Local()
  87. cols := []string{"SigningStatus", "ModifyTime"}
  88. if e = business.Update(cols); e != nil {
  89. err = fmt.Errorf("更新商家信息失败, Err: %s", e.Error())
  90. return
  91. }
  92. return
  93. }
  94. // 合同期内
  95. cols := []string{"ContractId", "SigningStatus", "SigningTime", "ExpiredTime", "ModifyTime"}
  96. if e = business.Update(cols); e != nil {
  97. err = fmt.Errorf("更新商家信息失败, Err: %s", e.Error())
  98. }
  99. return
  100. }