company_contract.go 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. package controllers
  2. import (
  3. "fmt"
  4. companyContractResp "hongze/hongze_mobile_admin/models/response/company_contract"
  5. "hongze/hongze_mobile_admin/models/tables/company_contract"
  6. "hongze/hongze_mobile_admin/models/tables/company_product"
  7. "hongze/hongze_mobile_admin/models/tables/company_report_permission"
  8. "hongze/hongze_mobile_admin/services"
  9. "hongze/hongze_mobile_admin/services/contract"
  10. "hongze/hongze_mobile_admin/utils"
  11. "strings"
  12. )
  13. // 客户合同模块
  14. type CompanyContractCommon struct {
  15. BaseAuth
  16. }
  17. // @Title 合同详情详情
  18. // @Description 合同详情接口
  19. // @Param CompanyId query int true "客户ID"
  20. // @Param CompanyContractId query int true "合同id"
  21. // @Success 200 {object} company_contract.CompanyContractDetailResp
  22. // @router /detail [get]
  23. func (c *CompanyContractCommon) ApplyContractDetail() {
  24. sysUser := c.AdminWx
  25. companyId, _ := c.GetInt("CompanyId")
  26. if companyId <= 0 {
  27. c.FailWithMessage("参数错误", "参数错误,客户id小于等于0")
  28. return
  29. }
  30. companyContractId, _ := c.GetInt("CompanyContractId")
  31. roleTypeCode := sysUser.RoleTypeCode
  32. productId := services.GetProductId(roleTypeCode)
  33. //if productId == 0 {
  34. // c.FailWithMessage("当前账户类型异常", "客户类型为:"+roleTypeCode)
  35. // return
  36. //}
  37. detail, err := company_contract.GetCompanyContractDetail(companyId, productId, companyContractId)
  38. if err != nil {
  39. c.FailWithMessage("获取信息失败", "获取信息失败,Err:"+err.Error())
  40. return
  41. }
  42. if detail.ProductId == utils.COMPANY_PRODUCT_FICC_ID {
  43. allFiccPermissions, e := company_report_permission.GetPermissionLookItemsByProductId(utils.COMPANY_PRODUCT_FICC_ID)
  44. if e != nil {
  45. c.FailWithMessage("获取权限信息失败", "获取权限信息失败,Err:"+err.Error())
  46. return
  47. }
  48. permissionMap := make(map[int][]*company_report_permission.PermissionLookItem, 0)
  49. for _, v := range allFiccPermissions {
  50. if v.ParentId > 0 {
  51. permissionMap[v.ParentId] = append(permissionMap[v.ParentId], v)
  52. }
  53. }
  54. for _, v := range allFiccPermissions {
  55. if v.ParentId == 0 {
  56. plist := new(company_report_permission.PermissionLookList)
  57. plist.Items = make([]*company_report_permission.PermissionLookItem, 0)
  58. plist.CheckList = make([]int, 0)
  59. items, ok := permissionMap[v.ChartPermissionId]
  60. if ok {
  61. plist.Items = items
  62. for _, n := range items {
  63. count, err := company_contract.GetCompanyContractPermissionCheckByContractId(companyId, detail.CompanyContractId, n.ChartPermissionId)
  64. if err != nil {
  65. c.FailWithMessage("获取失败", "获取权限信息失败,Err:"+err.Error())
  66. return
  67. }
  68. if count > 0 {
  69. plist.CheckList = append(plist.CheckList, n.ChartPermissionId)
  70. }
  71. }
  72. }
  73. plist.ClassifyName = v.PermissionName
  74. detail.PermissionList = append(detail.PermissionList, plist)
  75. }
  76. }
  77. /*for _, v := range utils.PermissionFiccClassifyArr {
  78. checkList := make([]int, 0)
  79. plist := new(company_report_permission.PermissionLookList)
  80. items, err := company_report_permission.GetPermissionLookItems(detail.ProductId, v)
  81. if err != nil {
  82. c.FailWithMessage("获取失败", "获取权限信息失败,Err:"+err.Error())
  83. return
  84. }
  85. for _, n := range items {
  86. count, err := company_contract.GetCompanyContractPermissionCheckByContractId(companyId, detail.CompanyContractId, n.ChartPermissionId)
  87. if err != nil {
  88. c.FailWithMessage("获取失败", "获取权限信息失败,Err:"+err.Error())
  89. return
  90. }
  91. if count > 0 {
  92. checkList = append(checkList, n.ChartPermissionId)
  93. }
  94. }
  95. plist.Items = items
  96. plist.ClassifyName = v
  97. plist.CheckList = checkList
  98. detail.PermissionList = append(detail.PermissionList, plist)
  99. }*/
  100. }
  101. if detail.ProductId == utils.COMPANY_PRODUCT_RAI_ID {
  102. classifyName := "权益"
  103. checkList := make([]int, 0)
  104. plist := new(company_report_permission.PermissionLookList)
  105. plist.ClassifyName = classifyName
  106. items, err := company_report_permission.GetPermissionLookItems(detail.ProductId, classifyName)
  107. if err != nil {
  108. c.FailWithMessage("获取失败", "获取权限信息失败,Err:"+err.Error())
  109. return
  110. }
  111. mapExpensive := make(map[int]bool) // 通过合同获取所勾选的买方研选5w
  112. permissionList, err := company_report_permission.GetCompanyContractPermissionByCompanyContractId(companyContractId)
  113. if err != nil && err.Error() != utils.ErrNoRow() {
  114. c.FailWithMessage("获取失败", "获取合同权限信息失败,Err:"+err.Error())
  115. return
  116. }
  117. permissions := make([]int, 0) // 合同权限IDs
  118. checkItems := make([]*company_report_permission.PermissionLookItem, 0)
  119. //expMap := map[bool]string{false: "(3w)", true: "(5w)"} // 买方研选价格
  120. //var expensiveYx int
  121. // 未选大套餐, 走老逻辑
  122. var points float64
  123. if detail.RaiPackageType == 0 {
  124. mapUpgrade := make(map[int]bool) // 通过合同获取所勾选的升级行业权限
  125. totalForever, err := company_product.GetCompanyProductRaiForeverCount(companyId) //判断是否是权益的永续客户
  126. if err != nil {
  127. c.FailWithMessage("获取失败", "判断是否是权益的永续客户失败,Err:"+err.Error())
  128. return
  129. }
  130. if totalForever > 0 {
  131. detail.Quarter, err = utils.GetQuarterStrStartDatesInRange(detail.StartDate, detail.EndDate) //通过开始时间,结束时间,获取对应季度的拼接字符串
  132. if err != nil {
  133. c.FailWithMessage("获取失败", "获取季度息失败,Err:"+err.Error())
  134. return
  135. }
  136. }
  137. for _, v := range permissionList {
  138. if v.IsUpgrade == 1 {
  139. mapUpgrade[v.ChartPermissionId] = true
  140. }
  141. if v.ExpensiveYx > 0 {
  142. mapExpensive[v.ChartPermissionId] = true
  143. //expensiveYx = v.ExpensiveYx
  144. }
  145. if v.Points > 0 && v.ChartPermissionId == utils.YAN_XUAN_KOU_DIAN_BAO_ID {
  146. points = v.Points
  147. }
  148. permissions = append(permissions, v.ChartPermissionId)
  149. }
  150. for _, n := range items {
  151. if points > 0 && n.ChartPermissionId == utils.YAN_XUAN_KOU_DIAN_BAO_ID {
  152. n.PermissionName += fmt.Sprint("(", points, "点)")
  153. }
  154. if utils.InArrayByInt(permissions, n.ChartPermissionId) {
  155. checkList = append(checkList, n.ChartPermissionId)
  156. checkItems = append(checkItems, n)
  157. }
  158. }
  159. plist.Items = checkItems
  160. plist.CheckList = checkList
  161. detail.PermissionList = append(detail.PermissionList, plist)
  162. newPermissionLookList := contract.HandleEquityPermissionLookList(detail.PermissionList)
  163. for _, cc := range newPermissionLookList {
  164. if cc.ClassifyName != "权益" {
  165. continue
  166. }
  167. for _, p := range cc.Items {
  168. // 行业升级
  169. if mapUpgrade[p.ChartPermissionId] {
  170. if strings.Contains(p.PermissionName, "主观") {
  171. p.PermissionName = strings.Replace(p.PermissionName, "主观", "升级", -1)
  172. continue
  173. }
  174. if strings.Contains(p.PermissionName, "客观") {
  175. p.PermissionName = strings.Replace(p.PermissionName, "客观", "升级", -1)
  176. continue
  177. }
  178. p.PermissionName += "(升级)"
  179. continue
  180. }
  181. // 买方研选
  182. //if p.ChartPermissionId == utils.CHART_PERMISSION_ID_YANXUAN {
  183. // if expensiveYx == 1 {
  184. // p.PermissionName += "(5w)"
  185. // } else if expensiveYx == 2 {
  186. // p.PermissionName += "(10w)"
  187. // }
  188. // //p.PermissionName += expMap[mapExpensive[p.ChartPermissionId]]
  189. //}
  190. }
  191. }
  192. detail.PermissionList = newPermissionLookList
  193. }
  194. // 如果选择的是大套餐, 那么不再展示每个具体的权限, 除大套餐外还需遍历一下专家和研选3w/5w是否有选(这两个与大套餐不互斥, 可额外选择)
  195. if detail.RaiPackageType > 0 {
  196. // 大套餐
  197. bigPackage := new(company_report_permission.PermissionLookItem)
  198. if detail.RaiPackageType == 1 {
  199. bigPackage.PermissionName = utils.CHART_PERMISSION_NAME_70W
  200. bigPackage.ChartPermissionId = utils.CHART_PERMISSION_ID_70W
  201. checkList = append(checkList, utils.CHART_PERMISSION_ID_70W)
  202. }
  203. if detail.RaiPackageType == 2 {
  204. bigPackage.PermissionName = utils.CHART_PERMISSION_NAME_45W
  205. bigPackage.ChartPermissionId = utils.CHART_PERMISSION_ID_45W
  206. checkList = append(checkList, utils.CHART_PERMISSION_ID_45W)
  207. }
  208. checkItems = append(checkItems, bigPackage)
  209. for _, v := range permissionList {
  210. if v.ExpensiveYx == 1 {
  211. mapExpensive[v.ChartPermissionId] = true
  212. }
  213. if v.Points > 0 && v.ChartPermissionId == utils.YAN_XUAN_KOU_DIAN_BAO_ID {
  214. points = v.Points
  215. }
  216. permissions = append(permissions, v.ChartPermissionId)
  217. }
  218. // 专家、研选订阅、研选扣点包
  219. for _, n := range items {
  220. if n.ChartPermissionId != utils.ZHUAN_JIA_ID && n.ChartPermissionId != utils.CHART_PERMISSION_ID_YANXUAN && n.ChartPermissionId != utils.YAN_XUAN_KOU_DIAN_BAO_ID {
  221. continue
  222. }
  223. //if n.ChartPermissionId == utils.CHART_PERMISSION_ID_YANXUAN {
  224. // n.PermissionName += expMap[mapExpensive[n.ChartPermissionId]]
  225. //}
  226. if n.ChartPermissionId == utils.YAN_XUAN_KOU_DIAN_BAO_ID {
  227. n.PermissionName += fmt.Sprint("(", points, "点)")
  228. }
  229. if utils.InArrayByInt(permissions, n.ChartPermissionId) {
  230. checkList = append(checkList, n.ChartPermissionId)
  231. checkItems = append(checkItems, n)
  232. }
  233. }
  234. plist.Items = checkItems
  235. plist.CheckList = checkList
  236. detail.PermissionList = append(detail.PermissionList, plist)
  237. }
  238. }
  239. resp := companyContractResp.CompanyContractDetailResp{
  240. detail,
  241. }
  242. c.OkDetailed(resp, "获取成功")
  243. }