calendar.go 95 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014
  1. package roadshow
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "github.com/rdlucklib/rdluck_tools/paging"
  6. "hongze/hz_crm_api/controllers"
  7. "hongze/hz_crm_api/models"
  8. "hongze/hz_crm_api/models/company"
  9. "hongze/hz_crm_api/models/cygx"
  10. "hongze/hz_crm_api/models/roadshow"
  11. "hongze/hz_crm_api/models/system"
  12. "hongze/hz_crm_api/services"
  13. roadshowService "hongze/hz_crm_api/services/roadshow"
  14. "hongze/hz_crm_api/utils"
  15. "strconv"
  16. "strings"
  17. "time"
  18. )
  19. // 日历
  20. type CalendarController struct {
  21. controllers.BaseAuthController
  22. }
  23. // @Title 新增路演活动接口
  24. // @Description 新增路演活动接口
  25. // @Param request body roadshow.AddActivityReq true "type json string"
  26. // @Success Ret=200 保存成功
  27. // @router /add [post]
  28. func (this *CalendarController) Add() {
  29. br := new(models.BaseResponse).Init()
  30. defer func() {
  31. this.Data["json"] = br
  32. this.ServeJSON()
  33. }()
  34. sysUser := this.SysUser
  35. if sysUser == nil {
  36. br.Msg = "请登录"
  37. br.ErrMsg = "请登录,SysUser Is Empty"
  38. br.Ret = 408
  39. return
  40. }
  41. deleteCache := true
  42. cacheKey := "CACHE_RS_ACTIVITY_ADD_" + strconv.Itoa(sysUser.AdminId)
  43. defer func() {
  44. if deleteCache {
  45. utils.Rc.Delete(cacheKey)
  46. }
  47. }()
  48. if !utils.Rc.SetNX(cacheKey, 1, 5*time.Second) {
  49. deleteCache = false
  50. br.Msg = "系统处理中,请稍后重试!"
  51. br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(this.Ctx.Input.RequestBody)
  52. return
  53. }
  54. var req roadshow.AddActivityReq
  55. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  56. if err != nil {
  57. br.Msg = "参数解析异常!"
  58. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  59. return
  60. }
  61. if len(req.ResearcherList) <= 0 {
  62. br.Msg = "请选择研究员!"
  63. return
  64. }
  65. researcherMap := make(map[int]string)
  66. var checkIsAdd []string
  67. //获取所有自定义的权益研究员
  68. sysUserList, err := cygx.GetAskEmailList()
  69. if err != nil {
  70. br.Msg = "获取失败"
  71. br.ErrMsg = "获取失败,GetAskEmailList Err: " + err.Error()
  72. return
  73. }
  74. raiAskadminMap := make(map[int]bool, 0)
  75. for _, v := range sysUserList {
  76. raiAskadminMap[v.AdminId] = true
  77. }
  78. sysUserFwang, e := system.GetSysUserByAdminName("fwang") // 手动拼接王芳到权益的策略行业下 start
  79. if e != nil {
  80. if e.Error() == utils.ErrNoRow() {
  81. br.Msg = "用户不存在, 请检查"
  82. return
  83. }
  84. br.Msg = "账号错误, 请重新输入"
  85. br.ErrMsg = "fwang 用户名获取用户失败, Err: " + e.Error()
  86. return
  87. }
  88. raiAskadminMap[sysUserFwang.AdminId] = true // 手动拼接王芳到权益的策略行业下 end
  89. //var tipMsg string
  90. for _, v := range req.ResearcherList {
  91. if v.ResearcherId <= 0 {
  92. br.Msg = "请选择研究员!"
  93. return
  94. }
  95. if v.ResearcherName == "" {
  96. br.Msg = "请选择研究员!"
  97. return
  98. }
  99. if v.StartDate == "" {
  100. br.Msg = "请选择开始日期!"
  101. return
  102. }
  103. if v.EndDate == "" {
  104. br.Msg = "请选择结束日期!"
  105. return
  106. }
  107. if v.StartTime == "" {
  108. br.Msg = "请选择开始时间!"
  109. return
  110. }
  111. if v.EndTime == "" {
  112. br.Msg = "请选择结束时间!"
  113. return
  114. }
  115. if v.StartWeek == "" {
  116. br.Msg = "请选择周!"
  117. return
  118. }
  119. if v.EndWeek == "" {
  120. br.Msg = "请选择周!"
  121. return
  122. }
  123. if req.ActivityType == "沙龙" && !raiAskadminMap[v.ResearcherId] {
  124. br.Msg = "ficc研究员暂不支持添加沙龙"
  125. return
  126. }
  127. startDateTime := v.StartDate + " " + v.StartTime
  128. endDateTime := v.EndDate + " " + v.EndTime
  129. startP, _ := time.ParseInLocation(utils.FormatDateTime, startDateTime, time.Local)
  130. endP, _ := time.ParseInLocation(utils.FormatDateTime, endDateTime, time.Local)
  131. if startP.Before(time.Now()) || startP.Equal(time.Now()) {
  132. br.Msg = "活动开始时间不能小于当前时间!"
  133. return
  134. }
  135. if endP.Before(time.Now()) || endP.Equal(time.Now()) {
  136. br.Msg = "活动结束时间不能小于当前时间!"
  137. return
  138. }
  139. if startP.After(endP) || startP.Equal(endP) {
  140. br.Msg = "活动开始时间应小于结束时间!"
  141. return
  142. }
  143. if realName, ok := researcherMap[v.ResearcherId]; ok {
  144. br.Msg = "研究员:" + realName + " 被重复选择"
  145. return
  146. }
  147. researcherMap[v.ResearcherId] = v.ResearcherName
  148. //同步上海数据
  149. researcherInfo, err := system.GetSysAdminById(v.ResearcherId)
  150. if err != nil {
  151. br.Msg = "研究员异常"
  152. return
  153. }
  154. _ = roadshowService.SyncCalendarFromShanghai(researcherInfo.Mobile, v.StartDate, v.EndDate)
  155. //校验事项时间冲突
  156. {
  157. matterCount, err := roadshowService.CheckMatters(startDateTime, endDateTime, v.ResearcherId, 0)
  158. if err != nil {
  159. br.Msg = "时间冲突检测失败!"
  160. br.ErrMsg = "时间冲突检测失败-CheckMattersCount!Err:" + err.Error()
  161. return
  162. }
  163. if matterCount > 0 {
  164. checkIsAdd = append(checkIsAdd, v.ResearcherName)
  165. }
  166. }
  167. //校验活动时间冲突
  168. {
  169. calendarCount, err := roadshowService.CheckCalendar(startDateTime, endDateTime, "1,2", v.ResearcherId, 0)
  170. if err != nil {
  171. br.Msg = "时间冲突检测失败!"
  172. br.ErrMsg = "时间冲突检测失败-CheckCalendar!Err:" + err.Error()
  173. return
  174. }
  175. if calendarCount > 0 {
  176. checkIsAdd = append(checkIsAdd, v.ResearcherName)
  177. }
  178. }
  179. }
  180. if len(checkIsAdd) > 0 {
  181. br.Msg = strings.Join(checkIsAdd, ",") + " 时间已被占用!"
  182. br.ErrMsg = "时间冲突检测失败-CheckMattersCount!"
  183. br.IsSendEmail = false
  184. return
  185. }
  186. //如果是权益客户,添加销售跟共享销售的信息
  187. var productItemRai *company.CompanyProduct
  188. roleTypeCode := sysUser.RoleTypeCode
  189. //如果是权益销售、权益销售组长、权益管理员 添加的路演信息,做销售与共享销售信息关联查看
  190. if req.CompanyId > 0 && req.ActivityType == "路演" && (roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER ||
  191. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP || roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN) {
  192. productItemRai, err = company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, utils.COMPANY_PRODUCT_RAI_ID)
  193. if err != nil && err.Error() != utils.ErrNoRow() {
  194. br.Msg = "客户信息有误"
  195. br.ErrMsg = "获取客户信息失败, Err: " + err.Error()
  196. return
  197. }
  198. }
  199. rsCalendar := new(roadshow.RsCalendar)
  200. rsCalendar.SysUserId = sysUser.AdminId
  201. rsCalendar.SysUserRealName = sysUser.RealName
  202. rsCalendar.ActivityType = req.ActivityType
  203. rsCalendar.RoadshowType = req.RoadshowType
  204. rsCalendar.RoadshowPlatform = req.RoadshowPlatform
  205. rsCalendar.CompanyId = req.CompanyId
  206. rsCalendar.CompanyName = req.CompanyName
  207. rsCalendar.Province = req.Province
  208. rsCalendar.ProvinceCode = req.ProvinceCode
  209. rsCalendar.City = req.City
  210. rsCalendar.CityCode = req.CityCode
  211. rsCalendar.District = req.District
  212. rsCalendar.Theme = req.Theme
  213. rsCalendar.CooperationName = req.CooperationName
  214. rsCalendar.CreateTime = time.Now()
  215. rsCalendar.ModifyTime = time.Now()
  216. rsCalendar.ActivityCategory = req.ActivityCategory
  217. rsCalendar.Source = 0
  218. rsCalendar.EnglishCompany = req.EnglishCompany
  219. rsCalendar.Title = getTitle(req.ActivityType, req.RoadshowType, req.ActivityCategory, req.RoadshowPlatform, req.Province, req.City)
  220. if productItemRai != nil {
  221. rsCalendar.SellerId = productItemRai.SellerId
  222. rsCalendar.ShareSellerId = productItemRai.ShareSellerId
  223. }
  224. rsCalendarId, err := roadshow.AddRsCalendar(rsCalendar)
  225. if err != nil {
  226. br.Msg = "保存失败!"
  227. br.ErrMsg = "保存日历活动信息失败!Err:" + err.Error()
  228. return
  229. }
  230. //if researcherId != 99 {
  231. for k, v := range req.ResearcherList {
  232. researcher := new(roadshow.RsCalendarResearcher)
  233. researcher.RsCalendarId = int(rsCalendarId)
  234. researcher.ResearcherId = v.ResearcherId
  235. researcher.ResearcherName = v.ResearcherName
  236. researcher.StartDate = v.StartDate
  237. researcher.EndDate = v.EndDate
  238. researcher.StartTime = v.StartTime
  239. researcher.EndTime = v.EndTime
  240. researcher.StartWeek = v.StartWeek
  241. researcher.EndWeek = v.EndWeek
  242. researcher.CreateTime = time.Now()
  243. researcher.ModifyTime = time.Now()
  244. researcher.ResearcherSort = k + 1
  245. if req.ActivityType == "路演" || req.ActivityType == "公开会议" {
  246. researcher.Status = 1
  247. } else {
  248. researcher.Status = 2
  249. }
  250. //CRM15.5 权益研究员直接通过
  251. if raiAskadminMap[v.ResearcherId] {
  252. researcher.Status = 2
  253. }
  254. rsCalendarResearcherId, err := roadshow.AddRsCalendarResearcher(researcher)
  255. if err != nil {
  256. br.Msg = "保存失败!"
  257. br.ErrMsg = "保存日历活动-研究员信息失败!Err:" + err.Error()
  258. return
  259. }
  260. rsCalendar.RsCalendarId = int(rsCalendarId)
  261. researcher.RsCalendarResearcherId = int(rsCalendarResearcherId)
  262. go roadshowService.CalendarToSH(*rsCalendar, *researcher)
  263. //模板消息通知
  264. {
  265. go func(researcherId, tmpRsCalendarId, tmpRsCalendarResearcherId int) { // 研究员id,路演id,路演与研究员记录的id
  266. var wxAppPath string
  267. sysAdmin, _ := system.GetSysAdminById(researcherId)
  268. if sysAdmin != nil && sysAdmin.OpenId != "" {
  269. openIdObj := &system.OpenIdList{
  270. OpenId: sysAdmin.OpenId,
  271. AdminId: sysAdmin.AdminId,
  272. }
  273. openIdList := make([]*system.OpenIdList, 0)
  274. openIdList = append(openIdList, openIdObj)
  275. if req.ActivityType == "路演" || req.ActivityType == "公开会议" {
  276. wxAppPath = "pages-approve/activity/detail?RsCalendarId=" + strconv.Itoa(tmpRsCalendarId) + "&RsCalendarResearcherId=" + strconv.Itoa(tmpRsCalendarResearcherId)
  277. first := "您收到一个新的【" + req.ActivityType + "】申请,请及时处理"
  278. keyword1 := sysUser.RealName
  279. keyword2 := "--"
  280. startDateSub := v.StartDate[5:]
  281. startDateSub = strings.Replace(startDateSub, "-", ".", -1)
  282. //keyword3 := time.Now().Format(utils.FormatDateTime)
  283. keyword3 := startDateSub + "(" + v.StartWeek + ")" + " " + v.StartTime[:5] + "~" + v.EndTime[:5]
  284. var keyword4 string
  285. if req.ActivityType == "路演" {
  286. keyword4 = req.CompanyName + "(" + req.RoadshowType + req.ActivityType + ")"
  287. } else {
  288. keyword4 = req.Theme + "(" + req.RoadshowType + req.ActivityType + ")"
  289. }
  290. remark := "请尽快完成审批"
  291. //wxAppPath := "pages-approve/activity/detail?RsCalendarId=" + strconv.Itoa(int(rsCalendarId)) + "&RsCalendarResearcherId=" + strconv.Itoa(int(rsCalendarResearcherId))
  292. if len(openIdList) > 0 {
  293. services.SendWxMsgWithRoadshowPending(first, keyword1, keyword2, keyword3, keyword4, remark, wxAppPath, openIdList)
  294. }
  295. } else {
  296. wxAppPath = ""
  297. first := sysUser.RealName + "为你添加了一场【" + req.ActivityType + "】"
  298. startDate := researcher.StartDate[5:]
  299. startDate = strings.Replace(startDate, "-", ".", -1)
  300. keyword1 := startDate + "(" + researcher.StartWeek + ")" + " " + researcher.StartTime[:5] + "-" + researcher.EndTime[:5]
  301. keyword2 := sysUser.RealName + "为你添加了【" + req.ActivityType + "】"
  302. if len(openIdList) > 0 {
  303. services.SendWxMsgWithRoadshowDeleteNotice(first, keyword1, keyword2, "", wxAppPath, openIdList)
  304. }
  305. }
  306. }
  307. }(v.ResearcherId, int(rsCalendarId), int(rsCalendarResearcherId))
  308. }
  309. }
  310. //if req.ActivityType == "公开会议" {
  311. // go roadshowService.SetPublicMeetingUnionCode()
  312. //}
  313. br.Ret = 200
  314. br.Success = true
  315. br.Msg = "保存成功"
  316. br.IsAddLog = true
  317. }
  318. // @Title 编辑路演活动接口
  319. // @Description编辑路演活动接口
  320. // @Param request body roadshow.EditActivityReq true "type json string"
  321. // @Success Ret=200 保存成功
  322. // @router /edit [post]
  323. func (this *CalendarController) Edit() {
  324. br := new(models.BaseResponse).Init()
  325. defer func() {
  326. this.Data["json"] = br
  327. this.ServeJSON()
  328. }()
  329. sysUser := this.SysUser
  330. if sysUser == nil {
  331. br.Msg = "请登录"
  332. br.ErrMsg = "请登录,SysUser Is Empty"
  333. br.Ret = 408
  334. return
  335. }
  336. deleteCache := true
  337. cacheKey := "CACHE_RS_ACTIVITY_EDIT_" + strconv.Itoa(sysUser.AdminId)
  338. defer func() {
  339. if deleteCache {
  340. utils.Rc.Delete(cacheKey)
  341. }
  342. }()
  343. if !utils.Rc.SetNX(cacheKey, 1, 5*time.Second) {
  344. deleteCache = false
  345. br.Msg = "系统处理中,请稍后重试!"
  346. br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(this.Ctx.Input.RequestBody)
  347. return
  348. }
  349. var req roadshow.EditActivityReq
  350. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  351. if err != nil {
  352. br.Msg = "参数解析异常!"
  353. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  354. return
  355. }
  356. if req.RsCalendarId <= 0 {
  357. br.Msg = "参数错误!"
  358. br.ErrMsg = "RsCalendarId<=0"
  359. return
  360. }
  361. if req.RsCalendarResearcherId <= 0 {
  362. br.Msg = "参数错误!"
  363. br.ErrMsg = "RsCalendarResearcherId<=0"
  364. return
  365. }
  366. if req.ActivityType == "" {
  367. br.Msg = "请选择活动类型!"
  368. return
  369. }
  370. if len(req.ResearcherList) <= 0 {
  371. br.Msg = "请选择研究员!"
  372. return
  373. }
  374. researcherMap := make(map[int]string)
  375. var checkIsAdd []string
  376. for _, v := range req.ResearcherList {
  377. if v.ResearcherId <= 0 {
  378. br.Msg = "请选择研究员!"
  379. return
  380. }
  381. if v.ResearcherName == "" {
  382. br.Msg = "请选择研究员!"
  383. return
  384. }
  385. if v.StartDate == "" {
  386. br.Msg = "请选择开始日期!"
  387. return
  388. }
  389. if v.EndDate == "" {
  390. br.Msg = "请选择结束日期!"
  391. return
  392. }
  393. if v.StartTime == "" {
  394. br.Msg = "请选择开始时间!"
  395. return
  396. }
  397. if v.EndTime == "" {
  398. br.Msg = "请选择结束时间!"
  399. return
  400. }
  401. if v.StartWeek == "" {
  402. br.Msg = "请选择周!"
  403. return
  404. }
  405. if v.EndWeek == "" {
  406. br.Msg = "请选择周!"
  407. return
  408. }
  409. if realName, ok := researcherMap[v.ResearcherId]; ok {
  410. br.Msg = "研究员:" + realName + " 被重复选择"
  411. return
  412. }
  413. researcherMap[v.ResearcherId] = v.ResearcherName
  414. startDateTime := v.StartDate + " " + v.StartTime
  415. endDateTime := v.EndDate + " " + v.EndTime
  416. startP, _ := time.ParseInLocation(utils.FormatDateTime, startDateTime, time.Local)
  417. endP, _ := time.ParseInLocation(utils.FormatDateTime, endDateTime, time.Local)
  418. if startP.Before(time.Now()) || startP.Equal(time.Now()) {
  419. br.Msg = "活动开始时间不能小于当前时间!"
  420. return
  421. }
  422. if endP.Before(time.Now()) || endP.Equal(time.Now()) {
  423. br.Msg = "活动结束时间不能小于当前时间!"
  424. return
  425. }
  426. if startP.After(endP) || startP.Equal(endP) {
  427. br.Msg = "活动开始时间应小于结束时间!"
  428. return
  429. }
  430. /*
  431. 时间冲突时,提示:xxx时间已被占用
  432. 当有任意一个研究员时间有冲突时,所有申请订单都不发送。
  433. */
  434. rsCalendarResearcherItem, err := roadshow.GetRsCalendarResearcherByRsCalendarIdAndResearcherId(req.RsCalendarId, v.ResearcherId)
  435. var isAdd bool
  436. if err != nil {
  437. if err.Error() == utils.ErrNoRow() {
  438. isAdd = true
  439. } else {
  440. br.Msg = "获取数据失败!"
  441. br.ErrMsg = "获取数据失败!GetRsCalendarResearcherByRsCalendarIdAndResearcherId:" + err.Error()
  442. return
  443. }
  444. }
  445. var rsCalendarResearcherId int
  446. if rsCalendarResearcherItem == nil {
  447. isAdd = true
  448. } else {
  449. rsCalendarResearcherId = rsCalendarResearcherItem.RsCalendarResearcherId
  450. }
  451. //同步上海数据
  452. researcherInfo, err := system.GetSysAdminById(v.ResearcherId)
  453. if err != nil {
  454. br.Msg = "研究员异常"
  455. return
  456. }
  457. _ = roadshowService.SyncCalendarFromShanghai(researcherInfo.Mobile, v.StartDate, v.EndDate)
  458. //校验事项时间冲突
  459. {
  460. if isAdd || (rsCalendarResearcherItem != nil && (rsCalendarResearcherItem.StartDate != v.StartDate ||
  461. rsCalendarResearcherItem.StartTime != v.StartTime ||
  462. rsCalendarResearcherItem.EndDate != v.EndDate ||
  463. rsCalendarResearcherItem.EndTime != v.EndTime)) {
  464. matterCount, err := roadshowService.CheckMatters(startDateTime, endDateTime, v.ResearcherId, 0)
  465. if err != nil {
  466. br.Msg = "时间冲突检测失败!"
  467. br.ErrMsg = "时间冲突检测失败-CheckMattersCount!Err:" + err.Error()
  468. return
  469. }
  470. if matterCount > 0 {
  471. checkIsAdd = append(checkIsAdd, v.ResearcherName)
  472. }
  473. }
  474. }
  475. //校验活动时间冲突
  476. //{
  477. // if isAdd || (rsCalendarResearcherItem != nil && (rsCalendarResearcherItem.StartDate != v.StartDate ||
  478. // rsCalendarResearcherItem.StartTime != v.StartTime ||
  479. // rsCalendarResearcherItem.EndDate != v.EndDate ||
  480. // rsCalendarResearcherItem.EndTime != v.EndTime)) {
  481. //
  482. // calendarCount, err := roadshowService.CheckCalendar(startDateTime, endDateTime, "1,2", v.ResearcherId, rsCalendarResearcherId)
  483. // if err != nil {
  484. // br.Msg = "时间冲突检测失败!"
  485. // br.ErrMsg = "时间冲突检测失败-CheckCalendarResearcherCount!Err:" + err.Error()
  486. // return
  487. // }
  488. // if calendarCount > 0 {
  489. // checkIsAdd = append(checkIsAdd, v.ResearcherName)
  490. // }
  491. // }
  492. //}
  493. calendarCount, err := roadshowService.CheckCalendar(startDateTime, endDateTime, "1,2", v.ResearcherId, rsCalendarResearcherId)
  494. if err != nil {
  495. br.Msg = "时间冲突检测失败!"
  496. br.ErrMsg = "时间冲突检测失败-CheckCalendarResearcherCount!Err:" + err.Error()
  497. return
  498. }
  499. if calendarCount > 0 {
  500. checkIsAdd = append(checkIsAdd, v.ResearcherName)
  501. }
  502. }
  503. if len(checkIsAdd) > 0 {
  504. br.Msg = strings.Join(checkIsAdd, ",") + "时间已被占用!"
  505. br.ErrMsg = "时间冲突检测失败-CheckMattersCount!"
  506. br.IsSendEmail = false
  507. return
  508. }
  509. rsCalendarItem, err := roadshow.GetRsCalendarById(req.RsCalendarId)
  510. if err != nil {
  511. br.Msg = "获取数据失败!"
  512. br.ErrMsg = "获取数据失败!GetRsCalendarById:" + err.Error()
  513. return
  514. }
  515. if rsCalendarItem == nil {
  516. br.Msg = "保存失败!"
  517. br.ErrMsg = "获取数据失败!GetRsCalendarById:" + err.Error()
  518. return
  519. }
  520. calendarWhereParams := make(map[string]interface{})
  521. calendarUpdateParams := make(map[string]interface{})
  522. calendarWhereParams["rs_calendar_id"] = req.RsCalendarId
  523. //if req.ActivityType != "" {
  524. calendarUpdateParams["activity_type"] = req.ActivityType
  525. //}
  526. //if req.RoadshowType != "" {
  527. calendarUpdateParams["roadshow_type"] = req.RoadshowType
  528. // }
  529. //if req.RoadshowPlatform != "" {
  530. calendarUpdateParams["roadshow_platform"] = req.RoadshowPlatform
  531. //}
  532. //if req.CompanyId > 0 {
  533. calendarUpdateParams["company_id"] = req.CompanyId
  534. //}
  535. //if req.CompanyName != "" {
  536. calendarUpdateParams["company_name"] = req.CompanyName
  537. //}
  538. //if req.ActivityCategory != "" {
  539. calendarUpdateParams["activity_category"] = req.ActivityCategory
  540. // }
  541. //if req.Theme != "" {
  542. calendarUpdateParams["theme"] = req.Theme
  543. //}
  544. //if req.CooperationName != "" {
  545. calendarUpdateParams["cooperation_name"] = req.CooperationName
  546. //}
  547. //if req.Province != "" {
  548. calendarUpdateParams["province"] = req.Province
  549. //}
  550. //if req.City != "" {
  551. calendarUpdateParams["city"] = req.City
  552. // }
  553. //if req.District != "" {
  554. calendarUpdateParams["district"] = req.District
  555. //}
  556. calendarUpdateParams["english_company"] = req.EnglishCompany
  557. calendarUpdateParams["modify_time"] = time.Now()
  558. calendarUpdateParams["title"] = getTitle(req.ActivityType, req.RoadshowType, req.ActivityCategory, req.RoadshowPlatform, req.Province, req.City)
  559. //如果是权益客户,添加销售跟共享销售的信息
  560. roleTypeCode := sysUser.RoleTypeCode
  561. //如果是权益销售、权益销售组长、权益管理员 添加的路演信息,做销售与共享销售信息关联查看
  562. if req.CompanyId > 0 && req.ActivityType == "路演" && (roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER ||
  563. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP || roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN) {
  564. var productItemRai *company.CompanyProduct
  565. productItemRai, err = company.GetCompanyProductByCompanyIdAndProductId(req.CompanyId, utils.COMPANY_PRODUCT_RAI_ID)
  566. if err != nil && err.Error() != utils.ErrNoRow() {
  567. br.Msg = "客户信息有误"
  568. br.ErrMsg = "获取客户信息失败, Err: " + err.Error()
  569. return
  570. }
  571. if productItemRai != nil {
  572. calendarUpdateParams["seller_id"] = productItemRai.SellerId
  573. calendarUpdateParams["share_seller_id"] = productItemRai.ShareSellerId
  574. }
  575. }
  576. err = roadshow.UpdateRsCalendar(calendarWhereParams, calendarUpdateParams)
  577. if err != nil {
  578. br.Msg = "保存失败!"
  579. br.ErrMsg = "保存失败!UpdateRsCalendar:" + err.Error()
  580. return
  581. }
  582. //newResearcherMap := make(map[int]string)
  583. existList, err := roadshow.GetRsCalendarResearcherByCalendarId(req.RsCalendarId)
  584. if err != nil {
  585. br.Msg = "保存失败!"
  586. br.ErrMsg = "保存失败!GetRsCalendarResearcherByCalendarId:" + err.Error()
  587. return
  588. }
  589. existResearcherMap := make(map[int]string)
  590. for _, ev := range existList {
  591. existResearcherMap[ev.ResearcherId] = ev.ResearcherName
  592. }
  593. sysUserList, err := cygx.GetAskEmailList()
  594. if err != nil {
  595. br.Msg = "获取失败"
  596. br.ErrMsg = "获取失败,GetAskEmailList Err: " + err.Error()
  597. return
  598. }
  599. raiAskadminMap := make(map[int]bool, 0)
  600. for _, v := range sysUserList {
  601. raiAskadminMap[v.AdminId] = true
  602. }
  603. if rsCalendarItem.ActivityType == "路演" || rsCalendarItem.ActivityType == "公开会议" {
  604. // 更新研究员信息
  605. //go roadshowService.UpdateSHCalendar(req.RsCalendarId, req.RsCalendarResearcherId, req.ActivityType, req.RoadshowType, req.ActivityCategory, req.RoadshowPlatform, req.Province, req.City, req.ResearcherList)
  606. for k, v := range req.ResearcherList {
  607. rsCalendarResearcherItem, err := roadshow.GetRsCalendarResearcherById(req.RsCalendarResearcherId)
  608. if err != nil {
  609. br.Msg = "获取数据失败!"
  610. br.ErrMsg = "获取数据失败!GetRsCalendarResearcherById:" + err.Error()
  611. return
  612. }
  613. calendarResearcherWhereParams := make(map[string]interface{})
  614. calendarResearcherUpdateParams := make(map[string]interface{})
  615. calendarResearcherWhereParams["rs_calendar_researcher_id"] = req.RsCalendarResearcherId
  616. calendarResearcherUpdateParams["researcher_id"] = v.ResearcherId
  617. calendarResearcherUpdateParams["researcher_name"] = v.ResearcherName
  618. rsCalendarResearcherItem.ResearcherId = v.ResearcherId
  619. rsCalendarResearcherItem.ResearcherName = v.ResearcherName
  620. if rsCalendarResearcherItem.Status == 3 || rsCalendarResearcherItem.Status == 5 {
  621. calendarResearcherUpdateParams["status"] = 1
  622. rsCalendarResearcherItem.Status = 1
  623. }
  624. //CRM15.5 权益研究员直接通过
  625. if raiAskadminMap[v.ResearcherId] {
  626. calendarResearcherUpdateParams["status"] = 2
  627. rsCalendarResearcherItem.Status = 2
  628. }
  629. calendarResearcherUpdateParams["start_date"] = v.StartDate
  630. rsCalendarResearcherItem.StartDate = v.StartDate
  631. calendarResearcherUpdateParams["end_date"] = v.EndDate
  632. rsCalendarResearcherItem.EndDate = v.EndDate
  633. calendarResearcherUpdateParams["start_time"] = v.StartTime
  634. rsCalendarResearcherItem.StartTime = v.StartTime
  635. calendarResearcherUpdateParams["end_time"] = v.EndTime
  636. rsCalendarResearcherItem.EndTime = v.EndTime
  637. calendarResearcherUpdateParams["start_week"] = v.StartWeek
  638. rsCalendarResearcherItem.StartWeek = v.StartWeek
  639. calendarResearcherUpdateParams["end_week"] = v.EndWeek
  640. rsCalendarResearcherItem.EndWeek = v.EndWeek
  641. calendarResearcherUpdateParams["refuse_reason"] = ""
  642. rsCalendarResearcherItem.RefuseReason = ""
  643. calendarResearcherUpdateParams["refuse_time"] = nil
  644. calendarResearcherUpdateParams["delete_reason"] = ""
  645. rsCalendarResearcherItem.DeleteReason = ""
  646. calendarResearcherUpdateParams["approve_time"] = nil
  647. calendarResearcherUpdateParams["researcher_sort"] = k + 1
  648. rsCalendarResearcherItem.ResearcherSort = k + 1
  649. calendarResearcherUpdateParams["modify_time"] = time.Now()
  650. rsCalendarResearcherItem.ModifyTime = time.Now()
  651. calendarResearcherUpdateParams["create_time"] = time.Now()
  652. rsCalendarResearcherItem.CreateTime = time.Now()
  653. err = roadshow.UpdateCalendarResearcher(calendarResearcherWhereParams, calendarResearcherUpdateParams)
  654. if err != nil {
  655. br.Msg = "保存失败!"
  656. br.ErrMsg = "保存失败!UpdateCalendarResearcher:" + err.Error()
  657. return
  658. }
  659. //上海新增(因为在驳回的时候,就把上海该时间段的日程给删除了,所以修改的时候,需要重新调用新增接口)
  660. calendar := roadshow.RsCalendar{
  661. RsCalendarId: req.RsCalendarId,
  662. SysUserId: this.SysUser.AdminId,
  663. CompanyName: req.CompanyName,
  664. Title: getTitle(req.ActivityType, req.RoadshowType, req.ActivityCategory, req.RoadshowPlatform, req.Province, req.City),
  665. }
  666. researcher := *rsCalendarResearcherItem
  667. researcher.StartDate = v.StartDate
  668. researcher.EndDate = v.EndDate
  669. researcher.StartTime = v.StartTime
  670. researcher.EndTime = v.EndTime
  671. researcher.StartWeek = v.StartWeek
  672. researcher.EndWeek = v.EndWeek
  673. roadshowService.DeleteSHCalendar(req.RsCalendarResearcherId) //删除老的
  674. go roadshowService.CalendarToSH(calendar, researcher)
  675. if req.EditType == 2 {
  676. //模板消息通知
  677. go func(researcherId, tmpRsCalendarId, tmpRsCalendarResearcherId int) {
  678. sysAdmin, _ := system.GetSysAdminById(researcherId)
  679. if sysAdmin != nil && req.ActivityType != "内部会议" && req.ActivityType != "报告电话会" {
  680. first := "您收到一个新的【" + req.ActivityType + "】申请,请及时处理"
  681. keyword1 := sysUser.RealName
  682. keyword2 := "--"
  683. //keyword3 := time.Now().Format(utils.FormatDateTime)
  684. startDateSub := v.StartDate[5:]
  685. startDateSub = strings.Replace(startDateSub, "-", ".", -1)
  686. keyword3 := startDateSub + "(" + v.StartWeek + ")" + " " + v.StartTime[:5] + "~" + v.EndTime[:5]
  687. var keyword4 string
  688. if req.ActivityType == "路演" {
  689. keyword4 = req.CompanyName + "(" + req.RoadshowType + req.ActivityType + ")"
  690. } else {
  691. keyword4 = req.Theme + "(" + req.RoadshowType + req.ActivityType + ")"
  692. }
  693. remark := "请尽快完成审批"
  694. wxAppPath := "pages-approve/activity/detail?RsCalendarId=" + strconv.Itoa(tmpRsCalendarId) + "&RsCalendarResearcherId=" + strconv.Itoa(tmpRsCalendarResearcherId)
  695. openIdObj := &system.OpenIdList{
  696. OpenId: sysAdmin.OpenId,
  697. AdminId: sysAdmin.AdminId,
  698. }
  699. openIdList := make([]*system.OpenIdList, 0)
  700. openIdList = append(openIdList, openIdObj)
  701. if sysAdmin.OpenId != "" {
  702. services.SendWxMsgWithRoadshowPending(first, keyword1, keyword2, keyword3, keyword4, remark, wxAppPath, openIdList)
  703. }
  704. }
  705. }(v.ResearcherId, req.RsCalendarId, rsCalendarResearcherItem.RsCalendarResearcherId)
  706. }
  707. }
  708. } else {
  709. //先获取到所有的研究员日历表id
  710. researchers, err := roadshow.GetRsCalendarResearcherByCalendarId(req.RsCalendarId)
  711. if err != nil {
  712. utils.FileLog.Info("GetRsCalendarResearcherByCalendarId err: ", err)
  713. fmt.Println(err)
  714. return
  715. }
  716. //先删后增
  717. err = roadshow.DeleteRsCalendarResearcher(req.RsCalendarId)
  718. if err != nil {
  719. br.Msg = "保存失败!"
  720. br.ErrMsg = "保存失败!DeleteRsCalendarResearcher:" + err.Error()
  721. return
  722. }
  723. //删除上海
  724. for _, researcher := range researchers {
  725. roadshowService.DeleteSHCalendar(researcher.RsCalendarResearcherId)
  726. }
  727. for k, v := range req.ResearcherList {
  728. researcher := new(roadshow.RsCalendarResearcher)
  729. researcher.RsCalendarId = req.RsCalendarId
  730. researcher.ResearcherId = v.ResearcherId
  731. researcher.ResearcherName = v.ResearcherName
  732. researcher.StartDate = v.StartDate
  733. researcher.EndDate = v.EndDate
  734. researcher.StartTime = v.StartTime
  735. researcher.EndTime = v.EndTime
  736. researcher.StartWeek = v.StartWeek
  737. researcher.EndWeek = v.EndWeek
  738. researcher.CreateTime = time.Now()
  739. researcher.ModifyTime = time.Now()
  740. researcher.ResearcherSort = k + 1
  741. if req.ActivityType == "路演" || req.ActivityType == "公开会议" {
  742. researcher.Status = 1
  743. } else {
  744. researcher.Status = 2
  745. }
  746. //CRM15.5 权益研究员直接通过
  747. if raiAskadminMap[v.ResearcherId] {
  748. researcher.Status = 2
  749. }
  750. rsCalendarResearcherId, err := roadshow.AddRsCalendarResearcher(researcher)
  751. if err != nil {
  752. br.Msg = "保存失败!"
  753. br.ErrMsg = "保存日历活动-研究员信息失败!Err:" + err.Error()
  754. return
  755. }
  756. //上海新增
  757. calendar := roadshow.RsCalendar{
  758. RsCalendarId: req.RsCalendarId,
  759. SysUserId: this.SysUser.AdminId,
  760. Title: getTitle(req.ActivityType, req.RoadshowType, req.ActivityCategory, req.RoadshowPlatform, req.Province, req.City),
  761. }
  762. researcher.RsCalendarResearcherId = int(rsCalendarResearcherId)
  763. go roadshowService.CalendarToSH(calendar, *researcher)
  764. go func(researcherId, tmpRsCalendarId, tmpRsCalendarResearcherId int) {
  765. sysAdmin, _ := system.GetSysAdminById(researcherId)
  766. if sysAdmin != nil && req.ActivityType != "内部会议" && req.ActivityType != "报告电话会" {
  767. first := "您收到一个新的【" + req.ActivityType + "】申请,请及时处理"
  768. keyword1 := sysUser.RealName
  769. keyword2 := "--"
  770. //keyword3 := time.Now().Format(utils.FormatDateTime)
  771. startDateSub := v.StartDate[5:]
  772. startDateSub = strings.Replace(startDateSub, "-", ".", -1)
  773. keyword3 := startDateSub + "(" + v.StartWeek + ")" + " " + v.StartTime[:5] + "~" + v.EndTime[:5]
  774. var keyword4 string
  775. if req.ActivityType == "路演" {
  776. keyword4 = req.CompanyName + "(" + req.RoadshowType + req.ActivityType + ")"
  777. } else {
  778. keyword4 = req.Theme + "(" + req.RoadshowType + req.ActivityType + ")"
  779. }
  780. remark := "请尽快完成审批"
  781. wxAppPath := "pages-approve/activity/detail?RsCalendarId=" + strconv.Itoa(tmpRsCalendarId) + "&RsCalendarResearcherId=" + strconv.Itoa(tmpRsCalendarResearcherId)
  782. openIdObj := &system.OpenIdList{
  783. OpenId: sysAdmin.OpenId,
  784. AdminId: sysAdmin.AdminId,
  785. }
  786. openIdList := make([]*system.OpenIdList, 0)
  787. openIdList = append(openIdList, openIdObj)
  788. if sysAdmin.OpenId != "" {
  789. services.SendWxMsgWithRoadshowPending(first, keyword1, keyword2, keyword3, keyword4, remark, wxAppPath, openIdList)
  790. }
  791. }
  792. }(v.ResearcherId, req.RsCalendarId, int(rsCalendarResearcherId))
  793. }
  794. }
  795. //for k, v := range req.ResearcherList {
  796. // rsCalendarResearcherItem, err := roadshow.GetRsCalendarResearcherById(req.RsCalendarResearcherId)
  797. // var isAdd bool
  798. // if err != nil {
  799. // if err.Error() == utils.ErrNoRow() {
  800. // isAdd = true
  801. // } else {
  802. // br.Msg = "获取数据失败!"
  803. // br.ErrMsg = "获取数据失败!GetRsCalendarResearcherById:" + err.Error()
  804. // return
  805. // }
  806. // }
  807. // if rsCalendarResearcherItem == nil {
  808. // isAdd = true
  809. // }
  810. // if _, ok := existResearcherMap[v.ResearcherId]; !ok {
  811. // isAdd = true
  812. // }
  813. // fmt.Println("isAdd:", isAdd)
  814. // if isAdd {
  815. // exist, err := roadshow.GetRsCalendarResearcherExist(req.RsCalendarResearcherId, req.RsCalendarId, v.ResearcherId)
  816. // if err != nil && err.Error() != utils.ErrNoRow() {
  817. // br.Msg = "保存失败!"
  818. // br.ErrMsg = "保存失败!GetRsCalendarResearcherExist:" + err.Error()
  819. // return
  820. // }
  821. // if exist > 0 {
  822. // br.Msg = "研究员 " + v.ResearcherName + " 已存在相同活动"
  823. // br.ErrMsg = "研究员 " + v.ResearcherName + " 已存在相同活动"
  824. // return
  825. // }
  826. // researcher := new(roadshow.RsCalendarResearcher)
  827. // researcher.RsCalendarId = req.RsCalendarId
  828. // researcher.ResearcherId = v.ResearcherId
  829. // researcher.ResearcherName = v.ResearcherName
  830. // researcher.StartDate = v.StartDate
  831. // researcher.EndDate = v.EndDate
  832. // researcher.StartTime = v.StartTime
  833. // researcher.EndTime = v.EndTime
  834. // researcher.StartWeek = v.StartWeek
  835. // researcher.EndWeek = v.EndWeek
  836. // researcher.CreateTime = time.Now()
  837. // researcher.ModifyTime = time.Now()
  838. // researcher.ResearcherSort = k + 1
  839. // if req.ActivityType == "路演" || req.ActivityType == "公开会议" {
  840. // researcher.Status = 1
  841. // } else {
  842. // researcher.Status = 2
  843. // }
  844. // rsCalendarResearcherId, err := roadshow.AddRsCalendarResearcher(researcher)
  845. // if err != nil {
  846. // br.Msg = "保存失败!"
  847. // br.ErrMsg = "保存日历活动-研究员信息失败!Err:" + err.Error()
  848. // return
  849. // }
  850. //
  851. // //模板消息通知
  852. // {
  853. // sysAdmin, _ := system.GetSysAdminById(v.ResearcherId)
  854. // if sysAdmin != nil && req.ActivityType != "内部会议" && req.ActivityType != "报告电话会" {
  855. // first := "您收到一个新的【" + req.ActivityType + "】申请,请及时处理"
  856. // keyword1 := sysUser.RealName
  857. // keyword2 := "--"
  858. // keyword3 := time.Now().Format(utils.FormatDateTime)
  859. // startDateSub := v.StartDate[5:]
  860. // startDateSub = strings.Replace(startDateSub, "-", ".", -1)
  861. // var keyword4 string
  862. // if req.ActivityType == "路演" {
  863. // keyword4 = startDateSub + "(" + v.StartWeek + ")" + " " + v.StartTime[:5] + "~" + v.EndTime[:5] + " ," + req.CompanyName + "(" + req.RoadshowType + req.ActivityType + ")"
  864. // } else {
  865. // keyword4 = startDateSub + "(" + v.StartWeek + ")" + " " + v.StartTime[:5] + "~" + v.EndTime[:5] + " ," + req.Theme + "(" + req.RoadshowType + req.ActivityType + ")"
  866. // }
  867. // remark := "请尽快完成审批"
  868. // wxAppPath := "pages-approve/activity/detail?RsCalendarId=" + strconv.Itoa(req.RsCalendarId) + "&RsCalendarResearcherId=" + strconv.Itoa(int(rsCalendarResearcherId))
  869. // openIdList, _ := models.GetOpenIdListByMobile(sysAdmin.Mobile)
  870. // if len(openIdList) > 0 {
  871. // go services.SendWxMsgWithRoadshowPending(first, keyword1, keyword2, keyword3, keyword4, remark, wxAppPath, openIdList)
  872. // }
  873. // }
  874. // }
  875. // } else {
  876. // calendarResearcherWhereParams := make(map[string]interface{})
  877. // calendarResearcherUpdateParams := make(map[string]interface{})
  878. //
  879. // calendarResearcherWhereParams["rs_calendar_researcher_id"] = req.RsCalendarResearcherId
  880. //
  881. // exist, err := roadshow.GetRsCalendarResearcherExist(req.RsCalendarResearcherId, req.RsCalendarId, v.ResearcherId)
  882. // if err != nil && err.Error() != utils.ErrNoRow() {
  883. // br.Msg = "保存失败!"
  884. // br.ErrMsg = "保存失败!GetRsCalendarResearcherExist:" + err.Error()
  885. // return
  886. // }
  887. // if exist > 0 {
  888. // br.Msg = "研究员 " + v.ResearcherName + " 已存在相同活动"
  889. // br.ErrMsg = "研究员 " + v.ResearcherName + " 已存在相同活动"
  890. // return
  891. // }
  892. //
  893. // calendarResearcherUpdateParams["researcher_id"] = v.ResearcherId
  894. // calendarResearcherUpdateParams["researcher_name"] = v.ResearcherName
  895. //
  896. // if rsCalendarResearcherItem.Status == 3 || rsCalendarResearcherItem.Status == 5 {
  897. // calendarResearcherUpdateParams["status"] = 1
  898. // }
  899. // calendarResearcherUpdateParams["start_date"] = v.StartDate
  900. // calendarResearcherUpdateParams["end_date"] = v.EndDate
  901. // calendarResearcherUpdateParams["start_time"] = v.StartTime
  902. // calendarResearcherUpdateParams["end_time"] = v.EndTime
  903. // calendarResearcherUpdateParams["start_week"] = v.StartWeek
  904. // calendarResearcherUpdateParams["end_week"] = v.EndWeek
  905. // calendarResearcherUpdateParams["refuse_reason"] = ""
  906. // calendarResearcherUpdateParams["refuse_time"] = nil
  907. // calendarResearcherUpdateParams["delete_reason"] = ""
  908. // calendarResearcherUpdateParams["approve_time"] = nil
  909. // calendarResearcherUpdateParams["researcher_sort"] = k + 1
  910. // calendarResearcherUpdateParams["modify_time"] = time.Now()
  911. // calendarResearcherUpdateParams["create_time"] = time.Now()
  912. //
  913. // err = roadshow.UpdateCalendarResearcher(calendarResearcherWhereParams, calendarResearcherUpdateParams)
  914. // if err != nil {
  915. // br.Msg = "保存失败!"
  916. // br.ErrMsg = "保存失败!UpdateCalendarResearcher:" + err.Error()
  917. // return
  918. // }
  919. // if req.EditType == 2 {
  920. // //模板消息通知
  921. // {
  922. // sysAdmin, _ := system.GetSysAdminById(v.ResearcherId)
  923. // if sysAdmin != nil && req.ActivityType != "内部会议" && req.ActivityType != "报告电话会" {
  924. // first := "您收到一个新的【" + req.ActivityType + "】申请,请及时处理"
  925. // keyword1 := sysUser.RealName
  926. // keyword2 := "--"
  927. // keyword3 := time.Now().Format(utils.FormatDateTime)
  928. // startDateSub := v.StartDate[5:]
  929. // startDateSub = strings.Replace(startDateSub, "-", ".", -1)
  930. // var keyword4 string
  931. // if req.ActivityType == "路演" {
  932. // keyword4 = startDateSub + "(" + v.StartWeek + ")" + " " + v.StartTime[:5] + "~" + v.EndTime[:5] + " ," + req.CompanyName + "(" + req.RoadshowType + req.ActivityType + ")"
  933. // } else {
  934. // keyword4 = startDateSub + "(" + v.StartWeek + ")" + " " + v.StartTime[:5] + "~" + v.EndTime[:5] + " ," + req.Theme + "(" + req.RoadshowType + req.ActivityType + ")"
  935. // }
  936. // remark := "请尽快完成审批"
  937. // wxAppPath := "pages-approve/activity/detail?RsCalendarId=" + strconv.Itoa(req.RsCalendarId) + "&RsCalendarResearcherId=" + strconv.Itoa(rsCalendarResearcherItem.RsCalendarResearcherId)
  938. // openIdList, _ := models.GetOpenIdListByMobile(sysAdmin.Mobile)
  939. // if len(openIdList) > 0 {
  940. // go services.SendWxMsgWithRoadshowPending(first, keyword1, keyword2, keyword3, keyword4, remark, wxAppPath, openIdList)
  941. // }
  942. // }
  943. // }
  944. // }
  945. //
  946. // }
  947. // newResearcherMap[v.ResearcherId] = v.ResearcherName
  948. //}
  949. //处理删除情况
  950. //{
  951. // if req.EditType == 1 {
  952. // researchList, err := roadshow.GetRsCalendarResearcherListByRsCalendarId(req.RsCalendarId)
  953. // if err != nil {
  954. // br.Msg = "保存失败!"
  955. // br.ErrMsg = "保存失败!UpdateCalendarResearcher:" + err.Error()
  956. // return
  957. // }
  958. // for _, ev := range researchList {
  959. // if _, ok := newResearcherMap[ev.ResearcherId]; !ok {
  960. // roadshow.DeleteCalendar(req.RsCalendarId, ev.RsCalendarResearcherId)
  961. // }
  962. // }
  963. // }
  964. //}
  965. //if req.ActivityType == "公开会议" {
  966. // go roadshowService.SetPublicMeetingUnionCode()
  967. //}
  968. br.Ret = 200
  969. br.Success = true
  970. br.Msg = "保存成功"
  971. br.IsAddLog = true
  972. }
  973. // ResearcherList
  974. // @Title 研究员列表
  975. // @Description 研究员列表接口
  976. // @Success 200 {object} roadshow.ResearcherGroup
  977. // @router /researcher/list [get]
  978. func (this *CalendarController) ResearcherList() {
  979. br := new(models.BaseResponse).Init()
  980. defer func() {
  981. this.Data["json"] = br
  982. this.ServeJSON()
  983. }()
  984. group, err := roadshow.GetResearcherGroup()
  985. if err != nil {
  986. br.Msg = "获取信息失败!"
  987. br.ErrMsg = "获取分组信息失败!Err:" + err.Error()
  988. return
  989. }
  990. researcherList, err := roadshow.GetResearcher()
  991. groupMap := make(map[int][]*roadshow.ResearcherGroup)
  992. for _, v := range researcherList {
  993. item := &roadshow.ResearcherGroup{
  994. GroupId: v.GroupId,
  995. GroupName: v.GroupName,
  996. AdminId: v.AdminId,
  997. RealName: v.RealName,
  998. RoleTypeCode: v.RoleTypeCode,
  999. }
  1000. if findItems, ok := groupMap[v.GroupId]; ok {
  1001. findItems = append(findItems, item)
  1002. groupMap[v.GroupId] = findItems
  1003. } else {
  1004. findItems = append(findItems, item)
  1005. groupMap[v.GroupId] = findItems
  1006. }
  1007. //}
  1008. }
  1009. for _, v := range group {
  1010. v.ResearcherList = groupMap[v.GroupId]
  1011. }
  1012. ficcGroup := new(roadshow.ResearcherGroup)
  1013. ficcGroup.GroupId = 999
  1014. ficcGroup.GroupName = "ficc"
  1015. ficcGroup.ResearcherList = group
  1016. sysUserList, err := system.GetAdminList()
  1017. if err != nil {
  1018. br.Msg = "获取失败"
  1019. br.ErrMsg = "获取admin列表失败, Err:" + err.Error()
  1020. return
  1021. }
  1022. adminMap := make(map[int]*system.Admin, 0)
  1023. for _, v := range sysUserList {
  1024. adminMap[v.AdminId] = v
  1025. }
  1026. askUserList, err := cygx.GetAskEmailList()
  1027. if err != nil {
  1028. br.Msg = "获取失败"
  1029. br.ErrMsg = "获取失败,GetAskEmailList Err: " + err.Error()
  1030. return
  1031. }
  1032. mapPermissionUser := make(map[string][]*roadshow.ResearcherGroup)
  1033. listPermission, err := cygx.GetChartPermissionAll()
  1034. if err != nil {
  1035. br.Msg = "获取信息失败"
  1036. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  1037. return
  1038. }
  1039. mapPermissionId := make(map[string]int)
  1040. for _, v := range listPermission {
  1041. mapPermissionId[v.PermissionName] = v.ChartPermissionId
  1042. }
  1043. sysUserFwang, e := system.GetSysUserByAdminName("fwang") // 手动拼接王芳到权益的策略行业下 start
  1044. if e != nil {
  1045. if e.Error() == utils.ErrNoRow() {
  1046. br.Msg = "用户不存在, 请检查"
  1047. return
  1048. }
  1049. br.Msg = "账号错误, 请重新输入"
  1050. br.ErrMsg = "fwang 用户名获取用户失败, Err: " + e.Error()
  1051. return
  1052. }
  1053. itemFwang := new(roadshow.ResearcherGroup)
  1054. itemFwang.AdminId = sysUserFwang.AdminId
  1055. itemFwang.GroupId = sysUserFwang.GroupId
  1056. itemFwang.GroupName = sysUserFwang.GroupName
  1057. itemFwang.RealName = sysUserFwang.RealName
  1058. itemFwang.RoleTypeCode = sysUserFwang.RoleTypeCode
  1059. mapPermissionUser["策略"] = append(mapPermissionUser["策略"], itemFwang) // 手动拼接王芳到权益的策略行业下 end
  1060. for _, v := range askUserList {
  1061. if admin, ok := adminMap[v.AdminId]; ok {
  1062. item := &roadshow.ResearcherGroup{
  1063. AdminId: v.AdminId,
  1064. RealName: v.Name,
  1065. GroupId: admin.GroupId,
  1066. GroupName: admin.GroupName,
  1067. RoleTypeCode: admin.RoleTypeCode,
  1068. }
  1069. mapPermissionUser[v.ChartPermissionName] = append(mapPermissionUser[v.ChartPermissionName], item)
  1070. }
  1071. }
  1072. raiList := make([]*roadshow.ResearcherGroup, 0)
  1073. for k, v := range mapPermissionUser {
  1074. respItem := new(roadshow.ResearcherGroup)
  1075. respItem.GroupName = k + "组"
  1076. respItem.GroupId = mapPermissionId[k]
  1077. respItem.ResearcherList = v
  1078. raiList = append(raiList, respItem)
  1079. }
  1080. raiGroup := new(roadshow.ResearcherGroup)
  1081. raiGroup.GroupId = 888
  1082. raiGroup.GroupName = "权益"
  1083. raiGroup.ResearcherList = raiList
  1084. var resp []*roadshow.ResearcherGroup
  1085. resp = append(resp, ficcGroup, raiGroup)
  1086. br.Ret = 200
  1087. br.Success = true
  1088. br.Msg = "获取成功"
  1089. br.Data = resp
  1090. }
  1091. // CalendarList
  1092. // @Title 我的日历列表
  1093. // @Description 我的日历列表接口
  1094. // @Param PageSize query int true "每页数据条数"
  1095. // @Param CurrentIndex query int true "当前页页码,从1开始"
  1096. // @Param CalendarType query int true "1:待处理申请,2:已处理申请,3:内部会议,4:报告电话会"
  1097. // @Success 200 {object} roadshow.CalendarListResp
  1098. // @router /calendar/list [get]
  1099. func (this *CalendarController) CalendarList() {
  1100. br := new(models.BaseResponse).Init()
  1101. defer func() {
  1102. this.Data["json"] = br
  1103. this.ServeJSON()
  1104. }()
  1105. sysUser := this.SysUser
  1106. if sysUser == nil {
  1107. br.Msg = "请登录"
  1108. br.ErrMsg = "请登录,SysUser Is Empty"
  1109. br.Ret = 408
  1110. return
  1111. }
  1112. calendarType, _ := this.GetInt("CalendarType")
  1113. pageSize, _ := this.GetInt("PageSize")
  1114. currentIndex, _ := this.GetInt("CurrentIndex")
  1115. var total int
  1116. page := paging.GetPaging(currentIndex, pageSize, total)
  1117. var startSize int
  1118. if pageSize <= 0 {
  1119. pageSize = utils.PageSize10
  1120. }
  1121. if currentIndex <= 0 {
  1122. currentIndex = 1
  1123. }
  1124. startSize = paging.StartIndex(currentIndex, pageSize)
  1125. var condition string
  1126. var pars []interface{}
  1127. roleTypeCode := sysUser.RoleTypeCode
  1128. //销售
  1129. if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_SELLER ||
  1130. //roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER ||
  1131. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP ||
  1132. //roleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP ||
  1133. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_TEAM ||
  1134. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  1135. condition += ` AND a.sys_user_id=?`
  1136. pars = append(pars, sysUser.AdminId)
  1137. //condition += ` AND a.activity_type IN('路演','公开会议') `
  1138. }
  1139. //权益销售
  1140. if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER ||
  1141. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  1142. //if calendarType == 2 {
  1143. condition += ` AND ( a.sys_user_id=? OR a.seller_id=? OR a.share_seller_id=? ) `
  1144. pars = append(pars, sysUser.AdminId, sysUser.AdminId, sysUser.AdminId)
  1145. //}
  1146. }
  1147. if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_RESEARCHR ||
  1148. roleTypeCode == utils.ROLE_TYPE_CODE_RESEARCHR ||
  1149. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_RESEARCHR ||
  1150. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_DEPARTMENT ||
  1151. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_DEPARTMENT ||
  1152. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN {
  1153. if calendarType != 3 {
  1154. condition += ` AND b.researcher_id=?`
  1155. pars = append(pars, sysUser.AdminId)
  1156. }
  1157. }
  1158. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  1159. condition += ` AND a.sys_user_id=?`
  1160. pars = append(pars, sysUser.AdminId)
  1161. }
  1162. if calendarType == 1 {
  1163. condition += ` AND b.status=1`
  1164. }
  1165. if calendarType == 2 {
  1166. condition += ` AND b.status>=2`
  1167. condition += ` AND a.activity_type IN('路演','公开会议','沙龙') `
  1168. }
  1169. if calendarType == 3 {
  1170. condition += ` AND a.activity_type='内部会议' `
  1171. condition += ` AND a.sys_user_id=?`
  1172. pars = append(pars, sysUser.AdminId)
  1173. }
  1174. if calendarType == 4 {
  1175. condition += ` AND a.activity_type='报告电话会' `
  1176. }
  1177. if calendarType < 0 || calendarType > 4 {
  1178. br.Msg = "参数错误"
  1179. br.ErrMsg = "参数错误,calendarType:" + strconv.Itoa(calendarType)
  1180. return
  1181. }
  1182. fmt.Println(condition)
  1183. resp := new(roadshow.CalendarListResp)
  1184. total, err := roadshow.GetCalendarListCount(condition, pars, calendarType)
  1185. if err != nil && err.Error() != utils.ErrNoRow() {
  1186. br.Msg = "获取信息失败"
  1187. br.ErrMsg = "获取数据总数失败,GetCalendarListCount,Err:" + err.Error()
  1188. return
  1189. }
  1190. page = paging.GetPaging(currentIndex, pageSize, total)
  1191. dataList, err := roadshow.GetCalendarList(condition, pars, startSize, pageSize, calendarType)
  1192. if err != nil {
  1193. br.Msg = "获取指标信息失败"
  1194. br.ErrMsg = "获取数据失败,GetCalendarList,Err:" + err.Error()
  1195. return
  1196. }
  1197. // 英文客户的国家以及点击量
  1198. englishIds := make([]int, 0)
  1199. adminIds := make([]int, 0) // 管理员ID
  1200. rsCalendarId := make([]int, 0) //路演ID
  1201. for i := range dataList {
  1202. if dataList[i].EnglishCompany == 1 {
  1203. englishIds = append(englishIds, dataList[i].CompanyId)
  1204. }
  1205. if calendarType == 2 {
  1206. adminIds = append(adminIds, dataList[i].SysUserId)
  1207. rsCalendarId = append(rsCalendarId, dataList[i].RsCalendarId)
  1208. }
  1209. }
  1210. englishMap := make(map[int]*models.EnglishCompany)
  1211. if len(englishIds) > 0 {
  1212. englishCond := ` AND company_id IN (` + utils.GetOrmInReplace(len(englishIds)) + `)`
  1213. englishPars := make([]interface{}, 0)
  1214. englishPars = append(englishPars, englishIds)
  1215. englishList, e := models.GetEnglishCompanyList(englishCond, englishPars, "")
  1216. if e != nil {
  1217. br.Msg = "获取英文客户失败"
  1218. br.ErrMsg = "获取英文客户失败, Err:" + e.Error()
  1219. return
  1220. }
  1221. for i := range englishList {
  1222. englishMap[englishList[i].CompanyId] = englishList[i]
  1223. }
  1224. }
  1225. //获取所有自定义的权益研究员
  1226. sysUserList, err := cygx.GetAskEmailList()
  1227. if err != nil {
  1228. br.Msg = "获取失败"
  1229. br.ErrMsg = "获取失败,GetAskEmailList Err: " + err.Error()
  1230. return
  1231. }
  1232. raiAskadminMap := make(map[string]bool, 0)
  1233. for _, v := range sysUserList {
  1234. raiAskadminMap[strconv.Itoa(v.AdminId)] = true
  1235. }
  1236. mapRaiSllerId := make(map[int]bool) // 是否为权益销售
  1237. mapMeetingCount := make(map[int]int) // 路演参会人员数量
  1238. if len(adminIds) > 0 {
  1239. listAdmin, e := system.GetAdminListByIdListWithoutEnable(adminIds)
  1240. if e != nil {
  1241. br.Msg = "获取信息失败"
  1242. br.ErrMsg = "获取管理员信息失败, Err:" + e.Error()
  1243. return
  1244. }
  1245. for _, v := range listAdmin { //权益销售与权益销售组长、权益管理员
  1246. if v.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER || v.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP || v.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN {
  1247. mapRaiSllerId[v.AdminId] = true
  1248. }
  1249. }
  1250. listMeetingCount, e := roadshow.GetRsCalendarMeetingUserListCount(rsCalendarId)
  1251. if e != nil {
  1252. br.Msg = "获取信息失败"
  1253. br.ErrMsg = "获取路演参会人员数量信息失败, Err:" + e.Error()
  1254. return
  1255. }
  1256. for _, v := range listMeetingCount {
  1257. mapMeetingCount[v.RsCalendarId] = v.Total
  1258. }
  1259. }
  1260. for i := range dataList {
  1261. if dataList[i].EnglishCompany == 1 {
  1262. en := englishMap[dataList[i].CompanyId]
  1263. if en != nil {
  1264. dataList[i].EnglishCountry = en.Country
  1265. dataList[i].EnglishViewTotal = en.ViewTotal
  1266. }
  1267. }
  1268. //如果是已结束的权益销售添加的活动,就行进行按钮展示
  1269. if mapRaiSllerId[dataList[i].SysUserId] && utils.InArrayByInt([]int{2, 6}, dataList[i].Status) && dataList[i].ActivityType != "沙龙" {
  1270. if mapMeetingCount[dataList[i].RsCalendarId] == 0 {
  1271. dataList[i].SubmitButton = true
  1272. } else {
  1273. dataList[i].ViewButton = true
  1274. }
  1275. }
  1276. //权益研究员的【路演】和【沙龙】,未结束时,显示修改按钮
  1277. if raiAskadminMap[dataList[i].ResearcherId] && utils.InArrayByStr([]string{"路演", "沙龙"}, dataList[i].ActivityType) && dataList[i].Status == 2 {
  1278. //未开始的才展示修改按钮
  1279. startTimeStr := dataList[i].StartDate + " " + dataList[i].StartTime
  1280. startTime := utils.StrTimeToTime(startTimeStr)
  1281. if startTime.After(time.Now()) {
  1282. dataList[i].EditButton = true
  1283. }
  1284. }
  1285. }
  1286. resp.Paging = page
  1287. resp.List = dataList
  1288. br.Ret = 200
  1289. br.Success = true
  1290. br.Msg = "获取成功"
  1291. br.Data = resp
  1292. }
  1293. // Accept
  1294. // @Description 接受路演活动接口
  1295. // @Param request body roadshow.AcceptReq true "type json string"
  1296. // @Success Ret=200 保存成功
  1297. // @router /accept [post]
  1298. func (this *CalendarController) Accept() {
  1299. br := new(models.BaseResponse).Init()
  1300. defer func() {
  1301. this.Data["json"] = br
  1302. this.ServeJSON()
  1303. }()
  1304. sysUser := this.SysUser
  1305. if sysUser == nil {
  1306. br.Msg = "请登录"
  1307. br.ErrMsg = "请登录,SysUser Is Empty"
  1308. br.Ret = 408
  1309. return
  1310. }
  1311. var req roadshow.AcceptReq
  1312. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1313. if err != nil {
  1314. br.Msg = "参数解析异常!"
  1315. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1316. return
  1317. }
  1318. if req.RsCalendarId <= 0 || req.RsCalendarResearcherId <= 0 {
  1319. br.Msg = "参数错误!"
  1320. br.ErrMsg = "参数错误!RsCalendarId:" + strconv.Itoa(req.RsCalendarId) + ";RsCalendarResearcherId:" + strconv.Itoa(req.RsCalendarResearcherId)
  1321. return
  1322. }
  1323. rsCalendar, err := roadshow.GetRsCalendarById(req.RsCalendarId)
  1324. if err != nil {
  1325. br.Msg = "获取数据失败!"
  1326. br.ErrMsg = "获取数据失败!GetRsCalendarById:" + err.Error()
  1327. return
  1328. }
  1329. rsCalendarResearcher, err := roadshow.GetRsCalendarResearcherById(req.RsCalendarResearcherId)
  1330. if err != nil {
  1331. br.Msg = "获取数据失败!"
  1332. br.ErrMsg = "获取数据失败!GetRsCalendarResearcherById:" + err.Error()
  1333. return
  1334. }
  1335. if rsCalendarResearcher.Status == 2 {
  1336. br.Msg = "已接受,不可重复操作!"
  1337. return
  1338. } else if rsCalendarResearcher.Status == 3 {
  1339. br.Msg = "已拒绝,不可进行接受操作!"
  1340. return
  1341. } else if rsCalendarResearcher.Status == 4 {
  1342. br.Msg = "已删除,不可进行接受操作!"
  1343. return
  1344. } else if rsCalendarResearcher.Status == 5 {
  1345. br.Msg = "已撤回,不可进行接受操作!"
  1346. return
  1347. }
  1348. whereParams := make(map[string]interface{})
  1349. updateParams := make(map[string]interface{})
  1350. whereParams["rs_calendar_researcher_id"] = req.RsCalendarResearcherId
  1351. whereParams["rs_calendar_id"] = req.RsCalendarId
  1352. updateParams["status"] = 2
  1353. updateParams["modify_time"] = time.Now()
  1354. updateParams["approve_time"] = time.Now()
  1355. err = roadshow.UpdateCalendarResearcher(whereParams, updateParams)
  1356. if err != nil {
  1357. br.Msg = "保存失败!"
  1358. br.ErrMsg = "保存失败!UpdateCalendarResearcher:" + err.Error()
  1359. return
  1360. }
  1361. rsCalendarResearcherItemList, err := roadshow.GetRsCalendarResearcherListById(req.RsCalendarId)
  1362. if err != nil {
  1363. br.Msg = "获取数据失败!"
  1364. br.ErrMsg = "获取数据失败!GetRsCalendarResearcherById:" + err.Error()
  1365. return
  1366. }
  1367. for _, v := range rsCalendarResearcherItemList {
  1368. go roadshowService.CalendarToSH(*rsCalendar, *v)
  1369. }
  1370. //模板消息通知
  1371. {
  1372. if rsCalendar != nil {
  1373. go func(tmpRsCalendar roadshow.RsCalendar) {
  1374. sysAdmin, _ := system.GetSysAdminById(tmpRsCalendar.SysUserId)
  1375. first := "【" + sysUser.RealName + "】接受了你的【" + tmpRsCalendar.ActivityType + "】申请"
  1376. var keyword1, keyword2, keyword3, keyword4, keyword5 string
  1377. keyword1 = tmpRsCalendar.CompanyName + "(" + tmpRsCalendar.RoadshowType + tmpRsCalendar.ActivityType + ")"
  1378. keyword2 = tmpRsCalendar.ActivityType
  1379. keyword4 = `【` + sysUser.RealName + `】已接受`
  1380. remark := ""
  1381. wxAppPath := ""
  1382. openIdObj := &system.OpenIdList{
  1383. OpenId: sysAdmin.OpenId,
  1384. AdminId: sysAdmin.AdminId,
  1385. }
  1386. openIdList := make([]*system.OpenIdList, 0)
  1387. openIdList = append(openIdList, openIdObj)
  1388. if sysAdmin.OpenId != "" {
  1389. services.SendWxMsgWithRoadshowDetailResult(first, keyword1, keyword2, keyword3, keyword4, keyword5, remark, wxAppPath, openIdList)
  1390. }
  1391. }(*rsCalendar)
  1392. }
  1393. }
  1394. br.Ret = 200
  1395. br.Success = true
  1396. br.Msg = "保存成功"
  1397. br.IsAddLog = true
  1398. }
  1399. // @Title 拒绝路演活动接口
  1400. // @Description 拒绝路演活动接口
  1401. // @Param request body roadshow.RefuseReq true "type json string"
  1402. // @Success Ret=200 保存成功
  1403. // @router /refuse [post]
  1404. func (this *CalendarController) Refuse() {
  1405. br := new(models.BaseResponse).Init()
  1406. defer func() {
  1407. this.Data["json"] = br
  1408. this.ServeJSON()
  1409. }()
  1410. sysUser := this.SysUser
  1411. if sysUser == nil {
  1412. br.Msg = "请登录"
  1413. br.ErrMsg = "请登录,SysUser Is Empty"
  1414. br.Ret = 408
  1415. return
  1416. }
  1417. var req roadshow.RefuseReq
  1418. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1419. if err != nil {
  1420. br.Msg = "参数解析异常!"
  1421. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1422. return
  1423. }
  1424. if req.RsCalendarId <= 0 || req.RsCalendarResearcherId <= 0 {
  1425. br.Msg = "参数错误!"
  1426. br.ErrMsg = "参数错误!RsCalendarId:" + strconv.Itoa(req.RsCalendarId) + ";RsCalendarResearcherId:" + strconv.Itoa(req.RsCalendarResearcherId)
  1427. return
  1428. }
  1429. rsCalendar, err := roadshow.GetRsCalendarById(req.RsCalendarId)
  1430. if err != nil {
  1431. br.Msg = "获取数据失败!"
  1432. br.ErrMsg = "获取数据失败!GetRsCalendarById:" + err.Error()
  1433. return
  1434. }
  1435. rsCalendarResearcher, err := roadshow.GetRsCalendarResearcherById(req.RsCalendarResearcherId)
  1436. if err != nil {
  1437. br.Msg = "获取数据失败!"
  1438. br.ErrMsg = "获取数据失败!GetRsCalendarResearcherById:" + err.Error()
  1439. return
  1440. }
  1441. if rsCalendarResearcher.Status == 2 {
  1442. br.Msg = "已接受,不可进行拒绝操作!"
  1443. return
  1444. } else if rsCalendarResearcher.Status == 3 {
  1445. br.Msg = "已拒绝,不可进行重复操作!"
  1446. return
  1447. } else if rsCalendarResearcher.Status == 4 {
  1448. br.Msg = "已删除,不可进行拒绝操作!"
  1449. return
  1450. } else if rsCalendarResearcher.Status == 5 {
  1451. br.Msg = "已撤回,不可进行拒绝操作!"
  1452. return
  1453. }
  1454. whereParams := make(map[string]interface{})
  1455. updateParams := make(map[string]interface{})
  1456. whereParams["rs_calendar_researcher_id"] = req.RsCalendarResearcherId
  1457. whereParams["rs_calendar_id"] = req.RsCalendarId
  1458. updateParams["status"] = 3
  1459. updateParams["refuse_reason"] = req.RefuseReason
  1460. updateParams["refuse_time"] = time.Now()
  1461. updateParams["modify_time"] = time.Now()
  1462. err = roadshow.UpdateCalendarResearcher(whereParams, updateParams)
  1463. if err != nil {
  1464. br.Msg = "保存失败!"
  1465. br.ErrMsg = "保存失败!UpdateCalendarResearcher:" + err.Error()
  1466. return
  1467. }
  1468. //拒绝后,需要删除该日程
  1469. go roadshowService.DeleteSHCalendar(req.RsCalendarResearcherId)
  1470. //模板消息通知
  1471. {
  1472. if rsCalendar != nil {
  1473. go func(tmpRsCalendar roadshow.RsCalendar) {
  1474. sysAdmin, _ := system.GetSysAdminById(tmpRsCalendar.SysUserId)
  1475. first := "【" + sysUser.RealName + "】拒绝了你的【" + tmpRsCalendar.ActivityType + "】申请"
  1476. var keyword1, keyword2, keyword3, keyword4, keyword5 string
  1477. keyword1 = tmpRsCalendar.CompanyName + "(" + tmpRsCalendar.RoadshowType + tmpRsCalendar.ActivityType + ")"
  1478. keyword2 = tmpRsCalendar.ActivityType
  1479. keyword4 = `【` + sysUser.RealName + `】已拒绝`
  1480. keyword5 = req.RefuseReason
  1481. remark := req.RefuseReason
  1482. wxAppPath := ""
  1483. openIdObj := &system.OpenIdList{
  1484. OpenId: sysAdmin.OpenId,
  1485. AdminId: sysAdmin.AdminId,
  1486. }
  1487. openIdList := make([]*system.OpenIdList, 0)
  1488. openIdList = append(openIdList, openIdObj)
  1489. if sysAdmin.OpenId != "" {
  1490. services.SendWxMsgWithRoadshowDetailResult(first, keyword1, keyword2, keyword3, keyword4, keyword5, remark, wxAppPath, openIdList)
  1491. }
  1492. }(*rsCalendar)
  1493. }
  1494. }
  1495. br.Ret = 200
  1496. br.Success = true
  1497. br.Msg = "保存成功"
  1498. br.IsAddLog = true
  1499. }
  1500. // @Title 撤回路演活动接口
  1501. // @Description 撤回路演活动接口
  1502. // @Param request body roadshow.AcceptReq true "type json string"
  1503. // @Success Ret=200 保存成功
  1504. // @router /back [post]
  1505. func (this *CalendarController) Back() {
  1506. br := new(models.BaseResponse).Init()
  1507. defer func() {
  1508. this.Data["json"] = br
  1509. this.ServeJSON()
  1510. }()
  1511. sysUser := this.SysUser
  1512. if sysUser == nil {
  1513. br.Msg = "请登录"
  1514. br.ErrMsg = "请登录,SysUser Is Empty"
  1515. br.Ret = 408
  1516. return
  1517. }
  1518. var req roadshow.AcceptReq
  1519. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1520. if err != nil {
  1521. br.Msg = "参数解析异常!"
  1522. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1523. return
  1524. }
  1525. if req.RsCalendarId <= 0 || req.RsCalendarResearcherId <= 0 {
  1526. br.Msg = "参数错误!"
  1527. br.ErrMsg = "参数错误!RsCalendarId:" + strconv.Itoa(req.RsCalendarId) + ";RsCalendarResearcherId:" + strconv.Itoa(req.RsCalendarResearcherId)
  1528. return
  1529. }
  1530. _, err = roadshow.GetRsCalendarById(req.RsCalendarId)
  1531. if err != nil {
  1532. br.Msg = "获取数据失败!"
  1533. br.ErrMsg = "获取数据失败!GetRsCalendarById:" + err.Error()
  1534. return
  1535. }
  1536. rsCalendarResearcher, err := roadshow.GetRsCalendarResearcherById(req.RsCalendarResearcherId)
  1537. if err != nil {
  1538. br.Msg = "获取数据失败!"
  1539. br.ErrMsg = "获取数据失败!GetRsCalendarResearcherById:" + err.Error()
  1540. return
  1541. }
  1542. if rsCalendarResearcher.Status == 2 {
  1543. br.Msg = "已接受,不可进行撤回操作!"
  1544. return
  1545. } else if rsCalendarResearcher.Status == 3 {
  1546. br.Msg = "已拒绝,不可进行撤回操作!"
  1547. return
  1548. } else if rsCalendarResearcher.Status == 4 {
  1549. br.Msg = "已删除,不可进行撤回操作!"
  1550. return
  1551. } else if rsCalendarResearcher.Status == 5 {
  1552. br.Msg = "已撤回,不可进行重复操作!"
  1553. return
  1554. }
  1555. whereParams := make(map[string]interface{})
  1556. updateParams := make(map[string]interface{})
  1557. whereParams["rs_calendar_researcher_id"] = req.RsCalendarResearcherId
  1558. whereParams["rs_calendar_id"] = req.RsCalendarId
  1559. updateParams["status"] = 5
  1560. updateParams["modify_time"] = time.Now()
  1561. err = roadshow.UpdateCalendarResearcher(whereParams, updateParams)
  1562. //撤回后,需要删除该日程
  1563. go roadshowService.DeleteSHCalendar(req.RsCalendarResearcherId)
  1564. if err != nil {
  1565. br.Msg = "保存失败!"
  1566. br.ErrMsg = "保存失败!UpdateCalendarResearcher:" + err.Error()
  1567. return
  1568. }
  1569. br.Ret = 200
  1570. br.Success = true
  1571. br.Msg = "保存成功"
  1572. br.IsAddLog = true
  1573. }
  1574. // @Title 删除路演活动接口
  1575. // @Description 删除路演活动接口
  1576. // @Param request body roadshow.DeleteReq true "type json string"
  1577. // @Success Ret=200 保存成功
  1578. // @router /delete [post]
  1579. func (this *CalendarController) Delete() {
  1580. br := new(models.BaseResponse).Init()
  1581. defer func() {
  1582. this.Data["json"] = br
  1583. this.ServeJSON()
  1584. }()
  1585. sysUser := this.SysUser
  1586. if sysUser == nil {
  1587. br.Msg = "请登录"
  1588. br.ErrMsg = "请登录,SysUser Is Empty"
  1589. br.Ret = 408
  1590. return
  1591. }
  1592. var req roadshow.DeleteReq
  1593. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1594. if err != nil {
  1595. br.Msg = "参数解析异常!"
  1596. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1597. return
  1598. }
  1599. if req.RsCalendarId <= 0 || req.RsCalendarResearcherId <= 0 {
  1600. br.Msg = "参数错误!"
  1601. br.ErrMsg = "参数错误!RsCalendarId:" + strconv.Itoa(req.RsCalendarId) + ";RsCalendarResearcherId:" + strconv.Itoa(req.RsCalendarResearcherId)
  1602. return
  1603. }
  1604. rsCalendarItem, err := roadshow.GetRsCalendarById(req.RsCalendarId)
  1605. if err != nil {
  1606. br.Msg = "获取数据失败!"
  1607. br.ErrMsg = "获取数据失败!GetRsCalendarById:" + err.Error()
  1608. return
  1609. }
  1610. rsCalendarResearcherItemList, err := roadshow.GetRsCalendarResearcherListById(req.RsCalendarId)
  1611. if err != nil {
  1612. br.Msg = "获取数据失败!"
  1613. br.ErrMsg = "获取数据失败!GetRsCalendarResearcherById:" + err.Error()
  1614. return
  1615. }
  1616. if rsCalendarItem.ActivityType == "报告电话会" || rsCalendarItem.ActivityType == "内部会议" {
  1617. err = roadshow.DeleteCalendar(req.RsCalendarId, req.RsCalendarResearcherId)
  1618. if err != nil {
  1619. br.Msg = "删除失败!"
  1620. br.ErrMsg = "删除失败!DeleteCalendar:" + err.Error()
  1621. return
  1622. }
  1623. //检测报表记录中是否已经存在,如果存在,则删除
  1624. {
  1625. err = roadshow.DeleteRsReportRecord(req.RsCalendarId, req.RsCalendarResearcherId)
  1626. if err != nil {
  1627. br.Msg = "删除失败!"
  1628. br.ErrMsg = "删除失败!DeleteRsReportRecord:" + err.Error()
  1629. return
  1630. }
  1631. }
  1632. } else {
  1633. //只获取一条路演数据
  1634. rsCalendarResearcherItemList, err = roadshow.GetRsCalendarResearcherListByCalendarResearcherId(req.RsCalendarResearcherId)
  1635. if err != nil {
  1636. br.Msg = "获取数据失败!"
  1637. br.ErrMsg = "获取数据失败!GetRsCalendarResearcherById:" + err.Error()
  1638. return
  1639. }
  1640. whereParams := make(map[string]interface{})
  1641. updateParams := make(map[string]interface{})
  1642. whereParams["rs_calendar_researcher_id"] = req.RsCalendarResearcherId
  1643. whereParams["rs_calendar_id"] = req.RsCalendarId
  1644. updateParams["status"] = 4
  1645. updateParams["delete_reason"] = req.DeleteReason
  1646. updateParams["modify_time"] = time.Now()
  1647. updateParams["delete_time"] = time.Now()
  1648. err = roadshow.UpdateCalendarResearcher(whereParams, updateParams)
  1649. if err != nil {
  1650. br.Msg = "删除失败!"
  1651. br.ErrMsg = "删除失败!UpdateCalendarResearcher:" + err.Error()
  1652. return
  1653. }
  1654. }
  1655. itemApiLog := new(roadshow.RsCalendarApiLog)
  1656. itemApiLog.CreateTime = time.Now()
  1657. itemApiLog.Remark = "CRM手动删除"
  1658. itemApiLog.Url = sysUser.RealName
  1659. itemApiLog.Body = ""
  1660. itemApiLog.Result = ""
  1661. itemApiLog.RsCalendarResearcherId = req.RsCalendarResearcherId
  1662. itemApiLog.RsCalendarId = req.RsCalendarId
  1663. go roadshow.AddRsCalendarApiLog(itemApiLog)
  1664. //`status` int(11) DEFAULT '0' COMMENT '1:待接受,2:已接受,3:已拒绝,4:已删除,5:已撤回,6:已结束',
  1665. //待接受、已接受的情况,需要同步删除上海那边的日程
  1666. for _, rsCalendarResearcherItem := range rsCalendarResearcherItemList {
  1667. //删除上海的活动
  1668. if rsCalendarResearcherItem.Status == 1 || rsCalendarResearcherItem.Status == 2 {
  1669. go roadshowService.DeleteSHCalendar(rsCalendarResearcherItem.RsCalendarResearcherId)
  1670. }
  1671. //模板消息通知
  1672. {
  1673. if rsCalendarItem != nil && rsCalendarResearcherItem != nil {
  1674. go func(tmpRsCalendarItem roadshow.RsCalendar, tmpRsCalendarResearcherItem roadshow.RsCalendarResearcher) {
  1675. sysAdmin, _ := system.GetSysAdminById(tmpRsCalendarResearcherItem.ResearcherId)
  1676. var first string
  1677. var wxAppPath string
  1678. if tmpRsCalendarItem.ActivityType == "路演" || tmpRsCalendarItem.ActivityType == "公开会议" {
  1679. wxAppPath = "pages-approve/activity/detail?RsCalendarId=" + strconv.Itoa(tmpRsCalendarItem.RsCalendarId) + "&RsCalendarResearcherId=" + strconv.Itoa(tmpRsCalendarResearcherItem.RsCalendarResearcherId)
  1680. }
  1681. first = "【" + sysUser.RealName + "】删除了你的【" + tmpRsCalendarItem.ActivityType + "】安排"
  1682. keyword2 := "【" + sysUser.RealName + "】已删除(" + req.DeleteReason + ")"
  1683. var keyword1 string
  1684. if tmpRsCalendarItem.ActivityType == "路演" {
  1685. keyword1 = tmpRsCalendarItem.CompanyName + "," + tmpRsCalendarItem.RoadshowType + tmpRsCalendarItem.ActivityType
  1686. } else if tmpRsCalendarItem.ActivityType == "公开会议" {
  1687. keyword1 = tmpRsCalendarItem.Theme + "," + tmpRsCalendarItem.RoadshowType + tmpRsCalendarItem.ActivityType
  1688. } else {
  1689. startDate := tmpRsCalendarResearcherItem.StartDate[5:]
  1690. startDate = strings.Replace(startDate, "-", ".", -1)
  1691. keyword1 = "会议时间:" + startDate + "(" + tmpRsCalendarResearcherItem.StartWeek + ")" + " " + tmpRsCalendarResearcherItem.StartTime[:5] + "-" + tmpRsCalendarResearcherItem.EndTime[:5]
  1692. keyword2 = "【" + sysUser.RealName + "】已删除" + "【" + tmpRsCalendarItem.ActivityType + ")"
  1693. }
  1694. //keyword2 := "已删除"
  1695. remark := req.DeleteReason
  1696. if sysAdmin.OpenId != "" {
  1697. openIdObj := &system.OpenIdList{
  1698. OpenId: sysAdmin.OpenId,
  1699. AdminId: sysAdmin.AdminId,
  1700. }
  1701. openIdList := make([]*system.OpenIdList, 0)
  1702. openIdList = append(openIdList, openIdObj)
  1703. if len(openIdList) > 0 {
  1704. services.SendWxMsgWithRoadshowDeleteNotice(first, keyword1, keyword2, remark, wxAppPath, openIdList)
  1705. }
  1706. }
  1707. }(*rsCalendarItem, *rsCalendarResearcherItem)
  1708. }
  1709. }
  1710. }
  1711. br.Ret = 200
  1712. br.Success = true
  1713. br.Msg = "删除成功"
  1714. br.IsAddLog = true
  1715. }
  1716. // @Title 新增事项接口
  1717. // @Description 新增事项接口
  1718. // @Param request body roadshow.AddMattersReq true "type json string"
  1719. // @Success Ret=200 保存成功
  1720. // @router /matters/add [post]
  1721. func (this *CalendarController) MattersAdd() {
  1722. br := new(models.BaseResponse).Init()
  1723. defer func() {
  1724. this.Data["json"] = br
  1725. this.ServeJSON()
  1726. }()
  1727. sysUser := this.SysUser
  1728. if sysUser == nil {
  1729. br.Msg = "请登录"
  1730. br.ErrMsg = "请登录,SysUser Is Empty"
  1731. br.Ret = 408
  1732. return
  1733. }
  1734. deleteCache := true
  1735. cacheKey := "CACHE_RS_MATTERS_ADD_" + strconv.Itoa(sysUser.AdminId)
  1736. defer func() {
  1737. if deleteCache {
  1738. utils.Rc.Delete(cacheKey)
  1739. }
  1740. }()
  1741. if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
  1742. deleteCache = false
  1743. br.Msg = "系统处理中,请稍后重试!"
  1744. br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(this.Ctx.Input.RequestBody)
  1745. return
  1746. }
  1747. var req roadshow.AddMattersReq
  1748. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1749. if err != nil {
  1750. br.Msg = "参数解析异常!"
  1751. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1752. return
  1753. }
  1754. if req.StartDate == "" {
  1755. br.Msg = "请选择开始日期!"
  1756. return
  1757. }
  1758. if req.EndDate == "" {
  1759. br.Msg = "请选择结束日期!"
  1760. return
  1761. }
  1762. if req.StartTime == "" {
  1763. br.Msg = "请选择开始时间!"
  1764. return
  1765. }
  1766. if req.EndTime == "" {
  1767. br.Msg = "请选择结束时间!"
  1768. return
  1769. }
  1770. if req.StartWeek == "" {
  1771. br.Msg = "请选择周!"
  1772. return
  1773. }
  1774. if req.EndWeek == "" {
  1775. br.Msg = "请选择周!"
  1776. return
  1777. }
  1778. if req.MatterContent == "" {
  1779. br.Msg = "请选择研究员!"
  1780. return
  1781. }
  1782. // 是否为销售
  1783. sales := isSellerRole(sysUser.RoleTypeCode)
  1784. startDateTime := req.StartDate + " " + req.StartTime
  1785. endDateTime := req.EndDate + " " + req.EndTime
  1786. //校验事项时间冲突
  1787. {
  1788. matterCount, err := roadshowService.CheckMatters(startDateTime, endDateTime, sysUser.AdminId, 0)
  1789. if err != nil {
  1790. br.Msg = "时间冲突检测失败!"
  1791. br.ErrMsg = "时间冲突检测失败-CheckMattersCount!Err:" + err.Error()
  1792. return
  1793. }
  1794. if matterCount > 0 {
  1795. br.Msg = "当前时间已被占用!"
  1796. br.ErrMsg = "时间冲突检测失败-CheckMattersCount!"
  1797. br.IsSendEmail = false
  1798. return
  1799. }
  1800. }
  1801. if !sales {
  1802. //校验活动时间冲突--待接受
  1803. {
  1804. calendarCount, err := roadshowService.CheckCalendar(startDateTime, endDateTime, "1", sysUser.AdminId, 0)
  1805. if err != nil {
  1806. br.Msg = "时间冲突检测失败!"
  1807. br.ErrMsg = "时间冲突检测失败-CheckCalendarResearcherCount!Err:" + err.Error()
  1808. return
  1809. }
  1810. if calendarCount > 0 {
  1811. br.Msg = "当前时间与待处理的申请有冲突,请与相关销售沟通!"
  1812. br.ErrMsg = "时间冲突检测失败-CheckCalendarResearcherCount!"
  1813. br.IsSendEmail = false
  1814. return
  1815. }
  1816. }
  1817. //校验活动时间冲突--已接受
  1818. {
  1819. calendarCount, err := roadshowService.CheckCalendar(startDateTime, endDateTime, "2", sysUser.AdminId, 0)
  1820. if err != nil {
  1821. br.Msg = "时间冲突检测失败!"
  1822. br.ErrMsg = "时间冲突检测失败-CheckCalendarResearcherCount!Err:" + err.Error()
  1823. return
  1824. }
  1825. if calendarCount > 0 {
  1826. br.Msg = "当前时间已被占用!"
  1827. br.ErrMsg = "时间冲突检测失败-CheckCalendarResearcherCount!"
  1828. br.IsSendEmail = false
  1829. return
  1830. }
  1831. }
  1832. }
  1833. startP, _ := time.ParseInLocation(utils.FormatDateTime, startDateTime, time.Local)
  1834. endP, _ := time.ParseInLocation(utils.FormatDateTime, endDateTime, time.Local)
  1835. if startP.Before(time.Now()) || startP.Equal(time.Now()) {
  1836. br.Msg = "事项开始时间不能小于当前时间!"
  1837. return
  1838. }
  1839. if endP.Before(time.Now()) || endP.Equal(time.Now()) {
  1840. br.Msg = "事项结束时间不能小于当前时间!"
  1841. return
  1842. }
  1843. if startP.After(endP) || startP.Equal(endP) {
  1844. br.Msg = "事项开始时间应小于结束时间!"
  1845. return
  1846. }
  1847. item := new(roadshow.RsMatters)
  1848. item.SysUserId = sysUser.AdminId
  1849. item.SysUserRealName = sysUser.RealName
  1850. item.StartDate = req.StartDate
  1851. item.EndDate = req.EndDate
  1852. item.StartTime = req.StartTime
  1853. item.EndTime = req.EndTime
  1854. item.StartWeek = req.StartWeek
  1855. item.EndWeek = req.EndWeek
  1856. item.MatterContent = req.MatterContent
  1857. item.Status = 1
  1858. item.CreateTime = time.Now()
  1859. item.ModifyTime = time.Now()
  1860. if sales {
  1861. item.IsSeller = 1
  1862. }
  1863. id, err := roadshow.AddRsMatters(item)
  1864. if err != nil {
  1865. br.Msg = "保存失败!"
  1866. br.ErrMsg = "保存失败,AddRsMatters Err:" + err.Error()
  1867. return
  1868. }
  1869. item.RsMattersId = int(id)
  1870. // 销售的事项不同步上海
  1871. if !sales {
  1872. go roadshowService.MatterToSH(*item)
  1873. }
  1874. br.Ret = 200
  1875. br.Success = true
  1876. br.Msg = "保存成功"
  1877. br.IsAddLog = true
  1878. }
  1879. // @Title 修改事项接口
  1880. // @Description 修改事项接口
  1881. // @Param request body roadshow.UpdateMattersReq true "type json string"
  1882. // @Success Ret=200 保存成功
  1883. // @router /matters/update [post]
  1884. func (this *CalendarController) MattersUpdate() {
  1885. br := new(models.BaseResponse).Init()
  1886. defer func() {
  1887. this.Data["json"] = br
  1888. this.ServeJSON()
  1889. }()
  1890. sysUser := this.SysUser
  1891. if sysUser == nil {
  1892. br.Msg = "请登录"
  1893. br.ErrMsg = "请登录,SysUser Is Empty"
  1894. br.Ret = 408
  1895. return
  1896. }
  1897. deleteCache := true
  1898. cacheKey := "CACHE_RS_MATTERS_UPDATE_" + strconv.Itoa(sysUser.AdminId)
  1899. defer func() {
  1900. if deleteCache {
  1901. utils.Rc.Delete(cacheKey)
  1902. }
  1903. }()
  1904. if !utils.Rc.SetNX(cacheKey, 1, 30*time.Second) {
  1905. deleteCache = false
  1906. br.Msg = "系统处理中,请稍后重试!"
  1907. br.ErrMsg = "系统处理中,请稍后重试!" + sysUser.RealName + ";data:" + string(this.Ctx.Input.RequestBody)
  1908. return
  1909. }
  1910. var req roadshow.UpdateMattersReq
  1911. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1912. if err != nil {
  1913. br.Msg = "参数解析异常!"
  1914. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1915. return
  1916. }
  1917. updateParams := make(map[string]interface{})
  1918. if req.RsMattersId <= 0 {
  1919. br.Msg = "参数错误!"
  1920. return
  1921. }
  1922. if req.StartDate == "" {
  1923. br.Msg = "请选择开始日期!"
  1924. return
  1925. } else {
  1926. updateParams["start_date"] = req.StartDate
  1927. }
  1928. if req.EndDate == "" {
  1929. br.Msg = "请选择结束日期!"
  1930. return
  1931. } else {
  1932. updateParams["end_date"] = req.EndDate
  1933. }
  1934. if req.StartTime == "" {
  1935. br.Msg = "请选择开始时间!"
  1936. return
  1937. } else {
  1938. updateParams["start_time"] = req.StartTime
  1939. }
  1940. if req.EndTime == "" {
  1941. br.Msg = "请选择结束时间!"
  1942. return
  1943. } else {
  1944. updateParams["end_time"] = req.EndTime
  1945. }
  1946. if req.StartWeek == "" {
  1947. br.Msg = "请选择周!"
  1948. return
  1949. } else {
  1950. updateParams["start_week"] = req.StartWeek
  1951. }
  1952. if req.EndWeek == "" {
  1953. br.Msg = "请选择周!"
  1954. return
  1955. } else {
  1956. updateParams["end_week"] = req.EndWeek
  1957. }
  1958. if req.MatterContent == "" {
  1959. br.Msg = "请选择研究员!"
  1960. return
  1961. } else {
  1962. updateParams["matter_content"] = req.MatterContent
  1963. }
  1964. req.EditReason = strings.TrimSpace(req.EditReason)
  1965. //if req.EditReason == "" {
  1966. // br.Msg = "请填写修改原因"
  1967. // return
  1968. //}
  1969. //updateParams["edit_reason"] = req.EditReason
  1970. startDateTime := req.StartDate + " " + req.StartTime
  1971. endDateTime := req.EndDate + " " + req.EndTime
  1972. startP, _ := time.ParseInLocation(utils.FormatDateTime, startDateTime, time.Local)
  1973. endP, _ := time.ParseInLocation(utils.FormatDateTime, endDateTime, time.Local)
  1974. if startP.Before(time.Now()) || startP.Equal(time.Now()) {
  1975. br.Msg = "事项开始时间不能小于当前时间!"
  1976. return
  1977. }
  1978. if endP.Before(time.Now()) || endP.Equal(time.Now()) {
  1979. br.Msg = "事项结束时间不能小于当前时间!"
  1980. return
  1981. }
  1982. if startP.After(endP) || startP.Equal(endP) {
  1983. br.Msg = "事项开始时间应小于结束时间!"
  1984. return
  1985. }
  1986. // 结束后14天不可再编辑
  1987. endP = endP.AddDate(0, 0, 14)
  1988. if endP.Before(time.Now().Local()) {
  1989. br.Msg = "事项结束14天后不可再编辑"
  1990. return
  1991. }
  1992. matterItem, err := roadshow.GetMattersById(req.RsMattersId)
  1993. if err != nil {
  1994. br.Msg = "保存失败!"
  1995. br.Msg = "保存失败,GetMattersById,Err:" + err.Error()
  1996. return
  1997. }
  1998. // 是否为销售
  1999. sales := isSellerRole(sysUser.RoleTypeCode)
  2000. //校验事项时间冲突
  2001. {
  2002. if matterItem != nil && (matterItem.StartDate != req.StartDate ||
  2003. matterItem.StartTime != req.StartTime ||
  2004. matterItem.EndDate != req.EndDate ||
  2005. matterItem.EndTime != req.EndTime) {
  2006. matterCount, err := roadshowService.CheckMatters(startDateTime, endDateTime, sysUser.AdminId, matterItem.RsMattersId)
  2007. if err != nil {
  2008. br.Msg = "时间冲突检测失败!"
  2009. br.ErrMsg = "时间冲突检测失败-CheckMattersCount!Err:" + err.Error()
  2010. return
  2011. }
  2012. if matterCount > 0 {
  2013. br.Msg = "时间冲突,已存在时间段内的事项!"
  2014. br.ErrMsg = "时间冲突检测失败-CheckMattersCount!"
  2015. br.IsSendEmail = false
  2016. return
  2017. }
  2018. }
  2019. }
  2020. if !sales {
  2021. //校验活动时间冲突--待接受
  2022. {
  2023. calendarCount, err := roadshowService.CheckCalendar(startDateTime, endDateTime, "1", sysUser.AdminId, 0)
  2024. if err != nil {
  2025. br.Msg = "时间冲突检测失败!"
  2026. br.ErrMsg = "时间冲突检测失败-CheckCalendarResearcherCount!Err:" + err.Error()
  2027. return
  2028. }
  2029. if calendarCount > 0 {
  2030. br.Msg = "当前时间与待处理的申请有冲突,请与相关销售沟通!"
  2031. br.ErrMsg = "时间冲突检测失败-CheckCalendarResearcherCount!"
  2032. br.IsSendEmail = false
  2033. return
  2034. }
  2035. }
  2036. //校验活动时间冲突--待接受
  2037. {
  2038. calendarCount, err := roadshowService.CheckCalendar(startDateTime, endDateTime, "2", sysUser.AdminId, 0)
  2039. if err != nil {
  2040. br.Msg = "时间冲突检测失败!"
  2041. br.ErrMsg = "时间冲突检测失败-CheckCalendarResearcherCount!Err:" + err.Error()
  2042. return
  2043. }
  2044. if calendarCount > 0 {
  2045. br.Msg = "时间冲突,已存在时间段内的活动!"
  2046. br.ErrMsg = "时间冲突检测失败-CheckCalendarResearcherCount!"
  2047. br.IsSendEmail = false
  2048. return
  2049. }
  2050. }
  2051. }
  2052. whereParams := make(map[string]interface{})
  2053. whereParams["rs_matters_id"] = req.RsMattersId
  2054. updateParams["modify_time"] = time.Now()
  2055. err = roadshow.UpdateRsMatters(whereParams, updateParams)
  2056. if err != nil {
  2057. br.Msg = "保存失败!"
  2058. br.ErrMsg = "保存失败!UpdateRsMatters:" + err.Error()
  2059. return
  2060. }
  2061. // 销售不做上海那边的处理
  2062. if !sales {
  2063. go roadshowService.UpdateSHCalendarByMatter(req)
  2064. }
  2065. br.Ret = 200
  2066. br.Success = true
  2067. br.Msg = "保存成功"
  2068. br.IsAddLog = true
  2069. }
  2070. // @Title 删除事项接口
  2071. // @Description 删除事项接口
  2072. // @Param request body roadshow.DeleteMattersReq true "type json string"
  2073. // @Success Ret=200 保存成功
  2074. // @router /matters/delete [post]
  2075. func (this *CalendarController) MattersDelete() {
  2076. br := new(models.BaseResponse).Init()
  2077. defer func() {
  2078. this.Data["json"] = br
  2079. this.ServeJSON()
  2080. }()
  2081. sysUser := this.SysUser
  2082. if sysUser == nil {
  2083. br.Msg = "请登录"
  2084. br.ErrMsg = "请登录,SysUser Is Empty"
  2085. br.Ret = 408
  2086. return
  2087. }
  2088. var req roadshow.DeleteMattersReq
  2089. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  2090. if err != nil {
  2091. br.Msg = "参数解析异常!"
  2092. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2093. return
  2094. }
  2095. if req.RsMattersId <= 0 {
  2096. br.Msg = "参数错误!"
  2097. return
  2098. }
  2099. matters, e := roadshow.GetMattersById(req.RsMattersId)
  2100. if e != nil {
  2101. if e.Error() == utils.ErrNoRow() {
  2102. br.Msg = "事项已被删除, 请刷新页面"
  2103. return
  2104. }
  2105. br.Msg = "操作失败"
  2106. br.ErrMsg = "获取事项失败, Err: " + e.Error()
  2107. return
  2108. }
  2109. // 事项结束14天后不可再删除
  2110. t := fmt.Sprintf("%s %s", matters.EndDate, matters.EndTime)
  2111. ed, _ := time.ParseInLocation(utils.FormatDateTime, t, time.Local)
  2112. ed = ed.AddDate(0, 0, 14)
  2113. if ed.Before(time.Now().Local()) {
  2114. br.Msg = "事项结束14天后不可再删除"
  2115. return
  2116. }
  2117. err = roadshow.DeleteRsMatters(req.RsMattersId)
  2118. if err != nil {
  2119. br.Msg = "保存失败!"
  2120. br.ErrMsg = "保存失败!DeleteRsMatters:" + err.Error()
  2121. return
  2122. }
  2123. // 是否为销售
  2124. sales := isSellerRole(sysUser.RoleTypeCode)
  2125. // 删除上海的路演活动, 销售不同步
  2126. if !sales {
  2127. go roadshowService.DeleteSHMatter(req.RsMattersId)
  2128. }
  2129. br.Ret = 200
  2130. br.Success = true
  2131. br.Msg = "删除成功"
  2132. br.IsAddLog = true
  2133. }
  2134. // @Title 路演-研究员日历详情
  2135. // @Description 路演-研究员日历详情接口
  2136. // @Param StartDate query string true "开始日期"
  2137. // @Param EndDate query string true "结束日期日期"
  2138. // @Param ResearcherId query int true "研究员id"
  2139. // @Success 200 {object} roadshow.CalendarDetailResp
  2140. // @router /researcher/calendar/detail [get]
  2141. func (this *CalendarController) ResearcherCalendarDetail() {
  2142. br := new(models.BaseResponse).Init()
  2143. defer func() {
  2144. this.Data["json"] = br
  2145. this.ServeJSON()
  2146. }()
  2147. sysUser := this.SysUser
  2148. if sysUser == nil {
  2149. br.Msg = "请登录"
  2150. br.ErrMsg = "请登录,SysUser Is Empty"
  2151. br.Ret = 408
  2152. return
  2153. }
  2154. startDate := this.GetString("StartDate")
  2155. endDate := this.GetString("EndDate")
  2156. researcherId, _ := this.GetInt("ResearcherId")
  2157. if startDate == "" || endDate == "" {
  2158. br.Msg = "参数错误"
  2159. return
  2160. }
  2161. var condition string
  2162. var pars []interface{}
  2163. if researcherId <= 0 {
  2164. calendarList := make([]*roadshow.CalendarListView, 0)
  2165. matterList := make([]*roadshow.RsMatters, 0)
  2166. resp := new(roadshow.CalendarDetailResp)
  2167. resp.CalendarList = calendarList
  2168. resp.RsMattersList = matterList
  2169. br.Ret = 200
  2170. br.Success = true
  2171. br.Msg = "获取成功"
  2172. br.Data = resp
  2173. return
  2174. } else {
  2175. condition += ` AND b.researcher_id =? `
  2176. pars = append(pars, researcherId)
  2177. }
  2178. //同步上海数据
  2179. researcherInfo, err := system.GetSysAdminById(researcherId)
  2180. if err != nil {
  2181. br.Msg = "研究员异常"
  2182. return
  2183. }
  2184. //go roadshowService.SyncCalendarFromShanghai(researcherInfo.Mobile, startDate, endDate)
  2185. go roadshowService.InsertSyncCalendarFromShanghaiLPush(researcherInfo.Mobile, startDate, endDate)
  2186. //condition += ` AND b.start_date>=?`
  2187. //pars = append(pars, startDate)
  2188. //condition += ` AND b.end_date<=?`
  2189. //pars = append(pars, endDate)
  2190. //解决研究员休假,产生跨周的数据查询不到的bug,
  2191. condition += ` AND ( b.start_date >= ? AND b.end_date <= ?
  2192. OR ( b.start_date >= ? AND b.start_date <= ? )
  2193. OR ( b.start_date <= ? AND b.end_date >= ? )
  2194. OR ( b.end_date >= ? AND b.end_date <= ? ) ) `
  2195. pars = append(pars, startDate, endDate, startDate, endDate, startDate, endDate, startDate, endDate)
  2196. condition += ` AND b.status IN(2) `
  2197. //pars = append(pars, 2)
  2198. calendarList, err := roadshow.GetCalendarDetailList(condition, pars)
  2199. if err != nil {
  2200. br.Msg = "获取数据失败"
  2201. br.ErrMsg = "获取数据失败,GetCalendarDetailList Err:" + err.Error()
  2202. return
  2203. }
  2204. matterList, err := roadshow.GetRsMattersList(startDate, endDate, researcherId)
  2205. if err != nil {
  2206. br.Msg = "获取数据失败"
  2207. br.ErrMsg = "获取数据失败,GetRsMattersList Err:" + err.Error()
  2208. return
  2209. }
  2210. if calendarList == nil {
  2211. calendarList = make([]*roadshow.CalendarListView, 0)
  2212. } else {
  2213. var sysUserIds []int //建会人ID
  2214. var companyIds []int //公司ID
  2215. for _, v := range calendarList { //上海同步过来信息展示逻辑替换 需求池 953
  2216. if v.Source == 1 && v.CompanyName == "" {
  2217. v.CompanyName = v.Title
  2218. }
  2219. if v.SysUserId > 0 {
  2220. sysUserIds = append(sysUserIds, v.SysUserId)
  2221. }
  2222. if v.CompanyId > 1 {
  2223. companyIds = append(companyIds, v.CompanyId)
  2224. }
  2225. }
  2226. //如果是权益销售建的会,客户状态替换成权益那边的
  2227. mapSellRai := make(map[int]bool) // 是否是权益销售
  2228. mapStatus := make(map[int]string) //权益客户对应的状态
  2229. if len(sysUserIds) > 0 && len(companyIds) > 0 {
  2230. //判断哪些人是权益销售
  2231. adminList, err := system.GetAdminListByIdListWithoutEnable(sysUserIds)
  2232. if err != nil {
  2233. br.Msg = "获取数据失败"
  2234. br.ErrMsg = "获取数据失败,GetAdminListByIdListWithoutEnable Err:" + err.Error()
  2235. return
  2236. }
  2237. for _, v := range adminList {
  2238. if v.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER || v.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  2239. mapSellRai[v.AdminId] = true
  2240. }
  2241. }
  2242. conditionProduct := ` AND company_id IN (` + utils.GetOrmInReplace(len(companyIds)) + `) AND product_id = 2 `
  2243. parsProduct := make([]interface{}, 0)
  2244. parsProduct = append(parsProduct, companyIds)
  2245. productList, err := company.GetCompanyProductList(conditionProduct, parsProduct)
  2246. if err != nil {
  2247. br.Msg = "获取数据失败"
  2248. br.ErrMsg = "获取数据失败,GetCompanyProductList Err:" + err.Error()
  2249. return
  2250. }
  2251. for _, v := range productList {
  2252. mapStatus[v.CompanyId] = v.Status
  2253. }
  2254. }
  2255. for _, v := range calendarList {
  2256. if mapSellRai[v.SysUserId] && mapStatus[v.CompanyId] != "" {
  2257. v.CompanyStatus = mapStatus[v.CompanyId]
  2258. }
  2259. }
  2260. }
  2261. if matterList == nil {
  2262. matterList = make([]*roadshow.RsMatters, 0)
  2263. }
  2264. resp := new(roadshow.CalendarDetailResp)
  2265. resp.CalendarList = calendarList
  2266. resp.RsMattersList = matterList
  2267. br.Ret = 200
  2268. br.Success = true
  2269. br.Msg = "获取成功"
  2270. br.Data = resp
  2271. }
  2272. // @Title 路演-我的日历详情
  2273. // @Description 路演-我的日历详情接口
  2274. // @Param StartDate query string true "开始日期"
  2275. // @Param EndDate query string true "结束日期日期"
  2276. // @Success 200 {object} roadshow.CalendarDetailResp
  2277. // @router /my/calendar/detail [get]
  2278. func (this *CalendarController) MyCalendarDetail() {
  2279. br := new(models.BaseResponse).Init()
  2280. defer func() {
  2281. this.Data["json"] = br
  2282. this.ServeJSON()
  2283. }()
  2284. sysUser := this.SysUser
  2285. if sysUser == nil {
  2286. br.Msg = "请登录"
  2287. br.ErrMsg = "请登录,SysUser Is Empty"
  2288. br.Ret = 408
  2289. return
  2290. }
  2291. startDate := this.GetString("StartDate")
  2292. endDate := this.GetString("EndDate")
  2293. if startDate == "" || endDate == "" {
  2294. br.Msg = "参数错误"
  2295. return
  2296. }
  2297. var condition string
  2298. var pars []interface{}
  2299. roleTypeCode := sysUser.RoleTypeCode
  2300. fmt.Println("roleTypeCode:", roleTypeCode)
  2301. //权益销售
  2302. if roleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER ||
  2303. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  2304. //if calendarType == 2 {
  2305. condition += ` AND ( a.sys_user_id=? OR a.seller_id=? OR a.share_seller_id=? ) `
  2306. pars = append(pars, sysUser.AdminId, sysUser.AdminId, sysUser.AdminId)
  2307. //}
  2308. } else {
  2309. //销售
  2310. sales := isSellerRole(sysUser.RoleTypeCode)
  2311. if sales || roleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN { // 王芳也作为销售身份处理
  2312. condition += ` AND a.sys_user_id=?`
  2313. pars = append(pars, sysUser.AdminId)
  2314. condition += ` AND a.activity_type IN('路演','公开会议','沙龙') `
  2315. }
  2316. }
  2317. //研究员
  2318. if roleTypeCode == utils.ROLE_TYPE_CODE_FICC_RESEARCHR ||
  2319. roleTypeCode == utils.ROLE_TYPE_CODE_RESEARCHR ||
  2320. roleTypeCode == utils.ROLE_TYPE_CODE_RAI_RESEARCHR ||
  2321. roleTypeCode == utils.ROLE_TYPE_CODE_FICC_ADMIN {
  2322. condition += ` AND b.researcher_id=?`
  2323. pars = append(pars, sysUser.AdminId)
  2324. //同步上海数据(研究员才需要同步上海的数据)
  2325. researcherInfo, err := system.GetSysAdminById(sysUser.AdminId)
  2326. if err != nil {
  2327. br.Msg = "研究员异常"
  2328. return
  2329. }
  2330. //go roadshowService.SyncCalendarFromShanghai(researcherInfo.Mobile, startDate, endDate)
  2331. go roadshowService.InsertSyncCalendarFromShanghaiLPush(researcherInfo.Mobile, startDate, endDate)
  2332. }
  2333. //中级/普通/admin 管理员
  2334. if roleTypeCode == utils.ROLE_TYPE_CODE_ADMIN {
  2335. condition += ` AND a.sys_user_id=?`
  2336. pars = append(pars, sysUser.AdminId)
  2337. }
  2338. //condition += ` AND b.start_date>=?`
  2339. //pars = append(pars, startDate)
  2340. //condition += ` AND b.end_date<=?`
  2341. //pars = append(pars, endDate)
  2342. //解决研究员休假,产生跨周的数据查询不到的bug,
  2343. condition += ` AND ( b.start_date >= ? AND b.end_date <= ?
  2344. OR ( b.start_date >= ? AND b.start_date <= ? )
  2345. OR ( b.start_date <= ? AND b.end_date >= ? )
  2346. OR ( b.end_date >= ? AND b.end_date <= ? ) ) `
  2347. pars = append(pars, startDate, endDate, startDate, endDate, startDate, endDate, startDate, endDate)
  2348. condition += ` AND b.status IN(2) `
  2349. //pars = append(pars, 2)
  2350. fmt.Println("condition:" + condition)
  2351. calendarList, err := roadshow.GetCalendarDetailList(condition, pars)
  2352. if err != nil {
  2353. br.Msg = "获取数据失败"
  2354. br.ErrMsg = "获取数据失败,GetCalendarDetailList Err:" + err.Error()
  2355. return
  2356. }
  2357. if calendarList == nil {
  2358. calendarList = make([]*roadshow.CalendarListView, 0)
  2359. } else {
  2360. var sysUserIds []int //建会人ID
  2361. var companyIds []int //公司ID
  2362. for _, v := range calendarList { //上海同步过来信息展示逻辑替换 需求池 953
  2363. if v.Source == 1 && v.CompanyName == "" {
  2364. v.CompanyName = v.Title
  2365. }
  2366. if v.SysUserId > 0 {
  2367. sysUserIds = append(sysUserIds, v.SysUserId)
  2368. }
  2369. if v.CompanyId > 1 {
  2370. companyIds = append(companyIds, v.CompanyId)
  2371. }
  2372. }
  2373. //如果是权益销售建的会,客户状态替换成权益那边的
  2374. mapSellRai := make(map[int]bool) // 是否是权益销售
  2375. mapStatus := make(map[int]string) //权益客户对应的状态
  2376. if len(sysUserIds) > 0 && len(companyIds) > 0 {
  2377. //判断哪些人是权益销售
  2378. adminList, err := system.GetAdminListByIdListWithoutEnable(sysUserIds)
  2379. if err != nil {
  2380. br.Msg = "获取数据失败"
  2381. br.ErrMsg = "获取数据失败,GetAdminListByIdListWithoutEnable Err:" + err.Error()
  2382. return
  2383. }
  2384. for _, v := range adminList {
  2385. if v.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER || v.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
  2386. mapSellRai[v.AdminId] = true
  2387. }
  2388. }
  2389. conditionProduct := ` AND company_id IN (` + utils.GetOrmInReplace(len(companyIds)) + `) AND product_id = 2 `
  2390. parsProduct := make([]interface{}, 0)
  2391. parsProduct = append(parsProduct, companyIds)
  2392. productList, err := company.GetCompanyProductList(conditionProduct, parsProduct)
  2393. if err != nil {
  2394. br.Msg = "获取数据失败"
  2395. br.ErrMsg = "获取数据失败,GetCompanyProductList Err:" + err.Error()
  2396. return
  2397. }
  2398. for _, v := range productList {
  2399. mapStatus[v.CompanyId] = v.Status
  2400. }
  2401. }
  2402. for _, v := range calendarList {
  2403. if mapSellRai[v.SysUserId] && mapStatus[v.CompanyId] != "" {
  2404. v.CompanyStatus = mapStatus[v.CompanyId]
  2405. }
  2406. }
  2407. }
  2408. matterList, err := roadshow.GetRsMattersList(startDate, endDate, sysUser.AdminId)
  2409. if err != nil {
  2410. br.Msg = "获取数据失败"
  2411. br.ErrMsg = "获取数据失败,GetRsMattersList Err:" + err.Error()
  2412. return
  2413. }
  2414. resp := new(roadshow.CalendarDetailResp)
  2415. resp.CalendarList = calendarList
  2416. resp.RsMattersList = matterList
  2417. br.Ret = 200
  2418. br.Success = true
  2419. br.Msg = "获取成功"
  2420. br.Data = resp
  2421. }
  2422. // @Title 事项列表
  2423. // @Description 事项列表接口
  2424. // @Param PageSize query int true "每页数据条数"
  2425. // @Param CurrentIndex query int true "当前页页码,从1开始"
  2426. // @Success 200 {object} roadshow.MattersListResp
  2427. // @router /matters/list [get]
  2428. func (this *CalendarController) MattersList() {
  2429. br := new(models.BaseResponse).Init()
  2430. defer func() {
  2431. this.Data["json"] = br
  2432. this.ServeJSON()
  2433. }()
  2434. sysUser := this.SysUser
  2435. if sysUser == nil {
  2436. br.Msg = "请登录"
  2437. br.ErrMsg = "请登录,SysUser Is Empty"
  2438. br.Ret = 408
  2439. return
  2440. }
  2441. pageSize, _ := this.GetInt("PageSize")
  2442. currentIndex, _ := this.GetInt("CurrentIndex")
  2443. var total int
  2444. page := paging.GetPaging(currentIndex, pageSize, total)
  2445. var startSize int
  2446. if pageSize <= 0 {
  2447. pageSize = utils.PageSize10
  2448. }
  2449. if currentIndex <= 0 {
  2450. currentIndex = 1
  2451. }
  2452. startSize = paging.StartIndex(currentIndex, pageSize)
  2453. var condition string
  2454. var pars []interface{}
  2455. condition += ` AND a.sys_user_id=?`
  2456. pars = append(pars, sysUser.AdminId)
  2457. resp := new(roadshow.MattersListResp)
  2458. total, err := roadshow.GetMattersListCount(condition, pars)
  2459. if err != nil && err.Error() != utils.ErrNoRow() {
  2460. br.Msg = "获取事项信息失败"
  2461. br.ErrMsg = "获取事项信息失败,GetMattersListCount,Err:" + err.Error()
  2462. return
  2463. }
  2464. page = paging.GetPaging(currentIndex, pageSize, total)
  2465. dataList, err := roadshow.GetMattersList(condition, pars, startSize, pageSize)
  2466. if err != nil {
  2467. br.Msg = "获取事项信息失败"
  2468. br.ErrMsg = "获取事项信息失败,GetMattersList,Err:" + err.Error()
  2469. return
  2470. }
  2471. // 按钮权限,超过14天无按钮
  2472. now := time.Now().Local()
  2473. for _, v := range dataList {
  2474. // 结束日期14天后无编辑删除按钮权限
  2475. t := fmt.Sprintf("%s %s", v.EndDate, v.EndTime)
  2476. ed, e := time.ParseInLocation(utils.FormatDateTime, t, time.Local)
  2477. if e != nil {
  2478. br.Msg = "事项结束日期有误"
  2479. br.ErrMsg = "事项结束日期有误, Err: " + e.Error()
  2480. return
  2481. }
  2482. ed = ed.AddDate(0, 0, 14)
  2483. if ed.Before(now) {
  2484. v.ButtonAuth.EditDisabled = true
  2485. v.ButtonAuth.RemoveDisabled = true
  2486. }
  2487. }
  2488. resp.Paging = page
  2489. resp.List = dataList
  2490. br.Ret = 200
  2491. br.Success = true
  2492. br.Msg = "获取成功"
  2493. br.Data = resp
  2494. }
  2495. func getTitle(activityType, roadshowType, activityCategory, roadshowPlatform, province, city string) string {
  2496. var title string
  2497. switch activityType {
  2498. case "内部会议":
  2499. title = "内部会议"
  2500. case "公开会议", "路演", "沙龙":
  2501. if roadshowType == "线上" {
  2502. title = roadshowType + activityType + roadshowPlatform
  2503. } else {
  2504. title = roadshowType + activityType + province + city
  2505. }
  2506. case "报告电话会":
  2507. title = activityCategory + "电话会"
  2508. }
  2509. return title
  2510. }
  2511. // @Title 路演-公开会议总览
  2512. // @Description 路演-公开会议总览接口
  2513. // @Param StartDate query string true "开始日期"
  2514. // @Param EndDate query string true "结束日期日期"
  2515. // @Success 200 {object} roadshow.PublicMeetingDetailResp
  2516. // @router /public_meeting/detail [get]
  2517. func (this *CalendarController) PublicMeetingDetail() {
  2518. br := new(models.BaseResponse).Init()
  2519. defer func() {
  2520. this.Data["json"] = br
  2521. this.ServeJSON()
  2522. }()
  2523. sysUser := this.SysUser
  2524. if sysUser == nil {
  2525. br.Msg = "请登录"
  2526. br.ErrMsg = "请登录,SysUser Is Empty"
  2527. br.Ret = 408
  2528. return
  2529. }
  2530. startDate := this.GetString("StartDate")
  2531. endDate := this.GetString("EndDate")
  2532. if startDate == "" || endDate == "" {
  2533. br.Msg = "参数错误"
  2534. return
  2535. }
  2536. var condition string
  2537. var pars []interface{}
  2538. roleTypeCode := sysUser.RoleTypeCode
  2539. fmt.Println("roleTypeCode:", roleTypeCode)
  2540. condition += ` AND a.activity_type = '公开会议' `
  2541. condition += ` AND b.start_date>=?`
  2542. pars = append(pars, startDate)
  2543. condition += ` AND b.end_date<=?`
  2544. pars = append(pars, endDate)
  2545. condition += ` AND b.status IN(2) `
  2546. //pars = append(pars, 2)
  2547. fmt.Println("condition:" + condition)
  2548. //calendarList, err := roadshow.GetCalendarDetailList(condition, pars)
  2549. calendarList, err := roadshow.GetPublicCalendarDetailList(condition, pars)
  2550. if err != nil {
  2551. br.Msg = "获取数据失败"
  2552. br.ErrMsg = "获取数据失败,GetCalendarDetailList Err:" + err.Error()
  2553. return
  2554. }
  2555. groupMap := make(map[string][]*roadshow.CalendarListView)
  2556. var groupArr []string
  2557. for _, v := range calendarList {
  2558. if findGroup, ok := groupMap[v.UnionCode]; !ok {
  2559. newGroup := make([]*roadshow.CalendarListView, 0)
  2560. newGroup = append(newGroup, v)
  2561. groupMap[v.UnionCode] = newGroup
  2562. groupArr = append(groupArr, v.UnionCode)
  2563. } else {
  2564. findGroup = append(findGroup, v)
  2565. groupMap[v.UnionCode] = findGroup
  2566. }
  2567. }
  2568. resp := new(roadshow.PublicMeetingDetailResp)
  2569. for _, v := range groupArr {
  2570. newGroup := new(roadshow.PublicMeetingGroup)
  2571. newGroup.UnionCode = v
  2572. calendarList := groupMap[v]
  2573. var minTimeStr, maxTimeStr string
  2574. var minTime, maxTime time.Time
  2575. for _, cv := range calendarList {
  2576. startTimeStr := cv.StartDate + " " + cv.StartTime
  2577. endTimeStr := cv.EndDate + " " + cv.EndTime
  2578. startTime, _ := time.ParseInLocation(utils.FormatDateTime, startTimeStr, time.Local)
  2579. endTime, _ := time.ParseInLocation(utils.FormatDateTime, endTimeStr, time.Local)
  2580. if minTime.IsZero() {
  2581. minTime = startTime
  2582. } else {
  2583. if startTime.Before(minTime) {
  2584. minTime = startTime
  2585. }
  2586. }
  2587. if maxTime.IsZero() {
  2588. maxTime = endTime
  2589. } else {
  2590. if endTime.After(maxTime) {
  2591. maxTime = endTime
  2592. }
  2593. }
  2594. }
  2595. minTimeStr = minTime.Format(utils.FormatDateTime)
  2596. maxTimeStr = maxTime.Format(utils.FormatDateTime)
  2597. newGroup.MinTime = minTimeStr
  2598. newGroup.MaxTime = maxTimeStr
  2599. newGroup.CalendarList = calendarList
  2600. resp.Group = append(resp.Group, newGroup)
  2601. }
  2602. br.Ret = 200
  2603. br.Success = true
  2604. br.Msg = "获取成功"
  2605. br.Data = resp
  2606. }
  2607. //func init() {
  2608. // fmt.Println("start")
  2609. // mobile := `13818594925`
  2610. // roadshowService.SyncCalendarFromShanghai(mobile, "", "2023-03-09")
  2611. // //err := roadshowService.SetPublicMeetingUnionCode()
  2612. // //if err != nil {
  2613. // // fmt.Println("SetPublicMeetingUnionCode Err:" + err.Error())
  2614. // //}
  2615. // fmt.Println("end")
  2616. //}
  2617. // SellerCalendarDetail
  2618. // @Title 路演-销售日历详情
  2619. // @Description 路演-销售日历详情
  2620. // @Param StartDate query string true "开始日期"
  2621. // @Param EndDate query string true "结束日期日期"
  2622. // @Param SellerId query int true "销售ID"
  2623. // @Success 200 {object} roadshow.CalendarDetailResp
  2624. // @router /seller/calendar/detail [get]
  2625. func (this *CalendarController) SellerCalendarDetail() {
  2626. br := new(models.BaseResponse).Init()
  2627. defer func() {
  2628. if br.ErrMsg == "" {
  2629. br.IsSendEmail = false
  2630. }
  2631. this.Data["json"] = br
  2632. this.ServeJSON()
  2633. }()
  2634. sysUser := this.SysUser
  2635. if sysUser == nil {
  2636. br.Msg = "请登录"
  2637. br.ErrMsg = "请登录,SysUser Is Empty"
  2638. br.Ret = 408
  2639. return
  2640. }
  2641. startDate := this.GetString("StartDate")
  2642. endDate := this.GetString("EndDate")
  2643. sellerId, _ := this.GetInt("SellerId")
  2644. if startDate == "" || endDate == "" {
  2645. br.Msg = "参数错误"
  2646. return
  2647. }
  2648. if sellerId <= 0 {
  2649. calendarList := make([]*roadshow.CalendarListView, 0)
  2650. matterList := make([]*roadshow.RsMatters, 0)
  2651. resp := new(roadshow.CalendarDetailResp)
  2652. resp.CalendarList = calendarList
  2653. resp.RsMattersList = matterList
  2654. br.Ret = 200
  2655. br.Success = true
  2656. br.Msg = "获取成功"
  2657. br.Data = resp
  2658. return
  2659. }
  2660. // 路演
  2661. condition := ` AND a.sys_user_id = ? AND b.start_date >= ? AND b.end_date <= ? AND b.status = 2`
  2662. pars := make([]interface{}, 0)
  2663. pars = append(pars, sellerId, startDate, endDate)
  2664. calendarList, err := roadshow.GetCalendarDetailList(condition, pars)
  2665. if err != nil {
  2666. br.Msg = "获取数据失败"
  2667. br.ErrMsg = "获取数据失败,GetCalendarDetailList Err:" + err.Error()
  2668. return
  2669. }
  2670. if calendarList == nil {
  2671. calendarList = make([]*roadshow.CalendarListView, 0)
  2672. }
  2673. // 事项
  2674. matterList, err := roadshow.GetRsMattersList(startDate, endDate, sellerId)
  2675. if err != nil {
  2676. br.Msg = "获取数据失败"
  2677. br.ErrMsg = "获取数据失败,GetRsMattersList Err:" + err.Error()
  2678. return
  2679. }
  2680. if matterList == nil {
  2681. matterList = make([]*roadshow.RsMatters, 0)
  2682. }
  2683. resp := new(roadshow.CalendarDetailResp)
  2684. resp.CalendarList = calendarList
  2685. resp.RsMattersList = matterList
  2686. br.Ret = 200
  2687. br.Success = true
  2688. br.Msg = "获取成功"
  2689. br.Data = resp
  2690. }
  2691. // isSellerRole 是否为销售角色
  2692. func isSellerRole(roleType string) (ok bool) {
  2693. sellerArr := []string{
  2694. utils.ROLE_TYPE_CODE_FICC_SELLER, utils.ROLE_TYPE_CODE_FICC_GROUP, utils.ROLE_TYPE_CODE_FICC_TEAM,
  2695. utils.ROLE_TYPE_CODE_RAI_SELLER, utils.ROLE_TYPE_CODE_RAI_GROUP,
  2696. }
  2697. if utils.InArrayByStr(sellerArr, roleType) {
  2698. ok = true
  2699. }
  2700. return
  2701. }
  2702. //func init() {
  2703. // init16_2()
  2704. //}
  2705. //func init16_2() {
  2706. // listDate, err := roadshow.GetRsCalendarResearcherListInit16_2()
  2707. // if err != nil {
  2708. // fmt.Println(err)
  2709. // return
  2710. // }
  2711. //
  2712. // sysUserList, err := system.GetAdminList()
  2713. // if err != nil {
  2714. // fmt.Println(err)
  2715. // return
  2716. // }
  2717. // adminMap := make(map[int]*system.Admin, 0)
  2718. // for _, v := range sysUserList {
  2719. // adminMap[v.AdminId] = v
  2720. // }
  2721. //
  2722. // for k, v := range listDate {
  2723. // fmt.Println(k, "__", v.CompanyId)
  2724. // //如果是权益客户,添加销售跟共享销售的信息
  2725. // var productItemRai *company.CompanyProduct
  2726. //
  2727. // productItemRai, err = company.GetCompanyProductByCompanyIdAndProductId(v.CompanyId, utils.COMPANY_PRODUCT_RAI_ID)
  2728. // if err != nil && err.Error() != utils.ErrNoRow() {
  2729. // fmt.Println(err)
  2730. // return
  2731. // }
  2732. //
  2733. // var RoleTypeCode string
  2734. // if adminMap[v.SysUserId] != nil {
  2735. // RoleTypeCode = adminMap[v.SysUserId].RoleTypeCode
  2736. // }
  2737. //
  2738. // if productItemRai != nil && (RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP || RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_SELLER || RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_ADMIN) {
  2739. // err = roadshow.UpdateRsCalendarSeller(productItemRai.SellerId, productItemRai.ShareSellerId, v.RsCalendarId)
  2740. // if err != nil && err.Error() != utils.ErrNoRow() {
  2741. // fmt.Println(err)
  2742. // return
  2743. // }
  2744. // }
  2745. // }
  2746. //
  2747. //}