calendar.go 95 KB

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