struct.go 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957
  1. package p
  2. import (
  3. "encoding/json"
  4. "sort"
  5. "strings"
  6. util "app.yhyue.com/moapp/jybase/common"
  7. "app.yhyue.com/moapp/jybase/logger"
  8. . "app.yhyue.com/moapp/jybase/mongodb"
  9. . "app.yhyue.com/moapp/jybase/mysql"
  10. "bp.jydev.jianyu360.cn/BaseService/pushpkg/dfa"
  11. )
  12. type MgoConf struct {
  13. Address string
  14. Size int
  15. DbName string
  16. ReplSet string
  17. UserName string
  18. Password string
  19. Collection string
  20. ExperienceDbName string
  21. }
  22. type RedisConf struct {
  23. Address string
  24. }
  25. type MysqlConf struct {
  26. DbName string
  27. Address string
  28. UserName string
  29. PassWord string
  30. MaxOpenConns int
  31. MaxIdleConns int
  32. }
  33. type EsConf struct {
  34. Address string
  35. Size int
  36. Version string
  37. UserName string
  38. Password string
  39. }
  40. type MemberService struct {
  41. IsBuy bool
  42. Services map[int]*memberService
  43. }
  44. type memberService struct {
  45. Id int
  46. StartTime string
  47. }
  48. // 关键词
  49. type KeySet struct {
  50. Item string `json:"item"` //分类名称
  51. Keys []string `json:"key"` //关键词
  52. NotKeys []string `json:"notkey"` //排除词
  53. SubTypes []string `json:"infotype"` //信息类型
  54. Areas []string `json:"area"` //地区
  55. AppendKeys []string `json:"appendkey"` //附加词
  56. MatchWay int `json:"matchway"` //匹配模式 0:精准匹配 1:模糊匹配
  57. }
  58. // 解析订阅词
  59. type SubSet struct {
  60. Matchbuyerclass_other int //是否开启其他按钮
  61. ProjectMatch int //项目关联推送
  62. Items []string //关键词分类
  63. Keys []string //过滤后的关键词
  64. Notkeys []string //排除词
  65. Key_item map[string]string //关键词对应的分类名称
  66. Key_notkey map[string]map[string]bool //关键词所对应的排除词
  67. Key_area map[string]map[string]bool //关键词所对应的信息范围
  68. Key_subtype map[string]map[string]bool //关键词所对应的信息类型
  69. OriginalKeys []string //原始关键词
  70. Areas []string //区域-省份
  71. Area map[string]interface{} //区域-省份
  72. District map[string]interface{} //区域-区县
  73. Subtype []interface{} //信息类型-二级分类
  74. Subtypes []string //信息类型-二级分类
  75. Buyerclass []interface{} //采购单位行业
  76. Buyerclasss []string //采购单位行业
  77. IsUpgrade bool //免费用户是否订阅升级
  78. MaxPushSize int //推送最大条数
  79. MaxMailSize int //邮件最大条数
  80. Switch int //开关
  81. MatchMode []string //匹配方式 title detail filetext projectname/purchasing
  82. Amount string //金额
  83. StartAmount float64 //开始金额
  84. EndAmount float64 //结束金额
  85. BusinessType []string //业务类型
  86. }
  87. // 推送设置
  88. type PushSet struct {
  89. Email string //邮箱
  90. SubSet *PushSetChild //订阅推送设置
  91. WeekReport *PushSetChild //周报推送设置
  92. MonthReport *PushSetChild //月报推送设置
  93. NewprojectForecast *PushSetChild //潜在项目预测推送设置
  94. EntInfo *PushSetChild //企业情报监控-企业工商变动推送设置
  95. FollowProject *PushSetChild //项目进度监控推送设置
  96. FollowEnt *PushSetChild //企业情报监控-企业中标动态推送设置
  97. OwnerMonitor *PushSetChild //业主监控推送设置
  98. }
  99. func (p *PushSet) Reset() {
  100. //
  101. if p.SubSet != nil {
  102. if p.SubSet.RateMode < 1 || p.SubSet.RateMode > 4 {
  103. p.SubSet.RateMode = 2
  104. if len(p.SubSet.Times) == 0 {
  105. p.SubSet.Times = append(p.SubSet.Times, "09:00", "14:00")
  106. }
  107. } else if p.SubSet.RateMode == 2 && len(p.SubSet.Times) == 0 {
  108. p.SubSet.Times = append(p.SubSet.Times, "09:00")
  109. }
  110. sort.Strings(p.SubSet.Times)
  111. }
  112. //
  113. if p.EntInfo != nil {
  114. if p.EntInfo.RateMode < 1 || p.EntInfo.RateMode > 4 {
  115. p.EntInfo.RateMode = 1
  116. if len(p.EntInfo.Times) == 0 {
  117. p.EntInfo.Times = append(p.EntInfo.Times, "09:00", "14:00")
  118. }
  119. } else if p.EntInfo.RateMode == 2 && len(p.EntInfo.Times) == 0 {
  120. p.EntInfo.Times = append(p.EntInfo.Times, "09:00")
  121. }
  122. sort.Strings(p.EntInfo.Times)
  123. }
  124. //
  125. if p.NewprojectForecast != nil {
  126. if p.NewprojectForecast.RateMode < 1 || p.NewprojectForecast.RateMode > 4 {
  127. p.NewprojectForecast.RateMode = 1
  128. if len(p.NewprojectForecast.Times) == 0 {
  129. p.NewprojectForecast.Times = append(p.NewprojectForecast.Times, "09:00", "14:00")
  130. }
  131. } else if p.NewprojectForecast.RateMode == 2 && len(p.NewprojectForecast.Times) == 0 {
  132. p.NewprojectForecast.Times = append(p.NewprojectForecast.Times, "09:00")
  133. }
  134. sort.Strings(p.NewprojectForecast.Times)
  135. }
  136. //
  137. if p.FollowProject != nil {
  138. if p.FollowProject.RateMode < 1 || p.FollowProject.RateMode > 4 {
  139. p.FollowProject.RateMode = 1
  140. if len(p.FollowProject.Times) == 0 {
  141. p.FollowProject.Times = append(p.FollowProject.Times, "09:00", "14:00")
  142. }
  143. } else if p.FollowProject.RateMode == 2 && len(p.FollowProject.Times) == 0 {
  144. p.FollowProject.Times = append(p.FollowProject.Times, "09:00")
  145. }
  146. sort.Strings(p.FollowProject.Times)
  147. }
  148. //
  149. if p.FollowEnt != nil {
  150. if p.FollowEnt.RateMode < 1 || p.FollowEnt.RateMode > 4 {
  151. p.FollowEnt.RateMode = 1
  152. if len(p.FollowEnt.Times) == 0 {
  153. p.FollowEnt.Times = append(p.FollowEnt.Times, "09:00", "14:00")
  154. }
  155. } else if p.FollowEnt.RateMode == 2 && len(p.FollowEnt.Times) == 0 {
  156. p.FollowEnt.Times = append(p.FollowEnt.Times, "09:00")
  157. }
  158. sort.Strings(p.FollowEnt.Times)
  159. }
  160. //
  161. if p.OwnerMonitor != nil {
  162. if p.OwnerMonitor.RateMode < 1 || p.OwnerMonitor.RateMode > 4 {
  163. p.OwnerMonitor.RateMode = 1
  164. if len(p.OwnerMonitor.Times) == 0 {
  165. p.OwnerMonitor.Times = append(p.OwnerMonitor.Times, "09:00", "14:00")
  166. }
  167. } else if p.OwnerMonitor.RateMode == 2 && len(p.OwnerMonitor.Times) == 0 {
  168. p.OwnerMonitor.Times = append(p.OwnerMonitor.Times, "09:00")
  169. }
  170. sort.Strings(p.OwnerMonitor.Times)
  171. }
  172. }
  173. type PushSetChild struct {
  174. RateMode int //推送时间
  175. Times []string //自定义推送时间
  176. WxPush int //是否开启微信推送
  177. AppPush int //是否开启app推送
  178. MailPush int //是否开启邮箱推送
  179. Nomsgtip int //是否开启无消息推送提醒
  180. }
  181. // 用户基本信息
  182. type UserInfo struct {
  183. Id string //mongoid
  184. PositionId int64 //职位id
  185. BaseUserId int64 //mysql用户id
  186. AccountId int64 //账户id
  187. S_m_openid string //公众号openid
  188. A_m_openid string //app微信登录openid
  189. Phone string //app手机号登录
  190. Jpushid string //极光推送id
  191. Opushid string //厂商推送id
  192. AppPhoneType string //手机型号
  193. Subscribe int //是否关注
  194. VipStatus int //超级订阅 1--试用 2--正式
  195. MemberStatus int //大会员
  196. NicheStatus int //商机管理
  197. IsMainAccount bool //是否是主账号
  198. SonAccountStatus int //子账号状态 0-禁用 1-启用
  199. MemberMainid string //主账号id
  200. SubPushInactive int //活跃状态
  201. Entniche *Entniche
  202. WxTplMsg *WxTplMsg
  203. SubSet *SubSet
  204. PushSet *PushSet
  205. Extend *UserInfoExtend
  206. }
  207. /*
  208. *获取用户信息
  209. *temp 用户数据
  210. *tp 1-免费 2-超级订阅 3-大会员
  211. */
  212. func NewUserInfo(temp map[string]interface{}, tp int) *UserInfo {
  213. ui := &UserInfo{
  214. Id: BsonIdToSId(temp["_id"]),
  215. BaseUserId: util.Int64All(temp["base_user_id"]),
  216. S_m_openid: util.ObjToString(temp["s_m_openid"]),
  217. A_m_openid: util.ObjToString(temp["a_m_openid"]),
  218. Phone: GetPhone(temp),
  219. Jpushid: util.ObjToString(temp["s_jpushid"]),
  220. Opushid: util.ObjToString(temp["s_opushid"]),
  221. AppPhoneType: util.ObjToString(temp["s_appponetype"]),
  222. Subscribe: util.IntAllDef(temp["i_ispush"], 1),
  223. VipStatus: util.IntAll(temp["i_vip_status"]),
  224. MemberStatus: util.IntAll(temp["i_member_status"]),
  225. SubPushInactive: util.IntAll(temp["subpush_inactive"]),
  226. }
  227. if ui.MemberStatus > 0 {
  228. ui.IsMainAccount = util.IntAll(temp["i_mainaccount"]) == 1
  229. ui.SonAccountStatus = util.IntAllDef(temp["i_member_sub_status"], -1)
  230. ui.MemberMainid = util.ObjToString(temp["s_member_mainid"])
  231. }
  232. if tp == 3 {
  233. obj, _ := temp["o_member_jy"].(map[string]interface{})
  234. ui.GetSubSet(false, ui.Id, obj)
  235. } else if tp == 2 {
  236. obj, _ := temp["o_vipjy"].(map[string]interface{})
  237. ui.GetSubSet(false, ui.Id, obj)
  238. } else if tp == 1 {
  239. obj, _ := temp["o_jy"].(map[string]interface{})
  240. ui.GetSubSet(true, ui.Id, obj)
  241. } else {
  242. ui.SubSet = &SubSet{}
  243. }
  244. o_pushset, _ := temp["o_pushset"].(map[string]interface{})
  245. ui.GetPushSet(o_pushset)
  246. ui.PushSetFilter()
  247. return ui
  248. }
  249. //
  250. func NewMyUserInfo(Mgo *MongodbSim, msl *Mysql, userId string) *UserInfo {
  251. var user *map[string]interface{}
  252. if IsObjectIdHex(userId) {
  253. user, _ = Mgo.FindById(Mgo_User, userId, UserCollFields)
  254. } else {
  255. user = GetAllByEntPositionId(Mgo, msl, util.IntAll(userId))
  256. }
  257. if user == nil || len(*user) == 0 {
  258. logger.Error(userId, "没有找到该用户信息")
  259. return nil
  260. }
  261. ui := NewUserInfo(*user, 0)
  262. ui.Id = userId
  263. return ui
  264. }
  265. //
  266. func NewMyUserInfoByEntUserId(Mgo *MongodbSim, Mysql *Mysql, userId string) *UserInfo {
  267. var user *map[string]interface{}
  268. if IsObjectIdHex(userId) {
  269. user, _ = Mgo.FindById(Mgo_User, userId, UserCollFields)
  270. } else {
  271. user = GetAllByEntUserId(Mgo, Mysql, util.IntAll(userId))
  272. }
  273. if user == nil || len(*user) == 0 {
  274. logger.Error(userId, "没有找到该用户信息")
  275. return nil
  276. }
  277. ui := NewUserInfo(*user, 0)
  278. ui.Id = userId
  279. return ui
  280. }
  281. // 解析用户的推送设置
  282. func (u *UserInfo) GetPushSet(obj map[string]interface{}) {
  283. subSet, _ := obj["o_subset"].(map[string]interface{})
  284. subSet_times, _ := subSet["a_times"].([]interface{})
  285. weekReport, _ := obj["o_week_report"].(map[string]interface{})
  286. monthReport, _ := obj["o_month_report"].(map[string]interface{})
  287. newprojectForecast, _ := obj["o_newproject_forecast"].(map[string]interface{})
  288. newprojectForecast_times, _ := newprojectForecast["a_times"].([]interface{})
  289. entInfo, _ := obj["o_entinfo"].(map[string]interface{})
  290. entInfo_times, _ := entInfo["a_times"].([]interface{})
  291. followProject, _ := obj["o_follow_project"].(map[string]interface{})
  292. followProject_times, _ := followProject["a_times"].([]interface{})
  293. followEnt, _ := obj["o_follow_ent"].(map[string]interface{})
  294. followEnt_times, _ := followEnt["a_times"].([]interface{})
  295. ownerMonitor, _ := obj["o_owner_monitor"].(map[string]interface{})
  296. ownerMonitor_times, _ := ownerMonitor["a_times"].([]interface{})
  297. u.PushSet = &PushSet{
  298. Email: strings.TrimSpace(util.ObjToString(obj["s_email"])),
  299. SubSet: &PushSetChild{
  300. WxPush: util.IntAllDef(subSet["i_wxpush"], 1),
  301. AppPush: util.IntAllDef(subSet["i_apppush"], 0),
  302. MailPush: util.IntAll(subSet["i_mailpush"]),
  303. RateMode: util.IntAll(subSet["i_ratemode"]),
  304. Times: util.ObjArrToStringArr(subSet_times),
  305. Nomsgtip: util.IntAllDef(subSet["i_nomsgtip"], 1), //默认开启
  306. },
  307. WeekReport: &PushSetChild{
  308. WxPush: util.IntAllDef(weekReport["i_wxpush"], 1),
  309. AppPush: util.IntAllDef(weekReport["i_apppush"], 1),
  310. MailPush: util.IntAll(weekReport["i_mailpush"]),
  311. },
  312. MonthReport: &PushSetChild{
  313. WxPush: util.IntAllDef(monthReport["i_wxpush"], 1),
  314. AppPush: util.IntAllDef(monthReport["i_apppush"], 1),
  315. MailPush: util.IntAll(monthReport["i_mailpush"]),
  316. },
  317. NewprojectForecast: &PushSetChild{
  318. WxPush: util.IntAllDef(newprojectForecast["i_wxpush"], 1),
  319. AppPush: util.IntAllDef(newprojectForecast["i_apppush"], 1),
  320. MailPush: util.IntAll(newprojectForecast["i_mailpush"]),
  321. RateMode: util.IntAll(newprojectForecast["i_ratemode"]),
  322. Times: util.ObjArrToStringArr(newprojectForecast_times),
  323. },
  324. EntInfo: &PushSetChild{
  325. WxPush: util.IntAllDef(entInfo["i_wxpush"], 1),
  326. AppPush: util.IntAllDef(entInfo["i_apppush"], 1),
  327. MailPush: util.IntAll(entInfo["i_mailpush"]),
  328. RateMode: util.IntAll(entInfo["i_ratemode"]),
  329. Times: util.ObjArrToStringArr(entInfo_times),
  330. },
  331. FollowProject: &PushSetChild{
  332. WxPush: util.IntAllDef(followProject["i_wxpush"], 1),
  333. AppPush: util.IntAllDef(followProject["i_apppush"], 1),
  334. MailPush: util.IntAll(followProject["i_mailpush"]),
  335. RateMode: util.IntAll(followProject["i_ratemode"]),
  336. Times: util.ObjArrToStringArr(followProject_times),
  337. },
  338. FollowEnt: &PushSetChild{
  339. WxPush: util.IntAllDef(followEnt["i_wxpush"], 1),
  340. AppPush: util.IntAllDef(followEnt["i_apppush"], 1),
  341. MailPush: util.IntAll(followEnt["i_mailpush"]),
  342. RateMode: util.IntAll(followEnt["i_ratemode"]),
  343. Times: util.ObjArrToStringArr(followEnt_times),
  344. },
  345. OwnerMonitor: &PushSetChild{
  346. WxPush: util.IntAllDef(ownerMonitor["i_wxpush"], 1),
  347. AppPush: util.IntAllDef(ownerMonitor["i_apppush"], 1),
  348. MailPush: util.IntAll(ownerMonitor["i_mailpush"]),
  349. RateMode: util.IntAll(ownerMonitor["i_ratemode"]),
  350. Times: util.ObjArrToStringArr(ownerMonitor_times),
  351. },
  352. }
  353. u.PushSet.Reset()
  354. }
  355. // 解析用户的推送设置
  356. func (u *UserInfo) PushSetFilter() {
  357. if u.Subscribe == 0 || u.S_m_openid == "" {
  358. if u.PushSet.SubSet != nil {
  359. u.PushSet.SubSet.WxPush = -1
  360. }
  361. if u.PushSet.WeekReport != nil {
  362. u.PushSet.WeekReport.WxPush = -1
  363. }
  364. if u.PushSet.MonthReport != nil {
  365. u.PushSet.MonthReport.WxPush = -1
  366. }
  367. if u.PushSet.NewprojectForecast != nil {
  368. u.PushSet.NewprojectForecast.WxPush = -1
  369. }
  370. if u.PushSet.EntInfo != nil {
  371. u.PushSet.EntInfo.WxPush = -1
  372. }
  373. if u.PushSet.FollowProject != nil {
  374. u.PushSet.FollowProject.WxPush = -1
  375. }
  376. if u.PushSet.FollowEnt != nil {
  377. u.PushSet.FollowEnt.WxPush = -1
  378. }
  379. }
  380. if u.Jpushid == "" && u.Opushid == "" {
  381. if u.PushSet.SubSet != nil {
  382. u.PushSet.SubSet.AppPush = -1
  383. }
  384. if u.PushSet.WeekReport != nil {
  385. u.PushSet.WeekReport.AppPush = -1
  386. }
  387. if u.PushSet.MonthReport != nil {
  388. u.PushSet.MonthReport.AppPush = -1
  389. }
  390. if u.PushSet.NewprojectForecast != nil {
  391. u.PushSet.NewprojectForecast.AppPush = -1
  392. }
  393. if u.PushSet.EntInfo != nil {
  394. u.PushSet.EntInfo.AppPush = -1
  395. }
  396. if u.PushSet.FollowProject != nil {
  397. u.PushSet.FollowProject.AppPush = -1
  398. }
  399. if u.PushSet.FollowEnt != nil {
  400. u.PushSet.FollowEnt.AppPush = -1
  401. }
  402. }
  403. mailPush := true
  404. if (u.S_m_openid == "" || (u.S_m_openid != "" && u.Subscribe == 0)) && u.Phone == "" && u.A_m_openid == "" {
  405. mailPush = false
  406. } else if (u.S_m_openid == "" || (u.S_m_openid != "" && u.Subscribe == 0)) && u.Phone == "" && u.A_m_openid != "" && u.Jpushid == "" && u.Opushid == "" {
  407. mailPush = false
  408. } else if !MailReg.MatchString(u.PushSet.Email) {
  409. mailPush = false
  410. }
  411. if !mailPush {
  412. if u.PushSet.SubSet != nil {
  413. u.PushSet.SubSet.MailPush = -1
  414. }
  415. if u.PushSet.WeekReport != nil {
  416. u.PushSet.WeekReport.MailPush = -1
  417. }
  418. if u.PushSet.MonthReport != nil {
  419. u.PushSet.MonthReport.MailPush = -1
  420. }
  421. if u.PushSet.NewprojectForecast != nil {
  422. u.PushSet.NewprojectForecast.MailPush = -1
  423. }
  424. if u.PushSet.EntInfo != nil {
  425. u.PushSet.EntInfo.MailPush = -1
  426. }
  427. if u.PushSet.FollowProject != nil {
  428. u.PushSet.FollowProject.MailPush = -1
  429. }
  430. if u.PushSet.FollowEnt != nil {
  431. u.PushSet.FollowEnt.MailPush = -1
  432. }
  433. }
  434. }
  435. // 解析用户的订阅设置
  436. func (u *UserInfo) GetSubSet(isFreeUser bool, userId string, obj map[string]interface{}) {
  437. subSet := &SubSet{
  438. Keys: []string{},
  439. Notkeys: []string{},
  440. Key_item: map[string]string{},
  441. Key_notkey: map[string]map[string]bool{},
  442. Key_area: map[string]map[string]bool{},
  443. Key_subtype: map[string]map[string]bool{},
  444. OriginalKeys: []string{},
  445. Areas: []string{},
  446. Subtypes: []string{},
  447. Buyerclasss: []string{},
  448. Matchbuyerclass_other: util.IntAllDef(obj["i_matchbuyerclass_other"], 1),
  449. ProjectMatch: util.IntAll(obj["i_projectmatch"]),
  450. MaxPushSize: util.IntAll(obj["i_maxpushsize"]),
  451. MaxMailSize: util.IntAll(obj["i_maxmailsize"]),
  452. Switch: util.IntAllDef(obj["i_switch"], 1),
  453. MatchMode: []string{},
  454. }
  455. matchMode, _ := obj["i_matchmode"].([]interface{})
  456. for _, v := range matchMode {
  457. vs, _ := v.(string)
  458. subSet.MatchMode = append(subSet.MatchMode, vs)
  459. }
  460. if len(subSet.MatchMode) == 0 {
  461. subSet.MatchMode = append(subSet.MatchMode, "title")
  462. }
  463. subSet.Amount = util.ObjToString(obj["amount"])
  464. if amount := strings.Split(subSet.Amount, "-"); len(amount) == 2 {
  465. subSet.StartAmount = util.Float64All(amount[0]) * 10000
  466. subSet.EndAmount = util.Float64All(amount[1]) * 10000
  467. }
  468. var keySets []*KeySet
  469. if isFreeUser {
  470. var err error
  471. keySets, err = u.GetKeySets(obj["a_key"])
  472. if err != nil {
  473. logger.Error("获取用户关键词错误!", userId, obj["a_key"], err)
  474. return
  475. }
  476. area := obj["o_area"]
  477. if ppStatus := util.IntAll(obj["i_ppstatus"]); ppStatus == 1 {
  478. area = obj["o_area_p"]
  479. }
  480. if newFree := util.IntAll(obj["i_newfree"]); newFree == 1 && area != nil {
  481. subSet.IsUpgrade = true
  482. subSet.Subtype, _ = obj["a_infotype"].([]interface{})
  483. subSet.Area, _ = area.(map[string]interface{})
  484. }
  485. } else {
  486. items, _ := obj["a_items"].([]interface{})
  487. for _, v := range items {
  488. item, _ := v.(map[string]interface{})
  489. itemName := strings.TrimSpace(util.ObjToString(item["s_item"]))
  490. subSet.Items = append(subSet.Items, itemName)
  491. kss, err := u.GetKeySets(item["a_key"])
  492. if err != nil {
  493. logger.Error("获取用户关键词错误!", userId, item["a_key"], err)
  494. continue
  495. }
  496. for _, vv := range kss {
  497. if vv == nil {
  498. continue
  499. }
  500. if vv.MatchWay == 1 {
  501. for _, vvv := range vv.Keys {
  502. keySets = append(keySets, &KeySet{
  503. Item: itemName,
  504. Keys: []string{vvv},
  505. NotKeys: vv.NotKeys,
  506. })
  507. }
  508. for _, vvv := range vv.AppendKeys {
  509. keySets = append(keySets, &KeySet{
  510. Item: itemName,
  511. Keys: []string{vvv},
  512. NotKeys: vv.NotKeys,
  513. })
  514. }
  515. } else {
  516. vv.Item = itemName
  517. keySets = append(keySets, vv)
  518. }
  519. }
  520. }
  521. subSet.Buyerclass, _ = obj["a_buyerclass"].([]interface{})
  522. subSet.Subtype, _ = obj["a_infotype"].([]interface{})
  523. subSet.Area, _ = obj["o_area"].(map[string]interface{})
  524. subSet.District, _ = obj["o_district"].(map[string]interface{})
  525. }
  526. for _, v := range subSet.Buyerclass {
  527. s_v, _ := v.(string)
  528. if s_v == "" {
  529. continue
  530. }
  531. subSet.Buyerclasss = append(subSet.Buyerclasss, s_v)
  532. }
  533. for _, v := range subSet.Subtype {
  534. s_v, _ := v.(string)
  535. if s_v == "" {
  536. continue
  537. }
  538. subSet.Subtypes = append(subSet.Subtypes, s_v)
  539. }
  540. for area, _ := range subSet.Area {
  541. if area == "" {
  542. continue
  543. }
  544. subSet.Areas = append(subSet.Areas, area)
  545. }
  546. ////////////////
  547. for _, vs := range keySets {
  548. if vs == nil {
  549. logger.Error(userId, "关键词设置异常")
  550. continue
  551. }
  552. var vs_keys []string
  553. for _, vs_v := range [][]string{vs.Keys, vs.AppendKeys} {
  554. for _, vs_vv := range vs_v {
  555. vs_vv = strings.TrimSpace(vs_vv)
  556. if vs_vv == "" {
  557. continue
  558. }
  559. vs_keys = append(vs_keys, vs_vv)
  560. }
  561. }
  562. if len(vs_keys) == 0 {
  563. continue
  564. }
  565. key := strings.Join(vs_keys, "+")
  566. subSet.OriginalKeys = append(subSet.OriginalKeys, key)
  567. if KeyFilterReg.MatchString(key) {
  568. continue
  569. } else if !KeyRetainReg.MatchString(key) {
  570. continue
  571. }
  572. subSet.Keys = append(subSet.Keys, key)
  573. subSet.Notkeys = append(subSet.Notkeys, vs.NotKeys...)
  574. //转大写
  575. upperKey := strings.ToUpper(key)
  576. subSet.Key_item[upperKey] = vs.Item
  577. //建立与排除词的对应关系
  578. for _, notkey := range vs.NotKeys {
  579. upperNotkey := strings.ToUpper(notkey)
  580. if subSet.Key_notkey[upperKey] == nil {
  581. subSet.Key_notkey[upperKey] = map[string]bool{}
  582. }
  583. subSet.Key_notkey[upperKey][upperNotkey] = true
  584. }
  585. //免费用户需要进行映射
  586. if isFreeUser {
  587. //建立与信息范围的对应关系
  588. for _, area := range vs.Areas {
  589. if subSet.Key_area[upperKey] == nil {
  590. subSet.Key_area[upperKey] = map[string]bool{}
  591. }
  592. subSet.Key_area[upperKey][area] = true
  593. }
  594. //建立与信息类型的对应关系
  595. for _, subtype := range vs.SubTypes {
  596. if subSet.Key_subtype[upperKey] == nil {
  597. subSet.Key_subtype[upperKey] = map[string]bool{}
  598. }
  599. subSet.Key_subtype[upperKey][subtype] = true
  600. }
  601. }
  602. }
  603. u.SubSet = subSet
  604. }
  605. // 得到用户的关键词
  606. func (u *UserInfo) GetKeySets(a_key interface{}) ([]*KeySet, error) {
  607. var keySets []*KeySet
  608. if a_key == nil {
  609. return keySets, nil
  610. }
  611. _bs, err := json.Marshal(a_key)
  612. if err == nil {
  613. err = json.Unmarshal(_bs, &keySets)
  614. }
  615. if err != nil {
  616. return keySets, err
  617. }
  618. for _, v := range keySets {
  619. if v == nil {
  620. continue
  621. }
  622. keys, appendKeys, notKeys := []string{}, []string{}, []string{}
  623. for _, vv := range v.Keys {
  624. keys = append(keys, SpaceReg.Split(strings.TrimSpace(vv), -1)...)
  625. }
  626. for _, vv := range v.AppendKeys {
  627. appendKeys = append(appendKeys, SpaceReg.Split(strings.TrimSpace(vv), -1)...)
  628. }
  629. for _, vv := range v.NotKeys {
  630. notKeys = append(notKeys, SpaceReg.Split(strings.TrimSpace(vv), -1)...)
  631. }
  632. v.Keys = keys
  633. v.AppendKeys = appendKeys
  634. v.NotKeys = notKeys
  635. }
  636. return keySets, err
  637. }
  638. type Entniche struct {
  639. AccountId int64 //企业账户id
  640. EntId int //企业id
  641. EntName string //企业名称
  642. DeptId int //部门id
  643. DisId string //分发id
  644. UserId int
  645. Unique string
  646. OnlyPush int
  647. IsNew int
  648. PowerSource int //权益来源
  649. ProductType string //产品类型
  650. Mail string //邮箱
  651. IsDis int //是否是分发
  652. DisMember int //分发-超级订阅
  653. DisVip int //分发-大会员
  654. }
  655. // 用户基本信息-扩展
  656. type UserInfoExtend struct {
  657. Object map[string]interface{}
  658. CreateTime int64 //
  659. Size int
  660. }
  661. func (u *UserInfo) Add(k string, m *map[string]map[*UserInfo]bool) {
  662. mk := (*m)[k]
  663. if mk == nil {
  664. mk = map[*UserInfo]bool{}
  665. }
  666. mk[u] = true
  667. (*m)[k] = mk
  668. }
  669. // 添加信息类型映射关系
  670. func (u *UserInfo) AddSubtype(m *map[string]map[*UserInfo]bool) {
  671. if len(u.SubSet.Subtypes) == 0 {
  672. u.Add("", m)
  673. } else {
  674. for _, v := range u.SubSet.Subtypes {
  675. u.Add(v, m)
  676. }
  677. }
  678. }
  679. // 添加采购单位类型映射关系
  680. func (u *UserInfo) AddBuyerclass(m *map[string]map[*UserInfo]bool) {
  681. //如果有关键词 有采购单位行业,行业加上“其它”
  682. if len(u.SubSet.Buyerclasss) == 0 {
  683. u.Add("", m)
  684. } else {
  685. if u.SubSet.Matchbuyerclass_other == 1 && len(u.SubSet.Keys) > 0 {
  686. u.Add("其它", m)
  687. }
  688. for _, v := range u.SubSet.Buyerclasss {
  689. u.Add(v, m)
  690. }
  691. }
  692. }
  693. // 添加区域映射关系
  694. func (u *UserInfo) AddArea(m *map[string]map[*UserInfo]bool) {
  695. if len(u.SubSet.Areas) == 0 {
  696. u.Add("", m)
  697. } else {
  698. for _, v := range u.SubSet.Areas {
  699. u.Add(v, m)
  700. }
  701. }
  702. }
  703. //添加省市映射关系
  704. func (u *UserInfo) AddAreaCity(area, city *map[string]map[*UserInfo]bool) {
  705. if len(u.SubSet.Area) == 0 {
  706. u.Add("", area)
  707. } else {
  708. for k, v := range u.SubSet.Area {
  709. if k == "" {
  710. continue
  711. }
  712. vs, _ := v.([]interface{})
  713. if len(vs) == 0 {
  714. u.Add(k, area)
  715. } else {
  716. for _, vv := range vs {
  717. s_vv, _ := vv.(string)
  718. if s_vv == "" {
  719. continue
  720. }
  721. u.Add(s_vv, city)
  722. }
  723. }
  724. }
  725. }
  726. }
  727. //添加省市县映射关系
  728. func (u *UserInfo) AddAreaCityDistrict(area, city *map[string]map[*UserInfo]bool, district *map[string]map[string]map[*UserInfo]bool) {
  729. if len(u.SubSet.Area) == 0 {
  730. u.Add("", area)
  731. } else {
  732. for k, v := range u.SubSet.Area {
  733. if k == "" {
  734. continue
  735. }
  736. vs, _ := v.([]interface{})
  737. if len(vs) == 0 {
  738. u.Add(k, area)
  739. } else {
  740. for _, vv := range vs {
  741. s_vv, _ := vv.(string)
  742. if s_vv == "" {
  743. continue
  744. }
  745. d_vv, _ := u.SubSet.District[s_vv].([]interface{})
  746. if len(d_vv) == 0 {
  747. u.Add(s_vv, city)
  748. } else {
  749. for _, vvv := range d_vv {
  750. s_vvv, _ := vvv.(string)
  751. if s_vvv == "" {
  752. continue
  753. }
  754. d_mm := (*district)[s_vv]
  755. if d_mm == nil {
  756. d_mm = map[string]map[*UserInfo]bool{}
  757. }
  758. u.Add(s_vvv, &d_mm)
  759. (*district)[s_vv] = d_mm
  760. }
  761. }
  762. }
  763. }
  764. }
  765. }
  766. }
  767. //
  768. func (u *UserInfo) MakeKeyUserByMatchMode(title_pjob, detail_pjob, filetext_pjob, pnp_pjob *KeyDfa) {
  769. for _, v := range u.SubSet.MatchMode {
  770. if v == "title" {
  771. u.MakeKeyUser(u.SubSet.Keys, title_pjob.Key_user)
  772. u.MakeKeyUser(u.SubSet.Notkeys, title_pjob.Notkey_user)
  773. } else if v == "detail" {
  774. u.MakeKeyUser(u.SubSet.Keys, detail_pjob.Key_user)
  775. u.MakeKeyUser(u.SubSet.Notkeys, detail_pjob.Notkey_user)
  776. } else if v == "filetext" {
  777. u.MakeKeyUser(u.SubSet.Keys, filetext_pjob.Key_user)
  778. u.MakeKeyUser(u.SubSet.Notkeys, filetext_pjob.Notkey_user)
  779. } else if v == "projectname/purchasing" {
  780. u.MakeKeyUser(u.SubSet.Keys, pnp_pjob.Key_user)
  781. u.MakeKeyUser(u.SubSet.Notkeys, pnp_pjob.Notkey_user)
  782. }
  783. }
  784. }
  785. // 把用户挂在词下面
  786. func (u *UserInfo) MakeKeyUser(keys []string, key_user *map[string]*[]*UserInfo) {
  787. mp := map[string]bool{}
  788. for _, key := range keys {
  789. v := strings.ToUpper(key)
  790. if v == "" || mp[v] {
  791. continue
  792. }
  793. mp[v] = true
  794. arr := (*key_user)[v]
  795. if arr == nil {
  796. arr = &[]*UserInfo{}
  797. }
  798. *arr = append(*arr, u)
  799. (*key_user)[v] = arr
  800. }
  801. }
  802. type WxTplMsg struct {
  803. Key string
  804. Area string
  805. }
  806. type SortList []*MatchInfo
  807. func (s SortList) Len() int {
  808. return len(s)
  809. }
  810. func (s SortList) Less(i, j int) bool {
  811. return util.Int64All(s[i].Info["publishtime"]) > util.Int64All(s[j].Info["publishtime"])
  812. }
  813. func (s SortList) Swap(i, j int) {
  814. s[i], s[j] = s[j], s[i]
  815. }
  816. type CSortList []map[string]interface{}
  817. func (s CSortList) Len() int {
  818. return len(s)
  819. }
  820. func (s CSortList) Less(i, j int) bool {
  821. return util.Int64All(s[i]["publishtime"]) > util.Int64All(s[j]["publishtime"])
  822. }
  823. func (s CSortList) Swap(i, j int) {
  824. s[i], s[j] = s[j], s[i]
  825. }
  826. type MatchInfo struct {
  827. Info map[string]interface{}
  828. Keys []string
  829. Items []string
  830. MatchWays []string
  831. DisId string
  832. HandDis bool //是否分发
  833. }
  834. type KeyDfa struct {
  835. Key *dfa.DFA
  836. NotKey *dfa.DFA
  837. Key_user *map[string]*[]*UserInfo
  838. Notkey_user *map[string]*[]*UserInfo
  839. }
  840. // 所有用户的关键词和排除词
  841. func (p *KeyDfa) CreateDaf() {
  842. //关键词
  843. p.Key = &dfa.DFA{}
  844. keys := make([]string, 0)
  845. for k, _ := range *p.Key_user {
  846. keys = append(keys, k)
  847. }
  848. p.Key.AddWord(keys...)
  849. //排除关键词
  850. p.NotKey = &dfa.DFA{}
  851. notKeys := make([]string, 0)
  852. for k, _ := range *p.Notkey_user {
  853. notKeys = append(notKeys, k)
  854. }
  855. p.NotKey.AddWord(notKeys...)
  856. }
  857. type MatchUser struct {
  858. Keys []string
  859. Items []string
  860. Item map[string]bool
  861. MatchWays []string
  862. MatchWay map[string]bool
  863. }
  864. type RelationProjectUser struct {
  865. TopTypes []string
  866. }
  867. type PushInfo struct {
  868. Ids []interface{}
  869. Info map[string]interface{}
  870. }
  871. // 推送返回结果
  872. type PushResult struct {
  873. WxStatus int
  874. AppStatus int
  875. MailStatus int
  876. PushDate int64
  877. Infos *SortList
  878. }
  879. type PushParam struct {
  880. JpushTitle string
  881. LastInfoDate int64
  882. TitleArray []string
  883. Infos *SortList
  884. InfosLength int
  885. MailHtml string
  886. PushDate int64
  887. PushCount int
  888. IsPush bool
  889. }
  890. type BiddingInfo struct {
  891. Id string
  892. Title string
  893. ClearTitle string
  894. HighlightTitle string
  895. AreaTitle string
  896. Area string
  897. Publishtime int64
  898. PublishtimeDiff string
  899. PublishtimeYMD string
  900. Buyerclass string
  901. Subscopeclass string
  902. Bidamount interface{}
  903. Budget interface{}
  904. Acount string
  905. Subtype string
  906. Toptype string
  907. Infotype string
  908. }