company_permission.go 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991
  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. p := new(company.PermissionSetList)
  266. p.Items = make([]*company.PermissionSetItem, 0)
  267. p.CheckList = make([]int, 0)
  268. p.ClassifyName = v.PermissionName
  269. if subList, ok := permissionMap[v.ChartPermissionId]; ok {
  270. p.Items = subList
  271. }
  272. if checkList, ok := permissionCheckMap[v.ChartPermissionId]; ok {
  273. p.CheckList = checkList
  274. }
  275. resp.List = append(resp.List, p)
  276. }
  277. }
  278. } else if productId == 2 {
  279. checkList := make([]int, 0)
  280. v := "权益"
  281. p := new(company.PermissionSetList)
  282. p.ClassifyName = v
  283. items, err := company.GetPermissionSetItems(productId, v)
  284. if err != nil {
  285. br.Msg = "获取失败"
  286. br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  287. return
  288. }
  289. p.Items = items
  290. p.CheckList = checkList
  291. resp.List = append(resp.List, p)
  292. } else {
  293. if companyType != utils.COMPANY_PRODUCT_FICC_NAME {
  294. v := "权益"
  295. checkList := make([]int, 0)
  296. p := new(company.PermissionSetList)
  297. p.ClassifyName = v
  298. items, err := company.GetPermissionSetItems(2, v)
  299. if err != nil {
  300. br.Msg = "获取失败"
  301. br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  302. return
  303. }
  304. p.Items = items
  305. p.CheckList = checkList
  306. resp.List = append(resp.List, p)
  307. }
  308. }
  309. br.Ret = 200
  310. br.Success = true
  311. br.Msg = "获取成功"
  312. br.Data = resp
  313. }
  314. // @Title 查看客户权限
  315. // @Description 查看客户权限接口
  316. // @Param CompanyId query int true "客户id"
  317. // @Param LookType query int true "调用类型:1增开试用,0其他"
  318. // @Success 200 {object} company.PermissionLookResp
  319. // @router /permission/look [get]
  320. func (this *CompanyPermissionController) PermissionLook() {
  321. br := new(models.BaseResponse).Init()
  322. defer func() {
  323. this.Data["json"] = br
  324. this.ServeJSON()
  325. }()
  326. sysUser := this.SysUser
  327. if sysUser == nil {
  328. br.Msg = "请登录"
  329. br.ErrMsg = "请登录,SysUser Is Empty"
  330. br.Ret = 408
  331. return
  332. }
  333. roleTypeCode := sysUser.RoleTypeCode
  334. companyId, _ := this.GetInt("CompanyId")
  335. if companyId <= 0 {
  336. br.Msg = "参数错误"
  337. br.ErrMsg = "参数错误,CompanyId 小于等于0 "
  338. return
  339. }
  340. lookType, _ := this.GetInt("LookType")
  341. productId := services.GetProductId(roleTypeCode)
  342. resp := new(company.PermissionLookResp)
  343. permissionArr := make([]*models.ChartPermission, 0)
  344. var err error
  345. if lookType == 1 {
  346. permissionArr, err = services.GetPermissionFirstArr(productId)
  347. } else {
  348. permissionArr, err = services.GetPermissionFirstArr(0)
  349. }
  350. if err != nil {
  351. br.Msg = "获取权限失败"
  352. br.ErrMsg = "获取权限失败 err:" + err.Error()
  353. return
  354. }
  355. //ficc权限类目
  356. for _, v := range permissionArr {
  357. checkList := make([]int, 0)
  358. p := new(company.PermissionLookList)
  359. p.Items = make([]*company.PermissionLookItem, 0)
  360. var productId int
  361. //if v == "权益" {
  362. // productId = 2
  363. //} else {
  364. // productId = 1
  365. //}
  366. if v.PermissionName != "权益" {
  367. productId = 1
  368. //mapPermissionName := make(map[string]int)
  369. items, err := company.GetPermissionLookItemsByParentId(productId, v.ChartPermissionId)
  370. if err != nil {
  371. br.Msg = "获取失败"
  372. br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  373. return
  374. }
  375. itemLen := len(items)
  376. permissionList := make([]*company.PermissionLookItem, 0)
  377. for i := 0; i < itemLen; i++ {
  378. var isAdd bool
  379. item := items[i]
  380. permission, err := company.GetCompanyPermissionCheckItem(companyId, item.ChartPermissionId)
  381. if err != nil && err.Error() != utils.ErrNoRow() {
  382. br.Msg = "获取失败"
  383. br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  384. return
  385. }
  386. if permission != nil && permission.ChartPermissionId > 0 {
  387. items[i].StartDate = permission.StartDate
  388. items[i].EndDate = permission.EndDate
  389. items[i].Status = permission.Status
  390. //判断主观、客观
  391. if items[i].PermissionType == 1 {
  392. items[i].PermissionTypeName = "主观"
  393. } else if items[i].PermissionType == 2 {
  394. items[i].PermissionTypeName = "客观"
  395. }
  396. checkList = append(checkList, item.ChartPermissionId)
  397. isAdd = true
  398. ////如果主观客观 都有,则不显示类型,如果只有一种就显示主观,或者客观
  399. //if mapPermissionName[items[i].PermissionName] == 0 {
  400. // checkList = append(checkList, item.ChartPermissionId)
  401. // mapPermissionName[items[i].PermissionName] = i + 1
  402. //
  403. //} else {
  404. // items[mapPermissionName[items[i].PermissionName]-1].PermissionTypeName = ""
  405. //}
  406. }
  407. endDateTime, _ := time.Parse(utils.FormatDate, item.EndDate)
  408. endDateTime = endDateTime.AddDate(0, 0, 1)
  409. sub := endDateTime.Sub(time.Now())
  410. if sub < 0 {
  411. sub = 0
  412. }
  413. expireDay := fmt.Sprintf("%v", int(sub.Hours()/24))
  414. items[i].ExpireDay = expireDay
  415. items[i].ClassifyName = v.PermissionName
  416. if lookType == 1 {
  417. permissionList = append(permissionList, items[i])
  418. } else {
  419. if isAdd {
  420. permissionList = append(permissionList, items[i])
  421. }
  422. }
  423. }
  424. //合并主观客观
  425. mapPermissionNameList := make(map[string]int)
  426. for _, v := range permissionList {
  427. if mapPermissionNameList[v.PermissionName] == 0 {
  428. p.Items = append(p.Items, v)
  429. mapPermissionNameList[v.PermissionName] = v.ChartPermissionId
  430. }
  431. }
  432. p.ClassifyName = v.PermissionName
  433. //p.Items = permissionList
  434. p.CheckList = checkList
  435. if lookType == 1 {
  436. resp.List = append(resp.List, p)
  437. } else {
  438. if len(checkList) > 0 {
  439. resp.List = append(resp.List, p)
  440. }
  441. }
  442. }
  443. }
  444. var filterPermissionName []string
  445. if lookType == 1 {
  446. filterPermissionName = []string{"专家", "路演服务", "研选扣点包", "调研"}
  447. } else {
  448. filterPermissionName = []string{"调研"}
  449. }
  450. //权益权限类目
  451. for _, v := range permissionArr {
  452. if v.PermissionName == "权益" {
  453. // CRM8.8-权益权限列表调用较多、统一进行调整
  454. unify := false
  455. if lookType == 1 {
  456. unify = true
  457. }
  458. p, e := services.RaiCompanyPermissionAndCheckList(companyId, unify, filterPermissionName)
  459. if e != nil {
  460. br.Msg = "获取客户权益权限列表信息失败"
  461. br.ErrMsg = "获取客户权益权限列表信息失败,Err:" + e.Error()
  462. return
  463. }
  464. if lookType == 1 {
  465. resp.ListRai = append(resp.ListRai, p)
  466. } else {
  467. if len(p.CheckList) > 0 {
  468. resp.ListRai = append(resp.ListRai, p)
  469. }
  470. }
  471. }
  472. }
  473. br.Ret = 200
  474. br.Success = true
  475. br.Msg = "获取成功"
  476. br.Data = resp
  477. }
  478. // @Title 查看客户权限(主观客观)(该接口暂已弃用-2022-0826)
  479. // @Description 查看客户权限接口(主观客观)
  480. // @Param CompanyId query int true "客户id"
  481. // @Param LookType query int true "调用类型:1增开试用,0其他"
  482. // @Success 200 {object} company.PermissionLookSandoResp
  483. // @router /permission/lookSando [get]
  484. func (this *CompanyPermissionController) PermissionLookSando() {
  485. br := new(models.BaseResponse).Init()
  486. defer func() {
  487. this.Data["json"] = br
  488. this.ServeJSON()
  489. }()
  490. sysUser := this.SysUser
  491. if sysUser == nil {
  492. br.Msg = "请登录"
  493. br.ErrMsg = "请登录,SysUser Is Empty"
  494. br.Ret = 408
  495. return
  496. }
  497. roleTypeCode := sysUser.RoleTypeCode
  498. companyId, _ := this.GetInt("CompanyId")
  499. if companyId <= 0 {
  500. br.Msg = "参数错误"
  501. br.ErrMsg = "参数错误,CompanyId 小于等于0 "
  502. return
  503. }
  504. lookType, _ := this.GetInt("LookType")
  505. productId := services.GetProductId(roleTypeCode)
  506. resp := new(company.PermissionLookSandoResp)
  507. permissionArr := []string{}
  508. if lookType == 1 {
  509. if productId == 1 {
  510. for _, permission := range utils.PermissionFiccClassifyArr {
  511. permissionArr = append(permissionArr, permission)
  512. }
  513. } else if productId == 2 {
  514. permissionArr = []string{"权益"}
  515. } else {
  516. for _, permission := range utils.PermissionAllClassifyArr {
  517. permissionArr = append(permissionArr, permission)
  518. }
  519. }
  520. } else {
  521. for _, permission := range utils.PermissionAllClassifyArr {
  522. permissionArr = append(permissionArr, permission)
  523. }
  524. }
  525. //ficc权限类目
  526. if productId == 1 {
  527. for _, v := range permissionArr {
  528. checkList := make([]int, 0)
  529. p := new(company.PermissionLookList)
  530. var productId int
  531. productId = 1
  532. items, err := company.GetPermissionLookItems(productId, v)
  533. if err != nil {
  534. br.Msg = "获取失败"
  535. br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  536. return
  537. }
  538. itemLen := len(items)
  539. permissionList := make([]*company.PermissionLookItem, 0)
  540. for i := 0; i < itemLen; i++ {
  541. var isAdd bool
  542. item := items[i]
  543. permission, err := company.GetCompanyPermissionCheckItem(companyId, item.ChartPermissionId)
  544. if err != nil && err.Error() != utils.ErrNoRow() {
  545. br.Msg = "获取失败"
  546. br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  547. return
  548. }
  549. if permission != nil && permission.ChartPermissionId > 0 {
  550. checkList = append(checkList, item.ChartPermissionId)
  551. items[i].StartDate = permission.StartDate
  552. items[i].EndDate = permission.EndDate
  553. items[i].Status = permission.Status
  554. isAdd = true
  555. }
  556. endDateTime, _ := time.Parse(utils.FormatDate, item.EndDate)
  557. endDateTime = endDateTime.AddDate(0, 0, 1)
  558. sub := endDateTime.Sub(time.Now())
  559. if sub < 0 {
  560. sub = 0
  561. }
  562. expireDay := fmt.Sprintf("%v", int(sub.Hours()/24))
  563. items[i].ExpireDay = expireDay
  564. items[i].ClassifyName = v
  565. if lookType == 1 {
  566. permissionList = append(permissionList, items[i])
  567. } else {
  568. if isAdd {
  569. permissionList = append(permissionList, items[i])
  570. }
  571. }
  572. }
  573. p.ClassifyName = v
  574. p.Items = permissionList
  575. p.CheckList = checkList
  576. if lookType == 1 {
  577. resp.List = append(resp.List, p)
  578. } else {
  579. if len(checkList) > 0 {
  580. resp.List = append(resp.List, p)
  581. }
  582. }
  583. }
  584. }
  585. //权益权限类目
  586. for _, v := range permissionArr {
  587. productId = 2
  588. if v == "权益" {
  589. v := "权益"
  590. checkList := make([]int, 0)
  591. p := new(company.PermissionLookList)
  592. pListType := new(company.PermissionSetListType)
  593. p.ClassifyName = v
  594. pListType.ClassifyName = v
  595. items, err := company.GetPermissionSetSandoItems(2, v)
  596. if err != nil {
  597. br.Msg = "获取失败"
  598. br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  599. return
  600. }
  601. itemLen := len(items)
  602. //permissionList := make([]*company.PermissionLookItem, 0)
  603. for i := 0; i < itemLen; i++ {
  604. //var isAdd bool
  605. item := items[i]
  606. permission, err := company.GetCompanyPermissionCheckItem(companyId, item.ChartPermissionId)
  607. if err != nil && err.Error() != utils.ErrNoRow() {
  608. br.Msg = "获取失败"
  609. br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  610. return
  611. }
  612. if permission != nil && permission.ChartPermissionId > 0 {
  613. checkList = append(checkList, item.ChartPermissionId)
  614. items[i].StartDate = permission.StartDate
  615. items[i].EndDate = permission.EndDate
  616. items[i].Status = permission.Status
  617. items[i].Checked = true
  618. }
  619. if items[i].PermissionType == 1 {
  620. items[i].PermissionTypeName = "主观"
  621. } else if items[i].PermissionType == 2 {
  622. items[i].PermissionTypeName = "客观"
  623. }
  624. endDateTime, _ := time.Parse(utils.FormatDate, item.EndDate)
  625. endDateTime = endDateTime.AddDate(0, 0, 1)
  626. sub := endDateTime.Sub(time.Now())
  627. if sub < 0 {
  628. sub = 0
  629. }
  630. expireDay := fmt.Sprintf("%v", int(sub.Hours()/24))
  631. items[i].ExpireDay = expireDay
  632. items[i].ClassifyName = v
  633. }
  634. //itemsType, err := company.GetPermissionSetItemsType(2, v)
  635. //if err != nil {
  636. // br.Msg = "获取失败"
  637. // br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  638. // return
  639. //}
  640. //mapChartPermission := make(map[string]int)
  641. //pType := new(company.PermissionSetItemType)
  642. //for i, val := range itemsType {
  643. // if mapChartPermission[val.PermissionName] == 0 {
  644. // mapChartPermission[val.PermissionName] = val.ChartPermissionId
  645. // pType = new(company.PermissionSetItemType)
  646. // pType.PermissionName = val.PermissionName
  647. // }
  648. // pType.Items = append(pType.Items, val)
  649. //
  650. // item := itemsType[i]
  651. // permission, err := company.GetCompanyPermissionCheckItem(companyId, item.ChartPermissionId)
  652. // if err != nil && err.Error() != utils.ErrNoRow() {
  653. // br.Msg = "获取失败"
  654. // br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  655. // return
  656. // }
  657. // if permission != nil && permission.ChartPermissionId > 0 {
  658. // checkList = append(checkList, item.ChartPermissionId)
  659. // itemsType[i].StartDate = permission.StartDate
  660. // itemsType[i].EndDate = permission.EndDate
  661. // itemsType[i].Status = permission.Status
  662. // itemsType[i].Checked = true
  663. // endDateTime, _ := time.Parse(utils.FormatDate, item.EndDate)
  664. // endDateTime = endDateTime.AddDate(0, 0, 1)
  665. // sub := endDateTime.Sub(time.Now())
  666. // if sub < 0 {
  667. // sub = 0
  668. // }
  669. // expireDay := fmt.Sprintf("%v", int(sub.Hours()/24))
  670. // itemsType[i].ExpireDay = expireDay
  671. // }
  672. // //判断主观、客观
  673. // if itemsType[i].PermissionType == 1 {
  674. // itemsType[i].PermissionTypeName = "主观"
  675. // } else if itemsType[i].PermissionType == 2 {
  676. // itemsType[i].PermissionTypeName = "客观"
  677. // }
  678. // itemsType[i].ClassifyName = v
  679. // //处理权限分类是否打钩
  680. // //if len(pType.Items) == 2 {
  681. // // var checkedMinateBool bool
  682. // // pType.Checked = true
  683. // // for _, pv := range pType.Items {
  684. // // if pv.Checked == false {
  685. // // pType.Checked = false
  686. // // } else {
  687. // // checkedMinateBool = true
  688. // // pType.NoClicking = true
  689. // // }
  690. // // }
  691. // // if checkedMinateBool == true && pType.Checked == false {
  692. // // pType.CheckedMinate = true
  693. // // }
  694. // // pListType.Items = append(pListType.Items, pType)
  695. // //}
  696. //}
  697. //合并主观客观
  698. mapPermissionName := make(map[string]int)
  699. for _, v := range items {
  700. if mapPermissionName[v.PermissionName] == 0 {
  701. p.Items = append(p.Items, v)
  702. mapPermissionName[v.PermissionName] = v.ChartPermissionId
  703. }
  704. }
  705. p.CheckList = checkList
  706. pListType.CheckList = checkList
  707. resp.List = append(resp.List, p)
  708. //resp.ListType = append(resp.ListType, pListType)
  709. }
  710. }
  711. br.Ret = 200
  712. br.Success = true
  713. br.Msg = "获取成功"
  714. br.Data = resp
  715. }
  716. // @Title 品种
  717. // @Description 品种接口
  718. // @Param CompanyType query string true "客户类型:传空字符串或者不传为全部,'ficc','权益'"
  719. // @Success 200 {object} company.PermissionVarietyResp
  720. // @router /permission/variety [get]
  721. func (this *CompanyPermissionController) PermissionVariety() {
  722. br := new(models.BaseResponse).Init()
  723. defer func() {
  724. this.Data["json"] = br
  725. this.ServeJSON()
  726. }()
  727. sysUser := this.SysUser
  728. if sysUser == nil {
  729. br.Msg = "请登录"
  730. br.ErrMsg = "请登录,SysUser Is Empty"
  731. br.Ret = 408
  732. return
  733. }
  734. companyType := this.GetString("CompanyType")
  735. var productId int
  736. resp := new(company.PermissionVarietyResp)
  737. roleTypeCode := sysUser.RoleTypeCode
  738. if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER || roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  739. productId = 2
  740. } else if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER || roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN {
  741. productId = 1
  742. } else {
  743. productId = 0
  744. }
  745. if productId == 1 || companyType == utils.COMPANY_PRODUCT_FICC_NAME {
  746. permissionFirst, e := services.GetPermissionFirstArr(utils.COMPANY_PRODUCT_FICC_ID)
  747. if e != nil {
  748. br.Msg = "获取权限信息失败"
  749. br.ErrMsg = "获取权限信息失败,Err:" + e.Error()
  750. return
  751. }
  752. allFiccPermissions, e := company.GetPermissionVarietyItemsByProductId(utils.COMPANY_PRODUCT_FICC_ID)
  753. if e != nil {
  754. br.Msg = "获取权限信息失败"
  755. br.ErrMsg = "获取权限信息失败,Err:" + e.Error()
  756. return
  757. }
  758. permissionMap := make(map[int][]*company.PermissionVarietyItem, 0)
  759. for _, v := range allFiccPermissions {
  760. permissionMap[v.ParentId] = append(permissionMap[v.ParentId], v)
  761. }
  762. for _, v := range permissionFirst {
  763. p := new(company.PermissionVarietyList)
  764. p.ClassifyName = v.ClassifyName
  765. p.ChartPermissionId = v.ChartPermissionId + 100
  766. items, ok := permissionMap[v.ChartPermissionId]
  767. if ok {
  768. p.Items = items
  769. }
  770. resp.List = append(resp.List, p)
  771. }
  772. /*for k, v := range utils.PermissionFiccClassifyArr {
  773. p := new(company.PermissionVarietyList)
  774. p.ClassifyName = v
  775. p.ChartPermissionId = k + 100
  776. items, err := company.GetPermissionVarietyItems(productId, v)
  777. if err != nil {
  778. br.Msg = "获取失败"
  779. br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  780. return
  781. }
  782. p.Items = items
  783. resp.List = append(resp.List, p)
  784. }*/
  785. } else if productId == 2 {
  786. v := "权益"
  787. p := new(company.PermissionVarietyList)
  788. p.ClassifyName = v
  789. p.ChartPermissionId = 105
  790. items, err := company.GetPermissionVarietyItems(productId, v)
  791. if err != nil {
  792. br.Msg = "获取失败"
  793. br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  794. return
  795. }
  796. p.Items = items
  797. resp.List = append(resp.List, p)
  798. } else {
  799. if companyType == utils.COMPANY_PRODUCT_RAI_NAME {
  800. v := "权益"
  801. p := new(company.PermissionVarietyList)
  802. p.ClassifyName = v
  803. p.ChartPermissionId = 105
  804. items, err := company.GetPermissionVarietyItems(2, v)
  805. if err != nil {
  806. br.Msg = "获取失败"
  807. br.ErrMsg = "获取权限信息失败,Err:" + err.Error()
  808. return
  809. }
  810. p.Items = items
  811. resp.List = append(resp.List, p)
  812. }
  813. }
  814. br.Ret = 200
  815. br.Success = true
  816. br.Msg = "获取成功"
  817. br.Data = resp
  818. }
  819. // @Title 新增试用权限
  820. // @Description 新增试用权限
  821. // @Param request body company.PermissionAddTryOutReq true "type json string"
  822. // @Success Ret=200
  823. // @router /permission/add/try/out [post]
  824. func (this *CompanyPermissionController) PermissionAddTryOut() {
  825. br := new(models.BaseResponse).Init()
  826. defer func() {
  827. this.Data["json"] = br
  828. this.ServeJSON()
  829. }()
  830. sysUser := this.SysUser
  831. if sysUser == nil {
  832. br.Msg = "请登录"
  833. br.ErrMsg = "请登录,SysUser Is Empty"
  834. br.Ret = 408
  835. return
  836. }
  837. var req company.PermissionAddTryOutReq
  838. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  839. if err != nil {
  840. br.Msg = "参数解析异常!"
  841. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  842. return
  843. }
  844. if req.ChartPermissionId == "" {
  845. br.Msg = "请选择权限"
  846. br.ErrMsg = "请选择权限"
  847. return
  848. } else {
  849. // CRM8.8-取消增开试用这里的主客观默认同时开启
  850. //permissionStr, err := company.GetPermissionIdById(req.ChartPermissionId)
  851. //if err != nil {
  852. // br.Msg = "获取信息失败"
  853. // br.ErrMsg = "获取主观客观权限信息失败,Err:" + err.Error()
  854. // return
  855. //}
  856. //req.ChartPermissionId = permissionStr
  857. }
  858. if req.CompanyId <= 0 {
  859. br.Msg = "参数错误"
  860. return
  861. }
  862. roleTypeCode := sysUser.RoleTypeCode
  863. product := services.GetProductId(roleTypeCode)
  864. if product == 0 {
  865. br.Msg = "无权新开试用权限"
  866. br.ErrMsg = "无权新开试用权限"
  867. return
  868. }
  869. companyProduct, err := company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, product)
  870. if err != nil {
  871. br.Msg = "新增试用权限失败"
  872. br.ErrMsg = "新增试用权限失败,Err:" + err.Error()
  873. return
  874. }
  875. if companyProduct.Status != utils.COMPANY_STATUS_FORMAL {
  876. br.Msg = "客户状态为:" + companyProduct.Status + ",不可增开试用权限"
  877. br.ErrMsg = "客户状态为:" + companyProduct.Status + ",不可增开试用权限"
  878. return
  879. }
  880. permissionArr := strings.Split(req.ChartPermissionId, ",")
  881. //增开试用修改对应更新时间,上海策略平台,同步客户信息试用
  882. err = company.UpdateCompanyProductModifyTime(req.CompanyId, product)
  883. if err != nil {
  884. br.Msg = "新增试用权限失败"
  885. br.ErrMsg = "新增更新更改时间失败,Err:" + err.Error()
  886. return
  887. }
  888. companyReportPermissionList := make([]*company.CompanyReportPermission, 0) //添加的品种
  889. startDateTime := time.Now()
  890. endDateTime := startDateTime.AddDate(0, 2, 0)
  891. for _, v := range permissionArr {
  892. permissionId, _ := strconv.Atoi(v)
  893. count, err := company.GetCompanyPermissionCheck(req.CompanyId, permissionId)
  894. if err != nil {
  895. br.Msg = "新增试用权限失败"
  896. br.ErrMsg = "判断权限是否存在失败,Err:" + err.Error()
  897. return
  898. }
  899. fmt.Println(permissionId)
  900. fmt.Println(count)
  901. if count <= 0 {
  902. item := new(company.CompanyReportPermission)
  903. startDate := startDateTime.Format(utils.FormatDate)
  904. endDate := endDateTime.Format(utils.FormatDate)
  905. item.CompanyId = req.CompanyId
  906. item.CreatedTime = time.Now()
  907. item.LastUpdatedTime = time.Now()
  908. item.ChartPermissionId = permissionId
  909. item.StartDate = startDate
  910. item.EndDate = endDate
  911. item.ProductId = product
  912. item.ProductName = companyProduct.ProductName
  913. item.CompanyContractId = 0
  914. item.Status = "试用"
  915. item.ModifyTime = time.Now()
  916. err = company.AddCompanyReportPermission(item)
  917. if err != nil {
  918. br.Msg = "新增试用权限失败"
  919. br.ErrMsg = "新增试用权限失败,Err:" + err.Error()
  920. return
  921. }
  922. companyReportPermissionList = append(companyReportPermissionList, item)
  923. }
  924. }
  925. //新增客户产品状态变更日志
  926. {
  927. companyProductTryOutUpdateLog := &company.CompanyProductTryOutUpdateLog{
  928. Id: 0,
  929. CompanyId: req.CompanyId,
  930. ProductId: companyProduct.ProductId,
  931. Source: "",
  932. SellerId: companyProduct.SellerId,
  933. SellerName: companyProduct.SellerName,
  934. StartDate: startDateTime,
  935. EndDate: endDateTime,
  936. RealEndDate: startDateTime,
  937. IsStop: 0,
  938. CreateTime: time.Now(),
  939. }
  940. go company.AddCompanyProductTryOutUpdateLog(companyProductTryOutUpdateLog, companyReportPermissionList)
  941. }
  942. br.Ret = 200
  943. br.Success = true
  944. br.Msg = "新增试用权限成功"
  945. br.IsAddLog = true
  946. }