activity.go 94 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "github.com/medivhzhan/weapp/v2"
  6. "github.com/rdlucklib/rdluck_tools/paging"
  7. "hongze/hongze_cygx/models"
  8. "hongze/hongze_cygx/services"
  9. "hongze/hongze_cygx/utils"
  10. "sort"
  11. "strconv"
  12. "strings"
  13. "time"
  14. )
  15. //活动
  16. type ActivityCoAntroller struct {
  17. BaseAuthController
  18. }
  19. type ActivityABaseController struct {
  20. BaseCommonController
  21. }
  22. // @Title 活动类型列表
  23. // @Description活动类型列表接口
  24. // @Success 200 {object} models.ActivityTypeListResp
  25. // @router /activityTypelist [get]
  26. func (this *ActivityCoAntroller) List() {
  27. br := new(models.BaseResponse).Init()
  28. defer func() {
  29. this.Data["json"] = br
  30. this.ServeJSON()
  31. }()
  32. user := this.User
  33. if user == nil {
  34. br.Msg = "请登录"
  35. br.ErrMsg = "请登录,SysUser Is Empty"
  36. br.Ret = 408
  37. return
  38. }
  39. resp := new(models.ActivityTypeListResp)
  40. list, err := models.GetActivityTypeList()
  41. if err != nil {
  42. br.Msg = "获取失败"
  43. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  44. return
  45. }
  46. resp.List = list
  47. br.Ret = 200
  48. br.Success = true
  49. br.Msg = "获取成功"
  50. br.Data = resp
  51. }
  52. // @Title 活动列表
  53. // @Description 获取活动列表接口
  54. // @Param PageSize query int true "每页数据条数"
  55. // @Param CurrentIndex query int true "当前页页码,从1开始"
  56. // @Param ChartPermissionIds query string false "行业id 多个用 , 隔开"
  57. // @Param ActivityTypeIds query string false "活动类型id 多个用 , 隔开"
  58. // @Param KeyWord query string false "搜索关键词 多个用 , 隔开"
  59. // @Param ActiveState query string false "活动进行状态 未开始:1、进行中2、已结束3"
  60. // @Param WhichDay query string false "哪一天 今天:1、明天:2,多个用 , 隔开"
  61. // @Param IsShowJurisdiction query int false "是否仅展示有权限的,1是,2否 默认为零"
  62. // @Param Label query string false "搜索主题 多个用 , 隔开"
  63. // @Success 200 {object} models.GetCygxActivityListRep
  64. // @router /list [get]
  65. func (this *ActivityCoAntroller) ActivityList() {
  66. br := new(models.BaseResponse).Init()
  67. defer func() {
  68. this.Data["json"] = br
  69. this.ServeJSON()
  70. }()
  71. user := this.User
  72. if user == nil {
  73. br.Msg = "请登录"
  74. br.ErrMsg = "请登录,SysUser Is Empty"
  75. return
  76. }
  77. uid := user.UserId
  78. pageSize, _ := this.GetInt("PageSize")
  79. currentIndex, _ := this.GetInt("CurrentIndex")
  80. chartPermissionIds := this.GetString("ChartPermissionIds")
  81. activityTypeIds := this.GetString("ActivityTypeIds")
  82. whichDay := this.GetString("WhichDay")
  83. isShowJurisdiction, _ := this.GetInt("IsShowJurisdiction")
  84. keyWord := this.GetString("KeyWord")
  85. keyWordSearch := this.GetString("KeyWord")
  86. activeState := this.GetString("ActiveState")
  87. label := this.GetString("Label")
  88. //入参为 undefined 时的处理
  89. if chartPermissionIds == "undefined" {
  90. chartPermissionIds = ""
  91. }
  92. if activityTypeIds == "undefined" {
  93. activityTypeIds = ""
  94. }
  95. if whichDay == "undefined" {
  96. whichDay = ""
  97. }
  98. if activeState == "undefined" {
  99. activeState = ""
  100. }
  101. if label == "undefined" {
  102. label = ""
  103. }
  104. //更新用户的搜索信息
  105. itemSearch := new(models.CygxActivityUserSearchContent)
  106. itemSearch.UserId = uid
  107. itemSearch.CreateTime = time.Now()
  108. itemSearch.Mobile = user.Mobile
  109. itemSearch.Email = user.Email
  110. itemSearch.CompanyId = user.CompanyId
  111. itemSearch.CompanyName = user.CompanyName
  112. itemSearch.ModifyTime = time.Now()
  113. itemSearch.ChartPermissionids = chartPermissionIds
  114. itemSearch.ActivityTypeids = activityTypeIds
  115. itemSearch.ActiveState = activeState
  116. itemSearch.IsShowJurisdiction = isShowJurisdiction
  117. //并发缓存校验
  118. cacheKey := fmt.Sprint("xygx:activity_user_search:add:", uid)
  119. ttlTime := utils.Rc.GetRedisTTL(cacheKey)
  120. _, errSearch := models.AddUserSearchContent(itemSearch, ttlTime)
  121. if errSearch != nil {
  122. br.Msg = "操作失败"
  123. br.ErrMsg = "操作失败,Err:" + errSearch.Error()
  124. return
  125. }
  126. utils.Rc.SetNX(cacheKey, user.Mobile, time.Second*10)
  127. userType, permissionStr, err := services.GetUserType(user.CompanyId)
  128. if isShowJurisdiction == 1 && chartPermissionIds == "" && userType == 4 {
  129. activityTypeIds = "1,3"
  130. }
  131. var startSize int
  132. if pageSize <= 0 {
  133. pageSize = utils.PageSize20
  134. }
  135. if currentIndex <= 0 {
  136. currentIndex = 1
  137. }
  138. startSize = utils.StartIndex(currentIndex, pageSize)
  139. var condition string
  140. var pars []interface{}
  141. //活动可见限制
  142. var sqlExport string
  143. slicePer := strings.Split(permissionStr, ",")
  144. var permissionSqlStr string
  145. for _, v := range slicePer {
  146. if userType == 1 {
  147. if v != "研选" {
  148. permissionSqlStr += "'" + v + "',"
  149. }
  150. } else {
  151. permissionSqlStr += "'" + v + "',"
  152. }
  153. }
  154. permissionSqlStr = strings.TrimRight(permissionSqlStr, ",")
  155. permissionSqlStr = ` AND art.chart_permission_name IN (` + permissionSqlStr + `)`
  156. sqlExport = ` AND (art.customer_type_ids LIKE '%` + strconv.Itoa(userType) + `%' `
  157. if userType == 2 {
  158. sqlExport += ` OR art.customer_type_ids LIKE '%3%' `
  159. }
  160. if (userType == 2 || userType == 3) && strings.Contains(permissionStr, "专家") {
  161. sqlExport += ` OR art.customer_type_ids LIKE '%4%' `
  162. }
  163. sqlExport += `) `
  164. if keyWord != "" {
  165. var mirrorword string
  166. var mirrorwordSql string
  167. slicemirrorword := strings.Split(keyWord, ",")
  168. for _, v := range slicemirrorword {
  169. mirrorwordSql += "'" + v + "'" + ","
  170. }
  171. mirrorwordSql = strings.TrimRight(mirrorwordSql, ",")
  172. total, err := models.GetActivityMirrorWordCount(mirrorwordSql)
  173. if err != nil {
  174. br.Msg = "获取失败"
  175. br.ErrMsg = "获取失败,Err:" + err.Error()
  176. return
  177. }
  178. if total > 0 {
  179. mirrorword, err = models.GetMirrorWord(mirrorwordSql)
  180. if err != nil {
  181. br.Msg = "获取信息失败"
  182. br.ErrMsg = "关系词映射获取失败,Err:" + err.Error()
  183. return
  184. }
  185. }
  186. keyWord = keyWord + "," + mirrorword
  187. slicekeyWord := strings.Split(keyWord, ",")
  188. var sqlKeyOr string
  189. if len(slicekeyWord) >= 2 {
  190. for _, v := range slicekeyWord {
  191. if v != "" {
  192. sqlKeyOr += ` OR art.activity_name LIKE '%` + v + `%' `
  193. }
  194. }
  195. condition += ` AND (art.activity_name LIKE '%` + keyWord + `%' ` + sqlKeyOr + ` )`
  196. } else {
  197. condition += ` AND (art.activity_name LIKE '%` + keyWord + `%' )`
  198. }
  199. }
  200. //主题
  201. if label != "" {
  202. sliceLabel := strings.Split(label, ",")
  203. var labelSqlStr string
  204. for _, v := range sliceLabel {
  205. labelSqlStr += "'" + v + "',"
  206. }
  207. labelSqlStr = strings.TrimRight(labelSqlStr, ",")
  208. condition = ` AND art.label IN (` + labelSqlStr + `)`
  209. }
  210. //行业名称
  211. if len(chartPermissionIds) > 0 {
  212. condition += ` AND art.chart_permission_id IN (` + chartPermissionIds + `)`
  213. }
  214. if activityTypeIds != "" {
  215. condition += ` AND art.activity_type_id IN (` + activityTypeIds + `)`
  216. }
  217. if whichDay != "" {
  218. var startDate string
  219. var endDate string
  220. if whichDay == "1" {
  221. startDate = time.Now().Format(utils.FormatDate)
  222. endDate = startDate
  223. } else if whichDay == "2" {
  224. startDate = time.Now().AddDate(0, 0, +1).Format(utils.FormatDate)
  225. endDate = startDate
  226. } else {
  227. startDate = time.Now().Format(utils.FormatDate)
  228. endDate = time.Now().AddDate(0, 0, +1).Format(utils.FormatDate)
  229. }
  230. condition += ` AND art.activity_time >= ` + "'" + startDate + " 00:00:00'"
  231. condition += ` AND art.activity_time <= ` + "'" + endDate + " 23:59:59'"
  232. }
  233. if activeState != "" {
  234. condition += ` AND art.active_state IN (` + activeState + `)`
  235. }
  236. condition += ` AND art.publish_status = 1 `
  237. var conditionOr string
  238. // 有专家权限的这几种用户,不做行业权限校验
  239. if (userType == 2 || userType == 3 || userType == 4) && strings.Contains(permissionStr, "专家") {
  240. conditionOr += ` OR ( art.is_limit_people = 1 AND art.customer_type_ids LIKE '%4%' ` + condition + `) `
  241. }
  242. if (userType == 5) && strings.Contains(permissionStr, "专家") {
  243. conditionOr += ` OR ( art.is_limit_people = 1 AND art.customer_type_ids LIKE '%5%' ` + condition + `) `
  244. }
  245. if userType == 1 {
  246. conditionOr += ` OR ( art.is_limit_people = 0 ` + condition + permissionSqlStr + `) `
  247. } else {
  248. conditionOr += ` OR ( art.is_limit_people = 0 ` + condition + `) `
  249. }
  250. condition += ` AND art.is_limit_people = 1 ` + permissionSqlStr + sqlExport + conditionOr
  251. total, err := models.GetActivityCount(condition, pars)
  252. if err != nil {
  253. br.Msg = "获取失败"
  254. br.ErrMsg = "获取失败,Err:" + err.Error()
  255. return
  256. }
  257. if activeState == "2" || activeState == "3" {
  258. condition += ` ORDER BY art.activity_time DESC `
  259. } else {
  260. condition += ` ORDER BY art.active_state ASC, art.activity_time ASC `
  261. }
  262. list, errList := models.GetActivityListAll(condition, pars, uid, startSize, pageSize)
  263. if errList != nil {
  264. br.Msg = "获取失败"
  265. br.ErrMsg = "获取失败,Err:" + errList.Error()
  266. return
  267. }
  268. var isShow bool
  269. isShow = services.GetShowSustainable()
  270. detail, err := models.GetConfigByCode("city_img_url")
  271. if err != nil {
  272. br.Msg = "获取数据失败"
  273. br.ErrMsg = "城市配置信息失败,Err:" + err.Error()
  274. return
  275. }
  276. detailChart, err := models.GetConfigByCode("chart_img_url")
  277. if err != nil {
  278. br.Msg = "获取数据失败"
  279. br.ErrMsg = "行业配置信息失败,Err:" + err.Error()
  280. return
  281. }
  282. addressList := strings.Split(detail.ConfigValue, "{|}")
  283. mapAddress := make(map[string]string)
  284. chartList := strings.Split(detailChart.ConfigValue, "{|}")
  285. mapChart := make(map[string]string)
  286. var cityName string
  287. var chartName string
  288. var imgUrl string
  289. var imgUrlChart string
  290. for _, v := range addressList {
  291. vslice := strings.Split(v, "_")
  292. cityName = vslice[0]
  293. imgUrl = vslice[len(vslice)-1]
  294. mapAddress[cityName] = imgUrl
  295. }
  296. for _, v := range chartList {
  297. vslice := strings.Split(v, "_")
  298. chartName = vslice[0]
  299. imgUrlChart = vslice[len(vslice)-1]
  300. mapChart[chartName] = imgUrlChart
  301. }
  302. for k, v := range list {
  303. if strings.Contains(v.ActivityName, "【") {
  304. list[k].IsBrackets = 1
  305. }
  306. if v.SignupNum > v.LimitPeopleNum {
  307. list[k].SignupNum = v.LimitPeopleNum
  308. }
  309. if isShow && v.ChartPermissionName == "研选" {
  310. list[k].IsShowSustainable = true
  311. }
  312. if v.ChartPermissionName == "研选" && v.ActivityTypeId == 1 {
  313. list[k].ActivityTypeName = "研选电话会"
  314. list[k].ImgUrlText = "https://hongze.oss-cn-shanghai.aliyuncs.com/static/images/202112/20211221/bIdfv8t86xrFRpDOeGGHXOmKEuKl.png"
  315. }
  316. if v.ActivityType == 0 {
  317. if mapAddress[v.City] != "" {
  318. list[k].ImgUrl = mapAddress[v.City]
  319. } else {
  320. list[k].ImgUrl = mapAddress["其它"]
  321. }
  322. } else {
  323. if mapChart[v.ChartPermissionName] != "" {
  324. list[k].ImgUrl = mapChart[v.ChartPermissionName]
  325. }
  326. }
  327. expertTxt, _ := services.GetReportContentTextSub(v.Expert)
  328. list[k].Expert = expertTxt
  329. }
  330. if keyWordSearch != "" {
  331. keyWordItem := new(models.CygxUserSearchKeyWord)
  332. keyWordItem.UserId = user.UserId
  333. keyWordItem.KeyWord = keyWordSearch
  334. keyWordItem.PageType = "ActivitSearch"
  335. keyWordItem.CreateTime = time.Now()
  336. go models.AddUserSearchKeyWord(keyWordItem)
  337. }
  338. page := paging.GetPaging(currentIndex, pageSize, total)
  339. resp := new(models.GetCygxActivityListRep)
  340. resp.List = list
  341. resp.Paging = page
  342. br.Ret = 200
  343. br.Success = true
  344. br.Msg = "获取成功"
  345. br.Data = resp
  346. }
  347. // @Title 我的日程
  348. // @Description 我的日程列表接口
  349. // @Param PageSize query int true "每页数据条数"
  350. // @Param CurrentIndex query int true "当前页页码,从1开始"
  351. // @Success 200 {object} models.GetCygxActivityListRep
  352. // @router /scheduleList [get]
  353. func (this *ActivityCoAntroller) ScheduleList() {
  354. br := new(models.BaseResponse).Init()
  355. defer func() {
  356. this.Data["json"] = br
  357. this.ServeJSON()
  358. }()
  359. user := this.User
  360. if user == nil {
  361. br.Msg = "请登录"
  362. br.ErrMsg = "请登录,SysUser Is Empty"
  363. return
  364. }
  365. uid := user.UserId
  366. pageSize, _ := this.GetInt("PageSize")
  367. currentIndex, _ := this.GetInt("CurrentIndex")
  368. var startSize int
  369. if pageSize <= 0 {
  370. pageSize = utils.PageSize20
  371. }
  372. if currentIndex <= 0 {
  373. currentIndex = 1
  374. }
  375. startSize = utils.StartIndex(currentIndex, pageSize)
  376. var condition string
  377. var conditionCount string
  378. var pars []interface{}
  379. condition += ` AND art.publish_status = 1 `
  380. total, err := models.GetScheduleCount(conditionCount, uid)
  381. page := paging.GetPaging(currentIndex, pageSize, total)
  382. if err != nil {
  383. br.Msg = "获取失败"
  384. br.ErrMsg = "获取失败,Err:" + err.Error()
  385. return
  386. }
  387. conditionCount = ` AND art.active_state = 2 `
  388. totalCount, err := models.GetScheduleCount(conditionCount, uid) //获取正在进行中的活动数量
  389. if err != nil {
  390. br.Msg = "获取失败"
  391. br.ErrMsg = "获取失败,Err:" + err.Error()
  392. return
  393. }
  394. var list []*models.CygxActivityList
  395. fmt.Println(totalCount)
  396. //全部都是进行中的活动
  397. if totalCount > currentIndex*pageSize {
  398. condition += ` AND art.active_state IN(2) `
  399. listHave, errList := models.GetScheduleList(condition, pars, uid, startSize, pageSize)
  400. list = listHave
  401. if errList != nil {
  402. br.Msg = "获取失败"
  403. br.ErrMsg = "获取失败,Err:" + errList.Error()
  404. return
  405. }
  406. } else if totalCount > currentIndex-1*pageSize && totalCount < currentIndex*pageSize { //部分是进行中的活动
  407. condition = ` AND art.publish_status = 1 AND art.active_state IN(2) `
  408. listHave, errList := models.GetScheduleList(condition, pars, uid, startSize, pageSize)
  409. list = listHave
  410. if errList != nil {
  411. br.Msg = "获取失败"
  412. br.ErrMsg = "获取失败,Err:" + errList.Error()
  413. return
  414. }
  415. pageSize = pageSize - len(listHave)
  416. condition = ` AND art.publish_status = 1 AND art.active_state IN(1,3) `
  417. listOther, errList := models.GetScheduleList(condition, pars, uid, startSize, pageSize)
  418. if errList != nil {
  419. br.Msg = "获取失败"
  420. br.ErrMsg = "获取失败,Err:" + errList.Error()
  421. return
  422. }
  423. fmt.Println("长度", len(listOther))
  424. if len(listOther) > 0 {
  425. for _, v := range listOther {
  426. list = append(list, v)
  427. }
  428. }
  429. } else {
  430. condition += ` AND art.active_state IN(1,3)` //全部都不是进行中的活动
  431. listOther, errList := models.GetScheduleList(condition, pars, uid, startSize, pageSize)
  432. list = listOther
  433. if errList != nil {
  434. br.Msg = "获取失败"
  435. br.ErrMsg = "获取失败,Err:" + errList.Error()
  436. return
  437. }
  438. }
  439. var isShow bool
  440. isShow = services.GetShowSustainable()
  441. detail, err := models.GetConfigByCode("city_img_url")
  442. if err != nil {
  443. br.Msg = "获取数据失败"
  444. br.ErrMsg = "城市配置信息失败,Err:" + err.Error()
  445. return
  446. }
  447. detailChart, err := models.GetConfigByCode("chart_img_url")
  448. if err != nil {
  449. br.Msg = "获取数据失败"
  450. br.ErrMsg = "行业配置信息失败,Err:" + err.Error()
  451. return
  452. }
  453. addressList := strings.Split(detail.ConfigValue, "{|}")
  454. mapAddress := make(map[string]string)
  455. chartList := strings.Split(detailChart.ConfigValue, "{|}")
  456. mapChart := make(map[string]string)
  457. var cityName string
  458. var chartName string
  459. var imgUrl string
  460. var imgUrlChart string
  461. for _, v := range addressList {
  462. vslice := strings.Split(v, "_")
  463. cityName = vslice[0]
  464. imgUrl = vslice[len(vslice)-1]
  465. mapAddress[cityName] = imgUrl
  466. }
  467. for _, v := range chartList {
  468. vslice := strings.Split(v, "_")
  469. chartName = vslice[0]
  470. imgUrlChart = vslice[len(vslice)-1]
  471. mapChart[chartName] = imgUrlChart
  472. }
  473. for k, v := range list {
  474. if strings.Contains(v.ActivityName, "【") {
  475. list[k].IsBrackets = 1
  476. }
  477. if v.SignupNum > v.LimitPeopleNum {
  478. list[k].SignupNum = v.LimitPeopleNum
  479. }
  480. //是否展示限免标签
  481. if isShow && v.ChartPermissionName == "研选" {
  482. list[k].IsShowSustainable = true
  483. }
  484. if v.ChartPermissionName == "研选" && v.ActivityTypeId == 1 {
  485. list[k].ActivityTypeName = "研选电话会"
  486. list[k].ImgUrlText = "https://hongze.oss-cn-shanghai.aliyuncs.com/static/images/202112/20211221/bIdfv8t86xrFRpDOeGGHXOmKEuKl.png"
  487. }
  488. if v.ActivityType == 0 {
  489. if mapAddress[v.City] != "" {
  490. list[k].ImgUrl = mapAddress[v.City]
  491. } else {
  492. list[k].ImgUrl = mapAddress["其它"]
  493. }
  494. } else {
  495. if mapChart[v.ChartPermissionName] != "" {
  496. list[k].ImgUrl = mapChart[v.ChartPermissionName]
  497. }
  498. }
  499. expertTxt, _ := services.GetReportContentTextSub(v.Expert)
  500. list[k].Expert = expertTxt
  501. }
  502. //添加我的日程访问记录
  503. item := new(models.CygxPageHistoryRecord)
  504. item.UserId = user.UserId
  505. item.CreateTime = time.Now()
  506. item.Mobile = user.Mobile
  507. item.Email = user.Email
  508. item.CompanyId = user.CompanyId
  509. item.CompanyName = user.CompanyName
  510. item.PageType = "MySchedule"
  511. go models.AddCygxPageHistoryRecord(item)
  512. resp := new(models.GetCygxActivityListRep)
  513. resp.List = list
  514. resp.Paging = page
  515. br.Ret = 200
  516. br.Success = true
  517. br.Msg = "获取成功"
  518. br.Data = resp
  519. }
  520. // @Title 活动详情
  521. // @Description 获取活动详情接口
  522. // @Param ActivityId query int true "活动ID"
  523. // @Success Ret=200 {object} models.CygxActivityResp
  524. // @router /detail [get]
  525. func (this *ActivityCoAntroller) Detail() {
  526. br := new(models.BaseResponse).Init()
  527. defer func() {
  528. this.Data["json"] = br
  529. this.ServeJSON()
  530. }()
  531. user := this.User
  532. if user == nil {
  533. br.Msg = "请登录"
  534. br.ErrMsg = "请登录,用户信息为空"
  535. br.Ret = 408
  536. return
  537. }
  538. uid := user.UserId
  539. activityId, _ := this.GetInt("ActivityId")
  540. if activityId < 1 {
  541. br.Msg = "请输入活动ID"
  542. return
  543. }
  544. resp := new(models.CygxActivityResp)
  545. hasPermission := 0
  546. var companyDetailStatus string
  547. activityInfo, err := models.GetAddActivityInfoByIdShow(uid, activityId)
  548. if err != nil && err.Error() != utils.ErrNoRow() {
  549. br.Msg = "获取信息失败"
  550. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  551. return
  552. }
  553. if activityInfo == nil {
  554. br.Msg = "活动不存在"
  555. br.ErrMsg = "活动ID错误,Err:" + "activityId:" + strconv.Itoa(activityId)
  556. return
  557. }
  558. applyCount, err := models.GetApplyRecordCount(uid)
  559. if err != nil && err.Error() != utils.ErrNoRow() {
  560. br.Msg = "获取信息失败"
  561. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  562. return
  563. }
  564. //获取FICC销售信息 如果是FICC的客户类型,则默认他申请过
  565. sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 1)
  566. if err != nil && err.Error() != utils.ErrNoRow() {
  567. br.Msg = "获取信息失败"
  568. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  569. return
  570. }
  571. if user.CompanyId <= 1 {
  572. companyDetailStatus = ""
  573. } else {
  574. companyPermission, err := models.GetCompanyPermission(user.CompanyId)
  575. if err != nil {
  576. br.Msg = "获取信息失败"
  577. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  578. return
  579. }
  580. if companyPermission == "" {
  581. if applyCount > 0 {
  582. hasPermission = 4
  583. } else {
  584. if sellerItem != nil {
  585. hasPermission = 5
  586. } else {
  587. //获取权益销售信息 如果是FICC的客户类型,则默认他申请过
  588. sellerItemQy, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  589. if err != nil && err.Error() != utils.ErrNoRow() {
  590. br.Msg = "获取信息失败"
  591. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  592. return
  593. }
  594. if sellerItemQy != nil {
  595. hasPermission = 2
  596. resp.SellerMobile = sellerItemQy.Mobile
  597. resp.SellerName = sellerItemQy.RealName
  598. } else {
  599. hasPermission = 3
  600. }
  601. }
  602. }
  603. resp.HasPermission = hasPermission
  604. resp.OperationMode = "Apply"
  605. resp.PopupMsg = "您暂无权限参加此活动,若想参加可以申请开通对应的试用权限"
  606. br.Ret = 200
  607. br.Success = true
  608. br.Msg = "获取成功"
  609. br.Data = resp
  610. return
  611. }
  612. companyDetail, err := models.GetCompanyDetailById(user.CompanyId)
  613. if err != nil {
  614. br.Msg = "获取信息失败!"
  615. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  616. return
  617. }
  618. if companyDetail == nil {
  619. br.Msg = "获取信息失败!"
  620. br.ErrMsg = "客户不存在,uid:" + strconv.Itoa(user.UserId) + "CompanyId:" + strconv.Itoa(user.CompanyId)
  621. return
  622. }
  623. companyDetailStatus = companyDetail.Status
  624. }
  625. userType, permissionStr, err := services.GetUserType(user.CompanyId)
  626. if err != nil {
  627. br.Msg = "获取信息失败"
  628. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  629. return
  630. }
  631. if activityInfo.IsLimitPeople > 0 {
  632. noPower, err := services.GetShareNoPowe(activityInfo, permissionStr, userType)
  633. if err != nil {
  634. br.Msg = "获取信息失败"
  635. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  636. return
  637. }
  638. if noPower {
  639. br.Msg = "您暂无查看该活动权限"
  640. br.ErrMsg = "被分享客户不可见,获取信息失败"
  641. return
  642. }
  643. }
  644. if userType == 1 && activityInfo.ChartPermissionName == "研选" {
  645. br.Msg = "您暂无查看该活动权限"
  646. br.ErrMsg = "被分享客户不可见,永续客户无法查看研选行业"
  647. return
  648. }
  649. detail, errDetail := models.GetActivityTypeDetailById(activityInfo.ActivityTypeId)
  650. if errDetail != nil {
  651. br.Msg = "获取信息失败"
  652. br.ErrMsg = "获取信息失败,Err:" + errDetail.Error()
  653. return
  654. }
  655. if activityInfo.IsSignup > 0 {
  656. detail, errDetail := models.GetActivitySignupDetail(activityId, uid)
  657. if errDetail != nil {
  658. br.Msg = "获取信息失败"
  659. br.ErrMsg = "获取信息失败,Err:" + errDetail.Error()
  660. return
  661. }
  662. activityInfo.SignupType = detail.SignupType
  663. }
  664. activityInfo.ShowType = detail.ShowType
  665. //判断是否已经申请过
  666. if user.CompanyId > 1 {
  667. permissionStr, err := models.GetCompanyPermissionByUser(user.CompanyId)
  668. fmt.Println(permissionStr)
  669. if err != nil {
  670. br.Msg = "获取信息失败"
  671. br.ErrMsg = "获取客户权限信息失败,Err:" + err.Error()
  672. return
  673. }
  674. companyItem, err := models.GetCompanyDetailById(user.CompanyId)
  675. //冻结客户
  676. if err != nil {
  677. if err.Error() == utils.ErrNoRow() {
  678. if applyCount > 0 {
  679. hasPermission = 4
  680. } else {
  681. if sellerItem != nil {
  682. hasPermission = 5
  683. } else {
  684. //获取权益销售信息 如果是FICC的客户类型,则默认他申请过
  685. sellerItemQy, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  686. if err != nil && err.Error() != utils.ErrNoRow() {
  687. br.Msg = "获取信息失败"
  688. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  689. return
  690. }
  691. if sellerItemQy != nil {
  692. hasPermission = 2
  693. resp.SellerMobile = sellerItemQy.Mobile
  694. resp.SellerName = sellerItemQy.RealName
  695. } else {
  696. hasPermission = 3
  697. }
  698. }
  699. }
  700. resp.HasPermission = hasPermission
  701. resp.OperationMode = "Apply"
  702. resp.PopupMsg = "您暂无权限参加此活动,若想参加可以申请开通对应的试用权限"
  703. br.Ret = 200
  704. br.Success = true
  705. br.Msg = "获取成功"
  706. br.Data = resp
  707. return
  708. } else {
  709. br.Msg = "获取信息失败"
  710. br.ErrMsg = "获取客户公司信息失败,Err:" + err.Error()
  711. return
  712. }
  713. }
  714. havePower, err := services.GetHavePower(activityInfo, permissionStr, companyDetailStatus, userType)
  715. if havePower {
  716. hasPermission = 1
  717. resp.HaqveJurisdiction = true
  718. } else {
  719. if permissionStr == "专家" {
  720. resp.PopupMsg = "您暂无权限参加此活动,若想参加可以申请开通对应的试用权限"
  721. resp.MsgType = "Type"
  722. } else {
  723. //if strings.Contains("医药,消费,科技,智造", activityInfo.ChartPermissionName) {
  724. // if activityInfo.ActivityTypeId == 1 || activityInfo.ActivityTypeId == 3 || activityInfo.ActivityTypeId == 5 || activityInfo.ActivityTypeId == 6 {
  725. // activityInfo.ChartPermissionName += "(主观)"
  726. // } else {
  727. // activityInfo.ChartPermissionName += "(客观)"
  728. // }
  729. //}
  730. resp.PopupMsg = "您暂无权限参加此活动,若想参加可以申请开通对应的试用权限"
  731. resp.MsgType = "Industry"
  732. }
  733. resp.SellerMobile = companyItem.Mobile
  734. resp.SellerName = companyItem.SellerName
  735. resp.OperationMode = "Call"
  736. hasPermission = 2
  737. }
  738. } else { //潜在客户
  739. if applyCount > 0 {
  740. hasPermission = 4
  741. } else {
  742. if sellerItem != nil {
  743. hasPermission = 5
  744. } else {
  745. hasPermission = 3
  746. }
  747. }
  748. resp.OperationMode = "Apply"
  749. resp.PopupMsg = "您暂无权限参加此活动,若想参加可以申请开通对应的试用权限"
  750. }
  751. if hasPermission == 1 {
  752. //是否展示限免标签
  753. if services.GetShowSustainable() && activityInfo.ChartPermissionName == "研选" {
  754. activityInfo.IsShowSustainable = true
  755. }
  756. configCode := "description_of_research"
  757. detail, err := models.GetConfigByCode(configCode)
  758. if err != nil {
  759. br.Msg = "获取数据失败"
  760. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  761. return
  762. }
  763. activityInfo.Description = detail.ConfigValue
  764. if activityInfo.SignupNum > activityInfo.LimitPeopleNum {
  765. activityInfo.SignupNum = activityInfo.LimitPeopleNum
  766. }
  767. if activityInfo.ChartPermissionNames != "" {
  768. activityInfo.ChartPermissionName = activityInfo.ChartPermissionNames
  769. }
  770. resp.Detail = activityInfo
  771. }
  772. resp.HasPermission = hasPermission
  773. br.Ret = 200
  774. br.Success = true
  775. br.Msg = "获取成功"
  776. br.Data = resp
  777. }
  778. // @Title 活动报名
  779. // @Description 活动报名接口
  780. // @Param request body models.ActivitySingnupRep true "type json string"
  781. // @Success Ret=200 {object} models.SignupStatus
  782. // @router /signup/add [post]
  783. func (this *ActivityCoAntroller) SignupAdd() {
  784. br := new(models.BaseResponse).Init()
  785. defer func() {
  786. this.Data["json"] = br
  787. this.ServeJSON()
  788. }()
  789. user := this.User
  790. if user == nil {
  791. br.Msg = "请登录"
  792. br.ErrMsg = "请登录,用户信息为空"
  793. br.Ret = 408
  794. return
  795. }
  796. uid := user.UserId
  797. signupStatus := ""
  798. var req models.ActivitySingnupRep
  799. resp := new(models.SignupStatus)
  800. var total int
  801. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  802. if err != nil {
  803. br.Msg = "参数解析异常!"
  804. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  805. return
  806. }
  807. activityId := req.ActivityId
  808. signupType := req.SignupType
  809. hasPermission := 0
  810. if signupType == 1 && user.Mobile == "" && user.OutboundMobile == "" {
  811. resp.GoBindEmail = true
  812. }
  813. //判断是否已经申请过
  814. applyCount, err := models.GetApplyRecordCount(uid)
  815. if err != nil && err.Error() != utils.ErrNoRow() {
  816. br.Msg = "获取信息失败"
  817. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  818. return
  819. }
  820. //获取FICC销售信息
  821. sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 1)
  822. if err != nil && err.Error() != utils.ErrNoRow() {
  823. br.Msg = "申请失败"
  824. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  825. return
  826. }
  827. activityInfo, errInfo := models.GetAddActivityInfoById(activityId)
  828. if activityInfo == nil {
  829. br.Msg = "操作失败"
  830. br.ErrMsg = "活动ID错误,不存在activityId:" + strconv.Itoa(activityId)
  831. return
  832. }
  833. if errInfo != nil {
  834. br.Msg = "操作失败"
  835. br.ErrMsg = "操作失败,Err:" + errInfo.Error()
  836. return
  837. }
  838. //SignupStatus "报名状态:人数已满:FullStarffed、单机构超过两人:TwoPeople、爽约次数过多:BreakPromise、超时:Overtime 、成功:Success"`
  839. //HasPermission "1:有该行业权限,正常展示,2:无该行业权限,3:潜在客户,未提交过申请,4:潜在客户,已提交过申请"`
  840. var companyDetailStatus string
  841. if user.CompanyId <= 1 {
  842. companyDetailStatus = ""
  843. } else {
  844. companyPermission, err := models.GetCompanyPermission(user.CompanyId)
  845. if err != nil {
  846. br.Msg = "获取信息失败"
  847. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  848. return
  849. }
  850. if companyPermission == "" {
  851. if applyCount > 0 {
  852. hasPermission = 4
  853. } else {
  854. if sellerItem != nil {
  855. hasPermission = 5
  856. } else {
  857. //获取权益销售信息 如果是FICC的客户类型,则默认他申请过
  858. sellerItemQy, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  859. if err != nil && err.Error() != utils.ErrNoRow() {
  860. br.Msg = "获取信息失败"
  861. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  862. return
  863. }
  864. if sellerItemQy != nil {
  865. hasPermission = 2
  866. resp.SellerMobile = sellerItemQy.Mobile
  867. resp.SellerName = sellerItemQy.RealName
  868. } else {
  869. hasPermission = 3
  870. }
  871. }
  872. }
  873. resp.HasPermission = hasPermission
  874. resp.ActivityId = activityId
  875. resp.OperationMode = "Apply"
  876. resp.PopupMsg = "您暂无权限参加此活动,若想参加可以申请开通对应的试用权限"
  877. br.Ret = 200
  878. br.Success = true
  879. br.Msg = "获取成功"
  880. br.Data = resp
  881. return
  882. }
  883. companyDetail, err := models.GetCompanyDetailById(user.CompanyId)
  884. if err != nil {
  885. br.Msg = "获取信息失败!"
  886. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  887. return
  888. }
  889. if companyDetail == nil {
  890. br.Msg = "获取信息失败!"
  891. br.ErrMsg = "客户不存在,uid:" + strconv.Itoa(user.UserId) + "CompanyId:" + strconv.Itoa(user.CompanyId)
  892. return
  893. }
  894. companyDetailStatus = companyDetail.Status
  895. }
  896. var userType int
  897. var permissionStr string
  898. userType, permissionStr, err = services.GetUserType(user.CompanyId)
  899. if err != nil {
  900. br.Msg = "获取信息失败!"
  901. br.ErrMsg = "获取失败,Err:" + err.Error()
  902. return
  903. }
  904. if userType == 1 && activityInfo.ChartPermissionName == "研选" {
  905. br.Msg = "您暂无查看该活动权限"
  906. br.ErrMsg = "被分享客户不可见,永续客户无法查看研选行业"
  907. return
  908. }
  909. item := new(models.CygxActivitySignup)
  910. if user.CompanyId > 1 {
  911. companyItem, err := models.GetCompanyDetailById(user.CompanyId)
  912. //冻结客户
  913. if err != nil {
  914. if err.Error() == utils.ErrNoRow() {
  915. if applyCount > 0 {
  916. hasPermission = 4
  917. } else {
  918. if sellerItem != nil {
  919. hasPermission = 5
  920. } else {
  921. hasPermission = 3
  922. }
  923. }
  924. resp.ActivityId = activityId
  925. resp.HasPermission = hasPermission
  926. resp.OperationMode = "Apply"
  927. resp.PopupMsg = "您暂无权限参加此活动,若想参加可以申请开通对应的试用权限"
  928. br.Ret = 200
  929. br.Success = true
  930. br.Msg = "获取成功"
  931. br.Data = resp
  932. return
  933. } else {
  934. br.Msg = "获取信息失败"
  935. br.ErrMsg = "获取客户公司信息失败,Err:" + err.Error()
  936. return
  937. }
  938. }
  939. //1专家电话会、2分析师电话会、3公司调研电话会、4公司线下调研、5专家线下沙龙、6分析师线下沙龙
  940. //OperationMode string `description:"操作方式 Apply:立即申请、Call:拨号 为空则为有权限"`
  941. havePower, err := services.GetHavePower(activityInfo, permissionStr, companyDetailStatus, userType)
  942. if err != nil {
  943. br.Msg = "获取信息失败!"
  944. br.ErrMsg = "获取失败,Err:" + err.Error()
  945. return
  946. }
  947. if havePower {
  948. hasPermission = 1
  949. signupStatus = "Success"
  950. resultTime := utils.StrTimeToTime(activityInfo.ActivityTime) //时间字符串格式转时间格式
  951. if time.Now().After(resultTime.Add(-time.Minute * 60)) {
  952. signupStatus = "Overtime"
  953. resp.SignupType = signupType
  954. resp.SignupStatus = signupStatus
  955. resp.HasPermission = hasPermission
  956. br.Ret = 200
  957. br.Success = true
  958. br.Msg = ""
  959. br.Data = resp
  960. return
  961. }
  962. var sellerName string
  963. sellerName, err = models.GetCompanySellerName(user.CompanyId)
  964. if err != nil {
  965. br.Msg = "报名失败!"
  966. br.ErrMsg = "获取对应销售失败,Err:" + err.Error()
  967. return
  968. }
  969. //人数已满:FullStarffed、单机构超过两人:TwoPeople、爽约次数过多:BreakPromise、超时:Overtime 、成功:Success"`
  970. //如果是下面几种情况则对报名信息做判断限制 (公司调研电话会(限制人数)、公司线下调研、专家/分析师线下沙龙)
  971. if (activityInfo.ActivityTypeId == 3 && activityInfo.IsLimitPeople == 1) || activityInfo.ActivityTypeId > 3 {
  972. //判断优先级:总人数限制→单机构2人限制→爽约3次限制
  973. totalRestrict, err := models.GetUserRestrictCount(user.Mobile)
  974. if err != nil {
  975. br.Msg = "获取信息失败"
  976. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  977. return
  978. }
  979. if totalRestrict >= 1 {
  980. signupStatus = "BreakPromise"
  981. item.FailType = 3
  982. }
  983. totalSignupCompany, err := models.GetActivitySignupCompanyCount(activityId, user.CompanyId)
  984. if err != nil {
  985. br.Msg = "获取信息失败"
  986. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  987. return
  988. }
  989. if totalSignupCompany >= 2 {
  990. signupStatus = "TwoPeople"
  991. item.FailType = 2
  992. }
  993. totaSignupPeopleNum, err := models.GetActivitySignupSuccessCount(activityId)
  994. if err != nil {
  995. br.Msg = "获取信息失败"
  996. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  997. return
  998. }
  999. if totaSignupPeopleNum >= activityInfo.LimitPeopleNum {
  1000. signupStatus = "FullStarffed"
  1001. item.FailType = 1
  1002. }
  1003. totalUserRestrictCount, err := models.GetActivitySignupByUserRestrictCount(uid, activityId)
  1004. if err != nil {
  1005. br.Msg = "获取失败"
  1006. br.ErrMsg = "获取失败,Err:" + err.Error()
  1007. return
  1008. }
  1009. //解除报名限制之后二次报名相同活动
  1010. if totalUserRestrictCount > 0 && totalRestrict == 0 && resp.GoBindEmail != true {
  1011. item.UserId = uid
  1012. item.RealName = user.RealName
  1013. item.SellerName = sellerName
  1014. item.ActivityId = activityId
  1015. item.CreateTime = time.Now()
  1016. item.Mobile = user.Mobile
  1017. item.Email = user.Email
  1018. item.CompanyId = user.CompanyId
  1019. item.CompanyName = user.CompanyName
  1020. item.SignupType = signupType
  1021. item.FailType = 0
  1022. item.DoFailType = 0
  1023. _, errSignup := models.AddActivitySignupByRestrict(item)
  1024. if errSignup != nil {
  1025. br.Msg = "操作失败"
  1026. br.ErrMsg = "操作失败,Err:" + errSignup.Error()
  1027. return
  1028. }
  1029. resp.HaqveJurisdiction = true
  1030. resp.SignupType = signupType
  1031. resp.SignupStatus = "Success"
  1032. resp.HasPermission = hasPermission
  1033. resp.ActivityId = activityId
  1034. total, err = models.GetUserMeetingReminderCount(user.UserId)
  1035. if err != nil {
  1036. br.Msg = "获取信息失败"
  1037. br.ErrMsg = "获取日程数量信息失败,Err:" + err.Error()
  1038. return
  1039. }
  1040. if total == 0 {
  1041. resp.GoFollow = true
  1042. }
  1043. br.Ret = 200
  1044. br.Success = true
  1045. br.Msg = "操作成功"
  1046. br.Data = resp
  1047. return
  1048. }
  1049. totalMy, err := models.GetActivitySignupByUserCount(uid, activityId)
  1050. if err != nil {
  1051. br.Msg = "获取失败"
  1052. br.ErrMsg = "获取失败,Err:" + err.Error()
  1053. return
  1054. }
  1055. if signupStatus != "Success" && totalMy == 0 && resp.GoBindEmail != true {
  1056. item.UserId = uid
  1057. item.RealName = user.RealName
  1058. item.SellerName = sellerName
  1059. item.ActivityId = activityId
  1060. item.CreateTime = time.Now()
  1061. item.Mobile = user.Mobile
  1062. item.Email = user.Email
  1063. item.CompanyId = user.CompanyId
  1064. item.CompanyName = user.CompanyName
  1065. item.SignupType = signupType
  1066. item.DoFailType = item.FailType
  1067. if user.OutboundMobile != "" {
  1068. item.OutboundMobile = user.OutboundMobile
  1069. if user.OutboundCountryCode == "" {
  1070. item.CountryCode = "86"
  1071. } else {
  1072. item.CountryCode = user.OutboundCountryCode
  1073. }
  1074. } else {
  1075. item.OutboundMobile = user.Mobile
  1076. if user.CountryCode == "" {
  1077. item.CountryCode = "86"
  1078. } else {
  1079. item.CountryCode = user.CountryCode
  1080. }
  1081. }
  1082. //添加报名信息,但是不加入日程
  1083. _, errSignup := models.AddActivitySignupNoSchedule(item)
  1084. if errSignup != nil {
  1085. br.Msg = "操作失败"
  1086. br.ErrMsg = "操作失败,Err:" + errSignup.Error()
  1087. return
  1088. }
  1089. }
  1090. }
  1091. totalMySuccess, err := models.GetActivitySignupCount(uid, activityId)
  1092. if err != nil {
  1093. br.Msg = "获取失败"
  1094. br.ErrMsg = "获取失败,Err:" + err.Error()
  1095. return
  1096. }
  1097. if totalMySuccess > 0 {
  1098. br.Msg = "您已报名这个活动"
  1099. return
  1100. }
  1101. if signupStatus == "Success" && resp.GoBindEmail != true {
  1102. item.UserId = uid
  1103. item.RealName = user.RealName
  1104. item.SellerName = sellerName
  1105. item.ActivityId = activityId
  1106. item.CreateTime = time.Now()
  1107. item.Mobile = user.Mobile
  1108. item.Email = user.Email
  1109. item.CompanyId = user.CompanyId
  1110. item.CompanyName = user.CompanyName
  1111. item.SignupType = signupType
  1112. item.FailType = 0
  1113. item.DoFailType = 0
  1114. item.OutboundMobile = user.Mobile
  1115. if user.OutboundMobile != "" {
  1116. item.OutboundMobile = user.OutboundMobile
  1117. if user.OutboundCountryCode == "" {
  1118. item.CountryCode = "86"
  1119. } else {
  1120. item.CountryCode = user.OutboundCountryCode
  1121. }
  1122. } else {
  1123. item.OutboundMobile = user.Mobile
  1124. if user.CountryCode == "" {
  1125. item.CountryCode = "86"
  1126. } else {
  1127. item.CountryCode = user.CountryCode
  1128. }
  1129. }
  1130. _, errSignup := models.AddActivitySignup(item)
  1131. if errSignup != nil {
  1132. br.Msg = "操作失败"
  1133. br.ErrMsg = "操作失败,Err:" + errSignup.Error()
  1134. return
  1135. }
  1136. resp.HaqveJurisdiction = true
  1137. }
  1138. } else {
  1139. hasPermission = 2
  1140. resp.SellerMobile = companyItem.Mobile
  1141. resp.SellerName = companyItem.SellerName
  1142. resp.MsgType = "Type"
  1143. resp.OperationMode = "Call"
  1144. if permissionStr == "专家" {
  1145. resp.PopupMsg = "您暂无权限参加【" + activityInfo.ActivityTypeName + "】类型活动,若想参加请联系对口销售--" + companyItem.SellerName + ":" + companyItem.Mobile
  1146. resp.MsgType = "Type"
  1147. } else {
  1148. resp.PopupMsg = "您暂无权限参加【" + activityInfo.ChartPermissionName + "】行业活动,若想参加请联系对口销售--" + companyItem.SellerName + ":" + companyItem.Mobile
  1149. resp.MsgType = "Industry"
  1150. }
  1151. }
  1152. } else { //潜在客户
  1153. if applyCount > 0 {
  1154. hasPermission = 4
  1155. } else {
  1156. if sellerItem != nil {
  1157. hasPermission = 5
  1158. } else {
  1159. hasPermission = 3
  1160. }
  1161. }
  1162. resp.OperationMode = "Apply"
  1163. resp.PopupMsg = "您暂无权限参加此活动,若想参加可以申请开通对应的试用权限"
  1164. }
  1165. if signupType == 1 && user.IsMsgOutboundMobile == 0 {
  1166. resp.GoOutboundMobile = true
  1167. if user.Mobile != "" || user.OutboundMobile != "" {
  1168. go models.ModifyWxUserIsMsgOutboundMobile(user.UserId)
  1169. }
  1170. }
  1171. if user.OutboundMobile == "" {
  1172. resp.Mobile = user.Mobile
  1173. if user.CountryCode == "" && len(user.Mobile) == 11 {
  1174. resp.CountryCode = "86"
  1175. } else {
  1176. resp.CountryCode = user.CountryCode
  1177. }
  1178. } else {
  1179. resp.Mobile = user.OutboundMobile
  1180. resp.CountryCode = user.OutboundCountryCode
  1181. }
  1182. //如果用户有绑定手机号,但是没有绑定外呼手机号
  1183. if signupType == 1 && user.Mobile != "" && user.OutboundMobile == "" {
  1184. var countryCode string
  1185. if len(user.Mobile) == 8 {
  1186. countryCode = "852"
  1187. } else if len(user.Mobile) == 9 {
  1188. countryCode = "886"
  1189. } else if len(user.Mobile) == 10 {
  1190. countryCode = "1"
  1191. } else if len(user.Mobile) >= 11 {
  1192. countryCode = "86"
  1193. }
  1194. models.BindUserOutboundMobileByMobile(user.Mobile, countryCode, uid)
  1195. }
  1196. resp.SignupType = signupType
  1197. resp.SignupStatus = signupStatus
  1198. resp.HasPermission = hasPermission
  1199. //if signupStatus == "Success" {
  1200. resp.ActivityId = activityId
  1201. //}
  1202. total, err = models.GetUserSignupCount(user.UserId)
  1203. if err != nil {
  1204. br.Msg = "获取信息失败"
  1205. br.ErrMsg = "获取日程数量信息失败,Err:" + err.Error()
  1206. return
  1207. }
  1208. if total <= 1 {
  1209. resp.GoFollow = true
  1210. }
  1211. br.Ret = 200
  1212. br.Success = true
  1213. br.Msg = "操作成功"
  1214. br.Data = resp
  1215. }
  1216. // @Title 活动取消报名
  1217. // @Description 活动取消报名接口
  1218. // @Param request body models.ActivitySingnupRep true "type json string"
  1219. // @Success Ret=200 {object} models.SignupStatus
  1220. // @router /signup/cancel [post]
  1221. func (this *ActivityCoAntroller) SignupCancel() {
  1222. br := new(models.BaseResponse).Init()
  1223. defer func() {
  1224. this.Data["json"] = br
  1225. this.ServeJSON()
  1226. }()
  1227. user := this.User
  1228. if user == nil {
  1229. br.Msg = "请登录"
  1230. br.ErrMsg = "请登录,用户信息为空"
  1231. br.Ret = 408
  1232. return
  1233. }
  1234. uid := user.UserId
  1235. var req models.ActivitySingnupRep
  1236. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1237. if err != nil {
  1238. br.Msg = "参数解析异常!"
  1239. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1240. return
  1241. }
  1242. activityId := req.ActivityId
  1243. signupType := req.SignupType
  1244. item := new(models.CygxActivitySignup)
  1245. activityInfo, errInfo := models.GetAddActivityInfoById(activityId)
  1246. if activityInfo == nil {
  1247. br.Msg = "操作失败"
  1248. br.ErrMsg = "活动ID错误,不存在activityId:" + strconv.Itoa(activityId)
  1249. return
  1250. }
  1251. if errInfo != nil {
  1252. br.Msg = "操作失败"
  1253. br.ErrMsg = "操作失败,Err:" + errInfo.Error()
  1254. return
  1255. }
  1256. resultTime := utils.StrTimeToTime(activityInfo.ActivityTime) //时间字符串格式转时间格式
  1257. if time.Now().After(resultTime.Add(-time.Minute * 60)) {
  1258. if signupType == 1 {
  1259. br.Msg = "活动开始前1小时内无法取消预约外呼,请联系对口销售处理"
  1260. } else {
  1261. br.Msg = "活动开始前1小时内无法取消报名,请联系对口销售处理"
  1262. }
  1263. return
  1264. }
  1265. total, err := models.GetActivitySignupCount(uid, activityId)
  1266. if err != nil {
  1267. br.Msg = "获取失败"
  1268. br.ErrMsg = "获取失败,Err:" + err.Error()
  1269. return
  1270. }
  1271. if total == 0 {
  1272. br.Msg = "您暂未报名这个活动"
  1273. return
  1274. }
  1275. item.UserId = uid
  1276. item.ActivityId = activityId
  1277. item.CreateTime = time.Now()
  1278. item.Mobile = user.Mobile
  1279. item.Email = user.Email
  1280. item.CompanyId = user.CompanyId
  1281. item.CompanyName = user.CompanyName
  1282. resp := new(models.SignupStatus)
  1283. resp.ActivityId = activityId
  1284. _, errSignup := models.CancelActivitySignup(item)
  1285. if errSignup != nil {
  1286. br.Msg = "操作失败"
  1287. br.ErrMsg = "操作失败,Err:" + errSignup.Error()
  1288. return
  1289. }
  1290. br.Ret = 200
  1291. br.Success = true
  1292. br.Msg = "操作成功"
  1293. br.Data = resp
  1294. }
  1295. // @Title 用户搜索详情
  1296. // @Description 获取用户搜索详情接口
  1297. // @Param IsShowJurisdiction query int true "是否仅展示有权限的,默认为0,1是,2否 "
  1298. // @Success Ret=200 {object} models.ActivityUserSearchContentList
  1299. // @router /getUserSearchContent [get]
  1300. func (this *ActivityCoAntroller) GetUserSearchContent() {
  1301. br := new(models.BaseResponse).Init()
  1302. defer func() {
  1303. this.Data["json"] = br
  1304. this.ServeJSON()
  1305. }()
  1306. user := this.User
  1307. if user == nil {
  1308. br.Msg = "请登录"
  1309. br.ErrMsg = "请登录,用户信息为空"
  1310. br.Ret = 408
  1311. return
  1312. }
  1313. uid := user.UserId
  1314. detailSeearch := new(models.CygxActivityUserSearchContent)
  1315. detailSeearch.IsShowJurisdiction = 0
  1316. detailSeearch.ChartPermissionids = ""
  1317. detailSeearch.ActiveState = ""
  1318. resp := new(models.ActivityUserSearchContentList)
  1319. detail, _ := models.GetUserSearchContentByUid(uid)
  1320. if detail == nil {
  1321. detail = detailSeearch
  1322. }
  1323. isShowJurisdiction, _ := this.GetInt("IsShowJurisdiction")
  1324. listActivityType, errActivityType := models.GetActivityTypeList()
  1325. if errActivityType != nil {
  1326. br.Msg = "获取失败"
  1327. br.ErrMsg = "获取数据失败,Err:" + errActivityType.Error()
  1328. return
  1329. }
  1330. var listChartPermissionid []*models.ActivityChartPermission
  1331. var errChart error
  1332. if isShowJurisdiction == 1 {
  1333. listChartPermissionidAll, errChartAll := models.GetUserCompanyPermission(user.CompanyId)
  1334. listChartPermissionid = listChartPermissionidAll
  1335. errChart = errChartAll
  1336. } else if isShowJurisdiction == 2 {
  1337. listChartPermissionidAll, errChartAll := models.GetChartPermissionActivity()
  1338. listChartPermissionid = listChartPermissionidAll
  1339. errChart = errChartAll
  1340. } else {
  1341. if detail.IsShowJurisdiction == 1 {
  1342. listChartPermissionidAll, errChartAll := models.GetUserCompanyPermission(user.CompanyId)
  1343. listChartPermissionid = listChartPermissionidAll
  1344. errChart = errChartAll
  1345. } else {
  1346. listChartPermissionidAll, errChartAll := models.GetChartPermissionActivity()
  1347. listChartPermissionid = listChartPermissionidAll
  1348. errChart = errChartAll
  1349. }
  1350. }
  1351. if errChart != nil {
  1352. br.Msg = "获取信息失败"
  1353. br.ErrMsg = "获取品种信息失败,Err:" + errChart.Error()
  1354. return
  1355. }
  1356. if detail.IsShowJurisdiction == 1 {
  1357. resp.IsShowJurisdiction = true
  1358. }
  1359. if isShowJurisdiction == 1 || detail.IsShowJurisdiction == 1 {
  1360. resp.IsShowJurisdiction = true
  1361. for k, _ := range listChartPermissionid {
  1362. listChartPermissionid[k].IsChoose = true
  1363. }
  1364. }
  1365. if isShowJurisdiction == 2 {
  1366. resp.IsShowJurisdiction = false
  1367. }
  1368. activeStateList := []models.ActivityStaus{models.ActivityStaus{Id: 1, StatusName: "未开始", IsChoose: true}, models.ActivityStaus{Id: 2, StatusName: "进行中"}, models.ActivityStaus{Id: 3, StatusName: "已结束"}}
  1369. list2, err := models.GetChartPermissionActivity()
  1370. if err != nil {
  1371. br.Msg = "获取信息失败"
  1372. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  1373. return
  1374. }
  1375. if activeStateList[1].IsChoose == activeStateList[2].IsChoose == false {
  1376. activeStateList[0].IsChoose = true
  1377. }
  1378. var userType int
  1379. userType, _, err = services.GetUserType(user.CompanyId)
  1380. if err != nil {
  1381. br.Msg = "获取信息失败!"
  1382. br.ErrMsg = "获取失败,Err:" + err.Error()
  1383. return
  1384. }
  1385. var listChartPermissionidNew2 []*models.ActivityChartPermission
  1386. for _, v := range list2 {
  1387. if userType == 1 {
  1388. if v.PermissionName != "研选" {
  1389. listChartPermissionidNew2 = append(listChartPermissionidNew2, v)
  1390. }
  1391. } else {
  1392. listChartPermissionidNew2 = append(listChartPermissionidNew2, v)
  1393. }
  1394. }
  1395. resp.ListChartPermission2 = listChartPermissionidNew2
  1396. var listChartPermissionidNew []*models.ActivityChartPermission
  1397. for _, v := range listChartPermissionid {
  1398. if userType == 1 {
  1399. if v.PermissionName != "研选" {
  1400. listChartPermissionidNew = append(listChartPermissionidNew, v)
  1401. }
  1402. } else {
  1403. listChartPermissionidNew = append(listChartPermissionidNew, v)
  1404. }
  1405. }
  1406. resp.ListActivityType = listActivityType
  1407. resp.ListChartPermission = listChartPermissionidNew
  1408. resp.ListActivityStaus = activeStateList
  1409. br.Ret = 200
  1410. br.Success = true
  1411. br.Msg = "获取成功"
  1412. br.Data = resp
  1413. }
  1414. // @Title 添加会议提醒
  1415. // @Description 添加会议提醒接口
  1416. // @Param request body models.ActivityIdRep true "type json string"
  1417. // @Success Ret=200 {object} models.SignupStatus
  1418. // @router /meetingReminder/add [post]
  1419. func (this *ActivityCoAntroller) MeetingReminderAdd() {
  1420. br := new(models.BaseResponse).Init()
  1421. defer func() {
  1422. this.Data["json"] = br
  1423. this.ServeJSON()
  1424. }()
  1425. user := this.User
  1426. if user == nil {
  1427. br.Msg = "请登录"
  1428. br.ErrMsg = "请登录,用户信息为空"
  1429. br.Ret = 408
  1430. return
  1431. }
  1432. uid := user.UserId
  1433. //var signupStatus string
  1434. signupStatus := "Success"
  1435. var req models.ActivityIdRep
  1436. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1437. if err != nil {
  1438. br.Msg = "参数解析异常!"
  1439. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1440. return
  1441. }
  1442. activityId := req.ActivityId
  1443. activityInfo, errInfo := models.GetAddActivityInfoById(activityId)
  1444. if activityInfo == nil {
  1445. br.Msg = "操作失败"
  1446. br.ErrMsg = "活动ID错误,不存在activityId:" + strconv.Itoa(activityId)
  1447. return
  1448. }
  1449. if errInfo != nil {
  1450. br.Msg = "操作失败"
  1451. br.ErrMsg = "操作失败,Err:" + errInfo.Error()
  1452. return
  1453. }
  1454. //判断是否已经申请过
  1455. applyCount, err := models.GetApplyRecordCount(uid)
  1456. if err != nil && err.Error() != utils.ErrNoRow() {
  1457. br.Msg = "获取信息失败"
  1458. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  1459. return
  1460. }
  1461. //获取销售信息
  1462. sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 1)
  1463. if err != nil && err.Error() != utils.ErrNoRow() {
  1464. br.Msg = "申请失败"
  1465. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  1466. return
  1467. }
  1468. //SignupStatus string `description:"报名状态:人数已满:FullStarffed、单机构超过两人:TwoPeople、爽约次数过多:BreakPromise、超时:Overtime 、成功:Success"`
  1469. item := new(models.CygxActivityMeetingReminder)
  1470. resp := new(models.SignupStatus)
  1471. hasPermission := 0
  1472. var companyDetailStatus string
  1473. if user.CompanyId <= 1 {
  1474. companyDetailStatus = ""
  1475. } else {
  1476. companyPermission, err := models.GetCompanyPermission(user.CompanyId)
  1477. if err != nil {
  1478. br.Msg = "获取信息失败"
  1479. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  1480. return
  1481. }
  1482. if companyPermission == "" {
  1483. if applyCount > 0 {
  1484. hasPermission = 4
  1485. } else {
  1486. if sellerItem != nil {
  1487. hasPermission = 5
  1488. } else {
  1489. //获取权益销售信息 如果是FICC的客户类型,则默认他申请过
  1490. sellerItemQy, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  1491. if err != nil && err.Error() != utils.ErrNoRow() {
  1492. br.Msg = "获取信息失败"
  1493. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  1494. return
  1495. }
  1496. if sellerItemQy != nil {
  1497. hasPermission = 2
  1498. resp.SellerMobile = sellerItemQy.Mobile
  1499. resp.SellerName = sellerItemQy.RealName
  1500. } else {
  1501. hasPermission = 3
  1502. }
  1503. }
  1504. }
  1505. resp.ActivityId = activityId
  1506. resp.HasPermission = hasPermission
  1507. resp.OperationMode = "Apply"
  1508. resp.PopupMsg = "您暂无权限参加此活动,若想参加可以申请开通对应的试用权限"
  1509. br.Ret = 200
  1510. br.Success = true
  1511. br.Msg = "获取成功"
  1512. br.Data = resp
  1513. return
  1514. }
  1515. companyDetail, err := models.GetCompanyDetailById(user.CompanyId)
  1516. if err != nil {
  1517. br.Msg = "获取信息失败!"
  1518. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  1519. return
  1520. }
  1521. if companyDetail == nil {
  1522. br.Msg = "获取信息失败!"
  1523. br.ErrMsg = "客户不存在,uid:" + strconv.Itoa(user.UserId) + "CompanyId:" + strconv.Itoa(user.CompanyId)
  1524. return
  1525. }
  1526. companyDetailStatus = companyDetail.Status
  1527. }
  1528. var userType int
  1529. var permissionStr string
  1530. userType, permissionStr, err = services.GetUserType(user.CompanyId)
  1531. if err != nil {
  1532. br.Msg = "获取信息失败!"
  1533. br.ErrMsg = "获取失败,Err:" + err.Error()
  1534. return
  1535. }
  1536. if userType == 1 && activityInfo.ChartPermissionName == "研选" {
  1537. br.Msg = "您暂无查看该活动权限"
  1538. br.ErrMsg = "被分享客户不可见,永续客户无法查看研选行业"
  1539. return
  1540. }
  1541. resultTime := utils.StrTimeToTime(activityInfo.ActivityTime) //时间字符串格式转时间格式
  1542. if time.Now().After(resultTime.Add(-time.Minute * 15)) {
  1543. br.Msg = "活动开始前15分钟无法设置会议提醒"
  1544. return
  1545. }
  1546. if user.CompanyId > 1 {
  1547. companyItem, err := models.GetCompanyDetailById(user.CompanyId)
  1548. //冻结客户
  1549. if err != nil {
  1550. if err.Error() == utils.ErrNoRow() {
  1551. //如果是FICC的客户类型,则默认他申请过
  1552. if applyCount > 0 {
  1553. hasPermission = 4
  1554. } else {
  1555. if sellerItem != nil {
  1556. hasPermission = 5
  1557. } else {
  1558. hasPermission = 3
  1559. }
  1560. }
  1561. resp.ActivityId = activityId
  1562. resp.HasPermission = hasPermission
  1563. resp.OperationMode = "Apply"
  1564. resp.PopupMsg = "您暂无权限参加此活动,若想参加可以申请开通对应的试用权限"
  1565. br.Ret = 200
  1566. br.Success = true
  1567. br.Msg = "获取成功"
  1568. br.Data = resp
  1569. return
  1570. } else {
  1571. br.Msg = "获取信息失败"
  1572. br.ErrMsg = "获取客户公司信息失败,Err:" + err.Error()
  1573. return
  1574. }
  1575. }
  1576. havePower, err := services.GetHavePower(activityInfo, permissionStr, companyDetailStatus, userType)
  1577. if err != nil {
  1578. br.Msg = "获取信息失败!"
  1579. br.ErrMsg = "获取失败,Err:" + err.Error()
  1580. return
  1581. }
  1582. if havePower {
  1583. hasPermission = 1
  1584. signupStatus = "Success"
  1585. totalMeeting, errMeeting := models.GetActivityMeetingReminderCount(uid, activityId)
  1586. if errMeeting != nil {
  1587. br.Msg = "获取失败"
  1588. br.ErrMsg = "获取失败,Err:" + errMeeting.Error()
  1589. return
  1590. }
  1591. if totalMeeting > 0 {
  1592. br.Msg = "您已预约,请勿重复预约"
  1593. return
  1594. }
  1595. item.UserId = uid
  1596. item.ActivityId = activityId
  1597. item.CreateTime = time.Now()
  1598. item.Mobile = user.Mobile
  1599. item.Email = user.Email
  1600. item.CompanyId = user.CompanyId
  1601. item.CompanyName = user.CompanyName
  1602. _, errSignup := models.AddActivityMeetingReminder(item)
  1603. if errSignup != nil {
  1604. br.Msg = "操作失败"
  1605. br.ErrMsg = "操作失败,Err:" + errSignup.Error()
  1606. return
  1607. }
  1608. resp.HaqveJurisdiction = true
  1609. } else {
  1610. hasPermission = 2
  1611. resp.SellerMobile = companyItem.Mobile
  1612. resp.SellerName = companyItem.SellerName
  1613. resp.MsgType = "Type"
  1614. resp.OperationMode = "Call"
  1615. if permissionStr == "专家" {
  1616. resp.PopupMsg = "您暂无权限参加【" + activityInfo.ActivityTypeName + "】类型活动,若想参加请联系对口销售--" + companyItem.SellerName + ":" + companyItem.Mobile
  1617. resp.MsgType = "Type"
  1618. } else {
  1619. resp.PopupMsg = "您暂无权限参加【" + activityInfo.ChartPermissionName + "】行业活动,若想参加请联系对口销售--" + companyItem.SellerName + ":" + companyItem.Mobile
  1620. resp.MsgType = "Industry"
  1621. }
  1622. }
  1623. } else { //潜在客户
  1624. if applyCount > 0 {
  1625. hasPermission = 4
  1626. } else {
  1627. if sellerItem != nil {
  1628. hasPermission = 5
  1629. } else {
  1630. hasPermission = 3
  1631. }
  1632. }
  1633. resp.OperationMode = "Apply"
  1634. resp.PopupMsg = "您暂无权限参加此活动,若想参加可以申请开通对应的试用权限"
  1635. }
  1636. resp.HasPermission = hasPermission
  1637. resp.SignupStatus = signupStatus
  1638. resp.ActivityId = activityId
  1639. var total int
  1640. total, err = models.GetUserActivityMeetingReminderCount(user.UserId)
  1641. if err != nil {
  1642. br.Msg = "获取信息失败"
  1643. br.ErrMsg = "获取日程数量信息失败,Err:" + err.Error()
  1644. return
  1645. }
  1646. if total <= 1 {
  1647. resp.GoFollow = true
  1648. }
  1649. br.Ret = 200
  1650. br.Success = true
  1651. if hasPermission == 1 {
  1652. br.Msg = "设置成功,会前15分钟会为您推送微信消息提醒"
  1653. }
  1654. br.Data = resp
  1655. }
  1656. // @Title 取消会议提醒
  1657. // @Description 取消会议提醒接口
  1658. // @Param request body models.ActivityIdRep true "type json string"
  1659. // @Success Ret=200 {object} models.SignupStatus
  1660. // @router /meetingReminder/cancel [post]
  1661. func (this *ActivityCoAntroller) MeetingReminderCancel() {
  1662. br := new(models.BaseResponse).Init()
  1663. defer func() {
  1664. this.Data["json"] = br
  1665. this.ServeJSON()
  1666. }()
  1667. user := this.User
  1668. if user == nil {
  1669. br.Msg = "请登录"
  1670. br.ErrMsg = "请登录,用户信息为空"
  1671. br.Ret = 408
  1672. return
  1673. }
  1674. uid := user.UserId
  1675. var req models.ActivityIdRep
  1676. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1677. if err != nil {
  1678. br.Msg = "参数解析异常!"
  1679. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1680. return
  1681. }
  1682. activityId := req.ActivityId
  1683. signupStatus := "Success"
  1684. item := new(models.CygxActivityMeetingReminder)
  1685. activityInfo, errInfo := models.GetAddActivityInfoById(activityId)
  1686. if activityInfo == nil {
  1687. br.Msg = "操作失败"
  1688. br.ErrMsg = "活动ID错误,不存在activityId:" + strconv.Itoa(activityId)
  1689. return
  1690. }
  1691. if errInfo != nil {
  1692. br.Msg = "操作失败"
  1693. br.ErrMsg = "操作失败,Err:" + errInfo.Error()
  1694. return
  1695. }
  1696. //if signupStatus == "Success" {
  1697. total, err := models.GetActivityMeetingReminderCount(uid, activityId)
  1698. if err != nil {
  1699. br.Msg = "获取失败"
  1700. br.ErrMsg = "获取失败,Err:" + err.Error()
  1701. return
  1702. }
  1703. if total == 0 {
  1704. br.Msg = "您暂未添加该活动会议提醒"
  1705. return
  1706. }
  1707. resultTime := utils.StrTimeToTime(activityInfo.ActivityTime) //时间字符串格式转时间格式
  1708. if time.Now().After(resultTime.Add(-time.Minute * 15)) {
  1709. br.Msg = "活动开始前15分钟无法取消会议提醒"
  1710. return
  1711. }
  1712. item.UserId = uid
  1713. item.ActivityId = activityId
  1714. item.CreateTime = time.Now()
  1715. item.Mobile = user.Mobile
  1716. item.Email = user.Email
  1717. item.CompanyId = user.CompanyId
  1718. item.CompanyName = user.CompanyName
  1719. _, errSignup := models.CancelActivityMeetingReminder(item)
  1720. if errSignup != nil {
  1721. br.Msg = "操作失败"
  1722. br.ErrMsg = "操作失败,Err:" + errSignup.Error()
  1723. return
  1724. }
  1725. //}
  1726. resp := new(models.SignupStatus)
  1727. resp.SignupStatus = signupStatus
  1728. resp.ActivityId = activityId
  1729. br.Ret = 200
  1730. br.Success = true
  1731. br.Msg = "会议提醒已取消"
  1732. br.Data = resp
  1733. }
  1734. // @Title 敏捷搜索关键词的列表
  1735. // @Description 获取敏捷搜索关键词的列表接口
  1736. // @Success 200 {object} models.ActivityFastsearchKeywordsListResp
  1737. // @router /fastSearchKeWord [get]
  1738. func (this *ActivityABaseController) FastSearch() {
  1739. br := new(models.BaseResponse).Init()
  1740. defer func() {
  1741. this.Data["json"] = br
  1742. this.ServeJSON()
  1743. }()
  1744. resp := new(models.ActivityFastsearchKeywordsListResp)
  1745. list, err := models.GetActivityFastsearchKeywordsList()
  1746. if err != nil {
  1747. br.Msg = "获取失败"
  1748. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1749. return
  1750. }
  1751. resp.List = list
  1752. br.Ret = 200
  1753. br.Success = true
  1754. br.Msg = "获取成功"
  1755. br.Data = resp
  1756. }
  1757. // @Title 主题列表
  1758. // @Description 获取活动主题列表接口
  1759. // @Param ChartPermissionIds query string false "行业id 多个用 , 隔开"
  1760. // @Param ActivityTypeIds query string false "活动类型id 多个用 , 隔开"
  1761. // @Param ActiveState query string false "活动进行状态 未开始:1、进行中2、已结束3"
  1762. // @Param WhichDay query string false "哪一天 今天:1、明天:2,多个用 , 隔开"
  1763. // @Param Label query string false "搜索主题 多个用 , 隔开 (空为活动主题,非空为更多主题)"
  1764. // @Success 200 {object} models.GetCygxActivityLabelListRep
  1765. // @router /labelList [get]
  1766. func (this *ActivityCoAntroller) LabelList() {
  1767. br := new(models.BaseResponse).Init()
  1768. defer func() {
  1769. this.Data["json"] = br
  1770. this.ServeJSON()
  1771. }()
  1772. user := this.User
  1773. if user == nil {
  1774. br.Msg = "请登录"
  1775. br.ErrMsg = "请登录,SysUser Is Empty"
  1776. return
  1777. }
  1778. pageSize, _ := this.GetInt("PageSize")
  1779. chartPermissionIds := this.GetString("ChartPermissionIds")
  1780. activityTypeIds := this.GetString("ActivityTypeIds")
  1781. whichDay := this.GetString("WhichDay")
  1782. isShowJurisdiction, _ := this.GetInt("IsShowJurisdiction")
  1783. activeState := this.GetString("ActiveState")
  1784. label := this.GetString("Label")
  1785. //入参为 undefined 时的处理
  1786. if chartPermissionIds == "undefined" {
  1787. chartPermissionIds = ""
  1788. }
  1789. if activityTypeIds == "undefined" {
  1790. activityTypeIds = ""
  1791. }
  1792. if whichDay == "undefined" {
  1793. whichDay = ""
  1794. }
  1795. if activeState == "undefined" {
  1796. activeState = ""
  1797. }
  1798. if label == "undefined" {
  1799. label = ""
  1800. }
  1801. userType, permissionStr, err := services.GetUserType(user.CompanyId)
  1802. if err != nil {
  1803. br.Msg = "获取失败"
  1804. br.ErrMsg = "获取失败,Err:" + err.Error()
  1805. return
  1806. }
  1807. if isShowJurisdiction == 1 && chartPermissionIds == "" && userType == 4 {
  1808. activityTypeIds = "1,3"
  1809. }
  1810. var startSize int
  1811. pageSize = 15
  1812. var condition string
  1813. var sortTime string
  1814. var pars []interface{}
  1815. //活动可见限制
  1816. var sqlExport string
  1817. slicePer := strings.Split(permissionStr, ",")
  1818. var permissionSqlStr string
  1819. for _, v := range slicePer {
  1820. if userType == 1 {
  1821. if v != "研选" {
  1822. permissionSqlStr += "'" + v + "',"
  1823. }
  1824. } else {
  1825. permissionSqlStr += "'" + v + "',"
  1826. }
  1827. }
  1828. permissionSqlStr = strings.TrimRight(permissionSqlStr, ",")
  1829. permissionSqlStr = ` AND art.chart_permission_name IN (` + permissionSqlStr + `)`
  1830. sqlExport = ` AND (art.customer_type_ids LIKE '%` + strconv.Itoa(userType) + `%' `
  1831. if userType == 2 {
  1832. sqlExport += ` OR art.customer_type_ids LIKE '%3%' `
  1833. }
  1834. if (userType == 2 || userType == 3) && strings.Contains(permissionStr, "专家") {
  1835. sqlExport += ` OR art.customer_type_ids LIKE '%4%' `
  1836. }
  1837. sqlExport += `) `
  1838. condition += ` AND art.publish_status = 1 AND art.label != '' `
  1839. var conditionOr string
  1840. if (userType == 2 || userType == 3 || userType == 4) && strings.Contains(permissionStr, "专家") {
  1841. conditionOr += ` OR ( art.is_limit_people = 1 AND art.customer_type_ids LIKE '%4%' ` + condition + `) `
  1842. }
  1843. if (userType == 5) && strings.Contains(permissionStr, "专家") {
  1844. conditionOr += ` OR ( art.is_limit_people = 1 AND art.customer_type_ids LIKE '%5%' ` + condition + `) `
  1845. }
  1846. if userType == 1 {
  1847. conditionOr += ` OR ( art.is_limit_people = 0 ` + condition + permissionSqlStr + `) `
  1848. } else {
  1849. conditionOr += ` OR ( art.is_limit_people = 0 ` + condition + `) `
  1850. }
  1851. condition += `AND art.is_limit_people = 1 ` + permissionSqlStr + sqlExport + conditionOr
  1852. resp := new(models.GetCygxActivityLabelListRep)
  1853. //主题
  1854. if label != "" {
  1855. sortTime = ` timesort DESC `
  1856. listAll, errList := models.GetActivityLabelListAll(condition, sortTime, pars, startSize, 32)
  1857. if errList != nil {
  1858. br.Msg = "获取失败"
  1859. br.ErrMsg = "获取失败,Err:" + errList.Error()
  1860. return
  1861. }
  1862. sortTime = ` mintimesort ASC `
  1863. condition += ` AND art.active_state = 1 `
  1864. list1, errList := models.GetActivityLabelListAll(condition, sortTime, pars, startSize, 16)
  1865. if errList != nil {
  1866. br.Msg = "获取失败"
  1867. br.ErrMsg = "获取失败,Err:" + errList.Error()
  1868. return
  1869. }
  1870. for _, v := range listAll {
  1871. var isHAve bool
  1872. for _, v2 := range list1 {
  1873. if v2.KeyWord == v.KeyWord {
  1874. isHAve = true
  1875. }
  1876. }
  1877. if !isHAve {
  1878. resp.List = append(resp.List, v)
  1879. }
  1880. }
  1881. resp.Label = label
  1882. resp.ImgUrl = ""
  1883. br.Ret = 200
  1884. br.Success = true
  1885. br.Msg = "获取成功"
  1886. br.Data = resp
  1887. return
  1888. } else {
  1889. //行业名称
  1890. condition = ` AND art.publish_status = 1 AND art.label != '' `
  1891. if len(chartPermissionIds) > 0 {
  1892. condition += ` AND art.chart_permission_id IN (` + chartPermissionIds + `)`
  1893. }
  1894. if activityTypeIds != "" {
  1895. condition += ` AND art.activity_type_id IN (` + activityTypeIds + `)`
  1896. }
  1897. var conditionOr string
  1898. if whichDay != "" {
  1899. var startDate string
  1900. var endDate string
  1901. if whichDay == "1" {
  1902. startDate = time.Now().Format(utils.FormatDate)
  1903. endDate = startDate
  1904. } else if whichDay == "2" {
  1905. startDate = time.Now().AddDate(0, 0, +1).Format(utils.FormatDate)
  1906. endDate = startDate
  1907. } else {
  1908. startDate = time.Now().Format(utils.FormatDate)
  1909. endDate = time.Now().AddDate(0, 0, +1).Format(utils.FormatDate)
  1910. }
  1911. condition += ` AND art.activity_time >= ` + "'" + startDate + " 00:00:00'"
  1912. condition += ` AND art.activity_time <= ` + "'" + endDate + " 23:59:59'"
  1913. }
  1914. if activeState != "" {
  1915. condition += ` AND art.active_state IN (` + activeState + `)`
  1916. } else {
  1917. condition += ` AND art.active_state IN (1)`
  1918. }
  1919. if (userType == 2 || userType == 3 || userType == 4) && strings.Contains(permissionStr, "专家") {
  1920. conditionOr += ` OR ( art.is_limit_people = 1 AND art.customer_type_ids LIKE '%4%' ` + condition + `) `
  1921. }
  1922. if (userType == 5) && strings.Contains(permissionStr, "专家") {
  1923. conditionOr += ` OR ( art.is_limit_people = 1 AND art.customer_type_ids LIKE '%5%' ` + condition + `) `
  1924. }
  1925. if userType == 1 {
  1926. conditionOr += ` OR ( art.is_limit_people = 0 ` + condition + permissionSqlStr + `) `
  1927. } else {
  1928. conditionOr += ` OR ( art.is_limit_people = 0 ` + condition + `) `
  1929. }
  1930. condition += `AND art.is_limit_people = 1 ` + permissionSqlStr + sqlExport + conditionOr
  1931. }
  1932. sortTime = ` mintimesort ASC `
  1933. list, errList := models.GetActivityLabelListAll(condition, sortTime, pars, startSize, pageSize)
  1934. if errList != nil {
  1935. br.Msg = "获取失败"
  1936. br.ErrMsg = "获取失败,Err:" + errList.Error()
  1937. return
  1938. }
  1939. resp.List = list
  1940. br.Ret = 200
  1941. br.Success = true
  1942. br.Msg = "获取成功"
  1943. br.Data = resp
  1944. }
  1945. // @Title 活动带问
  1946. // @Description 新增活动带问接口
  1947. // @Param request body models.AddCygxActivityHelpAsk true "type json string"
  1948. // @Success Ret=200 新增成功
  1949. // @router /askAdd [post]
  1950. func (this *ActivityCoAntroller) AskAdd() {
  1951. br := new(models.BaseResponse).Init()
  1952. defer func() {
  1953. this.Data["json"] = br
  1954. this.ServeJSON()
  1955. }()
  1956. user := this.User
  1957. if user == nil {
  1958. br.Msg = "请登录"
  1959. br.ErrMsg = "请登录,SysUser Is Empty"
  1960. br.Ret = 408
  1961. return
  1962. }
  1963. var req models.CygxActivityHelpAsk
  1964. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1965. if err != nil {
  1966. br.Msg = "参数解析异常!"
  1967. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1968. return
  1969. }
  1970. if req.Content == "" {
  1971. br.Msg = "建议内容不可为空"
  1972. return
  1973. }
  1974. content := req.Content
  1975. itemToken, err := services.WxGetToken()
  1976. if err != nil {
  1977. br.Msg = "GetWxAccessToken Err:" + err.Error()
  1978. return
  1979. }
  1980. if itemToken.AccessToken == "" {
  1981. br.Msg = "accessToken is empty"
  1982. return
  1983. }
  1984. commerr, err := weapp.MSGSecCheck(itemToken.AccessToken, content)
  1985. if err != nil {
  1986. br.Msg = "内容校验失败!"
  1987. br.ErrMsg = "内容校验失败,Err:" + err.Error()
  1988. return
  1989. }
  1990. if commerr.ErrCode != 0 {
  1991. br.Msg = "内容违规,请重新提交!"
  1992. br.ErrMsg = "颜文字内容违规,Err:" + commerr.ErrMSG
  1993. return
  1994. }
  1995. activityId := req.ActivityId
  1996. activityInfo, errInfo := models.GetAddActivityInfoById(activityId)
  1997. if activityInfo == nil {
  1998. br.Msg = "操作失败"
  1999. br.ErrMsg = "活动ID错误,不存在activityId:" + strconv.Itoa(activityId)
  2000. return
  2001. }
  2002. if errInfo != nil {
  2003. br.Msg = "操作失败"
  2004. br.ErrMsg = "操作失败,Err:" + errInfo.Error()
  2005. return
  2006. }
  2007. resultTime := utils.StrTimeToTime(activityInfo.ActivityTime) //时间字符串格式转时间格式
  2008. if activityInfo.ActivityTypeId == 1 && activityInfo.ChartPermissionId != 31 {
  2009. if time.Now().After(resultTime.Add(-time.Minute * 15)) {
  2010. br.Msg = "活动开始前15分钟内无法提交问题"
  2011. return
  2012. }
  2013. } else {
  2014. if time.Now().After(resultTime.Add(-time.Minute * 60)) {
  2015. br.Msg = "活动开始前1小时内无法提交问题"
  2016. return
  2017. }
  2018. }
  2019. companyDetail, err := models.GetCompanyDetailById(user.CompanyId)
  2020. if err != nil {
  2021. br.Msg = "提交失败!"
  2022. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  2023. return
  2024. }
  2025. if companyDetail == nil {
  2026. br.Msg = "提交失败!"
  2027. br.ErrMsg = "客户不存在,uid:" + strconv.Itoa(user.UserId)
  2028. return
  2029. }
  2030. item := new(models.CygxActivityHelpAsk)
  2031. item.UserId = user.UserId
  2032. item.ActivityId = req.ActivityId
  2033. item.CompanyId = user.CompanyId
  2034. item.CompanyName = companyDetail.CompanyName
  2035. item.CreateTime = time.Now()
  2036. item.Mobile = user.Mobile
  2037. item.Email = user.Email
  2038. item.Content = content
  2039. _, err = models.AddActivityHelpAsk(item)
  2040. if err != nil {
  2041. br.Msg = "提交失败"
  2042. br.ErrMsg = "提交带问失败,Err:" + err.Error()
  2043. return
  2044. }
  2045. br.Ret = 200
  2046. br.Success = true
  2047. br.Msg = "提交成功"
  2048. }
  2049. // @Title 活动类型下的主题列表(4.3版本)
  2050. // @Description 获取活动类型下的主题列表接口(4.3版本)
  2051. // @Param ChartPermissionIds query string false "行业id 多个用 , 隔开"
  2052. // @Param ActivityTypeIds query string false "活动类型id 多个用 , 隔开"
  2053. // @Param ActiveState query string false "活动进行状态 未开始:1、进行中2、已结束3"
  2054. // @Param WhichDay query string false "哪一天 今天:1、明天:2,多个用 , 隔开"
  2055. // @Param IsPower query int false "是否选择有权限行业 ,1是 0 否 默认0"
  2056. // @Success 200 {object} models.ActivityTypeListHomeResp
  2057. // @router /labelTypeList [get]
  2058. func (this *ActivityCoAntroller) LabelTypeList() {
  2059. br := new(models.BaseResponse).Init()
  2060. defer func() {
  2061. this.Data["json"] = br
  2062. this.ServeJSON()
  2063. }()
  2064. user := this.User
  2065. if user == nil {
  2066. br.Msg = "请登录"
  2067. br.ErrMsg = "请登录,SysUser Is Empty"
  2068. return
  2069. }
  2070. pageSize, _ := this.GetInt("PageSize")
  2071. isPower, _ := this.GetInt("IsPower")
  2072. //currentIndex, _ := this.GetInt("CurrentIndex")
  2073. chartPermissionIds := this.GetString("ChartPermissionIds")
  2074. //activityTypeIds := this.GetString("ActivityTypeIds")
  2075. whichDay := this.GetString("WhichDay")
  2076. activeState := this.GetString("ActiveState")
  2077. //入参为 undefined 时的处理
  2078. if chartPermissionIds == "undefined" {
  2079. chartPermissionIds = ""
  2080. }
  2081. if whichDay == "undefined" {
  2082. whichDay = ""
  2083. }
  2084. if activeState == "undefined" || activeState == "" {
  2085. activeState = "1"
  2086. }
  2087. userType, permissionStr, err := services.GetUserType(user.CompanyId)
  2088. if err != nil {
  2089. br.Msg = "获取失败"
  2090. br.ErrMsg = "获取失败,Err:" + err.Error()
  2091. return
  2092. }
  2093. var startSize int
  2094. pageSize = 40
  2095. var sortTime string
  2096. var pars []interface{}
  2097. //活动可见限制
  2098. slicePer := strings.Split(permissionStr, ",")
  2099. var permissionSqlStr string
  2100. var permissionNameStr string
  2101. for _, v := range slicePer {
  2102. if userType == 1 {
  2103. if v != "研选" {
  2104. permissionNameStr += "'" + v + "',"
  2105. }
  2106. } else {
  2107. permissionNameStr += "'" + v + "',"
  2108. }
  2109. }
  2110. permissionNameStr = strings.TrimRight(permissionNameStr, ",")
  2111. list, err := models.GetActivityTypeHomeList()
  2112. if err != nil {
  2113. br.Msg = "获取失败"
  2114. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  2115. return
  2116. }
  2117. resp := new(models.ActivityTypeListHomeResp)
  2118. for k, v := range list {
  2119. var sqlExport string
  2120. var condition string
  2121. permissionSqlStr = ` AND art.chart_permission_name IN (` + permissionNameStr + `)`
  2122. sqlExport = ` AND (art.customer_type_ids LIKE '%` + strconv.Itoa(userType) + `%' `
  2123. if userType == 2 {
  2124. sqlExport += ` OR art.customer_type_ids LIKE '%3%' `
  2125. }
  2126. if (userType == 2 || userType == 3) && strings.Contains(permissionStr, "专家") {
  2127. sqlExport += ` OR art.customer_type_ids LIKE '%4%' `
  2128. }
  2129. sqlExport += `) `
  2130. condition = ` AND art.publish_status = 1 AND art.label != '' AND art.activity_type_id = ` + strconv.Itoa(v.ActivityTypeId)
  2131. if isPower == 1 {
  2132. condition += permissionSqlStr
  2133. }
  2134. //行业名称
  2135. if len(chartPermissionIds) > 0 {
  2136. condition += ` AND art.chart_permission_id IN (` + chartPermissionIds + `)`
  2137. }
  2138. var conditionOr string
  2139. if whichDay != "" {
  2140. var startDate string
  2141. var endDate string
  2142. if whichDay == "1" {
  2143. startDate = time.Now().Format(utils.FormatDate)
  2144. endDate = startDate
  2145. } else if whichDay == "2" {
  2146. startDate = time.Now().AddDate(0, 0, +1).Format(utils.FormatDate)
  2147. endDate = startDate
  2148. } else {
  2149. startDate = time.Now().Format(utils.FormatDate)
  2150. endDate = time.Now().AddDate(0, 0, +1).Format(utils.FormatDate)
  2151. }
  2152. condition += ` AND art.activity_time >= ` + "'" + startDate + " 00:00:00'"
  2153. condition += ` AND art.activity_time <= ` + "'" + endDate + " 23:59:59'"
  2154. }
  2155. if activeState != "" {
  2156. condition += ` AND art.active_state IN (` + activeState + `)`
  2157. } else {
  2158. condition += ` AND art.active_state IN (1)`
  2159. }
  2160. if (userType == 2 || userType == 3 || userType == 4) && strings.Contains(permissionStr, "专家") {
  2161. conditionOr += ` OR ( art.is_limit_people = 1 AND art.customer_type_ids LIKE '%4%' ` + condition + `) `
  2162. }
  2163. if (userType == 5) && strings.Contains(permissionStr, "专家") {
  2164. conditionOr += ` OR ( art.is_limit_people = 1 AND art.customer_type_ids LIKE '%5%' ` + condition + `) `
  2165. }
  2166. if userType == 1 {
  2167. conditionOr += ` OR ( art.is_limit_people = 0 ` + condition + permissionSqlStr + `) `
  2168. } else {
  2169. conditionOr += ` OR ( art.is_limit_people = 0 ` + condition + `) `
  2170. }
  2171. condition += `AND art.is_limit_people = 1 ` + permissionSqlStr + sqlExport + conditionOr
  2172. sortTime = ` mintimesort ASC `
  2173. labelList, err := models.GetActivityLabelListAll(condition, sortTime, pars, startSize, pageSize)
  2174. if err != nil {
  2175. br.Msg = "获取失败"
  2176. br.ErrMsg = "获取失败,Err:" + err.Error()
  2177. return
  2178. }
  2179. //标签字段关联的产业与标签处理
  2180. for k2, v2 := range labelList {
  2181. labelList[k2].KeyWord = services.LabelStr(v2.KeyWord)
  2182. labelList[k2].ImgUrlBg = v.ImgUrlBgs
  2183. }
  2184. list[k].List = labelList
  2185. }
  2186. //获取对应活动的数量并排序
  2187. intArr := make([]int, 0)
  2188. var items []*models.ActivityTypeHome
  2189. for _, v := range list {
  2190. item := new(models.ActivityTypeHome)
  2191. if len(v.List) > 0 {
  2192. item.List = v.List
  2193. item.ActivityTypeName = v.ActivityTypeName
  2194. item.ActivityTypeId = v.ActivityTypeId
  2195. item.ImgUrlBg = v.ImgUrlBg
  2196. item.ImgUrl = v.ImgUrl
  2197. items = append(items, item)
  2198. intArr = append(intArr, len(v.List))
  2199. }
  2200. }
  2201. sort.Sort(sort.Reverse(sort.IntSlice(intArr)))
  2202. var itemsNew []*models.ActivityTypeHome
  2203. activityMap := make(map[int]int)
  2204. for _, v := range intArr {
  2205. for _, v2 := range items {
  2206. item := new(models.ActivityTypeHome)
  2207. if len(v2.List) > 0 && v == len(v2.List) && activityMap[v2.ActivityTypeId] == 0 {
  2208. item.List = v2.List
  2209. item.ActivityTypeName = v2.ActivityTypeName
  2210. item.ActivityTypeId = v2.ActivityTypeId
  2211. item.ImgUrlBg = v2.ImgUrlBg
  2212. item.ImgUrl = v2.ImgUrl
  2213. itemsNew = append(itemsNew, item)
  2214. activityMap[v2.ActivityTypeId] = len(v2.List)
  2215. }
  2216. }
  2217. }
  2218. //如果第三个活动数量比第四个多,则两者调换
  2219. if len(itemsNew) > 3 {
  2220. if len(itemsNew[2].List) > len(itemsNew[3].List) {
  2221. var itemsNewCopy []*models.ActivityTypeHome
  2222. for _, v := range itemsNew {
  2223. itemsNewCopy = append(itemsNewCopy, v)
  2224. }
  2225. itemsNew[2] = itemsNewCopy[3]
  2226. itemsNew[3] = itemsNewCopy[2]
  2227. }
  2228. }
  2229. //记录用户搜索的筛选条件
  2230. item := new(models.CygxActivitySearchHistory)
  2231. item.UserId = user.UserId
  2232. item.Mobile = user.Mobile
  2233. item.CompanyId = user.CompanyId
  2234. item.CompanyName = user.CompanyName
  2235. item.CreateTime = time.Now()
  2236. item.ChartPermissionIds = chartPermissionIds
  2237. item.IsPower = isPower
  2238. item.WhichDay = whichDay
  2239. go models.AddCygxActivitySearchHistory(item)
  2240. resp.List = itemsNew
  2241. br.Ret = 200
  2242. br.Success = true
  2243. br.Msg = "获取成功"
  2244. br.Data = resp
  2245. }
  2246. // @Title 更多主题列表(4.3版本)
  2247. // @Description 获取活动更多主题列表接口(4.3版本)
  2248. // @Success 200 {object} models.GetCygxActivityLabelListRep
  2249. // @router /labelMoreList [get]
  2250. func (this *ActivityCoAntroller) LabelMoreList() {
  2251. br := new(models.BaseResponse).Init()
  2252. defer func() {
  2253. this.Data["json"] = br
  2254. this.ServeJSON()
  2255. }()
  2256. user := this.User
  2257. if user == nil {
  2258. br.Msg = "请登录"
  2259. br.ErrMsg = "请登录,SysUser Is Empty"
  2260. return
  2261. }
  2262. userType, permissionStr, err := services.GetUserType(user.CompanyId)
  2263. if err != nil {
  2264. br.Msg = "获取失败"
  2265. br.ErrMsg = "获取失败,Err:" + err.Error()
  2266. return
  2267. }
  2268. var startSize, pageSize int
  2269. pageSize = 24
  2270. var condition string
  2271. var sortTime string
  2272. //var conditionStatus string
  2273. var pars []interface{}
  2274. //活动可见限制
  2275. var sqlExport string
  2276. resp := new(models.GetCygxActivityLabelListRep)
  2277. slicePer := strings.Split(permissionStr, ",")
  2278. var permissionSqlStr string
  2279. for _, v := range slicePer {
  2280. if userType == 1 {
  2281. if v != "研选" {
  2282. permissionSqlStr += "'" + v + "',"
  2283. }
  2284. } else {
  2285. permissionSqlStr += "'" + v + "',"
  2286. }
  2287. }
  2288. permissionSqlStr = strings.TrimRight(permissionSqlStr, ",")
  2289. permissionSqlStr = ` AND art.chart_permission_name IN (` + permissionSqlStr + `)`
  2290. sqlExport = ` AND (art.customer_type_ids LIKE '%` + strconv.Itoa(userType) + `%' `
  2291. if userType == 2 {
  2292. sqlExport += ` OR art.customer_type_ids LIKE '%3%' `
  2293. }
  2294. if (userType == 2 || userType == 3) && strings.Contains(permissionStr, "专家") {
  2295. sqlExport += ` OR art.customer_type_ids LIKE '%4%' `
  2296. }
  2297. sqlExport += `) `
  2298. //进行中的活动
  2299. condition = ` AND art.publish_status = 1 AND art.label != '' AND art.active_state = 2 `
  2300. var conditionOr string
  2301. if (userType == 2 || userType == 3 || userType == 4) && strings.Contains(permissionStr, "专家") {
  2302. conditionOr += ` OR ( art.is_limit_people = 1 AND art.customer_type_ids LIKE '%4%' ` + condition + `) `
  2303. }
  2304. if (userType == 5) && strings.Contains(permissionStr, "专家") {
  2305. conditionOr += ` OR ( art.is_limit_people = 1 AND art.customer_type_ids LIKE '%5%' ` + condition + `) `
  2306. }
  2307. if userType == 1 {
  2308. conditionOr += ` OR ( art.is_limit_people = 0 ` + condition + permissionSqlStr + `) `
  2309. } else {
  2310. conditionOr += ` OR ( art.is_limit_people = 0 ` + condition + `) `
  2311. }
  2312. condition += `AND art.is_limit_people = 1 ` + permissionSqlStr + sqlExport + conditionOr
  2313. //进行中的活动
  2314. sortTime = ` mintimesort ASC `
  2315. list, errList := models.GetActivityLabelListAll(condition, sortTime, pars, startSize, pageSize)
  2316. if errList != nil {
  2317. br.Msg = "获取失败"
  2318. br.ErrMsg = "获取失败,Err:" + errList.Error()
  2319. return
  2320. }
  2321. //已结束的活动
  2322. conditionOr = ""
  2323. condition = ` AND art.publish_status = 1 AND art.label != '' AND art.active_state = 3 `
  2324. if (userType == 2 || userType == 3 || userType == 4) && strings.Contains(permissionStr, "专家") {
  2325. conditionOr += ` OR ( art.is_limit_people = 1 AND art.customer_type_ids LIKE '%4%' ` + condition + `) `
  2326. }
  2327. if (userType == 5) && strings.Contains(permissionStr, "专家") {
  2328. conditionOr += ` OR ( art.is_limit_people = 1 AND art.customer_type_ids LIKE '%5%' ` + condition + `) `
  2329. }
  2330. if userType == 1 {
  2331. conditionOr += ` OR ( art.is_limit_people = 0 ` + condition + permissionSqlStr + `) `
  2332. } else {
  2333. conditionOr += ` OR ( art.is_limit_people = 0 ` + condition + `) `
  2334. }
  2335. condition += `AND art.is_limit_people = 1 ` + permissionSqlStr + sqlExport + conditionOr
  2336. startSize = 0
  2337. pageSize = 24 - len(list)
  2338. //已结束的活动
  2339. sortTime = ` timesort DESC `
  2340. listEnd, err := models.GetActivityLabelListAll(condition, sortTime, pars, startSize, pageSize)
  2341. if err != nil {
  2342. br.Msg = "获取失败"
  2343. br.ErrMsg = "获取失败,Err:" + err.Error()
  2344. return
  2345. }
  2346. for _, v := range listEnd {
  2347. list = append(list, v)
  2348. }
  2349. //标签字段关联的产业与标签处理
  2350. for k, v := range list {
  2351. list[k].KeyWord = services.LabelStr(v.KeyWord)
  2352. }
  2353. //添加更多主题访问记录
  2354. item := new(models.CygxPageHistoryRecord)
  2355. item.UserId = user.UserId
  2356. item.CreateTime = time.Now()
  2357. item.Mobile = user.Mobile
  2358. item.Email = user.Email
  2359. item.CompanyId = user.CompanyId
  2360. item.CompanyName = user.CompanyName
  2361. item.PageType = "LabelMore"
  2362. go models.AddCygxPageHistoryRecord(item)
  2363. resp.List = list
  2364. br.Ret = 200
  2365. br.Success = true
  2366. br.Msg = "获取成功"
  2367. br.Data = resp
  2368. }
  2369. // @Title 活动列表(4.3版本)
  2370. // @Description 获取活动列表接口(4.3版本)
  2371. // @Param PageSize query int true "每页数据条数"
  2372. // @Param CurrentIndex query int true "当前页页码,从1开始"
  2373. // @Param Label query string false "搜索主题 多个用 , 隔开"
  2374. // @Param ChartPermissionIds query string false "行业id 多个用 , 隔开"
  2375. // @Param WhichDay query string false "哪一天 今天:1、明天:2,多个用 , 隔开"
  2376. // @Param ActiveState query string false "活动进行状态 未开始:1、进行中2、已结束3"
  2377. // @Param ActivityTypeId query string false "活动类型id 多个用 , 隔开"
  2378. // @Success 200 {object} models.GetCygxActivityListRep
  2379. // @router /listNew [get]
  2380. func (this *ActivityCoAntroller) ActivityListNew() {
  2381. br := new(models.BaseResponse).Init()
  2382. defer func() {
  2383. this.Data["json"] = br
  2384. this.ServeJSON()
  2385. }()
  2386. user := this.User
  2387. if user == nil {
  2388. br.Msg = "请登录"
  2389. br.ErrMsg = "请登录,SysUser Is Empty"
  2390. return
  2391. }
  2392. uid := user.UserId
  2393. pageSize, _ := this.GetInt("PageSize")
  2394. currentIndex, _ := this.GetInt("CurrentIndex")
  2395. label := this.GetString("Label")
  2396. chartPermissionIds := this.GetString("ChartPermissionIds")
  2397. whichDay := this.GetString("WhichDay")
  2398. activeState := this.GetString("ActiveState")
  2399. activityTypeId := this.GetString("ActivityTypeId")
  2400. if label == "undefined" {
  2401. label = ""
  2402. }
  2403. if chartPermissionIds == "undefined" {
  2404. chartPermissionIds = ""
  2405. }
  2406. if whichDay == "undefined" {
  2407. whichDay = ""
  2408. }
  2409. if activeState == "undefined" {
  2410. activeState = ""
  2411. }
  2412. if activityTypeId == "undefined" {
  2413. activityTypeId = ""
  2414. }
  2415. var startSize int
  2416. if pageSize <= 0 {
  2417. pageSize = utils.PageSize20
  2418. }
  2419. if currentIndex <= 0 {
  2420. currentIndex = 1
  2421. }
  2422. startSize = utils.StartIndex(currentIndex, pageSize)
  2423. userType, permissionStr, err := services.GetUserType(user.CompanyId)
  2424. var condition string
  2425. var pars []interface{}
  2426. //活动可见限制
  2427. var sqlExport string
  2428. slicePer := strings.Split(permissionStr, ",")
  2429. var permissionSqlStr string
  2430. for _, v := range slicePer {
  2431. if userType == 1 {
  2432. if v != "研选" {
  2433. permissionSqlStr += "'" + v + "',"
  2434. }
  2435. } else {
  2436. permissionSqlStr += "'" + v + "',"
  2437. }
  2438. }
  2439. permissionSqlStr = strings.TrimRight(permissionSqlStr, ",")
  2440. permissionSqlStr = ` AND art.chart_permission_name IN (` + permissionSqlStr + `)`
  2441. sqlExport = ` AND (art.customer_type_ids LIKE '%` + strconv.Itoa(userType) + `%' `
  2442. if userType == 2 {
  2443. sqlExport += ` OR art.customer_type_ids LIKE '%3%' `
  2444. }
  2445. if (userType == 2 || userType == 3) && strings.Contains(permissionStr, "专家") {
  2446. sqlExport += ` OR art.customer_type_ids LIKE '%4%' `
  2447. }
  2448. sqlExport += `) `
  2449. //主题
  2450. if label != "" {
  2451. condition = ` AND art.label LIKE '%` + label + `%' `
  2452. }
  2453. if whichDay != "" {
  2454. var startDate string
  2455. var endDate string
  2456. if whichDay == "1" {
  2457. startDate = time.Now().Format(utils.FormatDate)
  2458. endDate = startDate
  2459. } else if whichDay == "2" {
  2460. startDate = time.Now().AddDate(0, 0, +1).Format(utils.FormatDate)
  2461. endDate = startDate
  2462. } else {
  2463. startDate = time.Now().Format(utils.FormatDate)
  2464. endDate = time.Now().AddDate(0, 0, +1).Format(utils.FormatDate)
  2465. }
  2466. condition += ` AND art.activity_time >= ` + "'" + startDate + " 00:00:00'"
  2467. condition += ` AND art.activity_time <= ` + "'" + endDate + " 23:59:59'"
  2468. }
  2469. //行业名称
  2470. if len(chartPermissionIds) > 0 {
  2471. condition += ` AND art.chart_permission_id IN (` + chartPermissionIds + `)`
  2472. }
  2473. if activeState != "" {
  2474. condition += ` AND art.active_state IN (` + activeState + `)`
  2475. } else {
  2476. condition += ` AND art.active_state IN (1)`
  2477. }
  2478. if activityTypeId != "" {
  2479. condition += ` AND art.activity_type_id IN (` + activityTypeId + `)`
  2480. }
  2481. condition += ` AND art.publish_status = 1 `
  2482. var conditionOr string
  2483. // 有专家权限的这几种用户,不做行业权限校验
  2484. if (userType == 2 || userType == 3 || userType == 4) && strings.Contains(permissionStr, "专家") {
  2485. conditionOr += ` OR ( art.is_limit_people = 1 AND art.customer_type_ids LIKE '%4%' ` + condition + `) `
  2486. }
  2487. if (userType == 5) && strings.Contains(permissionStr, "专家") {
  2488. conditionOr += ` OR ( art.is_limit_people = 1 AND art.customer_type_ids LIKE '%5%' ` + condition + `) `
  2489. }
  2490. if userType == 1 {
  2491. conditionOr += ` OR ( art.is_limit_people = 0 ` + condition + permissionSqlStr + `) `
  2492. } else {
  2493. conditionOr += ` OR ( art.is_limit_people = 0 ` + condition + `) `
  2494. }
  2495. condition += ` AND art.is_limit_people = 1 ` + permissionSqlStr + sqlExport + conditionOr
  2496. total, err := models.GetActivityCount(condition, pars)
  2497. if err != nil {
  2498. br.Msg = "获取失败"
  2499. br.ErrMsg = "获取失败,Err:" + err.Error()
  2500. return
  2501. }
  2502. if activeState == "2" || activeState == "3" {
  2503. condition += ` ORDER BY art.activity_time DESC `
  2504. } else if activeState == "2,3" {
  2505. condition += ` ORDER BY art.active_state ASC, art.activity_time DESC `
  2506. } else {
  2507. condition += ` ORDER BY art.active_state ASC, art.activity_time ASC `
  2508. }
  2509. list, errList := models.GetActivityListAll(condition, pars, uid, startSize, pageSize)
  2510. if errList != nil {
  2511. br.Msg = "获取失败"
  2512. br.ErrMsg = "获取失败,Err:" + errList.Error()
  2513. return
  2514. }
  2515. var isShow bool
  2516. isShow = services.GetShowSustainable()
  2517. detail, err := models.GetConfigByCode("city_img_url")
  2518. if err != nil {
  2519. br.Msg = "获取数据失败"
  2520. br.ErrMsg = "城市配置信息失败,Err:" + err.Error()
  2521. return
  2522. }
  2523. detailChart, err := models.GetConfigByCode("chart_img_url")
  2524. if err != nil {
  2525. br.Msg = "获取数据失败"
  2526. br.ErrMsg = "行业配置信息失败,Err:" + err.Error()
  2527. return
  2528. }
  2529. addressList := strings.Split(detail.ConfigValue, "{|}")
  2530. mapAddress := make(map[string]string)
  2531. chartList := strings.Split(detailChart.ConfigValue, "{|}")
  2532. mapChart := make(map[string]string)
  2533. var cityName string
  2534. var chartName string
  2535. var imgUrl string
  2536. var imgUrlChart string
  2537. for _, v := range addressList {
  2538. vslice := strings.Split(v, "_")
  2539. cityName = vslice[0]
  2540. imgUrl = vslice[len(vslice)-1]
  2541. mapAddress[cityName] = imgUrl
  2542. }
  2543. for _, v := range chartList {
  2544. vslice := strings.Split(v, "_")
  2545. chartName = vslice[0]
  2546. imgUrlChart = vslice[len(vslice)-1]
  2547. mapChart[chartName] = imgUrlChart
  2548. }
  2549. for k, v := range list {
  2550. if strings.Contains(v.ActivityName, "【") {
  2551. list[k].IsBrackets = 1
  2552. }
  2553. if v.SignupNum > v.LimitPeopleNum {
  2554. list[k].SignupNum = v.LimitPeopleNum
  2555. }
  2556. if isShow && v.ChartPermissionName == "研选" {
  2557. list[k].IsShowSustainable = true
  2558. }
  2559. if v.ChartPermissionName == "研选" && v.ActivityTypeId == 1 {
  2560. list[k].ActivityTypeName = "研选电话会"
  2561. list[k].ImgUrlText = "https://hongze.oss-cn-shanghai.aliyuncs.com/static/images/202112/20211221/bIdfv8t86xrFRpDOeGGHXOmKEuKl.png"
  2562. }
  2563. if v.ActivityType == 0 {
  2564. if mapAddress[v.City] != "" {
  2565. list[k].ImgUrl = mapAddress[v.City]
  2566. } else {
  2567. list[k].ImgUrl = mapAddress["其它"]
  2568. }
  2569. } else {
  2570. if mapChart[v.ChartPermissionName] != "" {
  2571. list[k].ImgUrl = mapChart[v.ChartPermissionName]
  2572. }
  2573. }
  2574. expertTxt, _ := services.GetReportContentTextSub(v.Expert)
  2575. list[k].Expert = expertTxt
  2576. }
  2577. page := paging.GetPaging(currentIndex, pageSize, total)
  2578. resp := new(models.GetCygxActivityListRep)
  2579. resp.Label = label
  2580. if activityTypeId != "" {
  2581. activityTypeIdint, err := strconv.Atoi(activityTypeId)
  2582. if err == nil {
  2583. detail, errDetail := models.GetActivityTypeDetailById(activityTypeIdint)
  2584. if errDetail != nil {
  2585. br.Msg = "获取信息失败"
  2586. br.ErrMsg = "获取信息失败,Err:" + errDetail.Error()
  2587. return
  2588. }
  2589. resp.ImgUrl = detail.OnlineIco
  2590. resp.Label = detail.ActivityTypeName
  2591. }
  2592. }
  2593. resp.List = list
  2594. resp.Paging = page
  2595. br.Ret = 200
  2596. br.Success = true
  2597. br.Msg = "获取成功"
  2598. br.Data = resp
  2599. }
  2600. // @Title 活动类型下的主题列表Pc端
  2601. // @Description 获取活动类型下的主题列表接口Pc端
  2602. // @Param ChartPermissionIds query string false "行业id 多个用 , 隔开"
  2603. // @Param ActivityTypeIds query string false "活动类型id 多个用 , 隔开"
  2604. // @Param ActiveState query string false "活动进行状态 未开始:1、进行中2、已结束3"
  2605. // @Param WhichDay query string false "哪一天 今天:1、明天:2,多个用 , 隔开"
  2606. // @Param IsPower query int false "是否选择有权限行业 ,1是 0 否 默认0"
  2607. // @Success 200 {object} models.ActivityTypeListHomeRespPc
  2608. // @router /labelTypeListPc [get]
  2609. func (this *ActivityCoAntroller) LabelTypeListPc() {
  2610. br := new(models.BaseResponse).Init()
  2611. defer func() {
  2612. this.Data["json"] = br
  2613. this.ServeJSON()
  2614. }()
  2615. user := this.User
  2616. if user == nil {
  2617. br.Msg = "请登录"
  2618. br.ErrMsg = "请登录,SysUser Is Empty"
  2619. return
  2620. }
  2621. pageSize, _ := this.GetInt("PageSize")
  2622. isPower, _ := this.GetInt("IsPower")
  2623. //currentIndex, _ := this.GetInt("CurrentIndex")
  2624. chartPermissionIds := this.GetString("ChartPermissionIds")
  2625. //activityTypeIds := this.GetString("ActivityTypeIds")
  2626. whichDay := this.GetString("WhichDay")
  2627. activeState := this.GetString("ActiveState")
  2628. //入参为 undefined 时的处理
  2629. if chartPermissionIds == "undefined" {
  2630. chartPermissionIds = ""
  2631. }
  2632. if whichDay == "undefined" {
  2633. whichDay = ""
  2634. }
  2635. if activeState == "undefined" || activeState == "" {
  2636. activeState = "1"
  2637. }
  2638. userType, permissionStr, err := services.GetUserType(user.CompanyId)
  2639. if err != nil {
  2640. br.Msg = "获取失败"
  2641. br.ErrMsg = "获取失败,Err:" + err.Error()
  2642. return
  2643. }
  2644. var startSize int
  2645. pageSize = 8
  2646. var sortTime string
  2647. var pars []interface{}
  2648. //活动可见限制
  2649. slicePer := strings.Split(permissionStr, ",")
  2650. var permissionSqlStr string
  2651. var permissionNameStr string
  2652. for _, v := range slicePer {
  2653. if userType == 1 {
  2654. if v != "研选" {
  2655. permissionNameStr += "'" + v + "',"
  2656. }
  2657. } else {
  2658. permissionNameStr += "'" + v + "',"
  2659. }
  2660. }
  2661. permissionNameStr = strings.TrimRight(permissionNameStr, ",")
  2662. list, err := models.GetActivityTypeHomeListPc()
  2663. if err != nil {
  2664. br.Msg = "获取失败"
  2665. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  2666. return
  2667. }
  2668. resp := new(models.ActivityTypeListHomeRespPc)
  2669. for k, v := range list {
  2670. var sqlExport string
  2671. var condition string
  2672. permissionSqlStr = ` AND art.chart_permission_name IN (` + permissionNameStr + `)`
  2673. sqlExport = ` AND (art.customer_type_ids LIKE '%` + strconv.Itoa(userType) + `%' `
  2674. if userType == 2 {
  2675. sqlExport += ` OR art.customer_type_ids LIKE '%3%' `
  2676. }
  2677. if (userType == 2 || userType == 3) && strings.Contains(permissionStr, "专家") {
  2678. sqlExport += ` OR art.customer_type_ids LIKE '%4%' `
  2679. }
  2680. sqlExport += `) `
  2681. condition = ` AND art.publish_status = 1 AND art.label != '' AND art.activity_type_id = ` + strconv.Itoa(v.ActivityTypeId)
  2682. if isPower == 1 {
  2683. condition += permissionSqlStr
  2684. }
  2685. //行业名称
  2686. if len(chartPermissionIds) > 0 {
  2687. condition += ` AND art.chart_permission_id IN (` + chartPermissionIds + `)`
  2688. }
  2689. var conditionOr string
  2690. if whichDay != "" {
  2691. var startDate string
  2692. var endDate string
  2693. if whichDay == "1" {
  2694. startDate = time.Now().Format(utils.FormatDate)
  2695. endDate = startDate
  2696. } else if whichDay == "2" {
  2697. startDate = time.Now().AddDate(0, 0, +1).Format(utils.FormatDate)
  2698. endDate = startDate
  2699. } else {
  2700. startDate = time.Now().Format(utils.FormatDate)
  2701. endDate = time.Now().AddDate(0, 0, +1).Format(utils.FormatDate)
  2702. }
  2703. condition += ` AND art.activity_time >= ` + "'" + startDate + " 00:00:00'"
  2704. condition += ` AND art.activity_time <= ` + "'" + endDate + " 23:59:59'"
  2705. }
  2706. if activeState != "" {
  2707. condition += ` AND art.active_state IN (` + activeState + `)`
  2708. } else {
  2709. condition += ` AND art.active_state IN (1)`
  2710. }
  2711. if (userType == 2 || userType == 3 || userType == 4) && strings.Contains(permissionStr, "专家") {
  2712. conditionOr += ` OR ( art.is_limit_people = 1 AND art.customer_type_ids LIKE '%4%' ` + condition + `) `
  2713. }
  2714. if (userType == 5) && strings.Contains(permissionStr, "专家") {
  2715. conditionOr += ` OR ( art.is_limit_people = 1 AND art.customer_type_ids LIKE '%5%' ` + condition + `) `
  2716. }
  2717. if userType == 1 {
  2718. conditionOr += ` OR ( art.is_limit_people = 0 ` + condition + permissionSqlStr + `) `
  2719. } else {
  2720. conditionOr += ` OR ( art.is_limit_people = 0 ` + condition + `) `
  2721. }
  2722. condition += `AND art.is_limit_people = 1 ` + permissionSqlStr + sqlExport + conditionOr
  2723. sortTime = ` mintimesort ASC `
  2724. labelList, err := models.GetActivityLabelListAll(condition, sortTime, pars, startSize, pageSize)
  2725. if err != nil {
  2726. br.Msg = "获取失败"
  2727. br.ErrMsg = "获取失败,Err:" + err.Error()
  2728. return
  2729. }
  2730. //标签字段关联的产业与标签处理
  2731. for k2, v2 := range labelList {
  2732. labelList[k2].KeyWord = services.LabelStr(v2.KeyWord)
  2733. }
  2734. list[k].List = labelList
  2735. }
  2736. //记录用户搜索的筛选条件
  2737. item := new(models.CygxActivitySearchHistory)
  2738. item.UserId = user.UserId
  2739. item.Mobile = user.Mobile
  2740. item.CompanyId = user.CompanyId
  2741. item.CompanyName = user.CompanyName
  2742. item.CreateTime = time.Now()
  2743. item.ChartPermissionIds = chartPermissionIds
  2744. item.IsPower = isPower
  2745. item.WhichDay = whichDay
  2746. go models.AddCygxActivitySearchHistory(item)
  2747. resp.List = list
  2748. br.Ret = 200
  2749. br.Success = true
  2750. br.Msg = "获取成功"
  2751. br.Data = resp
  2752. }
  2753. // @Title 校验活动带问是否有权限
  2754. // @Description 校验活动带问是否有权限接口
  2755. // @Param request body models.ActivityIdRep true "type json string"
  2756. // @Success Ret=200 {object} models.SignupStatus
  2757. // @router /checkAsk [post]
  2758. func (this *ActivityCoAntroller) CheckAsk() {
  2759. br := new(models.BaseResponse).Init()
  2760. defer func() {
  2761. this.Data["json"] = br
  2762. this.ServeJSON()
  2763. }()
  2764. user := this.User
  2765. if user == nil {
  2766. br.Msg = "请登录"
  2767. br.ErrMsg = "请登录,用户信息为空"
  2768. br.Ret = 408
  2769. return
  2770. }
  2771. uid := user.UserId
  2772. signupStatus := "Success"
  2773. var req models.ActivityIdRep
  2774. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  2775. if err != nil {
  2776. br.Msg = "参数解析异常!"
  2777. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  2778. return
  2779. }
  2780. activityId := req.ActivityId
  2781. activityInfo, errInfo := models.GetAddActivityInfoById(activityId)
  2782. if activityInfo == nil {
  2783. br.Msg = "操作失败"
  2784. br.ErrMsg = "活动ID错误,不存在activityId:" + strconv.Itoa(activityId)
  2785. return
  2786. }
  2787. if errInfo != nil {
  2788. br.Msg = "操作失败"
  2789. br.ErrMsg = "操作失败,Err:" + errInfo.Error()
  2790. return
  2791. }
  2792. //判断是否已经申请过
  2793. applyCount, err := models.GetApplyRecordCount(uid)
  2794. if err != nil && err.Error() != utils.ErrNoRow() {
  2795. br.Msg = "获取信息失败"
  2796. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  2797. return
  2798. }
  2799. //获取销售信息
  2800. sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 1)
  2801. if err != nil && err.Error() != utils.ErrNoRow() {
  2802. br.Msg = "申请失败"
  2803. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  2804. return
  2805. }
  2806. resp := new(models.SignupStatus)
  2807. hasPermission := 0
  2808. var companyDetailStatus string
  2809. if user.CompanyId <= 1 {
  2810. companyDetailStatus = ""
  2811. } else {
  2812. companyPermission, err := models.GetCompanyPermission(user.CompanyId)
  2813. if err != nil {
  2814. br.Msg = "获取信息失败"
  2815. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  2816. return
  2817. }
  2818. if companyPermission == "" {
  2819. if applyCount > 0 {
  2820. hasPermission = 4
  2821. } else {
  2822. if sellerItem != nil {
  2823. hasPermission = 5
  2824. } else {
  2825. //获取权益销售信息 如果是FICC的客户类型,则默认他申请过
  2826. sellerItemQy, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  2827. if err != nil && err.Error() != utils.ErrNoRow() {
  2828. br.Msg = "获取信息失败"
  2829. br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
  2830. return
  2831. }
  2832. if sellerItemQy != nil {
  2833. hasPermission = 2
  2834. resp.SellerMobile = sellerItemQy.Mobile
  2835. resp.SellerName = sellerItemQy.RealName
  2836. } else {
  2837. hasPermission = 3
  2838. }
  2839. }
  2840. }
  2841. resp.ActivityId = activityId
  2842. resp.HasPermission = hasPermission
  2843. resp.OperationMode = "Apply"
  2844. resp.PopupMsg = "您暂无权限参加此活动,若想参加可以申请开通对应的试用权限"
  2845. br.Ret = 200
  2846. br.Success = true
  2847. br.Msg = "获取成功"
  2848. br.Data = resp
  2849. return
  2850. }
  2851. companyDetail, err := models.GetCompanyDetailById(user.CompanyId)
  2852. if err != nil {
  2853. br.Msg = "获取信息失败!"
  2854. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  2855. return
  2856. }
  2857. if companyDetail == nil {
  2858. br.Msg = "获取信息失败!"
  2859. br.ErrMsg = "客户不存在,uid:" + strconv.Itoa(user.UserId) + "CompanyId:" + strconv.Itoa(user.CompanyId)
  2860. return
  2861. }
  2862. companyDetailStatus = companyDetail.Status
  2863. }
  2864. var userType int
  2865. var permissionStr string
  2866. userType, permissionStr, err = services.GetUserType(user.CompanyId)
  2867. if err != nil {
  2868. br.Msg = "获取信息失败!"
  2869. br.ErrMsg = "获取失败,Err:" + err.Error()
  2870. return
  2871. }
  2872. if userType == 1 && activityInfo.ChartPermissionName == "研选" {
  2873. br.Msg = "您暂无查看该活动权限"
  2874. br.ErrMsg = "被分享客户不可见,永续客户无法查看研选行业"
  2875. return
  2876. }
  2877. if user.CompanyId > 1 {
  2878. companyItem, err := models.GetCompanyDetailById(user.CompanyId)
  2879. //冻结客户
  2880. if err != nil {
  2881. if err.Error() == utils.ErrNoRow() {
  2882. if applyCount > 0 {
  2883. hasPermission = 4
  2884. } else {
  2885. if sellerItem != nil {
  2886. hasPermission = 5
  2887. } else {
  2888. hasPermission = 3
  2889. }
  2890. }
  2891. resp.ActivityId = activityId
  2892. resp.HasPermission = hasPermission
  2893. resp.OperationMode = "Apply"
  2894. resp.PopupMsg = "您暂无权限参加此活动,若想参加可以申请开通对应的试用权限"
  2895. br.Ret = 200
  2896. br.Success = true
  2897. br.Msg = "获取成功"
  2898. br.Data = resp
  2899. return
  2900. } else {
  2901. br.Msg = "获取信息失败"
  2902. br.ErrMsg = "获取客户公司信息失败,Err:" + err.Error()
  2903. return
  2904. }
  2905. }
  2906. havePower, err := services.GetHavePower(activityInfo, permissionStr, companyDetailStatus, userType)
  2907. if err != nil {
  2908. br.Msg = "获取信息失败!"
  2909. br.ErrMsg = "获取失败,Err:" + err.Error()
  2910. return
  2911. }
  2912. if havePower {
  2913. hasPermission = 1
  2914. signupStatus = "Success"
  2915. resp.HaqveJurisdiction = true
  2916. } else {
  2917. hasPermission = 2
  2918. resp.SellerMobile = companyItem.Mobile
  2919. resp.SellerName = companyItem.SellerName
  2920. resp.MsgType = "Type"
  2921. resp.OperationMode = "Call"
  2922. if permissionStr == "专家" {
  2923. resp.PopupMsg = "您暂无权限参加【" + activityInfo.ActivityTypeName + "】类型活动,若想参加请联系对口销售--" + companyItem.SellerName + ":" + companyItem.Mobile
  2924. resp.MsgType = "Type"
  2925. } else {
  2926. resp.PopupMsg = "您暂无权限参加【" + activityInfo.ChartPermissionName + "】行业活动,若想参加请联系对口销售--" + companyItem.SellerName + ":" + companyItem.Mobile
  2927. resp.MsgType = "Industry"
  2928. }
  2929. }
  2930. } else { //潜在客户
  2931. if applyCount > 0 {
  2932. hasPermission = 4
  2933. } else {
  2934. if sellerItem != nil {
  2935. hasPermission = 5
  2936. } else {
  2937. hasPermission = 3
  2938. }
  2939. }
  2940. resp.OperationMode = "Apply"
  2941. resp.PopupMsg = "您暂无权限参加此活动,若想参加可以申请开通对应的试用权限"
  2942. }
  2943. resp.HasPermission = hasPermission
  2944. resp.SignupStatus = signupStatus
  2945. resp.ActivityId = activityId
  2946. br.Ret = 200
  2947. br.Success = true
  2948. br.Data = resp
  2949. }