activity_special.go 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265
  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 != "" && userType == 3 {
  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 && e.Error() != utils.ErrNoRow() {
  419. err = errors.New("GetCompanyDetailByIdGroupTrip, Err: " + e.Error())
  420. return
  421. }
  422. if companyDetail == nil {
  423. return
  424. }
  425. //如果是永续的就按照普通的权限逻辑来查,如果不是就按照升级的逻辑来查
  426. var condition string
  427. var conditionUser string
  428. //var userType int
  429. if companyDetail.Status == "永续" {
  430. conditionUser, e = HandleActivityLabelSpecialPermission(user)
  431. if e != nil {
  432. err = errors.New("HandleActivityLabelSpecialPermission, Err: " + e.Error())
  433. return
  434. }
  435. } else {
  436. conditionUser, _, e = HandleActivityLabelSpecialTripPermission(user)
  437. if e != nil {
  438. err = errors.New("HandleActivityLabelSpecialPermission, Err: " + e.Error())
  439. return
  440. }
  441. }
  442. var pars []interface{}
  443. condition += ` AND art.days >0 AND art.publish_status =1 AND art.is_offline = 0 `
  444. if state == 1 {
  445. condition += ` AND art.activity_time > '` + time.Now().Format(utils.FormatDateTime) + `'`
  446. }
  447. if state == 2 {
  448. condition += ` AND art.activity_time < '` + time.Now().Format(utils.FormatDateTime) + `'`
  449. condition += ` AND art.activity_time_end > '` + time.Now().Format(utils.FormatDateTime) + `'`
  450. }
  451. if state == 3 {
  452. condition += ` AND art.activity_time_end < '` + time.Now().Format(utils.FormatDateTime) + `'`
  453. }
  454. if state == 4 {
  455. condition += ` AND art.activity_time_end > '` + time.Now().Format(utils.FormatDateTime) + `'`
  456. }
  457. if keywords != "" {
  458. keywords = "%" + keywords + "%"
  459. condition += ` AND art.research_theme LIKE ` + keywords
  460. //pars = append(pars, keywords)
  461. }
  462. conditionTrip := condition
  463. conditionTripSql := condition
  464. conditionShengji, conditionZhengshi, conditionHangYe, e := ActivityLabelSpecialUserSql(user)
  465. if e != nil {
  466. err = errors.New("ActivityLabelSpecialUserSql, Err: " + e.Error())
  467. return
  468. }
  469. conditionTrip += ` AND art.days > 0 AND art.activity_time_end > '` + time.Now().Format(utils.FormatDateTime) + ` '`
  470. var conditionZhengshiTrip string
  471. var conditionShengjiTrip string
  472. var conditionHangYeTrip string
  473. //处理专项调研确认行程的其它正式客户权限查询
  474. if conditionZhengshi != "" {
  475. conditionZhengshiTrip = ` OR ( ` + conditionZhengshi + conditionTrip + ` )`
  476. }
  477. //处理专项调研确认行程的升级权限查询
  478. if conditionShengji != "" {
  479. conditionShengjiTrip = ` OR ( ` + conditionShengji + conditionTrip + ` )`
  480. }
  481. //处理行业套餐客户权限查询
  482. if conditionHangYe != "" {
  483. conditionHangYeTrip = ` OR ( ` + conditionHangYe + conditionTrip + ` )`
  484. }
  485. if conditionZhengshi != "" {
  486. conditionTrip += conditionZhengshiTrip
  487. }
  488. if conditionShengjiTrip != "" {
  489. conditionTrip += conditionShengjiTrip
  490. }
  491. if conditionHangYeTrip != "" {
  492. conditionTrip += conditionHangYeTrip
  493. }
  494. conditionTripSql += conditionUser + conditionTrip + ` ORDER BY art.activity_time ASC `
  495. totalConfirm, e = models.GetActivitySpecialCount(conditionTripSql, pars)
  496. if e != nil {
  497. err = errors.New("GetActivitySpecialCount, Err: " + e.Error())
  498. return
  499. }
  500. condition += ` ORDER BY art.activity_time ASC `
  501. list, e = models.GetCygxActivitySpecialDetailList(conditionTripSql, pars, user.UserId, startSize, pageSize)
  502. if e != nil {
  503. err = errors.New("GetCygxActivitySpecialDetailList, Err: " + e.Error())
  504. return
  505. }
  506. var activityIds []int
  507. for k, v := range list {
  508. resultTimeStart := utils.StrTimeToTime(v.ActivityTime) //时间字符串格式转时间格式
  509. resultTimeEnd := utils.StrTimeToTime(v.ActivityTimeEnd) //时间字符串格式转时间格式
  510. if resultTimeStart.After(time.Now()) {
  511. list[k].ActiveState = 1
  512. } else if time.Now().After(resultTimeEnd) {
  513. list[k].ActiveState = 3
  514. } else {
  515. list[k].ActiveState = 2
  516. }
  517. if list[k].Days == 0 {
  518. list[k].TripStatus = 1
  519. } else {
  520. list[k].TripStatus = 2
  521. }
  522. activityIds = append(activityIds, v.ActivityId)
  523. }
  524. //处理用户已经报名了的行程
  525. UserMap, e := GetSpecialTripUserMap(activityIds, user.UserId)
  526. if e != nil {
  527. err = errors.New("GetSpecialTripUserMap, Err: " + e.Error())
  528. return
  529. }
  530. for k, v := range list {
  531. if _, ok := UserMap[v.ActivityId]; ok {
  532. list[k].IsTrip = 1
  533. }
  534. }
  535. return
  536. }
  537. // 获取用户已经报名的活动
  538. func GetSpecialTripUserMap(activityIds []int, userId int) (mapUserId map[int]int, err error) {
  539. var condition string
  540. var pars []interface{}
  541. activityIdsLen := len(activityIds)
  542. if activityIdsLen > 0 {
  543. condition += ` AND activity_id IN (` + utils.GetOrmInReplace(activityIdsLen) + `)`
  544. pars = append(pars, activityIds)
  545. }
  546. condition += ` AND user_id = ? AND is_cancel = 0 `
  547. pars = append(pars, userId)
  548. list, e := models.GetCygxActivitySpecialTripList(condition, pars)
  549. if e != nil {
  550. err = errors.New("GetCygxActivitySpecialTripList, Err: " + e.Error())
  551. return
  552. }
  553. mapUid := make(map[int]int)
  554. for _, v := range list {
  555. mapUid[v.ActivityId] = v.UserId
  556. }
  557. mapUserId = mapUid
  558. return
  559. }
  560. // 获取用户已经报名的活动数量
  561. func GetSpecialTripUserSchedule(userId int) (total int, err error) {
  562. var condition string
  563. var pars []interface{}
  564. condition += ` AND t.user_id = ? AND t.is_cancel = 0 `
  565. pars = append(pars, userId)
  566. condition += ` AND a.activity_time_end >= ? `
  567. pars = append(pars, time.Now())
  568. condition += ` AND is_valid = 1 `
  569. total, err = models.GetActivitySpecialTripCountByActivitySpecial(condition, pars)
  570. return
  571. }
  572. // GetActivitySpecialList 获取专项调研列表
  573. func GetActivitySpecialList(user *models.WxUserItem, currentIndex, pageSize int, keywords string) (list []*models.CygxActivitySpecialDetail, total int, err error) {
  574. listConfirm, totalConfirm, e := GetActivityLabelSpecialConfirmList(user, (currentIndex-1)*pageSize, pageSize, 4, keywords)
  575. if e != nil && e.Error() != utils.ErrNoRow() {
  576. err = errors.New("GetActivityLabelSpecialConfirmList11, Err: " + e.Error())
  577. return
  578. }
  579. //if totalConfirm == 0 {
  580. // return
  581. //}
  582. if currentIndex == 1 && len(listConfirm) > 0 {
  583. listConfirm[0].Explain = utils.ACtIVITY_SPECIAL_TRIP_EXPLAIN
  584. }
  585. list = listConfirm
  586. total = totalConfirm
  587. var startSizePrepare, pageSizePrepare int
  588. //全是确定行程的查询数据
  589. if totalConfirm >= currentIndex*pageSize {
  590. startSizePrepare = 0
  591. pageSizePrepare = 0
  592. } else if totalConfirm > (currentIndex-1)*pageSize && totalConfirm < currentIndex*pageSize {
  593. //一半确认行程一半预报名
  594. startSizePrepare = 0
  595. pageSizePrepare = pageSize - len(listConfirm)
  596. } else {
  597. //全是预报名
  598. startSizePrepare = (currentIndex-1)*pageSize - totalConfirm
  599. pageSizePrepare = pageSize - len(listConfirm)
  600. }
  601. listPrepare, totalPrepare, e := GetActivitySpecialPrepareList(user, startSizePrepare, pageSizePrepare, keywords)
  602. if e != nil {
  603. err = errors.New("GetActivityLabelSpecialConfirmList, Err: " + e.Error())
  604. return
  605. }
  606. if len(listPrepare) > 0 {
  607. for _, v := range listPrepare {
  608. list = append(list, v)
  609. }
  610. if startSizePrepare == 0 {
  611. listPrepare[0].Explain = utils.ACtIVITY_SPECIAL_EXPLAIN
  612. }
  613. }
  614. total = totalConfirm + totalPrepare
  615. //处理封面图片
  616. detail, e := models.GetConfigByCode("city_img_url")
  617. if e != nil {
  618. err = errors.New("GetConfigByCode, Err: " + e.Error())
  619. return
  620. }
  621. detailChart, e := models.GetConfigByCode("chart_img_url")
  622. if e != nil {
  623. err = errors.New("GetConfigByCode, Err: " + e.Error())
  624. return
  625. }
  626. addressList := strings.Split(detail.ConfigValue, "{|}")
  627. mapAddress := make(map[string]string)
  628. chartList := strings.Split(detailChart.ConfigValue, "{|}")
  629. mapChart := make(map[string]string)
  630. var cityName string
  631. var chartName string
  632. var imgUrl string
  633. var imgUrlChart string
  634. for _, v := range addressList {
  635. vslice := strings.Split(v, "_")
  636. cityName = vslice[0]
  637. imgUrl = vslice[len(vslice)-1]
  638. mapAddress[cityName] = imgUrl
  639. }
  640. for _, v := range chartList {
  641. vslice := strings.Split(v, "_")
  642. chartName = vslice[0]
  643. imgUrlChart = vslice[len(vslice)-1]
  644. mapChart[chartName] = imgUrlChart
  645. }
  646. for k, v := range list {
  647. //list[k].ImgUrlText = "https://hongze.oss-cn-shanghai.aliyuncs.com/static/images/202112/20211221/bIdfv8t86xrFRpDOeGGHXOmKEuKl.png"
  648. if mapChart[v.ChartPermissionName] != "" {
  649. list[k].ImgUrl = mapChart[v.ChartPermissionName]
  650. }
  651. list[k].ActivityTypeName = "专项调研"
  652. if list[k].Days == 0 {
  653. list[k].TripStatus = 1
  654. } else {
  655. list[k].TripStatus = 2
  656. list[k].TripImgLink = list[k].TripImgLinkFix
  657. }
  658. }
  659. return
  660. }
  661. // HandleActivitySpecialShow 处理活动的状态
  662. func HandleActivitySpecialShow(activityDetail *models.CygxActivitySpecialDetail, user *models.WxUserItem) (item *models.CygxActivitySpecialDetail, err error) {
  663. var activityIds []int
  664. resultTimeStart := utils.StrTimeToTime(activityDetail.ActivityTime) //时间字符串格式转时间格式
  665. resultTimeEnd := utils.StrTimeToTime(activityDetail.ActivityTimeEnd) //时间字符串格式转时间格式
  666. if resultTimeStart.After(time.Now()) {
  667. activityDetail.ActiveState = 1
  668. } else if time.Now().After(resultTimeEnd) {
  669. activityDetail.ActiveState = 3
  670. } else {
  671. activityDetail.ActiveState = 2
  672. }
  673. activityIds = append(activityIds, activityDetail.ActivityId)
  674. //处理用户已经报名了的行程
  675. UserMap, e := GetSpecialTripUserMap(activityIds, user.UserId)
  676. if e != nil {
  677. err = errors.New("GetSpecialTripUserMap, Err: " + e.Error())
  678. return
  679. }
  680. if activityDetail.Days == 0 {
  681. activityDetail.TripStatus = 1
  682. activityDetail.Explain = utils.ACtIVITY_SPECIAL_EXPLAIN
  683. } else {
  684. activityDetail.TripStatus = 2
  685. activityDetail.TripImgLink = activityDetail.TripImgLinkFix
  686. activityDetail.Explain = utils.ACtIVITY_SPECIAL_TRIP_EXPLAIN
  687. }
  688. if _, ok := UserMap[activityDetail.ActivityId]; ok {
  689. activityDetail.IsTrip = 1
  690. }
  691. item = activityDetail
  692. return
  693. }
  694. // 活动与专项调研搜索 GetActivitySpecialSearcheList
  695. func GetActivitySpecialSearcheList(user *models.WxUserItem, condition string, startSize, pageSize int, keywords string) (items []*models.ActivityDetail, total int, err error) {
  696. var conditionSpecil string
  697. var pars, parsSpecil []interface{}
  698. keyword := keywords
  699. if keywords != "" {
  700. keywords = "%" + keywords + "%"
  701. 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 ? ) `
  702. parsSpecil = append(parsSpecil, keywords, keywords, keywords, keywords)
  703. }
  704. list, totalSearche, e := models.GetActivitySpecialSearcheList(condition, pars, conditionSpecil, parsSpecil, startSize, pageSize)
  705. if e != nil {
  706. err = errors.New("GetActivitySpecialSearcheList, Err: " + e.Error())
  707. return
  708. }
  709. keyWordArr, e := GetIndustryMapNameSliceV3(keywords)
  710. if e != nil {
  711. err = errors.New("GetActivityonditionList, Err: " + e.Error())
  712. return
  713. }
  714. var totalIk int
  715. if len(keyWordArr) > 1 {
  716. // 查询IK分词后那一部分的数据
  717. conditionActivityIk, e := GetActivityonditionList(user, "", "", "", "", "", 0, 1, keyword, 0, 2)
  718. if e != nil && e.Error() != utils.ErrNoRow() {
  719. err = errors.New("GetActivityonditionList, Err: " + e.Error())
  720. return
  721. }
  722. conditionActivityIk += " AND art.is_limit_people = 1 AND art.publish_status = 1 "
  723. totalIk, e = models.GetActivityCount(conditionActivityIk, 0, pars, 0)
  724. if e != nil {
  725. err = errors.New("GetActivityonditionList, Err: " + e.Error())
  726. return
  727. }
  728. keyWordArr = RemoveDuplicatesAndEmpty(keyWordArr)
  729. startSizeIk := startSize - totalSearche
  730. if startSizeIk < 0 {
  731. startSizeIk = 0
  732. }
  733. var pageSizeIk int
  734. pageSizeIk = pageSize - len(list)
  735. if pageSizeIk > 0 {
  736. //搜索关键词联想
  737. conditionActivityIk += ` ORDER BY art.activity_time DESC , art.active_state ASC `
  738. listIk, e := models.GetActivityListNew(conditionActivityIk, pars, user.UserId, startSizeIk, pageSizeIk, 0, 0, "")
  739. if e != nil {
  740. err = errors.New("GetActivityonditionList, Err: " + e.Error())
  741. return
  742. }
  743. for _, item := range listIk {
  744. list = append(list, item)
  745. }
  746. }
  747. }
  748. total = totalSearche + totalIk
  749. items, e = HandleActivityListButton(list, user)
  750. if e != nil {
  751. err = errors.New("HandleActivityListButton, Err: " + e.Error())
  752. return
  753. }
  754. return
  755. }
  756. // 获取 专项调研客户类型 //1、永续客户 //2、大套餐客户(4个行业全开通的正式客户) //8、行业升级套餐客户 //9、其余正式客户;5、试用客户
  757. func GetActivitySpecialUserType(companyId int) (userType int, permissionStrnew string, err error) {
  758. var permissionStr string
  759. if companyId <= 1 {
  760. userType = 0
  761. } else {
  762. total, e := models.GetCountCompanyDetailByIdGroupTrip(companyId)
  763. if e != nil {
  764. err = errors.New("GetCountCompanyDetailByIdGroupTrip, Err: " + e.Error())
  765. return
  766. }
  767. if total == 0 {
  768. userType = 0
  769. } else {
  770. companyDetail, e := models.GetCompanyDetailByIdGroupTrip(companyId)
  771. if e != nil {
  772. err = errors.New("GetCompanyDetailByIdGroupTrip, Err: " + e.Error())
  773. return
  774. }
  775. permissionStr, e = models.GetCompanyPermissionByUserTrip(companyId)
  776. if e != nil {
  777. err = errors.New("GetCompanyPermissionByUserTrip, Err: " + e.Error())
  778. return
  779. }
  780. //permissionZhengShiStr, e = models.GetCompanyPermissionByUserZhengShiTrip(companyId)
  781. //if e != nil {
  782. // err = errors.New("GetCompanyPermissionByUserZhengShiTrip, Err: " + e.Error())
  783. // return
  784. //}
  785. //大套餐客户定义:医药、消费、科技、智造。4个行业中为升级,策略是正式,属于大套餐客户
  786. if companyDetail.Status == "永续" {
  787. userType = 1
  788. } else if companyDetail.Status == "试用" {
  789. userType = 5
  790. } else if companyDetail.Status == "正式" {
  791. if permissionStr == "专家" {
  792. userType = 4
  793. } else if strings.Count(permissionStr, "医药") == 2 && strings.Count(permissionStr, "消费") == 2 && strings.Count(permissionStr, "科技") == 2 && strings.Count(permissionStr, "智造") == 2 && strings.Count(permissionStr, "策略") == 1 {
  794. userType = 2
  795. } else {
  796. userType = 3
  797. }
  798. if userType == 3 {
  799. if !strings.Contains(permissionStr, "医药") && !strings.Contains(permissionStr, "消费") && !strings.Contains(permissionStr, "科技") && !strings.Contains(permissionStr, "智造") {
  800. userType = 4
  801. }
  802. }
  803. } else if companyDetail.Status == "冻结" {
  804. userType = 6
  805. } else if companyDetail.Status == "流失" {
  806. userType = 7
  807. }
  808. }
  809. }
  810. permissionStrnew = permissionStr
  811. return
  812. }
  813. // GetSpecialUserType 获取专项产业调研的用户身份类型
  814. // 获取 专项调研客户类型 //1、永续客户 //2、大套餐客户(4个行业全开通的正式客户) //8、行业升级套餐客户 //9、其余正式客户;5、试用客户
  815. func GetSpecialUserType(user *models.WxUserItem) (userType int, err error) {
  816. companyId := user.CompanyId
  817. companyDetail, e := models.GetCompanyDetailByIdGroupTrip(companyId)
  818. if e != nil && e.Error() != utils.ErrNoRow() {
  819. err = errors.New("GetCompanyDetailByIdGroupTrip, Err: " + e.Error())
  820. return
  821. }
  822. if companyDetail == nil {
  823. return
  824. }
  825. if companyId <= 1 {
  826. userType = 0
  827. } else {
  828. if companyDetail.Status == "永续" {
  829. userType = 1
  830. } else {
  831. if companyDetail.Status == "正式" {
  832. list, e := models.GetCompanyReportPermissionUpgrade(companyId, 2)
  833. if e != nil && e.Error() != utils.ErrNoRow() {
  834. err = errors.New("GetCompanyReportPermissionUpgrade, Err: " + e.Error())
  835. }
  836. if len(list) == 0 {
  837. userType = 9
  838. }
  839. if len(list) == 4 {
  840. totalName, e := models.GetCompanyPermissionNameCheck(companyId, 2, "策略")
  841. if e != nil {
  842. err = errors.New("获取品种信息失败, Err:" + e.Error())
  843. return
  844. }
  845. if totalName > 0 {
  846. userType = 2
  847. } else {
  848. userType = 8
  849. }
  850. } else {
  851. userType = 8
  852. }
  853. } else if companyDetail.Status == "试用" {
  854. userType = 5
  855. }
  856. }
  857. }
  858. return
  859. }
  860. // GetSpecialDetailUserPower 处理用户查看专项调研详情的权限
  861. func GetSpecialDetailUserPower(user *models.WxUserItem, activityInfo *models.CygxActivitySpecialDetail) (havePower bool, err error) {
  862. if user.CompanyId == utils.HZ_COMPANY_ID {
  863. havePower = true
  864. return
  865. }
  866. userType, _, e := GetUserType(user.CompanyId)
  867. if e != nil {
  868. err = errors.New("GetSpecialUserType, Err: " + e.Error())
  869. return
  870. }
  871. if userType == 0 {
  872. return
  873. }
  874. mapUserType, e := GetActivityCcustomerTypeList()
  875. if e != nil {
  876. err = e
  877. return
  878. }
  879. var userTypeStr string
  880. userTypeStr = mapUserType[userType]
  881. // 永续客户、大套餐客户可以查看行业升级套餐客户 权限
  882. if userTypeStr == "1" || userTypeStr == "2" {
  883. if strings.Contains(activityInfo.CustomerTypeIds, userTypeStr) || strings.Contains(activityInfo.CustomerTypeIds, "8") {
  884. havePower = true
  885. return
  886. }
  887. }
  888. permissionStr, e := GetCompanyPermissionUpgrade(user.CompanyId)
  889. if e != nil {
  890. err = errors.New("GetCompanyPermissionUpgrade, Err: " + e.Error())
  891. return
  892. }
  893. //如果没有对应的升级权限,则返回
  894. if !strings.Contains(permissionStr, activityInfo.ChartPermissionName) {
  895. return
  896. }
  897. //userType, e := GetSpecialUserType(user)
  898. var pars []interface{}
  899. var condition string
  900. var userTypes string
  901. condition += ` AND art.publish_status = 1 AND art.is_offline = 0 `
  902. userTypes = "%" + userTypeStr + "%"
  903. condition += ` AND art.customer_type_ids LIKE ? `
  904. pars = append(pars, userTypes)
  905. condition += ` AND art.activity_id = ? `
  906. pars = append(pars, activityInfo.ActivityId)
  907. total, e := models.GetActivitySpecialCount(condition, pars)
  908. if e != nil {
  909. err = errors.New("GetSpecialUserType, Err: " + e.Error())
  910. return
  911. }
  912. if total == 1 {
  913. havePower = true
  914. return
  915. }
  916. if strings.Contains(permissionStr, activityInfo.ChartPermissionName) && strings.Contains(activityInfo.CustomerTypeIds, "8") {
  917. havePower = true
  918. return
  919. }
  920. return
  921. }
  922. // 预报名活动,感兴趣人数满10人时,推送给活动负责人和王芳
  923. func SendWxMsgActivitySpecial10(activityInfo *models.CygxActivitySpecialDetail) (err error) {
  924. activityId := activityInfo.ActivityId
  925. var msg string
  926. defer func() {
  927. if err != nil {
  928. go utils.SendEmail("发送模版消息失败"+"【"+utils.APPNAME+"】"+time.Now().Format("2006-01-02 15:04:05"), msg+";Err:"+err.Error(), utils.EmailSendToUsers)
  929. go utils.SendAlarmMsg(fmt.Sprint("预报名活动,感兴趣人数满10人时,推送给活动负责人和王芳消息发送失败", activityInfo.ResearchTheme, ", activityId"), 2)
  930. utils.FileLog.Info("发送模版消息失败,Err:%s", err.Error())
  931. }
  932. }()
  933. var first string
  934. var keyword1 string
  935. var keyword2 string
  936. var keyword3 string
  937. var keyword4 string
  938. var remark string
  939. adminUser, e := models.GetSellerByAdminId(activityInfo.AdminId)
  940. if e != nil {
  941. err = errors.New("GetSellerByAdminId, Err: " + e.Error())
  942. return
  943. }
  944. cnf, _ := models.GetConfigByCode("tpl_msg")
  945. mobile := adminUser.Mobile + "," + cnf.ConfigValue
  946. specialSignupList, e := models.GetActivityListSpecialByActivityId(activityId)
  947. if e != nil {
  948. err = errors.New("GetActivityListSpecialAll, Err: " + e.Error())
  949. return
  950. }
  951. for _, v := range specialSignupList {
  952. keyword1 += "【" + v.RealName + "--" + v.CompanyName + "】"
  953. }
  954. openIdList, e := models.GetWxOpenIdByMobileList(mobile)
  955. if e != nil {
  956. err = errors.New("GetSellerByAdminId, Err: " + e.Error())
  957. return
  958. }
  959. first = "【" + activityInfo.ResearchTheme + "】已有10人预报名"
  960. keyword3 = "-"
  961. keyword2 = "-"
  962. keyword4 = activityInfo.ResearchTheme
  963. openIdArr := make([]string, 0)
  964. for _, v := range openIdList {
  965. openIdArr = append(openIdArr, v.OpenId)
  966. }
  967. redirectUrl := utils.WX_MSG_PATH_ACTIVITY_SPECIAL_DETAIL + strconv.Itoa(activityId)
  968. sendInfo := new(SendWxTemplate)
  969. sendInfo.First = first
  970. sendInfo.Keyword1 = keyword1
  971. sendInfo.Keyword2 = keyword2
  972. sendInfo.Keyword3 = keyword3
  973. sendInfo.Keyword4 = keyword4
  974. sendInfo.Remark = remark
  975. sendInfo.TemplateId = utils.WxMsgTemplateIdAskMsgXzs
  976. sendInfo.RedirectUrl = redirectUrl
  977. sendInfo.RedirectTarget = 3
  978. sendInfo.Resource = strconv.Itoa(activityId)
  979. sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ARTICLE_ADD
  980. sendInfo.OpenIdArr = openIdArr
  981. err = PublicSendTemplateMsg(sendInfo)
  982. if err != nil {
  983. return
  984. }
  985. return
  986. }
  987. // SendWxMsgActivitySpecialTwoDays 活动开始前两天08:00,提醒报名客户 \提醒报名客户的对口销售
  988. func SendWxMsgActivitySpecialTwoDays(cont context.Context) (err error) {
  989. var msg string
  990. defer func() {
  991. if err != nil {
  992. fmt.Println(err)
  993. go utils.SendEmail("发送模版消息失败"+"【"+utils.APPNAME+"】"+time.Now().Format("2006-01-02 15:04:05"), msg+";Err:"+err.Error(), utils.EmailSendToUsers)
  994. go utils.SendAlarmMsg(fmt.Sprint(" 活动开始前两天08:00,提醒报名客户、提醒报名客户的对口销售消息发送失败"), 2)
  995. utils.FileLog.Info("发送模版消息失败,Err:%s", err.Error())
  996. }
  997. }()
  998. twoDayTime := time.Now().AddDate(0, 0, 2)
  999. startTime := twoDayTime.Format(utils.FormatDate) + " 00:00:00"
  1000. endTime := twoDayTime.Format(utils.FormatDate) + " 23:59:59"
  1001. var condition string
  1002. var pars []interface{}
  1003. condition = ` AND days >0 AND activity_time BETWEEN ? AND ? `
  1004. pars = append(pars, startTime, endTime)
  1005. listActivitySpecial, e := models.GetActivitySpecialListAll(condition, pars, 0, 1000)
  1006. if e != nil {
  1007. err = errors.New("GetSellerByAdminId, Err: " + e.Error())
  1008. return
  1009. }
  1010. if len(listActivitySpecial) == 0 {
  1011. return
  1012. }
  1013. var activityIds []int
  1014. for _, v := range listActivitySpecial {
  1015. activityIds = append(activityIds, v.ActivityId)
  1016. condition = ` AND is_cancel = 0 AND activity_id = ` + strconv.Itoa(v.ActivityId)
  1017. pars = make([]interface{}, 0)
  1018. listSpecialTrip, e := models.GetCygxActivitySpecialTripList(condition, pars)
  1019. if e != nil {
  1020. err = errors.New("GetCygxActivitySpecialTripList, Err: " + e.Error())
  1021. return
  1022. }
  1023. if len(listSpecialTrip) == 0 {
  1024. return
  1025. }
  1026. var mobile string
  1027. var companyIds []int
  1028. for _, vT := range listSpecialTrip {
  1029. mobile += "'" + vT.Mobile + "',"
  1030. companyIds = append(companyIds, vT.CompanyId)
  1031. }
  1032. mobile = strings.TrimRight(mobile, ",")
  1033. openIdList, e := models.GetWxOpenIdByMobileList(mobile)
  1034. if e != nil {
  1035. err = errors.New("GetSellerByAdminId, Err: " + e.Error())
  1036. return
  1037. }
  1038. first := "【" + v.ResearchTheme + "】专项调研将在两天后进行,如不能参加,请及时取消报名"
  1039. keyword1 := v.ResearchTheme
  1040. keyword2 := "已报名"
  1041. keyword3 := v.ActivityTimeTextByDay
  1042. keyword4 := "线上"
  1043. if v.SpecialType == 2 {
  1044. keyword4 = v.City
  1045. }
  1046. remark := "点击查看活动详情"
  1047. SendWxMsgWithFrequencySpecial(first, keyword1, keyword2, keyword3, keyword4, remark, openIdList, v.ActivityId)
  1048. //活动开始前两天08:00,提醒报名客户的对口销售
  1049. companyIdsLen := len(companyIds)
  1050. if companyIdsLen == 0 {
  1051. continue
  1052. } else {
  1053. pars = make([]interface{}, 0)
  1054. condition = ` AND p.company_id IN (` + utils.GetOrmInReplace(companyIdsLen) + `) GROUP BY p.company_id `
  1055. pars = append(pars, companyIds)
  1056. listSeller, e := models.GetAdminOpendidByCompany(condition, pars)
  1057. if e != nil && e.Error() != utils.ErrNoRow() {
  1058. err = errors.New("GetAdminOpendidByCompany, Err: " + e.Error())
  1059. return
  1060. }
  1061. if len(listSeller) == 0 {
  1062. continue
  1063. }
  1064. type SllerData struct {
  1065. Openid string `description:"Openid"`
  1066. Keyword string `description:"Keyword "`
  1067. }
  1068. mapSller := make(map[string]string)
  1069. mapSllerOpenid := make(map[string]string)
  1070. for _, vS := range listSeller {
  1071. for _, vT := range listSpecialTrip {
  1072. if vT.CompanyId == vS.CompanyId {
  1073. mapSller[vS.Mobile] += "【" + vT.RealName + "--" + vT.CompanyName + "】"
  1074. mapSllerOpenid[vS.Mobile] = vS.OpenId
  1075. }
  1076. }
  1077. }
  1078. for k, vM := range mapSller {
  1079. first = "【" + v.ResearchTheme + "】专项调研将在两天后进行,请及时提醒您的报名客户"
  1080. keyword2 = vM
  1081. openIdList = make([]*models.OpenIdList, 0)
  1082. openIdList = append(openIdList, &models.OpenIdList{OpenId: mapSllerOpenid[k]})
  1083. SendWxMsgWithFrequencySpecial(first, keyword1, keyword2, keyword3, keyword4, remark, openIdList, v.ActivityId)
  1084. }
  1085. }
  1086. }
  1087. return
  1088. }
  1089. // SendWxMsgActivitySpecialCancel 线下活动前4天08:00报名人数不足7人,线上活动前3天08:00报名人数不足10人,活动自动取消发布,并推送模板消息至报名客户及对口销售
  1090. func SendWxMsgActivitySpecialCancel(cont context.Context) (err error) {
  1091. var msg string
  1092. defer func() {
  1093. if err != nil {
  1094. fmt.Println(err)
  1095. go utils.SendEmail("发送模版消息失败"+"【"+utils.APPNAME+"】"+time.Now().Format("2006-01-02 15:04:05"), msg+";Err:"+err.Error(), utils.EmailSendToUsers)
  1096. go utils.SendAlarmMsg(fmt.Sprint(" 活动开始前两天08:00,提醒报名客户、提醒报名客户的对口销售消息发送失败"), 2)
  1097. utils.FileLog.Info("发送模版消息失败,Err:%s", err.Error())
  1098. }
  1099. }()
  1100. dayTime3 := time.Now().AddDate(0, 0, 3)
  1101. startTime := dayTime3.Format(utils.FormatDate) + " 00:00:00"
  1102. endTime := dayTime3.Format(utils.FormatDate) + " 23:59:59"
  1103. dayTime4 := time.Now().AddDate(0, 0, 4)
  1104. startTime4 := dayTime4.Format(utils.FormatDate) + " 00:00:00"
  1105. endTime4 := dayTime4.Format(utils.FormatDate) + " 23:59:59"
  1106. var condition string
  1107. var pars []interface{}
  1108. condition = ` AND days >0 AND activity_time BETWEEN ? AND ? AND special_type= 1 `
  1109. pars = append(pars, startTime, endTime)
  1110. condition += ` OR ( days >0 AND activity_time BETWEEN ? AND ? AND special_type= 2 ) `
  1111. pars = append(pars, startTime4, endTime4)
  1112. listActivitySpecial, e := models.GetActivitySpecialListAll(condition, pars, 0, 1000)
  1113. if e != nil {
  1114. err = errors.New("GetSellerByAdminId, Err: " + e.Error())
  1115. return
  1116. }
  1117. if len(listActivitySpecial) == 0 {
  1118. return
  1119. }
  1120. var activityIds []int
  1121. for _, v := range listActivitySpecial {
  1122. activityIds = append(activityIds, v.ActivityId)
  1123. condition = ` AND is_cancel = 0 AND activity_id = ` + strconv.Itoa(v.ActivityId)
  1124. pars = make([]interface{}, 0)
  1125. listSpecialTrip, e := models.GetCygxActivitySpecialTripList(condition, pars)
  1126. if e != nil {
  1127. err = errors.New("GetCygxActivitySpecialTripList, Err: " + e.Error())
  1128. return
  1129. }
  1130. if v.SpecialType == 1 {
  1131. if len(listSpecialTrip) >= 10 {
  1132. continue
  1133. }
  1134. }
  1135. if v.SpecialType == 2 {
  1136. if len(listSpecialTrip) >= 7 {
  1137. continue
  1138. }
  1139. }
  1140. e = models.UpdateActivitySpecialPublishStatus(0, v.ActivityId)
  1141. if e != nil {
  1142. err = errors.New("UpdateActivitySpecialPublishStatus,自动取消专项调研日程失败 Err: " + e.Error() + strconv.Itoa(v.ActivityId))
  1143. return
  1144. }
  1145. if len(listSpecialTrip) < 0 {
  1146. return
  1147. }
  1148. var mobile string
  1149. var companyIds []int
  1150. for _, vT := range listSpecialTrip {
  1151. mobile += "'" + vT.Mobile + "',"
  1152. companyIds = append(companyIds, vT.CompanyId)
  1153. }
  1154. mobile = strings.TrimRight(mobile, ",")
  1155. openIdList, e := models.GetWxOpenIdByMobileList(mobile)
  1156. if e != nil {
  1157. err = errors.New("GetSellerByAdminId, Err: " + e.Error())
  1158. return
  1159. }
  1160. first := "【" + v.ResearchTheme + "】专项调研因专家安排变动,本次调研活动延期举办,具体时间另行通知"
  1161. keyword1 := v.ResearchTheme
  1162. keyword2 := "已取消"
  1163. keyword3 := ""
  1164. keyword4 := ""
  1165. remark := ""
  1166. openIdArr := make([]string, 0)
  1167. for _, vOpenid := range openIdList {
  1168. openIdArr = append(openIdArr, vOpenid.OpenId)
  1169. }
  1170. companyIdsLen := len(companyIds)
  1171. if len(companyIds) > 0 {
  1172. pars = make([]interface{}, 0)
  1173. condition = ` AND p.company_id IN (` + utils.GetOrmInReplace(companyIdsLen) + `) GROUP BY p.company_id `
  1174. pars = append(pars, companyIds)
  1175. listSeller, e := models.GetAdminOpendidByCompany(condition, pars)
  1176. if e != nil && e.Error() != utils.ErrNoRow() {
  1177. err = errors.New("GetAdminOpendidByCompany, Err: " + e.Error())
  1178. return
  1179. }
  1180. if len(listSeller) > 0 {
  1181. for _, vOpenid := range listSeller {
  1182. openIdArr = append(openIdArr, vOpenid.OpenId)
  1183. }
  1184. }
  1185. }
  1186. redirectUrl := ""
  1187. sendInfo := new(SendWxTemplate)
  1188. sendInfo.First = first
  1189. sendInfo.Keyword1 = keyword1
  1190. sendInfo.Keyword2 = keyword2
  1191. sendInfo.Keyword3 = keyword3
  1192. sendInfo.Keyword4 = keyword4
  1193. sendInfo.Remark = remark
  1194. sendInfo.TemplateId = utils.WxMsgTemplateIdArticleUserRemind
  1195. sendInfo.RedirectUrl = redirectUrl
  1196. sendInfo.RedirectTarget = 3
  1197. sendInfo.Resource = strconv.Itoa(v.ActivityId)
  1198. sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ARTICLE_ADD
  1199. sendInfo.OpenIdArr = openIdArr
  1200. fmt.Println(sendInfo)
  1201. err = PublicSendTemplateMsg(sendInfo)
  1202. }
  1203. return
  1204. }