calendar.go 90 KB

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