activity.go 62 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "github.com/medivhzhan/weapp/v2"
  6. "github.com/tealeg/xlsx"
  7. "hongze/hongze_cygx/models"
  8. "hongze/hongze_cygx/services"
  9. "hongze/hongze_cygx/utils"
  10. "os"
  11. "path/filepath"
  12. "rdluck_tools/paging"
  13. "strconv"
  14. "strings"
  15. "time"
  16. )
  17. //活动
  18. type ActivityCoAntroller struct {
  19. BaseAuthController
  20. }
  21. type ActivityABaseController struct {
  22. BaseCommonController
  23. }
  24. // @Title 活动类型列表
  25. // @Description活动类型列表接口
  26. // @Success 200 {object} models.ActivityTypeListResp
  27. // @router /activityTypelist [get]
  28. func (this *ActivityCoAntroller) List() {
  29. br := new(models.BaseResponse).Init()
  30. defer func() {
  31. this.Data["json"] = br
  32. this.ServeJSON()
  33. }()
  34. user := this.User
  35. if user == nil {
  36. br.Msg = "请登录"
  37. br.ErrMsg = "请登录,SysUser Is Empty"
  38. br.Ret = 408
  39. return
  40. }
  41. resp := new(models.ActivityTypeListResp)
  42. list, err := models.GetActivityTypeList()
  43. if err != nil {
  44. br.Msg = "获取失败"
  45. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  46. return
  47. }
  48. resp.List = list
  49. br.Ret = 200
  50. br.Success = true
  51. br.Msg = "获取成功"
  52. br.Data = resp
  53. }
  54. // @Title 活动列表
  55. // @Description 获取活动列表接口
  56. // @Param PageSize query int true "每页数据条数"
  57. // @Param CurrentIndex query int true "当前页页码,从1开始"
  58. // @Param ChartPermissionIds query string false "行业id 多个用 , 隔开"
  59. // @Param ActivityTypeIds query string false "活动类型id 多个用 , 隔开"
  60. // @Param KeyWord query string false "搜索关键词 多个用 , 隔开"
  61. // @Param ActiveState query string false "活动进行状态 未开始:1、进行中2、已结束3"
  62. // @Param WhichDay query string false "哪一天 今天:1、明天:2,多个用 , 隔开"
  63. // @Param IsShowJurisdiction query int false "是否仅展示有权限的,1是,2否 默认为零"
  64. // @Param Label query string false "搜索主题 多个用 , 隔开"
  65. // @Success 200 {object} models.GetCygxActivityListRep
  66. // @router /list [get]
  67. func (this *ActivityCoAntroller) ActivityList() {
  68. br := new(models.BaseResponse).Init()
  69. defer func() {
  70. this.Data["json"] = br
  71. this.ServeJSON()
  72. }()
  73. user := this.User
  74. if user == nil {
  75. br.Msg = "请登录"
  76. br.ErrMsg = "请登录,SysUser Is Empty"
  77. return
  78. }
  79. uid := user.UserId
  80. pageSize, _ := this.GetInt("PageSize")
  81. currentIndex, _ := this.GetInt("CurrentIndex")
  82. chartPermissionIds := this.GetString("ChartPermissionIds")
  83. activityTypeIds := this.GetString("ActivityTypeIds")
  84. whichDay := this.GetString("WhichDay")
  85. isShowJurisdiction, _ := this.GetInt("IsShowJurisdiction")
  86. keyWord := this.GetString("KeyWord")
  87. keyWordSearch := this.GetString("KeyWord")
  88. activeState := this.GetString("ActiveState")
  89. label := this.GetString("Label")
  90. //入参为 undefined 时的处理
  91. if chartPermissionIds == "undefined" {
  92. chartPermissionIds = ""
  93. }
  94. if activityTypeIds == "undefined" {
  95. activityTypeIds = ""
  96. }
  97. if whichDay == "undefined" {
  98. whichDay = ""
  99. }
  100. if activeState == "undefined" {
  101. activeState = ""
  102. }
  103. if label == "undefined" {
  104. label = ""
  105. }
  106. //更新用户的搜索信息
  107. itemSearch := new(models.CygxActivityUserSearchContent)
  108. itemSearch.UserId = uid
  109. itemSearch.CreateTime = time.Now()
  110. itemSearch.Mobile = user.Mobile
  111. itemSearch.Email = user.Email
  112. itemSearch.CompanyId = user.CompanyId
  113. itemSearch.CompanyName = user.CompanyName
  114. itemSearch.ModifyTime = time.Now()
  115. itemSearch.ChartPermissionids = chartPermissionIds
  116. itemSearch.ActivityTypeids = activityTypeIds
  117. itemSearch.ActiveState = activeState
  118. itemSearch.IsShowJurisdiction = isShowJurisdiction
  119. //并发缓存校验
  120. cacheKey := fmt.Sprint("xygx:activity_user_search:add:", uid)
  121. ttlTime := utils.Rc.GetRedisTTL(cacheKey)
  122. _, errSearch := models.AddUserSearchContent(itemSearch, ttlTime)
  123. if errSearch != nil {
  124. br.Msg = "操作失败"
  125. br.ErrMsg = "操作失败,Err:" + errSearch.Error()
  126. return
  127. }
  128. utils.Rc.SetNX(cacheKey, user.Mobile, time.Second*10)
  129. userType, permissionStr, err := services.GetUserType(user.CompanyId)
  130. if isShowJurisdiction == 1 && chartPermissionIds == "" && userType == 4 {
  131. activityTypeIds = "1,3"
  132. }
  133. var startSize int
  134. if pageSize <= 0 {
  135. pageSize = utils.PageSize20
  136. }
  137. if currentIndex <= 0 {
  138. currentIndex = 1
  139. }
  140. startSize = utils.StartIndex(currentIndex, pageSize)
  141. var condition string
  142. var pars []interface{}
  143. //活动可见限制
  144. var sqlExport string
  145. slicePer := strings.Split(permissionStr, ",")
  146. var permissionSqlStr string
  147. for _, v := range slicePer {
  148. if userType == 1 {
  149. if v != "研选" {
  150. permissionSqlStr += "'" + v + "',"
  151. }
  152. } else {
  153. permissionSqlStr += "'" + v + "',"
  154. }
  155. }
  156. permissionSqlStr = strings.TrimRight(permissionSqlStr, ",")
  157. permissionSqlStr = ` AND art.chart_permission_name IN (` + permissionSqlStr + `)`
  158. sqlExport = ` AND (art.customer_type_ids LIKE '%` + strconv.Itoa(userType) + `%' `
  159. if userType == 2 {
  160. sqlExport += ` OR art.customer_type_ids LIKE '%3%' `
  161. }
  162. if (userType == 2 || userType == 3) && strings.Contains(permissionStr, "专家") {
  163. sqlExport += ` OR art.customer_type_ids LIKE '%4%' `
  164. }
  165. sqlExport += `) `
  166. if keyWord != "" {
  167. var mirrorword string
  168. var mirrorwordSql string
  169. slicemirrorword := strings.Split(keyWord, ",")
  170. for _, v := range slicemirrorword {
  171. mirrorwordSql += "'" + v + "'" + ","
  172. }
  173. mirrorwordSql = strings.TrimRight(mirrorwordSql, ",")
  174. total, err := models.GetActivityMirrorWordCount(mirrorwordSql)
  175. if err != nil {
  176. br.Msg = "获取失败"
  177. br.ErrMsg = "获取失败,Err:" + err.Error()
  178. return
  179. }
  180. if total > 0 {
  181. mirrorword, err = models.GetMirrorWord(mirrorwordSql)
  182. if err != nil {
  183. br.Msg = "获取信息失败"
  184. br.ErrMsg = "关系词映射获取失败,Err:" + err.Error()
  185. return
  186. }
  187. }
  188. keyWord = keyWord + "," + mirrorword
  189. slicekeyWord := strings.Split(keyWord, ",")
  190. var sqlKeyOr string
  191. if len(slicekeyWord) >= 2 {
  192. for _, v := range slicekeyWord {
  193. if v != "" {
  194. sqlKeyOr += ` OR art.activity_name LIKE '%` + v + `%' `
  195. }
  196. }
  197. condition += ` AND (art.activity_name LIKE '%` + keyWord + `%' ` + sqlKeyOr + ` )`
  198. } else {
  199. condition += ` AND (art.activity_name LIKE '%` + keyWord + `%' )`
  200. }
  201. }
  202. //主题
  203. if label != "" {
  204. sliceLabel := strings.Split(label, ",")
  205. var labelSqlStr string
  206. for _, v := range sliceLabel {
  207. labelSqlStr += "'" + v + "',"
  208. }
  209. labelSqlStr = strings.TrimRight(labelSqlStr, ",")
  210. condition = ` AND art.label IN (` + labelSqlStr + `)`
  211. }
  212. //行业名称
  213. if len(chartPermissionIds) > 0 {
  214. condition += ` AND art.chart_permission_id IN (` + chartPermissionIds + `)`
  215. }
  216. if activityTypeIds != "" {
  217. condition += ` AND art.activity_type_id IN (` + activityTypeIds + `)`
  218. }
  219. if whichDay != "" {
  220. var startDate string
  221. var endDate string
  222. if whichDay == "1" {
  223. startDate = time.Now().Format(utils.FormatDate)
  224. endDate = startDate
  225. } else if whichDay == "2" {
  226. startDate = time.Now().AddDate(0, 0, +1).Format(utils.FormatDate)
  227. endDate = startDate
  228. } else {
  229. startDate = time.Now().Format(utils.FormatDate)
  230. endDate = time.Now().AddDate(0, 0, +1).Format(utils.FormatDate)
  231. }
  232. condition += ` AND art.activity_time >= ` + "'" + startDate + " 00:00:00'"
  233. condition += ` AND art.activity_time <= ` + "'" + endDate + " 23:59:59'"
  234. }
  235. if activeState != "" {
  236. condition += ` AND art.active_state IN (` + activeState + `)`
  237. }
  238. condition += ` AND art.publish_status = 1 `
  239. var conditionOr string
  240. // 有专家权限的这几种用户,不做行业权限校验
  241. if (userType == 2 || userType == 3 || userType == 4) && strings.Contains(permissionStr, "专家") {
  242. conditionOr += ` OR ( art.is_limit_people = 1 AND art.customer_type_ids LIKE '%4%' ` + condition + `) `
  243. }
  244. if (userType == 5) && strings.Contains(permissionStr, "专家") {
  245. conditionOr += ` OR ( art.is_limit_people = 1 AND art.customer_type_ids LIKE '%5%' ` + condition + `) `
  246. }
  247. if userType == 1 {
  248. conditionOr += ` OR ( art.is_limit_people = 0 ` + condition + permissionSqlStr + `) `
  249. } else {
  250. conditionOr += ` OR ( art.is_limit_people = 0 ` + condition + `) `
  251. }
  252. condition += ` AND art.is_limit_people = 1 ` + permissionSqlStr + sqlExport + conditionOr
  253. total, err := models.GetActivityCount(condition, pars)
  254. if err != nil {
  255. br.Msg = "获取失败"
  256. br.ErrMsg = "获取失败,Err:" + err.Error()
  257. return
  258. }
  259. if activeState == "2" || activeState == "3" {
  260. condition += ` ORDER BY art.activity_time DESC `
  261. } else {
  262. condition += ` ORDER BY art.active_state ASC, art.activity_time ASC `
  263. }
  264. list, errList := models.GetActivityListAll(condition, pars, uid, startSize, pageSize)
  265. if errList != nil {
  266. br.Msg = "获取失败"
  267. br.ErrMsg = "获取失败,Err:" + errList.Error()
  268. return
  269. }
  270. for k, v := range list {
  271. if strings.Contains(v.ActivityName, "【") {
  272. list[k].IsBrackets = 1
  273. }
  274. if v.SignupNum > v.LimitPeopleNum {
  275. list[k].SignupNum = v.LimitPeopleNum
  276. }
  277. if services.GetShowSustainable() && v.ChartPermissionName == "研选" {
  278. list[k].IsShowSustainable = true
  279. }
  280. }
  281. if keyWordSearch != "" {
  282. keyWordItem := new(models.CygxUserSearchKeyWord)
  283. keyWordItem.UserId = user.UserId
  284. keyWordItem.KeyWord = keyWordSearch
  285. keyWordItem.PageType = "ActivitSearch"
  286. keyWordItem.CreateTime = time.Now()
  287. go models.AddUserSearchKeyWord(keyWordItem)
  288. }
  289. page := paging.GetPaging(currentIndex, pageSize, total)
  290. resp := new(models.GetCygxActivityListRep)
  291. resp.List = list
  292. resp.Paging = page
  293. br.Ret = 200
  294. br.Success = true
  295. br.Msg = "获取成功"
  296. br.Data = resp
  297. }
  298. // @Title 我的日程
  299. // @Description 我的日程列表接口
  300. // @Param PageSize query int true "每页数据条数"
  301. // @Param CurrentIndex query int true "当前页页码,从1开始"
  302. // @Success 200 {object} models.GetCygxActivityListRep
  303. // @router /scheduleList [get]
  304. func (this *ActivityCoAntroller) ScheduleList() {
  305. br := new(models.BaseResponse).Init()
  306. defer func() {
  307. this.Data["json"] = br
  308. this.ServeJSON()
  309. }()
  310. user := this.User
  311. if user == nil {
  312. br.Msg = "请登录"
  313. br.ErrMsg = "请登录,SysUser Is Empty"
  314. return
  315. }
  316. uid := user.UserId
  317. pageSize, _ := this.GetInt("PageSize")
  318. currentIndex, _ := this.GetInt("CurrentIndex")
  319. var startSize int
  320. if pageSize <= 0 {
  321. pageSize = utils.PageSize20
  322. }
  323. if currentIndex <= 0 {
  324. currentIndex = 1
  325. }
  326. startSize = utils.StartIndex(currentIndex, pageSize)
  327. var condition string
  328. var conditionCount string
  329. var pars []interface{}
  330. condition += ` AND art.publish_status = 1 `
  331. total, err := models.GetScheduleCount(conditionCount, uid)
  332. page := paging.GetPaging(currentIndex, pageSize, total)
  333. if err != nil {
  334. br.Msg = "获取失败"
  335. br.ErrMsg = "获取失败,Err:" + err.Error()
  336. return
  337. }
  338. conditionCount = ` AND art.active_state = 2 `
  339. totalCount, err := models.GetScheduleCount(conditionCount, uid) //获取正在进行中的活动数量
  340. if err != nil {
  341. br.Msg = "获取失败"
  342. br.ErrMsg = "获取失败,Err:" + err.Error()
  343. return
  344. }
  345. var list []*models.CygxActivityList
  346. fmt.Println(totalCount)
  347. //全部都是进行中的活动
  348. if totalCount > currentIndex*pageSize {
  349. condition += ` AND art.active_state IN(2) `
  350. listHave, errList := models.GetScheduleList(condition, pars, uid, startSize, pageSize)
  351. list = listHave
  352. if errList != nil {
  353. br.Msg = "获取失败"
  354. br.ErrMsg = "获取失败,Err:" + errList.Error()
  355. return
  356. }
  357. fmt.Println("22222")
  358. } else if totalCount > currentIndex-1*pageSize && totalCount < currentIndex*pageSize { //部分是进行中的活动
  359. condition = ` AND art.publish_status = 1 AND art.active_state IN(2) `
  360. listHave, errList := models.GetScheduleList(condition, pars, uid, startSize, pageSize)
  361. list = listHave
  362. if errList != nil {
  363. br.Msg = "获取失败"
  364. br.ErrMsg = "获取失败,Err:" + errList.Error()
  365. return
  366. }
  367. fmt.Println("33333")
  368. pageSize = pageSize - len(listHave)
  369. condition = ` AND art.publish_status = 1 AND art.active_state IN(1,3) `
  370. listOther, errList := models.GetScheduleList(condition, pars, uid, startSize, pageSize)
  371. if errList != nil {
  372. br.Msg = "获取失败"
  373. br.ErrMsg = "获取失败,Err:" + errList.Error()
  374. return
  375. }
  376. fmt.Println("长度", len(listOther))
  377. if len(listOther) > 0 {
  378. for _, v := range listOther {
  379. list = append(list, v)
  380. }
  381. }
  382. } else {
  383. condition += ` AND art.active_state IN(1,3)` //全部都不是进行中的活动
  384. listOther, errList := models.GetScheduleList(condition, pars, uid, startSize, pageSize)
  385. list = listOther
  386. if errList != nil {
  387. br.Msg = "获取失败"
  388. br.ErrMsg = "获取失败,Err:" + errList.Error()
  389. return
  390. }
  391. }
  392. for k, v := range list {
  393. if strings.Contains(v.ActivityName, "【") {
  394. list[k].IsBrackets = 1
  395. }
  396. if v.SignupNum > v.LimitPeopleNum {
  397. list[k].SignupNum = v.LimitPeopleNum
  398. }
  399. //是否展示限免标签
  400. if services.GetShowSustainable() && v.ChartPermissionName == "研选" {
  401. list[k].IsShowSustainable = true
  402. }
  403. }
  404. resp := new(models.GetCygxActivityListRep)
  405. resp.List = list
  406. resp.Paging = page
  407. br.Ret = 200
  408. br.Success = true
  409. br.Msg = "获取成功"
  410. br.Data = resp
  411. }
  412. // @Title 活动详情
  413. // @Description 获取活动详情接口
  414. // @Param ActivityId query int true "活动ID"
  415. // @Success Ret=200 {object} models.CygxActivityResp
  416. // @router /detail [get]
  417. func (this *ActivityCoAntroller) Detail() {
  418. br := new(models.BaseResponse).Init()
  419. defer func() {
  420. this.Data["json"] = br
  421. this.ServeJSON()
  422. }()
  423. user := this.User
  424. if user == nil {
  425. br.Msg = "请登录"
  426. br.ErrMsg = "请登录,用户信息为空"
  427. br.Ret = 408
  428. return
  429. }
  430. uid := user.UserId
  431. activityId, _ := this.GetInt("ActivityId")
  432. if activityId < 1 {
  433. br.Msg = "请输入活动ID"
  434. return
  435. }
  436. resp := new(models.CygxActivityResp)
  437. hasPermission := 0
  438. var companyDetailStatus string
  439. activityInfo, err := models.GetAddActivityInfoByIdShow(uid, activityId)
  440. if err != nil && err.Error() != utils.ErrNoRow() {
  441. br.Msg = "获取信息失败"
  442. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  443. return
  444. }
  445. if activityInfo == nil {
  446. br.Msg = "活动不存在"
  447. br.ErrMsg = "活动ID错误,Err:" + "activityId:" + strconv.Itoa(activityId)
  448. return
  449. }
  450. applyCount, err := models.GetApplyRecordCount(uid)
  451. if err != nil && err.Error() != utils.ErrNoRow() {
  452. br.Msg = "获取信息失败"
  453. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  454. return
  455. }
  456. if user.CompanyId <= 1 {
  457. companyDetailStatus = ""
  458. } else {
  459. companyPermission, err := models.GetCompanyPermission(user.CompanyId)
  460. if err != nil {
  461. br.Msg = "获取信息失败"
  462. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  463. return
  464. }
  465. if companyPermission == "" {
  466. if applyCount > 0 {
  467. hasPermission = 4
  468. } else {
  469. hasPermission = 3
  470. }
  471. resp.HasPermission = hasPermission
  472. resp.OperationMode = "Apply"
  473. resp.PopupMsg = "您暂无权限参加 【" + activityInfo.ChartPermissionName + "】行业活动,若想参加可以申请开通哦"
  474. br.Ret = 200
  475. br.Success = true
  476. br.Msg = "获取成功"
  477. br.Data = resp
  478. return
  479. }
  480. companyDetail, err := models.GetCompanyDetailById(user.CompanyId)
  481. if err != nil {
  482. br.Msg = "获取信息失败!"
  483. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  484. return
  485. }
  486. if companyDetail == nil {
  487. br.Msg = "获取信息失败!"
  488. br.ErrMsg = "客户不存在,uid:" + strconv.Itoa(user.UserId) + "CompanyId:" + strconv.Itoa(user.CompanyId)
  489. return
  490. }
  491. companyDetailStatus = companyDetail.Status
  492. }
  493. userType, permissionStr, err := services.GetUserType(user.CompanyId)
  494. if err != nil {
  495. br.Msg = "获取信息失败"
  496. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  497. return
  498. }
  499. if activityInfo.IsLimitPeople > 0 {
  500. noPower, err := services.GetShareNoPowe(activityInfo, permissionStr, userType)
  501. if err != nil {
  502. br.Msg = "获取信息失败"
  503. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  504. return
  505. }
  506. if noPower {
  507. br.Msg = "您暂无查看该活动权限"
  508. br.ErrMsg = "被分享客户不可见,获取信息失败"
  509. return
  510. }
  511. }
  512. if userType == 1 && activityInfo.ChartPermissionName == "研选" {
  513. br.Msg = "您暂无查看该活动权限"
  514. br.ErrMsg = "被分享客户不可见,永续客户无法查看研选行业"
  515. return
  516. }
  517. detail, errDetail := models.GetActivityTypeDetailById(activityInfo.ActivityTypeId)
  518. if errDetail != nil {
  519. br.Msg = "获取信息失败"
  520. br.ErrMsg = "获取信息失败,Err:" + errDetail.Error()
  521. return
  522. }
  523. if activityInfo.IsSignup > 0 {
  524. detail, errDetail := models.GetActivitySignupDetail(activityId, uid)
  525. if errDetail != nil {
  526. br.Msg = "获取信息失败"
  527. br.ErrMsg = "获取信息失败,Err:" + errDetail.Error()
  528. return
  529. }
  530. activityInfo.SignupType = detail.SignupType
  531. }
  532. activityInfo.ShowType = detail.ShowType
  533. //判断是否已经申请过
  534. if user.CompanyId > 1 {
  535. permissionStr, err := models.GetCompanyPermission(user.CompanyId)
  536. if err != nil {
  537. br.Msg = "获取信息失败"
  538. br.ErrMsg = "获取客户权限信息失败,Err:" + err.Error()
  539. return
  540. }
  541. companyItem, err := models.GetCompanyDetailById(user.CompanyId)
  542. //冻结客户
  543. if err != nil {
  544. if err.Error() == utils.ErrNoRow() {
  545. resp.HasPermission = 4
  546. resp.OperationMode = "Apply"
  547. resp.PopupMsg = "您暂无权限参加 【" + activityInfo.ChartPermissionName + "】行业活动"
  548. br.Ret = 200
  549. br.Success = true
  550. br.Msg = "获取成功"
  551. br.Data = resp
  552. return
  553. } else {
  554. br.Msg = "获取信息失败"
  555. br.ErrMsg = "获取客户公司信息失败,Err:" + err.Error()
  556. return
  557. }
  558. }
  559. havePower, err := services.GetHavePower(activityInfo, permissionStr, companyDetailStatus, userType)
  560. if havePower {
  561. hasPermission = 1
  562. resp.HaqveJurisdiction = true
  563. } else {
  564. if permissionStr == "专家" {
  565. resp.PopupMsg = "您暂无权限参加【" + activityInfo.ActivityTypeName + "】类型活动"
  566. resp.MsgType = "Type"
  567. } else {
  568. resp.PopupMsg = "您暂无权限参加【" + activityInfo.ChartPermissionName + "】行业活动"
  569. resp.MsgType = "Industry"
  570. }
  571. resp.SellerMobile = companyItem.Mobile
  572. resp.SellerName = companyItem.SellerName
  573. resp.OperationMode = "Call"
  574. hasPermission = 2
  575. }
  576. } else { //潜在客户
  577. if applyCount > 0 {
  578. hasPermission = 4
  579. } else {
  580. hasPermission = 3
  581. }
  582. resp.OperationMode = "Apply"
  583. resp.PopupMsg = "您暂无权限参加 【" + activityInfo.ChartPermissionName + "】行业活动,若想参加可以申请开通哦"
  584. }
  585. if hasPermission == 1 {
  586. //是否展示限免标签
  587. if services.GetShowSustainable() && activityInfo.ChartPermissionName == "研选" {
  588. activityInfo.IsShowSustainable = true
  589. }
  590. configCode := "description_of_research"
  591. detail, err := models.GetConfigByCode(configCode)
  592. if err != nil {
  593. br.Msg = "获取数据失败"
  594. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  595. return
  596. }
  597. activityInfo.Description = detail.ConfigValue
  598. if activityInfo.SignupNum > activityInfo.LimitPeopleNum {
  599. activityInfo.SignupNum = activityInfo.LimitPeopleNum
  600. }
  601. if activityInfo.ChartPermissionNames != "" {
  602. activityInfo.ChartPermissionName = activityInfo.ChartPermissionNames
  603. }
  604. resp.Detail = activityInfo
  605. }
  606. resp.HasPermission = hasPermission
  607. br.Ret = 200
  608. br.Success = true
  609. br.Msg = "获取成功"
  610. br.Data = resp
  611. }
  612. // @Title 活动报名
  613. // @Description 活动报名接口
  614. // @Param request body models.ActivitySingnupRep true "type json string"
  615. // @Success Ret=200 {object} models.SignupStatus
  616. // @router /signup/add [post]
  617. func (this *ActivityCoAntroller) SignupAdd() {
  618. br := new(models.BaseResponse).Init()
  619. defer func() {
  620. this.Data["json"] = br
  621. this.ServeJSON()
  622. }()
  623. user := this.User
  624. if user == nil {
  625. br.Msg = "请登录"
  626. br.ErrMsg = "请登录,用户信息为空"
  627. br.Ret = 408
  628. return
  629. }
  630. uid := user.UserId
  631. signupStatus := ""
  632. var req models.ActivitySingnupRep
  633. resp := new(models.SignupStatus)
  634. var total int
  635. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  636. if err != nil {
  637. br.Msg = "参数解析异常!"
  638. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  639. return
  640. }
  641. activityId := req.ActivityId
  642. signupType := req.SignupType
  643. hasPermission := 0
  644. if signupType == 1 && user.Mobile == "" && user.OutboundMobile == "" {
  645. resp.GoBindEmail = true
  646. }
  647. //判断是否已经申请过
  648. applyCount, err := models.GetApplyRecordCount(uid)
  649. if err != nil && err.Error() != utils.ErrNoRow() {
  650. br.Msg = "获取信息失败"
  651. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  652. return
  653. }
  654. activityInfo, errInfo := models.GetAddActivityInfoById(activityId)
  655. if activityInfo == nil {
  656. br.Msg = "操作失败"
  657. br.ErrMsg = "活动ID错误,不存在activityId:" + strconv.Itoa(activityId)
  658. return
  659. }
  660. if errInfo != nil {
  661. br.Msg = "操作失败"
  662. br.ErrMsg = "操作失败,Err:" + errInfo.Error()
  663. return
  664. }
  665. //SignupStatus "报名状态:人数已满:FullStarffed、单机构超过两人:TwoPeople、爽约次数过多:BreakPromise、超时:Overtime 、成功:Success"`
  666. //HasPermission "1:有该行业权限,正常展示,2:无该行业权限,3:潜在客户,未提交过申请,4:潜在客户,已提交过申请"`
  667. var companyDetailStatus string
  668. if user.CompanyId <= 1 {
  669. companyDetailStatus = ""
  670. } else {
  671. companyPermission, err := models.GetCompanyPermission(user.CompanyId)
  672. if err != nil {
  673. br.Msg = "获取信息失败"
  674. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  675. return
  676. }
  677. if companyPermission == "" {
  678. if applyCount > 0 {
  679. hasPermission = 4
  680. } else {
  681. hasPermission = 3
  682. }
  683. resp.HasPermission = hasPermission
  684. resp.OperationMode = "Apply"
  685. resp.PopupMsg = "您暂无权限参加 【" + activityInfo.ChartPermissionName + "】行业活动,若想参加可以申请开通哦"
  686. br.Ret = 200
  687. br.Success = true
  688. br.Msg = "获取成功"
  689. br.Data = resp
  690. return
  691. }
  692. companyDetail, err := models.GetCompanyDetailById(user.CompanyId)
  693. if err != nil {
  694. br.Msg = "获取信息失败!"
  695. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  696. return
  697. }
  698. if companyDetail == nil {
  699. br.Msg = "获取信息失败!"
  700. br.ErrMsg = "客户不存在,uid:" + strconv.Itoa(user.UserId) + "CompanyId:" + strconv.Itoa(user.CompanyId)
  701. return
  702. }
  703. companyDetailStatus = companyDetail.Status
  704. }
  705. var userType int
  706. var permissionStr string
  707. userType, permissionStr, err = services.GetUserType(user.CompanyId)
  708. if err != nil {
  709. br.Msg = "获取信息失败!"
  710. br.ErrMsg = "获取失败,Err:" + err.Error()
  711. return
  712. }
  713. if userType == 1 && activityInfo.ChartPermissionName == "研选" {
  714. br.Msg = "您暂无查看该活动权限"
  715. br.ErrMsg = "被分享客户不可见,永续客户无法查看研选行业"
  716. return
  717. }
  718. item := new(models.CygxActivitySignup)
  719. if user.CompanyId > 1 {
  720. companyItem, err := models.GetCompanyDetailById(user.CompanyId)
  721. //冻结客户
  722. if err != nil {
  723. if err.Error() == utils.ErrNoRow() {
  724. resp.HasPermission = 4
  725. resp.OperationMode = "Apply"
  726. resp.PopupMsg = "您暂无权限参加 【" + activityInfo.ChartPermissionName + "】行业活动,若想参加可以申请开通哦"
  727. br.Ret = 200
  728. br.Success = true
  729. br.Msg = "获取成功"
  730. br.Data = resp
  731. return
  732. } else {
  733. br.Msg = "获取信息失败"
  734. br.ErrMsg = "获取客户公司信息失败,Err:" + err.Error()
  735. return
  736. }
  737. }
  738. //1专家电话会、2分析师电话会、3公司调研电话会、4公司线下调研、5专家线下沙龙、6分析师线下沙龙
  739. //OperationMode string `description:"操作方式 Apply:立即申请、Call:拨号 为空则为有权限"`
  740. havePower, err := services.GetHavePower(activityInfo, permissionStr, companyDetailStatus, userType)
  741. if err != nil {
  742. br.Msg = "获取信息失败!"
  743. br.ErrMsg = "获取失败,Err:" + err.Error()
  744. return
  745. }
  746. if havePower {
  747. hasPermission = 1
  748. signupStatus = "Success"
  749. resultTime := utils.StrTimeToTime(activityInfo.ActivityTime) //时间字符串格式转时间格式
  750. if time.Now().After(resultTime.Add(-time.Minute * 60)) {
  751. signupStatus = "Overtime"
  752. resp.SignupType = signupType
  753. resp.SignupStatus = signupStatus
  754. resp.HasPermission = hasPermission
  755. br.Ret = 200
  756. br.Success = true
  757. br.Msg = ""
  758. br.Data = resp
  759. return
  760. }
  761. //人数已满:FullStarffed、单机构超过两人:TwoPeople、爽约次数过多:BreakPromise、超时:Overtime 、成功:Success"`
  762. //如果是下面几种情况则对报名信息做判断限制 (公司调研电话会(限制人数)、公司线下调研、专家/分析师线下沙龙)
  763. if (activityInfo.ActivityTypeId == 3 && activityInfo.IsLimitPeople == 1) || activityInfo.ActivityTypeId > 3 {
  764. //判断优先级:总人数限制→单机构2人限制→爽约3次限制
  765. totalRestrict, err := models.GetUserRestrictCount(user.Mobile)
  766. if err != nil {
  767. br.Msg = "获取信息失败"
  768. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  769. return
  770. }
  771. if totalRestrict >= 1 {
  772. signupStatus = "BreakPromise"
  773. item.FailType = 3
  774. }
  775. totalSignupCompany, err := models.GetActivitySignupCompanyCount(activityId, user.CompanyId)
  776. if err != nil {
  777. br.Msg = "获取信息失败"
  778. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  779. return
  780. }
  781. if totalSignupCompany >= 2 {
  782. signupStatus = "TwoPeople"
  783. item.FailType = 2
  784. }
  785. totaSignupPeopleNum, err := models.GetActivitySignupSuccessCount(activityId)
  786. if err != nil {
  787. br.Msg = "获取信息失败"
  788. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  789. return
  790. }
  791. if totaSignupPeopleNum >= activityInfo.LimitPeopleNum {
  792. signupStatus = "FullStarffed"
  793. item.FailType = 1
  794. }
  795. totalUserRestrictCount, err := models.GetActivitySignupByUserRestrictCount(uid, activityId)
  796. if err != nil {
  797. br.Msg = "获取失败"
  798. br.ErrMsg = "获取失败,Err:" + err.Error()
  799. return
  800. }
  801. //解除报名限制之后二次报名相同活动
  802. if totalUserRestrictCount > 0 && totalRestrict == 0 && resp.GoBindEmail != true {
  803. item.UserId = uid
  804. item.ActivityId = activityId
  805. item.CreateTime = time.Now()
  806. item.Mobile = user.Mobile
  807. item.Email = user.Email
  808. item.CompanyId = user.CompanyId
  809. item.CompanyName = user.CompanyName
  810. item.SignupType = signupType
  811. item.FailType = 0
  812. item.DoFailType = 0
  813. _, errSignup := models.AddActivitySignupByRestrict(item)
  814. if errSignup != nil {
  815. br.Msg = "操作失败"
  816. br.ErrMsg = "操作失败,Err:" + errSignup.Error()
  817. return
  818. }
  819. resp.HaqveJurisdiction = true
  820. resp.SignupType = signupType
  821. resp.SignupStatus = "Success"
  822. resp.HasPermission = hasPermission
  823. resp.ActivityId = activityId
  824. total, err = models.GetUserMeetingReminderCount(user.UserId)
  825. if err != nil {
  826. br.Msg = "获取信息失败"
  827. br.ErrMsg = "获取日程数量信息失败,Err:" + err.Error()
  828. return
  829. }
  830. if total == 0 {
  831. resp.GoFollow = true
  832. }
  833. br.Ret = 200
  834. br.Success = true
  835. br.Msg = "操作成功"
  836. br.Data = resp
  837. return
  838. }
  839. totalMy, err := models.GetActivitySignupByUserCount(uid, activityId)
  840. if err != nil {
  841. br.Msg = "获取失败"
  842. br.ErrMsg = "获取失败,Err:" + err.Error()
  843. return
  844. }
  845. if signupStatus != "Success" && totalMy == 0 && resp.GoBindEmail != true {
  846. item.UserId = uid
  847. item.ActivityId = activityId
  848. item.CreateTime = time.Now()
  849. item.Mobile = user.Mobile
  850. item.Email = user.Email
  851. item.CompanyId = user.CompanyId
  852. item.CompanyName = user.CompanyName
  853. item.SignupType = signupType
  854. item.DoFailType = item.FailType
  855. if user.OutboundMobile != "" {
  856. item.OutboundMobile = user.OutboundMobile
  857. if user.OutboundCountryCode == "" {
  858. item.CountryCode = "86"
  859. } else {
  860. item.CountryCode = user.OutboundCountryCode
  861. }
  862. } else {
  863. item.OutboundMobile = user.Mobile
  864. if user.CountryCode == "" {
  865. item.CountryCode = "86"
  866. } else {
  867. item.CountryCode = user.CountryCode
  868. }
  869. }
  870. //添加报名信息,但是不加入日程
  871. _, errSignup := models.AddActivitySignupNoSchedule(item)
  872. if errSignup != nil {
  873. br.Msg = "操作失败"
  874. br.ErrMsg = "操作失败,Err:" + errSignup.Error()
  875. return
  876. }
  877. }
  878. }
  879. totalMySuccess, err := models.GetActivitySignupCount(uid, activityId)
  880. if err != nil {
  881. br.Msg = "获取失败"
  882. br.ErrMsg = "获取失败,Err:" + err.Error()
  883. return
  884. }
  885. if totalMySuccess > 0 {
  886. br.Msg = "您已报名这个活动"
  887. return
  888. }
  889. if signupStatus == "Success" && resp.GoBindEmail != true {
  890. item.UserId = uid
  891. item.ActivityId = activityId
  892. item.CreateTime = time.Now()
  893. item.Mobile = user.Mobile
  894. item.Email = user.Email
  895. item.CompanyId = user.CompanyId
  896. item.CompanyName = user.CompanyName
  897. item.SignupType = signupType
  898. item.FailType = 0
  899. item.DoFailType = 0
  900. item.OutboundMobile = user.Mobile
  901. if user.OutboundMobile != "" {
  902. item.OutboundMobile = user.OutboundMobile
  903. if user.OutboundCountryCode == "" {
  904. item.CountryCode = "86"
  905. } else {
  906. item.CountryCode = user.OutboundCountryCode
  907. }
  908. } else {
  909. item.OutboundMobile = user.Mobile
  910. if user.CountryCode == "" {
  911. item.CountryCode = "86"
  912. } else {
  913. item.CountryCode = user.CountryCode
  914. }
  915. }
  916. _, errSignup := models.AddActivitySignup(item)
  917. if errSignup != nil {
  918. br.Msg = "操作失败"
  919. br.ErrMsg = "操作失败,Err:" + errSignup.Error()
  920. return
  921. }
  922. resp.HaqveJurisdiction = true
  923. }
  924. } else {
  925. hasPermission = 2
  926. resp.SellerMobile = companyItem.Mobile
  927. resp.SellerName = companyItem.SellerName
  928. resp.MsgType = "Type"
  929. resp.OperationMode = "Call"
  930. if permissionStr == "专家" {
  931. resp.PopupMsg = "您暂无权限参加【" + activityInfo.ActivityTypeName + "】类型活动,若想参加请联系对口销售--" + companyItem.SellerName + ":" + companyItem.Mobile
  932. resp.MsgType = "Type"
  933. } else {
  934. resp.PopupMsg = "您暂无权限参加【" + activityInfo.ChartPermissionName + "】行业活动,若想参加请联系对口销售--" + companyItem.SellerName + ":" + companyItem.Mobile
  935. resp.MsgType = "Industry"
  936. }
  937. }
  938. } else { //潜在客户
  939. if applyCount > 0 {
  940. hasPermission = 4
  941. } else {
  942. hasPermission = 3
  943. }
  944. resp.OperationMode = "Apply"
  945. resp.PopupMsg = "您暂无权限参加 【" + activityInfo.ChartPermissionName + "】行业活动,若想参加可以申请开通哦"
  946. }
  947. if signupType == 1 && user.IsMsgOutboundMobile == 0 {
  948. resp.GoOutboundMobile = true
  949. if user.Mobile != "" || user.OutboundMobile != "" {
  950. go models.ModifyWxUserIsMsgOutboundMobile(user.UserId)
  951. }
  952. }
  953. if user.OutboundMobile == "" {
  954. resp.Mobile = user.Mobile
  955. if user.CountryCode == "" && len(user.Mobile) == 11 {
  956. resp.CountryCode = "86"
  957. } else {
  958. resp.CountryCode = user.CountryCode
  959. }
  960. } else {
  961. resp.Mobile = user.OutboundMobile
  962. resp.CountryCode = user.OutboundCountryCode
  963. }
  964. //如果用户有绑定手机号,但是没有绑定外呼手机号
  965. if signupType == 1 && user.Mobile != "" && user.OutboundMobile == "" {
  966. var countryCode string
  967. if len(user.Mobile) == 8 {
  968. countryCode = "852"
  969. } else if len(user.Mobile) == 9 {
  970. countryCode = "886"
  971. } else if len(user.Mobile) == 10 {
  972. countryCode = "1"
  973. } else if len(user.Mobile) >= 11 {
  974. countryCode = "86"
  975. }
  976. models.BindUserOutboundMobileByMobile(user.Mobile, countryCode, uid)
  977. }
  978. resp.SignupType = signupType
  979. resp.SignupStatus = signupStatus
  980. resp.HasPermission = hasPermission
  981. if signupStatus == "Success" {
  982. resp.ActivityId = activityId
  983. }
  984. total, err = models.GetUserSignupCount(user.UserId)
  985. if err != nil {
  986. br.Msg = "获取信息失败"
  987. br.ErrMsg = "获取日程数量信息失败,Err:" + err.Error()
  988. return
  989. }
  990. if total <= 1 {
  991. resp.GoFollow = true
  992. }
  993. br.Ret = 200
  994. br.Success = true
  995. br.Msg = "操作成功"
  996. br.Data = resp
  997. }
  998. // @Title 活动取消报名
  999. // @Description 活动取消报名接口
  1000. // @Param request body models.ActivitySingnupRep true "type json string"
  1001. // @Success Ret=200 {object} models.SignupStatus
  1002. // @router /signup/cancel [post]
  1003. func (this *ActivityCoAntroller) SignupCancel() {
  1004. br := new(models.BaseResponse).Init()
  1005. defer func() {
  1006. this.Data["json"] = br
  1007. this.ServeJSON()
  1008. }()
  1009. user := this.User
  1010. if user == nil {
  1011. br.Msg = "请登录"
  1012. br.ErrMsg = "请登录,用户信息为空"
  1013. br.Ret = 408
  1014. return
  1015. }
  1016. uid := user.UserId
  1017. var req models.ActivitySingnupRep
  1018. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1019. if err != nil {
  1020. br.Msg = "参数解析异常!"
  1021. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1022. return
  1023. }
  1024. activityId := req.ActivityId
  1025. signupType := req.SignupType
  1026. item := new(models.CygxActivitySignup)
  1027. activityInfo, errInfo := models.GetAddActivityInfoById(activityId)
  1028. if activityInfo == nil {
  1029. br.Msg = "操作失败"
  1030. br.ErrMsg = "活动ID错误,不存在activityId:" + strconv.Itoa(activityId)
  1031. return
  1032. }
  1033. if errInfo != nil {
  1034. br.Msg = "操作失败"
  1035. br.ErrMsg = "操作失败,Err:" + errInfo.Error()
  1036. return
  1037. }
  1038. resultTime := utils.StrTimeToTime(activityInfo.ActivityTime) //时间字符串格式转时间格式
  1039. if time.Now().After(resultTime.Add(-time.Minute * 60)) {
  1040. if signupType == 1 {
  1041. br.Msg = "活动开始前1小时内无法取消预约外呼,请联系对口销售处理"
  1042. } else {
  1043. br.Msg = "活动开始前1小时内无法取消报名,请联系对口销售处理"
  1044. }
  1045. return
  1046. }
  1047. total, err := models.GetActivitySignupCount(uid, activityId)
  1048. if err != nil {
  1049. br.Msg = "获取失败"
  1050. br.ErrMsg = "获取失败,Err:" + err.Error()
  1051. return
  1052. }
  1053. if total == 0 {
  1054. br.Msg = "您暂未报名这个活动"
  1055. return
  1056. }
  1057. item.UserId = uid
  1058. item.ActivityId = activityId
  1059. item.CreateTime = time.Now()
  1060. item.Mobile = user.Mobile
  1061. item.Email = user.Email
  1062. item.CompanyId = user.CompanyId
  1063. item.CompanyName = user.CompanyName
  1064. resp := new(models.SignupStatus)
  1065. resp.ActivityId = activityId
  1066. _, errSignup := models.CancelActivitySignup(item)
  1067. if errSignup != nil {
  1068. br.Msg = "操作失败"
  1069. br.ErrMsg = "操作失败,Err:" + errSignup.Error()
  1070. return
  1071. }
  1072. br.Ret = 200
  1073. br.Success = true
  1074. br.Msg = "操作成功"
  1075. br.Data = resp
  1076. }
  1077. // @Title 用户搜索详情
  1078. // @Description 获取用户搜索详情接口
  1079. // @Param IsShowJurisdiction query int true "是否仅展示有权限的,默认为0,1是,2否 "
  1080. // @Success Ret=200 {object} models.ActivityUserSearchContentList
  1081. // @router /getUserSearchContent [get]
  1082. func (this *ActivityCoAntroller) GetUserSearchContent() {
  1083. br := new(models.BaseResponse).Init()
  1084. defer func() {
  1085. this.Data["json"] = br
  1086. this.ServeJSON()
  1087. }()
  1088. user := this.User
  1089. if user == nil {
  1090. br.Msg = "请登录"
  1091. br.ErrMsg = "请登录,用户信息为空"
  1092. br.Ret = 408
  1093. return
  1094. }
  1095. uid := user.UserId
  1096. detailSeearch := new(models.CygxActivityUserSearchContent)
  1097. detailSeearch.IsShowJurisdiction = 0
  1098. detailSeearch.ChartPermissionids = ""
  1099. detailSeearch.ActiveState = ""
  1100. resp := new(models.ActivityUserSearchContentList)
  1101. detail, _ := models.GetUserSearchContentByUid(uid)
  1102. if detail == nil {
  1103. detail = detailSeearch
  1104. }
  1105. isShowJurisdiction, _ := this.GetInt("IsShowJurisdiction")
  1106. listActivityType, errActivityType := models.GetActivityTypeList()
  1107. if errActivityType != nil {
  1108. br.Msg = "获取失败"
  1109. br.ErrMsg = "获取数据失败,Err:" + errActivityType.Error()
  1110. return
  1111. }
  1112. var listChartPermissionid []*models.ActivityChartPermission
  1113. var errChart error
  1114. if isShowJurisdiction == 1 {
  1115. listChartPermissionidAll, errChartAll := models.GetUserCompanyPermission(user.CompanyId)
  1116. listChartPermissionid = listChartPermissionidAll
  1117. errChart = errChartAll
  1118. } else if isShowJurisdiction == 2 {
  1119. listChartPermissionidAll, errChartAll := models.GetChartPermissionActivity()
  1120. listChartPermissionid = listChartPermissionidAll
  1121. errChart = errChartAll
  1122. } else {
  1123. if detail.IsShowJurisdiction == 1 {
  1124. listChartPermissionidAll, errChartAll := models.GetUserCompanyPermission(user.CompanyId)
  1125. listChartPermissionid = listChartPermissionidAll
  1126. errChart = errChartAll
  1127. } else {
  1128. listChartPermissionidAll, errChartAll := models.GetChartPermissionActivity()
  1129. listChartPermissionid = listChartPermissionidAll
  1130. errChart = errChartAll
  1131. }
  1132. }
  1133. if errChart != nil {
  1134. br.Msg = "获取信息失败"
  1135. br.ErrMsg = "获取品种信息失败,Err:" + errChart.Error()
  1136. return
  1137. }
  1138. if detail.IsShowJurisdiction == 1 {
  1139. resp.IsShowJurisdiction = true
  1140. }
  1141. if isShowJurisdiction == 1 || detail.IsShowJurisdiction == 1 {
  1142. resp.IsShowJurisdiction = true
  1143. for k, _ := range listChartPermissionid {
  1144. listChartPermissionid[k].IsChoose = true
  1145. }
  1146. }
  1147. if isShowJurisdiction == 2 {
  1148. resp.IsShowJurisdiction = false
  1149. }
  1150. activeStateList := []models.ActivityStaus{models.ActivityStaus{Id: 1, StatusName: "未开始", IsChoose: true}, models.ActivityStaus{Id: 2, StatusName: "进行中"}, models.ActivityStaus{Id: 3, StatusName: "已结束"}}
  1151. list2, err := models.GetChartPermissionActivity()
  1152. if err != nil {
  1153. br.Msg = "获取信息失败"
  1154. br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
  1155. return
  1156. }
  1157. if activeStateList[1].IsChoose == activeStateList[2].IsChoose == false {
  1158. activeStateList[0].IsChoose = true
  1159. }
  1160. var userType int
  1161. userType, _, err = services.GetUserType(user.CompanyId)
  1162. if err != nil {
  1163. br.Msg = "获取信息失败!"
  1164. br.ErrMsg = "获取失败,Err:" + err.Error()
  1165. return
  1166. }
  1167. var listChartPermissionidNew2 []*models.ActivityChartPermission
  1168. for _, v := range list2 {
  1169. if userType == 1 {
  1170. if v.PermissionName != "研选" {
  1171. listChartPermissionidNew2 = append(listChartPermissionidNew2, v)
  1172. }
  1173. } else {
  1174. listChartPermissionidNew2 = append(listChartPermissionidNew2, v)
  1175. }
  1176. }
  1177. resp.ListChartPermission2 = listChartPermissionidNew2
  1178. var listChartPermissionidNew []*models.ActivityChartPermission
  1179. for _, v := range listChartPermissionid {
  1180. if userType == 1 {
  1181. if v.PermissionName != "研选" {
  1182. listChartPermissionidNew = append(listChartPermissionidNew, v)
  1183. }
  1184. } else {
  1185. listChartPermissionidNew = append(listChartPermissionidNew, v)
  1186. }
  1187. }
  1188. resp.ListActivityType = listActivityType
  1189. resp.ListChartPermission = listChartPermissionidNew
  1190. resp.ListActivityStaus = activeStateList
  1191. br.Ret = 200
  1192. br.Success = true
  1193. br.Msg = "获取成功"
  1194. br.Data = resp
  1195. }
  1196. // @Title 添加会议提醒
  1197. // @Description 添加会议提醒接口
  1198. // @Param request body models.ActivityIdRep true "type json string"
  1199. // @Success Ret=200 {object} models.SignupStatus
  1200. // @router /meetingReminder/add [post]
  1201. func (this *ActivityCoAntroller) MeetingReminderAdd() {
  1202. br := new(models.BaseResponse).Init()
  1203. defer func() {
  1204. this.Data["json"] = br
  1205. this.ServeJSON()
  1206. }()
  1207. user := this.User
  1208. if user == nil {
  1209. br.Msg = "请登录"
  1210. br.ErrMsg = "请登录,用户信息为空"
  1211. br.Ret = 408
  1212. return
  1213. }
  1214. uid := user.UserId
  1215. //var signupStatus string
  1216. signupStatus := "Success"
  1217. var req models.ActivityIdRep
  1218. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1219. if err != nil {
  1220. br.Msg = "参数解析异常!"
  1221. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1222. return
  1223. }
  1224. activityId := req.ActivityId
  1225. activityInfo, errInfo := models.GetAddActivityInfoById(activityId)
  1226. if activityInfo == nil {
  1227. br.Msg = "操作失败"
  1228. br.ErrMsg = "活动ID错误,不存在activityId:" + strconv.Itoa(activityId)
  1229. return
  1230. }
  1231. if errInfo != nil {
  1232. br.Msg = "操作失败"
  1233. br.ErrMsg = "操作失败,Err:" + errInfo.Error()
  1234. return
  1235. }
  1236. //判断是否已经申请过
  1237. applyCount, err := models.GetApplyRecordCount(uid)
  1238. if err != nil && err.Error() != utils.ErrNoRow() {
  1239. br.Msg = "获取信息失败"
  1240. br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
  1241. return
  1242. }
  1243. //SignupStatus string `description:"报名状态:人数已满:FullStarffed、单机构超过两人:TwoPeople、爽约次数过多:BreakPromise、超时:Overtime 、成功:Success"`
  1244. item := new(models.CygxActivityMeetingReminder)
  1245. resp := new(models.SignupStatus)
  1246. hasPermission := 0
  1247. var companyDetailStatus string
  1248. if user.CompanyId <= 1 {
  1249. companyDetailStatus = ""
  1250. } else {
  1251. companyPermission, err := models.GetCompanyPermission(user.CompanyId)
  1252. if err != nil {
  1253. br.Msg = "获取信息失败"
  1254. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  1255. return
  1256. }
  1257. if companyPermission == "" {
  1258. if applyCount > 0 {
  1259. hasPermission = 4
  1260. } else {
  1261. hasPermission = 3
  1262. }
  1263. resp.HasPermission = hasPermission
  1264. resp.OperationMode = "Apply"
  1265. resp.PopupMsg = "您暂无权限参加 【" + activityInfo.ChartPermissionName + "】行业活动,若想参加可以申请开通哦"
  1266. br.Ret = 200
  1267. br.Success = true
  1268. br.Msg = "获取成功"
  1269. br.Data = resp
  1270. return
  1271. }
  1272. companyDetail, err := models.GetCompanyDetailById(user.CompanyId)
  1273. if err != nil {
  1274. br.Msg = "获取信息失败!"
  1275. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  1276. return
  1277. }
  1278. if companyDetail == nil {
  1279. br.Msg = "获取信息失败!"
  1280. br.ErrMsg = "客户不存在,uid:" + strconv.Itoa(user.UserId) + "CompanyId:" + strconv.Itoa(user.CompanyId)
  1281. return
  1282. }
  1283. companyDetailStatus = companyDetail.Status
  1284. }
  1285. var userType int
  1286. var permissionStr string
  1287. userType, permissionStr, err = services.GetUserType(user.CompanyId)
  1288. if err != nil {
  1289. br.Msg = "获取信息失败!"
  1290. br.ErrMsg = "获取失败,Err:" + err.Error()
  1291. return
  1292. }
  1293. if userType == 1 && activityInfo.ChartPermissionName == "研选" {
  1294. br.Msg = "您暂无查看该活动权限"
  1295. br.ErrMsg = "被分享客户不可见,永续客户无法查看研选行业"
  1296. return
  1297. }
  1298. resultTime := utils.StrTimeToTime(activityInfo.ActivityTime) //时间字符串格式转时间格式
  1299. if time.Now().After(resultTime.Add(-time.Minute * 15)) {
  1300. br.Msg = "活动开始前15分钟无法设置会议提醒"
  1301. return
  1302. }
  1303. if user.CompanyId > 1 {
  1304. companyItem, err := models.GetCompanyDetailById(user.CompanyId)
  1305. //冻结客户
  1306. if err != nil {
  1307. if err.Error() == utils.ErrNoRow() {
  1308. resp.HasPermission = 4
  1309. resp.OperationMode = "Apply"
  1310. resp.PopupMsg = "您暂无权限参加 【" + activityInfo.ChartPermissionName + "】行业活动,若想参加可以申请开通哦"
  1311. br.Ret = 200
  1312. br.Success = true
  1313. br.Msg = "获取成功"
  1314. br.Data = resp
  1315. return
  1316. } else {
  1317. br.Msg = "获取信息失败"
  1318. br.ErrMsg = "获取客户公司信息失败,Err:" + err.Error()
  1319. return
  1320. }
  1321. }
  1322. havePower, err := services.GetHavePower(activityInfo, permissionStr, companyDetailStatus, userType)
  1323. if err != nil {
  1324. br.Msg = "获取信息失败!"
  1325. br.ErrMsg = "获取失败,Err:" + err.Error()
  1326. return
  1327. }
  1328. if havePower {
  1329. hasPermission = 1
  1330. signupStatus = "Success"
  1331. totalMeeting, errMeeting := models.GetActivityMeetingReminderCount(uid, activityId)
  1332. if errMeeting != nil {
  1333. br.Msg = "获取失败"
  1334. br.ErrMsg = "获取失败,Err:" + errMeeting.Error()
  1335. return
  1336. }
  1337. if totalMeeting > 0 {
  1338. br.Msg = "您已预约,请勿重复预约"
  1339. return
  1340. }
  1341. item.UserId = uid
  1342. item.ActivityId = activityId
  1343. item.CreateTime = time.Now()
  1344. item.Mobile = user.Mobile
  1345. item.Email = user.Email
  1346. item.CompanyId = user.CompanyId
  1347. item.CompanyName = user.CompanyName
  1348. _, errSignup := models.AddActivityMeetingReminder(item)
  1349. if errSignup != nil {
  1350. br.Msg = "操作失败"
  1351. br.ErrMsg = "操作失败,Err:" + errSignup.Error()
  1352. return
  1353. }
  1354. resp.HaqveJurisdiction = true
  1355. } else {
  1356. hasPermission = 2
  1357. resp.SellerMobile = companyItem.Mobile
  1358. resp.SellerName = companyItem.SellerName
  1359. resp.MsgType = "Type"
  1360. resp.OperationMode = "Call"
  1361. if permissionStr == "专家" {
  1362. resp.PopupMsg = "您暂无权限参加【" + activityInfo.ActivityTypeName + "】类型活动,若想参加请联系对口销售--" + companyItem.SellerName + ":" + companyItem.Mobile
  1363. resp.MsgType = "Type"
  1364. } else {
  1365. resp.PopupMsg = "您暂无权限参加【" + activityInfo.ChartPermissionName + "】行业活动,若想参加请联系对口销售--" + companyItem.SellerName + ":" + companyItem.Mobile
  1366. resp.MsgType = "Industry"
  1367. }
  1368. }
  1369. } else { //潜在客户
  1370. if applyCount > 0 {
  1371. hasPermission = 4
  1372. } else {
  1373. hasPermission = 3
  1374. }
  1375. resp.OperationMode = "Apply"
  1376. resp.PopupMsg = "您暂无权限参加 【" + activityInfo.ChartPermissionName + "】行业活动,若想参加可以申请开通哦"
  1377. }
  1378. resp.HasPermission = hasPermission
  1379. resp.SignupStatus = signupStatus
  1380. resp.ActivityId = activityId
  1381. var total int
  1382. total, err = models.GetUserActivityMeetingReminderCount(user.UserId)
  1383. if err != nil {
  1384. br.Msg = "获取信息失败"
  1385. br.ErrMsg = "获取日程数量信息失败,Err:" + err.Error()
  1386. return
  1387. }
  1388. if total <= 1 {
  1389. resp.GoFollow = true
  1390. }
  1391. br.Ret = 200
  1392. br.Success = true
  1393. if hasPermission == 1 {
  1394. br.Msg = "设置成功,会前15分钟会为您推送微信消息提醒"
  1395. }
  1396. br.Data = resp
  1397. }
  1398. // @Title 取消会议提醒
  1399. // @Description 取消会议提醒接口
  1400. // @Param request body models.ActivityIdRep true "type json string"
  1401. // @Success Ret=200 {object} models.SignupStatus
  1402. // @router /meetingReminder/cancel [post]
  1403. func (this *ActivityCoAntroller) MeetingReminderCancel() {
  1404. br := new(models.BaseResponse).Init()
  1405. defer func() {
  1406. this.Data["json"] = br
  1407. this.ServeJSON()
  1408. }()
  1409. user := this.User
  1410. if user == nil {
  1411. br.Msg = "请登录"
  1412. br.ErrMsg = "请登录,用户信息为空"
  1413. br.Ret = 408
  1414. return
  1415. }
  1416. uid := user.UserId
  1417. var req models.ActivityIdRep
  1418. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1419. if err != nil {
  1420. br.Msg = "参数解析异常!"
  1421. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1422. return
  1423. }
  1424. activityId := req.ActivityId
  1425. signupStatus := "Success"
  1426. item := new(models.CygxActivityMeetingReminder)
  1427. activityInfo, errInfo := models.GetAddActivityInfoById(activityId)
  1428. if activityInfo == nil {
  1429. br.Msg = "操作失败"
  1430. br.ErrMsg = "活动ID错误,不存在activityId:" + strconv.Itoa(activityId)
  1431. return
  1432. }
  1433. if errInfo != nil {
  1434. br.Msg = "操作失败"
  1435. br.ErrMsg = "操作失败,Err:" + errInfo.Error()
  1436. return
  1437. }
  1438. //if signupStatus == "Success" {
  1439. total, err := models.GetActivityMeetingReminderCount(uid, activityId)
  1440. if err != nil {
  1441. br.Msg = "获取失败"
  1442. br.ErrMsg = "获取失败,Err:" + err.Error()
  1443. return
  1444. }
  1445. if total == 0 {
  1446. br.Msg = "您暂未添加该活动会议提醒"
  1447. return
  1448. }
  1449. resultTime := utils.StrTimeToTime(activityInfo.ActivityTime) //时间字符串格式转时间格式
  1450. if time.Now().After(resultTime.Add(-time.Minute * 15)) {
  1451. br.Msg = "活动开始前15分钟无法取消会议提醒"
  1452. return
  1453. }
  1454. item.UserId = uid
  1455. item.ActivityId = activityId
  1456. item.CreateTime = time.Now()
  1457. item.Mobile = user.Mobile
  1458. item.Email = user.Email
  1459. item.CompanyId = user.CompanyId
  1460. item.CompanyName = user.CompanyName
  1461. _, errSignup := models.CancelActivityMeetingReminder(item)
  1462. if errSignup != nil {
  1463. br.Msg = "操作失败"
  1464. br.ErrMsg = "操作失败,Err:" + errSignup.Error()
  1465. return
  1466. }
  1467. //}
  1468. resp := new(models.SignupStatus)
  1469. resp.SignupStatus = signupStatus
  1470. resp.ActivityId = activityId
  1471. br.Ret = 200
  1472. br.Success = true
  1473. br.Msg = "会议提醒已取消"
  1474. br.Data = resp
  1475. }
  1476. // @Title 敏捷搜索关键词的列表
  1477. // @Description 获取敏捷搜索关键词的列表接口
  1478. // @Success 200 {object} models.ActivityFastsearchKeywordsListResp
  1479. // @router /fastSearchKeWord [get]
  1480. func (this *ActivityABaseController) FastSearch() {
  1481. br := new(models.BaseResponse).Init()
  1482. defer func() {
  1483. this.Data["json"] = br
  1484. this.ServeJSON()
  1485. }()
  1486. resp := new(models.ActivityFastsearchKeywordsListResp)
  1487. list, err := models.GetActivityFastsearchKeywordsList()
  1488. if err != nil {
  1489. br.Msg = "获取失败"
  1490. br.ErrMsg = "获取数据失败,Err:" + err.Error()
  1491. return
  1492. }
  1493. resp.List = list
  1494. br.Ret = 200
  1495. br.Success = true
  1496. br.Msg = "获取成功"
  1497. br.Data = resp
  1498. }
  1499. // @Title 主题列表
  1500. // @Description 获取活动主题列表接口
  1501. // @Param ChartPermissionIds query string false "行业id 多个用 , 隔开"
  1502. // @Param ActivityTypeIds query string false "活动类型id 多个用 , 隔开"
  1503. // @Param ActiveState query string false "活动进行状态 未开始:1、进行中2、已结束3"
  1504. // @Param WhichDay query string false "哪一天 今天:1、明天:2,多个用 , 隔开"
  1505. // @Param Label query string false "搜索主题 多个用 , 隔开 (空为活动主题,非空为更多主题)"
  1506. // @Success 200 {object} models.GetCygxActivityLabelListRep
  1507. // @router /labelList [get]
  1508. func (this *ActivityCoAntroller) LabelList() {
  1509. br := new(models.BaseResponse).Init()
  1510. defer func() {
  1511. this.Data["json"] = br
  1512. this.ServeJSON()
  1513. }()
  1514. user := this.User
  1515. if user == nil {
  1516. br.Msg = "请登录"
  1517. br.ErrMsg = "请登录,SysUser Is Empty"
  1518. return
  1519. }
  1520. pageSize, _ := this.GetInt("PageSize")
  1521. //currentIndex, _ := this.GetInt("CurrentIndex")
  1522. chartPermissionIds := this.GetString("ChartPermissionIds")
  1523. activityTypeIds := this.GetString("ActivityTypeIds")
  1524. whichDay := this.GetString("WhichDay")
  1525. isShowJurisdiction, _ := this.GetInt("IsShowJurisdiction")
  1526. activeState := this.GetString("ActiveState")
  1527. label := this.GetString("Label")
  1528. //入参为 undefined 时的处理
  1529. if chartPermissionIds == "undefined" {
  1530. chartPermissionIds = ""
  1531. }
  1532. if activityTypeIds == "undefined" {
  1533. activityTypeIds = ""
  1534. }
  1535. if whichDay == "undefined" {
  1536. whichDay = ""
  1537. }
  1538. if activeState == "undefined" {
  1539. activeState = ""
  1540. }
  1541. if label == "undefined" {
  1542. label = ""
  1543. }
  1544. var userType int
  1545. var permissionStr string
  1546. if user.CompanyId <= 1 {
  1547. userType = 0
  1548. } else {
  1549. total, err := models.GetCountCompanyDetailByIdGroup(user.CompanyId)
  1550. if err != nil {
  1551. br.Msg = "获取失败"
  1552. br.ErrMsg = "获取失败,Err:" + err.Error()
  1553. return
  1554. }
  1555. if total == 0 {
  1556. userType = 0
  1557. } else {
  1558. companyDetail, err := models.GetCompanyDetailByIdGroup(user.CompanyId)
  1559. if err != nil {
  1560. br.Msg = "获取信息失败!"
  1561. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  1562. return
  1563. }
  1564. if companyDetail == nil {
  1565. br.Msg = "获取信息失败!"
  1566. br.ErrMsg = "客户不存在,uid:" + strconv.Itoa(user.UserId) + "CompanyId:" + strconv.Itoa(user.CompanyId)
  1567. return
  1568. }
  1569. permissionStr, err = models.GetCompanyPermission(user.CompanyId)
  1570. if err != nil {
  1571. br.Msg = "获取信息失败"
  1572. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  1573. return
  1574. }
  1575. //1、永续客户
  1576. //2、大套餐客户(4个行业全开通的正式客户)
  1577. //3、分行业套餐客户(开通对应行业的正式客户)
  1578. //4、仅开通专家套餐的正式客户
  1579. //5、开通对应行业套餐或专家套餐的试用客户
  1580. if companyDetail.Status == "永续" {
  1581. userType = 1
  1582. } else if companyDetail.Status == "试用" {
  1583. userType = 5
  1584. } else if companyDetail.Status == "正式" {
  1585. if permissionStr == "专家" {
  1586. userType = 4
  1587. } else if strings.Contains(permissionStr, "医药") && strings.Contains(permissionStr, "消费") && strings.Contains(permissionStr, "科技") && strings.Contains(permissionStr, "智造") {
  1588. userType = 2
  1589. } else {
  1590. userType = 3
  1591. }
  1592. if userType == 3 {
  1593. if !strings.Contains(permissionStr, "医药") && !strings.Contains(permissionStr, "消费") && !strings.Contains(permissionStr, "科技") && !strings.Contains(permissionStr, "智造") {
  1594. userType = 4
  1595. }
  1596. }
  1597. }
  1598. }
  1599. }
  1600. if isShowJurisdiction == 1 && chartPermissionIds == "" && userType == 4 {
  1601. activityTypeIds = "1,3"
  1602. }
  1603. var startSize int
  1604. //if pageSize <= 0 {
  1605. // pageSize = utils.PageSize20
  1606. //}
  1607. //currentIndex = 1
  1608. pageSize = 15
  1609. //startSize = utils.StartIndex(currentIndex, pageSize)
  1610. var condition string
  1611. var sortTime string
  1612. var pars []interface{}
  1613. //活动可见限制
  1614. var sqlExport string
  1615. slicePer := strings.Split(permissionStr, ",")
  1616. var permissionSqlStr string
  1617. //for _, v := range slicePer {
  1618. // permissionSqlStr += "'" + v + "',"
  1619. //}
  1620. for _, v := range slicePer {
  1621. if userType == 1 {
  1622. if v != "研选" {
  1623. permissionSqlStr += "'" + v + "',"
  1624. }
  1625. } else {
  1626. permissionSqlStr += "'" + v + "',"
  1627. }
  1628. }
  1629. permissionSqlStr = strings.TrimRight(permissionSqlStr, ",")
  1630. permissionSqlStr = ` AND art.chart_permission_name IN (` + permissionSqlStr + `)`
  1631. sqlExport = ` AND (art.customer_type_ids LIKE '%` + strconv.Itoa(userType) + `%' `
  1632. if userType == 2 {
  1633. sqlExport += ` OR art.customer_type_ids LIKE '%3%' `
  1634. }
  1635. if (userType == 2 || userType == 3) && strings.Contains(permissionStr, "专家") {
  1636. sqlExport += ` OR art.customer_type_ids LIKE '%4%' `
  1637. }
  1638. sqlExport += `) `
  1639. condition += ` AND art.publish_status = 1 AND art.label != '' `
  1640. //condition += ` AND art.active_state = 1 `
  1641. var conditionOr string
  1642. if (userType == 2 || userType == 3 || userType == 4) && strings.Contains(permissionStr, "专家") {
  1643. conditionOr += ` OR ( art.is_limit_people = 1 AND art.customer_type_ids LIKE '%4%' ` + condition + `) `
  1644. }
  1645. if (userType == 5) && strings.Contains(permissionStr, "专家") {
  1646. conditionOr += ` OR ( art.is_limit_people = 1 AND art.customer_type_ids LIKE '%5%' ` + condition + `) `
  1647. }
  1648. if userType == 1 {
  1649. conditionOr += ` OR ( art.is_limit_people = 0 ` + condition + permissionSqlStr + `) `
  1650. } else {
  1651. conditionOr += ` OR ( art.is_limit_people = 0 ` + condition + `) `
  1652. }
  1653. //conditionOr += ` OR ( art.is_limit_people = 0 ` + condition + `) `
  1654. condition += `AND art.is_limit_people = 1 ` + permissionSqlStr + sqlExport + conditionOr
  1655. resp := new(models.GetCygxActivityLabelListRep)
  1656. //conditionLaable := condition
  1657. //主题
  1658. if label != "" {
  1659. sortTime = ` timesort DESC `
  1660. listAll, errList := models.GetActivityLabelListAll(condition, sortTime, pars, startSize, 32)
  1661. if errList != nil {
  1662. br.Msg = "获取失败"
  1663. br.ErrMsg = "获取失败,Err:" + errList.Error()
  1664. return
  1665. }
  1666. sortTime = ` mintimesort ASC `
  1667. condition += ` AND art.active_state = 1 `
  1668. list1, errList := models.GetActivityLabelListAll(condition, sortTime, pars, startSize, 16)
  1669. if errList != nil {
  1670. br.Msg = "获取失败"
  1671. br.ErrMsg = "获取失败,Err:" + errList.Error()
  1672. return
  1673. }
  1674. for _, v := range listAll {
  1675. var isHAve bool
  1676. for _, v2 := range list1 {
  1677. if v2.KeyWord == v.KeyWord {
  1678. isHAve = true
  1679. }
  1680. }
  1681. if !isHAve {
  1682. resp.List = append(resp.List, v)
  1683. }
  1684. }
  1685. br.Ret = 200
  1686. br.Success = true
  1687. br.Msg = "获取成功"
  1688. br.Data = resp
  1689. return
  1690. } else {
  1691. //行业名称
  1692. condition = ` AND art.publish_status = 1 AND art.label != '' `
  1693. if len(chartPermissionIds) > 0 {
  1694. condition += ` AND art.chart_permission_id IN (` + chartPermissionIds + `)`
  1695. }
  1696. if activityTypeIds != "" {
  1697. condition += ` AND art.activity_type_id IN (` + activityTypeIds + `)`
  1698. }
  1699. var conditionOr string
  1700. if whichDay != "" {
  1701. var startDate string
  1702. var endDate string
  1703. if whichDay == "1" {
  1704. startDate = time.Now().Format(utils.FormatDate)
  1705. endDate = startDate
  1706. } else if whichDay == "2" {
  1707. startDate = time.Now().AddDate(0, 0, +1).Format(utils.FormatDate)
  1708. endDate = startDate
  1709. } else {
  1710. startDate = time.Now().Format(utils.FormatDate)
  1711. endDate = time.Now().AddDate(0, 0, +1).Format(utils.FormatDate)
  1712. }
  1713. condition += ` AND art.activity_time >= ` + "'" + startDate + " 00:00:00'"
  1714. condition += ` AND art.activity_time <= ` + "'" + endDate + " 23:59:59'"
  1715. }
  1716. if activeState != "" {
  1717. condition += ` AND art.active_state IN (` + activeState + `)`
  1718. } else {
  1719. condition += ` AND art.active_state IN (1)`
  1720. }
  1721. if (userType == 2 || userType == 3 || userType == 4) && strings.Contains(permissionStr, "专家") {
  1722. conditionOr += ` OR ( art.is_limit_people = 1 AND art.customer_type_ids LIKE '%4%' ` + condition + `) `
  1723. }
  1724. if (userType == 5) && strings.Contains(permissionStr, "专家") {
  1725. conditionOr += ` OR ( art.is_limit_people = 1 AND art.customer_type_ids LIKE '%5%' ` + condition + `) `
  1726. }
  1727. if userType == 1 {
  1728. conditionOr += ` OR ( art.is_limit_people = 0 ` + condition + permissionSqlStr + `) `
  1729. } else {
  1730. conditionOr += ` OR ( art.is_limit_people = 0 ` + condition + `) `
  1731. }
  1732. condition += `AND art.is_limit_people = 1 ` + permissionSqlStr + sqlExport + conditionOr
  1733. }
  1734. sortTime = ` mintimesort ASC `
  1735. list, errList := models.GetActivityLabelListAll(condition, sortTime, pars, startSize, pageSize)
  1736. if errList != nil {
  1737. br.Msg = "获取失败"
  1738. br.ErrMsg = "获取失败,Err:" + errList.Error()
  1739. return
  1740. }
  1741. //resp := new(models.GetCygxActivityLabelListRep)
  1742. resp.List = list
  1743. br.Ret = 200
  1744. br.Success = true
  1745. br.Msg = "获取成功"
  1746. br.Data = resp
  1747. }
  1748. // @Title 上传公司名称excel
  1749. // @Description 上传参会表格数据
  1750. // @Param File query file true "文件"
  1751. // @Success 200 Ret=200 导入成功
  1752. // @router /activityMeet/import [post]
  1753. func (this *ActivityCoAntroller) Import() {
  1754. br := new(models.BaseResponse).Init()
  1755. defer func() {
  1756. this.Data["json"] = br
  1757. this.ServeJSON()
  1758. }()
  1759. sysUser := this.User
  1760. if sysUser == nil {
  1761. br.Msg = "请重新登录"
  1762. return
  1763. }
  1764. file, h, err := this.GetFile("File")
  1765. if err != nil {
  1766. br.Msg = "获取文件失败"
  1767. br.ErrMsg = "获取文件失败,Err:" + err.Error()
  1768. return
  1769. }
  1770. uploadDir := "static/xls"
  1771. err = os.MkdirAll(uploadDir, 766)
  1772. if err != nil {
  1773. br.Msg = "存储目录创建失败"
  1774. br.ErrMsg = "存储目录创建失败,Err:" + err.Error()
  1775. return
  1776. }
  1777. path := uploadDir + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + h.Filename
  1778. defer file.Close()
  1779. err = this.SaveToFile("File", path)
  1780. if err != nil {
  1781. br.Msg = "文件保存失败"
  1782. br.ErrMsg = "文件保存失败,Err:" + err.Error()
  1783. return
  1784. }
  1785. xlFile, err := xlsx.OpenFile(path)
  1786. if err != nil {
  1787. br.Msg = "文件导入失败"
  1788. br.ErrMsg = "文件导入失败,Err:" + err.Error()
  1789. return
  1790. }
  1791. //允许添加的联系人
  1792. needAddAttendanc := make([]*models.UserWhiteList, 0)
  1793. // 遍历sheet页读取
  1794. for _, sheet := range xlFile.Sheets {
  1795. //遍历行读取
  1796. maxRow := sheet.MaxRow
  1797. for i := 0; i < maxRow; i++ {
  1798. if i >= 1 {
  1799. row := sheet.Row(i)
  1800. cells := row.Cells
  1801. var companyName, permission string
  1802. for k, cell := range cells {
  1803. if k == 0 {
  1804. companyName = cell.String()
  1805. }
  1806. if k == 2 {
  1807. permission = cell.String()
  1808. }
  1809. }
  1810. //这些字段都没有的话,系统认为excel到底了
  1811. if companyName == "" {
  1812. break
  1813. }
  1814. item := new(models.UserWhiteList)
  1815. item.CompanyName = companyName
  1816. item.Permission = permission
  1817. needAddAttendanc = append(needAddAttendanc, item)
  1818. }
  1819. }
  1820. }
  1821. //var mobileStr string
  1822. var permissionStr string
  1823. for k, v := range needAddAttendanc {
  1824. if k > 0 && v.CompanyName != needAddAttendanc[k-1].CompanyName {
  1825. permissionStr, err = models.GetCompanyPermissionByName(v.CompanyName)
  1826. if err != nil {
  1827. br.Msg = "获取信息失败"
  1828. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  1829. return
  1830. }
  1831. }
  1832. if k == 0 {
  1833. permissionStr, err = models.GetCompanyPermissionByName(v.CompanyName)
  1834. if err != nil {
  1835. br.Msg = "获取信息失败"
  1836. br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
  1837. return
  1838. }
  1839. }
  1840. needAddAttendanc[k].Permission = permissionStr
  1841. fmt.Println(permissionStr)
  1842. }
  1843. defer func() {
  1844. os.Remove(path)
  1845. }()
  1846. //创建excel
  1847. dir, errFile := os.Executable()
  1848. exPath := filepath.Dir(dir)
  1849. downLoadnFilePath := exPath + "/" + time.Now().Format(utils.FormatDateTimeUnSpace) + ".xlsx"
  1850. xlsxFile := xlsx.NewFile()
  1851. if errFile != nil {
  1852. br.Msg = "生成文件失败Err:" + errFile.Error()
  1853. return
  1854. }
  1855. style := xlsx.NewStyle()
  1856. alignment := xlsx.Alignment{
  1857. Horizontal: "center",
  1858. Vertical: "center",
  1859. WrapText: true,
  1860. }
  1861. style.Alignment = alignment
  1862. style.ApplyAlignment = true
  1863. sheet, err := xlsxFile.AddSheet("白名单")
  1864. if err != nil {
  1865. br.Msg = "新增Sheet失败,Err:" + err.Error()
  1866. return
  1867. }
  1868. //标头
  1869. rowTitle := sheet.AddRow()
  1870. cellA := rowTitle.AddCell()
  1871. cellA.Value = ""
  1872. cellB := rowTitle.AddCell()
  1873. cellB.Value = "公司"
  1874. cellC := rowTitle.AddCell()
  1875. cellC.Value = "权限"
  1876. for _, item := range needAddAttendanc {
  1877. row := sheet.AddRow()
  1878. cellA := row.AddCell()
  1879. cellA.Value = item.CompanyName
  1880. cellB := row.AddCell()
  1881. if item.Permission == "" {
  1882. //item.Permission = "专家/医药/智造/消费/研选/科技/策略/路演服务"
  1883. }
  1884. cellB.Value = item.Permission
  1885. }
  1886. errFile = xlsxFile.Save(downLoadnFilePath)
  1887. if errFile != nil {
  1888. br.Msg = "保存文件失败Err:" + errFile.Error()
  1889. return
  1890. }
  1891. br.Msg = "导入成功"
  1892. br.Ret = 200
  1893. br.Success = true
  1894. }
  1895. // @Title 活动带问
  1896. // @Description 新增活动带问接口
  1897. // @Param request body models.AddCygxActivityHelpAsk true "type json string"
  1898. // @Success Ret=200 新增成功
  1899. // @router /askAdd [post]
  1900. func (this *ActivityCoAntroller) AskAdd() {
  1901. br := new(models.BaseResponse).Init()
  1902. defer func() {
  1903. this.Data["json"] = br
  1904. this.ServeJSON()
  1905. }()
  1906. user := this.User
  1907. if user == nil {
  1908. br.Msg = "请登录"
  1909. br.ErrMsg = "请登录,SysUser Is Empty"
  1910. br.Ret = 408
  1911. return
  1912. }
  1913. var req models.CygxActivityHelpAsk
  1914. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  1915. if err != nil {
  1916. br.Msg = "参数解析异常!"
  1917. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  1918. return
  1919. }
  1920. if req.Content == "" {
  1921. br.Msg = "建议内容不可为空"
  1922. return
  1923. }
  1924. content := req.Content
  1925. itemToken, err := services.WxGetToken()
  1926. if err != nil {
  1927. br.Msg = "GetWxAccessToken Err:" + err.Error()
  1928. return
  1929. }
  1930. if itemToken.AccessToken == "" {
  1931. br.Msg = "accessToken is empty"
  1932. return
  1933. }
  1934. commerr, err := weapp.MSGSecCheck(itemToken.AccessToken, content)
  1935. if err != nil {
  1936. br.Msg = "内容校验失败!"
  1937. br.ErrMsg = "内容校验失败,Err:" + err.Error()
  1938. return
  1939. }
  1940. if commerr.ErrCode != 0 {
  1941. br.Msg = "内容违规,请重新提交!"
  1942. br.ErrMsg = "颜文字内容违规,Err:" + commerr.ErrMSG
  1943. return
  1944. }
  1945. activityId := req.ActivityId
  1946. activityInfo, errInfo := models.GetAddActivityInfoById(activityId)
  1947. if activityInfo == nil {
  1948. br.Msg = "操作失败"
  1949. br.ErrMsg = "活动ID错误,不存在activityId:" + strconv.Itoa(activityId)
  1950. return
  1951. }
  1952. if errInfo != nil {
  1953. br.Msg = "操作失败"
  1954. br.ErrMsg = "操作失败,Err:" + errInfo.Error()
  1955. return
  1956. }
  1957. resultTime := utils.StrTimeToTime(activityInfo.ActivityTime) //时间字符串格式转时间格式
  1958. if activityInfo.ActivityTypeId == 1 && activityInfo.ChartPermissionId != 31 {
  1959. if time.Now().After(resultTime.Add(-time.Minute * 15)) {
  1960. br.Msg = "活动开始前15分钟内无法提交问题"
  1961. return
  1962. }
  1963. } else {
  1964. if time.Now().After(resultTime.Add(-time.Minute * 60)) {
  1965. br.Msg = "活动开始前1小时内无法提交问题"
  1966. return
  1967. }
  1968. }
  1969. companyDetail, err := models.GetCompanyDetailById(user.CompanyId)
  1970. if err != nil {
  1971. br.Msg = "提交失败!"
  1972. br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
  1973. return
  1974. }
  1975. if companyDetail == nil {
  1976. br.Msg = "提交失败!"
  1977. br.ErrMsg = "客户不存在,uid:" + strconv.Itoa(user.UserId)
  1978. return
  1979. }
  1980. item := new(models.CygxActivityHelpAsk)
  1981. item.UserId = user.UserId
  1982. item.ActivityId = req.ActivityId
  1983. item.CompanyId = user.CompanyId
  1984. item.CompanyName = companyDetail.CompanyName
  1985. item.CreateTime = time.Now()
  1986. item.Mobile = user.Mobile
  1987. item.Email = user.Email
  1988. item.Content = content
  1989. _, err = models.AddActivityHelpAsk(item)
  1990. if err != nil {
  1991. br.Msg = "提交失败"
  1992. br.ErrMsg = "提交带问失败,Err:" + err.Error()
  1993. return
  1994. }
  1995. br.Ret = 200
  1996. br.Success = true
  1997. br.Msg = "提交成功"
  1998. }