company_permission.go 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "hongze/hz_crm_api/models"
  6. "hongze/hz_crm_api/models/company"
  7. "hongze/hz_crm_api/services"
  8. "hongze/hz_crm_api/utils"
  9. "strconv"
  10. "strings"
  11. "time"
  12. )
  13. // 客户权限管理
  14. type CompanyPermissionController struct {
  15. BaseAuthController
  16. }
  17. // List
  18. // @Title 获取权限设置基础信息
  19. // @Description 获取权限设置基础信息接口
  20. // @Param CompanyType query string true "客户类型:传空字符串或者不传为全部,'ficc','权益'"
  21. // @Param CompanyStatus query string true "客户状态"
  22. // @Param NoUpgrade query bool false "是否不展示升级权限,默认为 false"
  23. // @Param IsShowYanXuanKouDian query bool false "是否展示研选扣点包,默认为 false"
  24. // @Success 200 {object} company.PermissionSetResp
  25. // @router /permission/list [get]
  26. func (this *CompanyPermissionController) List() {
  27. br := new(models.BaseResponse).Init()
  28. defer func() {
  29. this.Data["json"] = br
  30. this.ServeJSON()
  31. }()
  32. sysUser := this.SysUser
  33. if sysUser == nil {
  34. br.Msg = "请登录"
  35. br.ErrMsg = "请登录,SysUser Is Empty"
  36. br.Ret = 408
  37. return
  38. }
  39. // Tips:目前这个接口权益在添加客户、申请转正、领取客户、续约申请均有用到
  40. companyType := this.GetString("CompanyType")
  41. noUpgrade, _ := this.GetBool("NoUpgrade", false) // 添加客户、领取客户=true; 申请转正、续约申请=false
  42. isShowYanXuanKouDian, _ := this.GetBool("IsShowYanXuanKouDian", false) // 是否展示研选扣点
  43. companyStatus := this.GetString("CompanyStatus") // 客户状态
  44. if strings.Contains(companyStatus, utils.COMPANY_STATUS_X_CLASS_TRY_OUT) || strings.Contains(companyStatus, utils.COMPANY_STATUS_FOREVER) {
  45. companyStatus = utils.COMPANY_STATUS_FOREVER
  46. }
  47. var productId int
  48. resp := new(company.PermissionSetResp)
  49. roleTypeCode := sysUser.RoleTypeCode
  50. productId = services.GetProductId(roleTypeCode)
  51. // FICC
  52. if productId == utils.COMPANY_PRODUCT_FICC_ID || companyType == utils.COMPANY_PRODUCT_FICC_NAME {
  53. items, err := company.GetPermissionByProductId(utils.COMPANY_PRODUCT_FICC_ID)
  54. if err != nil {
  55. br.Msg = "获取失败"
  56. br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  57. return
  58. }
  59. permissionMap := make(map[int][]*company.PermissionSetItem, 0)
  60. permissionCheckMap := make(map[int][]int, 0)
  61. for _, v := range items {
  62. if v.ParentId > 0 {
  63. permissionMap[v.ParentId] = append(permissionMap[v.ParentId], v)
  64. if v.IsPublic == 1 {
  65. permissionCheckMap[v.ParentId] = append(permissionCheckMap[v.ParentId], v.ChartPermissionId)
  66. }
  67. }
  68. }
  69. for _, v := range items {
  70. if v.ParentId == 0 {
  71. p := new(company.PermissionSetList)
  72. p.Items = make([]*company.PermissionSetItem, 0)
  73. p.CheckList = make([]int, 0)
  74. p.ClassifyName = v.PermissionName
  75. if subList, ok := permissionMap[v.ChartPermissionId]; ok {
  76. p.Items = subList
  77. }
  78. if checkList, ok := permissionCheckMap[v.ChartPermissionId]; ok {
  79. p.CheckList = checkList
  80. }
  81. resp.List = append(resp.List, p)
  82. }
  83. }
  84. br.Ret = 200
  85. br.Success = true
  86. br.Msg = "获取成功"
  87. br.Data = resp
  88. return
  89. }
  90. // 权益
  91. if productId == utils.COMPANY_PRODUCT_RAI_ID || companyType == utils.COMPANY_PRODUCT_RAI_NAME {
  92. p := new(company.PermissionSetList)
  93. items, err := company.GetPermissionSetItemsByType(utils.COMPANY_PRODUCT_RAI_ID, utils.COMPANY_PRODUCT_RAI_NAME)
  94. if err != nil {
  95. br.Msg = "获取失败"
  96. br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  97. return
  98. }
  99. filterPermissionName := []string{"专家", "路演服务", "调研"} // 需要过滤不展示的行业
  100. if isShowYanXuanKouDian {
  101. filterPermissionName = []string{"专家"} //申请转正,或者申请续约的时候 调研 行业需要进行展示
  102. }
  103. // 原始版的权限
  104. if noUpgrade {
  105. for _, v := range items {
  106. if !isShowYanXuanKouDian && v.ChartPermissionId == utils.YAN_XUAN_KOU_DIAN_BAO_ID {
  107. continue
  108. }
  109. if utils.InArrayByStr(filterPermissionName, v.PermissionName) {
  110. continue
  111. }
  112. p.Items = append(p.Items, v)
  113. }
  114. }
  115. // 展示升级权限, 需要有套餐的展示, 行业可能需要拆分主客观, 买方研选需要分为3w和5w两种
  116. if !noUpgrade {
  117. //判断是不是永续类型的客户
  118. if companyStatus == utils.COMPANY_STATUS_FOREVER {
  119. filterPermissionName = []string{"专家", "路演服务", "调研", "研选订阅", "研选扣点包"} //权益的永续客户这些不展示
  120. for _, v := range items {
  121. if utils.InArrayByStr(filterPermissionName, v.PermissionName) {
  122. continue
  123. }
  124. p.Items = append(p.Items, v)
  125. }
  126. } else {
  127. p.Items = append(p.Items, &company.PermissionSetItem{
  128. PermissionName: utils.CHART_PERMISSION_NAME_45W,
  129. }, &company.PermissionSetItem{
  130. PermissionName: utils.CHART_PERMISSION_NAME_70W,
  131. })
  132. // 是否为内部人员
  133. isRai, e := services.CheckRaiAdmin(sysUser.AdminId)
  134. if e != nil {
  135. br.Msg = "获取失败"
  136. br.ErrMsg = "判断是否为权益内部人员失败, GetRaiAdmin Err: " + e.Error()
  137. return
  138. }
  139. // 获取行业主客观权限ID
  140. childSubMap, childObjMap := make(map[string]int), make(map[string]int)
  141. {
  142. permissions, e := models.GetChartPermissionList()
  143. if e != nil {
  144. br.Msg = "获取失败"
  145. br.ErrMsg = "获取权限列表失败, GetChartPermissionList Err: " + e.Error()
  146. return
  147. }
  148. for _, v := range permissions {
  149. if !strings.Contains("医药消费科技智造", v.PermissionName) {
  150. continue
  151. }
  152. if strings.Contains(v.Remark, "主观") {
  153. childSubMap[v.PermissionName] = v.ChartPermissionId
  154. continue
  155. }
  156. childObjMap[v.PermissionName] = v.ChartPermissionId
  157. }
  158. }
  159. for _, v := range items {
  160. if !isShowYanXuanKouDian && v.ChartPermissionId == utils.YAN_XUAN_KOU_DIAN_BAO_ID {
  161. continue
  162. }
  163. if utils.InArrayByStr(filterPermissionName, v.PermissionName) {
  164. continue
  165. }
  166. // 处理四大行业的升级展示
  167. if strings.Contains("医药消费科技智造", v.PermissionName) {
  168. // 内部人员需要拆分主客观权限
  169. if isRai {
  170. v.Child = make([]*company.PermissionSetItem, 0)
  171. v.Child = append(v.Child, &company.PermissionSetItem{
  172. ChartPermissionId: childSubMap[v.PermissionName],
  173. PermissionName: "主观",
  174. PermissionType: 1,
  175. }, &company.PermissionSetItem{
  176. ChartPermissionId: childObjMap[v.PermissionName],
  177. PermissionName: "客观",
  178. PermissionType: 2,
  179. })
  180. }
  181. p.Items = append(p.Items, v)
  182. t := new(company.PermissionSetItem)
  183. t.ChartPermissionId = v.ChartPermissionId + utils.PERMISSION_ID_UPGRADE
  184. t.PermissionName = v.PermissionName + "(升级)"
  185. t.PermissionType = v.PermissionType
  186. t.Checked = v.Checked
  187. p.Items = append(p.Items, t)
  188. continue
  189. }
  190. // 买方研选划分为3w和5w,10W三种
  191. //if v.PermissionName == utils.CHART_PERMISSION_NAME_MF_YANXUAN {
  192. // m3, m5, m10 := new(company.PermissionSetItem), new(company.PermissionSetItem), new(company.PermissionSetItem)
  193. // m3.ChartPermissionId = v.ChartPermissionId
  194. // m3.PermissionName = fmt.Sprint(v.PermissionName, "(3w)")
  195. // p.Items = append(p.Items, m3)
  196. //
  197. // m5.ChartPermissionId = v.ChartPermissionId + utils.PERMISSION_ID_YANXUAN_DIFF
  198. // m5.PermissionName = fmt.Sprint(v.PermissionName, "(5w)")
  199. // p.Items = append(p.Items, m5)
  200. //
  201. // m10.ChartPermissionId = utils.PERMISSION_ID_YANXUAN_10W_DIFF
  202. // m10.PermissionName = fmt.Sprint(v.PermissionName, "(10w)")
  203. // p.Items = append(p.Items, m10)
  204. // continue
  205. //}
  206. p.Items = append(p.Items, v)
  207. }
  208. }
  209. }
  210. p.ClassifyName = utils.COMPANY_PRODUCT_RAI_NAME
  211. p.CheckList = make([]int, 0)
  212. resp.List = append(resp.List, p)
  213. }
  214. br.Ret = 200
  215. br.Success = true
  216. br.Msg = "获取成功"
  217. br.Data = resp
  218. }
  219. // @Title 获取合同列表的权限设置基础信息
  220. // @Description 获取权限设置基础信息接口
  221. // @Param CompanyType query string true "客户类型:传空字符串或者不传为全部,'ficc','权益'"
  222. // @Success 200 {object} company.PermissionSetResp
  223. // @router /contract_permission/list [get]
  224. func (this *CompanyPermissionController) ListByContract() {
  225. br := new(models.BaseResponse).Init()
  226. defer func() {
  227. this.Data["json"] = br
  228. this.ServeJSON()
  229. }()
  230. sysUser := this.SysUser
  231. if sysUser == nil {
  232. br.Msg = "请登录"
  233. br.ErrMsg = "请登录,SysUser Is Empty"
  234. br.Ret = 408
  235. return
  236. }
  237. companyType := this.GetString("CompanyType")
  238. var productId int
  239. resp := new(company.PermissionSetResp)
  240. roleTypeCode := sysUser.RoleTypeCode
  241. productId = services.GetProductId(roleTypeCode)
  242. if productId == 1 || companyType == utils.COMPANY_PRODUCT_FICC_NAME {
  243. allFiccPermissions, err := company.GetPermissionByProductId(utils.COMPANY_PRODUCT_FICC_ID)
  244. if err != nil {
  245. br.Msg = "获取失败"
  246. br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  247. return
  248. }
  249. permissionMap := make(map[int][]*company.PermissionSetItem, 0)
  250. permissionCheckMap := make(map[int][]int, 0)
  251. for _, v := range allFiccPermissions {
  252. if v.ParentId > 0 {
  253. permissionMap[v.ParentId] = append(permissionMap[v.ParentId], v)
  254. if v.IsPublic == 1 {
  255. permissionCheckMap[v.ParentId] = append(permissionCheckMap[v.ParentId], v.ChartPermissionId)
  256. }
  257. }
  258. }
  259. for _, v := range allFiccPermissions {
  260. if v.ParentId == 0 {
  261. //合同这边市场策略不需要体现出来,所以调整返回
  262. if v.PermissionName == "市场策略" {
  263. continue
  264. }
  265. if v.PermissionName == "固定收益" {
  266. continue
  267. }
  268. p := new(company.PermissionSetList)
  269. p.Items = make([]*company.PermissionSetItem, 0)
  270. p.CheckList = make([]int, 0)
  271. p.ClassifyName = v.PermissionName
  272. if subList, ok := permissionMap[v.ChartPermissionId]; ok {
  273. p.Items = subList
  274. }
  275. if checkList, ok := permissionCheckMap[v.ChartPermissionId]; ok {
  276. p.CheckList = checkList
  277. }
  278. resp.List = append(resp.List, p)
  279. }
  280. }
  281. } else if productId == 2 {
  282. checkList := make([]int, 0)
  283. v := "权益"
  284. p := new(company.PermissionSetList)
  285. p.ClassifyName = v
  286. items, err := company.GetPermissionSetItems(productId, v)
  287. if err != nil {
  288. br.Msg = "获取失败"
  289. br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  290. return
  291. }
  292. p.Items = items
  293. p.CheckList = checkList
  294. resp.List = append(resp.List, p)
  295. } else {
  296. if companyType != utils.COMPANY_PRODUCT_FICC_NAME {
  297. v := "权益"
  298. checkList := make([]int, 0)
  299. p := new(company.PermissionSetList)
  300. p.ClassifyName = v
  301. items, err := company.GetPermissionSetItems(2, v)
  302. if err != nil {
  303. br.Msg = "获取失败"
  304. br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  305. return
  306. }
  307. p.Items = items
  308. p.CheckList = checkList
  309. resp.List = append(resp.List, p)
  310. }
  311. }
  312. br.Ret = 200
  313. br.Success = true
  314. br.Msg = "获取成功"
  315. br.Data = resp
  316. }
  317. // @Title 查看客户权限
  318. // @Description 查看客户权限接口
  319. // @Param CompanyId query int true "客户id"
  320. // @Param LookType query int true "调用类型:1增开试用,0其他"
  321. // @Success 200 {object} company.PermissionLookResp
  322. // @router /permission/look [get]
  323. func (this *CompanyPermissionController) PermissionLook() {
  324. br := new(models.BaseResponse).Init()
  325. defer func() {
  326. this.Data["json"] = br
  327. this.ServeJSON()
  328. }()
  329. sysUser := this.SysUser
  330. if sysUser == nil {
  331. br.Msg = "请登录"
  332. br.ErrMsg = "请登录,SysUser Is Empty"
  333. br.Ret = 408
  334. return
  335. }
  336. roleTypeCode := sysUser.RoleTypeCode
  337. companyId, _ := this.GetInt("CompanyId")
  338. if companyId <= 0 {
  339. br.Msg = "参数错误"
  340. br.ErrMsg = "参数错误,CompanyId 小于等于0 "
  341. return
  342. }
  343. lookType, _ := this.GetInt("LookType")
  344. productId := services.GetProductId(roleTypeCode)
  345. resp := new(company.PermissionLookResp)
  346. permissionArr := make([]*models.ChartPermission, 0)
  347. var err error
  348. if lookType == 1 {
  349. permissionArr, err = services.GetPermissionFirstArr(productId)
  350. } else {
  351. permissionArr, err = services.GetPermissionFirstArr(0)
  352. }
  353. if err != nil {
  354. br.Msg = "获取权限失败"
  355. br.ErrMsg = "获取权限失败 err:" + err.Error()
  356. return
  357. }
  358. //ficc权限类目
  359. for _, v := range permissionArr {
  360. checkList := make([]int, 0)
  361. p := new(company.PermissionLookList)
  362. p.Items = make([]*company.PermissionLookItem, 0)
  363. var productId int
  364. //if v == "权益" {
  365. // productId = 2
  366. //} else {
  367. // productId = 1
  368. //}
  369. if v.PermissionName != "权益" {
  370. productId = 1
  371. //mapPermissionName := make(map[string]int)
  372. items, err := company.GetPermissionLookItemsByParentId(productId, v.ChartPermissionId)
  373. if err != nil {
  374. br.Msg = "获取失败"
  375. br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  376. return
  377. }
  378. itemLen := len(items)
  379. permissionList := make([]*company.PermissionLookItem, 0)
  380. for i := 0; i < itemLen; i++ {
  381. var isAdd bool
  382. item := items[i]
  383. permission, err := company.GetCompanyPermissionCheckItem(companyId, item.ChartPermissionId)
  384. if err != nil && err.Error() != utils.ErrNoRow() {
  385. br.Msg = "获取失败"
  386. br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  387. return
  388. }
  389. if permission != nil && permission.ChartPermissionId > 0 {
  390. items[i].StartDate = permission.StartDate
  391. items[i].EndDate = permission.EndDate
  392. items[i].Status = permission.Status
  393. //判断主观、客观
  394. if items[i].PermissionType == 1 {
  395. items[i].PermissionTypeName = "主观"
  396. } else if items[i].PermissionType == 2 {
  397. items[i].PermissionTypeName = "客观"
  398. }
  399. checkList = append(checkList, item.ChartPermissionId)
  400. isAdd = true
  401. ////如果主观客观 都有,则不显示类型,如果只有一种就显示主观,或者客观
  402. //if mapPermissionName[items[i].PermissionName] == 0 {
  403. // checkList = append(checkList, item.ChartPermissionId)
  404. // mapPermissionName[items[i].PermissionName] = i + 1
  405. //
  406. //} else {
  407. // items[mapPermissionName[items[i].PermissionName]-1].PermissionTypeName = ""
  408. //}
  409. }
  410. endDateTime, _ := time.Parse(utils.FormatDate, item.EndDate)
  411. endDateTime = endDateTime.AddDate(0, 0, 1)
  412. sub := endDateTime.Sub(time.Now())
  413. if sub < 0 {
  414. sub = 0
  415. }
  416. expireDay := fmt.Sprintf("%v", int(sub.Hours()/24))
  417. items[i].ExpireDay = expireDay
  418. items[i].ClassifyName = v.PermissionName
  419. if lookType == 1 {
  420. permissionList = append(permissionList, items[i])
  421. } else {
  422. if isAdd {
  423. permissionList = append(permissionList, items[i])
  424. }
  425. }
  426. }
  427. //合并主观客观
  428. mapPermissionNameList := make(map[string]int)
  429. for _, v := range permissionList {
  430. if mapPermissionNameList[v.PermissionName] == 0 {
  431. p.Items = append(p.Items, v)
  432. mapPermissionNameList[v.PermissionName] = v.ChartPermissionId
  433. }
  434. }
  435. p.ClassifyName = v.PermissionName
  436. //p.Items = permissionList
  437. p.CheckList = checkList
  438. if lookType == 1 {
  439. resp.List = append(resp.List, p)
  440. } else {
  441. if len(checkList) > 0 {
  442. resp.List = append(resp.List, p)
  443. }
  444. }
  445. }
  446. }
  447. var filterPermissionName []string
  448. if lookType == 1 {
  449. filterPermissionName = []string{"专家", "路演服务", "研选扣点包", "调研"}
  450. } else {
  451. filterPermissionName = []string{"调研"}
  452. }
  453. //权益权限类目
  454. for _, v := range permissionArr {
  455. if v.PermissionName == "权益" {
  456. // CRM8.8-权益权限列表调用较多、统一进行调整
  457. unify := false
  458. if lookType == 1 {
  459. unify = true
  460. }
  461. p, e := services.RaiCompanyPermissionAndCheckList(companyId, unify, filterPermissionName)
  462. if e != nil {
  463. br.Msg = "获取客户权益权限列表信息失败"
  464. br.ErrMsg = "获取客户权益权限列表信息失败,Err:" + e.Error()
  465. return
  466. }
  467. if lookType == 1 {
  468. resp.ListRai = append(resp.ListRai, p)
  469. } else {
  470. if len(p.CheckList) > 0 {
  471. resp.ListRai = append(resp.ListRai, p)
  472. }
  473. }
  474. }
  475. }
  476. br.Ret = 200
  477. br.Success = true
  478. br.Msg = "获取成功"
  479. br.Data = resp
  480. }
  481. // @Title 查看客户权限(主观客观)(该接口暂已弃用-2022-0826)
  482. // @Description 查看客户权限接口(主观客观)
  483. // @Param CompanyId query int true "客户id"
  484. // @Param LookType query int true "调用类型:1增开试用,0其他"
  485. // @Success 200 {object} company.PermissionLookSandoResp
  486. // @router /permission/lookSando [get]
  487. func (this *CompanyPermissionController) PermissionLookSando() {
  488. br := new(models.BaseResponse).Init()
  489. defer func() {
  490. this.Data["json"] = br
  491. this.ServeJSON()
  492. }()
  493. sysUser := this.SysUser
  494. if sysUser == nil {
  495. br.Msg = "请登录"
  496. br.ErrMsg = "请登录,SysUser Is Empty"
  497. br.Ret = 408
  498. return
  499. }
  500. roleTypeCode := sysUser.RoleTypeCode
  501. companyId, _ := this.GetInt("CompanyId")
  502. if companyId <= 0 {
  503. br.Msg = "参数错误"
  504. br.ErrMsg = "参数错误,CompanyId 小于等于0 "
  505. return
  506. }
  507. lookType, _ := this.GetInt("LookType")
  508. productId := services.GetProductId(roleTypeCode)
  509. resp := new(company.PermissionLookSandoResp)
  510. permissionArr := []string{}
  511. if lookType == 1 {
  512. if productId == 1 {
  513. for _, permission := range utils.PermissionFiccClassifyArr {
  514. permissionArr = append(permissionArr, permission)
  515. }
  516. } else if productId == 2 {
  517. permissionArr = []string{"权益"}
  518. } else {
  519. for _, permission := range utils.PermissionAllClassifyArr {
  520. permissionArr = append(permissionArr, permission)
  521. }
  522. }
  523. } else {
  524. for _, permission := range utils.PermissionAllClassifyArr {
  525. permissionArr = append(permissionArr, permission)
  526. }
  527. }
  528. //ficc权限类目
  529. if productId == 1 {
  530. for _, v := range permissionArr {
  531. checkList := make([]int, 0)
  532. p := new(company.PermissionLookList)
  533. var productId int
  534. productId = 1
  535. items, err := company.GetPermissionLookItems(productId, v)
  536. if err != nil {
  537. br.Msg = "获取失败"
  538. br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  539. return
  540. }
  541. itemLen := len(items)
  542. permissionList := make([]*company.PermissionLookItem, 0)
  543. for i := 0; i < itemLen; i++ {
  544. var isAdd bool
  545. item := items[i]
  546. permission, err := company.GetCompanyPermissionCheckItem(companyId, item.ChartPermissionId)
  547. if err != nil && err.Error() != utils.ErrNoRow() {
  548. br.Msg = "获取失败"
  549. br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  550. return
  551. }
  552. if permission != nil && permission.ChartPermissionId > 0 {
  553. checkList = append(checkList, item.ChartPermissionId)
  554. items[i].StartDate = permission.StartDate
  555. items[i].EndDate = permission.EndDate
  556. items[i].Status = permission.Status
  557. isAdd = true
  558. }
  559. endDateTime, _ := time.Parse(utils.FormatDate, item.EndDate)
  560. endDateTime = endDateTime.AddDate(0, 0, 1)
  561. sub := endDateTime.Sub(time.Now())
  562. if sub < 0 {
  563. sub = 0
  564. }
  565. expireDay := fmt.Sprintf("%v", int(sub.Hours()/24))
  566. items[i].ExpireDay = expireDay
  567. items[i].ClassifyName = v
  568. if lookType == 1 {
  569. permissionList = append(permissionList, items[i])
  570. } else {
  571. if isAdd {
  572. permissionList = append(permissionList, items[i])
  573. }
  574. }
  575. }
  576. p.ClassifyName = v
  577. p.Items = permissionList
  578. p.CheckList = checkList
  579. if lookType == 1 {
  580. resp.List = append(resp.List, p)
  581. } else {
  582. if len(checkList) > 0 {
  583. resp.List = append(resp.List, p)
  584. }
  585. }
  586. }
  587. }
  588. //权益权限类目
  589. for _, v := range permissionArr {
  590. productId = 2
  591. if v == "权益" {
  592. v := "权益"
  593. checkList := make([]int, 0)
  594. p := new(company.PermissionLookList)
  595. pListType := new(company.PermissionSetListType)
  596. p.ClassifyName = v
  597. pListType.ClassifyName = v
  598. items, err := company.GetPermissionSetSandoItems(2, v)
  599. if err != nil {
  600. br.Msg = "获取失败"
  601. br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  602. return
  603. }
  604. itemLen := len(items)
  605. //permissionList := make([]*company.PermissionLookItem, 0)
  606. for i := 0; i < itemLen; i++ {
  607. //var isAdd bool
  608. item := items[i]
  609. permission, err := company.GetCompanyPermissionCheckItem(companyId, item.ChartPermissionId)
  610. if err != nil && err.Error() != utils.ErrNoRow() {
  611. br.Msg = "获取失败"
  612. br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  613. return
  614. }
  615. if permission != nil && permission.ChartPermissionId > 0 {
  616. checkList = append(checkList, item.ChartPermissionId)
  617. items[i].StartDate = permission.StartDate
  618. items[i].EndDate = permission.EndDate
  619. items[i].Status = permission.Status
  620. items[i].Checked = true
  621. }
  622. if items[i].PermissionType == 1 {
  623. items[i].PermissionTypeName = "主观"
  624. } else if items[i].PermissionType == 2 {
  625. items[i].PermissionTypeName = "客观"
  626. }
  627. endDateTime, _ := time.Parse(utils.FormatDate, item.EndDate)
  628. endDateTime = endDateTime.AddDate(0, 0, 1)
  629. sub := endDateTime.Sub(time.Now())
  630. if sub < 0 {
  631. sub = 0
  632. }
  633. expireDay := fmt.Sprintf("%v", int(sub.Hours()/24))
  634. items[i].ExpireDay = expireDay
  635. items[i].ClassifyName = v
  636. }
  637. //itemsType, err := company.GetPermissionSetItemsType(2, v)
  638. //if err != nil {
  639. // br.Msg = "获取失败"
  640. // br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  641. // return
  642. //}
  643. //mapChartPermission := make(map[string]int)
  644. //pType := new(company.PermissionSetItemType)
  645. //for i, val := range itemsType {
  646. // if mapChartPermission[val.PermissionName] == 0 {
  647. // mapChartPermission[val.PermissionName] = val.ChartPermissionId
  648. // pType = new(company.PermissionSetItemType)
  649. // pType.PermissionName = val.PermissionName
  650. // }
  651. // pType.Items = append(pType.Items, val)
  652. //
  653. // item := itemsType[i]
  654. // permission, err := company.GetCompanyPermissionCheckItem(companyId, item.ChartPermissionId)
  655. // if err != nil && err.Error() != utils.ErrNoRow() {
  656. // br.Msg = "获取失败"
  657. // br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  658. // return
  659. // }
  660. // if permission != nil && permission.ChartPermissionId > 0 {
  661. // checkList = append(checkList, item.ChartPermissionId)
  662. // itemsType[i].StartDate = permission.StartDate
  663. // itemsType[i].EndDate = permission.EndDate
  664. // itemsType[i].Status = permission.Status
  665. // itemsType[i].Checked = true
  666. // endDateTime, _ := time.Parse(utils.FormatDate, item.EndDate)
  667. // endDateTime = endDateTime.AddDate(0, 0, 1)
  668. // sub := endDateTime.Sub(time.Now())
  669. // if sub < 0 {
  670. // sub = 0
  671. // }
  672. // expireDay := fmt.Sprintf("%v", int(sub.Hours()/24))
  673. // itemsType[i].ExpireDay = expireDay
  674. // }
  675. // //判断主观、客观
  676. // if itemsType[i].PermissionType == 1 {
  677. // itemsType[i].PermissionTypeName = "主观"
  678. // } else if itemsType[i].PermissionType == 2 {
  679. // itemsType[i].PermissionTypeName = "客观"
  680. // }
  681. // itemsType[i].ClassifyName = v
  682. // //处理权限分类是否打钩
  683. // //if len(pType.Items) == 2 {
  684. // // var checkedMinateBool bool
  685. // // pType.Checked = true
  686. // // for _, pv := range pType.Items {
  687. // // if pv.Checked == false {
  688. // // pType.Checked = false
  689. // // } else {
  690. // // checkedMinateBool = true
  691. // // pType.NoClicking = true
  692. // // }
  693. // // }
  694. // // if checkedMinateBool == true && pType.Checked == false {
  695. // // pType.CheckedMinate = true
  696. // // }
  697. // // pListType.Items = append(pListType.Items, pType)
  698. // //}
  699. //}
  700. //合并主观客观
  701. mapPermissionName := make(map[string]int)
  702. for _, v := range items {
  703. if mapPermissionName[v.PermissionName] == 0 {
  704. p.Items = append(p.Items, v)
  705. mapPermissionName[v.PermissionName] = v.ChartPermissionId
  706. }
  707. }
  708. p.CheckList = checkList
  709. pListType.CheckList = checkList
  710. resp.List = append(resp.List, p)
  711. //resp.ListType = append(resp.ListType, pListType)
  712. }
  713. }
  714. br.Ret = 200
  715. br.Success = true
  716. br.Msg = "获取成功"
  717. br.Data = resp
  718. }
  719. // @Title 品种
  720. // @Description 品种接口
  721. // @Param CompanyType query string true "客户类型:传空字符串或者不传为全部,'ficc','权益'"
  722. // @Success 200 {object} company.PermissionVarietyResp
  723. // @router /permission/variety [get]
  724. func (this *CompanyPermissionController) PermissionVariety() {
  725. br := new(models.BaseResponse).Init()
  726. defer func() {
  727. this.Data["json"] = br
  728. this.ServeJSON()
  729. }()
  730. sysUser := this.SysUser
  731. if sysUser == nil {
  732. br.Msg = "请登录"
  733. br.ErrMsg = "请登录,SysUser Is Empty"
  734. br.Ret = 408
  735. return
  736. }
  737. companyType := this.GetString("CompanyType")
  738. var productId int
  739. resp := new(company.PermissionVarietyResp)
  740. roleTypeCode := sysUser.RoleTypeCode
  741. if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER || roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  742. productId = 2
  743. } else if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER || roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN {
  744. productId = 1
  745. } else {
  746. productId = 0
  747. }
  748. if productId == 1 || companyType == utils.COMPANY_PRODUCT_FICC_NAME {
  749. permissionFirst, e := services.GetPermissionFirstArr(utils.COMPANY_PRODUCT_FICC_ID)
  750. if e != nil {
  751. br.Msg = "获取权限信息失败"
  752. br.ErrMsg = "获取权限信息失败,Err:" + e.Error()
  753. return
  754. }
  755. allFiccPermissions, e := company.GetPermissionVarietyItemsByProductId(utils.COMPANY_PRODUCT_FICC_ID)
  756. if e != nil {
  757. br.Msg = "获取权限信息失败"
  758. br.ErrMsg = "获取权限信息失败,Err:" + e.Error()
  759. return
  760. }
  761. permissionMap := make(map[int][]*company.PermissionVarietyItem, 0)
  762. for _, v := range allFiccPermissions {
  763. permissionMap[v.ParentId] = append(permissionMap[v.ParentId], v)
  764. }
  765. for _, v := range permissionFirst {
  766. p := new(company.PermissionVarietyList)
  767. p.ClassifyName = v.ClassifyName
  768. p.ChartPermissionId = v.ChartPermissionId + 100
  769. items, ok := permissionMap[v.ChartPermissionId]
  770. if ok {
  771. p.Items = items
  772. }
  773. resp.List = append(resp.List, p)
  774. }
  775. /*for k, v := range utils.PermissionFiccClassifyArr {
  776. p := new(company.PermissionVarietyList)
  777. p.ClassifyName = v
  778. p.ChartPermissionId = k + 100
  779. items, err := company.GetPermissionVarietyItems(productId, v)
  780. if err != nil {
  781. br.Msg = "获取失败"
  782. br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  783. return
  784. }
  785. p.Items = items
  786. resp.List = append(resp.List, p)
  787. }*/
  788. } else if productId == 2 {
  789. v := "权益"
  790. p := new(company.PermissionVarietyList)
  791. p.ClassifyName = v
  792. p.ChartPermissionId = 105
  793. items, err := company.GetPermissionVarietyItems(productId, v)
  794. if err != nil {
  795. br.Msg = "获取失败"
  796. br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  797. return
  798. }
  799. p.Items = items
  800. resp.List = append(resp.List, p)
  801. } else {
  802. if companyType == utils.COMPANY_PRODUCT_RAI_NAME {
  803. v := "权益"
  804. p := new(company.PermissionVarietyList)
  805. p.ClassifyName = v
  806. p.ChartPermissionId = 105
  807. items, err := company.GetPermissionVarietyItems(2, v)
  808. if err != nil {
  809. br.Msg = "获取失败"
  810. br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  811. return
  812. }
  813. p.Items = items
  814. resp.List = append(resp.List, p)
  815. }
  816. }
  817. br.Ret = 200
  818. br.Success = true
  819. br.Msg = "获取成功"
  820. br.Data = resp
  821. }
  822. // @Title 新增试用权限
  823. // @Description 新增试用权限
  824. // @Param request body company.PermissionAddTryOutReq true "type json string"
  825. // @Success Ret=200
  826. // @router /permission/add/try/out [post]
  827. func (this *CompanyPermissionController) PermissionAddTryOut() {
  828. br := new(models.BaseResponse).Init()
  829. defer func() {
  830. this.Data["json"] = br
  831. this.ServeJSON()
  832. }()
  833. sysUser := this.SysUser
  834. if sysUser == nil {
  835. br.Msg = "请登录"
  836. br.ErrMsg = "请登录,SysUser Is Empty"
  837. br.Ret = 408
  838. return
  839. }
  840. var req company.PermissionAddTryOutReq
  841. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  842. if err != nil {
  843. br.Msg = "参数解析异常!"
  844. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  845. return
  846. }
  847. if req.ChartPermissionId == "" {
  848. br.Msg = "请选择权限"
  849. br.ErrMsg = "请选择权限"
  850. return
  851. } else {
  852. // CRM8.8-取消增开试用这里的主客观默认同时开启
  853. //permissionStr, err := company.GetPermissionIdById(req.ChartPermissionId)
  854. //if err != nil {
  855. // br.Msg = "获取信息失败"
  856. // br.ErrMsg = "获取主观客观权限信息失败,Err:" + err.Error()
  857. // return
  858. //}
  859. //req.ChartPermissionId = permissionStr
  860. }
  861. if req.CompanyId <= 0 {
  862. br.Msg = "参数错误"
  863. return
  864. }
  865. roleTypeCode := sysUser.RoleTypeCode
  866. product := services.GetProductId(roleTypeCode)
  867. if product == 0 {
  868. br.Msg = "无权新开试用权限"
  869. br.ErrMsg = "无权新开试用权限"
  870. return
  871. }
  872. companyProduct, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, product)
  873. if err != nil {
  874. br.Msg = "新增试用权限失败"
  875. br.ErrMsg = "新增试用权限失败,Err:" + err.Error()
  876. return
  877. }
  878. if companyProduct.Status != utils.COMPANY_STATUS_FORMAL {
  879. br.Msg = "客户状态为:" + companyProduct.Status + ",不可增开试用权限"
  880. br.ErrMsg = "客户状态为:" + companyProduct.Status + ",不可增开试用权限"
  881. return
  882. }
  883. permissionArr := strings.Split(req.ChartPermissionId, ",")
  884. //增开试用修改对应更新时间,上海策略平台,同步客户信息试用
  885. err = company.UpdateCompanyProductModifyTime(req.CompanyId, product)
  886. if err != nil {
  887. br.Msg = "新增试用权限失败"
  888. br.ErrMsg = "新增更新更改时间失败,Err:" + err.Error()
  889. return
  890. }
  891. companyReportPermissionList := make([]*company.CompanyReportPermission, 0) //添加的品种
  892. startDateTime := time.Now()
  893. endDateTime := startDateTime.AddDate(0, 2, 0)
  894. if product == utils.COMPANY_PRODUCT_RAI_ID { // 权益客户试用期改为1个月。 需求池 1035
  895. endDateTime = startDateTime.AddDate(0, 1, 0)
  896. }
  897. for _, v := range permissionArr {
  898. permissionId, _ := strconv.Atoi(v)
  899. count, err := company.GetCompanyPermissionCheck(req.CompanyId, permissionId)
  900. if err != nil {
  901. br.Msg = "新增试用权限失败"
  902. br.ErrMsg = "判断权限是否存在失败,Err:" + err.Error()
  903. return
  904. }
  905. fmt.Println(permissionId)
  906. fmt.Println(count)
  907. if count <= 0 {
  908. item := new(company.CompanyReportPermission)
  909. startDate := startDateTime.Format(utils.FormatDate)
  910. endDate := endDateTime.Format(utils.FormatDate)
  911. item.CompanyId = req.CompanyId
  912. item.CreatedTime = time.Now()
  913. item.LastUpdatedTime = time.Now()
  914. item.ChartPermissionId = permissionId
  915. item.StartDate = startDate
  916. item.EndDate = endDate
  917. item.ProductId = product
  918. item.ProductName = companyProduct.ProductName
  919. item.CompanyContractId = 0
  920. item.Status = "试用"
  921. item.ModifyTime = time.Now()
  922. err = company.AddCompanyReportPermission(item)
  923. if err != nil {
  924. br.Msg = "新增试用权限失败"
  925. br.ErrMsg = "新增试用权限失败,Err:" + err.Error()
  926. return
  927. }
  928. companyReportPermissionList = append(companyReportPermissionList, item)
  929. }
  930. }
  931. //新增客户产品状态变更日志
  932. {
  933. companyProductTryOutUpdateLog := &company.CompanyProductTryOutUpdateLog{
  934. Id: 0,
  935. CompanyId: req.CompanyId,
  936. ProductId: companyProduct.ProductId,
  937. Source: "",
  938. SellerId: companyProduct.SellerId,
  939. SellerName: companyProduct.SellerName,
  940. StartDate: startDateTime,
  941. EndDate: endDateTime,
  942. RealEndDate: startDateTime,
  943. IsStop: 0,
  944. CreateTime: time.Now(),
  945. }
  946. go company.AddCompanyProductTryOutUpdateLog(companyProductTryOutUpdateLog, companyReportPermissionList)
  947. }
  948. br.Ret = 200
  949. br.Success = true
  950. br.Msg = "新增试用权限成功"
  951. br.IsAddLog = true
  952. }