calendar.go 94 KB

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