calendar.go 82 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393
  1. package roadshow
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "github.com/rdlucklib/rdluck_tools/paging"
  6. "hongze/hongze_mobile_admin/controllers"
  7. "hongze/hongze_mobile_admin/models"
  8. "hongze/hongze_mobile_admin/models/cygx"
  9. "hongze/hongze_mobile_admin/models/roadshow"
  10. "hongze/hongze_mobile_admin/models/tables/admin"
  11. "hongze/hongze_mobile_admin/models/tables/company_product"
  12. "hongze/hongze_mobile_admin/models/tables/english_company"
  13. "hongze/hongze_mobile_admin/models/tables/system"
  14. "hongze/hongze_mobile_admin/services"
  15. "hongze/hongze_mobile_admin/services/rs"
  16. "hongze/hongze_mobile_admin/utils"
  17. "strconv"
  18. "strings"
  19. "time"
  20. )
  21. // 日历
  22. type CalendarController struct {
  23. controllers.BaseAuth
  24. }
  25. // @Title 新增路演活动接口
  26. // @Description 新增路演活动接口
  27. // @Param request body rs.AddActivityReq true "type json string"
  28. // @Success Ret=200 保存成功
  29. // @router /add [post]
  30. func (this *CalendarController) Add() {
  31. sysUser := this.AdminWx
  32. if sysUser == nil {
  33. this.FailWithMessage("请登录", "请登录,SysUser Is Empty")
  34. return
  35. }
  36. deleteCache := true
  37. cacheKey := "CACHE_RS_ACTIVITY_WX_ADD_" + strconv.Itoa(sysUser.AdminId)
  38. defer func() {
  39. if deleteCache {
  40. utils.Rc.Delete(cacheKey)
  41. }
  42. }()
  43. if !utils.Rc.SetNX(cacheKey, 1, 5*time.Second) {
  44. deleteCache = false
  45. this.FailWithMessage("系统处理中,请稍后重试!", "系统处理中,请稍后重试!"+sysUser.RealName+";data:"+string(this.Ctx.Input.RequestBody))
  46. return
  47. }
  48. var req roadshow.AddActivityReq
  49. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  50. if err != nil {
  51. this.FailWithMessage("参数解析异常", "参数解析失败,Err:"+err.Error())
  52. return
  53. }
  54. if len(req.ResearcherList) <= 0 {
  55. this.FailWithMessage("请选择研究员!", "请选择研究员!")
  56. return
  57. }
  58. researcherMap := make(map[int]string)
  59. var checkIsAdd []string
  60. sysUserList, err := cygx.GetAskEmailList()
  61. if err != nil {
  62. this.FailWithMessage("获取失败!", "获取失败,GetAskEmailList Err:"+err.Error())
  63. return
  64. }
  65. raiAskadminMap := make(map[int]bool, 0)
  66. for _, v := range sysUserList {
  67. raiAskadminMap[v.AdminId] = true
  68. }
  69. sysUserFwang, e := admin.GetSysUserByAdminName("fwang") // 手动拼接王芳到权益的策略行业下 start
  70. if e != nil {
  71. if e.Error() == utils.ErrNoRow() {
  72. this.FailWithMessage("用户不存在, 请检查!", "用户不存在, 请检查!")
  73. return
  74. }
  75. this.FailWithMessage("用户不存在, 请检查!", "fwang 用户名获取用户失败!Err: "+e.Error())
  76. return
  77. }
  78. raiAskadminMap[sysUserFwang.AdminId] = true // 手动拼接王芳到权益的策略行业下 end
  79. //var tipMsg string
  80. for _, v := range req.ResearcherList {
  81. if v.ResearcherId <= 0 {
  82. this.FailWithMessage("请选择研究员!", "请选择研究员!")
  83. return
  84. }
  85. if v.ResearcherName == "" {
  86. this.FailWithMessage("请选择研究员!", "请选择研究员!")
  87. return
  88. }
  89. if v.StartDate == "" {
  90. this.FailWithMessage("请选择开始日期!", "请选择开始日期!")
  91. return
  92. }
  93. if v.EndDate == "" {
  94. this.FailWithMessage("请选择结束日期!", "请选择结束日期!")
  95. return
  96. }
  97. if v.StartTime == "" {
  98. this.FailWithMessage("请选择开始时间!", "请选择开始时间!")
  99. return
  100. }
  101. if v.EndTime == "" {
  102. this.FailWithMessage("请选择结束时间!", "请选择结束时间!")
  103. return
  104. }
  105. if v.StartWeek == "" {
  106. this.FailWithMessage("请选择周!", "请选择周!")
  107. return
  108. }
  109. if v.EndWeek == "" {
  110. this.FailWithMessage("请选择周!", "请选择周!")
  111. return
  112. }
  113. if req.ActivityType == "沙龙" && !raiAskadminMap[v.ResearcherId] {
  114. this.FailWithMessage("ficc研究员暂不支持添加沙龙", "ficc研究员暂不支持添加沙龙")
  115. return
  116. }
  117. startDateTime := v.StartDate + " " + v.StartTime
  118. endDateTime := v.EndDate + " " + v.EndTime
  119. startP, _ := time.ParseInLocation(utils.FormatDateTime, startDateTime, time.Local)
  120. endP, _ := time.ParseInLocation(utils.FormatDateTime, endDateTime, time.Local)
  121. if startP.Before(time.Now()) || startP.Equal(time.Now()) {
  122. this.FailWithMessage("活动开始时间不能小于当前时间!", "活动开始时间不能小于当前时间!")
  123. return
  124. }
  125. if endP.Before(time.Now()) || endP.Equal(time.Now()) {
  126. this.FailWithMessage("活动结束时间不能小于当前时间!", "活动结束时间不能小于当前时间!")
  127. return
  128. }
  129. if startP.After(endP) || startP.Equal(endP) {
  130. this.FailWithMessage("活动开始时间应小于结束时间!", "活动开始时间应小于结束时间!")
  131. return
  132. }
  133. if realName, ok := researcherMap[v.ResearcherId]; ok {
  134. this.FailWithMessage("研究员:"+realName+" 被重复选择", "研究员:"+realName+" 被重复选择")
  135. return
  136. }
  137. researcherMap[v.ResearcherId] = v.ResearcherName
  138. //同步上海数据
  139. researcherInfo, err := admin.GetAdminWxById(v.ResearcherId)
  140. if err != nil {
  141. this.FailWithMessage("研究员异常", "获取研究员异常,Err:"+err.Error())
  142. return
  143. }
  144. _ = rs.SyncCalendarFromShanghai(researcherInfo.Mobile, v.StartDate, v.EndDate)
  145. //校验事项时间冲突
  146. {
  147. matterCount, err := rs.CheckMatters(startDateTime, endDateTime, v.ResearcherId, 0)
  148. if err != nil {
  149. this.FailWithMessage("时间冲突检测失败!", "时间冲突检测失败-CheckMattersCount!Err:"+err.Error())
  150. return
  151. }
  152. if matterCount > 0 {
  153. checkIsAdd = append(checkIsAdd, v.ResearcherName)
  154. }
  155. }
  156. //校验活动时间冲突
  157. {
  158. calendarCount, err := rs.CheckCalendar(startDateTime, endDateTime, "1,2", v.ResearcherId, 0)
  159. if err != nil {
  160. this.FailWithMessage("时间冲突检测失败!", "时间冲突检测失败-CheckCalendar!Err:"+err.Error())
  161. return
  162. }
  163. if calendarCount > 0 {
  164. checkIsAdd = append(checkIsAdd, v.ResearcherName)
  165. }
  166. }
  167. }
  168. if len(checkIsAdd) > 0 {
  169. this.FailWithMessage(strings.Join(checkIsAdd, ",")+" 时间已被占用!", "时间冲突检测失败-CheckMattersCount!")
  170. return
  171. }
  172. //如果是权益客户,添加销售跟共享销售的信息
  173. var productItemRai *company_product.CompanyProduct
  174. roleTypeCode := sysUser.RoleTypeCode
  175. //如果是权益销售、权益销售组长、权益管理员 添加的路演信息,做销售与共享销售信息关联查看
  176. if req.CompanyId > 0 && req.ActivityType == "路演" && (roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER ||
  177. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP || roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN) {
  178. productItemRai, err = company_product.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, utils.COMPANY_PRODUCT_RAI_ID)
  179. if err != nil && err.Error() != utils.ErrNoRow() {
  180. this.FailWithMessage("客户信息有误!", "获取客户信息失败!Err:"+err.Error())
  181. return
  182. }
  183. }
  184. rsCalendar := new(roadshow.RsCalendar)
  185. rsCalendar.SysUserId = sysUser.AdminId
  186. rsCalendar.SysUserRealName = sysUser.RealName
  187. rsCalendar.ActivityType = req.ActivityType
  188. rsCalendar.RoadshowType = req.RoadshowType
  189. rsCalendar.RoadshowPlatform = req.RoadshowPlatform
  190. rsCalendar.CompanyId = req.CompanyId
  191. rsCalendar.CompanyName = req.CompanyName
  192. rsCalendar.Province = req.Province
  193. rsCalendar.ProvinceCode = req.ProvinceCode
  194. rsCalendar.City = req.City
  195. rsCalendar.CityCode = req.CityCode
  196. rsCalendar.District = req.District
  197. rsCalendar.Theme = req.Theme
  198. rsCalendar.CooperationName = req.CooperationName
  199. rsCalendar.CreateTime = time.Now()
  200. rsCalendar.ModifyTime = time.Now()
  201. rsCalendar.ActivityCategory = req.ActivityCategory
  202. rsCalendar.Source = 0
  203. rsCalendar.EnglishCompany = req.EnglishCompany
  204. rsCalendar.Title = getTitle(req.ActivityType, req.RoadshowType, req.ActivityCategory, req.RoadshowPlatform, req.Province, req.City)
  205. if productItemRai != nil {
  206. rsCalendar.SellerId = productItemRai.SellerId
  207. rsCalendar.ShareSellerId = productItemRai.ShareSellerId
  208. }
  209. rsCalendarId, err := roadshow.AddRsCalendar(rsCalendar)
  210. if err != nil {
  211. this.FailWithMessage("保存失败", "保存日历活动信息失败!Err:"+err.Error())
  212. return
  213. }
  214. //if researcherId != 99 {
  215. for k, v := range req.ResearcherList {
  216. researcher := new(roadshow.RsCalendarResearcher)
  217. researcher.RsCalendarId = int(rsCalendarId)
  218. researcher.ResearcherId = v.ResearcherId
  219. researcher.ResearcherName = v.ResearcherName
  220. researcher.StartDate = v.StartDate
  221. researcher.EndDate = v.EndDate
  222. researcher.StartTime = v.StartTime
  223. researcher.EndTime = v.EndTime
  224. researcher.StartWeek = v.StartWeek
  225. researcher.EndWeek = v.EndWeek
  226. researcher.CreateTime = time.Now()
  227. researcher.ModifyTime = time.Now()
  228. researcher.ResearcherSort = k + 1
  229. if req.ActivityType == "路演" || req.ActivityType == "公开会议" {
  230. researcher.Status = 1
  231. } else {
  232. researcher.Status = 2
  233. }
  234. //CRM15.5 权益研究员直接通过
  235. if raiAskadminMap[v.ResearcherId] {
  236. researcher.Status = 2
  237. }
  238. rsCalendarResearcherId, err := roadshow.AddRsCalendarResearcher(researcher)
  239. if err != nil {
  240. this.FailWithMessage("保存失败", "保存日历活动-研究员信息失败!Err:"+err.Error())
  241. return
  242. }
  243. rsCalendar.RsCalendarId = int(rsCalendarId)
  244. researcher.RsCalendarResearcherId = int(rsCalendarResearcherId)
  245. go rs.CalendarToSH(*rsCalendar, *researcher)
  246. //模板消息通知
  247. {
  248. go func(researcherId, tmpRsCalendarId, tmpRsCalendarResearcherId int) {
  249. var wxAppPath string
  250. sysAdmin, _ := admin.GetAdminWxById(researcherId)
  251. if sysAdmin != nil {
  252. if req.ActivityType == "路演" || req.ActivityType == "公开会议" {
  253. wxAppPath = "pages-approve/activity/detail?RsCalendarId=" + strconv.Itoa(tmpRsCalendarId) + "&RsCalendarResearcherId=" + strconv.Itoa(tmpRsCalendarResearcherId)
  254. first := "您收到一个新的【" + req.ActivityType + "】申请,请及时处理"
  255. keyword1 := sysUser.RealName
  256. keyword2 := "--"
  257. //keyword3 := time.Now().Format(utils.FormatDateTime)
  258. startDateSub := v.StartDate[5:]
  259. startDateSub = strings.Replace(startDateSub, "-", ".", -1)
  260. keyword3 := startDateSub + "(" + v.StartWeek + ")" + " " + v.StartTime[:5] + "~" + v.EndTime[:5]
  261. var keyword4 string
  262. if req.ActivityType == "路演" {
  263. keyword4 = req.CompanyName + "(" + req.RoadshowType + req.ActivityType + ")"
  264. } else {
  265. keyword4 = req.Theme + "(" + req.RoadshowType + req.ActivityType + ")"
  266. }
  267. remark := "请尽快完成审批"
  268. //wxAppPath := "pages-approve/activity/detail?RsCalendarId=" + strconv.Itoa(int(rsCalendarId)) + "&RsCalendarResearcherId=" + strconv.Itoa(int(rsCalendarResearcherId))
  269. if sysAdmin.OpenId != "" {
  270. go services.SendWxMsgWithRoadshowPending(first, keyword1, keyword2, keyword3, keyword4, remark, wxAppPath, sysAdmin.Mobile)
  271. }
  272. } else {
  273. wxAppPath = ""
  274. first := sysUser.RealName + "为你添加了一场【" + req.ActivityType + "】"
  275. startDate := researcher.StartDate[5:]
  276. startDate = strings.Replace(startDate, "-", ".", -1)
  277. keyword1 := startDate + "(" + researcher.StartWeek + ")" + " " + researcher.StartTime[:5] + "-" + researcher.EndTime[:5]
  278. keyword2 := sysUser.RealName + "为你添加了【" + req.ActivityType + "】"
  279. if sysAdmin.OpenId != "" {
  280. go services.SendWxMsgWithRoadshowDeleteNotice(first, keyword1, keyword2, "", wxAppPath, sysAdmin.Mobile)
  281. }
  282. }
  283. }
  284. }(v.ResearcherId, int(rsCalendarId), int(rsCalendarResearcherId))
  285. }
  286. }
  287. this.OkDetailed(nil, "保存成功")
  288. }
  289. // CalendarList
  290. // @Title 我的日历列表
  291. // @Description 我的日历列表接口
  292. // @Param PageSize query int true "每页数据条数"
  293. // @Param CurrentIndex query int true "当前页页码,从1开始"
  294. // @Param Status query int true "1:待接受,2:包含,已接受,已拒绝,已删除,已撤回,已结束"
  295. // @Success 200 {object} rs.CalendarListResp
  296. // @router /calendar/list [get]
  297. func (this *CalendarController) CalendarList() {
  298. adminItem := this.AdminWx
  299. status, _ := this.GetInt("Status")
  300. pageSize, _ := this.GetInt("PageSize")
  301. currentIndex, _ := this.GetInt("CurrentIndex")
  302. var total int
  303. page := paging.GetPaging(currentIndex, pageSize, total)
  304. var startSize int
  305. if pageSize <= 0 {
  306. pageSize = utils.PageSize10
  307. }
  308. if currentIndex <= 0 {
  309. currentIndex = 1
  310. }
  311. startSize = paging.StartIndex(currentIndex, pageSize)
  312. var condition string
  313. var pars []interface{}
  314. roleTypeCode := adminItem.RoleTypeCode
  315. //销售
  316. //if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER ||
  317. // roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER ||
  318. // roleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP ||
  319. // roleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP ||
  320. // roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  321. // condition += ` AND a.sys_user_id=?`
  322. // pars = append(pars, adminItem.AdminId)
  323. //}
  324. if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER ||
  325. //roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER ||
  326. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP ||
  327. //roleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP ||
  328. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_TEAM ||
  329. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  330. condition += ` AND a.sys_user_id=?`
  331. pars = append(pars, adminItem.AdminId)
  332. //condition += ` AND a.activity_type IN('路演','公开会议') `
  333. }
  334. //权益销售
  335. if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER ||
  336. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  337. //if calendarType == 2 {
  338. condition += ` AND ( a.sys_user_id=? OR a.seller_id=? OR a.share_seller_id=? ) `
  339. pars = append(pars, adminItem.AdminId, adminItem.AdminId, adminItem.AdminId)
  340. //}
  341. }
  342. if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_RESEARCHR ||
  343. roleTypeCode == utils.ROLE_TYPE_CODE_RESEARCHR ||
  344. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_RESEARCHR ||
  345. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_DEPARTMENT ||
  346. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_DEPARTMENT ||
  347. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN {
  348. condition += ` AND b.researcher_id=?`
  349. pars = append(pars, adminItem.AdminId)
  350. }
  351. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  352. condition += ` AND a.sys_user_id=?`
  353. pars = append(pars, adminItem.AdminId)
  354. }
  355. condition += ` AND a.activity_type IN('路演','公开会议','沙龙') `
  356. if status == 1 {
  357. condition += ` AND b.status=?`
  358. pars = append(pars, 1)
  359. } else {
  360. condition += ` AND b.status IN(2,3,4,5,6)`
  361. }
  362. resp := new(roadshow.CalendarListResp)
  363. total, err := roadshow.GetCalendarListCount(condition, pars)
  364. if err != nil && err.Error() != utils.ErrNoRow() {
  365. this.FailWithMessage("获取信息失败!", "获取数据总数失败,GetCalendarListCount,Err:"+err.Error())
  366. return
  367. }
  368. page = paging.GetPaging(currentIndex, pageSize, total)
  369. dataList, err := roadshow.GetCalendarList(condition, pars, status, startSize, pageSize)
  370. if err != nil {
  371. this.FailWithMessage("获取信息失败!", "获取数据失败,GetCalendarList,Err:"+err.Error())
  372. return
  373. }
  374. // 英文客户的国家以及点击量
  375. englishIds := make([]int, 0)
  376. for i := range dataList {
  377. if dataList[i].EnglishCompany == 1 {
  378. englishIds = append(englishIds, dataList[i].CompanyId)
  379. }
  380. }
  381. englishMap := make(map[int]*english_company.EnglishCompany)
  382. if len(englishIds) > 0 {
  383. englishCond := ` AND company_id IN (` + utils.GetOrmInReplace(len(englishIds)) + `)`
  384. englishPars := make([]interface{}, 0)
  385. englishPars = append(englishPars, englishIds)
  386. englishList, e := english_company.GetEnglishCompanyList(englishCond, englishPars, "")
  387. if e != nil {
  388. this.FailWithMessage("获取英文客户失败!", "获取英文客户失败, Err:"+err.Error())
  389. return
  390. }
  391. for i := range englishList {
  392. englishMap[englishList[i].CompanyId] = englishList[i]
  393. }
  394. }
  395. for i := range dataList {
  396. if dataList[i].EnglishCompany == 1 {
  397. en := englishMap[dataList[i].CompanyId]
  398. if en != nil {
  399. dataList[i].EnglishCountry = en.Country
  400. dataList[i].EnglishViewTotal = en.ViewTotal
  401. }
  402. }
  403. }
  404. resp.Paging = page
  405. resp.List = dataList
  406. this.OkDetailed(resp, "获取成功")
  407. }
  408. // CalendarList
  409. // @Title 内部会议和报告电话会日历列表
  410. // @Description 内部会议和报告电话会日历列表
  411. // @Param PageSize query int true "每页数据条数"
  412. // @Param CurrentIndex query int true "当前页页码,从1开始"
  413. // @Param CalendarType query int true "1:内部会议,2:报告电话会"
  414. // @Success 200 {object} rs.CalendarListResp
  415. // @router /calendar/type/list [get]
  416. func (this *CalendarController) CalendarTypeList() {
  417. adminItem := this.AdminWx
  418. pageSize, _ := this.GetInt("PageSize")
  419. currentIndex, _ := this.GetInt("CurrentIndex")
  420. calendarType, _ := this.GetInt("CalendarType")
  421. var total int
  422. page := paging.GetPaging(currentIndex, pageSize, total)
  423. var startSize int
  424. if pageSize <= 0 {
  425. pageSize = utils.PageSize10
  426. }
  427. if currentIndex <= 0 {
  428. currentIndex = 1
  429. }
  430. startSize = paging.StartIndex(currentIndex, pageSize)
  431. var condition string
  432. var pars []interface{}
  433. if calendarType == 1 {
  434. condition += ` AND a.activity_type='内部会议' `
  435. condition += ` AND a.sys_user_id=?`
  436. pars = append(pars, adminItem.AdminId)
  437. }
  438. if calendarType == 2 {
  439. condition += ` AND a.activity_type='报告电话会' `
  440. }
  441. resp := new(roadshow.CalendarListResp)
  442. total, err := roadshow.GetCalendarTypeListCount(condition, pars)
  443. if err != nil && err.Error() != utils.ErrNoRow() {
  444. this.FailWithMessage("获取信息失败!", "获取数据总数失败,GetCalendarTypeListCount,Err:"+err.Error())
  445. return
  446. }
  447. page = paging.GetPaging(currentIndex, pageSize, total)
  448. dataList, err := roadshow.GetCalendarTypeList(condition, pars, startSize, pageSize)
  449. if err != nil {
  450. this.FailWithMessage("获取信息失败!", "获取数据失败,GetCalendarTypeList,Err:"+err.Error())
  451. return
  452. }
  453. resp.Paging = page
  454. resp.List = dataList
  455. this.OkDetailed(resp, "获取成功")
  456. }
  457. // Accept
  458. // @Description 接受路演活动接口
  459. // @Param request body rs.AcceptReq true "type json string"
  460. // @Success Ret=200 保存成功
  461. // @router /accept [post]
  462. func (this *CalendarController) Accept() {
  463. //adminItem:=this.AdminWx
  464. var req roadshow.AcceptReq
  465. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  466. if err != nil {
  467. this.FailWithMessage("参数解析失败!", "参数解析失败,Err:"+err.Error())
  468. return
  469. }
  470. if req.RsCalendarId <= 0 || req.RsCalendarResearcherId <= 0 {
  471. this.FailWithMessage("参数错误!", "RsCalendarId 或 RsCalendarResearcherId 小于等于0:")
  472. return
  473. }
  474. rsCalendar, err := roadshow.GetRsCalendarById(req.RsCalendarId)
  475. if err != nil {
  476. this.FailWithMessage("获取数据失败!", "GetRsCalendarById Err:"+err.Error())
  477. return
  478. }
  479. rsCalendarResearcher, err := roadshow.GetRsCalendarResearcherById(req.RsCalendarResearcherId)
  480. if err != nil {
  481. this.FailWithMessage("获取数据失败!", "GetRsCalendarResearcherById Err:"+err.Error())
  482. return
  483. }
  484. if rsCalendarResearcher.Status == 2 {
  485. this.FailWithMessage("已接受,不可重复操作!", "")
  486. return
  487. } else if rsCalendarResearcher.Status == 3 {
  488. this.FailWithMessage("已拒绝,不可进行接受操作!", "")
  489. return
  490. } else if rsCalendarResearcher.Status == 4 {
  491. this.FailWithMessage("已删除,不可进行接受操作!", "")
  492. return
  493. } else if rsCalendarResearcher.Status == 5 {
  494. this.FailWithMessage("已撤回,不可进行接受操作!", "")
  495. return
  496. }
  497. whereParams := make(map[string]interface{})
  498. updateParams := make(map[string]interface{})
  499. whereParams["rs_calendar_researcher_id"] = req.RsCalendarResearcherId
  500. whereParams["rs_calendar_id"] = req.RsCalendarId
  501. updateParams["status"] = 2
  502. updateParams["modify_time"] = time.Now()
  503. updateParams["approve_time"] = time.Now()
  504. err = roadshow.UpdateCalendarResearcher(whereParams, updateParams)
  505. if err != nil {
  506. this.FailWithMessage("获取数据失败!", "UpdateCalendarResearcher Err:"+err.Error())
  507. return
  508. }
  509. //模板消息通知
  510. {
  511. if rsCalendar != nil {
  512. sysAdmin, _ := admin.GetAdminById(rsCalendar.SysUserId)
  513. first := "【" + this.AdminWx.RealName + "】接受了你的【" + rsCalendar.ActivityType + "】申请"
  514. var keyword1, keyword2, keyword3, keyword4, keyword5 string
  515. keyword1 = rsCalendar.CompanyName + "(" + rsCalendar.RoadshowType + rsCalendar.ActivityType + ")"
  516. keyword2 = rsCalendar.ActivityType
  517. keyword4 = `【` + this.AdminWx.RealName + `】已接受`
  518. remark := ""
  519. if sysAdmin.Mobile != "" {
  520. go services.SendWxMsgWithRoadshowDetailResult(first, keyword1, keyword2, keyword3, keyword4, keyword5, remark, sysAdmin.Mobile, "", "")
  521. }
  522. }
  523. }
  524. this.OkDetailed(nil, "保存成功")
  525. }
  526. // @Title 拒绝路演活动接口
  527. // @Description 拒绝路演活动接口
  528. // @Param request body rs.RefuseReq true "type json string"
  529. // @Success Ret=200 保存成功
  530. // @router /refuse [post]
  531. func (this *CalendarController) Refuse() {
  532. //adminItem:=this.AdminWx
  533. var req roadshow.RefuseReq
  534. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  535. if err != nil {
  536. this.FailWithMessage("参数解析失败!", "参数解析失败,Err:"+err.Error())
  537. return
  538. }
  539. if req.RsCalendarId <= 0 || req.RsCalendarResearcherId <= 0 {
  540. this.FailWithMessage("参数错误!", "参数错误!RsCalendarId:"+strconv.Itoa(req.RsCalendarId)+";RsCalendarResearcherId:"+strconv.Itoa(req.RsCalendarResearcherId))
  541. return
  542. }
  543. rsCalendar, err := roadshow.GetRsCalendarById(req.RsCalendarId)
  544. if err != nil {
  545. this.FailWithMessage("获取数据失败!", "GetRsCalendarById,Err:"+err.Error())
  546. return
  547. }
  548. rsCalendarResearcher, err := roadshow.GetRsCalendarResearcherById(req.RsCalendarResearcherId)
  549. if err != nil {
  550. this.FailWithMessage("获取数据失败!", "GetRsCalendarResearcherById,Err:"+err.Error())
  551. return
  552. }
  553. if rsCalendarResearcher.Status == 2 {
  554. this.FailWithMessage("已接受,不可进行拒绝操作!", "")
  555. return
  556. } else if rsCalendarResearcher.Status == 3 {
  557. this.FailWithMessage("已拒绝,不可进行重复操作!", "")
  558. return
  559. } else if rsCalendarResearcher.Status == 4 {
  560. this.FailWithMessage("已删除,不可进行拒绝操作!", "")
  561. return
  562. } else if rsCalendarResearcher.Status == 5 {
  563. this.FailWithMessage("已撤回,不可进行拒绝操作!", "")
  564. return
  565. }
  566. whereParams := make(map[string]interface{})
  567. updateParams := make(map[string]interface{})
  568. whereParams["rs_calendar_researcher_id"] = req.RsCalendarResearcherId
  569. whereParams["rs_calendar_id"] = req.RsCalendarId
  570. updateParams["status"] = 3
  571. updateParams["refuse_reason"] = req.RefuseReason
  572. updateParams["refuse_time"] = time.Now()
  573. updateParams["modify_time"] = time.Now()
  574. err = roadshow.UpdateCalendarResearcher(whereParams, updateParams)
  575. if err != nil {
  576. this.FailWithMessage("保存失败", "保存失败!UpdateCalendarResearcher:"+err.Error())
  577. return
  578. }
  579. // 拒绝后需要删除上海的日程
  580. go rs.DeleteSHCalendar(req.RsCalendarResearcherId)
  581. //模板消息通知
  582. {
  583. if rsCalendar != nil {
  584. sysAdmin, _ := admin.GetAdminById(rsCalendar.SysUserId)
  585. first := "【" + this.AdminWx.RealName + "】拒绝了你的【" + rsCalendar.ActivityType + "】申请"
  586. var keyword1, keyword2, keyword3, keyword4, keyword5 string
  587. keyword1 = rsCalendar.CompanyName + "(" + rsCalendar.RoadshowType + rsCalendar.ActivityType + ")"
  588. keyword2 = rsCalendar.ActivityType
  589. keyword4 = `【` + this.AdminWx.RealName + `】已拒绝`
  590. keyword5 = req.RefuseReason
  591. remark := req.RefuseReason
  592. if sysAdmin.Mobile != "" {
  593. go services.SendWxMsgWithRoadshowDetailResult(first, keyword1, keyword2, keyword3, keyword4, keyword5, remark, sysAdmin.Mobile, "", "")
  594. }
  595. }
  596. }
  597. this.OkDetailed(nil, "保存成功")
  598. }
  599. // @Title 日历详情
  600. // @Description 日历详情接口
  601. // @Param RsCalendarId query int true "路演活动id"
  602. // @Param RsCalendarResearcherId query int true "活动研究员id"
  603. // @Success 200 {object} rs.CalendarDetailResp
  604. // @router /calendar/detail [get]
  605. func (this *CalendarController) CalendarDetail() {
  606. //adminItem:=this.AdminWx
  607. //roleTypeCode := adminItem.RoleTypeCode
  608. sysUser := this.AdminWx
  609. if sysUser == nil {
  610. this.FailWithMessage("请登录", "请登录,SysUser Is Empty")
  611. return
  612. }
  613. rsCalendarId, _ := this.GetInt("RsCalendarId")
  614. rsCalendarResearcherId, _ := this.GetInt("RsCalendarResearcherId")
  615. if rsCalendarId <= 0 || rsCalendarResearcherId <= 0 {
  616. this.FailWithMessage("参数错误", "rsCalendarId 或 rsCalendarResearcherId")
  617. return
  618. }
  619. calendarItem, err := roadshow.GetRsCalendarById(rsCalendarId)
  620. if err != nil {
  621. this.FailWithMessage("获取数据失败", "获取数据失败!GetRsCalendarById:"+err.Error())
  622. return
  623. }
  624. rsCalendarResearcherItem, err := roadshow.GetRsCalendarResearcherById(rsCalendarResearcherId)
  625. if err != nil {
  626. this.FailWithMessage("获取数据失败", "获取数据失败!GetRsCalendarResearcherById:"+err.Error())
  627. return
  628. }
  629. companyDetailView := new(roadshow.CompanyDetailView)
  630. productId := services.GetProductId(sysUser.RoleTypeCode)
  631. if productId == 0 {
  632. productId = 1
  633. }
  634. if calendarItem != nil && calendarItem.CompanyId > 0 {
  635. // 中文客户
  636. if calendarItem.EnglishCompany == 0 {
  637. companyId := calendarItem.CompanyId
  638. companyProductItem, err := models.GetCompanyProductByCompanyIdAndProductId(companyId, productId)
  639. if err != nil {
  640. this.FailWithMessage("获取数据失败", "获取数据失败!GetCompanyProductByCompanyIdAndProductId:"+err.Error())
  641. return
  642. }
  643. permissionList, err := models.GetCompanyProductReportPermissionList(companyId, productId)
  644. if err != nil {
  645. this.FailWithMessage("搜索客户权限失败", "搜索客户权限失败!GetCompanyProductReportPermissionList:"+err.Error())
  646. return
  647. }
  648. var permissionArr []string
  649. for _, v := range permissionList {
  650. permissionArr = append(permissionArr, v.PermissionName)
  651. }
  652. readNum := companyProductItem.ViewTotal
  653. companyDetailView.CompanyId = companyProductItem.CompanyId
  654. companyDetailView.CompanyName = companyProductItem.CompanyName
  655. companyDetailView.Status = companyProductItem.Status
  656. companyDetailView.IndustryId = companyProductItem.IndustryId
  657. companyDetailView.IndustryName = companyProductItem.IndustryName
  658. companyDetailView.PermissionName = strings.Join(permissionArr, "/")
  659. companyDetailView.ReportReadTotal = readNum //ficc报告-累计阅读次数
  660. }
  661. // 英文客户
  662. if calendarItem.EnglishCompany == 1 {
  663. enItem, e := english_company.GetEnglishCompanyById(calendarItem.CompanyId)
  664. if e != nil {
  665. this.FailWithMessage("搜索客户失败!", "获取英文客户详情失败, GetEnglishCompanyById Err: "+e.Error())
  666. return
  667. }
  668. companyDetailView.CompanyId = enItem.CompanyId
  669. companyDetailView.CompanyName = enItem.CompanyName
  670. companyDetailView.Status = "正常"
  671. companyDetailView.EnglishCompany = 1
  672. companyDetailView.EnglishCountry = enItem.Country
  673. companyDetailView.EnglishViewTotal = enItem.ViewTotal
  674. }
  675. }
  676. resp := new(roadshow.CalendarDetailResp)
  677. resp.RsCalendarItem = calendarItem
  678. resp.RsCalendarResearcherItem = rsCalendarResearcherItem
  679. resp.CompanyDetail = companyDetailView
  680. this.OkDetailed(resp, "获取成功")
  681. }
  682. // @Title 事项列表
  683. // @Description 事项列表接口
  684. // @Param PageSize query int true "每页数据条数"
  685. // @Param CurrentIndex query int true "当前页页码,从1开始"
  686. // @Success 200 {object} rs.MattersListResp
  687. // @router /matters/list [get]
  688. func (this *CalendarController) MattersList() {
  689. sysUser := this.AdminWx
  690. if sysUser == nil {
  691. this.FailWithMessage("请登录", "请登录,SysUser Is Empty")
  692. return
  693. }
  694. pageSize, _ := this.GetInt("PageSize")
  695. currentIndex, _ := this.GetInt("CurrentIndex")
  696. var total int
  697. page := paging.GetPaging(currentIndex, pageSize, total)
  698. var startSize int
  699. if pageSize <= 0 {
  700. pageSize = utils.PageSize10
  701. }
  702. if currentIndex <= 0 {
  703. currentIndex = 1
  704. }
  705. startSize = paging.StartIndex(currentIndex, pageSize)
  706. var condition string
  707. var pars []interface{}
  708. condition += ` AND a.sys_user_id=?`
  709. pars = append(pars, sysUser.AdminId)
  710. resp := new(roadshow.MattersListResp)
  711. total, err := roadshow.GetMattersListCount(condition, pars)
  712. if err != nil && err.Error() != utils.ErrNoRow() {
  713. this.FailWithMessage("获取事项信息失败", "获取事项信息失败,GetMattersListCount,Err:"+err.Error())
  714. return
  715. }
  716. page = paging.GetPaging(currentIndex, pageSize, total)
  717. dataList, err := roadshow.GetMattersList(condition, pars, startSize, pageSize)
  718. if err != nil {
  719. this.FailWithMessage("获取事项信息失败", "获取事项信息失败,GetMattersList,Err:"+err.Error())
  720. return
  721. }
  722. // 按钮权限,超过14天无按钮
  723. now := time.Now().Local()
  724. for _, v := range dataList {
  725. // 结束日期14天后无编辑删除按钮权限
  726. t := fmt.Sprintf("%s %s", v.EndDate, v.EndTime)
  727. ed, e := time.ParseInLocation(utils.FormatDateTime, t, time.Local)
  728. if e != nil {
  729. this.FailWithMessage("事项结束日期有误", "事项结束日期有误, Err:"+err.Error())
  730. return
  731. }
  732. ed = ed.AddDate(0, 0, 14)
  733. if ed.Before(now) {
  734. v.ButtonAuth.EditDisabled = true
  735. v.ButtonAuth.RemoveDisabled = true
  736. }
  737. }
  738. resp.Paging = page
  739. resp.List = dataList
  740. this.OkDetailed(resp, "获取成功")
  741. }
  742. // @Title 新增事项接口
  743. // @Description 新增事项接口
  744. // @Param request body rs.AddMattersReq true "type json string"
  745. // @Success Ret=200 保存成功
  746. // @router /matters/add [post]
  747. func (this *CalendarController) MattersAdd() {
  748. sysUser := this.AdminWx
  749. if sysUser == nil {
  750. this.FailWithMessage("请登录", "请登录,SysUser Is Empty")
  751. return
  752. }
  753. deleteCache := true
  754. cacheKey := "CACHE_RS_MATTERS_ADD_" + strconv.Itoa(sysUser.AdminId)
  755. defer func() {
  756. if deleteCache {
  757. utils.Rc.Delete(cacheKey)
  758. }
  759. }()
  760. if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
  761. deleteCache = false
  762. this.FailWithMessage("系统处理中,请稍后重试!", "系统处理中,请稍后重试!"+sysUser.RealName+";data:"+string(this.Ctx.Input.RequestBody))
  763. return
  764. }
  765. var req roadshow.AddMattersReq
  766. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  767. if err != nil {
  768. this.FailWithMessage("参数解析异常", "参数解析失败,Err:"+err.Error())
  769. return
  770. }
  771. if req.StartDate == "" {
  772. this.FailWithMessage("请选择开始日期!", "请选择开始日期!")
  773. return
  774. }
  775. if req.EndDate == "" {
  776. this.FailWithMessage("请选择结束日期!", "请选择结束日期!")
  777. return
  778. }
  779. if req.StartTime == "" {
  780. this.FailWithMessage("请选择开始时间!", "请选择开始时间!")
  781. return
  782. }
  783. if req.EndTime == "" {
  784. this.FailWithMessage("请选择结束时间!", "请选择结束时间!")
  785. return
  786. }
  787. if req.StartWeek == "" {
  788. this.FailWithMessage("请选择周!", "请选择周!")
  789. return
  790. }
  791. if req.EndWeek == "" {
  792. this.FailWithMessage("请选择周!", "请选择周!")
  793. return
  794. }
  795. if req.MatterContent == "" {
  796. this.FailWithMessage("请选择研究员!", "请选择研究员!")
  797. return
  798. }
  799. // 是否为销售
  800. sales := isSellerRole(sysUser.RoleTypeCode)
  801. startDateTime := req.StartDate + " " + req.StartTime
  802. endDateTime := req.EndDate + " " + req.EndTime
  803. //校验事项时间冲突
  804. {
  805. matterCount, err := rs.CheckMatters(startDateTime, endDateTime, sysUser.AdminId, 0)
  806. if err != nil {
  807. this.FailWithMessage("时间冲突检测失败!", "时间冲突检测失败-CheckMattersCount!Err:"+err.Error())
  808. return
  809. }
  810. if matterCount > 0 {
  811. this.FailWithMessage("当前时间已被占用!", "时间冲突检测失败-CheckMattersCount!")
  812. return
  813. }
  814. }
  815. if !sales {
  816. //校验活动时间冲突--待接受
  817. {
  818. calendarCount, err := rs.CheckCalendar(startDateTime, endDateTime, "1", sysUser.AdminId, 0)
  819. if err != nil {
  820. this.FailWithMessage("时间冲突检测失败!", "时间冲突检测失败-CheckCalendarResearcherCount!Err:"+err.Error())
  821. return
  822. }
  823. if calendarCount > 0 {
  824. this.FailWithMessage("当前时间与待处理的申请有冲突,请与相关销售沟通!", "时间冲突检测失败-CheckCalendarResearcherCount!")
  825. return
  826. }
  827. }
  828. //校验活动时间冲突--已接受
  829. {
  830. calendarCount, err := rs.CheckCalendar(startDateTime, endDateTime, "2", sysUser.AdminId, 0)
  831. if err != nil {
  832. this.FailWithMessage("时间冲突检测失败!", "时间冲突检测失败-CheckCalendarResearcherCount!Err:"+err.Error())
  833. return
  834. }
  835. if calendarCount > 0 {
  836. this.FailWithMessage("当前时间已被占用!", "时间冲突检测失败-CheckCalendarResearcherCount!")
  837. return
  838. }
  839. }
  840. }
  841. startP, _ := time.ParseInLocation(utils.FormatDateTime, startDateTime, time.Local)
  842. endP, _ := time.ParseInLocation(utils.FormatDateTime, endDateTime, time.Local)
  843. if startP.Before(time.Now()) || startP.Equal(time.Now()) {
  844. this.FailWithMessage("事项开始时间不能小于当前时间!", "事项开始时间不能小于当前时间!")
  845. return
  846. }
  847. if endP.Before(time.Now()) || endP.Equal(time.Now()) {
  848. this.FailWithMessage("事项结束时间不能小于当前时间!", "事项结束时间不能小于当前时间!")
  849. return
  850. }
  851. if startP.After(endP) || startP.Equal(endP) {
  852. this.FailWithMessage("事项开始时间应小于结束时间!", "事项开始时间应小于结束时间!")
  853. return
  854. }
  855. item := new(roadshow.RsMatters)
  856. item.SysUserId = sysUser.AdminId
  857. item.SysUserRealName = sysUser.RealName
  858. item.StartDate = req.StartDate
  859. item.EndDate = req.EndDate
  860. item.StartTime = req.StartTime
  861. item.EndTime = req.EndTime
  862. item.StartWeek = req.StartWeek
  863. item.EndWeek = req.EndWeek
  864. item.MatterContent = req.MatterContent
  865. item.Status = 1
  866. item.CreateTime = time.Now()
  867. item.ModifyTime = time.Now()
  868. if sales {
  869. item.IsSeller = 1
  870. }
  871. id, err := roadshow.AddRsMatters(item)
  872. if err != nil {
  873. this.FailWithMessage("保存失败!", "保存失败,AddRsMatters Err:"+err.Error())
  874. return
  875. }
  876. item.RsMattersId = int(id)
  877. // 销售的事项不同步上海
  878. if !sales {
  879. go rs.MatterToSH(*item)
  880. }
  881. this.OkDetailed(nil, "保存成功")
  882. }
  883. // @Title 修改事项接口
  884. // @Description 修改事项接口
  885. // @Param request body rs.UpdateMattersReq true "type json string"
  886. // @Success Ret=200 保存成功
  887. // @router /matters/update [post]
  888. func (this *CalendarController) MattersUpdate() {
  889. sysUser := this.AdminWx
  890. if sysUser == nil {
  891. this.FailWithMessage("请登录", "请登录,SysUser Is Empty")
  892. return
  893. }
  894. deleteCache := true
  895. cacheKey := "CACHE_RS_MATTERS_UPDATE_" + strconv.Itoa(sysUser.AdminId)
  896. defer func() {
  897. if deleteCache {
  898. utils.Rc.Delete(cacheKey)
  899. }
  900. }()
  901. if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
  902. deleteCache = false
  903. this.FailWithMessage("系统处理中,请稍后重试!", "系统处理中,请稍后重试!")
  904. return
  905. }
  906. var req roadshow.UpdateMattersReq
  907. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  908. if err != nil {
  909. this.FailWithMessage("参数解析失败!", "参数解析失败,Err:"+err.Error())
  910. return
  911. }
  912. updateParams := make(map[string]interface{})
  913. if req.RsMattersId <= 0 {
  914. this.FailWithMessage("参数错误!", "参数错误")
  915. return
  916. }
  917. if req.StartDate == "" {
  918. this.FailWithMessage("请选择开始日期!", "请选择开始日期")
  919. return
  920. } else {
  921. updateParams["start_date"] = req.StartDate
  922. }
  923. if req.EndDate == "" {
  924. this.FailWithMessage("请选择结束日期!", "请选择结束日期")
  925. return
  926. } else {
  927. updateParams["end_date"] = req.EndDate
  928. }
  929. if req.StartTime == "" {
  930. this.FailWithMessage("请选择开始时间!", "请选择开始时间")
  931. return
  932. } else {
  933. updateParams["start_time"] = req.StartTime
  934. }
  935. if req.EndTime == "" {
  936. this.FailWithMessage("请选择结束时间!", "请选择结束时间")
  937. return
  938. } else {
  939. updateParams["end_time"] = req.EndTime
  940. }
  941. if req.StartWeek == "" {
  942. this.FailWithMessage("请选择周!", "请选择周")
  943. return
  944. } else {
  945. updateParams["start_week"] = req.StartWeek
  946. }
  947. if req.EndWeek == "" {
  948. this.FailWithMessage("请选择周!", "请选择周")
  949. return
  950. } else {
  951. updateParams["end_week"] = req.EndWeek
  952. }
  953. if req.MatterContent == "" {
  954. this.FailWithMessage("请选择研究员!", "请选择研究员")
  955. return
  956. } else {
  957. updateParams["matter_content"] = req.MatterContent
  958. }
  959. req.EditReason = strings.TrimSpace(req.EditReason)
  960. if req.EditReason == "" {
  961. this.FailWithMessage("请填写修改原因!", "请填写修改原因")
  962. return
  963. }
  964. updateParams["edit_reason"] = req.EditReason
  965. startDateTime := req.StartDate + " " + req.StartTime
  966. endDateTime := req.EndDate + " " + req.EndTime
  967. startP, _ := time.ParseInLocation(utils.FormatDateTime, startDateTime, time.Local)
  968. endP, _ := time.ParseInLocation(utils.FormatDateTime, endDateTime, time.Local)
  969. if startP.Before(time.Now()) || startP.Equal(time.Now()) {
  970. this.FailWithMessage("事项开始时间不能小于当前时间!", "事项开始时间不能小于当前时间!")
  971. return
  972. }
  973. if endP.Before(time.Now()) || endP.Equal(time.Now()) {
  974. this.FailWithMessage("事项结束时间不能小于当前时间!", "事项结束时间不能小于当前时间!")
  975. return
  976. }
  977. if startP.After(endP) || startP.Equal(endP) {
  978. this.FailWithMessage("事项开始时间应小于结束时间!", "事项开始时间应小于结束时间!")
  979. return
  980. }
  981. // 结束后14天不可再编辑
  982. endP = endP.AddDate(0, 0, 14)
  983. if endP.Before(time.Now().Local()) {
  984. this.FailWithMessage("事项结束14天后不可再编辑!", "事项结束14天后不可再编辑!")
  985. return
  986. }
  987. matterItem, err := roadshow.GetMattersById(req.RsMattersId)
  988. if err != nil {
  989. this.FailWithMessage("保存失败!", "保存失败,GetMattersById,Err:"+err.Error())
  990. return
  991. }
  992. // 是否为销售
  993. sales := isSellerRole(sysUser.RoleTypeCode)
  994. //校验事项时间冲突
  995. {
  996. if matterItem != nil && (matterItem.StartDate != req.StartDate ||
  997. matterItem.StartTime != req.StartTime ||
  998. matterItem.EndDate != req.EndDate ||
  999. matterItem.EndTime != req.EndTime) {
  1000. matterCount, err := rs.CheckMatters(startDateTime, endDateTime, sysUser.AdminId, matterItem.RsMattersId)
  1001. if err != nil {
  1002. this.FailWithMessage("时间冲突检测失败!", "时间冲突检测失败-CheckMattersCount!Err:"+err.Error())
  1003. return
  1004. }
  1005. if matterCount > 0 {
  1006. this.FailWithMessage("时间冲突,已存在时间段内的事项!", "时间冲突检测失败-CheckMattersCount!")
  1007. return
  1008. }
  1009. }
  1010. }
  1011. if !sales {
  1012. //校验活动时间冲突--待接受
  1013. {
  1014. calendarCount, err := rs.CheckCalendar(startDateTime, endDateTime, "1", sysUser.AdminId, 0)
  1015. if err != nil {
  1016. this.FailWithMessage("时间冲突检测失败!", "时间冲突检测失败-CheckCalendarResearcherCount!Err:"+err.Error())
  1017. return
  1018. }
  1019. if calendarCount > 0 {
  1020. this.FailWithMessage("当前时间与待处理的申请有冲突,请与相关销售沟通!", "时间冲突检测失败-CheckCalendarResearcherCount!")
  1021. return
  1022. }
  1023. }
  1024. //校验活动时间冲突--待接受
  1025. {
  1026. calendarCount, err := rs.CheckCalendar(startDateTime, endDateTime, "2", sysUser.AdminId, 0)
  1027. if err != nil {
  1028. this.FailWithMessage("时间冲突检测失败!", "时间冲突检测失败-CheckCalendarResearcherCount!Err:"+err.Error())
  1029. return
  1030. }
  1031. if calendarCount > 0 {
  1032. this.FailWithMessage("时间冲突,已存在时间段内的活动!", "时间冲突检测失败-CheckCalendarResearcherCount!")
  1033. return
  1034. }
  1035. }
  1036. }
  1037. whereParams := make(map[string]interface{})
  1038. whereParams["rs_matters_id"] = req.RsMattersId
  1039. updateParams["modify_time"] = time.Now()
  1040. err = roadshow.UpdateRsMatters(whereParams, updateParams)
  1041. if err != nil {
  1042. this.FailWithMessage("保存失败!", "保存失败!UpdateRsMatters:"+err.Error())
  1043. return
  1044. }
  1045. // 销售不做上海那边的处理
  1046. if !sales {
  1047. go rs.UpdateSHCalendarByMatter(req)
  1048. }
  1049. this.OkDetailed(nil, "保存成功")
  1050. }
  1051. // @Title 删除事项接口
  1052. // @Description 删除事项接口
  1053. // @Param request body rs.DeleteMattersReq true "type json string"
  1054. // @Success Ret=200 保存成功
  1055. // @router /matters/delete [post]
  1056. func (this *CalendarController) MattersDelete() {
  1057. sysUser := this.AdminWx
  1058. if sysUser == nil {
  1059. this.FailWithMessage("请登录", "请登录,SysUser Is Empty")
  1060. return
  1061. }
  1062. var req roadshow.DeleteMattersReq
  1063. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1064. if err != nil {
  1065. this.FailWithMessage("参数解析失败", "参数解析失败,Err:"+err.Error())
  1066. return
  1067. }
  1068. if req.RsMattersId <= 0 {
  1069. this.FailWithMessage("参数错误", "参数错误")
  1070. return
  1071. }
  1072. matters, e := roadshow.GetMattersById(req.RsMattersId)
  1073. if e != nil {
  1074. if e.Error() == utils.ErrNoRow() {
  1075. this.FailWithMessage("事项已被删除, 请刷新页面", "事项已被删除, 请刷新页面")
  1076. return
  1077. }
  1078. this.FailWithMessage("操作失败", "获取事项失败, Err: "+e.Error())
  1079. return
  1080. }
  1081. // 事项结束14天后不可再删除
  1082. t := fmt.Sprintf("%s %s", matters.EndDate, matters.EndTime)
  1083. ed, _ := time.ParseInLocation(utils.FormatDateTime, t, time.Local)
  1084. ed = ed.AddDate(0, 0, 14)
  1085. if ed.Before(time.Now().Local()) {
  1086. this.FailWithMessage("事项结束14天后不可再删除", "事项结束14天后不可再删除")
  1087. return
  1088. }
  1089. err = roadshow.DeleteRsMatters(req.RsMattersId)
  1090. if err != nil {
  1091. this.FailWithMessage("保存失败", "保存失败!DeleteRsMatters:"+err.Error())
  1092. return
  1093. }
  1094. // 是否为销售
  1095. sales := isSellerRole(sysUser.RoleTypeCode)
  1096. // 删除上海的路演活动, 销售不同步
  1097. if !sales {
  1098. go rs.DeleteSHMatter(req.RsMattersId)
  1099. }
  1100. this.OkDetailed(nil, "删除成功")
  1101. }
  1102. func getTitle(activityType, roadshowType, activityCategory, roadshowPlatform, province, city string) string {
  1103. var title string
  1104. switch activityType {
  1105. case "内部会议":
  1106. title = "内部会议"
  1107. case "公开会议", "路演", "沙龙":
  1108. if roadshowType == "线上" {
  1109. title = roadshowType + activityType + roadshowPlatform
  1110. } else {
  1111. title = roadshowType + activityType + province + city
  1112. }
  1113. case "报告电话会":
  1114. title = activityCategory + "电话会"
  1115. }
  1116. return title
  1117. }
  1118. // @Title 编辑路演活动接口
  1119. // @Description编辑路演活动接口
  1120. // @Param request body rs.EditActivityReq true "type json string"
  1121. // @Success Ret=200 保存成功
  1122. // @router /edit [post]
  1123. func (this *CalendarController) Edit() {
  1124. sysUser := this.AdminWx
  1125. if sysUser == nil {
  1126. this.FailWithMessage("请登录", "请登录,SysUser Is Empty")
  1127. return
  1128. }
  1129. deleteCache := true
  1130. cacheKey := "CACHE_RS_ACTIVITY_EDIT_" + strconv.Itoa(sysUser.AdminId)
  1131. defer func() {
  1132. if deleteCache {
  1133. utils.Rc.Delete(cacheKey)
  1134. }
  1135. }()
  1136. if !utils.Rc.SetNX(cacheKey, 1, 3*time.Second) {
  1137. deleteCache = false
  1138. this.FailWithMessage("系统处理中,请稍后重试!", "系统处理中,请稍后重试!"+sysUser.RealName+";data:"+string(this.Ctx.Input.RequestBody))
  1139. return
  1140. }
  1141. var req roadshow.EditActivityReq
  1142. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1143. if err != nil {
  1144. this.FailWithMessage("参数解析异常", "参数解析失败,Err:"+err.Error())
  1145. return
  1146. }
  1147. if req.RsCalendarId <= 0 {
  1148. this.FailWithMessage("参数错误", "RsCalendarId<=0")
  1149. return
  1150. }
  1151. if req.RsCalendarResearcherId <= 0 {
  1152. this.FailWithMessage("参数错误", "RsCalendarResearcherId<=0")
  1153. return
  1154. }
  1155. if req.ActivityType == "" {
  1156. this.FailWithMessage("请选择活动类型", "请选择活动类型")
  1157. return
  1158. }
  1159. if len(req.ResearcherList) <= 0 {
  1160. this.FailWithMessage("请选择研究员!", "请选择研究员!")
  1161. return
  1162. }
  1163. researcherMap := make(map[int]string)
  1164. var checkIsAdd []string
  1165. for _, v := range req.ResearcherList {
  1166. if v.ResearcherId <= 0 {
  1167. this.FailWithMessage("请选择研究员!", "请选择研究员!")
  1168. return
  1169. }
  1170. if v.ResearcherName == "" {
  1171. this.FailWithMessage("请选择研究员!", "请选择研究员!")
  1172. return
  1173. }
  1174. if v.StartDate == "" {
  1175. this.FailWithMessage("请选择开始日期!", "请选择开始日期!")
  1176. return
  1177. }
  1178. if v.EndDate == "" {
  1179. this.FailWithMessage("请选择结束日期!", "请选择结束日期!")
  1180. return
  1181. }
  1182. if v.StartTime == "" {
  1183. this.FailWithMessage("请选择开始时间!", "请选择开始时间!")
  1184. return
  1185. }
  1186. if v.EndTime == "" {
  1187. this.FailWithMessage("请选择结束时间!", "请选择结束时间!")
  1188. return
  1189. }
  1190. if v.StartWeek == "" {
  1191. this.FailWithMessage("请选择周!", "请选择周!")
  1192. return
  1193. }
  1194. if v.EndWeek == "" {
  1195. this.FailWithMessage("请选择周!", "请选择周!")
  1196. return
  1197. }
  1198. if realName, ok := researcherMap[v.ResearcherId]; ok {
  1199. this.FailWithMessage("研究员:"+realName+" 被重复选择", "研究员:"+realName+" 被重复选择")
  1200. return
  1201. }
  1202. researcherMap[v.ResearcherId] = v.ResearcherName
  1203. startDateTime := v.StartDate + " " + v.StartTime
  1204. endDateTime := v.EndDate + " " + v.EndTime
  1205. startP, _ := time.ParseInLocation(utils.FormatDateTime, startDateTime, time.Local)
  1206. endP, _ := time.ParseInLocation(utils.FormatDateTime, endDateTime, time.Local)
  1207. if startP.Before(time.Now()) || startP.Equal(time.Now()) {
  1208. this.FailWithMessage("活动开始时间不能小于当前时间!", "活动开始时间不能小于当前时间!")
  1209. return
  1210. }
  1211. if endP.Before(time.Now()) || endP.Equal(time.Now()) {
  1212. this.FailWithMessage("活动结束时间不能小于当前时间!", "活动结束时间不能小于当前时间!")
  1213. return
  1214. }
  1215. if startP.After(endP) || startP.Equal(endP) {
  1216. this.FailWithMessage("活动开始时间应小于结束时间!", "活动开始时间应小于结束时间!")
  1217. return
  1218. }
  1219. /*
  1220. 时间冲突时,提示:xxx时间已被占用
  1221. 当有任意一个研究员时间有冲突时,所有申请订单都不发送。
  1222. */
  1223. rsCalendarResearcherItem, err := roadshow.GetRsCalendarResearcherByRsCalendarIdAndResearcherId(req.RsCalendarId, v.ResearcherId)
  1224. var isAdd bool
  1225. if err != nil {
  1226. if err.Error() == utils.ErrNoRow() {
  1227. isAdd = true
  1228. } else {
  1229. this.FailWithMessage("获取数据失败!", "获取数据失败!GetRsCalendarResearcherByRsCalendarIdAndResearcherId:"+err.Error())
  1230. return
  1231. }
  1232. }
  1233. var rsCalendarResearcherId int
  1234. if rsCalendarResearcherItem == nil {
  1235. isAdd = true
  1236. } else {
  1237. rsCalendarResearcherId = rsCalendarResearcherItem.RsCalendarResearcherId
  1238. }
  1239. //同步上海数据
  1240. researcherInfo, err := admin.GetAdminById(v.ResearcherId)
  1241. if err != nil {
  1242. this.FailWithMessage("研究员异常!", "研究员异常,Err:"+err.Error())
  1243. return
  1244. }
  1245. _ = rs.SyncCalendarFromShanghai(researcherInfo.Mobile, v.StartDate, v.EndDate)
  1246. //校验事项时间冲突
  1247. {
  1248. if isAdd || (rsCalendarResearcherItem != nil && (rsCalendarResearcherItem.StartDate != v.StartDate ||
  1249. rsCalendarResearcherItem.StartTime != v.StartTime ||
  1250. rsCalendarResearcherItem.EndDate != v.EndDate ||
  1251. rsCalendarResearcherItem.EndTime != v.EndTime)) {
  1252. matterCount, err := rs.CheckMatters(startDateTime, endDateTime, v.ResearcherId, 0)
  1253. if err != nil {
  1254. this.FailWithMessage("时间冲突检测失败!", "时间冲突检测失败-CheckMattersCount!Err:"+err.Error())
  1255. return
  1256. }
  1257. if matterCount > 0 {
  1258. checkIsAdd = append(checkIsAdd, v.ResearcherName)
  1259. }
  1260. }
  1261. }
  1262. calendarCount, err := rs.CheckCalendar(startDateTime, endDateTime, "1,2", v.ResearcherId, rsCalendarResearcherId)
  1263. if err != nil {
  1264. this.FailWithMessage("时间冲突检测失败!", "时间冲突检测失败-CheckCalendarResearcherCount!Err:"+err.Error())
  1265. return
  1266. }
  1267. if calendarCount > 0 {
  1268. checkIsAdd = append(checkIsAdd, v.ResearcherName)
  1269. }
  1270. }
  1271. if len(checkIsAdd) > 0 {
  1272. this.FailWithMessage(strings.Join(checkIsAdd, ",")+"时间已被占用!", "时间冲突检测失败-CheckMattersCount!")
  1273. return
  1274. }
  1275. rsCalendarItem, err := roadshow.GetRsCalendarById(req.RsCalendarId)
  1276. if err != nil {
  1277. this.FailWithMessage("获取数据失败!", "获取数据失败!GetRsCalendarById:"+err.Error())
  1278. return
  1279. }
  1280. if rsCalendarItem == nil {
  1281. this.FailWithMessage("保存失败!", "获取数据失败!GetRsCalendarById:"+err.Error())
  1282. return
  1283. }
  1284. calendarWhereParams := make(map[string]interface{})
  1285. calendarUpdateParams := make(map[string]interface{})
  1286. calendarWhereParams["rs_calendar_id"] = req.RsCalendarId
  1287. //if req.ActivityType != "" {
  1288. calendarUpdateParams["activity_type"] = req.ActivityType
  1289. //}
  1290. //if req.RoadshowType != "" {
  1291. calendarUpdateParams["roadshow_type"] = req.RoadshowType
  1292. //}
  1293. //if req.RoadshowPlatform != "" {
  1294. calendarUpdateParams["roadshow_platform"] = req.RoadshowPlatform
  1295. //}
  1296. //if req.CompanyId > 0 {
  1297. calendarUpdateParams["company_id"] = req.CompanyId
  1298. //}
  1299. //if req.CompanyName != "" {
  1300. calendarUpdateParams["company_name"] = req.CompanyName
  1301. //}
  1302. //if req.ActivityCategory != "" {
  1303. calendarUpdateParams["activity_category"] = req.ActivityCategory
  1304. //}
  1305. //if req.Theme != "" {
  1306. calendarUpdateParams["theme"] = req.Theme
  1307. //}
  1308. //if req.CooperationName != "" {
  1309. calendarUpdateParams["cooperation_name"] = req.CooperationName
  1310. //}
  1311. //if req.Province != "" {
  1312. calendarUpdateParams["province"] = req.Province
  1313. // }
  1314. //if req.City != "" {
  1315. calendarUpdateParams["city"] = req.City
  1316. //}
  1317. //if req.District != "" {
  1318. calendarUpdateParams["district"] = req.District
  1319. // }
  1320. calendarUpdateParams["english_company"] = req.EnglishCompany
  1321. calendarUpdateParams["modify_time"] = time.Now()
  1322. calendarUpdateParams["title"] = getTitle(req.ActivityType, req.RoadshowType, req.ActivityCategory, req.RoadshowPlatform, req.Province, req.City)
  1323. err = roadshow.UpdateRsCalendar(calendarWhereParams, calendarUpdateParams)
  1324. if err != nil {
  1325. this.FailWithMessage("保存失败!", "保存失败!UpdateRsCalendar:"+err.Error())
  1326. return
  1327. }
  1328. existList, err := roadshow.GetRsCalendarResearcherByCalendarId(req.RsCalendarId)
  1329. if err != nil {
  1330. this.FailWithMessage("保存失败!", "保存失败!GetRsCalendarResearcherByCalendarId:"+err.Error())
  1331. return
  1332. }
  1333. existResearcherMap := make(map[int]string)
  1334. for _, ev := range existList {
  1335. existResearcherMap[ev.ResearcherId] = ev.ResearcherName
  1336. }
  1337. sysUserList, err := cygx.GetAskEmailList()
  1338. if err != nil {
  1339. this.FailWithMessage("获取失败!", "获取失败,GetAskEmailList Err:"+err.Error())
  1340. return
  1341. }
  1342. raiAskadminMap := make(map[int]bool, 0)
  1343. for _, v := range sysUserList {
  1344. raiAskadminMap[v.AdminId] = true
  1345. }
  1346. if rsCalendarItem.ActivityType == "路演" || rsCalendarItem.ActivityType == "公开会议" {
  1347. // 更新研究员信息
  1348. //go roadshowService.UpdateSHCalendar(req.RsCalendarId, req.RsCalendarResearcherId, req.ActivityType, req.RoadshowType, req.ActivityCategory, req.RoadshowPlatform, req.Province, req.City, req.ResearcherList)
  1349. for k, v := range req.ResearcherList {
  1350. rsCalendarResearcherItem, err := roadshow.GetRsCalendarResearcherById(req.RsCalendarResearcherId)
  1351. if err != nil {
  1352. this.FailWithMessage("获取数据失败!", "获取数据失败!GetRsCalendarResearcherById:"+err.Error())
  1353. return
  1354. }
  1355. calendarResearcherWhereParams := make(map[string]interface{})
  1356. calendarResearcherUpdateParams := make(map[string]interface{})
  1357. calendarResearcherWhereParams["rs_calendar_researcher_id"] = req.RsCalendarResearcherId
  1358. calendarResearcherUpdateParams["researcher_id"] = v.ResearcherId
  1359. calendarResearcherUpdateParams["researcher_name"] = v.ResearcherName
  1360. if rsCalendarResearcherItem.Status == 3 || rsCalendarResearcherItem.Status == 5 {
  1361. calendarResearcherUpdateParams["status"] = 1
  1362. }
  1363. //CRM15.5 权益研究员直接通过
  1364. if raiAskadminMap[v.ResearcherId] {
  1365. calendarResearcherUpdateParams["status"] = 2
  1366. rsCalendarResearcherItem.Status = 2
  1367. }
  1368. calendarResearcherUpdateParams["start_date"] = v.StartDate
  1369. calendarResearcherUpdateParams["end_date"] = v.EndDate
  1370. calendarResearcherUpdateParams["start_time"] = v.StartTime
  1371. calendarResearcherUpdateParams["end_time"] = v.EndTime
  1372. calendarResearcherUpdateParams["start_week"] = v.StartWeek
  1373. calendarResearcherUpdateParams["end_week"] = v.EndWeek
  1374. calendarResearcherUpdateParams["refuse_reason"] = ""
  1375. calendarResearcherUpdateParams["refuse_time"] = nil
  1376. calendarResearcherUpdateParams["delete_reason"] = ""
  1377. calendarResearcherUpdateParams["approve_time"] = nil
  1378. calendarResearcherUpdateParams["researcher_sort"] = k + 1
  1379. calendarResearcherUpdateParams["modify_time"] = time.Now()
  1380. calendarResearcherUpdateParams["create_time"] = time.Now()
  1381. err = roadshow.UpdateCalendarResearcher(calendarResearcherWhereParams, calendarResearcherUpdateParams)
  1382. if err != nil {
  1383. this.FailWithMessage("保存失败!", "保存失败!UpdateCalendarResearcher:"+err.Error())
  1384. return
  1385. }
  1386. //上海新增(因为在驳回的时候,就把上海该时间段的日程给删除了,所以修改的时候,需要重新调用新增接口)
  1387. calendar := roadshow.RsCalendar{
  1388. RsCalendarId: req.RsCalendarId,
  1389. SysUserId: sysUser.AdminId,
  1390. Title: getTitle(req.ActivityType, req.RoadshowType, req.ActivityCategory, req.RoadshowPlatform, req.Province, req.City),
  1391. }
  1392. researcher := *rsCalendarResearcherItem
  1393. researcher.StartDate = v.StartDate
  1394. researcher.EndDate = v.EndDate
  1395. researcher.StartTime = v.StartTime
  1396. researcher.EndTime = v.EndTime
  1397. researcher.StartWeek = v.StartWeek
  1398. researcher.EndWeek = v.EndWeek
  1399. go rs.CalendarToSH(calendar, researcher)
  1400. if req.EditType == 2 {
  1401. //模板消息通知
  1402. go func(researcherId, tmpRsCalendarId, tmpRsCalendarResearcherId int) {
  1403. sysAdmin, _ := admin.GetAdminById(researcherId)
  1404. if sysAdmin != nil && req.ActivityType != "内部会议" && req.ActivityType != "报告电话会" {
  1405. first := "您收到一个新的【" + req.ActivityType + "】申请,请及时处理"
  1406. keyword1 := sysUser.RealName
  1407. keyword2 := "--"
  1408. //keyword3 := time.Now().Format(utils.FormatDateTime)
  1409. startDateSub := v.StartDate[5:]
  1410. startDateSub = strings.Replace(startDateSub, "-", ".", -1)
  1411. keyword3 := startDateSub + "(" + v.StartWeek + ")" + " " + v.StartTime[:5] + "~" + v.EndTime[:5]
  1412. var keyword4 string
  1413. if req.ActivityType == "路演" {
  1414. keyword4 = req.CompanyName + "(" + req.RoadshowType + req.ActivityType + ")"
  1415. } else {
  1416. keyword4 = req.Theme + "(" + req.RoadshowType + req.ActivityType + ")"
  1417. }
  1418. remark := "请尽快完成审批"
  1419. wxAppPath := "pages-approve/activity/detail?RsCalendarId=" + strconv.Itoa(req.RsCalendarId) + "&RsCalendarResearcherId=" + strconv.Itoa(tmpRsCalendarResearcherId)
  1420. if sysAdmin.OpenId != "" {
  1421. services.SendWxMsgWithRoadshowPending(first, keyword1, keyword2, keyword3, keyword4, remark, wxAppPath, sysAdmin.Mobile)
  1422. }
  1423. }
  1424. }(v.ResearcherId, req.RsCalendarId, rsCalendarResearcherItem.RsCalendarResearcherId)
  1425. }
  1426. }
  1427. } else {
  1428. //先获取到所有的研究员日历表id
  1429. researchers, err := roadshow.GetRsCalendarResearcherByCalendarId(req.RsCalendarId)
  1430. if err != nil {
  1431. utils.FileLog.Info("GetRsCalendarResearcherByCalendarId err: ", err)
  1432. fmt.Println(err)
  1433. this.FailWithMessage("保存失败!", "获取数据失败,GetRsCalendarResearcherByCalendarId:"+err.Error())
  1434. return
  1435. }
  1436. //先删后增
  1437. err = roadshow.DeleteRsCalendarResearcher(req.RsCalendarId)
  1438. if err != nil {
  1439. this.FailWithMessage("保存失败!", "保存失败!DeleteRsCalendarResearcher:"+err.Error())
  1440. return
  1441. }
  1442. //删除上海
  1443. for _, researcher := range researchers {
  1444. rs.DeleteSHCalendar(researcher.RsCalendarResearcherId)
  1445. }
  1446. for k, v := range req.ResearcherList {
  1447. researcher := new(roadshow.RsCalendarResearcher)
  1448. researcher.RsCalendarId = req.RsCalendarId
  1449. researcher.ResearcherId = v.ResearcherId
  1450. researcher.ResearcherName = v.ResearcherName
  1451. researcher.StartDate = v.StartDate
  1452. researcher.EndDate = v.EndDate
  1453. researcher.StartTime = v.StartTime
  1454. researcher.EndTime = v.EndTime
  1455. researcher.StartWeek = v.StartWeek
  1456. researcher.EndWeek = v.EndWeek
  1457. researcher.CreateTime = time.Now()
  1458. researcher.ModifyTime = time.Now()
  1459. researcher.ResearcherSort = k + 1
  1460. if req.ActivityType == "路演" || req.ActivityType == "公开会议" {
  1461. researcher.Status = 1
  1462. } else {
  1463. researcher.Status = 2
  1464. }
  1465. //CRM15.5 权益研究员直接通过
  1466. if raiAskadminMap[v.ResearcherId] {
  1467. researcher.Status = 2
  1468. }
  1469. rsCalendarResearcherId, err := roadshow.AddRsCalendarResearcher(researcher)
  1470. if err != nil {
  1471. this.FailWithMessage("保存失败!", "保存日历活动-研究员信息失败!Err:"+err.Error())
  1472. return
  1473. }
  1474. //上海新增
  1475. calendar := roadshow.RsCalendar{
  1476. RsCalendarId: req.RsCalendarId,
  1477. SysUserId: sysUser.AdminId,
  1478. Title: getTitle(req.ActivityType, req.RoadshowType, req.ActivityCategory, req.RoadshowPlatform, req.Province, req.City),
  1479. }
  1480. researcher.RsCalendarResearcherId = int(rsCalendarResearcherId)
  1481. go rs.CalendarToSH(calendar, *researcher)
  1482. go func(researcherId, tmpRsCalendarId, tmpRsCalendarResearcherId int) {
  1483. sysAdmin, _ := admin.GetAdminById(researcherId)
  1484. if sysAdmin != nil && req.ActivityType != "内部会议" && req.ActivityType != "报告电话会" {
  1485. first := "您收到一个新的【" + req.ActivityType + "】申请,请及时处理"
  1486. keyword1 := sysUser.RealName
  1487. keyword2 := "--"
  1488. keyword3 := time.Now().Format(utils.FormatDateTime)
  1489. startDateSub := v.StartDate[5:]
  1490. startDateSub = strings.Replace(startDateSub, "-", ".", -1)
  1491. //keyword3 := startDateSub + "(" + v.StartWeek + ")" + " " + v.StartTime[:5] + "~" + v.EndTime[:5]
  1492. var keyword4 string
  1493. if req.ActivityType == "路演" {
  1494. keyword4 = req.CompanyName + "(" + req.RoadshowType + req.ActivityType + ")"
  1495. } else {
  1496. keyword4 = req.Theme + "(" + req.RoadshowType + req.ActivityType + ")"
  1497. }
  1498. remark := "请尽快完成审批"
  1499. wxAppPath := "pages-approve/activity/detail?RsCalendarId=" + strconv.Itoa(tmpRsCalendarId) + "&RsCalendarResearcherId=" + strconv.Itoa(tmpRsCalendarResearcherId)
  1500. if sysAdmin.OpenId != "" {
  1501. services.SendWxMsgWithRoadshowPending(first, keyword1, keyword2, keyword3, keyword4, remark, wxAppPath, sysAdmin.Mobile)
  1502. }
  1503. }
  1504. }(v.ResearcherId, req.RsCalendarId, int(rsCalendarResearcherId))
  1505. }
  1506. }
  1507. this.OkDetailed(nil, "保存成功")
  1508. }
  1509. // ResearcherList
  1510. // @Title 研究员列表
  1511. // @Description 研究员列表接口
  1512. // @Success 200 {object} rs.ResearcherGroup
  1513. // @router /researcher/list [get]
  1514. func (this *CalendarController) ResearcherList() {
  1515. sysUser := this.AdminWx
  1516. if sysUser == nil {
  1517. this.FailWithMessage("请登录", "请登录,SysUser Is Empty")
  1518. return
  1519. }
  1520. group, err := roadshow.GetResearcherGroup()
  1521. if err != nil {
  1522. this.FailWithMessage("获取信息失败!", "获取分组信息失败!Err:"+err.Error())
  1523. return
  1524. }
  1525. researcherList, err := roadshow.GetResearcher()
  1526. groupMap := make(map[int][]*roadshow.ResearcherGroup)
  1527. for _, v := range researcherList {
  1528. item := &roadshow.ResearcherGroup{
  1529. GroupId: v.GroupId,
  1530. GroupName: v.GroupName,
  1531. AdminId: v.AdminId,
  1532. RealName: v.RealName,
  1533. RoleTypeCode: v.RoleTypeCode,
  1534. }
  1535. if findItems, ok := groupMap[v.GroupId]; ok {
  1536. findItems = append(findItems, item)
  1537. groupMap[v.GroupId] = findItems
  1538. } else {
  1539. findItems = append(findItems, item)
  1540. groupMap[v.GroupId] = findItems
  1541. }
  1542. //}
  1543. }
  1544. for _, v := range group {
  1545. v.ResearcherList = groupMap[v.GroupId]
  1546. }
  1547. ficcGroup := new(roadshow.ResearcherGroup)
  1548. ficcGroup.GroupId = 999
  1549. ficcGroup.GroupName = "ficc"
  1550. ficcGroup.ResearcherList = group
  1551. sysUserList, err := system.GetAdminList()
  1552. if err != nil {
  1553. this.FailWithMessage("获取失败!", "获取失败,获取admin列表失败 Err:"+err.Error())
  1554. return
  1555. }
  1556. adminMap := make(map[int]*system.AdminItem, 0)
  1557. for _, v := range sysUserList {
  1558. adminMap[v.AdminId] = v
  1559. }
  1560. askUserList, err := cygx.GetAskEmailList()
  1561. if err != nil {
  1562. this.FailWithMessage("获取失败!", "获取失败,GetAskEmailList Err:"+err.Error())
  1563. return
  1564. }
  1565. mapPermissionUser := make(map[string][]*roadshow.ResearcherGroup)
  1566. listPermission, err := cygx.GetChartPermissionAll()
  1567. if err != nil {
  1568. this.FailWithMessage("获取失败!", "获取失败,获取品种信息失败 Err:"+err.Error())
  1569. return
  1570. }
  1571. mapPermissionId := make(map[string]int)
  1572. for _, v := range listPermission {
  1573. mapPermissionId[v.PermissionName] = v.ChartPermissionId
  1574. }
  1575. sysUserFwang, e := admin.GetSysUserByAdminName("fwang") // 手动拼接王芳到权益的策略行业下 start
  1576. if e != nil {
  1577. if e.Error() == utils.ErrNoRow() {
  1578. this.FailWithMessage("用户不存在, 请检查!", "用户不存在, 请检查!")
  1579. return
  1580. }
  1581. this.FailWithMessage("用户不存在, 请检查!", "fwang 用户名获取用户失败!Err: "+e.Error())
  1582. return
  1583. }
  1584. itemFwang := new(roadshow.ResearcherGroup)
  1585. itemFwang.AdminId = sysUserFwang.AdminId
  1586. itemFwang.GroupId = sysUserFwang.GroupId
  1587. itemFwang.GroupName = sysUserFwang.GroupName
  1588. itemFwang.RealName = sysUserFwang.RealName
  1589. itemFwang.RoleTypeCode = sysUserFwang.RoleTypeCode
  1590. mapPermissionUser["策略"] = append(mapPermissionUser["策略"], itemFwang) // 手动拼接王芳到权益的策略行业下 end
  1591. for _, v := range askUserList {
  1592. if admin, ok := adminMap[v.AdminId]; ok {
  1593. item := &roadshow.ResearcherGroup{
  1594. AdminId: v.AdminId,
  1595. RealName: v.Name,
  1596. GroupId: admin.GroupId,
  1597. GroupName: admin.GroupName,
  1598. RoleTypeCode: admin.RoleTypeCode,
  1599. }
  1600. mapPermissionUser[v.ChartPermissionName] = append(mapPermissionUser[v.ChartPermissionName], item)
  1601. }
  1602. }
  1603. raiList := make([]*roadshow.ResearcherGroup, 0)
  1604. for k, v := range mapPermissionUser {
  1605. respItem := new(roadshow.ResearcherGroup)
  1606. respItem.GroupName = k + "组"
  1607. respItem.GroupId = mapPermissionId[k]
  1608. respItem.ResearcherList = v
  1609. raiList = append(raiList, respItem)
  1610. }
  1611. raiGroup := new(roadshow.ResearcherGroup)
  1612. raiGroup.GroupId = 888
  1613. raiGroup.GroupName = "权益"
  1614. raiGroup.ResearcherList = raiList
  1615. var resp []*roadshow.ResearcherGroup
  1616. resp = append(resp, ficcGroup, raiGroup)
  1617. this.OkDetailed(resp, "获取成功")
  1618. }
  1619. // @Title 撤回路演活动接口
  1620. // @Description 撤回路演活动接口
  1621. // @Param request body rs.AcceptReq true "type json string"
  1622. // @Success Ret=200 保存成功
  1623. // @router /back [post]
  1624. func (this *CalendarController) Back() {
  1625. sysUser := this.AdminWx
  1626. if sysUser == nil {
  1627. this.FailWithMessage("请登录", "请登录,SysUser Is Empty")
  1628. return
  1629. }
  1630. var req roadshow.AcceptReq
  1631. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1632. if err != nil {
  1633. this.FailWithMessage("参数解析异常", "参数解析失败,Err:"+err.Error())
  1634. return
  1635. }
  1636. if req.RsCalendarId <= 0 || req.RsCalendarResearcherId <= 0 {
  1637. this.FailWithMessage("参数错误", "参数错误!RsCalendarId:"+strconv.Itoa(req.RsCalendarId)+";RsCalendarResearcherId:"+strconv.Itoa(req.RsCalendarResearcherId))
  1638. return
  1639. }
  1640. _, err = roadshow.GetRsCalendarById(req.RsCalendarId)
  1641. if err != nil {
  1642. this.FailWithMessage("获取数据失败", "获取数据失败!GetRsCalendarById:"+err.Error())
  1643. return
  1644. }
  1645. rsCalendarResearcher, err := roadshow.GetRsCalendarResearcherById(req.RsCalendarResearcherId)
  1646. if err != nil {
  1647. this.FailWithMessage("获取数据失败", "获取数据失败!GetRsCalendarResearcherById:"+err.Error())
  1648. return
  1649. }
  1650. if rsCalendarResearcher.Status == 2 {
  1651. this.FailWithMessage("已接受,不可进行撤回操作!", "已接受,不可进行撤回操作!")
  1652. return
  1653. } else if rsCalendarResearcher.Status == 3 {
  1654. this.FailWithMessage("已拒绝,不可进行撤回操作!", "已拒绝,不可进行撤回操作!")
  1655. return
  1656. } else if rsCalendarResearcher.Status == 4 {
  1657. this.FailWithMessage("已删除,不可进行撤回操作!", "已删除,不可进行撤回操作!")
  1658. return
  1659. } else if rsCalendarResearcher.Status == 5 {
  1660. this.FailWithMessage("已撤回,不可进行重复操作!", "已撤回,不可进行重复操作!")
  1661. return
  1662. }
  1663. whereParams := make(map[string]interface{})
  1664. updateParams := make(map[string]interface{})
  1665. whereParams["rs_calendar_researcher_id"] = req.RsCalendarResearcherId
  1666. whereParams["rs_calendar_id"] = req.RsCalendarId
  1667. updateParams["status"] = 5
  1668. updateParams["modify_time"] = time.Now()
  1669. err = roadshow.UpdateCalendarResearcher(whereParams, updateParams)
  1670. //撤回后,需要删除该日程
  1671. go rs.DeleteSHCalendar(req.RsCalendarResearcherId)
  1672. if err != nil {
  1673. this.FailWithMessage("保存失败", "保存失败!UpdateCalendarResearcher:"+err.Error())
  1674. return
  1675. }
  1676. this.OkDetailed(nil, "撤回成功")
  1677. }
  1678. // @Title 删除路演活动接口
  1679. // @Description 删除路演活动接口
  1680. // @Param request body rs.DeleteReq true "type json string"
  1681. // @Success Ret=200 保存成功
  1682. // @router /delete [post]
  1683. func (this *CalendarController) Delete() {
  1684. sysUser := this.AdminWx
  1685. if sysUser == nil {
  1686. this.FailWithMessage("请登录", "请登录,SysUser Is Empty")
  1687. return
  1688. }
  1689. var req roadshow.DeleteReq
  1690. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1691. if err != nil {
  1692. this.FailWithMessage("参数解析异常!", "参数解析失败,Err:"+err.Error())
  1693. return
  1694. }
  1695. if req.RsCalendarId <= 0 || req.RsCalendarResearcherId <= 0 {
  1696. this.FailWithMessage("参数错误!", "参数错误!RsCalendarId:"+strconv.Itoa(req.RsCalendarId)+";RsCalendarResearcherId:"+strconv.Itoa(req.RsCalendarResearcherId))
  1697. return
  1698. }
  1699. rsCalendarItem, err := roadshow.GetRsCalendarById(req.RsCalendarId)
  1700. if err != nil {
  1701. this.FailWithMessage("获取数据失败!", "获取数据失败!GetRsCalendarById:"+err.Error())
  1702. return
  1703. }
  1704. rsCalendarResearcherItemList, err := roadshow.GetRsCalendarResearcherListById(req.RsCalendarId)
  1705. if err != nil {
  1706. this.FailWithMessage("获取数据失败!", "获取数据失败!GetRsCalendarResearcherById:"+err.Error())
  1707. return
  1708. }
  1709. if rsCalendarItem.ActivityType == "报告电话会" || rsCalendarItem.ActivityType == "内部会议" {
  1710. err = roadshow.DeleteCalendar(req.RsCalendarId, req.RsCalendarResearcherId)
  1711. if err != nil {
  1712. this.FailWithMessage("删除失败!", "删除失败!DeleteCalendar:"+err.Error())
  1713. return
  1714. }
  1715. } else {
  1716. //只获取一条路演数据
  1717. rsCalendarResearcherItemList, err = roadshow.GetRsCalendarResearcherListByCalendarResearcherId(req.RsCalendarResearcherId)
  1718. if err != nil {
  1719. this.FailWithMessage("获取数据失败!", "获取数据失败!GetRsCalendarResearcherById:"+err.Error())
  1720. return
  1721. }
  1722. if req.DeleteReason == "" {
  1723. this.FailWithMessage("删除失败,请输入删除理由!", "删除失败!请输入删除理由")
  1724. return
  1725. }
  1726. whereParams := make(map[string]interface{})
  1727. updateParams := make(map[string]interface{})
  1728. whereParams["rs_calendar_researcher_id"] = req.RsCalendarResearcherId
  1729. whereParams["rs_calendar_id"] = req.RsCalendarId
  1730. updateParams["status"] = 4
  1731. updateParams["delete_reason"] = req.DeleteReason
  1732. updateParams["modify_time"] = time.Now()
  1733. updateParams["delete_time"] = time.Now()
  1734. err = roadshow.UpdateCalendarResearcher(whereParams, updateParams)
  1735. if err != nil {
  1736. this.FailWithMessage("删除失败!", "删除失败!UpdateCalendarResearcher:"+err.Error())
  1737. return
  1738. }
  1739. }
  1740. //`status` int(11) DEFAULT '0' COMMENT '1:待接受,2:已接受,3:已拒绝,4:已删除,5:已撤回,6:已结束',
  1741. for _, rsCalendarResearcherItem := range rsCalendarResearcherItemList {
  1742. //待接受、已接受的情况,需要同步删除上海那边的日程
  1743. if rsCalendarResearcherItem.Status == 1 || rsCalendarResearcherItem.Status == 2 {
  1744. go rs.DeleteSHCalendar(rsCalendarResearcherItem.RsCalendarResearcherId)
  1745. }
  1746. ////模板消息通知
  1747. //{
  1748. // go func() {
  1749. // if rsCalendarItem != nil && rsCalendarResearcherItem != nil {
  1750. // sysAdmin, _ := admin.GetAdminById(rsCalendarResearcherItem.ResearcherId)
  1751. // if sysAdmin != nil && sysAdmin.Mobile != "" {
  1752. // first := "【" + sysUser.RealName + "】删除了你的【路演】安排"
  1753. // var keyword1 string
  1754. // if rsCalendarItem.ActivityType == "路演" {
  1755. // keyword1 = rsCalendarItem.CompanyName + "," + rsCalendarItem.RoadshowType + rsCalendarItem.ActivityType
  1756. // } else {
  1757. // keyword1 = rsCalendarItem.Theme + "," + rsCalendarItem.RoadshowType + rsCalendarItem.ActivityType
  1758. // }
  1759. // keyword2 := "已删除"
  1760. // remark := req.DeleteReason
  1761. // var wxAppPath string
  1762. // if rsCalendarItem.ActivityType == "路演" || rsCalendarItem.ActivityType == "公开会议" {
  1763. // wxAppPath = "pages-approve/activity/detail?RsCalendarId=" + strconv.Itoa(rsCalendarItem.RsCalendarId) + "&RsCalendarResearcherId=" + strconv.Itoa(rsCalendarResearcherItem.RsCalendarResearcherId)
  1764. // }
  1765. // go services.SendWxMsgWithRoadshowDeleteNotice(first, keyword1, keyword2, remark, wxAppPath, sysAdmin.Mobile)
  1766. // }
  1767. // }
  1768. // }()
  1769. //}
  1770. //模板消息通知
  1771. {
  1772. if rsCalendarItem != nil && rsCalendarResearcherItem != nil {
  1773. go func(tmpRsCalendarItem roadshow.RsCalendar, tmpRsCalendarResearcherItem roadshow.RsCalendarResearcher) {
  1774. sysAdmin, _ := admin.GetAdminById(tmpRsCalendarResearcherItem.ResearcherId)
  1775. var first string
  1776. var wxAppPath string
  1777. if tmpRsCalendarItem.ActivityType == "路演" || tmpRsCalendarItem.ActivityType == "公开会议" {
  1778. wxAppPath = "pages-approve/activity/detail?RsCalendarId=" + strconv.Itoa(tmpRsCalendarItem.RsCalendarId) + "&RsCalendarResearcherId=" + strconv.Itoa(tmpRsCalendarResearcherItem.RsCalendarResearcherId)
  1779. }
  1780. first = "【" + sysUser.RealName + "】删除了你的【" + tmpRsCalendarItem.ActivityType + "】安排"
  1781. keyword2 := "【" + sysUser.RealName + "】已删除(" + req.DeleteReason + ")"
  1782. var keyword1 string
  1783. if tmpRsCalendarItem.ActivityType == "路演" {
  1784. keyword1 = tmpRsCalendarItem.CompanyName + "," + tmpRsCalendarItem.RoadshowType + tmpRsCalendarItem.ActivityType
  1785. } else if tmpRsCalendarItem.ActivityType == "公开会议" {
  1786. keyword1 = tmpRsCalendarItem.Theme + "," + tmpRsCalendarItem.RoadshowType + tmpRsCalendarItem.ActivityType
  1787. } else {
  1788. startDate := tmpRsCalendarResearcherItem.StartDate[5:]
  1789. startDate = strings.Replace(startDate, "-", ".", -1)
  1790. keyword1 = "会议时间:" + startDate + "(" + tmpRsCalendarResearcherItem.StartWeek + ")" + " " + tmpRsCalendarResearcherItem.StartTime[:5] + "-" + tmpRsCalendarResearcherItem.EndTime[:5]
  1791. keyword2 = "【" + sysUser.RealName + "】已删除" + "【" + tmpRsCalendarItem.ActivityType + ")"
  1792. }
  1793. //keyword2 := "已删除"
  1794. remark := req.DeleteReason
  1795. if sysAdmin.OpenId != "" {
  1796. go services.SendWxMsgWithRoadshowDeleteNotice(first, keyword1, keyword2, remark, wxAppPath, sysAdmin.Mobile)
  1797. }
  1798. }(*rsCalendarItem, *rsCalendarResearcherItem)
  1799. }
  1800. }
  1801. }
  1802. this.OkDetailed(nil, "删除成功")
  1803. }
  1804. // ResearcherList
  1805. // @Title 获取报告电话会类型
  1806. // @Description 获取报告电话会类型接口
  1807. // @Success 200 {object} rs.ResearcherGroup
  1808. // @router /activity/type/list [get]
  1809. func (this *CalendarController) ActivityTypeList() {
  1810. sysUser := this.AdminWx
  1811. if sysUser == nil {
  1812. this.FailWithMessage("请登录", "请登录,SysUser Is Empty")
  1813. return
  1814. }
  1815. // 获取所有的分类
  1816. list, err := rs.GetAllActivityType()
  1817. if err != nil {
  1818. this.FailWithMessage("获取活动类型列表失败", "获取活动类型列表失败,Err:"+err.Error())
  1819. return
  1820. }
  1821. this.OkDetailed(list, "获取成功")
  1822. }
  1823. // @Title 路演-研究员日历详情
  1824. // @Description 路演-研究员日历详情接口
  1825. // @Param StartDate query string true "开始日期"
  1826. // @Param EndDate query string true "结束日期日期"
  1827. // @Param ResearcherId query int true "研究员id"
  1828. // @Success 200 {object} roadshow.CalendarDetailResp
  1829. // @router /researcher/calendar/detail [get]
  1830. func (this *CalendarController) ResearcherCalendarDetail() {
  1831. sysUser := this.AdminWx
  1832. if sysUser == nil {
  1833. this.FailWithMessage("请登录", "请登录,SysUser Is Empty")
  1834. return
  1835. }
  1836. startDate := this.GetString("StartDate")
  1837. endDate := this.GetString("EndDate")
  1838. researcherId, _ := this.GetInt("ResearcherId")
  1839. if startDate == "" || endDate == "" {
  1840. this.FailWithMessage("参数错误!", "参数错误 StartDate"+startDate+" EndDate:"+endDate)
  1841. return
  1842. }
  1843. var condition string
  1844. var pars []interface{}
  1845. if researcherId <= 0 {
  1846. calendarList := make([]*roadshow.CalendarListView, 0)
  1847. matterList := make([]*roadshow.RsMatters, 0)
  1848. resp := new(roadshow.CalendarPanelDetailResp)
  1849. resp.CalendarList = calendarList
  1850. resp.RsMattersList = matterList
  1851. this.OkDetailed(resp, "删除成功")
  1852. return
  1853. } else {
  1854. condition += ` AND b.researcher_id =? `
  1855. pars = append(pars, researcherId)
  1856. }
  1857. //同步上海数据
  1858. researcherInfo, err := admin.GetAdminById(researcherId)
  1859. if err != nil {
  1860. this.FailWithMessage("研究员异常!", "研究员异常"+err.Error())
  1861. return
  1862. }
  1863. //go rs.SyncCalendarFromShanghai(researcherInfo.Mobile, startDate, endDate)
  1864. go rs.InsertSyncCalendarFromShanghaiLPush(researcherInfo.Mobile, startDate, endDate)
  1865. //condition += ` AND b.start_date>=?`
  1866. //pars = append(pars, startDate)
  1867. //condition += ` AND b.end_date<=?`
  1868. //pars = append(pars, endDate)
  1869. //解决研究员休假,产生跨周的数据查询不到的bug,
  1870. condition += ` AND ( b.start_date >= ? AND b.end_date <= ?
  1871. OR ( b.start_date >= ? AND b.start_date <= ? )
  1872. OR ( b.start_date <= ? AND b.end_date >= ? )
  1873. OR ( b.end_date >= ? AND b.end_date <= ? ) ) `
  1874. pars = append(pars, startDate, endDate, startDate, endDate, startDate, endDate, startDate, endDate)
  1875. condition += ` AND b.status IN(2) `
  1876. //pars = append(pars, 2)
  1877. calendarList, err := roadshow.GetCalendarDetailList(condition, pars)
  1878. if err != nil {
  1879. this.FailWithMessage("获取数据失败!", "获取数据失败,GetCalendarDetailList Err:"+err.Error())
  1880. return
  1881. }
  1882. matterList, err := roadshow.GetRsMattersList(startDate, endDate, researcherId)
  1883. if err != nil {
  1884. this.FailWithMessage("获取数据失败!", "获取数据失败,GetRsMattersList Err:"+err.Error())
  1885. return
  1886. }
  1887. if calendarList == nil {
  1888. calendarList = make([]*roadshow.CalendarListView, 0)
  1889. } else {
  1890. var sysUserIds []int //建会人ID
  1891. var companyIds []int //公司ID
  1892. for _, v := range calendarList { //上海同步过来信息展示逻辑替换 需求池 953
  1893. if v.Source == 1 && v.CompanyName == "" {
  1894. v.CompanyName = v.Title
  1895. }
  1896. if v.SysUserId > 0 {
  1897. sysUserIds = append(sysUserIds, v.SysUserId)
  1898. }
  1899. if v.CompanyId > 1 {
  1900. companyIds = append(companyIds, v.CompanyId)
  1901. }
  1902. }
  1903. //如果是权益销售建的会,客户状态替换成权益那边的
  1904. mapSellRai := make(map[int]bool) // 是否是权益销售
  1905. mapStatus := make(map[int]string) //权益客户对应的状态
  1906. if len(sysUserIds) > 0 && len(companyIds) > 0 {
  1907. //判断哪些人是权益销售
  1908. adminList, err := admin.GetAdminListByIdListWithoutEnable(sysUserIds)
  1909. if err != nil {
  1910. this.FailWithMessage("获取数据失败!", "获取数据失败,GetAdminListByIdListWithoutEnable Err:"+err.Error())
  1911. return
  1912. }
  1913. for _, v := range adminList {
  1914. if v.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER || v.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  1915. mapSellRai[v.AdminId] = true
  1916. }
  1917. }
  1918. conditionProduct := ` AND company_id IN (` + utils.GetOrmInReplace(len(companyIds)) + `) AND product_id = 2 `
  1919. parsProduct := make([]interface{}, 0)
  1920. parsProduct = append(parsProduct, companyIds)
  1921. productList, err := company_product.GetCompanyProductList(conditionProduct, parsProduct)
  1922. if err != nil {
  1923. this.FailWithMessage("获取数据失败!", "获取数据失败,GetCompanyProductList Err:"+err.Error())
  1924. return
  1925. }
  1926. for _, v := range productList {
  1927. mapStatus[v.CompanyId] = v.Status
  1928. }
  1929. }
  1930. for _, v := range calendarList {
  1931. if mapSellRai[v.SysUserId] && mapStatus[v.CompanyId] != "" {
  1932. v.CompanyStatus = mapStatus[v.CompanyId]
  1933. }
  1934. }
  1935. }
  1936. if matterList == nil {
  1937. matterList = make([]*roadshow.RsMatters, 0)
  1938. }
  1939. resp := new(roadshow.CalendarPanelDetailResp)
  1940. resp.CalendarList = calendarList
  1941. resp.RsMattersList = matterList
  1942. this.OkDetailed(resp, "删除成功")
  1943. }
  1944. // @Title 路演-我的日历详情
  1945. // @Description 路演-我的日历详情接口
  1946. // @Param StartDate query string true "开始日期"
  1947. // @Param EndDate query string true "结束日期日期"
  1948. // @Success 200 {object} roadshow.CalendarDetailResp
  1949. // @router /my/calendar/detail [get]
  1950. func (this *CalendarController) MyCalendarDetail() {
  1951. sysUser := this.AdminWx
  1952. if sysUser == nil {
  1953. this.FailWithMessage("请登录", "请登录,SysUser Is Empty")
  1954. return
  1955. }
  1956. startDate := this.GetString("StartDate")
  1957. endDate := this.GetString("EndDate")
  1958. if startDate == "" || endDate == "" {
  1959. this.FailWithMessage("参数错误!", "参数错误 StartDate:"+startDate+" EndDate:"+endDate)
  1960. return
  1961. }
  1962. var condition string
  1963. var pars []interface{}
  1964. roleTypeCode := sysUser.RoleTypeCode
  1965. //权益销售
  1966. if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER ||
  1967. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  1968. //if calendarType == 2 {
  1969. condition += ` AND ( a.sys_user_id=? OR a.seller_id=? OR a.share_seller_id=? ) `
  1970. pars = append(pars, sysUser.AdminId, sysUser.AdminId, sysUser.AdminId)
  1971. //}
  1972. } else {
  1973. //销售
  1974. if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER ||
  1975. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER ||
  1976. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP ||
  1977. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP ||
  1978. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN { // 王芳也作为销售身份处理 {
  1979. condition += ` AND a.sys_user_id=?`
  1980. pars = append(pars, sysUser.AdminId)
  1981. condition += ` AND a.activity_type IN('路演','公开会议','沙龙') `
  1982. }
  1983. }
  1984. //研究员
  1985. if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_RESEARCHR ||
  1986. roleTypeCode == utils.ROLE_TYPE_CODE_RESEARCHR ||
  1987. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_RESEARCHR ||
  1988. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN {
  1989. condition += ` AND b.researcher_id=?`
  1990. pars = append(pars, sysUser.AdminId)
  1991. //同步上海数据
  1992. researcherInfo, err := admin.GetAdminById(sysUser.AdminId)
  1993. if err != nil {
  1994. this.FailWithMessage("研究员异常!", "研究员异常"+err.Error())
  1995. return
  1996. }
  1997. //go rs.SyncCalendarFromShanghai(researcherInfo.Mobile, startDate, endDate)
  1998. go rs.InsertSyncCalendarFromShanghaiLPush(researcherInfo.Mobile, startDate, endDate)
  1999. }
  2000. //中级/普通/admin 管理员
  2001. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  2002. condition += ` AND a.sys_user_id=?`
  2003. pars = append(pars, sysUser.AdminId)
  2004. }
  2005. //condition += ` AND b.start_date>=?`
  2006. //pars = append(pars, startDate)
  2007. //condition += ` AND b.end_date<=?`
  2008. //pars = append(pars, endDate)
  2009. //解决研究员休假,产生跨周的数据查询不到的bug,
  2010. condition += ` AND ( b.start_date >= ? AND b.end_date <= ?
  2011. OR ( b.start_date >= ? AND b.start_date <= ? )
  2012. OR ( b.start_date <= ? AND b.end_date >= ? )
  2013. OR ( b.end_date >= ? AND b.end_date <= ? ) ) `
  2014. pars = append(pars, startDate, endDate, startDate, endDate, startDate, endDate, startDate, endDate)
  2015. condition += ` AND b.status IN(2) `
  2016. //pars = append(pars, 2)
  2017. calendarList, err := roadshow.GetCalendarDetailList(condition, pars)
  2018. if err != nil {
  2019. this.FailWithMessage("获取数据失败!", "获取数据失败,GetCalendarDetailList Err:"+err.Error())
  2020. return
  2021. }
  2022. if calendarList == nil {
  2023. calendarList = make([]*roadshow.CalendarListView, 0)
  2024. } else {
  2025. var sysUserIds []int //建会人ID
  2026. var companyIds []int //公司ID
  2027. for _, v := range calendarList { //上海同步过来信息展示逻辑替换 需求池 953
  2028. if v.Source == 1 && v.CompanyName == "" {
  2029. v.CompanyName = v.Title
  2030. }
  2031. if v.SysUserId > 0 {
  2032. sysUserIds = append(sysUserIds, v.SysUserId)
  2033. }
  2034. if v.CompanyId > 1 {
  2035. companyIds = append(companyIds, v.CompanyId)
  2036. }
  2037. }
  2038. //如果是权益销售建的会,客户状态替换成权益那边的
  2039. mapSellRai := make(map[int]bool) // 是否是权益销售
  2040. mapStatus := make(map[int]string) //权益客户对应的状态
  2041. if len(sysUserIds) > 0 && len(companyIds) > 0 {
  2042. //判断哪些人是权益销售
  2043. adminList, err := admin.GetAdminListByIdListWithoutEnable(sysUserIds)
  2044. if err != nil {
  2045. this.FailWithMessage("获取数据失败!", "获取数据失败,GetAdminListByIdListWithoutEnable Err:"+err.Error())
  2046. return
  2047. }
  2048. for _, v := range adminList {
  2049. if v.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER || v.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  2050. mapSellRai[v.AdminId] = true
  2051. }
  2052. }
  2053. conditionProduct := ` AND company_id IN (` + utils.GetOrmInReplace(len(companyIds)) + `) AND product_id = 2 `
  2054. parsProduct := make([]interface{}, 0)
  2055. parsProduct = append(parsProduct, companyIds)
  2056. productList, err := company_product.GetCompanyProductList(conditionProduct, parsProduct)
  2057. if err != nil {
  2058. this.FailWithMessage("获取数据失败!", "获取数据失败,GetCompanyProductList Err:"+err.Error())
  2059. return
  2060. }
  2061. for _, v := range productList {
  2062. mapStatus[v.CompanyId] = v.Status
  2063. }
  2064. }
  2065. for _, v := range calendarList {
  2066. if mapSellRai[v.SysUserId] && mapStatus[v.CompanyId] != "" {
  2067. v.CompanyStatus = mapStatus[v.CompanyId]
  2068. }
  2069. }
  2070. }
  2071. matterList, err := roadshow.GetRsMattersList(startDate, endDate, sysUser.AdminId)
  2072. if err != nil {
  2073. this.FailWithMessage("获取数据失败!", "获取数据失败,GetRsMattersList Err:"+err.Error())
  2074. return
  2075. }
  2076. resp := new(roadshow.CalendarPanelDetailResp)
  2077. resp.CalendarList = calendarList
  2078. resp.RsMattersList = matterList
  2079. this.OkDetailed(resp, "删除成功")
  2080. }
  2081. // SellerCalendarDetail
  2082. // @Title 路演-销售日历详情
  2083. // @Description 路演-销售日历详情
  2084. // @Param StartDate query string true "开始日期"
  2085. // @Param EndDate query string true "结束日期日期"
  2086. // @Param SellerId query int true "销售ID"
  2087. // @Success 200 {object} roadshow.CalendarDetailResp
  2088. // @router /seller/calendar/detail [get]
  2089. func (this *CalendarController) SellerCalendarDetail() {
  2090. sysUser := this.AdminWx
  2091. if sysUser == nil {
  2092. this.FailWithMessage("请登录", "请登录,SysUser Is Empty")
  2093. return
  2094. }
  2095. startDate := this.GetString("StartDate")
  2096. endDate := this.GetString("EndDate")
  2097. sellerId, _ := this.GetInt("SellerId")
  2098. if startDate == "" || endDate == "" {
  2099. this.FailWithMessage("参数错误!", "参数错误 StartDate"+startDate+" EndDate:"+endDate)
  2100. return
  2101. }
  2102. if sellerId <= 0 {
  2103. calendarList := make([]*roadshow.CalendarListView, 0)
  2104. matterList := make([]*roadshow.RsMatters, 0)
  2105. resp := new(roadshow.CalendarPanelDetailResp)
  2106. resp.CalendarList = calendarList
  2107. resp.RsMattersList = matterList
  2108. this.OkDetailed(resp, "删除成功")
  2109. return
  2110. }
  2111. // 路演
  2112. condition := ` AND a.sys_user_id = ? AND b.start_date >= ? AND b.end_date <= ? AND b.status = 2`
  2113. pars := make([]interface{}, 0)
  2114. pars = append(pars, sellerId, startDate, endDate)
  2115. calendarList, err := roadshow.GetCalendarDetailList(condition, pars)
  2116. if err != nil {
  2117. this.FailWithMessage("获取数据失败", "获取数据失败, GetCalendarDetailList Err:"+err.Error())
  2118. return
  2119. }
  2120. if calendarList == nil {
  2121. calendarList = make([]*roadshow.CalendarListView, 0)
  2122. }
  2123. // 事项
  2124. matterList, err := roadshow.GetRsMattersList(startDate, endDate, sellerId)
  2125. if err != nil {
  2126. this.FailWithMessage("获取数据失败", "获取数据失败, GetRsMattersList Err:"+err.Error())
  2127. return
  2128. }
  2129. if matterList == nil {
  2130. matterList = make([]*roadshow.RsMatters, 0)
  2131. }
  2132. resp := new(roadshow.CalendarPanelDetailResp)
  2133. resp.CalendarList = calendarList
  2134. resp.RsMattersList = matterList
  2135. this.OkDetailed(resp, "删除成功")
  2136. }
  2137. // isSellerRole 是否为销售角色
  2138. func isSellerRole(roleType string) (ok bool) {
  2139. sellerArr := []string{
  2140. utils.ROLE_TYPE_CODE_FICC_SELLER, utils.ROLE_TYPE_CODE_FICC_GROUP, utils.ROLE_TYPE_CODE_FICC_TEAM,
  2141. utils.ROLE_TYPE_CODE_RAI_SELLER, utils.ROLE_TYPE_CODE_RAI_GROUP,
  2142. }
  2143. if utils.InArrayByStr(sellerArr, roleType) {
  2144. ok = true
  2145. }
  2146. return
  2147. }