calendar.go 92 KB

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