rai_serve.go 36 KB

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