activity_special.go 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038
  1. package services
  2. import (
  3. "context"
  4. "errors"
  5. "fmt"
  6. "hongze/hongze_cygx/models"
  7. "hongze/hongze_cygx/utils"
  8. "strconv"
  9. "strings"
  10. "time"
  11. )
  12. //func init() {
  13. // UpdateCygxActivitySpecialSignupNum()
  14. //}
  15. // 修改专项调研,用户与公司的参与数量
  16. func UpdateCygxActivitySpecialSignupNum(cont context.Context) (err error) {
  17. defer func() {
  18. if err != nil {
  19. fmt.Println(err)
  20. go utils.SendAlarmMsg("修改活动状态至进行中失败"+err.Error(), 2)
  21. go utils.SendEmail(utils.APPNAME+"【"+utils.RunMode+"】"+"失败提醒", "修改活动状态至进行中失败 ErrMsg:"+err.Error(), utils.EmailSendToUsers)
  22. }
  23. }()
  24. //根据手机号分组获取列表以及数量
  25. var condition string
  26. var pars []interface{}
  27. condition += ` AND s.create_time < ? `
  28. pars = append(pars, time.Now().Format(utils.FormatDate))
  29. listSpecial, err := models.GetActivityListSpecialGroupByMobile(condition, pars)
  30. if err != nil {
  31. return err
  32. }
  33. var mapMobile []string
  34. for _, v := range listSpecial {
  35. mapMobile = append(mapMobile, v.Mobile)
  36. }
  37. //根据手机号获取这些用户的信息
  38. userList, err := models.GetWxUserByMobiles(mapMobile)
  39. if err != nil {
  40. return err
  41. }
  42. //更改这些手机对应的关注关注数量
  43. err = models.UpdateActivitySpecialSignupNumMulti(listSpecial)
  44. if err != nil {
  45. return err
  46. }
  47. //更改这些手机对应的公司ID
  48. err = models.UpdateActivitySpecialSignupCompanyIdMulti(userList)
  49. if err != nil {
  50. return err
  51. }
  52. //根据CompanyId分组获取列表以及数量
  53. listSpecialByCompanyId, err := models.GetActivityListSpecialGroupByCompanyId(condition, pars)
  54. if err != nil {
  55. return err
  56. }
  57. //更改这些公司对应的关注关注数量
  58. err = models.UpdateActivitySpecialSignupCompanyNumMulti(listSpecialByCompanyId)
  59. if err != nil {
  60. return err
  61. }
  62. fmt.Println("UpdateCygxActivitySpecialSignupNum end")
  63. return
  64. }
  65. // 处理专项调研的展示
  66. func GetActivityLabelSpecialList(user *models.WxUserItem, isPower int, chartPermissionIds, permissionNameStr string) (item *models.ActivityTypeHome, err error) {
  67. itemList := new(models.ActivityTypeHome)
  68. if user.CompanyId <= 1 {
  69. itemList.List = make([]*models.CygxActivityLabelList, 0)
  70. item = itemList
  71. return
  72. }
  73. userType, e := GetSpecialUserType(user)
  74. if e != nil {
  75. err = errors.New("GetSpecialUserType, Err: " + e.Error())
  76. return
  77. }
  78. if userType == 0 {
  79. itemList.List = make([]*models.CygxActivityLabelList, 0)
  80. item = itemList
  81. return
  82. }
  83. companyDetail, e := models.GetCompanyDetailByIdGroupTrip(user.CompanyId)
  84. if e != nil {
  85. err = errors.New("GetCompanyDetailByIdGroupTrip, Err: " + e.Error())
  86. return
  87. }
  88. //如果是永续的就按照普通的权限逻辑来查,如果不是就按照升级的逻辑来查
  89. var condition string
  90. if companyDetail.Status == "永续" {
  91. condition, e = HandleActivityLabelSpecialPermission(user)
  92. if e != nil {
  93. err = errors.New("HandleActivityLabelSpecialPermission, Err: " + e.Error())
  94. return
  95. }
  96. } else {
  97. condition, e = HandleActivityLabelSpecialTripPermission(user)
  98. if e != nil {
  99. err = errors.New("HandleActivityLabelSpecialPermission, Err: " + e.Error())
  100. return
  101. }
  102. }
  103. var pars []interface{}
  104. condition += ` AND art.publish_status = 1 AND art.label != '' AND art.is_offline = 0 `
  105. //行业名称
  106. if isPower == 1 {
  107. condition += ` AND art.chart_permission_name IN (` + permissionNameStr + `) `
  108. }
  109. if chartPermissionIds != "" {
  110. condition += ` AND art.chart_permission_id IN (` + chartPermissionIds + `) `
  111. }
  112. conditionTrip := condition
  113. conditionTrip += ` AND art.activity_time_end > ` + "'" + time.Now().Format(utils.FormatDateTime) + " '"
  114. conditionTrip += ` AND art.days > 0 ORDER BY art.activity_time ASC `
  115. specialList, err := models.GetActivityLabelSpecialListAll(conditionTrip, pars, 0, 8)
  116. if err != nil {
  117. return
  118. }
  119. //if len(specialList) < 8 {
  120. // conditionTrip += ` AND art.days = 0 ORDER BY art.last_updated_time DESC`
  121. condition += ` AND art.days = 0 ORDER BY art.last_updated_time DESC`
  122. specialListNotrip, e := models.GetActivityLabelSpecialListAll(condition, pars, 0, 20)
  123. if e != nil {
  124. err = e
  125. return
  126. }
  127. for _, v := range specialListNotrip {
  128. specialList = append(specialList, v)
  129. }
  130. //}
  131. for k2, v2 := range specialList {
  132. if v2.Days == 0 {
  133. specialList[k2].TripStatus = 1
  134. } else {
  135. specialList[k2].TripStatus = 2
  136. }
  137. specialList[k2].KeyWord = LabelStrV5(v2.KeyWord, v2.IsShowSubjectName, v2.TemporaryLabel)
  138. specialList[k2].ImgUrlBg = "https://hzstatic.hzinsights.com/static/temp/20220426202204/20220426/XDLLsjC9XAAy8LIzQr7GsjrBbtX6.png"
  139. specialList[k2].ImgUrlBg = utils.ACTIVITY_ZXDY_ImgUrl3
  140. }
  141. itemList.ActivityTypeName = "专项产业调研"
  142. itemList.Resource = 2
  143. itemList.List = specialList
  144. itemList.ActivityTypeId = 7
  145. itemList.ImgUrl = utils.ACTIVITY_ZXDY_ImgUrl1
  146. itemList.ImgUrlBg = utils.ACTIVITY_ZXDY_ImgUrl2
  147. item = itemList
  148. return
  149. }
  150. // HandleActivityLabelSpecialPermission 处理专项产业调研的查询权限sql 永续
  151. func HandleActivityLabelSpecialPermission(user *models.WxUserItem) (condition string, err error) {
  152. permissionStr, e := GetCompanyPermission(user.CompanyId)
  153. if e != nil {
  154. err = errors.New("GetCompanyPermission, Err: " + e.Error())
  155. return
  156. }
  157. userType, e := GetSpecialUserType(user)
  158. if e != nil {
  159. err = errors.New("GetSpecialUserType, Err: " + e.Error())
  160. return
  161. }
  162. slicePer := strings.Split(permissionStr, ",")
  163. var permissionSqlStr string
  164. for _, v := range slicePer {
  165. if userType == 1 {
  166. if !strings.Contains(v, "研选") {
  167. permissionSqlStr += "'" + v + "',"
  168. }
  169. } else {
  170. permissionSqlStr += "'" + v + "',"
  171. }
  172. }
  173. permissionSqlStr = strings.TrimRight(permissionSqlStr, ",")
  174. condition = ` AND art.publish_status = 1 AND art.label != '' AND art.is_offline = 0 `
  175. if permissionSqlStr != "" {
  176. condition += ` AND art.chart_permission_name IN (` + permissionSqlStr + `) `
  177. }
  178. condition += ` AND art.customer_type_ids LIKE '%` + strconv.Itoa(userType) + `%' `
  179. return
  180. }
  181. // HandleActivityLabelSpecialPermisseion 处理专项产业调研的查询权限sql
  182. func HandleActivityLabelSpecialTripPermission(user *models.WxUserItem) (condition string, err error) {
  183. permissionStr, e := GetCompanyPermission(user.CompanyId)
  184. if e != nil {
  185. err = errors.New("GetCompanyPermission, Err: " + e.Error())
  186. return
  187. }
  188. userType, e := GetSpecialUserType(user)
  189. if e != nil {
  190. err = errors.New("GetSpecialUserType, Err: " + e.Error())
  191. return
  192. }
  193. slicePer := strings.Split(permissionStr, ",")
  194. var permissionSqlStr string
  195. for _, v := range slicePer {
  196. if userType == 1 {
  197. if !strings.Contains(v, "研选") {
  198. permissionSqlStr += "'" + v + "',"
  199. }
  200. } else {
  201. permissionSqlStr += "'" + v + "',"
  202. }
  203. }
  204. permissionSqlStr = strings.TrimRight(permissionSqlStr, ",")
  205. condition = ` AND art.publish_status = 1 AND art.label != '' AND art.is_offline = 0 `
  206. if permissionSqlStr != "" {
  207. condition += ` AND art.chart_permission_name IN (` + permissionSqlStr + `) `
  208. }
  209. condition += ` AND art.customer_type_ids LIKE '%` + strconv.Itoa(userType) + `%' `
  210. return
  211. }
  212. // 获取预报名列表
  213. func GetActivitySpecialPrepareList(user *models.WxUserItem, startSize, pageSize int, keywords string) (list []*models.CygxActivitySpecialDetail, totalPrepare int, err error) {
  214. companyDetail, e := models.GetCompanyDetailByIdGroupTrip(user.CompanyId)
  215. if e != nil {
  216. err = errors.New("GetCompanyDetailByIdGroupTrip, Err: " + e.Error())
  217. return
  218. }
  219. //如果是永续的就按照普通的权限逻辑来查,如果不是就按照升级的逻辑来查
  220. var condition string
  221. if companyDetail.Status == "永续" {
  222. condition, e = HandleActivityLabelSpecialPermission(user)
  223. if e != nil {
  224. err = errors.New("HandleActivityLabelSpecialPermission, Err: " + e.Error())
  225. return
  226. }
  227. } else {
  228. condition, e = HandleActivityLabelSpecialTripPermission(user)
  229. if e != nil {
  230. err = errors.New("HandleActivityLabelSpecialPermission, Err: " + e.Error())
  231. return
  232. }
  233. }
  234. var pars []interface{}
  235. condition += ` AND art.days = 0 AND art.publish_status = 1 AND art.is_offline = 0 `
  236. if keywords != "" {
  237. keywords = "%" + keywords + "%"
  238. condition += ` AND art.research_theme LIKE ? `
  239. pars = append(pars, keywords)
  240. }
  241. totalPrepare, e = models.GetActivitySpecialCount(condition, pars)
  242. if e != nil {
  243. err = errors.New("GetActivitySpecialCount, Err: " + e.Error())
  244. return
  245. }
  246. condition += ` ORDER BY art.last_updated_time DESC `
  247. list, e = models.GetCygxActivitySpecialDetailList(condition, pars, user.UserId, startSize, pageSize)
  248. if e != nil {
  249. err = errors.New("GetCygxActivitySpecialDetailList, Err: " + e.Error())
  250. return
  251. }
  252. return
  253. }
  254. /*
  255. 确定行程的查询 GetActivityLabelSpecialConfirmList
  256. state 进行状态 1:未开始,2:进行中,3:已结束,4:未开始、进行中 不传默认查询全部items []*CygxActivitySpecialDetail
  257. */
  258. func GetActivityLabelSpecialConfirmList(user *models.WxUserItem, startSize, pageSize, state int, keywords string) (list []*models.CygxActivitySpecialDetail, totalConfirm int, err error) {
  259. //var condition string
  260. companyDetail, e := models.GetCompanyDetailByIdGroupTrip(user.CompanyId)
  261. if e != nil && e.Error() != utils.ErrNoRow() {
  262. err = errors.New("GetCompanyDetailByIdGroupTrip, Err: " + e.Error())
  263. return
  264. }
  265. if companyDetail == nil {
  266. return
  267. }
  268. //如果是永续的就按照普通的权限逻辑来查,如果不是就按照升级的逻辑来查
  269. var condition string
  270. if companyDetail.Status == "永续" {
  271. condition, e = HandleActivityLabelSpecialPermission(user)
  272. if e != nil {
  273. err = errors.New("HandleActivityLabelSpecialPermission, Err: " + e.Error())
  274. return
  275. }
  276. } else {
  277. condition, e = HandleActivityLabelSpecialTripPermission(user)
  278. if e != nil {
  279. err = errors.New("HandleActivityLabelSpecialPermission, Err: " + e.Error())
  280. return
  281. }
  282. }
  283. var pars []interface{}
  284. condition += ` AND art.days >0 AND art.publish_status =1 AND art.is_offline = 0 `
  285. if state == 1 {
  286. condition += ` AND art.activity_time > ? `
  287. pars = append(pars, time.Now())
  288. }
  289. if state == 2 {
  290. condition += ` AND art.activity_time < ? `
  291. pars = append(pars, time.Now())
  292. condition += ` AND art.activity_time_end > ? `
  293. pars = append(pars, time.Now())
  294. }
  295. if state == 3 {
  296. condition += ` AND art.activity_time_end < ? `
  297. pars = append(pars, time.Now())
  298. }
  299. if state == 4 {
  300. condition += ` AND art.activity_time_end > ? `
  301. pars = append(pars, time.Now())
  302. }
  303. if keywords != "" {
  304. keywords = "%" + keywords + "%"
  305. condition += ` AND art.research_theme LIKE ? `
  306. pars = append(pars, keywords)
  307. }
  308. totalConfirm, e = models.GetActivitySpecialCount(condition, pars)
  309. if e != nil {
  310. err = errors.New("GetActivitySpecialCount, Err: " + e.Error())
  311. return
  312. }
  313. condition += ` ORDER BY art.activity_time ASC `
  314. list, e = models.GetCygxActivitySpecialDetailList(condition, pars, user.UserId, startSize, pageSize)
  315. if e != nil {
  316. err = errors.New("GetCygxActivitySpecialDetailList, Err: " + e.Error())
  317. return
  318. }
  319. var activityIds []int
  320. for k, v := range list {
  321. resultTimeStart := utils.StrTimeToTime(v.ActivityTime) //时间字符串格式转时间格式
  322. resultTimeEnd := utils.StrTimeToTime(v.ActivityTimeEnd) //时间字符串格式转时间格式
  323. if resultTimeStart.After(time.Now()) {
  324. list[k].ActiveState = 1
  325. } else if time.Now().After(resultTimeEnd) {
  326. list[k].ActiveState = 3
  327. } else {
  328. list[k].ActiveState = 2
  329. }
  330. if list[k].Days == 0 {
  331. list[k].TripStatus = 1
  332. } else {
  333. list[k].TripStatus = 2
  334. }
  335. activityIds = append(activityIds, v.ActivityId)
  336. }
  337. //处理用户已经报名了的行程
  338. UserMap, e := GetSpecialTripUserMap(activityIds, user.UserId)
  339. if e != nil {
  340. err = errors.New("GetSpecialTripUserMap, Err: " + e.Error())
  341. return
  342. }
  343. for k, v := range list {
  344. if _, ok := UserMap[v.ActivityId]; ok {
  345. list[k].IsTrip = 1
  346. }
  347. }
  348. return
  349. }
  350. // 获取用户已经报名的活动
  351. func GetSpecialTripUserMap(activityIds []int, userId int) (mapUserId map[int]int, err error) {
  352. var condition string
  353. var pars []interface{}
  354. activityIdsLen := len(activityIds)
  355. if activityIdsLen > 0 {
  356. condition += ` AND activity_id IN (` + utils.GetOrmInReplace(activityIdsLen) + `)`
  357. pars = append(pars, activityIds)
  358. }
  359. condition += ` AND user_id = ? AND is_cancel = 0 `
  360. pars = append(pars, userId)
  361. list, e := models.GetCygxActivitySpecialTripList(condition, pars)
  362. if e != nil {
  363. err = errors.New("GetCygxActivitySpecialTripList, Err: " + e.Error())
  364. return
  365. }
  366. mapUid := make(map[int]int)
  367. for _, v := range list {
  368. mapUid[v.ActivityId] = v.UserId
  369. }
  370. mapUserId = mapUid
  371. return
  372. }
  373. // 获取用户已经报名的活动数量
  374. func GetSpecialTripUserSchedule(userId int) (total int, err error) {
  375. var condition string
  376. var pars []interface{}
  377. condition += ` AND t.user_id = ? AND t.is_cancel = 0 `
  378. pars = append(pars, userId)
  379. condition += ` AND a.activity_time_end >= ? `
  380. pars = append(pars, time.Now())
  381. condition += ` AND is_valid = 1 `
  382. total, err = models.GetActivitySpecialTripCountByActivitySpecial(condition, pars)
  383. return
  384. }
  385. // GetActivitySpecialList 获取专项调研列表
  386. func GetActivitySpecialList(user *models.WxUserItem, currentIndex, pageSize int, keywords string) (list []*models.CygxActivitySpecialDetail, total int, err error) {
  387. listConfirm, totalConfirm, e := GetActivityLabelSpecialConfirmList(user, (currentIndex-1)*pageSize, pageSize, 4, keywords)
  388. if e != nil && e.Error() != utils.ErrNoRow() {
  389. err = errors.New("GetActivityLabelSpecialConfirmList11, Err: " + e.Error())
  390. return
  391. }
  392. if totalConfirm == 0 {
  393. return
  394. }
  395. if currentIndex == 1 && len(listConfirm) > 0 {
  396. listConfirm[0].Explain = utils.ACtIVITY_SPECIAL_TRIP_EXPLAIN
  397. }
  398. list = listConfirm
  399. total = totalConfirm
  400. var startSizePrepare, pageSizePrepare int
  401. //全是确定行程的查询数据
  402. if totalConfirm >= currentIndex*pageSize {
  403. startSizePrepare = 0
  404. pageSizePrepare = 0
  405. } else if totalConfirm > (currentIndex-1)*pageSize && totalConfirm < currentIndex*pageSize {
  406. //一半确认行程一半预报名
  407. startSizePrepare = 0
  408. pageSizePrepare = pageSize - len(listConfirm)
  409. } else {
  410. //全是预报名
  411. startSizePrepare = (currentIndex-1)*pageSize - totalConfirm
  412. pageSizePrepare = pageSize - len(listConfirm)
  413. }
  414. listPrepare, totalPrepare, e := GetActivitySpecialPrepareList(user, startSizePrepare, pageSizePrepare, keywords)
  415. if e != nil {
  416. err = errors.New("GetActivityLabelSpecialConfirmList, Err: " + e.Error())
  417. return
  418. }
  419. if len(listPrepare) > 0 {
  420. for _, v := range listPrepare {
  421. list = append(list, v)
  422. }
  423. if startSizePrepare == 0 {
  424. listPrepare[0].Explain = utils.ACtIVITY_SPECIAL_EXPLAIN
  425. }
  426. }
  427. total = totalConfirm + totalPrepare
  428. //处理封面图片
  429. detail, e := models.GetConfigByCode("city_img_url")
  430. if e != nil {
  431. err = errors.New("GetConfigByCode, Err: " + e.Error())
  432. return
  433. }
  434. detailChart, e := models.GetConfigByCode("chart_img_url")
  435. if e != nil {
  436. err = errors.New("GetConfigByCode, Err: " + e.Error())
  437. return
  438. }
  439. addressList := strings.Split(detail.ConfigValue, "{|}")
  440. mapAddress := make(map[string]string)
  441. chartList := strings.Split(detailChart.ConfigValue, "{|}")
  442. mapChart := make(map[string]string)
  443. var cityName string
  444. var chartName string
  445. var imgUrl string
  446. var imgUrlChart string
  447. for _, v := range addressList {
  448. vslice := strings.Split(v, "_")
  449. cityName = vslice[0]
  450. imgUrl = vslice[len(vslice)-1]
  451. mapAddress[cityName] = imgUrl
  452. }
  453. for _, v := range chartList {
  454. vslice := strings.Split(v, "_")
  455. chartName = vslice[0]
  456. imgUrlChart = vslice[len(vslice)-1]
  457. mapChart[chartName] = imgUrlChart
  458. }
  459. for k, v := range list {
  460. //list[k].ImgUrlText = "https://hongze.oss-cn-shanghai.aliyuncs.com/static/images/202112/20211221/bIdfv8t86xrFRpDOeGGHXOmKEuKl.png"
  461. if mapChart[v.ChartPermissionName] != "" {
  462. list[k].ImgUrl = mapChart[v.ChartPermissionName]
  463. }
  464. list[k].ActivityTypeName = "专项调研"
  465. if list[k].Days == 0 {
  466. list[k].TripStatus = 1
  467. } else {
  468. list[k].TripStatus = 2
  469. list[k].TripImgLink = list[k].TripImgLinkFix
  470. }
  471. }
  472. return
  473. }
  474. // HandleActivitySpecialShow 处理活动的状态
  475. func HandleActivitySpecialShow(activityDetail *models.CygxActivitySpecialDetail, user *models.WxUserItem) (item *models.CygxActivitySpecialDetail, err error) {
  476. var activityIds []int
  477. resultTimeStart := utils.StrTimeToTime(activityDetail.ActivityTime) //时间字符串格式转时间格式
  478. resultTimeEnd := utils.StrTimeToTime(activityDetail.ActivityTimeEnd) //时间字符串格式转时间格式
  479. if resultTimeStart.After(time.Now()) {
  480. activityDetail.ActiveState = 1
  481. } else if time.Now().After(resultTimeEnd) {
  482. activityDetail.ActiveState = 3
  483. } else {
  484. activityDetail.ActiveState = 2
  485. }
  486. activityIds = append(activityIds, activityDetail.ActivityId)
  487. //处理用户已经报名了的行程
  488. UserMap, e := GetSpecialTripUserMap(activityIds, user.UserId)
  489. if e != nil {
  490. err = errors.New("GetSpecialTripUserMap, Err: " + e.Error())
  491. return
  492. }
  493. if activityDetail.Days == 0 {
  494. activityDetail.TripStatus = 1
  495. activityDetail.Explain = utils.ACtIVITY_SPECIAL_EXPLAIN
  496. } else {
  497. activityDetail.TripStatus = 2
  498. activityDetail.TripImgLink = activityDetail.TripImgLinkFix
  499. activityDetail.Explain = utils.ACtIVITY_SPECIAL_TRIP_EXPLAIN
  500. }
  501. if _, ok := UserMap[activityDetail.ActivityId]; ok {
  502. activityDetail.IsTrip = 1
  503. }
  504. item = activityDetail
  505. return
  506. }
  507. // 活动与专项调研搜索 GetActivitySpecialSearcheList
  508. func GetActivitySpecialSearcheList(user *models.WxUserItem, condition string, startSize, pageSize int, keywords string) (items []*models.ActivityDetail, total int, err error) {
  509. var conditionSpecil string
  510. var pars, parsSpecil []interface{}
  511. keyword := keywords
  512. if keywords != "" {
  513. keywords = "%" + keywords + "%"
  514. conditionSpecil += ` AND art.days > 0 AND (art.research_theme LIKE ? OR art.label LIKE ? OR art.industrial_name LIKE ? OR art.industrial_subject_name LIKE ? ) `
  515. parsSpecil = append(parsSpecil, keywords, keywords, keywords, keywords)
  516. }
  517. list, totalSearche, e := models.GetActivitySpecialSearcheList(condition, pars, conditionSpecil, parsSpecil, startSize, pageSize)
  518. if e != nil {
  519. err = errors.New("GetActivitySpecialSearcheList, Err: " + e.Error())
  520. return
  521. }
  522. keyWordArr, e := GetIndustryMapNameSliceV3(keywords)
  523. if e != nil {
  524. err = errors.New("GetActivityonditionList, Err: " + e.Error())
  525. return
  526. }
  527. var totalIk int
  528. if len(keyWordArr) > 1 {
  529. // 查询IK分词后那一部分的数据
  530. conditionActivityIk, e := GetActivityonditionList(user, "", "", "", "", "", 0, 1, keyword, 0, 2)
  531. if e != nil && e.Error() != utils.ErrNoRow() {
  532. err = errors.New("GetActivityonditionList, Err: " + e.Error())
  533. return
  534. }
  535. conditionActivityIk += " AND art.is_limit_people = 1 AND art.publish_status = 1 "
  536. totalIk, e = models.GetActivityCount(conditionActivityIk, 0, pars, 0)
  537. if e != nil {
  538. err = errors.New("GetActivityonditionList, Err: " + e.Error())
  539. return
  540. }
  541. keyWordArr = RemoveDuplicatesAndEmpty(keyWordArr)
  542. startSizeIk := startSize - totalSearche
  543. if startSizeIk < 0 {
  544. startSizeIk = 0
  545. }
  546. var pageSizeIk int
  547. pageSizeIk = pageSize - len(list)
  548. if pageSizeIk > 0 {
  549. //搜索关键词联想
  550. conditionActivityIk += ` ORDER BY art.activity_time DESC , art.active_state ASC `
  551. listIk, e := models.GetActivityListNew(conditionActivityIk, pars, user.UserId, startSizeIk, pageSizeIk, 0, 0, "")
  552. if e != nil {
  553. err = errors.New("GetActivityonditionList, Err: " + e.Error())
  554. return
  555. }
  556. for _, item := range listIk {
  557. list = append(list, item)
  558. }
  559. }
  560. }
  561. total = totalSearche + totalIk
  562. items, e = HandleActivityListButton(list, user)
  563. if e != nil {
  564. err = errors.New("HandleActivityListButton, Err: " + e.Error())
  565. return
  566. }
  567. return
  568. }
  569. // 获取 专项调研客户类型 //1、永续客户 //2、大套餐客户(4个行业全开通的正式客户) //8、行业升级套餐客户 //9、其余正式客户;5、试用客户
  570. func GetActivitySpecialUserType(companyId int) (userType int, permissionStrnew string, err error) {
  571. var permissionStr string
  572. if companyId <= 1 {
  573. userType = 0
  574. } else {
  575. total, e := models.GetCountCompanyDetailByIdGroupTrip(companyId)
  576. if e != nil {
  577. err = errors.New("GetCountCompanyDetailByIdGroupTrip, Err: " + e.Error())
  578. return
  579. }
  580. if total == 0 {
  581. userType = 0
  582. } else {
  583. companyDetail, e := models.GetCompanyDetailByIdGroupTrip(companyId)
  584. if e != nil {
  585. err = errors.New("GetCompanyDetailByIdGroupTrip, Err: " + e.Error())
  586. return
  587. }
  588. permissionStr, e = models.GetCompanyPermissionByUserTrip(companyId)
  589. if e != nil {
  590. err = errors.New("GetCompanyPermissionByUserTrip, Err: " + e.Error())
  591. return
  592. }
  593. //permissionZhengShiStr, e = models.GetCompanyPermissionByUserZhengShiTrip(companyId)
  594. //if e != nil {
  595. // err = errors.New("GetCompanyPermissionByUserZhengShiTrip, Err: " + e.Error())
  596. // return
  597. //}
  598. //大套餐客户定义:医药、消费、科技、智造。4个行业中为升级,策略是正式,属于大套餐客户
  599. if companyDetail.Status == "永续" {
  600. userType = 1
  601. } else if companyDetail.Status == "试用" {
  602. userType = 5
  603. } else if companyDetail.Status == "正式" {
  604. if permissionStr == "专家" {
  605. userType = 4
  606. } else if strings.Count(permissionStr, "医药") == 2 && strings.Count(permissionStr, "消费") == 2 && strings.Count(permissionStr, "科技") == 2 && strings.Count(permissionStr, "智造") == 2 && strings.Count(permissionStr, "策略") == 1 {
  607. userType = 2
  608. } else {
  609. userType = 3
  610. }
  611. if userType == 3 {
  612. if !strings.Contains(permissionStr, "医药") && !strings.Contains(permissionStr, "消费") && !strings.Contains(permissionStr, "科技") && !strings.Contains(permissionStr, "智造") {
  613. userType = 4
  614. }
  615. }
  616. } else if companyDetail.Status == "冻结" {
  617. userType = 6
  618. } else if companyDetail.Status == "流失" {
  619. userType = 7
  620. }
  621. }
  622. }
  623. permissionStrnew = permissionStr
  624. return
  625. }
  626. // GetSpecialUserType 获取专项产业调研的用户身份类型
  627. // 获取 专项调研客户类型 //1、永续客户 //2、大套餐客户(4个行业全开通的正式客户) //8、行业升级套餐客户 //9、其余正式客户;5、试用客户
  628. func GetSpecialUserType(user *models.WxUserItem) (userType int, err error) {
  629. companyId := user.CompanyId
  630. companyDetail, e := models.GetCompanyDetailByIdGroupTrip(companyId)
  631. if e != nil && e.Error() != utils.ErrNoRow() {
  632. err = errors.New("GetCompanyDetailByIdGroupTrip, Err: " + e.Error())
  633. return
  634. }
  635. if companyDetail == nil {
  636. return
  637. }
  638. if companyId <= 1 {
  639. userType = 0
  640. } else {
  641. if companyDetail.Status == "永续" {
  642. userType = 1
  643. } else {
  644. if companyDetail.Status == "正式" {
  645. list, e := models.GetCompanyReportPermissionUpgrade(companyId, 2)
  646. if e != nil && e.Error() != utils.ErrNoRow() {
  647. err = errors.New("GetCompanyReportPermissionUpgrade, Err: " + e.Error())
  648. }
  649. if len(list) == 0 {
  650. userType = 9
  651. }
  652. if len(list) == 4 {
  653. totalName, e := models.GetCompanyPermissionNameCheck(companyId, 2, "策略")
  654. if e != nil {
  655. err = errors.New("获取品种信息失败, Err:" + e.Error())
  656. return
  657. }
  658. if totalName > 0 {
  659. userType = 2
  660. } else {
  661. userType = 8
  662. }
  663. } else {
  664. userType = 8
  665. }
  666. } else if companyDetail.Status == "试用" {
  667. userType = 5
  668. }
  669. }
  670. }
  671. return
  672. }
  673. // GetSpecialDetailUserPower 处理用户查看专项调研详情的权限
  674. func GetSpecialDetailUserPower(user *models.WxUserItem, activityInfo *models.CygxActivitySpecialDetail) (havePower bool, err error) {
  675. permissionStr, e := GetCompanyPermissionUpgrade(user.CompanyId)
  676. if e != nil {
  677. err = errors.New("GetCompanyPermissionUpgrade, Err: " + e.Error())
  678. return
  679. }
  680. fmt.Println(permissionStr)
  681. //如果没有对应的升级权限,则返回
  682. if !strings.Contains(permissionStr, activityInfo.ChartPermissionName) {
  683. return
  684. }
  685. userType, e := GetSpecialUserType(user)
  686. if e != nil {
  687. err = errors.New("GetSpecialUserType, Err: " + e.Error())
  688. return
  689. }
  690. if userType == 0 {
  691. return
  692. }
  693. var pars []interface{}
  694. var condition string
  695. var userTypes string
  696. condition += ` AND art.publish_status = 1 AND art.is_offline = 0 `
  697. userTypes = "%" + strconv.Itoa(userType) + "%"
  698. condition += ` AND art.customer_type_ids LIKE ? `
  699. pars = append(pars, userTypes)
  700. condition += ` AND art.activity_id = ? `
  701. pars = append(pars, activityInfo.ActivityId)
  702. total, e := models.GetActivitySpecialCount(condition, pars)
  703. if e != nil {
  704. err = errors.New("GetSpecialUserType, Err: " + e.Error())
  705. return
  706. }
  707. if total == 1 {
  708. havePower = true
  709. }
  710. return
  711. }
  712. // 预报名活动,感兴趣人数满10人时,推送给活动负责人和王芳
  713. func SendWxMsgActivitySpecial10(activityInfo *models.CygxActivitySpecialDetail) (err error) {
  714. activityId := activityInfo.ActivityId
  715. var msg string
  716. defer func() {
  717. if err != nil {
  718. go utils.SendEmail("发送模版消息失败"+"【"+utils.APPNAME+"】"+time.Now().Format("2006-01-02 15:04:05"), msg+";Err:"+err.Error(), utils.EmailSendToUsers)
  719. go utils.SendAlarmMsg(fmt.Sprint("预报名活动,感兴趣人数满10人时,推送给活动负责人和王芳消息发送失败", activityInfo.ResearchTheme, ", activityId"), 2)
  720. utils.FileLog.Info("发送模版消息失败,Err:%s", err.Error())
  721. }
  722. }()
  723. var first string
  724. var keyword1 string
  725. var keyword2 string
  726. var keyword3 string
  727. var keyword4 string
  728. var remark string
  729. adminUser, e := models.GetSellerByAdminId(activityInfo.AdminId)
  730. if e != nil {
  731. err = errors.New("GetSellerByAdminId, Err: " + e.Error())
  732. return
  733. }
  734. cnf, _ := models.GetConfigByCode("tpl_msg")
  735. mobile := adminUser.Mobile + "," + cnf.ConfigValue
  736. specialSignupList, e := models.GetActivityListSpecialByActivityId(activityId)
  737. if e != nil {
  738. err = errors.New("GetActivityListSpecialAll, Err: " + e.Error())
  739. return
  740. }
  741. for _, v := range specialSignupList {
  742. keyword1 += "【" + v.RealName + "--" + v.CompanyName + "】"
  743. }
  744. openIdList, e := models.GetWxOpenIdByMobileList(mobile)
  745. if e != nil {
  746. err = errors.New("GetSellerByAdminId, Err: " + e.Error())
  747. return
  748. }
  749. first = "【" + activityInfo.ResearchTheme + "】已有10人预报名"
  750. keyword3 = "-"
  751. keyword2 = "-"
  752. keyword4 = activityInfo.ResearchTheme
  753. openIdArr := make([]string, 0)
  754. for _, v := range openIdList {
  755. openIdArr = append(openIdArr, v.OpenId)
  756. }
  757. redirectUrl := utils.WX_MSG_PATH_ACTIVITY_SPECIAL_DETAIL + strconv.Itoa(activityId)
  758. sendInfo := new(SendWxTemplate)
  759. sendInfo.First = first
  760. sendInfo.Keyword1 = keyword1
  761. sendInfo.Keyword2 = keyword2
  762. sendInfo.Keyword3 = keyword3
  763. sendInfo.Keyword4 = keyword4
  764. sendInfo.Remark = remark
  765. sendInfo.TemplateId = utils.WxMsgTemplateIdAskMsgXzs
  766. sendInfo.RedirectUrl = redirectUrl
  767. sendInfo.RedirectTarget = 3
  768. sendInfo.Resource = strconv.Itoa(activityId)
  769. sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ARTICLE_ADD
  770. sendInfo.OpenIdArr = openIdArr
  771. err = PublicSendTemplateMsg(sendInfo)
  772. if err != nil {
  773. return
  774. }
  775. return
  776. }
  777. // SendWxMsgActivitySpecialTwoDays 活动开始前两天08:00,提醒报名客户 \提醒报名客户的对口销售
  778. func SendWxMsgActivitySpecialTwoDays(cont context.Context) (err error) {
  779. var msg string
  780. defer func() {
  781. if err != nil {
  782. fmt.Println(err)
  783. go utils.SendEmail("发送模版消息失败"+"【"+utils.APPNAME+"】"+time.Now().Format("2006-01-02 15:04:05"), msg+";Err:"+err.Error(), utils.EmailSendToUsers)
  784. go utils.SendAlarmMsg(fmt.Sprint(" 活动开始前两天08:00,提醒报名客户、提醒报名客户的对口销售消息发送失败"), 2)
  785. utils.FileLog.Info("发送模版消息失败,Err:%s", err.Error())
  786. }
  787. }()
  788. twoDayTime := time.Now().AddDate(0, 0, 2)
  789. startTime := twoDayTime.Format(utils.FormatDate) + " 00:00:00"
  790. endTime := twoDayTime.Format(utils.FormatDate) + " 23:59:59"
  791. var condition string
  792. var pars []interface{}
  793. condition = ` AND days >0 AND activity_time BETWEEN ? AND ? `
  794. pars = append(pars, startTime, endTime)
  795. listActivitySpecial, e := models.GetActivitySpecialListAll(condition, pars, 0, 1000)
  796. if e != nil {
  797. err = errors.New("GetSellerByAdminId, Err: " + e.Error())
  798. return
  799. }
  800. if len(listActivitySpecial) == 0 {
  801. return
  802. }
  803. var activityIds []int
  804. for _, v := range listActivitySpecial {
  805. activityIds = append(activityIds, v.ActivityId)
  806. condition = ` AND is_cancel = 0 AND activity_id = ` + strconv.Itoa(v.ActivityId)
  807. pars = make([]interface{}, 0)
  808. listSpecialTrip, e := models.GetCygxActivitySpecialTripList(condition, pars)
  809. if e != nil {
  810. err = errors.New("GetCygxActivitySpecialTripList, Err: " + e.Error())
  811. return
  812. }
  813. if len(listSpecialTrip) == 0 {
  814. return
  815. }
  816. var mobile string
  817. var companyIds []int
  818. for _, vT := range listSpecialTrip {
  819. mobile += "'" + vT.Mobile + "',"
  820. companyIds = append(companyIds, vT.CompanyId)
  821. }
  822. mobile = strings.TrimRight(mobile, ",")
  823. openIdList, e := models.GetWxOpenIdByMobileList(mobile)
  824. if e != nil {
  825. err = errors.New("GetSellerByAdminId, Err: " + e.Error())
  826. return
  827. }
  828. first := "【" + v.ResearchTheme + "】专项调研将在两天后进行,如不能参加,请及时取消报名"
  829. keyword1 := v.ResearchTheme
  830. keyword2 := "已报名"
  831. keyword3 := v.ActivityTimeTextByDay
  832. keyword4 := "线上"
  833. if v.SpecialType == 2 {
  834. keyword4 = v.City
  835. }
  836. remark := "点击查看活动详情"
  837. SendWxMsgWithFrequencySpecial(first, keyword1, keyword2, keyword3, keyword4, remark, openIdList, v.ActivityId)
  838. //活动开始前两天08:00,提醒报名客户的对口销售
  839. companyIdsLen := len(companyIds)
  840. if companyIdsLen == 0 {
  841. continue
  842. } else {
  843. pars = make([]interface{}, 0)
  844. condition = ` AND p.company_id IN (` + utils.GetOrmInReplace(companyIdsLen) + `) GROUP BY p.company_id `
  845. pars = append(pars, companyIds)
  846. listSeller, e := models.GetAdminOpendidByCompany(condition, pars)
  847. if e != nil && e.Error() != utils.ErrNoRow() {
  848. err = errors.New("GetAdminOpendidByCompany, Err: " + e.Error())
  849. return
  850. }
  851. if len(listSeller) == 0 {
  852. continue
  853. }
  854. type SllerData struct {
  855. Openid string `description:"Openid"`
  856. Keyword string `description:"Keyword "`
  857. }
  858. mapSller := make(map[string]string)
  859. mapSllerOpenid := make(map[string]string)
  860. for _, vS := range listSeller {
  861. for _, vT := range listSpecialTrip {
  862. if vT.CompanyId == vS.CompanyId {
  863. mapSller[vS.Mobile] += "【" + vT.RealName + "--" + vT.CompanyName + "】"
  864. mapSllerOpenid[vS.Mobile] = vS.OpenId
  865. }
  866. }
  867. }
  868. for k, vM := range mapSller {
  869. first = "【" + v.ResearchTheme + "】专项调研将在两天后进行,请及时提醒您的报名客户"
  870. keyword2 = vM
  871. openIdList = make([]*models.OpenIdList, 0)
  872. openIdList = append(openIdList, &models.OpenIdList{OpenId: mapSllerOpenid[k]})
  873. SendWxMsgWithFrequencySpecial(first, keyword1, keyword2, keyword3, keyword4, remark, openIdList, v.ActivityId)
  874. }
  875. }
  876. }
  877. return
  878. }
  879. // SendWxMsgActivitySpecialCancel 线下活动前4天08:00报名人数不足7人,线上活动前3天08:00报名人数不足10人,活动自动取消发布,并推送模板消息至报名客户及对口销售
  880. func SendWxMsgActivitySpecialCancel(cont context.Context) (err error) {
  881. var msg string
  882. defer func() {
  883. if err != nil {
  884. fmt.Println(err)
  885. go utils.SendEmail("发送模版消息失败"+"【"+utils.APPNAME+"】"+time.Now().Format("2006-01-02 15:04:05"), msg+";Err:"+err.Error(), utils.EmailSendToUsers)
  886. go utils.SendAlarmMsg(fmt.Sprint(" 活动开始前两天08:00,提醒报名客户、提醒报名客户的对口销售消息发送失败"), 2)
  887. utils.FileLog.Info("发送模版消息失败,Err:%s", err.Error())
  888. }
  889. }()
  890. dayTime3 := time.Now().AddDate(0, 0, 3)
  891. startTime := dayTime3.Format(utils.FormatDate) + " 00:00:00"
  892. endTime := dayTime3.Format(utils.FormatDate) + " 23:59:59"
  893. dayTime4 := time.Now().AddDate(0, 0, 4)
  894. startTime4 := dayTime4.Format(utils.FormatDate) + " 00:00:00"
  895. endTime4 := dayTime4.Format(utils.FormatDate) + " 23:59:59"
  896. var condition string
  897. var pars []interface{}
  898. condition = ` AND days >0 AND activity_time BETWEEN ? AND ? AND special_type= 1 `
  899. pars = append(pars, startTime, endTime)
  900. condition += ` OR ( days >0 AND activity_time BETWEEN ? AND ? AND special_type= 2 ) `
  901. pars = append(pars, startTime4, endTime4)
  902. listActivitySpecial, e := models.GetActivitySpecialListAll(condition, pars, 0, 1000)
  903. if e != nil {
  904. err = errors.New("GetSellerByAdminId, Err: " + e.Error())
  905. return
  906. }
  907. if len(listActivitySpecial) == 0 {
  908. return
  909. }
  910. var activityIds []int
  911. for _, v := range listActivitySpecial {
  912. activityIds = append(activityIds, v.ActivityId)
  913. condition = ` AND is_cancel = 0 AND activity_id = ` + strconv.Itoa(v.ActivityId)
  914. pars = make([]interface{}, 0)
  915. listSpecialTrip, e := models.GetCygxActivitySpecialTripList(condition, pars)
  916. if e != nil {
  917. err = errors.New("GetCygxActivitySpecialTripList, Err: " + e.Error())
  918. return
  919. }
  920. if v.SpecialType == 1 {
  921. if len(listSpecialTrip) >= 10 {
  922. continue
  923. }
  924. }
  925. if v.SpecialType == 2 {
  926. if len(listSpecialTrip) >= 7 {
  927. continue
  928. }
  929. }
  930. e = models.UpdateActivitySpecialPublishStatus(0, v.ActivityId)
  931. if e != nil {
  932. err = errors.New("UpdateActivitySpecialPublishStatus,自动取消专项调研日程失败 Err: " + e.Error() + strconv.Itoa(v.ActivityId))
  933. return
  934. }
  935. if len(listSpecialTrip) < 0 {
  936. return
  937. }
  938. var mobile string
  939. var companyIds []int
  940. for _, vT := range listSpecialTrip {
  941. mobile += "'" + vT.Mobile + "',"
  942. companyIds = append(companyIds, vT.CompanyId)
  943. }
  944. mobile = strings.TrimRight(mobile, ",")
  945. openIdList, e := models.GetWxOpenIdByMobileList(mobile)
  946. if e != nil {
  947. err = errors.New("GetSellerByAdminId, Err: " + e.Error())
  948. return
  949. }
  950. first := "【" + v.ResearchTheme + "】专项调研因专家安排变动,本次调研活动延期举办,具体时间另行通知"
  951. keyword1 := v.ResearchTheme
  952. keyword2 := "已取消"
  953. keyword3 := ""
  954. keyword4 := ""
  955. remark := ""
  956. openIdArr := make([]string, 0)
  957. for _, vOpenid := range openIdList {
  958. openIdArr = append(openIdArr, vOpenid.OpenId)
  959. }
  960. companyIdsLen := len(companyIds)
  961. if len(companyIds) > 0 {
  962. pars = make([]interface{}, 0)
  963. condition = ` AND p.company_id IN (` + utils.GetOrmInReplace(companyIdsLen) + `) GROUP BY p.company_id `
  964. pars = append(pars, companyIds)
  965. listSeller, e := models.GetAdminOpendidByCompany(condition, pars)
  966. if e != nil && e.Error() != utils.ErrNoRow() {
  967. err = errors.New("GetAdminOpendidByCompany, Err: " + e.Error())
  968. return
  969. }
  970. if len(listSeller) > 0 {
  971. for _, vOpenid := range listSeller {
  972. openIdArr = append(openIdArr, vOpenid.OpenId)
  973. }
  974. }
  975. }
  976. redirectUrl := ""
  977. sendInfo := new(SendWxTemplate)
  978. sendInfo.First = first
  979. sendInfo.Keyword1 = keyword1
  980. sendInfo.Keyword2 = keyword2
  981. sendInfo.Keyword3 = keyword3
  982. sendInfo.Keyword4 = keyword4
  983. sendInfo.Remark = remark
  984. sendInfo.TemplateId = utils.WxMsgTemplateIdArticleUserRemind
  985. sendInfo.RedirectUrl = redirectUrl
  986. sendInfo.RedirectTarget = 3
  987. sendInfo.Resource = strconv.Itoa(v.ActivityId)
  988. sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ARTICLE_ADD
  989. sendInfo.OpenIdArr = openIdArr
  990. fmt.Println(sendInfo)
  991. err = PublicSendTemplateMsg(sendInfo)
  992. }
  993. return
  994. }