calendar.go 83 KB

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