pushSet.go 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  1. package service
  2. import (
  3. "app.yhyue.com/moapp/jybase/common"
  4. "bp.jydev.jianyu360.cn/BaseService/powerCheckCenter/rpc/pb"
  5. "fmt"
  6. IC "jyBXSubscribe/rpc/init"
  7. "jyBXSubscribe/rpc/type/bxsubscribe"
  8. "jyBXSubscribe/rpc/util"
  9. "regexp"
  10. )
  11. type PushSetService struct {
  12. UserId string //mongodb 的用户id
  13. PositionType int64
  14. EntId int64
  15. EntUserId int64
  16. BaseUserId int64
  17. AccountId int64
  18. PositionId int64
  19. MgoUserId string
  20. }
  21. func (this *PushSetService) Update(item, setType, pushType string, ratemode, pushValue, interested int64, times []string) bool {
  22. set := map[string]interface{}{}
  23. switch setType {
  24. case "pushRoute":
  25. set = map[string]interface{}{
  26. fmt.Sprintf("o_pushset.%s.%s", item, pushType): common.IntAll(pushValue),
  27. }
  28. break
  29. case "a_times":
  30. if ratemode == 2 {
  31. if len(times) == 0 {
  32. return false
  33. }
  34. }
  35. set = map[string]interface{}{
  36. fmt.Sprintf("o_pushset.%s.a_times", item): times,
  37. fmt.Sprintf("o_pushset.%s.i_ratemode", item): common.IntAll(ratemode),
  38. }
  39. case "message":
  40. set = map[string]interface{}{
  41. fmt.Sprintf("o_pushset.%s.%s", item, pushType): common.IntAll(pushValue),
  42. }
  43. default:
  44. set = map[string]interface{}{
  45. "o_pushset.i_interested": common.IntAll(interested),
  46. }
  47. }
  48. update := false
  49. if (setType == "message" && this.PositionType == 1) || this.PositionType == 0 {
  50. update = IC.Mgo.UpdateById(util.USER, this.UserId, map[string]interface{}{
  51. "$set": set,
  52. })
  53. } else {
  54. update = IC.Mgo.Update(util.ENTUSER, map[string]interface{}{"i_entid": this.EntId, "i_userid": this.EntUserId}, map[string]interface{}{
  55. "$set": set,
  56. }, true, false)
  57. }
  58. return update
  59. }
  60. func (this *PushSetService) Find() map[string]*bxsubscribe.PushSet {
  61. pushSetMap := &map[string]interface{}{}
  62. o_msgPushSet := map[string]interface{}{}
  63. //
  64. ShowWx := false
  65. s_m_openid := ""
  66. pushSetMap, _ = IC.Mgo.FindById(util.USER, this.UserId, `{"o_pushset":":1,"s_m_openid":1}`)
  67. if pushSetMap != nil && len(*pushSetMap) > 0 {
  68. s_m_openid = common.InterfaceToStr((*pushSetMap)["s_m_openid"])
  69. o_msgPushSet, _ = (*pushSetMap)["o_pushset"].(map[string]interface{})
  70. }
  71. if s_m_openid != "" {
  72. //微信是否关注处理
  73. subscribeList := &[]map[string]interface{}{}
  74. subscribeList, _ = IC.Mgo.Find(util.SUBSCRIBE, map[string]interface{}{"s_m_openid": s_m_openid}, `{"l_date":-1}`, `{"s_event":1"}`, true, -1, -1)
  75. if subscribeList != nil && len(*subscribeList) > 0 {
  76. s_event := common.InterfaceToStr((*subscribeList)[0]["s_event"])
  77. if s_event == "subscribe" {
  78. ShowWx = true
  79. }
  80. }
  81. }
  82. if this.PositionType == 1 {
  83. pushSetMap, _ = IC.Mgo.FindOne(util.ENTUSER, map[string]interface{}{"i_entid": this.EntId, "i_userid": this.EntUserId})
  84. }
  85. pushSet := map[string]*bxsubscribe.PushSet{}
  86. //用户权益获取
  87. powerData := IC.Middleground.PowerCheckCenter.Check("10000", this.MgoUserId, this.BaseUserId, this.AccountId, this.EntId, this.PositionType, this.PositionId)
  88. o_pushset := map[string]interface{}{}
  89. if pushSetMap != nil && len(*pushSetMap) > 0 {
  90. o_pushset, _ = (*pushSetMap)["o_pushset"].(map[string]interface{})
  91. }
  92. if o_pushset != nil {
  93. pushSet["interested"] = &bxsubscribe.PushSet{
  94. Interested: common.Int64All(common.If(o_pushset["i_interested"] == nil, 1, common.Int64All(o_pushset["i_interested"]))),
  95. }
  96. } else {
  97. pushSet["interested"] = &bxsubscribe.PushSet{
  98. Interested: 1,
  99. }
  100. }
  101. //推送设置
  102. fool, o_subset := pushSetMontage(o_pushset["o_subset"], "o_subset", powerData, ShowWx)
  103. if fool {
  104. pushSet["o_subset"] = o_subset
  105. }
  106. fool, o_week_report := pushSetMontage(o_pushset["o_week_report"], "o_week_report", powerData, ShowWx)
  107. if fool {
  108. pushSet["o_week_report"] = o_week_report
  109. }
  110. fool, o_month_report := pushSetMontage(o_pushset["o_month_report"], "o_month_report", powerData, ShowWx)
  111. if fool {
  112. pushSet["o_month_report"] = o_month_report
  113. }
  114. fool, o_newproject_forecast := pushSetMontage(o_pushset["o_newproject_forecast"], "o_newproject_forecast", powerData, ShowWx)
  115. if fool {
  116. pushSet["o_newproject_forecast"] = o_newproject_forecast
  117. }
  118. //企业信息
  119. fool, o_entinfo := pushSetMontage(o_pushset["o_entinfo"], "o_entinfo", powerData, ShowWx)
  120. if fool {
  121. pushSet["o_entinfo"] = o_entinfo
  122. }
  123. //项目关注
  124. fool, o_follow_project := pushSetMontage(o_pushset["o_follow_project"], "o_follow_project", powerData, ShowWx)
  125. if fool {
  126. pushSet["o_follow_project"] = o_follow_project
  127. }
  128. //业主监控 P303
  129. fool, o_owner_monitor := pushSetMontage(o_pushset["o_owner_monitor"], "o_owner_monitor", powerData, ShowWx)
  130. if fool {
  131. pushSet["o_owner_monitor"] = o_owner_monitor
  132. }
  133. //企业关注
  134. fool, o_follow_ent := pushSetMontage(o_pushset["o_follow_ent"], "o_follow_ent", powerData, ShowWx)
  135. if fool {
  136. pushSet["o_follow_ent"] = o_follow_ent
  137. }
  138. //消息
  139. fool, o_msg_active := pushSetMontage(o_msgPushSet["o_msg_active"], "o_msg_active", powerData, ShowWx)
  140. if fool {
  141. pushSet["o_msg_active"] = o_msg_active
  142. }
  143. //消息服务
  144. fool, o_msg_service := pushSetMontage(o_msgPushSet["o_msg_service"], "o_msg_service", powerData, ShowWx)
  145. if fool {
  146. pushSet["o_msg_service"] = o_msg_service
  147. }
  148. //剑鱼学堂
  149. fool, o_msg_jyschool := pushSetMontage(o_msgPushSet["o_msg_jyschool"], "o_msg_jyschool", powerData, ShowWx)
  150. if fool {
  151. pushSet["o_msg_jyschool"] = o_msg_jyschool
  152. }
  153. fool, o_msg_business := pushSetMontage(o_msgPushSet["o_msg_business"], "o_msg_business", powerData, ShowWx)
  154. if fool {
  155. pushSet["o_msg_business"] = o_msg_business
  156. }
  157. //私信
  158. fool, o_msg_pending := pushSetMontage(o_msgPushSet["o_msg_pending"], "o_msg_business", powerData, ShowWx)
  159. if fool {
  160. pushSet["o_msg_pending"] = o_msg_pending
  161. }
  162. fool, o_msg_privateletter := pushSetMontage(o_msgPushSet["o_msg_privateletter"], "o_msg_privateletter", powerData, ShowWx)
  163. if fool {
  164. pushSet["o_msg_privateletter"] = o_msg_privateletter
  165. }
  166. return pushSet
  167. }
  168. func pushSetMontage(in interface{}, name string, powerData *pb.CheckResp, ShowWx bool) (bool, *bxsubscribe.PushSet) {
  169. data := common.ObjToMap(in)
  170. a_times := []string{}
  171. isMailShow := int64(1)
  172. isReturnMailShow := true
  173. if !(data == nil || len(*data) == 0) {
  174. if (*data)["a_times"] != nil {
  175. a_times = common.ObjArrToStringArr((*data)["a_times"].([]interface{}))
  176. }
  177. }
  178. power := make(map[int]bool)
  179. for _, v := range powerData.Member.MemberPowerList {
  180. power[common.IntAll(v)] = true
  181. }
  182. returnData := &bxsubscribe.PushSet{}
  183. switch name {
  184. case "o_subset":
  185. if powerData.Free.IsFree {
  186. returnData = &bxsubscribe.PushSet{
  187. ATimes: []string{"每日上午、下午各推送1次"},
  188. IApppush: common.Int64All(common.If((*data)["i_apppush"] == nil, 0, (*data)["i_apppush"])),
  189. IApppushTip: common.Int64All(common.If((*data)["i_apppush_tip"] == nil, 0, (*data)["i_apppush_tip"])),
  190. IWxpush: common.Int64All(common.If((*data)["i_wxpush"] == nil, common.If(ShowWx, 1, 0), common.If(ShowWx, (*data)["i_wxpush"], 0))),
  191. IMailpush: common.Int64All(common.If((*data)["i_mailpush"] == nil, 0, (*data)["i_mailpush"])),
  192. IRatemode: 2,
  193. IsWxShow: 1,
  194. INomsgtip: common.Int64All(common.If((*data)["i_nomsgtip"] == nil, 1, (*data)["i_nomsgtip"])),
  195. }
  196. } else {
  197. if data == nil || len(*data) == 0 {
  198. returnData = &bxsubscribe.PushSet{
  199. ATimes: util.TimeMap[2],
  200. IApppush: 0,
  201. IApppushTip: 0,
  202. IWxpush: common.Int64All(common.If(ShowWx, 1, 0)),
  203. IMailpush: 0,
  204. IRatemode: 2,
  205. IsWxShow: 1,
  206. INomsgtip: 1,
  207. }
  208. } else {
  209. returnData = &bxsubscribe.PushSet{
  210. ATimes: common.If((*data)["i_ratemode"] == nil, util.TimeMap[2], a_times).([]string),
  211. IApppush: common.Int64All(common.If((*data)["i_apppush"] == nil, 0, (*data)["i_apppush"])),
  212. IApppushTip: common.Int64All(common.If((*data)["i_apppush_tip"] == nil, 0, (*data)["i_apppush_tip"])),
  213. IWxpush: common.Int64All(common.If((*data)["i_wxpush"] == nil, common.If(ShowWx, 1, 0), common.If(ShowWx, (*data)["i_wxpush"], 0))),
  214. IMailpush: common.Int64All(common.If((*data)["i_mailpush"] == nil, 0, (*data)["i_mailpush"])),
  215. IRatemode: common.Int64All(common.If((*data)["i_ratemode"] == nil, 2, (*data)["i_ratemode"])),
  216. IsWxShow: 1,
  217. INomsgtip: common.Int64All(common.If((*data)["i_nomsgtip"] == nil, 1, (*data)["i_nomsgtip"])),
  218. }
  219. if common.Int64All((*data)["i_ratemode"]) == 5 {
  220. returnData.ATimes = []string{"14:00"}
  221. }
  222. }
  223. }
  224. case "o_follow_project", "o_follow_ent":
  225. if powerData.Free.IsFree {
  226. returnData = &bxsubscribe.PushSet{
  227. ATimes: []string{"实时推送"},
  228. IApppush: common.Int64All(common.If((*data)["i_apppush"] == nil, 1, (*data)["i_apppush"])),
  229. IWxpush: common.Int64All(common.If((*data)["i_wxpush"] == nil, common.If(ShowWx, 1, 0), common.If(ShowWx, (*data)["i_wxpush"], 0))),
  230. IMailpush: common.Int64All(common.If((*data)["i_mailpush"] == nil, 0, (*data)["i_mailpush"])),
  231. IRatemode: 1,
  232. IsWxShow: 1,
  233. }
  234. } else if data == nil || len(*data) == 0 {
  235. a_times = append(a_times, "实时推送")
  236. returnData = &bxsubscribe.PushSet{
  237. ATimes: a_times,
  238. IApppush: 1,
  239. IWxpush: common.Int64All(common.If(ShowWx, 1, 0)),
  240. IMailpush: 0,
  241. IRatemode: 1,
  242. IsWxShow: 1,
  243. }
  244. } else {
  245. returnData = &bxsubscribe.PushSet{
  246. ATimes: a_times,
  247. IApppush: common.Int64All(common.If((*data)["i_apppush"] == nil, 1, (*data)["i_apppush"])),
  248. IWxpush: common.Int64All(common.If((*data)["i_wxpush"] == nil, common.If(ShowWx, 1, 0), common.If(ShowWx, (*data)["i_wxpush"], 0))),
  249. IMailpush: common.Int64All(common.If((*data)["i_mailpush"] == nil, 0, (*data)["i_mailpush"])),
  250. IRatemode: common.Int64All(common.If((*data)["i_ratemode"] == nil, 1, (*data)["i_ratemode"])),
  251. IsWxShow: 1,
  252. }
  253. }
  254. case "o_newproject_forecast":
  255. if powerData.Member.Status > 0 && power[9] {
  256. if data == nil || len(*data) == 0 {
  257. a_times = append(a_times, "实时推送")
  258. returnData = &bxsubscribe.PushSet{
  259. ATimes: a_times,
  260. IApppush: 1,
  261. IWxpush: common.Int64All(common.If(ShowWx, 1, 0)),
  262. IMailpush: 0,
  263. IRatemode: 1,
  264. IsWxShow: 0,
  265. }
  266. } else {
  267. returnData = &bxsubscribe.PushSet{
  268. ATimes: a_times,
  269. IApppush: common.Int64All(common.If((*data)["i_apppush"] == nil, 1, (*data)["i_apppush"])),
  270. IWxpush: common.Int64All(common.If((*data)["i_wxpush"] == nil, common.If(ShowWx, 1, 0), common.If(ShowWx, (*data)["i_wxpush"], 0))),
  271. IMailpush: common.Int64All(common.If((*data)["i_mailpush"] == nil, 0, (*data)["i_mailpush"])),
  272. IRatemode: common.Int64All(common.If((*data)["i_ratemode"] == nil, 1, (*data)["i_ratemode"])),
  273. IsWxShow: 0,
  274. }
  275. }
  276. } else {
  277. return false, nil
  278. }
  279. case "o_owner_monitor":
  280. //付费用户
  281. powerData.Free.IsFree = false
  282. if !powerData.Free.IsFree {
  283. if data == nil || len(*data) == 0 {
  284. a_times = append(a_times, "实时推送")
  285. returnData = &bxsubscribe.PushSet{
  286. ATimes: a_times,
  287. IApppush: 1,
  288. IWxpush: common.Int64All(common.If(ShowWx, 1, 0)),
  289. IMailpush: 0,
  290. IRatemode: 1,
  291. IsWxShow: 0,
  292. }
  293. } else {
  294. returnData = &bxsubscribe.PushSet{
  295. ATimes: a_times,
  296. IApppush: common.Int64All(common.If((*data)["i_apppush"] == nil, 1, (*data)["i_apppush"])),
  297. IWxpush: common.Int64All(common.If((*data)["i_wxpush"] == nil, common.If(ShowWx, 1, 0), common.If(ShowWx, (*data)["i_wxpush"], 0))),
  298. IMailpush: common.Int64All(common.If((*data)["i_mailpush"] == nil, 0, (*data)["i_mailpush"])),
  299. IRatemode: common.Int64All(common.If((*data)["i_ratemode"] == nil, 1, (*data)["i_ratemode"])),
  300. IsWxShow: 0,
  301. }
  302. }
  303. } else {
  304. return false, nil
  305. }
  306. case "o_entinfo":
  307. if powerData.Member.Status > 0 && power[12] {
  308. if data == nil || len(*data) == 0 {
  309. a_times = append(a_times, "实时推送")
  310. returnData = &bxsubscribe.PushSet{
  311. ATimes: a_times,
  312. IApppush: 1,
  313. IWxpush: common.Int64All(common.If(ShowWx, 1, 0)),
  314. IMailpush: 0,
  315. IRatemode: 1,
  316. IsWxShow: 0,
  317. }
  318. } else {
  319. returnData = &bxsubscribe.PushSet{
  320. ATimes: a_times,
  321. IApppush: common.Int64All(common.If((*data)["i_apppush"] == nil, 1, (*data)["i_apppush"])),
  322. IWxpush: common.Int64All(common.If((*data)["i_wxpush"] == nil, common.If(ShowWx, 1, 0), common.If(ShowWx, (*data)["i_wxpush"], 0))),
  323. IMailpush: common.Int64All(common.If((*data)["i_mailpush"] == nil, 0, (*data)["i_mailpush"])),
  324. IRatemode: common.Int64All(common.If((*data)["i_ratemode"] == nil, 1, (*data)["i_ratemode"])),
  325. IsWxShow: 0,
  326. }
  327. }
  328. } else {
  329. return false, nil
  330. }
  331. case "o_week_report", "o_month_report":
  332. if powerData.Vip.Status > 0 || power[10] {
  333. if name == "o_week_report" {
  334. a_times = append(a_times, "每周推送 (周一 08:00)")
  335. } else {
  336. a_times = append(a_times, "每月推送 (1日 08:00)")
  337. }
  338. IsWxShow := int64(0)
  339. if powerData.Vip.Status > 0 {
  340. IsWxShow = int64(1)
  341. }
  342. if !power[10] {
  343. isMailShow = int64(0)
  344. }
  345. if data == nil || len(*data) == 0 {
  346. returnData = &bxsubscribe.PushSet{
  347. ATimes: a_times,
  348. IApppush: 1,
  349. IWxpush: common.Int64All(common.If(ShowWx, 1, 0)),
  350. IMailpush: 0,
  351. IRatemode: 3,
  352. IsWxShow: IsWxShow,
  353. }
  354. } else {
  355. returnData = &bxsubscribe.PushSet{
  356. ATimes: a_times,
  357. IApppush: common.Int64All(common.If((*data)["i_apppush"] == nil, 1, (*data)["i_apppush"])),
  358. IWxpush: common.Int64All(common.If((*data)["i_wxpush"] == nil, common.If(ShowWx, 1, 0), common.If(ShowWx, (*data)["i_wxpush"], 0))),
  359. IMailpush: common.Int64All(common.If((*data)["i_mailpush"] == nil, 0, (*data)["i_mailpush"])),
  360. IRatemode: 3,
  361. IsWxShow: IsWxShow,
  362. }
  363. }
  364. } else {
  365. return false, nil
  366. }
  367. case "o_msg_active", "o_msg_service", "o_msg_jyschool", "o_msg_privateletter", "o_msg_business", "o_msg_pending":
  368. isReturnMailShow = false
  369. var isWXShow int64
  370. isWXShow = 1
  371. if name == "o_msg_active" {
  372. isWXShow = 0
  373. }
  374. if data == nil || len(*data) == 0 {
  375. returnData = &bxsubscribe.PushSet{
  376. IApppush: 0,
  377. IWxpush: 0,
  378. IsWxShow: isWXShow,
  379. }
  380. } else {
  381. returnData = &bxsubscribe.PushSet{
  382. IApppush: common.Int64All(common.If((*data)["i_apppush"] == nil, 0, (*data)["i_apppush"])),
  383. IWxpush: common.Int64All(common.If((*data)["i_wxpush"] == nil, 0, (*data)["i_wxpush"])),
  384. IsWxShow: isWXShow,
  385. }
  386. }
  387. }
  388. if isReturnMailShow {
  389. returnData.IsMailShow = isMailShow
  390. }
  391. return true, returnData
  392. }
  393. func (this *PushSetService) SetUser(mail string) (bool, string) {
  394. var emailPattern = regexp.MustCompile("^([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$")
  395. if !emailPattern.MatchString(mail) {
  396. return false, "邮箱格式不正确"
  397. }
  398. set := map[string]interface{}{
  399. "o_pushset.s_email": mail,
  400. }
  401. update := false
  402. if this.PositionType == 0 {
  403. update = IC.Mgo.UpdateById(util.USER, this.UserId, map[string]interface{}{
  404. "$set": set,
  405. })
  406. } else {
  407. update = IC.Mgo.Update(util.ENTUSER, map[string]interface{}{"i_entid": this.EntId, "i_userid": this.EntUserId}, map[string]interface{}{
  408. "$set": set,
  409. }, true, false)
  410. IC.MainMysql.UpdateOrDeleteBySql(`update entniche_user set mail=? where id=? and ent_id=?`, mail, this.EntUserId, this.EntId)
  411. }
  412. return update, ""
  413. }