rai_serve.go 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193
  1. package cygx
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "fmt"
  6. "github.com/rdlucklib/rdluck_tools/paging"
  7. "github.com/tealeg/xlsx"
  8. "hongze/hz_crm_api/controllers"
  9. "hongze/hz_crm_api/models"
  10. "hongze/hz_crm_api/models/company"
  11. "hongze/hz_crm_api/models/cygx"
  12. "hongze/hz_crm_api/models/roadshow"
  13. cygxService "hongze/hz_crm_api/services/cygx"
  14. "hongze/hz_crm_api/utils"
  15. "os"
  16. "path/filepath"
  17. "strconv"
  18. "strings"
  19. "time"
  20. )
  21. // 权益服务类型
  22. type RaiServeCoAntroller struct {
  23. controllers.BaseAuthController
  24. }
  25. // @Title 服务类型列表
  26. // @Description 服务类型列表接口
  27. // @Success 200 {object} cygx.RaiServeTypeListResp
  28. // @router /rai_serve/type_list [get]
  29. func (this *RaiServeCoAntroller) TypeList() {
  30. br := new(models.BaseResponse).Init()
  31. defer func() {
  32. this.Data["json"] = br
  33. this.ServeJSON()
  34. }()
  35. sysUser := this.SysUser
  36. if sysUser == nil {
  37. br.Msg = "请登录"
  38. br.ErrMsg = "请登录,SysUser Is Empty"
  39. br.Ret = 408
  40. return
  41. }
  42. resp := new(cygx.RaiServeTypeListResp)
  43. var condition string
  44. list, err := cygx.GetRaiServeTypeRespList(condition)
  45. if err != nil {
  46. br.Msg = "获取失败"
  47. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  48. return
  49. }
  50. resp.List = list
  51. br.Ret = 200
  52. br.Success = true
  53. br.Msg = "获取成功"
  54. br.Data = resp
  55. }
  56. // @Title 标签搜索
  57. // @Description 标签搜索接口
  58. // @Param KeyWord query string false "搜索关键词"
  59. // @Success 200 {object} cygx.RaiServeTagListResp
  60. // @router /rai_serve/search_tag [get]
  61. func (this *RaiServeCoAntroller) SearchTag() {
  62. br := new(models.BaseResponse).Init()
  63. defer func() {
  64. this.Data["json"] = br
  65. this.ServeJSON()
  66. }()
  67. sysUser := this.SysUser
  68. if sysUser == nil {
  69. br.Msg = "请登录"
  70. br.ErrMsg = "请登录,SysUser Is Empty"
  71. br.Ret = 408
  72. return
  73. }
  74. keyWord := this.GetString("KeyWord")
  75. if keyWord == "" {
  76. br.Msg = "请输入搜索关键词"
  77. return
  78. }
  79. resp := new(cygx.RaiServeTagListResp)
  80. list, err := cygx.GetRaiServeSearchTagRespList(keyWord)
  81. if err != nil {
  82. br.Msg = "获取失败"
  83. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  84. return
  85. }
  86. //如果有固收或者策略就去查询行业表
  87. if strings.Contains("固收", keyWord) || strings.Contains("策略", keyWord) {
  88. var condition string
  89. var pars []interface{}
  90. keyWord = "%" + keyWord + "%"
  91. condition = ` AND product_id = 2 AND permission_name IN ('策略','固收') AND permission_name LIKE ? `
  92. pars = append(pars, keyWord)
  93. listChartPermission, err := models.GetChartPermissionListByCondition(condition, pars)
  94. if err != nil {
  95. br.Msg = "获取失败"
  96. br.ErrMsg = "获取数据失败,GetChartPermissionListByCondition Err:" + err.Error()
  97. return
  98. }
  99. for _, v := range listChartPermission {
  100. item := new(cygx.RaiServeTagResp)
  101. item.TagType = 3
  102. item.TagId = v.ChartPermissionId
  103. item.TagName = v.PermissionName
  104. list = append(list, item)
  105. }
  106. }
  107. if len(list) == 0 {
  108. list = make([]*cygx.RaiServeTagResp, 0)
  109. } else {
  110. mapUniqueKey := make(map[string]bool)
  111. for _, v := range list {
  112. uniqueKey := fmt.Sprintf("K_", v.TagType, "V_", v.TagName)
  113. if mapUniqueKey[uniqueKey] {
  114. continue
  115. }
  116. v.Md5Key = utils.MD5(fmt.Sprintf("K_", v.TagType, "V_", v.TagId))
  117. mapUniqueKey[uniqueKey] = true
  118. resp.List = append(resp.List, v)
  119. }
  120. }
  121. br.Ret = 200
  122. br.Success = true
  123. br.Msg = "获取成功"
  124. br.Data = resp
  125. }
  126. // @Title 标签搜索(研究员日历添加到会信息)
  127. // @Description 标签搜索接口
  128. // @Param KeyWord query string false "搜索关键词"
  129. // @Param ResearcherId query int false "研究员ID"
  130. // @Success 200 {object} cygx.RaiServeTagListResp
  131. // @router /rai_serve/search_tag_by_calendar [get]
  132. func (this *RaiServeCoAntroller) SearchTagCalendar() {
  133. br := new(models.BaseResponse).Init()
  134. defer func() {
  135. this.Data["json"] = br
  136. this.ServeJSON()
  137. }()
  138. sysUser := this.SysUser
  139. if sysUser == nil {
  140. br.Msg = "请登录"
  141. br.ErrMsg = "请登录,SysUser Is Empty"
  142. br.Ret = 408
  143. return
  144. }
  145. keyWord := this.GetString("KeyWord")
  146. researcherId := this.GetString("ResearcherId")
  147. askEmailList, err := cygx.GetAskEmailListByAdminIds(researcherId)
  148. if err != nil {
  149. br.Msg = "获取失败"
  150. br.ErrMsg = "GetAskEmailCountByCelue,Err:" + err.Error()
  151. return
  152. }
  153. var hasCelue bool
  154. var permissionName []string
  155. for _, v := range askEmailList {
  156. permissionName = append(permissionName, v.ChartPermissionName)
  157. if v.ChartPermissionName == "策略" || v.ChartPermissionName == "固收" {
  158. hasCelue = true
  159. }
  160. }
  161. var permissionNameSql []string
  162. for _, v := range permissionName {
  163. permissionNameSql = append(permissionNameSql, "'"+v+"'")
  164. }
  165. chartList, err := models.GetChartPermissionByNamesByRai(permissionNameSql)
  166. if err != nil {
  167. br.Msg = "获取失败"
  168. br.ErrMsg = "获取数据失败,GetChartPermissionByNames Err:" + err.Error()
  169. return
  170. }
  171. var list []*cygx.RaiServeTagResp
  172. resp := new(cygx.RaiServeTagListResp)
  173. if hasCelue {
  174. for _, v := range chartList {
  175. item := new(cygx.RaiServeTagResp)
  176. item.TagType = 3
  177. item.TagId = v.ChartPermissionId
  178. item.TagName = v.PermissionName
  179. list = append(list, item)
  180. }
  181. } else {
  182. if keyWord == "" {
  183. br.Msg = "请输入搜索关键词"
  184. return
  185. }
  186. keyWordSlice := strings.Split(keyWord, ",")
  187. var conditionindustrial string
  188. var conditionsubject string
  189. for _, v := range keyWordSlice {
  190. conditionindustrial += ` OR i.industry_name LIKE '%` + v + `%' `
  191. conditionsubject += ` OR s.subject_name LIKE '%` + v + `%' `
  192. }
  193. var permissionId []string
  194. for _, v := range chartList {
  195. permissionId = append(permissionId, strconv.Itoa(v.ChartPermissionId))
  196. }
  197. list, err = cygx.GetRaiServeSearchTagRespListBycharId(keyWord, strings.Join(permissionId, ","), conditionindustrial, conditionsubject)
  198. if err != nil {
  199. br.Msg = "获取失败"
  200. br.ErrMsg = "获取数据失败,GetRaiServeSearchTagRespListBycharId Err:" + err.Error()
  201. return
  202. }
  203. }
  204. if len(list) == 0 {
  205. list = make([]*cygx.RaiServeTagResp, 0)
  206. } else {
  207. mapUniqueKey := make(map[string]bool)
  208. for _, v := range list {
  209. uniqueKey := fmt.Sprintf("K_", v.TagType, "V_", v.TagName)
  210. if mapUniqueKey[uniqueKey] {
  211. continue
  212. }
  213. v.Md5Key = utils.MD5(fmt.Sprintf("K_", v.TagType, "V_", v.TagId))
  214. mapUniqueKey[uniqueKey] = true
  215. resp.List = append(resp.List, v)
  216. }
  217. }
  218. br.Ret = 200
  219. br.Success = true
  220. br.Msg = "获取成功"
  221. br.Data = resp
  222. }
  223. // @Title 校验是否属于策略固收
  224. // @Description 校验是否属于策略固收接口
  225. // @Param ResearcherId query int false "研究员ID"
  226. // @Success 200 {object} cygx.RaiServeTagListResp
  227. // @router /rai_serve/chcck_PermissionName [get]
  228. func (this *RaiServeCoAntroller) ChcckPermissionName() {
  229. br := new(models.BaseResponse).Init()
  230. defer func() {
  231. this.Data["json"] = br
  232. this.ServeJSON()
  233. }()
  234. sysUser := this.SysUser
  235. if sysUser == nil {
  236. br.Msg = "请登录"
  237. br.ErrMsg = "请登录,SysUser Is Empty"
  238. br.Ret = 408
  239. return
  240. }
  241. researcherId := this.GetString("ResearcherId")
  242. askEmailList, err := cygx.GetAskEmailListByAdminIds(researcherId)
  243. if err != nil {
  244. br.Msg = "获取失败"
  245. br.ErrMsg = "GetAskEmailCountByCelue,Err:" + err.Error()
  246. return
  247. }
  248. var belong bool
  249. var permissionNameResp []string
  250. var permissionNames []string
  251. for _, v := range askEmailList {
  252. permissionNames = append(permissionNames, v.ChartPermissionName)
  253. if v.ChartPermissionName == "策略" || v.ChartPermissionName == "固收" {
  254. belong = true
  255. permissionNameResp = append(permissionNameResp, v.ChartPermissionName)
  256. }
  257. }
  258. var list []*cygx.RaiServeTagResp
  259. if belong {
  260. var permissionNameSql []string
  261. for _, v := range permissionNameResp {
  262. permissionNameSql = append(permissionNameSql, "'"+v+"'")
  263. }
  264. chartList, err := models.GetChartPermissionByNamesByRai(permissionNameSql)
  265. if err != nil {
  266. br.Msg = "获取失败"
  267. br.ErrMsg = "获取数据失败,GetChartPermissionByNames Err:" + err.Error()
  268. return
  269. }
  270. for _, v := range chartList {
  271. item := new(cygx.RaiServeTagResp)
  272. item.TagType = 3
  273. item.TagId = v.ChartPermissionId
  274. item.TagName = v.PermissionName
  275. item.Md5Key = utils.MD5(fmt.Sprintf("K_", item.TagType, "V_", item.TagId))
  276. list = append(list, item)
  277. }
  278. }
  279. resp := new(cygx.ChekChartPermissionNameResp)
  280. if len(list) == 0 {
  281. list = make([]*cygx.RaiServeTagResp, 0)
  282. }
  283. resp.List = list
  284. resp.Belong = belong
  285. resp.ChartPermissionName = strings.Join(permissionNameResp, ",")
  286. br.Ret = 200
  287. br.Success = true
  288. br.Msg = "获取成功"
  289. br.Data = resp
  290. }
  291. // @Title 权益服务统计列表
  292. // @Description 权益服务统计列表接口
  293. // @Param PageSize query int true "每页数据条数"
  294. // @Param CurrentIndex query int true "当前页页码,从1开始"
  295. // @Param SellerId query string false "销售id"
  296. // @Param ShareSellerId query string false "共享销售ID"
  297. // @Param ServeTypeId int int false "服务类型ID"
  298. // @Param TagType int string false "标签类型"
  299. // @Param TagId int string false "标签ID"
  300. // @Param Status query string false "客户状态,正式、未续约(除了正式之外的所有)"
  301. // @Param SortType query string true "如何排序,是正序还是倒序,枚举值:`asc 正序`,`desc 倒叙`"
  302. // @Param SortParam query string false "排序字段参数,用来排序的字段, 枚举值:'money':金额 、 'endDate':结束时间"
  303. // @Param KeyWord query string false "搜索关键词"
  304. // @Param IsExport query bool false "是否导出excel,默认是false"
  305. // @Success 200 {object} cygx.RaiServeTagListResp
  306. // @router /rai_serve/list [get]
  307. func (this *RaiServeCoAntroller) List() {
  308. br := new(models.BaseResponse).Init()
  309. defer func() {
  310. this.Data["json"] = br
  311. this.ServeJSON()
  312. }()
  313. sysUser := this.SysUser
  314. if sysUser == nil {
  315. br.Msg = "请登录"
  316. br.ErrMsg = "请登录,SysUser Is Empty"
  317. br.Ret = 408
  318. return
  319. }
  320. pageSize, _ := this.GetInt("PageSize")
  321. currentIndex, _ := this.GetInt("CurrentIndex")
  322. status := this.GetString("Status")
  323. sellerId := this.GetString("SellerId")
  324. shareSellerId := this.GetString("ShareSellerId")
  325. //排序参数
  326. sortParam := this.GetString("SortParam")
  327. sortType := this.GetString("SortType")
  328. tagType, _ := this.GetInt("TagType")
  329. tagId, _ := this.GetInt("TagId")
  330. serveTypeId, _ := this.GetInt("ServeTypeId")
  331. keyWord := this.GetString("KeyWord")
  332. isExport, _ := this.GetBool("IsExport")
  333. resp := new(cygx.CygxRaiServeCompanyListResp)
  334. if isExport {
  335. pageSize = 999
  336. }
  337. var startSize int
  338. if pageSize <= 0 {
  339. pageSize = utils.PageSize20
  340. }
  341. if currentIndex <= 0 {
  342. currentIndex = 1
  343. }
  344. startSize = utils.StartIndex(currentIndex, pageSize)
  345. var condition string
  346. var sortStr string
  347. var pars []interface{}
  348. if status != "" {
  349. if status == "正式" {
  350. condition += " AND status = '正式' "
  351. } else {
  352. condition += " AND status != '正式' "
  353. }
  354. }
  355. if sellerId != "" {
  356. condition += " AND seller_id IN (" + sellerId + ") "
  357. //pars = append(pars, sellerId)
  358. }
  359. if shareSellerId != "" {
  360. condition += " AND share_seller_id IN (" + shareSellerId + ") "
  361. //pars = append(pars, shareSellerId)
  362. }
  363. if sortType != "" && sortParam != "" {
  364. if sortParam == "money" {
  365. sortStr = " ORDER BY money "
  366. }
  367. if sortParam == "endDate" {
  368. sortStr = " ORDER BY end_date "
  369. }
  370. if sortType == "asc" {
  371. sortStr += " ASC "
  372. } else {
  373. sortStr += " DESC "
  374. }
  375. } else {
  376. sortStr = " ORDER BY end_date DESC "
  377. }
  378. //如果不是权益管理员和admin、财务,就做可见权限限制
  379. if sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_RAI_ADMIN && sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_ADMIN && sysUser.RoleTypeCode != utils.ROLE_TYPE_CODE_RAI_RESEARCHR {
  380. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER {
  381. condition += " AND (seller_id = ? OR share_seller_id = ? ) "
  382. pars = append(pars, sysUser.AdminId, sysUser.AdminId)
  383. }
  384. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  385. condition += " AND ( seller_id = ? OR share_seller_id = ? OR group_id = ? OR share_group_id = ? ) "
  386. pars = append(pars, sysUser.AdminId, sysUser.AdminId, sysUser.GroupId, sysUser.GroupId)
  387. }
  388. }
  389. //公司名称搜索
  390. if keyWord != "" {
  391. keyWord = "%" + keyWord + "%"
  392. condition += ` AND company_name LIKE ? `
  393. pars = append(pars, keyWord)
  394. }
  395. total, err := cygx.GetCygxRaiServeCompanyCount(condition, pars)
  396. if err != nil {
  397. br.Msg = "获取失败"
  398. br.ErrMsg = "获取失败,GetCygxRaiServeCompanyCountErr:" + err.Error()
  399. return
  400. }
  401. listRaiServeCompany, err := cygx.GetCygxRaiServeCompanyList(condition+sortStr, pars, startSize, pageSize)
  402. if err != nil {
  403. br.Msg = "获取失败"
  404. br.ErrMsg = "获取失败,Err:" + err.Error()
  405. return
  406. }
  407. var companyIds []int
  408. for _, v := range listRaiServeCompany {
  409. companyIds = append(companyIds, v.CompanyId)
  410. }
  411. mapWeekAmount := make(map[string]float64) //周度服务量
  412. weeks := 4
  413. if isExport {
  414. weeks = 12 // 下载获取近12周的数据
  415. }
  416. lencompanyIds := len(companyIds)
  417. if lencompanyIds > 0 {
  418. var conditionBill string
  419. var parsBill []interface{}
  420. conditionBill, parsBill, err = getServeBillTag(tagType, tagId) // 标签ID搜索语句处理
  421. if err != nil {
  422. br.Msg = "获取信息失败!"
  423. br.ErrMsg = "获取用户信息失败-getServeBillTag!Err:" + err.Error()
  424. return
  425. }
  426. //服务类型筛选
  427. if serveTypeId > 0 {
  428. conditionBill += ` AND serve_type_id = ? `
  429. parsBill = append(parsBill, serveTypeId)
  430. }
  431. conditionBill += " AND company_id IN (" + utils.GetOrmInReplace(lencompanyIds) + ") "
  432. parsBill = append(parsBill, companyIds)
  433. listBill, err := cygx.GetCygxRaiServeBillListAll(conditionBill, parsBill)
  434. if err != nil {
  435. br.Msg = "获取信息失败!"
  436. br.ErrMsg = "获取用户信息失败-GetCygxRaiServeBillListAll!Err:" + err.Error()
  437. return
  438. }
  439. now := time.Now()
  440. for _, v := range listBill {
  441. for i := 0; i < weeks; i++ {
  442. // 计算当前周的周一
  443. monday := now.AddDate(0, 0, -int(now.Weekday()-time.Monday)-i*7)
  444. weekmonday := monday.Format(utils.FormatDate)
  445. if v.WeekStartDate == weekmonday {
  446. mapWeekAmount[fmt.Sprintf("CID_", v.CompanyId, "WEEK_", i)] += v.ServeCount
  447. }
  448. }
  449. }
  450. }
  451. for _, v := range listRaiServeCompany {
  452. item := new(cygx.CygxRaiServeCompanyResp)
  453. item.CompanyId = v.CompanyId
  454. item.CompanyName = v.CompanyName
  455. item.Money = v.Money
  456. item.ServeCoverageRate = v.ServeCoverageRate + "%"
  457. item.SellerId = v.SellerId
  458. item.SellerName = v.SellerName
  459. item.StartDate = v.StartDate
  460. item.StartDate = v.StartDate
  461. item.EndDate = v.EndDate
  462. item.ShareSeller = v.ShareSeller
  463. item.ShareSellerId = v.ShareSellerId
  464. item.Status = v.Status
  465. item.PermissionName = v.PermissionName
  466. item.IsUserMaker = v.IsUserMaker
  467. item.ThisWeekAmount = mapWeekAmount[fmt.Sprintf("CID_", v.CompanyId, "WEEK_", 0)]
  468. item.LastWeekAmount = mapWeekAmount[fmt.Sprintf("CID_", v.CompanyId, "WEEK_", 1)]
  469. item.TwoWeekAmount = mapWeekAmount[fmt.Sprintf("CID_", v.CompanyId, "WEEK_", 2)]
  470. item.ThreeWeekAmount = mapWeekAmount[fmt.Sprintf("CID_", v.CompanyId, "WEEK_", 3)]
  471. resp.List = append(resp.List, item)
  472. }
  473. //导出excel
  474. if isExport {
  475. RaiServeListExport(this, resp, mapWeekAmount, br)
  476. return
  477. }
  478. page := paging.GetPaging(currentIndex, pageSize, total)
  479. resp.Paging = page
  480. br.Ret = 200
  481. br.Success = true
  482. br.Msg = "获取成功"
  483. br.Data = resp
  484. }
  485. // EnterScoreScoreListExport 导出Excel
  486. func RaiServeListExport(this *RaiServeCoAntroller, resp *cygx.CygxRaiServeCompanyListResp, mapWeekAmount map[string]float64, br *models.BaseResponse) {
  487. weeks := 12 // 下载获取近12周的数据
  488. mapWeekFormat := make(map[int]string)
  489. now := time.Now()
  490. for i := 0; i < weeks; i++ {
  491. // 计算当前周的周一
  492. monday := now.AddDate(0, 0, -int(now.Weekday()-time.Monday)-i*7)
  493. sunday := monday.AddDate(0, 0, 6)
  494. weekmonday := monday.Format(utils.FormatMonthDayUnSpace2)
  495. weeksunday := sunday.Format(utils.FormatMonthDayUnSpace2)
  496. mapWeekFormat[i] = weekmonday + "~" + weeksunday
  497. }
  498. dir, err := os.Executable()
  499. exPath := filepath.Dir(dir)
  500. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  501. xlsxFile := xlsx.NewFile()
  502. if err != nil {
  503. br.Msg = "生成文件失败"
  504. br.ErrMsg = "生成文件失败"
  505. return
  506. }
  507. style := xlsx.NewStyle()
  508. border := xlsx.NewBorder("thin", "thin", "thin", "thin")
  509. alignment := xlsx.Alignment{
  510. Horizontal: "center",
  511. Vertical: "center",
  512. WrapText: true,
  513. }
  514. redStyle := xlsx.NewStyle()
  515. redStyle.Alignment = alignment
  516. redStyle.ApplyAlignment = true
  517. redStyle.Font.Color = "ff0000"
  518. redStyle.Border = *border
  519. style.Alignment = alignment
  520. style.ApplyAlignment = true
  521. sheel, err := xlsxFile.AddSheet("权益服务统计")
  522. if err != nil {
  523. br.Msg = "新增Sheet失败"
  524. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  525. return
  526. }
  527. sheel.SetColWidth(0, 0, 30)
  528. sheel.SetColWidth(1, 1, 15)
  529. sheel.SetColWidth(2, 2, 15)
  530. sheel.SetColWidth(3, 3, 18)
  531. titleRow := sheel.AddRow()
  532. cellA := titleRow.AddCell()
  533. cellA.SetStyle(style)
  534. cellA.SetValue("客户名称")
  535. cellWeek := titleRow.AddCell()
  536. cellWeek.SetStyle(style)
  537. cellWeek.SetValue("近4周平均服务覆盖率")
  538. cellB := titleRow.AddCell()
  539. cellB.SetStyle(style)
  540. cellB.SetValue("当前状态")
  541. cellC := titleRow.AddCell()
  542. cellC.SetStyle(style)
  543. cellC.SetValue("所属销售")
  544. cellD := titleRow.AddCell()
  545. cellD.SetStyle(style)
  546. cellD.SetValue("咨询销售")
  547. cellE := titleRow.AddCell()
  548. cellE.SetStyle(style)
  549. cellE.SetValue("合同期限")
  550. cellF := titleRow.AddCell()
  551. cellF.SetStyle(style)
  552. cellF.SetValue("合同金额")
  553. cellG := titleRow.AddCell()
  554. cellG.SetStyle(style)
  555. cellG.SetValue("签约套餐")
  556. cellWe1 := titleRow.AddCell()
  557. cellWe1.SetStyle(style)
  558. cellWe1.SetValue("本周服务量(" + mapWeekFormat[0] + ")")
  559. cellWe2 := titleRow.AddCell()
  560. cellWe2.SetStyle(style)
  561. cellWe2.SetValue("上周服务量(" + mapWeekFormat[1] + ")")
  562. cellWe3 := titleRow.AddCell()
  563. cellWe3.SetStyle(style)
  564. cellWe3.SetValue("上上周服务量(" + mapWeekFormat[2] + ")")
  565. cellWe4 := titleRow.AddCell()
  566. cellWe4.SetStyle(style)
  567. cellWe4.SetValue("上三周服务量(" + mapWeekFormat[3] + ")")
  568. for i := 0; i < weeks; i++ {
  569. if i < 4 {
  570. continue
  571. }
  572. // 计算当前周的周一
  573. cellWei := titleRow.AddCell()
  574. cellWei.SetStyle(style)
  575. cellWei.SetValue(mapWeekFormat[i])
  576. }
  577. for _, v := range resp.List {
  578. dataRow := sheel.AddRow()
  579. dataRow.SetHeight(20)
  580. cellA := dataRow.AddCell()
  581. if v.IsUserMaker == -1 {
  582. cellA.SetStyle(redStyle)
  583. } else {
  584. cellA.SetStyle(style)
  585. }
  586. cellA.SetValue(v.CompanyName)
  587. cellWeekData := dataRow.AddCell()
  588. cellWeekData.SetStyle(style)
  589. cellWeekData.SetValue(v.ServeCoverageRate)
  590. cellB := dataRow.AddCell()
  591. cellB.SetStyle(style)
  592. cellB.SetValue(v.Status)
  593. cellC := dataRow.AddCell()
  594. cellC.SetStyle(style)
  595. cellC.SetValue(v.SellerName)
  596. cellD := dataRow.AddCell()
  597. cellD.SetStyle(style)
  598. cellD.SetValue(v.ShareSeller)
  599. cellE := dataRow.AddCell()
  600. cellE.SetStyle(style)
  601. cellE.SetValue(v.StartDate + "~" + v.EndDate)
  602. cellF := dataRow.AddCell()
  603. cellF.SetStyle(style)
  604. cellF.SetValue(v.Money)
  605. cellG := dataRow.AddCell()
  606. cellG.SetStyle(style)
  607. cellG.SetValue(v.PermissionName)
  608. for i := 0; i < weeks; i++ {
  609. cellWei := dataRow.AddCell()
  610. cellWei.SetStyle(style)
  611. cellWei.SetValue(mapWeekAmount[fmt.Sprintf("CID_", v.CompanyId, "WEEK_", i)])
  612. }
  613. }
  614. err = xlsxFile.Save(downLoadnFilePath)
  615. if err != nil {
  616. br.Msg = "保存文件失败"
  617. br.ErrMsg = "保存文件失败"
  618. return
  619. }
  620. randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
  621. downloadFileName := "权益服务统计导出数据_" + randStr + ".xlsx"
  622. this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  623. defer func() {
  624. os.Remove(downLoadnFilePath)
  625. }()
  626. br.Ret = 200
  627. br.Success = true
  628. br.Msg = "导出成功"
  629. }
  630. // 标签搜索语句筛选
  631. func getServeBillTag(tagType, tagId int) (conditionBill string, parsBill []interface{}, err error) {
  632. if tagType == 0 {
  633. return
  634. }
  635. var activityIds []int
  636. var activitySpecialIds []int
  637. var articleIds []int
  638. var rsCalendarIds []int
  639. switch tagType {
  640. case 1:
  641. listGroupActivity, e := cygx.GetIndustrialActivityGroupManagementListByIndustriaId(tagId, 1) // 关联的活动
  642. if e != nil {
  643. err = errors.New("GetIndustrialActivityGroupManagementListByIndustriaId, Err: " + e.Error())
  644. return
  645. }
  646. for _, v := range listGroupActivity {
  647. activityIds = append(activityIds, v.ActivityId)
  648. }
  649. listGroupActivitySpecial, e := cygx.GetIndustrialActivityGroupManagementListByIndustriaId(tagId, 2) // 关联的产业
  650. if e != nil {
  651. err = errors.New("GetIndustrialActivityGroupManagementListByIndustriaId, Err: " + e.Error())
  652. return
  653. }
  654. for _, v := range listGroupActivitySpecial {
  655. activitySpecialIds = append(activitySpecialIds, v.ActivityId)
  656. }
  657. listGroupArticle, e := cygx.GetIndustrialArticleGroupManagementListByindustrialId(tagId) // 关联的产业
  658. if e != nil {
  659. err = errors.New("GetIndustrialArticleGroupManagementListByindustrialId, Err: " + e.Error())
  660. return
  661. }
  662. for _, v := range listGroupArticle {
  663. articleIds = append(articleIds, v.ArticleId)
  664. }
  665. listGroupRsCalendar, e := roadshow.GetRsCalendarMeetingLabelGroupDetailByTag(tagType, tagId)
  666. if e != nil {
  667. err = errors.New("GetRsCalendarMeetingLabelGroupDetailByTag, Err: " + e.Error())
  668. return
  669. }
  670. for _, v := range listGroupRsCalendar {
  671. rsCalendarIds = append(rsCalendarIds, v.RsCalendarId)
  672. }
  673. case 2:
  674. //通过ID获取标的名称
  675. detailSubjecj, e := cygx.GetIndustrialSubjectDetailById(tagId)
  676. if e != nil {
  677. err = errors.New("GetIndustrialSubjectDetailById, Err: " + e.Error())
  678. return
  679. }
  680. //通过名称获取所有相同名称的标的
  681. listSubject, e := cygx.GetListIndustrialSubjectDetailByName(detailSubjecj.SubjectName)
  682. if e != nil {
  683. err = errors.New("GetIndustrialSubjectDetailById, Err: " + e.Error())
  684. return
  685. }
  686. var industrialSubjectIds []int
  687. for _, v := range listSubject {
  688. industrialSubjectIds = append(industrialSubjectIds, v.IndustrialSubjectId)
  689. }
  690. listGroupActivity, e := cygx.GetSubjectActivityGroupManagementListBySubjectIds(industrialSubjectIds, 1) // 关联的活动
  691. if e != nil {
  692. err = errors.New("GetSubjectActivityGroupManagementListBySubjectId, Err: " + e.Error())
  693. return
  694. }
  695. for _, v := range listGroupActivity {
  696. activityIds = append(activityIds, v.ActivityId)
  697. }
  698. listGroupActivitySpecial, e := cygx.GetSubjectActivityGroupManagementListBySubjectIds(industrialSubjectIds, 2) // 关联的专项调研活动
  699. if e != nil {
  700. err = errors.New("GetSubjectActivityGroupManagementListBySubjectIds, Err: " + e.Error())
  701. return
  702. }
  703. for _, v := range listGroupActivitySpecial {
  704. activitySpecialIds = append(activitySpecialIds, v.ActivityId)
  705. }
  706. listGroupArticle, e := cygx.GetSubjectArticleGroupManagementListBysubjectIds(industrialSubjectIds) // 关联的报告
  707. if e != nil {
  708. err = errors.New("GetSubjectArticleGroupManagementListBysubjectIds, Err: " + e.Error())
  709. return
  710. }
  711. for _, v := range listGroupArticle {
  712. articleIds = append(articleIds, v.ArticleId)
  713. }
  714. listGroupRsCalendar, e := roadshow.GetRsCalendarMeetingLabelGroupDetailByTagIds(tagType, industrialSubjectIds)
  715. if e != nil {
  716. err = errors.New("GetRsCalendarMeetingLabelGroupDetailByTagIds, Err: " + e.Error())
  717. return
  718. }
  719. for _, v := range listGroupRsCalendar {
  720. rsCalendarIds = append(rsCalendarIds, v.RsCalendarId)
  721. }
  722. activityIds = append(activityIds, 0)
  723. lenactivityIds := len(activityIds)
  724. //if lenactivityIds > 0 {
  725. conditionBill += ` AND IF ( source = 'activity', source_id IN (` + utils.GetOrmInReplace(lenactivityIds) + `) , 1 = 1 ) `
  726. parsBill = append(parsBill, activityIds)
  727. //}
  728. activitySpecialIds = append(activitySpecialIds, 0)
  729. lenactivitySpecialIds := len(activitySpecialIds)
  730. //if lenactivitySpecialIds > 0 {
  731. conditionBill += ` AND IF ( source = 'activityspecial', source_id IN (` + utils.GetOrmInReplace(lenactivitySpecialIds) + `) , 1 = 1 ) `
  732. parsBill = append(parsBill, activitySpecialIds)
  733. //}
  734. articleIds = append(articleIds, 0)
  735. lenarticleIds := len(articleIds)
  736. //if lenarticleIds > 0 {
  737. conditionBill += ` AND IF ( source = 'article', source_id IN (` + utils.GetOrmInReplace(lenarticleIds) + `) , 1 = 1 ) `
  738. parsBill = append(parsBill, articleIds)
  739. //}
  740. rsCalendarIds = append(rsCalendarIds, 0)
  741. lenrsCalendarIds := len(rsCalendarIds)
  742. //if lenrsCalendarIds > 0 {
  743. conditionBill += ` AND IF ( source = 'rscalendar', source_id IN (` + utils.GetOrmInReplace(lenrsCalendarIds) + `) , 1 = 1 ) `
  744. parsBill = append(parsBill, rsCalendarIds)
  745. case 3:
  746. conditionBill += " AND chart_permission_id = ? "
  747. parsBill = append(parsBill, tagId)
  748. }
  749. //}
  750. conditionBill += ` AND source != 'yanxuanspecial' AND source != 'userfeedback' `
  751. return
  752. }
  753. // @Title 近四周覆盖率
  754. // @Description 近四周覆盖率接口
  755. // @Param CompanyId query int false "公司ID"
  756. // @Success 200 {object} cygx.RaiServeTagListResp
  757. // @router /rai_serve/coverage_rate [get]
  758. func (this *RaiServeCoAntroller) CoverageRate() {
  759. br := new(models.BaseResponse).Init()
  760. defer func() {
  761. this.Data["json"] = br
  762. this.ServeJSON()
  763. }()
  764. sysUser := this.SysUser
  765. if sysUser == nil {
  766. br.Msg = "请登录"
  767. br.ErrMsg = "请登录,SysUser Is Empty"
  768. br.Ret = 408
  769. return
  770. }
  771. companyId, _ := this.GetInt("CompanyId")
  772. listWeekBill, err := cygx.GetCygxRaiServeBillListWeek4(companyId)
  773. if err != nil {
  774. br.Msg = "获取信息失败!"
  775. br.ErrMsg = "获取用户信息失败-GetCygxRaiServeBillListWeek4!Err:" + err.Error()
  776. return
  777. }
  778. mapWeek := make(map[int]string)
  779. for k, v := range listWeekBill {
  780. mapWeek[k] = utils.SubFloatToString(v.CoverageRate, 2)
  781. }
  782. resp := new(cygx.RaiServeCoverageRateResp)
  783. resp.ThisWeekAmount = mapWeek[0] + "%"
  784. resp.LastWeekAmount = mapWeek[1] + "%"
  785. resp.TwoWeekAmount = mapWeek[2] + "%"
  786. resp.ThreeWeekAmount = mapWeek[3] + "%"
  787. br.Ret = 200
  788. br.Success = true
  789. br.Msg = "获取成功"
  790. br.Data = resp
  791. }
  792. // @Title 明细列表
  793. // @Description 明细列表接口
  794. // @Param PageSize query int true "每页数据条数"
  795. // @Param CurrentIndex query int true "当前页页码,从1开始"
  796. // @Param CompanyId query int false "公司ID"
  797. // @Param TagType query int false "标签类型"
  798. // @Param TagId query int false "标签ID"
  799. // @Param ServeTypeId int int false "服务类型ID"
  800. // @Param WhatWeek query int false "哪一周 ,1:本周、2:上周、3:上上周、4上三周"
  801. // @Success 200 {object} cygx.RaiServeTagListResp
  802. // @router /rai_serve/bill_list [get]
  803. func (this *RaiServeCoAntroller) BillList() {
  804. br := new(models.BaseResponse).Init()
  805. defer func() {
  806. this.Data["json"] = br
  807. this.ServeJSON()
  808. }()
  809. sysUser := this.SysUser
  810. if sysUser == nil {
  811. br.Msg = "请登录"
  812. br.ErrMsg = "请登录,SysUser Is Empty"
  813. br.Ret = 408
  814. return
  815. }
  816. pageSize, _ := this.GetInt("PageSize")
  817. currentIndex, _ := this.GetInt("CurrentIndex")
  818. companyId, _ := this.GetInt("CompanyId")
  819. tagType, _ := this.GetInt("TagType")
  820. tagId, _ := this.GetInt("TagId")
  821. serveTypeId, _ := this.GetInt("ServeTypeId")
  822. whatWeek, _ := this.GetInt("WhatWeek")
  823. var startSize int
  824. if pageSize <= 0 {
  825. pageSize = utils.PageSize20
  826. }
  827. if currentIndex <= 0 {
  828. currentIndex = 1
  829. }
  830. startSize = utils.StartIndex(currentIndex, pageSize)
  831. if companyId == 0 {
  832. br.Msg = "请选择对应公司ID"
  833. return
  834. }
  835. var condition string
  836. var pars []interface{}
  837. var err error
  838. condition, pars, err = getServeBillTag(tagType, tagId) // 标签ID搜索语句处理
  839. if err != nil {
  840. br.Msg = "获取信息失败!"
  841. br.ErrMsg = "获取用户信息失败-getServeBillTag!Err:" + err.Error()
  842. return
  843. }
  844. if whatWeek > 0 {
  845. now := time.Now()
  846. // 计算所选周的周一
  847. monday := now.AddDate(0, 0, -int(now.Weekday()-time.Monday)-(whatWeek-1)*7)
  848. condition += " AND week_start_date = ? "
  849. pars = append(pars, monday.Format(utils.FormatDate))
  850. }
  851. condition += " AND company_id = ? "
  852. pars = append(pars, companyId)
  853. if serveTypeId > 0 {
  854. condition += " AND serve_type_id = ? "
  855. pars = append(pars, serveTypeId)
  856. }
  857. total, err := cygx.GetCygxRaiServeBillCount(condition, pars)
  858. if err != nil {
  859. br.Msg = "获取失败"
  860. br.ErrMsg = "获取失败,GetCygxRaiServeBillCount:" + err.Error()
  861. return
  862. }
  863. list, err := cygx.GetCygxRaiServeBillRespList(condition, pars, startSize, pageSize)
  864. if err != nil {
  865. br.Msg = "获取失败"
  866. br.ErrMsg = "获取失败,GetCygxRaiServeBillRespList:" + err.Error()
  867. return
  868. }
  869. page := paging.GetPaging(currentIndex, pageSize, total)
  870. resp := new(cygx.CygxRaiServeBillListResp)
  871. resp.Paging = page
  872. if len(list) == 0 {
  873. resp.List = make([]*cygx.CygxRaiServeBillResp, 0)
  874. } else {
  875. var activityIds []int
  876. var activitySpecialIds []int
  877. var articleIds []int
  878. var rsCalendarIds []int
  879. for _, v := range list {
  880. switch v.Source {
  881. case utils.CYGX_OBJ_ARTICLE:
  882. articleIds = append(articleIds, v.SourceId)
  883. case utils.CYGX_OBJ_ACTIVITY:
  884. activityIds = append(activityIds, v.SourceId)
  885. case utils.CYGX_OBJ_ACTIVITYSPECIAL:
  886. activitySpecialIds = append(activitySpecialIds, v.SourceId)
  887. case utils.CYGX_OBJ_RS_CALENDAR:
  888. rsCalendarIds = append(rsCalendarIds, v.SourceId)
  889. }
  890. }
  891. maparticleIndustrialLabel := make(map[int][]string) //文章产业标签
  892. maparticleSubjectLabel := make(map[int][]string) // 文章行业标签
  893. if len(articleIds) > 0 {
  894. maparticleIndustrialLabel = cygxService.GetArticleIndustrialLabelByArticleId(articleIds) // 关联产业
  895. maparticleSubjectLabel = cygxService.GetArticleSubjectLabelByArticleId(articleIds) // 关联标的
  896. }
  897. mapActivityIndustrialLabel := make(map[int][]string) //活动产业标签
  898. mapActivitySubjectLabel := make(map[int][]string) //活动标的标签
  899. mapActivityIndustrialLabel = cygxService.GetActivityIndustrialLabelByActivityIds(activityIds, 1)
  900. mapActivitySubjectLabel = cygxService.GetActivitySubjectLabelByActivityIds(activityIds, 1)
  901. mapActivitySpeicalIndustrialLabel := make(map[int][]string) //活动产业标签
  902. mapActivitySpeicalSubjectLabel := make(map[int][]string) //活动标的标签
  903. mapActivitySpeicalIndustrialLabel = cygxService.GetActivityIndustrialLabelByActivityIds(activityIds, 2)
  904. mapActivitySpeicalSubjectLabel = cygxService.GetActivitySubjectLabelByActivityIds(activityIds, 2)
  905. mapRsCalendarLabel := make(map[int][]string) //1v1 路演标签
  906. mapRsCalendarLabel = cygxService.GetRsCalendarLabelByRsCalendarIds(rsCalendarIds)
  907. for _, v := range list {
  908. switch v.Source {
  909. case utils.CYGX_OBJ_ARTICLE:
  910. if v.ChartPermissionName == utils.GU_SHOU_NAME || v.ChartPermissionName == utils.CE_LUE_NAME {
  911. v.Tag = v.ChartPermissionName
  912. } else {
  913. v.Tag = strings.Join(maparticleIndustrialLabel[v.SourceId], ",")
  914. if len(maparticleSubjectLabel[v.SourceId]) > 0 {
  915. v.Tag += "," + strings.Join(maparticleSubjectLabel[v.SourceId], ",")
  916. }
  917. }
  918. case utils.CYGX_OBJ_ACTIVITY:
  919. if v.ChartPermissionName == utils.GU_SHOU_NAME || v.ChartPermissionName == utils.CE_LUE_NAME {
  920. v.Tag = v.ChartPermissionName
  921. } else {
  922. v.Tag = strings.Join(mapActivityIndustrialLabel[v.SourceId], ",")
  923. if len(mapActivitySubjectLabel[v.SourceId]) > 0 {
  924. v.Tag += "," + strings.Join(mapActivitySubjectLabel[v.SourceId], ",")
  925. }
  926. }
  927. case utils.CYGX_OBJ_ACTIVITYSPECIAL:
  928. if v.ChartPermissionName == utils.GU_SHOU_NAME || v.ChartPermissionName == utils.CE_LUE_NAME {
  929. v.Tag = v.ChartPermissionName
  930. } else {
  931. v.Tag = strings.Join(mapActivitySpeicalIndustrialLabel[v.SourceId], ",")
  932. if len(mapActivitySpeicalSubjectLabel[v.SourceId]) > 0 {
  933. v.Tag += "," + strings.Join(mapActivitySpeicalSubjectLabel[v.SourceId], ",")
  934. }
  935. }
  936. case utils.CYGX_OBJ_RS_CALENDAR:
  937. if v.ChartPermissionName == utils.GU_SHOU_NAME || v.ChartPermissionName == utils.CE_LUE_NAME {
  938. v.Tag = v.ChartPermissionName
  939. } else {
  940. v.Tag = strings.Join(mapRsCalendarLabel[v.SourceId], ",")
  941. }
  942. }
  943. }
  944. resp.List = list
  945. }
  946. br.Ret = 200
  947. br.Success = true
  948. br.Msg = "获取成功"
  949. br.Data = resp
  950. }
  951. // AddCompanyHistoryRemark
  952. // @Title 新增历史备注
  953. // @Description 新增历史备注
  954. // @Param request body company.CompanyHistoryRemarkReq true "type json string"
  955. // @Success 200 编辑成功
  956. // @router /rai_serve/remark/add [post]
  957. func (this *RaiServeCoAntroller) AddRemark() {
  958. br := new(models.BaseResponse).Init()
  959. defer func() {
  960. this.Data["json"] = br
  961. this.ServeJSON()
  962. }()
  963. sysUser := this.SysUser
  964. if sysUser == nil {
  965. br.Msg = "请登录"
  966. br.ErrMsg = "请登录,SysUser Is Empty"
  967. br.Ret = 408
  968. return
  969. }
  970. var req company.CompanyHistoryRemarkReq
  971. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  972. if err != nil {
  973. br.Msg = "参数解析异常!"
  974. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  975. return
  976. }
  977. if req.CompanyId <= 0 {
  978. br.Msg = "参数缺失"
  979. br.ErrMsg = "参数缺失,客户编号未传!"
  980. return
  981. }
  982. if req.Content == "" {
  983. br.Msg = "参数缺失"
  984. br.ErrMsg = "参数缺失,备注说明未传!"
  985. return
  986. }
  987. var productId int
  988. //var productName string
  989. if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_TEAM || sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
  990. br.Msg = "角色类型错误"
  991. br.ErrMsg = "角色类型错误,该角色不能添加备注!"
  992. return
  993. }
  994. productId = 2
  995. item := new(company.CompanyHistoryRemark)
  996. item.CompanyId = req.CompanyId
  997. item.ProductId = productId
  998. item.Content = req.Content
  999. item.SysAdminId = sysUser.AdminId
  1000. item.SysAdminName = sysUser.RealName
  1001. item.CreateTime = time.Now()
  1002. item.ModifyTime = time.Now()
  1003. item.ShowTime = time.Now()
  1004. item.TableName = "company_history_remark"
  1005. err = company.AddCompanyHistoryRemark(item)
  1006. //{
  1007. // approveContent := req.Remark
  1008. // remark := "新增备注"
  1009. // operation := "add_remark"
  1010. // services.AddCompanyOperationRecord(req.CompanyId, companyProduct.SellerId, sysUser.AdminId, companyProduct.ProductId, sysUser.AdminId, companyProduct.CompanyName,
  1011. // companyProduct.ProductName, sysUser.RealName, remark, operation, approveContent, sysUser.RealName, "", companyProduct.Status)
  1012. //}
  1013. if err != nil {
  1014. br.Msg = "编辑失败"
  1015. br.ErrMsg = "编辑失败,Err:" + err.Error()
  1016. }
  1017. br.Ret = 200
  1018. br.Success = true
  1019. br.Msg = "编辑成功"
  1020. }
  1021. // RemarkList 备注列表
  1022. // @Title 备注列表
  1023. // @Description 备注列表
  1024. // @Param CompanyId query string true "客户id"
  1025. // @Success 200 {object} company.RemarkResp
  1026. // @router /rai_serve/remark/list [get]
  1027. func (this *RaiServeCoAntroller) RemarkList() {
  1028. br := new(models.BaseResponse).Init()
  1029. defer func() {
  1030. this.Data["json"] = br
  1031. this.ServeJSON()
  1032. }()
  1033. sysUser := this.SysUser
  1034. if sysUser == nil {
  1035. br.Msg = "请登录"
  1036. br.ErrMsg = "请登录,SysUser Is Empty"
  1037. br.Ret = 408
  1038. return
  1039. }
  1040. companyId := this.GetString("CompanyId")
  1041. var remarkList []*company.CompanyHistoryRemark
  1042. var err error
  1043. groupFicc := []string{
  1044. utils.ROLE_TYPE_CODE_FICC_SELLER, utils.ROLE_TYPE_CODE_FICC_TEAM, utils.ROLE_TYPE_CODE_FICC_GROUP,
  1045. utils.ROLE_TYPE_CODE_FICC_DEPARTMENT, utils.ROLE_TYPE_CODE_FICC_ADMIN,
  1046. }
  1047. if utils.InArrayByStr(groupFicc, sysUser.RoleTypeCode) {
  1048. br.Msg = "角色类型错误"
  1049. br.ErrMsg = "角色类型错误,该角色不能添加备注!"
  1050. return
  1051. }
  1052. remarkList, err = company.GetCompanyHistoryRemarkList(companyId, "2")
  1053. if err != nil {
  1054. br.Msg = "获取失败"
  1055. br.ErrMsg = "获取失败,Err:" + err.Error()
  1056. return
  1057. }
  1058. resp := new(company.CompanyHistoryRemarkListResp)
  1059. for _, v := range remarkList {
  1060. item := new(company.CompanyHistoryRemarkResp)
  1061. item.CompanyId = v.CompanyId
  1062. item.Content = v.Content
  1063. item.SysAdminName = v.SysAdminName
  1064. item.CreateTime = v.ShowTime.Format(utils.FormatDateTime)
  1065. switch v.TableName {
  1066. case "company_service_record":
  1067. item.RemarkType = "沟通记录"
  1068. case "company_product_remark":
  1069. item.RemarkType = "备注"
  1070. case "company_no_renewed_note":
  1071. item.RemarkType = "未续约备注"
  1072. case "company_renewal_reason":
  1073. item.RemarkType = "未续约说明"
  1074. case "cygx_user_feedback":
  1075. item.RemarkType = "交流反馈(" + v.RealName + ")"
  1076. default:
  1077. item.RemarkType = "备注"
  1078. }
  1079. resp.List = append(resp.List, item)
  1080. }
  1081. br.Ret = 200
  1082. br.Success = true
  1083. br.Msg = "获取成功"
  1084. br.Data = resp
  1085. }