activity_special_trip.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551
  1. package services
  2. import (
  3. "errors"
  4. "fmt"
  5. "hongze/hongze_cygx/models"
  6. "hongze/hongze_cygx/models/company"
  7. "hongze/hongze_cygx/utils"
  8. "strconv"
  9. "strings"
  10. "time"
  11. )
  12. func SpecialTripPopupMsg(activityInfo *models.CygxActivitySpecialDetail, user *models.WxUserItem) (signupStatus int, popupMsg, popupMsg2 string, err error) {
  13. //SignupStatus int `description:"返回状态:1:成功 、2 :人数已满 、3:调研次数已用完、 4:超时"`
  14. signupStatus = 1
  15. resultTime := utils.StrTimeToTime(activityInfo.ActivityTime) //时间字符串格式转时间格式
  16. if time.Now().After(resultTime.Add(-time.Minute * 60)) {
  17. signupStatus = 4
  18. popupMsg = "活动开始前1小时内无法报名,请联系对口销售处理"
  19. return
  20. }
  21. errMsg, e := CheckTripRemainingtimesBycompany(user, activityInfo)
  22. if e != nil {
  23. err = errors.New("获取客户剩余报名次数失败 GetActivitySpecialUserType, Err: " + e.Error())
  24. return
  25. }
  26. if errMsg != "" {
  27. popupMsg = errMsg
  28. signupStatus = 3
  29. return
  30. }
  31. var condition string
  32. var pars []interface{}
  33. condition += ` AND activity_id = ? AND is_cancel = 0 `
  34. pars = append(pars, activityInfo.ActivityId)
  35. tripTota, e := models.GetActivitySpecialTripCountByActivityId(condition, pars)
  36. if e != nil {
  37. err = errors.New("GetCygxActivitySpecialDetailList, Err: " + e.Error())
  38. return
  39. }
  40. if activityInfo.LimitPeopleNum-tripTota < 1 {
  41. signupStatus = 2
  42. popupMsg = "此活动报名人数已满,请留意下期活动"
  43. return
  44. }
  45. //signupStatus = 4
  46. popupMsg = "感谢参与,本次报名会扣除一次贵司在弘则的调研点数。"
  47. popupMsg2 = "由于每场活动人数有限,如果不能参加请提前48小时取消,未及时取消导致影响其他客户报名将会维持扣点。"
  48. return
  49. }
  50. // 获取用户剩余报名次数
  51. //func GetTripRemainingtimesBycompany(user *models.WxUserItem, activityInfo *models.CygxActivitySpecialDetail) (errMsg string, tripRemaining int, err error) {
  52. //
  53. // //获取 专项调研客户类型 //1、永续客户 //2、大套餐客户(4个行业全开通的正式客户) //3、分行业套餐客户(开通对应行业的正式客户) //4、仅开通专家套餐的正式客户 //5、开通对应行业套餐或专家套餐的试用客户;6、冻结客户;7、流失客户 8:行业升级套餐客户
  54. // msgTemplate := "您的专项调研次数已用完,如仍想参加,请与您的对口销售商议"
  55. // //var tripTota int
  56. // //var airborneTota int
  57. // //userType, _, e := GetActivitySpecialUserType(user.CompanyId)
  58. // userType, _, e := GetUserType(user.CompanyId)
  59. // if e != nil {
  60. // err = errors.New("获取客户身份信息失败 GetActivitySpecialUserType, Err: " + e.Error())
  61. // return
  62. // }
  63. // if userType == 0 {
  64. // errMsg = msgTemplate
  65. // return
  66. // } else if userType == 1 {
  67. // tripRemaining = 999
  68. // return
  69. // } else if userType == 2 {
  70. // var condition string
  71. // var pars []interface{}
  72. //
  73. // condition += ` AND company_id = ? `
  74. // pars = append(pars, user.CompanyId)
  75. //
  76. // //airborneTota, e = models.GetActivitySpecialTripAirborneCountByActivitySpecial(condition, pars)
  77. // //if e != nil {
  78. // // err = errors.New("GetActivitySpecialTripAirborneCountByActivitySpecial, Err: " + e.Error())
  79. // // return
  80. // //}
  81. // //condition += ` AND is_valid = 1 `
  82. // //查询当年的数据
  83. // condition += ` AND create_time >= ? `
  84. // pars = append(pars, time.Now().Format(utils.FormatYearDate)+"-01-01")
  85. // listTripBill, e := models.GetCygxActivitySpecialTripBill(condition, pars)
  86. // if e != nil {
  87. // err = errors.New("GetActivitySpecialTripCountByActivitySpecial, Err: " + e.Error())
  88. // return
  89. // }
  90. // var TripBillNum int
  91. // for _, v := range listTripBill {
  92. // TripBillNum += v.BillDetailed
  93. // }
  94. // var packageType int
  95. // //大套餐客户,数据库添加标识,
  96. // companyUserTypeDetail, errs := models.GetCygxCompanyUserType(user.CompanyId)
  97. // if errs != nil && errs.Error() != utils.ErrNoRow() {
  98. // err = errs
  99. // return
  100. // }
  101. // if companyUserTypeDetail != nil {
  102. // packageType = companyUserTypeDetail.PackageType
  103. // if companyUserTypeDetail.CustomerTypeId != 0 {
  104. // userType = companyUserTypeDetail.CustomerTypeId
  105. // return
  106. // }
  107. // }
  108. //
  109. // packageTypeMap := map[int]int{1: 16, 2: 10}
  110. // totalTrip := packageTypeMap[packageType]
  111. // //tripRemaining = 10 - airborneTota + TripBillNum
  112. // tripRemaining = totalTrip + TripBillNum
  113. // if tripRemaining <= 0 {
  114. // errMsg = msgTemplate
  115. // return
  116. // }
  117. // //tripRemaining = 12 - tripTota
  118. // } else {
  119. // var condition string
  120. // var pars []interface{}
  121. //
  122. // condition += ` AND company_id = ? `
  123. // pars = append(pars, user.CompanyId)
  124. //
  125. // condition += ` AND chart_permission_id = ? `
  126. // pars = append(pars, activityInfo.ChartPermissionId)
  127. //
  128. // //airborneTota, e = models.GetActivitySpecialTripAirborneCountByActivitySpecial(condition, pars)
  129. // //if e != nil {
  130. // // err = errors.New("GetActivitySpecialTripAirborneCountByActivitySpecial, Err: " + e.Error())
  131. // // return
  132. // //}
  133. // //查询当年的数据
  134. // condition += ` AND create_time >= ? `
  135. // pars = append(pars, time.Now().Format(utils.FormatYearDate)+"-01-01")
  136. // listTripBill, e := models.GetCygxActivitySpecialTripBill(condition, pars)
  137. // if e != nil {
  138. // err = errors.New("GetActivitySpecialTripCountByActivitySpecial, Err: " + e.Error())
  139. // return
  140. // }
  141. // var TripBillNum int
  142. // for _, v := range listTripBill {
  143. // TripBillNum += v.BillDetailed
  144. // }
  145. // //tripRemaining = 5 - airborneTota + TripBillNum
  146. // tripRemaining = 5 + TripBillNum
  147. // if tripRemaining <= 0 {
  148. // errMsg = msgTemplate
  149. // return
  150. // }
  151. // }
  152. // return
  153. //}
  154. // 校验是否还有剩余次数
  155. func CheckTripRemainingtimesBycompany(user *models.WxUserItem, activityInfo *models.CygxActivitySpecialDetail) (errMsg string, err error) {
  156. msgTemplate := "您的专项调研次数已用完,如仍想参加,请与您的对口销售商议"
  157. companyId := user.CompanyId
  158. chartPermissionName := activityInfo.ChartPermissionName
  159. companyDetail, e := models.GetCompanyDetailByIdGroup(companyId)
  160. if e != nil {
  161. err = errors.New("GetCompanyDetailByIdGroup, Err:" + e.Error())
  162. return
  163. }
  164. //永续客户不限制次数
  165. if companyDetail.Status == utils.COMPANY_STATUS_FOREVER {
  166. return
  167. }
  168. var condition string
  169. var pars []interface{}
  170. condition = " AND company_id = ? AND points > 0 ORDER BY chart_permission_id DESC "
  171. pars = append(pars, companyId)
  172. activitySpecialPermissionPointsList, e := models.GetCygxActivitySpecialPermissionPointsList(condition, pars)
  173. if e != nil && e.Error() != utils.ErrNoRow() {
  174. err = errors.New("GetCygxActivitySpecialPermissionPointsList, Err:" + e.Error())
  175. return
  176. }
  177. //如果没有剩余的点数,就返回
  178. if len(activitySpecialPermissionPointsList) == 0 {
  179. errMsg = msgTemplate
  180. return
  181. }
  182. //判断是不是策略行业的活动,策略的任何一个行业有剩余点数都能参加
  183. //if chartPermissionName == utils.CE_LUE_NAME {
  184. if utils.InArrayByStr(utils.ACTIVITY_SPECIAL_TRIP_PERMISSION_NAME_OTHER, activityInfo.ChartPermissionName) {
  185. return
  186. } else {
  187. for _, v := range activitySpecialPermissionPointsList {
  188. if v.ChartPermissionName == chartPermissionName || v.ChartPermissionId == 0 {
  189. return
  190. } // 如果对应行业有剩余次数,或者是属于大套餐且有次数,那么校验也通过
  191. }
  192. }
  193. return
  194. }
  195. // GetSpecialBillMaxChartPermissionId 获取专项调研剩余点数最多的行业
  196. func GetSpecialBillMaxChartPermissionId(user *models.WxUserItem) (maxChartPermissionId int, maxChartPermissionName string, err error) {
  197. companyId := user.CompanyId
  198. var condition string
  199. var pars []interface{}
  200. condition = " AND company_id = ? AND points > 0 ORDER BY points DESC LIMIT 1 "
  201. pars = append(pars, companyId)
  202. activitySpecialPermissionPointsList, e := models.GetCygxActivitySpecialPermissionPointsList(condition, pars)
  203. if e != nil && e.Error() != utils.ErrNoRow() {
  204. err = errors.New("GetCygxActivitySpecialPermissionPointsList, Err:" + e.Error())
  205. return
  206. }
  207. for _, v := range activitySpecialPermissionPointsList {
  208. maxChartPermissionId = v.ChartPermissionId
  209. maxChartPermissionName = v.ChartPermissionName
  210. }
  211. return
  212. }
  213. // DeductTripRemainingtimesByUser 扣除用户专项调研剩余次数
  214. func DeductTripRemainingtimesByUser(user *models.WxUserItem, activityInfo *models.CygxActivitySpecialDetail) (err error) {
  215. msgTemplate := "您的专项调研次数已用完,如仍想参加,请与您的对口销售商议"
  216. companyId := user.CompanyId
  217. //chartPermissionName := activityInfo.ChartPermissionName
  218. companyProduct, e := company.GetCompanyProductByCompanyIdAndProductId(companyId, utils.COMPANY_PRODUCT_RAI_ID)
  219. if e != nil {
  220. err = errors.New("GetCompanyProductByCompanyIdAndProductId, Err:" + e.Error())
  221. return
  222. }
  223. var condition string
  224. var pars []interface{}
  225. var maxChartPermissionId int // 剩余点数最多的行业
  226. var points int // 剩余点数
  227. var activitySpecialPermissionPointsList []*models.CygxActivitySpecialPermissionPoints
  228. //永续客户不限次数需要单独处理
  229. if companyProduct.Status == utils.COMPANY_STATUS_FOREVER {
  230. condition = " AND company_id = ? ORDER BY points DESC LIMIT 1 "
  231. pars = append(pars, companyId)
  232. activitySpecialPermissionPointsList, e = models.GetCygxActivitySpecialPermissionPointsList(condition, pars)
  233. if e != nil && e.Error() != utils.ErrNoRow() {
  234. err = errors.New("GetCygxActivitySpecialPermissionPointsList, Err:" + e.Error())
  235. return
  236. }
  237. //如果永续客户不存在单独的行业剩余点数记录,那么就添加一条 -1 的记录作为初始化数据
  238. if len(activitySpecialPermissionPointsList) == 0 {
  239. item := new(models.CygxActivitySpecialPermissionPoints)
  240. item.CompanyId = companyProduct.CompanyId
  241. item.Points = -1
  242. item.CompanyName = companyProduct.CompanyName
  243. //item.ChartPermissionId = activityInfo.ChartPermissionId
  244. //item.ChartPermissionName = activityInfo.ChartPermissionName
  245. item.CreateTime = time.Now()
  246. item.ModifyTime = time.Now()
  247. e = models.AddCygxActivitySpecialPermissionPoints(item)
  248. if e != nil {
  249. err = errors.New("AddCygxActivitySpecialPermissionPoints, Err:" + e.Error())
  250. return
  251. }
  252. return
  253. }
  254. } else {
  255. condition = " AND company_id = ? AND points > 0 ORDER BY points DESC LIMIT 1 "
  256. pars = append(pars, companyId)
  257. //判断是不是策略、固收、周期行业的活动,如果不是策略就获取对应行业的点数 ,策略的任何一个行业有剩余点数都能参加
  258. //if chartPermissionName != utils.CE_LUE_NAME && chartPermissionName != utils.GU_SHOU_NAME {
  259. if !utils.InArrayByStr(utils.ACTIVITY_SPECIAL_TRIP_PERMISSION_NAME_OTHER, activityInfo.ChartPermissionName) {
  260. pars = make([]interface{}, 0)
  261. condition = " AND company_id = ? AND ( chart_permission_id = ? OR chart_permission_id =0 ) AND points > 0 ORDER BY points DESC LIMIT 1 "
  262. pars = append(pars, companyId, activityInfo.ChartPermissionId)
  263. }
  264. activitySpecialPermissionPointsList, e = models.GetCygxActivitySpecialPermissionPointsList(condition, pars)
  265. if e != nil && e.Error() != utils.ErrNoRow() {
  266. err = errors.New("GetCygxActivitySpecialPermissionPointsList, Err:" + e.Error())
  267. return
  268. }
  269. }
  270. //如果没有剩余的点数,就返回
  271. if len(activitySpecialPermissionPointsList) == 0 {
  272. err = errors.New(msgTemplate)
  273. return
  274. }
  275. for _, v := range activitySpecialPermissionPointsList {
  276. maxChartPermissionId = v.ChartPermissionId
  277. points = v.Points - 1
  278. }
  279. //更新对应行业剩余点数
  280. e = models.UpdateCygxActivitySpecialPermissionPoints(points, companyId, maxChartPermissionId)
  281. if e != nil {
  282. err = errors.New("UpdateCygxActivitySpecialPermissionPoints, Err:" + e.Error())
  283. return
  284. }
  285. return
  286. }
  287. // RebateTripRemainingtimesByUser 返点用户专项调研剩余次数
  288. func RebateTripRemainingtimesByUser(user *models.WxUserItem, activityInfo *models.CygxActivitySpecialDetail) (err error) {
  289. companyId := user.CompanyId
  290. //chartPermissionName := activityInfo.ChartPermissionName
  291. var condition string
  292. var pars []interface{}
  293. condition = " AND company_id = ? ORDER BY points DESC LIMIT 1 "
  294. pars = append(pars, companyId)
  295. //判断是不是策略、固收、周期行业的活动,如果不是策略就获取对应行业的点数 ,策略的任何一个行业有剩余点数都能参加
  296. //if chartPermissionName != utils.CE_LUE_NAME && chartPermissionName != utils.GU_SHOU_NAME {
  297. if !utils.InArrayByStr(utils.ACTIVITY_SPECIAL_TRIP_PERMISSION_NAME_OTHER, activityInfo.ChartPermissionName) {
  298. pars = make([]interface{}, 0)
  299. condition = " AND company_id = ? AND (chart_permission_id = ? OR chart_permission_id = 0 ) LIMIT 1 "
  300. pars = append(pars, companyId, activityInfo.ChartPermissionId)
  301. } else {
  302. lastTripBill, e := models.GetCygxActivitySpecialTripBillLastDetialByActivityId(activityInfo.ActivityId, user.UserId)
  303. if e != nil {
  304. err = errors.New("GetActivitySpecialTripCountByActivitySpecial, Err: " + e.Error())
  305. return
  306. }
  307. pars = make([]interface{}, 0)
  308. condition = " AND company_id = ? AND (chart_permission_id = ? OR chart_permission_id = 0 ) LIMIT 1 "
  309. pars = append(pars, companyId, lastTripBill.ChartPermissionId)
  310. }
  311. activitySpecialPermissionPointsList, e := models.GetCygxActivitySpecialPermissionPointsList(condition, pars)
  312. if e != nil && e.Error() != utils.ErrNoRow() {
  313. err = errors.New("GetCygxActivitySpecialPermissionPointsList, Err:" + e.Error())
  314. return
  315. }
  316. var maxChartPermissionId int // 剩余点数最多的行业(返点行业)
  317. var points int // 剩余点数
  318. for _, v := range activitySpecialPermissionPointsList {
  319. maxChartPermissionId = v.ChartPermissionId
  320. points = v.Points + 1
  321. }
  322. //更新对应行业剩余点数
  323. e = models.UpdateCygxActivitySpecialPermissionPoints(points, companyId, maxChartPermissionId)
  324. if e != nil {
  325. err = errors.New("UpdateCygxActivitySpecialPermissionPoints, Err:" + e.Error())
  326. return
  327. }
  328. return
  329. }
  330. // 预处理专项调研流水明细表描述内容
  331. func HandleActivitySpecialTripBillTotalText(companyId int) (totalText string, err error) {
  332. //companyId := user.CompanyId
  333. companyDetail, e := models.GetCompanyDetailByIdGroup(companyId)
  334. if e != nil {
  335. err = errors.New("GetCompanyDetailByIdGroup, Err:" + e.Error())
  336. return
  337. }
  338. var condition string
  339. var pars []interface{}
  340. pars = make([]interface{}, 0)
  341. condition = " AND company_id = ? AND points != 0 ORDER BY chart_permission_id DESC "
  342. pars = append(pars, companyId)
  343. activitySpecialPermissionPointsList, e := models.GetCygxActivitySpecialPermissionPointsList(condition, pars)
  344. if e != nil && e.Error() != utils.ErrNoRow() {
  345. err = errors.New("GetCygxActivitySpecialPermissionPointsList, Err:" + e.Error())
  346. return
  347. }
  348. //永续客户次数累加
  349. if companyDetail.Status == utils.COMPANY_STATUS_FOREVER {
  350. var points int
  351. for _, v := range activitySpecialPermissionPointsList {
  352. points += v.Points
  353. }
  354. totalText = fmt.Sprint(points, "次") //追加永续客户展示规则(2024-02-23)
  355. return
  356. }
  357. var itemBillTotal []string
  358. itemBillTotalMap := make(map[string]string)
  359. for _, v := range activitySpecialPermissionPointsList {
  360. if v.ChartPermissionId > 0 {
  361. itemBillTotal = append(itemBillTotal, fmt.Sprint(v.ChartPermissionName, v.Points, "次")) // 行业套餐客户展示规则
  362. itemBillTotalMap[v.ChartPermissionName] = fmt.Sprint(v.ChartPermissionName, v.Points, "次")
  363. }
  364. if v.ChartPermissionId == 0 {
  365. totalText = fmt.Sprint(v.Points, "次") // 大套餐客户展示规则,
  366. }
  367. }
  368. if len(itemBillTotal) > 0 {
  369. permissionNameSlice := []string{"医药", "消费", "科技", "智造"}
  370. var itemBillTotalNew []string
  371. for _, v := range permissionNameSlice {
  372. if itemBillTotalMap[v] == "" {
  373. itemBillTotalNew = append(itemBillTotalNew, fmt.Sprint(v, "0次"))
  374. } else {
  375. itemBillTotalNew = append(itemBillTotalNew, itemBillTotalMap[v])
  376. }
  377. }
  378. totalText = strings.Join(itemBillTotalNew, "+")
  379. }
  380. return
  381. }
  382. // 用户搜专项调研操作操作行为,模板消息推送
  383. func ActivitySpecialUserRmind(user *models.WxUserItem, activityId, TripStatus int) (err error) {
  384. defer func() {
  385. if err != nil {
  386. go utils.SendAlarmMsg("用户搜专项调研操作操作行为,模板消息推送失败"+err.Error(), 2)
  387. }
  388. }()
  389. countUser, err := models.GetUserRemind(user.UserId)
  390. if err != nil {
  391. return err
  392. }
  393. if countUser == 0 {
  394. return err
  395. }
  396. var first string
  397. var keyword1 string
  398. var keyword2 string
  399. var keyword3 string
  400. var keyword4 string
  401. var remark string
  402. //获取销售手机号
  403. sellerItemQy, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  404. if err != nil && err.Error() != utils.ErrNoRow() {
  405. return err
  406. }
  407. if sellerItemQy != nil {
  408. sllerAndShareMobileArr, e := GetCompanySellerAndShareMobileByRai(user.CompanyId) //获取所属销售以及对应销售的手机号
  409. if e != nil {
  410. err = errors.New("GetCompanySellerAndShareMobileByRai, Err: " + e.Error())
  411. return
  412. }
  413. sllerAndShareMobiles := strings.Join(sllerAndShareMobileArr, ",")
  414. openIdList, e := models.GetWxOpenIdByMobileList(sllerAndShareMobiles)
  415. if e != nil {
  416. err = errors.New("GetSellerByAdminId, Err: " + e.Error())
  417. return
  418. }
  419. activityInfo, e := models.GetCygxActivitySpecialDetailById(user.UserId, activityId)
  420. if e != nil {
  421. err = errors.New("GetCygxActivitySpecialDetailById, Err: " + e.Error())
  422. return
  423. }
  424. if activityInfo == nil {
  425. return
  426. }
  427. //TripStatus int `description:"行程进行状态 1:预报名,2:确定行程"`
  428. if TripStatus == 1 {
  429. keyword2 = fmt.Sprint("互动:专项调研预报名,", user.RealName, "--", user.CompanyName)
  430. } else {
  431. keyword2 = fmt.Sprint("互动:活动报名,", user.RealName, "--", user.CompanyName)
  432. }
  433. keyword1 = activityInfo.ResearchTheme
  434. //keyword2 = "__"
  435. remark = "点击查看活动详情"
  436. openIdArr := make([]string, 0)
  437. for _, v := range openIdList {
  438. openIdArr = append(openIdArr, v.OpenId)
  439. }
  440. redirectUrl := utils.WX_MSG_PATH_ACTIVITY_SPECIAL_DETAIL + strconv.Itoa(activityId)
  441. sendInfo := new(SendWxTemplate)
  442. sendInfo.First = first
  443. sendInfo.Keyword1 = keyword1
  444. sendInfo.Keyword2 = keyword2
  445. sendInfo.Keyword3 = keyword3
  446. sendInfo.Keyword4 = keyword4
  447. sendInfo.Remark = remark
  448. sendInfo.TemplateId = utils.WxMsgTemplateIdArticleUserRemind
  449. sendInfo.RedirectUrl = redirectUrl
  450. sendInfo.RedirectTarget = 3
  451. sendInfo.Resource = strconv.Itoa(activityId)
  452. sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ARTICLE_ADD
  453. sendInfo.OpenIdArr = openIdArr
  454. err = PublicSendTemplateMsg(sendInfo)
  455. if err != nil {
  456. return
  457. }
  458. }
  459. return
  460. }
  461. // 确定行程用户报名模版消息推送
  462. func ActivitySpecialUserAddTrip(user *models.WxUserItem, activityId int) (err error) {
  463. defer func() {
  464. if err != nil {
  465. go utils.SendAlarmMsg("确定行程用户报名模版消息推送,模板消息推送失败"+err.Error(), 2)
  466. }
  467. }()
  468. var first string
  469. var keyword1 string
  470. var keyword2 string
  471. var keyword3 string
  472. var keyword4 string
  473. var remark string
  474. //获取销售手机号
  475. sellerItemQy, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  476. if err != nil && err.Error() != utils.ErrNoRow() {
  477. return err
  478. }
  479. cnf, _ := models.GetConfigByCode("tpl_msg")
  480. if cnf != nil && sellerItemQy != nil {
  481. openIdList, e := models.GetWxOpenIdByMobileList(cnf.ConfigValue + "," + sellerItemQy.Mobile)
  482. if e != nil {
  483. err = errors.New("GetSellerByAdminId, Err: " + e.Error())
  484. return
  485. }
  486. activityInfo, e := models.GetCygxActivitySpecialDetailById(user.UserId, activityId)
  487. if e != nil {
  488. err = errors.New("GetCygxActivitySpecialDetailById, Err: " + e.Error())
  489. return
  490. }
  491. if activityInfo == nil {
  492. return
  493. }
  494. keyword1 = fmt.Sprint(user.RealName, "--", user.CompanyName, "(所属销售:", sellerItemQy.RealName, ")")
  495. keyword2 = user.Mobile
  496. keyword3 = time.Now().Format(utils.FormatDateTime)
  497. keyword4 = "报名专项调研【" + activityInfo.ResearchTheme + "】 "
  498. remark = ""
  499. openIdArr := make([]string, 0)
  500. for _, v := range openIdList {
  501. openIdArr = append(openIdArr, v.OpenId)
  502. }
  503. redirectUrl := utils.WX_MSG_PATH_ACTIVITY_SPECIAL_DETAIL + strconv.Itoa(activityId)
  504. sendInfo := new(SendWxTemplate)
  505. sendInfo.First = first
  506. sendInfo.Keyword1 = keyword1
  507. sendInfo.Keyword2 = keyword2
  508. sendInfo.Keyword3 = keyword3
  509. sendInfo.Keyword4 = keyword4
  510. sendInfo.Remark = remark
  511. sendInfo.TemplateId = utils.WxMsgTemplateIdApplyXzs
  512. sendInfo.RedirectUrl = redirectUrl
  513. sendInfo.RedirectTarget = 3
  514. sendInfo.Resource = strconv.Itoa(activityId)
  515. sendInfo.SendType = utils.TEMPLATE_MSG_CYGX_ARTICLE_ADD
  516. sendInfo.OpenIdArr = openIdArr
  517. err = PublicSendTemplateMsg(sendInfo)
  518. if err != nil {
  519. return
  520. }
  521. }
  522. return
  523. }