struct.go 29 KB

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