activity_special_trip.go 22 KB

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