contract_allocation.go 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. package cygxService
  2. import (
  3. "fmt"
  4. "errors"
  5. "hongze/hongze_mobile_admin/models/tables/company_contract_permission"
  6. "hongze/hongze_mobile_admin/models/tables/cygx_allocation_company_contract"
  7. "hongze/hongze_mobile_admin/services/alarm_msg"
  8. "hongze/hongze_mobile_admin/utils"
  9. "time"
  10. "hongze/hongze_mobile_admin/models/tables/company_contract"
  11. )
  12. // 如果合同只有研选的时候,自动处理派点
  13. func HandleAllocationCompanyContractByYanXuan(companyContractId int) (err error) {
  14. defer func() {
  15. if err != nil {
  16. fmt.Println(err)
  17. go alarm_msg.SendAlarmMsg(fmt.Sprint("如果合同只有研选的时候,自动处理派点失败,Err:", err.Error(), "companyContractId", companyContractId), 2)
  18. }
  19. }()
  20. var condition string
  21. var pars []interface{}
  22. pars = make([]interface{}, 0)
  23. condition = " AND company_contract_id = ? "
  24. pars = append(pars, companyContractId)
  25. companyContractPermissionList, e := company_contract_permission.GetCompanyContractPermissionList(condition, pars)
  26. if e != nil && e.Error() != utils.ErrNoRow() {
  27. err = errors.New("GetCompanyContractPermissionList, Err: " + e.Error())
  28. return
  29. }
  30. if e != nil && e.Error() != utils.ErrNoRow() {
  31. err = errors.New("GetCygxAllocationCompanyContractPermissionListById, Err: " + e.Error())
  32. return
  33. }
  34. if len(companyContractPermissionList) > 1 {
  35. return
  36. }
  37. var expensiveYxmoney float64
  38. for _, v := range companyContractPermissionList {
  39. if v.ChartPermissionId != utils.CHART_PERMISSION_ID_YANXUAN {
  40. err = errors.New("没有发现研选权限: ")
  41. return
  42. }
  43. if v.ExpensiveYx == 1 {
  44. expensiveYxmoney = 5
  45. } else if v.ExpensiveYx == 2 {
  46. expensiveYxmoney = 10
  47. } else{
  48. expensiveYxmoney = 3
  49. }
  50. }
  51. var items []*cygx_allocation_company_contract.CygxAllocationCompanyContract
  52. var itemsPermission []*cygx_allocation_company_contract.CygxAllocationCompanyContractPermission
  53. itemPermission := new(cygx_allocation_company_contract.CygxAllocationCompanyContractPermission)
  54. itemPermission.CompanyContractId = companyContractId
  55. //itemPermission.AdminId = sysUser.AdminId
  56. //itemPermission.AdminName = sysUser.RealName
  57. itemPermission.Proportion = 0
  58. itemPermission.Money = expensiveYxmoney
  59. itemPermission.MoneyAvg = 0
  60. itemPermission.ChartPermissionName = utils.CHART_PERMISSION_NAME_MF_YANXUAN
  61. itemPermission.CreateTime = time.Now()
  62. itemPermission.ModifyTime = time.Now()
  63. itemsPermission = append(itemsPermission, itemPermission)
  64. item := new(cygx_allocation_company_contract.CygxAllocationCompanyContract)
  65. item.CompanyContractId = companyContractId
  66. //item.AdminId = sysUser.AdminId
  67. //item.AdminName = sysUser.RealName
  68. item.Proportion = 0
  69. item.Money = expensiveYxmoney
  70. item.RealName = utils.CHART_PERMISSION_NAME_MF_YANXUAN
  71. item.ChartPermissionName = utils.CHART_PERMISSION_NAME_MF_YANXUAN
  72. item.CreateTime = time.Now()
  73. item.ModifyTime = time.Now()
  74. items = append(items, item)
  75. e = cygx_allocation_company_contract.AddAndUpdateCygxAllocationCompanyContract(items, itemsPermission, companyContractId)
  76. if e != nil {
  77. err = errors.New("AddAndUpdateCygxAllocationCompanyContract, Err: " + e.Error())
  78. return
  79. }
  80. return
  81. }
  82. // HandleCompanyContractPackageDifference 更新与上一份合同的金额的对比 '增加套餐','减少套餐','维持套餐'
  83. func HandleCompanyContractPackageDifference(companyContractId int) (err error) {
  84. defer func() {
  85. if err != nil {
  86. fmt.Println(err)
  87. go alarm_msg.SendAlarmMsg(fmt.Sprint("如果合同只有研选的时候,自动处理派点失败,Err:", err.Error(), "companyContractId", companyContractId), 2)
  88. }
  89. }()
  90. var condition string
  91. var pars []interface{}
  92. condition = " AND company_contract_id = ? "
  93. pars = append(pars, companyContractId)
  94. detail, e := company_contract.GetCompanyContracDetail(condition, pars)
  95. if e != nil {
  96. err = errors.New("GetCompanyContracDetail,detail Err: " + e.Error())
  97. return
  98. }
  99. //如果不是续约合同就不做对比处理
  100. if detail.ContractType != "续约合同" {
  101. return
  102. }
  103. //获取前一份合同的信息
  104. pars = make([]interface{}, 0)
  105. condition = " AND company_id = ? AND company_contract_id < ? AND status = 1 AND product_id = ? ORDER BY company_contract_id DESC LIMIT 1 "
  106. pars = append(pars, detail.CompanyId, companyContractId, detail.ProductId)
  107. detailPrevious, e := company_contract.GetCompanyContracDetail(condition, pars)
  108. if e != nil {
  109. err = errors.New("GetCompanyContracDetail,detailPrevious Err: " + e.Error())
  110. return
  111. }
  112. var packageDifference string
  113. if detail.Money > detailPrevious.Money {
  114. packageDifference = "增加套餐"
  115. } else if detail.Money < detailPrevious.Money {
  116. packageDifference = "减少套餐"
  117. } else {
  118. packageDifference = "维持套餐"
  119. }
  120. e = company_contract.UpdateCompanyContractPackageDifference(packageDifference, companyContractId)
  121. fmt.Println(packageDifference)
  122. if e != nil {
  123. err = errors.New("UpdateCompanyContractPackageDifference, Err: " + e.Error())
  124. return
  125. }
  126. return
  127. }