rai_serve.go 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232
  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. months := 3
  421. if isExport {
  422. weeks = 12 // 下载获取近12周的数据
  423. }
  424. lencompanyIds := len(companyIds)
  425. if lencompanyIds > 0 {
  426. var conditionBill string
  427. var parsBill []interface{}
  428. conditionBill, parsBill, err = getServeBillTag(tagType, tagId) // 标签ID搜索语句处理
  429. if err != nil {
  430. br.Msg = "获取信息失败!"
  431. br.ErrMsg = "获取用户信息失败-getServeBillTag!Err:" + err.Error()
  432. return
  433. }
  434. //服务类型筛选
  435. if serveTypeId > 0 {
  436. conditionBill += ` AND serve_type_id = ? `
  437. parsBill = append(parsBill, serveTypeId)
  438. }
  439. conditionBill += " AND company_id IN (" + utils.GetOrmInReplace(lencompanyIds) + ") "
  440. parsBill = append(parsBill, companyIds)
  441. listBill, err := cygx.GetCygxRaiServeBillListAll(conditionBill, parsBill)
  442. if err != nil {
  443. br.Msg = "获取信息失败!"
  444. br.ErrMsg = "获取用户信息失败-GetCygxRaiServeBillListAll!Err:" + err.Error()
  445. return
  446. }
  447. now := time.Now()
  448. for _, v := range listBill {
  449. for i := 0; i < weeks; i++ {
  450. // 计算当前周的周一
  451. monday := now.AddDate(0, 0, -int(now.Weekday()-time.Monday)-i*7)
  452. weekmonday := monday.Format(utils.FormatDate)
  453. if v.WeekStartDate == weekmonday {
  454. mapWeekAmount[fmt.Sprint("CID_", v.CompanyId, "WEEK_", i)] += v.ServeCount
  455. }
  456. }
  457. for i := 0; i < months; i++ {
  458. // 计算当前月的第一天
  459. monthday := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location()).AddDate(0, i, 0)
  460. monthFirstDay := monthday.Format(utils.FormatDate)
  461. if v.MonthStartDate == monthFirstDay {
  462. mapWeekAmount[fmt.Sprint("CID_", v.CompanyId, "MONTH_", i)] += v.ServeCount
  463. }
  464. }
  465. }
  466. }
  467. for _, v := range listRaiServeCompany {
  468. item := new(cygx.CygxRaiServeCompanyResp)
  469. item.CompanyId = v.CompanyId
  470. item.CompanyName = v.CompanyName
  471. item.Money = v.Money
  472. item.ServeCoverageRate = v.ServeCoverageRate + "%"
  473. item.SellerId = v.SellerId
  474. item.SellerName = v.SellerName
  475. item.StartDate = v.StartDate
  476. item.StartDate = v.StartDate
  477. item.EndDate = v.EndDate
  478. item.ShareSeller = v.ShareSeller
  479. item.ShareSellerId = v.ShareSellerId
  480. item.Status = v.Status
  481. item.PermissionName = v.PermissionName
  482. item.IsUserMaker = v.IsUserMaker
  483. item.ThisWeekAmount = mapWeekAmount[fmt.Sprint("CID_", v.CompanyId, "WEEK_", 0)]
  484. item.LastWeekAmount = mapWeekAmount[fmt.Sprint("CID_", v.CompanyId, "WEEK_", 1)]
  485. item.TwoWeekAmount = mapWeekAmount[fmt.Sprint("CID_", v.CompanyId, "WEEK_", 2)]
  486. item.ThreeWeekAmount = mapWeekAmount[fmt.Sprint("CID_", v.CompanyId, "WEEK_", 3)]
  487. item.ThisMonthAmount = mapWeekAmount[fmt.Sprint("CID_", v.CompanyId, "MONTH_", 0)]
  488. item.LastMonthAmount = mapWeekAmount[fmt.Sprint("CID_", v.CompanyId, "MONTH_", 1)]
  489. item.TwoMonthAmount = mapWeekAmount[fmt.Sprint("CID_", v.CompanyId, "MONTH_", 2)]
  490. if item.TwoMonthAmount == 0 || item.LastMonthAmount-item.TwoMonthAmount == 0 {
  491. item.LastMonthQoq = "0%" //上月环比=(上月服务量-上上月服务量)/上上月服务量,当数值≤-20%时,用红色字显示
  492. } else {
  493. item.LastMonthQoq = fmt.Sprint(utils.SubFloatToString((item.LastMonthAmount-item.TwoMonthAmount)/item.TwoMonthAmount*100, 2)) + "%"
  494. if (item.LastMonthAmount-item.TwoMonthAmount)/item.TwoMonthAmount <= 0.2 {
  495. item.LastMonthQoqIsRed = true
  496. }
  497. }
  498. resp.List = append(resp.List, item)
  499. }
  500. //导出excel
  501. if isExport {
  502. RaiServeListExport(this, resp, mapWeekAmount, br)
  503. return
  504. }
  505. page := paging.GetPaging(currentIndex, pageSize, total)
  506. resp.Paging = page
  507. br.Ret = 200
  508. br.Success = true
  509. br.Msg = "获取成功"
  510. br.Data = resp
  511. }
  512. // EnterScoreScoreListExport 导出Excel
  513. func RaiServeListExport(this *RaiServeCoAntroller, resp *cygx.CygxRaiServeCompanyListResp, mapWeekAmount map[string]float64, br *models.BaseResponse) {
  514. weeks := 12 // 下载获取近12周的数据
  515. mapWeekFormat := make(map[int]string)
  516. now := time.Now()
  517. for i := 0; i < weeks; i++ {
  518. // 计算当前周的周一
  519. monday := now.AddDate(0, 0, -int(now.Weekday()-time.Monday)-i*7)
  520. sunday := monday.AddDate(0, 0, 6)
  521. weekmonday := monday.Format(utils.FormatMonthDayUnSpace2)
  522. weeksunday := sunday.Format(utils.FormatMonthDayUnSpace2)
  523. mapWeekFormat[i] = weekmonday + "~" + weeksunday
  524. }
  525. dir, err := os.Executable()
  526. exPath := filepath.Dir(dir)
  527. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  528. xlsxFile := xlsx.NewFile()
  529. if err != nil {
  530. br.Msg = "生成文件失败"
  531. br.ErrMsg = "生成文件失败"
  532. return
  533. }
  534. style := xlsx.NewStyle()
  535. border := xlsx.NewBorder("thin", "thin", "thin", "thin")
  536. alignment := xlsx.Alignment{
  537. Horizontal: "center",
  538. Vertical: "center",
  539. WrapText: true,
  540. }
  541. redStyle := xlsx.NewStyle()
  542. redStyle.Alignment = alignment
  543. redStyle.ApplyAlignment = true
  544. redStyle.Font.Color = "ff0000"
  545. redStyle.Border = *border
  546. style.Alignment = alignment
  547. style.ApplyAlignment = true
  548. sheel, err := xlsxFile.AddSheet("权益服务统计")
  549. if err != nil {
  550. br.Msg = "新增Sheet失败"
  551. br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
  552. return
  553. }
  554. sheel.SetColWidth(0, 0, 30)
  555. sheel.SetColWidth(1, 1, 15)
  556. sheel.SetColWidth(2, 2, 15)
  557. sheel.SetColWidth(3, 3, 18)
  558. titleRow := sheel.AddRow()
  559. cellA := titleRow.AddCell()
  560. cellA.SetStyle(style)
  561. cellA.SetValue("客户名称")
  562. cellWeek := titleRow.AddCell()
  563. cellWeek.SetStyle(style)
  564. cellWeek.SetValue("近4周平均服务覆盖率")
  565. cellB := titleRow.AddCell()
  566. cellB.SetStyle(style)
  567. cellB.SetValue("当前状态")
  568. cellC := titleRow.AddCell()
  569. cellC.SetStyle(style)
  570. cellC.SetValue("所属销售")
  571. cellD := titleRow.AddCell()
  572. cellD.SetStyle(style)
  573. cellD.SetValue("服务销售")
  574. cellE := titleRow.AddCell()
  575. cellE.SetStyle(style)
  576. cellE.SetValue("合同期限")
  577. cellF := titleRow.AddCell()
  578. cellF.SetStyle(style)
  579. cellF.SetValue("合同金额")
  580. cellG := titleRow.AddCell()
  581. cellG.SetStyle(style)
  582. cellG.SetValue("签约套餐")
  583. cellWe1 := titleRow.AddCell()
  584. cellWe1.SetStyle(style)
  585. cellWe1.SetValue("本周服务量(" + mapWeekFormat[0] + ")")
  586. cellWe2 := titleRow.AddCell()
  587. cellWe2.SetStyle(style)
  588. cellWe2.SetValue("上周服务量(" + mapWeekFormat[1] + ")")
  589. cellWe3 := titleRow.AddCell()
  590. cellWe3.SetStyle(style)
  591. cellWe3.SetValue("上上周服务量(" + mapWeekFormat[2] + ")")
  592. cellWe4 := titleRow.AddCell()
  593. cellWe4.SetStyle(style)
  594. cellWe4.SetValue("上三周服务量(" + mapWeekFormat[3] + ")")
  595. for i := 0; i < weeks; i++ {
  596. if i < 4 {
  597. continue
  598. }
  599. // 计算当前周的周一
  600. cellWei := titleRow.AddCell()
  601. cellWei.SetStyle(style)
  602. cellWei.SetValue(mapWeekFormat[i])
  603. }
  604. for _, v := range resp.List {
  605. dataRow := sheel.AddRow()
  606. dataRow.SetHeight(20)
  607. cellA := dataRow.AddCell()
  608. if v.IsUserMaker == -1 {
  609. cellA.SetStyle(redStyle)
  610. } else {
  611. cellA.SetStyle(style)
  612. }
  613. cellA.SetValue(v.CompanyName)
  614. cellWeekData := dataRow.AddCell()
  615. cellWeekData.SetStyle(style)
  616. cellWeekData.SetValue(v.ServeCoverageRate)
  617. cellB := dataRow.AddCell()
  618. cellB.SetStyle(style)
  619. cellB.SetValue(v.Status)
  620. cellC := dataRow.AddCell()
  621. cellC.SetStyle(style)
  622. cellC.SetValue(v.SellerName)
  623. cellD := dataRow.AddCell()
  624. cellD.SetStyle(style)
  625. cellD.SetValue(v.ShareSeller)
  626. cellE := dataRow.AddCell()
  627. cellE.SetStyle(style)
  628. cellE.SetValue(v.StartDate + "~" + v.EndDate)
  629. cellF := dataRow.AddCell()
  630. cellF.SetStyle(style)
  631. cellF.SetValue(v.Money)
  632. cellG := dataRow.AddCell()
  633. cellG.SetStyle(style)
  634. cellG.SetValue(v.PermissionName)
  635. for i := 0; i < weeks; i++ {
  636. cellWei := dataRow.AddCell()
  637. cellWei.SetStyle(style)
  638. cellWei.SetValue(mapWeekAmount[fmt.Sprintf("CID_", v.CompanyId, "WEEK_", i)])
  639. }
  640. }
  641. err = xlsxFile.Save(downLoadnFilePath)
  642. if err != nil {
  643. br.Msg = "保存文件失败"
  644. br.ErrMsg = "保存文件失败"
  645. return
  646. }
  647. randStr := time.Now().Format(utils.FormatDateTimeUnSpace)
  648. downloadFileName := "权益服务统计导出数据_" + randStr + ".xlsx"
  649. this.Ctx.Output.Download(downLoadnFilePath, downloadFileName)
  650. defer func() {
  651. os.Remove(downLoadnFilePath)
  652. }()
  653. br.Ret = 200
  654. br.Success = true
  655. br.Msg = "导出成功"
  656. }
  657. // 标签搜索语句筛选
  658. func getServeBillTag(tagType, tagId int) (conditionBill string, parsBill []interface{}, err error) {
  659. if tagType == 0 {
  660. return
  661. }
  662. var activityIds []int
  663. var activitySpecialIds []int
  664. var articleIds []int
  665. var rsCalendarIds []int
  666. switch tagType {
  667. case 1:
  668. listGroupActivity, e := cygx.GetIndustrialActivityGroupManagementListByIndustriaId(tagId, 1) // 关联的活动
  669. if e != nil {
  670. err = errors.New("GetIndustrialActivityGroupManagementListByIndustriaId, Err: " + e.Error())
  671. return
  672. }
  673. for _, v := range listGroupActivity {
  674. activityIds = append(activityIds, v.ActivityId)
  675. }
  676. listGroupActivitySpecial, e := cygx.GetIndustrialActivityGroupManagementListByIndustriaId(tagId, 2) // 关联的产业
  677. if e != nil {
  678. err = errors.New("GetIndustrialActivityGroupManagementListByIndustriaId, Err: " + e.Error())
  679. return
  680. }
  681. for _, v := range listGroupActivitySpecial {
  682. activitySpecialIds = append(activitySpecialIds, v.ActivityId)
  683. }
  684. listGroupArticle, e := cygx.GetIndustrialArticleGroupManagementListByindustrialId(tagId) // 关联的产业
  685. if e != nil {
  686. err = errors.New("GetIndustrialArticleGroupManagementListByindustrialId, Err: " + e.Error())
  687. return
  688. }
  689. for _, v := range listGroupArticle {
  690. articleIds = append(articleIds, v.ArticleId)
  691. }
  692. listGroupRsCalendar, e := roadshow.GetRsCalendarMeetingLabelGroupDetailByTag(tagType, tagId)
  693. if e != nil {
  694. err = errors.New("GetRsCalendarMeetingLabelGroupDetailByTag, Err: " + e.Error())
  695. return
  696. }
  697. for _, v := range listGroupRsCalendar {
  698. rsCalendarIds = append(rsCalendarIds, v.RsCalendarId)
  699. }
  700. case 2:
  701. //通过ID获取标的名称
  702. detailSubjecj, e := cygx.GetIndustrialSubjectDetailById(tagId)
  703. if e != nil {
  704. err = errors.New("GetIndustrialSubjectDetailById, Err: " + e.Error())
  705. return
  706. }
  707. //通过名称获取所有相同名称的标的
  708. listSubject, e := cygx.GetListIndustrialSubjectDetailByName(detailSubjecj.SubjectName)
  709. if e != nil {
  710. err = errors.New("GetIndustrialSubjectDetailById, Err: " + e.Error())
  711. return
  712. }
  713. var industrialSubjectIds []int
  714. for _, v := range listSubject {
  715. industrialSubjectIds = append(industrialSubjectIds, v.IndustrialSubjectId)
  716. }
  717. listGroupActivity, e := cygx.GetSubjectActivityGroupManagementListBySubjectIds(industrialSubjectIds, 1) // 关联的活动
  718. if e != nil {
  719. err = errors.New("GetSubjectActivityGroupManagementListBySubjectId, Err: " + e.Error())
  720. return
  721. }
  722. for _, v := range listGroupActivity {
  723. activityIds = append(activityIds, v.ActivityId)
  724. }
  725. listGroupActivitySpecial, e := cygx.GetSubjectActivityGroupManagementListBySubjectIds(industrialSubjectIds, 2) // 关联的专项调研活动
  726. if e != nil {
  727. err = errors.New("GetSubjectActivityGroupManagementListBySubjectIds, Err: " + e.Error())
  728. return
  729. }
  730. for _, v := range listGroupActivitySpecial {
  731. activitySpecialIds = append(activitySpecialIds, v.ActivityId)
  732. }
  733. listGroupArticle, e := cygx.GetSubjectArticleGroupManagementListBysubjectIds(industrialSubjectIds) // 关联的报告
  734. if e != nil {
  735. err = errors.New("GetSubjectArticleGroupManagementListBysubjectIds, Err: " + e.Error())
  736. return
  737. }
  738. for _, v := range listGroupArticle {
  739. articleIds = append(articleIds, v.ArticleId)
  740. }
  741. listGroupRsCalendar, e := roadshow.GetRsCalendarMeetingLabelGroupDetailByTagIds(tagType, industrialSubjectIds)
  742. if e != nil {
  743. err = errors.New("GetRsCalendarMeetingLabelGroupDetailByTagIds, Err: " + e.Error())
  744. return
  745. }
  746. for _, v := range listGroupRsCalendar {
  747. rsCalendarIds = append(rsCalendarIds, v.RsCalendarId)
  748. }
  749. activityIds = append(activityIds, 0)
  750. lenactivityIds := len(activityIds)
  751. //if lenactivityIds > 0 {
  752. conditionBill += ` AND IF ( source = 'activity', source_id IN (` + utils.GetOrmInReplace(lenactivityIds) + `) , 1 = 1 ) `
  753. parsBill = append(parsBill, activityIds)
  754. //}
  755. activitySpecialIds = append(activitySpecialIds, 0)
  756. lenactivitySpecialIds := len(activitySpecialIds)
  757. //if lenactivitySpecialIds > 0 {
  758. conditionBill += ` AND IF ( source = 'activityspecial', source_id IN (` + utils.GetOrmInReplace(lenactivitySpecialIds) + `) , 1 = 1 ) `
  759. parsBill = append(parsBill, activitySpecialIds)
  760. //}
  761. articleIds = append(articleIds, 0)
  762. lenarticleIds := len(articleIds)
  763. //if lenarticleIds > 0 {
  764. conditionBill += ` AND IF ( source = 'article', source_id IN (` + utils.GetOrmInReplace(lenarticleIds) + `) , 1 = 1 ) `
  765. parsBill = append(parsBill, articleIds)
  766. //}
  767. rsCalendarIds = append(rsCalendarIds, 0)
  768. lenrsCalendarIds := len(rsCalendarIds)
  769. //if lenrsCalendarIds > 0 {
  770. conditionBill += ` AND IF ( source = 'rscalendar', source_id IN (` + utils.GetOrmInReplace(lenrsCalendarIds) + `) , 1 = 1 ) `
  771. parsBill = append(parsBill, rsCalendarIds)
  772. case 3:
  773. conditionBill += " AND chart_permission_id = ? "
  774. parsBill = append(parsBill, tagId)
  775. }
  776. //}
  777. conditionBill += ` AND source != 'yanxuanspecial' AND source != 'userfeedback' `
  778. return
  779. }
  780. // @Title 近四周覆盖率
  781. // @Description 近四周覆盖率接口
  782. // @Param CompanyId query int false "公司ID"
  783. // @Success 200 {object} cygx.RaiServeTagListResp
  784. // @router /rai_serve/coverage_rate [get]
  785. func (this *RaiServeCoAntroller) CoverageRate() {
  786. br := new(models.BaseResponse).Init()
  787. defer func() {
  788. this.Data["json"] = br
  789. this.ServeJSON()
  790. }()
  791. sysUser := this.SysUser
  792. if sysUser == nil {
  793. br.Msg = "请登录"
  794. br.ErrMsg = "请登录,SysUser Is Empty"
  795. br.Ret = 408
  796. return
  797. }
  798. companyId, _ := this.GetInt("CompanyId")
  799. listWeekBill, err := cygx.GetCygxRaiServeBillListWeek4(companyId)
  800. if err != nil {
  801. br.Msg = "获取信息失败!"
  802. br.ErrMsg = "获取用户信息失败-GetCygxRaiServeBillListWeek4!Err:" + err.Error()
  803. return
  804. }
  805. mapWeek := make(map[int]string)
  806. for k, v := range listWeekBill {
  807. mapWeek[k] = utils.SubFloatToString(v.CoverageRate, 2)
  808. }
  809. resp := new(cygx.RaiServeCoverageRateResp)
  810. resp.ThisWeekAmount = mapWeek[0] + "%"
  811. resp.LastWeekAmount = mapWeek[1] + "%"
  812. resp.TwoWeekAmount = mapWeek[2] + "%"
  813. resp.ThreeWeekAmount = mapWeek[3] + "%"
  814. br.Ret = 200
  815. br.Success = true
  816. br.Msg = "获取成功"
  817. br.Data = resp
  818. }
  819. // @Title 明细列表
  820. // @Description 明细列表接口
  821. // @Param PageSize query int true "每页数据条数"
  822. // @Param CurrentIndex query int true "当前页页码,从1开始"
  823. // @Param CompanyId query int false "公司ID"
  824. // @Param TagType query int false "标签类型"
  825. // @Param TagId query int false "标签ID"
  826. // @Param ServeTypeId int int false "服务类型ID"
  827. // @Param WhatWeek query int false "哪一周 ,1:本周、2:上周、3:上上周、4上三周"
  828. // @Param WhatMonth query int false "哪一月 ,1:本月、2:上月、3:上上月"
  829. // @Success 200 {object} cygx.RaiServeTagListResp
  830. // @router /rai_serve/bill_list [get]
  831. func (this *RaiServeCoAntroller) BillList() {
  832. br := new(models.BaseResponse).Init()
  833. defer func() {
  834. this.Data["json"] = br
  835. this.ServeJSON()
  836. }()
  837. sysUser := this.SysUser
  838. if sysUser == nil {
  839. br.Msg = "请登录"
  840. br.ErrMsg = "请登录,SysUser Is Empty"
  841. br.Ret = 408
  842. return
  843. }
  844. pageSize, _ := this.GetInt("PageSize")
  845. currentIndex, _ := this.GetInt("CurrentIndex")
  846. companyId, _ := this.GetInt("CompanyId")
  847. tagType, _ := this.GetInt("TagType")
  848. tagId, _ := this.GetInt("TagId")
  849. serveTypeId, _ := this.GetInt("ServeTypeId")
  850. whatWeek, _ := this.GetInt("WhatWeek")
  851. whatMonth, _ := this.GetInt("WhatMonth")
  852. var startSize int
  853. if pageSize <= 0 {
  854. pageSize = utils.PageSize20
  855. }
  856. if currentIndex <= 0 {
  857. currentIndex = 1
  858. }
  859. startSize = utils.StartIndex(currentIndex, pageSize)
  860. if companyId == 0 {
  861. br.Msg = "请选择对应公司ID"
  862. return
  863. }
  864. var condition string
  865. var pars []interface{}
  866. var err error
  867. condition, pars, err = getServeBillTag(tagType, tagId) // 标签ID搜索语句处理
  868. if err != nil {
  869. br.Msg = "获取信息失败!"
  870. br.ErrMsg = "获取用户信息失败-getServeBillTag!Err:" + err.Error()
  871. return
  872. }
  873. if whatWeek > 0 {
  874. now := time.Now()
  875. // 计算所选周的周一
  876. monday := now.AddDate(0, 0, -int(now.Weekday()-time.Monday)-(whatWeek-1)*7)
  877. condition += " AND week_start_date = ? "
  878. pars = append(pars, monday.Format(utils.FormatDate))
  879. }
  880. if whatMonth > 0 {
  881. now := time.Now()
  882. // 计算所选月份的第一天
  883. monthday := time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, now.Location()).AddDate(0, whatWeek, 0)
  884. condition += " AND month_start_date = ? "
  885. pars = append(pars, monthday.Format(utils.FormatDate))
  886. }
  887. condition += " AND company_id = ? "
  888. pars = append(pars, companyId)
  889. if serveTypeId > 0 {
  890. condition += " AND serve_type_id = ? "
  891. pars = append(pars, serveTypeId)
  892. }
  893. total, err := cygx.GetCygxRaiServeBillCount(condition, pars)
  894. if err != nil {
  895. br.Msg = "获取失败"
  896. br.ErrMsg = "获取失败,GetCygxRaiServeBillCount:" + err.Error()
  897. return
  898. }
  899. list, err := cygx.GetCygxRaiServeBillRespList(condition, pars, startSize, pageSize)
  900. if err != nil {
  901. br.Msg = "获取失败"
  902. br.ErrMsg = "获取失败,GetCygxRaiServeBillRespList:" + err.Error()
  903. return
  904. }
  905. page := paging.GetPaging(currentIndex, pageSize, total)
  906. resp := new(cygx.CygxRaiServeBillListResp)
  907. resp.Paging = page
  908. if len(list) == 0 {
  909. resp.List = make([]*cygx.CygxRaiServeBillResp, 0)
  910. } else {
  911. var activityIds []int
  912. var activitySpecialIds []int
  913. var articleIds []int
  914. var rsCalendarIds []int
  915. for _, v := range list {
  916. switch v.Source {
  917. case utils.CYGX_OBJ_ARTICLE:
  918. articleIds = append(articleIds, v.SourceId)
  919. case utils.CYGX_OBJ_ACTIVITY:
  920. activityIds = append(activityIds, v.SourceId)
  921. case utils.CYGX_OBJ_ACTIVITYSPECIAL:
  922. activitySpecialIds = append(activitySpecialIds, v.SourceId)
  923. case utils.CYGX_OBJ_RS_CALENDAR:
  924. rsCalendarIds = append(rsCalendarIds, v.SourceId)
  925. }
  926. }
  927. maparticleIndustrialLabel := make(map[int][]string) //文章产业标签
  928. maparticleSubjectLabel := make(map[int][]string) // 文章行业标签
  929. if len(articleIds) > 0 {
  930. maparticleIndustrialLabel = cygxService.GetArticleIndustrialLabelByArticleId(articleIds) // 关联产业
  931. maparticleSubjectLabel = cygxService.GetArticleSubjectLabelByArticleId(articleIds) // 关联标的
  932. }
  933. mapActivityIndustrialLabel := make(map[int][]string) //活动产业标签
  934. mapActivitySubjectLabel := make(map[int][]string) //活动标的标签
  935. mapActivityIndustrialLabel = cygxService.GetActivityIndustrialLabelByActivityIds(activityIds, 1)
  936. mapActivitySubjectLabel = cygxService.GetActivitySubjectLabelByActivityIds(activityIds, 1)
  937. mapActivitySpeicalIndustrialLabel := make(map[int][]string) //活动产业标签
  938. mapActivitySpeicalSubjectLabel := make(map[int][]string) //活动标的标签
  939. mapActivitySpeicalIndustrialLabel = cygxService.GetActivityIndustrialLabelByActivityIds(activityIds, 2)
  940. mapActivitySpeicalSubjectLabel = cygxService.GetActivitySubjectLabelByActivityIds(activityIds, 2)
  941. mapRsCalendarLabel := make(map[int][]string) //1v1 路演标签
  942. mapRsCalendarLabel = cygxService.GetRsCalendarLabelByRsCalendarIds(rsCalendarIds)
  943. for _, v := range list {
  944. switch v.Source {
  945. case utils.CYGX_OBJ_ARTICLE:
  946. if v.ChartPermissionName == utils.GU_SHOU_NAME || v.ChartPermissionName == utils.CE_LUE_NAME {
  947. v.Tag = v.ChartPermissionName
  948. } else {
  949. v.Tag = strings.Join(maparticleIndustrialLabel[v.SourceId], ",")
  950. if len(maparticleSubjectLabel[v.SourceId]) > 0 {
  951. v.Tag += "," + strings.Join(maparticleSubjectLabel[v.SourceId], ",")
  952. }
  953. }
  954. case utils.CYGX_OBJ_ACTIVITY:
  955. if v.ChartPermissionName == utils.GU_SHOU_NAME || v.ChartPermissionName == utils.CE_LUE_NAME {
  956. v.Tag = v.ChartPermissionName
  957. } else {
  958. v.Tag = strings.Join(mapActivityIndustrialLabel[v.SourceId], ",")
  959. if len(mapActivitySubjectLabel[v.SourceId]) > 0 {
  960. v.Tag += "," + strings.Join(mapActivitySubjectLabel[v.SourceId], ",")
  961. }
  962. }
  963. case utils.CYGX_OBJ_ACTIVITYSPECIAL:
  964. if v.ChartPermissionName == utils.GU_SHOU_NAME || v.ChartPermissionName == utils.CE_LUE_NAME {
  965. v.Tag = v.ChartPermissionName
  966. } else {
  967. v.Tag = strings.Join(mapActivitySpeicalIndustrialLabel[v.SourceId], ",")
  968. if len(mapActivitySpeicalSubjectLabel[v.SourceId]) > 0 {
  969. v.Tag += "," + strings.Join(mapActivitySpeicalSubjectLabel[v.SourceId], ",")
  970. }
  971. }
  972. case utils.CYGX_OBJ_RS_CALENDAR:
  973. if v.ChartPermissionName == utils.GU_SHOU_NAME || v.ChartPermissionName == utils.CE_LUE_NAME {
  974. v.Tag = v.ChartPermissionName
  975. } else {
  976. v.Tag = strings.Join(mapRsCalendarLabel[v.SourceId], ",")
  977. }
  978. }
  979. }
  980. resp.List = list
  981. }
  982. br.Ret = 200
  983. br.Success = true
  984. br.Msg = "获取成功"
  985. br.Data = resp
  986. }
  987. // AddCompanyHistoryRemark
  988. // @Title 新增历史备注
  989. // @Description 新增历史备注
  990. // @Param request body company.CompanyHistoryRemarkReq true "type json string"
  991. // @Success 200 编辑成功
  992. // @router /rai_serve/remark/add [post]
  993. func (this *RaiServeCoAntroller) AddRemark() {
  994. br := new(models.BaseResponse).Init()
  995. defer func() {
  996. this.Data["json"] = br
  997. this.ServeJSON()
  998. }()
  999. sysUser := this.SysUser
  1000. if sysUser == nil {
  1001. br.Msg = "请登录"
  1002. br.ErrMsg = "请登录,SysUser Is Empty"
  1003. br.Ret = 408
  1004. return
  1005. }
  1006. var req company.CompanyHistoryRemarkReq
  1007. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1008. if err != nil {
  1009. br.Msg = "参数解析异常!"
  1010. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1011. return
  1012. }
  1013. if req.CompanyId <= 0 {
  1014. br.Msg = "参数缺失"
  1015. br.ErrMsg = "参数缺失,客户编号未传!"
  1016. return
  1017. }
  1018. if req.Content == "" {
  1019. br.Msg = "参数缺失"
  1020. br.ErrMsg = "参数缺失,备注说明未传!"
  1021. return
  1022. }
  1023. var productId int
  1024. //var productName string
  1025. 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 {
  1026. br.Msg = "角色类型错误"
  1027. br.ErrMsg = "角色类型错误,该角色不能添加备注!"
  1028. return
  1029. }
  1030. productId = 2
  1031. item := new(company.CompanyHistoryRemark)
  1032. item.CompanyId = req.CompanyId
  1033. item.ProductId = productId
  1034. item.Content = req.Content
  1035. item.SysAdminId = sysUser.AdminId
  1036. item.SysAdminName = sysUser.RealName
  1037. item.CreateTime = time.Now()
  1038. item.ModifyTime = time.Now()
  1039. item.ShowTime = time.Now()
  1040. item.TableName = "company_history_remark"
  1041. err = company.AddCompanyHistoryRemark(item)
  1042. //{
  1043. // approveContent := req.Remark
  1044. // remark := "新增备注"
  1045. // operation := "add_remark"
  1046. // services.AddCompanyOperationRecord(req.CompanyId, companyProduct.SellerId, sysUser.AdminId, companyProduct.ProductId, sysUser.AdminId, companyProduct.CompanyName,
  1047. // companyProduct.ProductName, sysUser.RealName, remark, operation, approveContent, sysUser.RealName, "", companyProduct.Status)
  1048. //}
  1049. if err != nil {
  1050. br.Msg = "编辑失败"
  1051. br.ErrMsg = "编辑失败,Err:" + err.Error()
  1052. }
  1053. br.Ret = 200
  1054. br.Success = true
  1055. br.Msg = "编辑成功"
  1056. }
  1057. // RemarkList 备注列表
  1058. // @Title 备注列表
  1059. // @Description 备注列表
  1060. // @Param CompanyId query string true "客户id"
  1061. // @Success 200 {object} company.RemarkResp
  1062. // @router /rai_serve/remark/list [get]
  1063. func (this *RaiServeCoAntroller) RemarkList() {
  1064. br := new(models.BaseResponse).Init()
  1065. defer func() {
  1066. this.Data["json"] = br
  1067. this.ServeJSON()
  1068. }()
  1069. sysUser := this.SysUser
  1070. if sysUser == nil {
  1071. br.Msg = "请登录"
  1072. br.ErrMsg = "请登录,SysUser Is Empty"
  1073. br.Ret = 408
  1074. return
  1075. }
  1076. companyId := this.GetString("CompanyId")
  1077. var remarkList []*company.CompanyHistoryRemark
  1078. var err error
  1079. groupFicc := []string{
  1080. utils.ROLE_TYPE_CODE_FICC_SELLER, utils.ROLE_TYPE_CODE_FICC_TEAM, utils.ROLE_TYPE_CODE_FICC_GROUP,
  1081. utils.ROLE_TYPE_CODE_FICC_DEPARTMENT, utils.ROLE_TYPE_CODE_FICC_ADMIN,
  1082. }
  1083. if utils.InArrayByStr(groupFicc, sysUser.RoleTypeCode) {
  1084. br.Msg = "角色类型错误"
  1085. br.ErrMsg = "角色类型错误,该角色不能添加备注!"
  1086. return
  1087. }
  1088. remarkList, err = company.GetCompanyHistoryRemarkList(companyId, "2")
  1089. if err != nil {
  1090. br.Msg = "获取失败"
  1091. br.ErrMsg = "获取失败,Err:" + err.Error()
  1092. return
  1093. }
  1094. resp := new(company.CompanyHistoryRemarkListResp)
  1095. for _, v := range remarkList {
  1096. item := new(company.CompanyHistoryRemarkResp)
  1097. item.CompanyId = v.CompanyId
  1098. item.Content = v.Content
  1099. item.SysAdminName = v.SysAdminName
  1100. item.CreateTime = v.ShowTime.Format(utils.FormatDateTime)
  1101. switch v.TableName {
  1102. case "company_service_record":
  1103. item.RemarkType = "沟通记录"
  1104. case "company_product_remark":
  1105. item.RemarkType = "备注"
  1106. case "company_no_renewed_note":
  1107. item.RemarkType = "未续约备注"
  1108. case "company_renewal_reason":
  1109. item.RemarkType = "未续约说明"
  1110. case "cygx_user_feedback":
  1111. item.RemarkType = "交流反馈(" + v.RealName + ")"
  1112. default:
  1113. item.RemarkType = "备注"
  1114. }
  1115. resp.List = append(resp.List, item)
  1116. }
  1117. br.Ret = 200
  1118. br.Success = true
  1119. br.Msg = "获取成功"
  1120. br.Data = resp
  1121. }