activity_special.go 42 KB

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