company_contract.go 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. package cygx
  2. import (
  3. "fmt"
  4. "hongze/hongze_task/models"
  5. "hongze/hongze_task/models/company_contract"
  6. "hongze/hongze_task/models/cygx"
  7. "hongze/hongze_task/services/alarm_msg"
  8. "hongze/hongze_task/utils"
  9. "time"
  10. "errors"
  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.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.CygxAllocationCompanyContract
  52. var itemsPermission []*cygx.CygxAllocationCompanyContractPermission
  53. itemPermission := new(cygx.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.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.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. if e != nil {
  122. err = errors.New("UpdateCompanyContractPackageDifference, Err: " + e.Error())
  123. return
  124. }
  125. return
  126. }
  127. // HandleCompanyContractPermissionContractType 更新合同权限表中的权限名称,以及对应的行业权限类型(行业新签、行业续约)
  128. func HandleCompanyContractPermissionContractType(companyContractId int) (err error) {
  129. defer func() {
  130. if err != nil {
  131. fmt.Println(err)
  132. go alarm_msg.SendAlarmMsg(fmt.Sprint("更新合同权限表中的权限名称,以及对应的行业权限类型(行业新签、行业续约)失败,HandleCompanyContractPermissionContractType Err:", err.Error(), "companyContractId", companyContractId), 2)
  133. }
  134. }()
  135. var condition string
  136. var pars []interface{}
  137. condition = " AND company_contract_id = ? "
  138. pars = append(pars, companyContractId)
  139. detail, e := company_contract.GetCompanyContracDetail(condition, pars)
  140. if e != nil {
  141. err = errors.New("GetCompanyContracDetail,detail Err: " + e.Error())
  142. return
  143. }
  144. //获取权限ID与名称的map映射
  145. permissionList, e := models.GetChartPermissionList()
  146. if e != nil && e.Error() != utils.ErrNoRow() {
  147. err = errors.New("GetChartPermissionList Err: " + e.Error())
  148. return
  149. }
  150. mapChartPermission := make(map[int]string)
  151. for _, v := range permissionList {
  152. mapChartPermission[v.ChartPermissionId] = v.PermissionName
  153. }
  154. companyId := detail.CompanyId
  155. //如果不是续约合同就不做对比处理
  156. pars = make([]interface{}, 0)
  157. condition = " AND company_contract_id != ? AND company_id = ? "
  158. pars = append(pars, companyContractId, companyId)
  159. //获取历史签约信息
  160. companyContractPermissionListHistory, e := company_contract.GetCompanyContractPermissionList(condition, pars)
  161. if e != nil && e.Error() != utils.ErrNoRow() {
  162. err = errors.New("companyContractPermissionListHistory Err: " + e.Error())
  163. return
  164. }
  165. var mapHistoryPerssionName []string
  166. for _, v := range companyContractPermissionListHistory {
  167. mapHistoryPerssionName = append(mapHistoryPerssionName, mapChartPermission[v.ChartPermissionId])
  168. }
  169. pars = make([]interface{}, 0)
  170. condition = " AND company_contract_id = ? "
  171. pars = append(pars, companyContractId)
  172. //获取当前签约的合同信息
  173. companyContractPermissionLisThis, e := company_contract.GetCompanyContractPermissionList(condition, pars)
  174. if e != nil && e.Error() != utils.ErrNoRow() {
  175. err = errors.New("companyContractPermissionLisThis Err: " + e.Error())
  176. return
  177. }
  178. var items []*company_contract.CompanyContractPermission
  179. for _, v := range companyContractPermissionLisThis {
  180. v.PermissionName = mapChartPermission[v.ChartPermissionId]
  181. if v.PermissionName == "" {
  182. continue
  183. }
  184. //已经存在的属于行业续约、不存在的属于行业新签
  185. if utils.InArrayByStr(mapHistoryPerssionName, v.PermissionName) {
  186. v.ContractType = "行业续约"
  187. } else {
  188. v.ContractType = "行业新签"
  189. }
  190. items = append(items, v)
  191. }
  192. //批量更新合同权限表的权限行业名称,以及签约合同时,当前行业类型(行业续约、行业新签)
  193. e = company_contract.UpdateCompanyContractPermissionMulti(items)
  194. if e != nil {
  195. err = errors.New("UpdateCompanyContractPermissionMulti Err: " + e.Error())
  196. return
  197. }
  198. return
  199. }