public.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694
  1. package p
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "reflect"
  6. "sort"
  7. "strconv"
  8. "strings"
  9. "time"
  10. . "app.yhyue.com/moapp/jybase/common"
  11. util "app.yhyue.com/moapp/jybase/common"
  12. . "app.yhyue.com/moapp/jybase/date"
  13. . "app.yhyue.com/moapp/jybase/mongodb"
  14. . "app.yhyue.com/moapp/jybase/mysql"
  15. "app.yhyue.com/moapp/jybase/redis"
  16. "github.com/donnie4w/go-logger/logger"
  17. )
  18. //金额转化 金额:0-万元以下单位为元 ,万元以上至亿元以下单位为万元 ,亿元以上单位为亿元。保留 小数点后 2 位,不进行四舍五入。
  19. func ConversionMoney(i_money interface{}) string {
  20. m := ""
  21. if reflect.TypeOf(i_money).Name() == "float64" {
  22. m = strconv.FormatFloat(Float64All(i_money), 'f', -1, 64)
  23. } else {
  24. m = ObjToString(i_money)
  25. }
  26. if m == "" {
  27. return m
  28. }
  29. m_arr := strings.Split(m, ".")
  30. m_1 := m_arr[0]
  31. len_m1 := len([]rune(m_1))
  32. if len_m1 >= 9 {
  33. m = m_1[0:len_m1-8] + "." + m_1[len_m1-8:len_m1-6] + "亿元"
  34. } else if len_m1 >= 5 {
  35. m = m_1[0:len_m1-4] + "." + m_1[len_m1-4:len_m1-2] + "万元"
  36. } else {
  37. if len(m_arr) == 1 {
  38. return m + ".00元"
  39. }
  40. m_2 := m_arr[1]
  41. if len([]rune(m_2)) > 1 {
  42. m_2 = m_2[0:2]
  43. } else {
  44. m_2 = m_2[0:1] + "0"
  45. }
  46. m = m_1 + "." + m_2 + "元"
  47. }
  48. return m
  49. }
  50. //微信模板消息 remark
  51. func WxTplRemark(titles []string, lastTime int64, hasLen int) string {
  52. tip := ""
  53. second := time.Now().Unix() - lastTime
  54. if second > 0 {
  55. if second < 61 {
  56. tip = fmt.Sprintf("%d秒前发布的:\n", second)
  57. } else {
  58. second = second / 60
  59. if second < 121 {
  60. if second < 1 {
  61. second = 1
  62. }
  63. tip = fmt.Sprintf("%d分钟前发布的:\n", second)
  64. }
  65. }
  66. }
  67. lastTip := ""
  68. if len(titles) > 1 {
  69. lastTip = fmt.Sprintf("...(共%d条)", len(titles))
  70. }
  71. reLen := 199 - hasLen - len([]rune(tip))
  72. lastTipLen := len([]rune(lastTip))
  73. wxTplMsgTitle := ""
  74. bshow := false
  75. for n := 1; n < len(titles)+1; n++ {
  76. curTitle := titles[n-1]
  77. tmptitle := wxTplMsgTitle + fmt.Sprintf("%d %s\n", n, curTitle)
  78. ch := reLen - len([]rune(tmptitle))
  79. if ch < lastTipLen { //加上后大于后辍,则没有完全显示
  80. if ch == 0 && n == len(titles) {
  81. wxTplMsgTitle = tmptitle
  82. bshow = true
  83. } else {
  84. ch_1 := reLen - len([]rune(wxTplMsgTitle)) - lastTipLen
  85. if ch_1 > 8 {
  86. curLen := len([]rune(curTitle))
  87. if ch_1 > curLen {
  88. ch_1 = curLen
  89. }
  90. wxTplMsgTitle += fmt.Sprintf("%d %s\n", n, string([]rune(curTitle)[:ch_1-3]))
  91. }
  92. }
  93. } else {
  94. wxTplMsgTitle = tmptitle
  95. if n == len(titles) {
  96. bshow = true
  97. }
  98. }
  99. }
  100. if bshow {
  101. lastTip = ""
  102. }
  103. return tip + wxTplMsgTitle + lastTip
  104. }
  105. //获取信息行业
  106. func GetSubScopeClass(subscopeclass interface{}) string {
  107. industry := ""
  108. if subscopeclass != nil {
  109. k2sub := strings.Split(ObjToString(subscopeclass), ",")
  110. if len(k2sub) > 0 {
  111. industry = k2sub[0]
  112. if industry != "" {
  113. ss := strings.Split(industry, "_")
  114. if len(ss) > 1 {
  115. industry = ss[0]
  116. }
  117. }
  118. }
  119. }
  120. return industry
  121. }
  122. //控制一分钟最大推送数,均匀调度
  123. func LimitMaxOneMinutePush(pushPoll *chan bool, maxOneMinute int) {
  124. max := int(maxOneMinute / 60)
  125. *pushPoll = make(chan bool, max)
  126. go func() {
  127. for {
  128. time.Sleep(time.Second)
  129. for i := 0; i < max; i++ {
  130. select {
  131. case *pushPoll <- true:
  132. default:
  133. continue
  134. }
  135. }
  136. }
  137. }()
  138. }
  139. //
  140. func UpdateUserIsPush(Mgo *MongodbSim, userId string, err error) {
  141. if err == nil {
  142. return
  143. }
  144. if strings.Contains(err.Error(), "[43004]") {
  145. Mgo.UpdateById("user", userId, map[string]interface{}{
  146. "$set": map[string]interface{}{
  147. "i_ispush": 0,
  148. },
  149. })
  150. }
  151. }
  152. //查找我的子账号
  153. func MySonAccounts(Mgo *MongodbSim, coll, userId string, field map[string]interface{}) *[]map[string]interface{} {
  154. users, _ := Mgo.Find(coll, map[string]interface{}{
  155. "i_member_sub_status": 1,
  156. "s_member_mainid": userId,
  157. "i_member_status": map[string]interface{}{"$gt": 0},
  158. }, nil, field, false, -1, -1)
  159. if users == nil {
  160. users = &[]map[string]interface{}{}
  161. }
  162. return users
  163. }
  164. //是否购买此服务
  165. func HasService(mysql *Mysql, userId string, params ...int) *MemberService {
  166. args := []interface{}{}
  167. ws := []string{}
  168. for _, v := range params {
  169. args = append(args, v)
  170. ws = append(ws, "?")
  171. }
  172. args = append(args, args...)
  173. args = append(args, userId, NowFormat(Date_Full_Layout))
  174. list := mysql.SelectBySql(`SELECT a.l_starttime,b.id from bigmember_service_user a
  175. INNER JOIN bigmember_service b on (((b.id in (`+strings.Join(ws, ",")+`) and a.s_serviceid=b.id) or (b.i_pid in (`+strings.Join(ws, ",")+`) and a.s_serviceid=b.i_pid)) and b.i_status=0 and a.s_userid=? and a.i_status=0 and a.l_endtime>?)`, args...)
  176. ms := &MemberService{
  177. Services: map[int]*memberService{},
  178. }
  179. if list != nil {
  180. for _, v := range *list {
  181. ms.IsBuy = true
  182. id := util.IntAll(v["id"])
  183. ms.Services[id] = &memberService{
  184. Id: id,
  185. StartTime: util.ObjToString(v["l_starttime"]),
  186. }
  187. }
  188. }
  189. return ms
  190. }
  191. //
  192. func GetInfoTitle(info *map[string]interface{}) string {
  193. title, _ := (*info)["title"].(string)
  194. jsondata, _ := (*info)["jsondata"].(map[string]interface{})
  195. if jsondata != nil {
  196. goods, _ := jsondata["goods"].(string)
  197. title += goods
  198. }
  199. title = strings.ToUpper(title)
  200. return title
  201. }
  202. //加载数据到内存中
  203. func LoadBidding(mgo *MongodbSim, dbName, coll string, startTime int64, redisCache bool) (*[]map[string]interface{}, int64) {
  204. defer util.Catch()
  205. endTime := time.Now().Unix()
  206. query := map[string]interface{}{
  207. "pici": map[string]interface{}{
  208. "$gte": startTime,
  209. "$lt": endTime,
  210. },
  211. }
  212. // query = map[string]interface{}{
  213. // "_id": map[string]interface{}{
  214. // "$in": ToObjectIds([]string{"5b7bd6b9a5cb26b9b7449fd7", "5b7bd6b9a5cb26b9b7449fe4", "626c4b63923488e172579d81", "5b7bd6b9a5cb26b9b7449fde"}),
  215. // },
  216. // }
  217. logger.Info("开始加载", coll, "数据", query)
  218. var res []map[string]interface{}
  219. sess := mgo.GetMgoConn()
  220. defer mgo.DestoryMongoConn(sess)
  221. it := sess.DB(dbName).C(coll).Find(query).Select(map[string]interface{}{
  222. "title": 1,
  223. "detail": 1,
  224. "projectname": 1,
  225. "projectcode": 1,
  226. "buyer": 1,
  227. "buyerperson": 1,
  228. "buyertel": 1,
  229. "s_winner": 1,
  230. "agency": 1,
  231. "bidopentime": 1,
  232. "projectscope": 1,
  233. "publishtime": 1,
  234. "toptype": 1,
  235. "subtype": 1,
  236. "area": 1,
  237. "s_subscopeclass": 1,
  238. "city": 1,
  239. "buyerclass": 1,
  240. "jsondata": 1,
  241. "budget": 1,
  242. "bidamount": 1,
  243. "isValidFile": 1,
  244. "site": 1,
  245. "agencyperson": 1,
  246. "agencytel": 1,
  247. "winnerperson": 1,
  248. "winnertel": 1,
  249. "signendtime": 1,
  250. "bidendtime": 1,
  251. "entidlist": 1,
  252. }).Iter()
  253. index := 0
  254. for temp := make(map[string]interface{}); it.Next(&temp); {
  255. _id := BsonIdToSId(temp["_id"])
  256. if publishtime := util.Int64All(temp["publishtime"]); startTime-publishtime > 7*86400 {
  257. logger.Info(_id, "发布时间大于7天,不参与匹配", startTime, publishtime)
  258. continue
  259. }
  260. temp["_id"] = _id
  261. title, _ := temp["title"].(string)
  262. title = strings.ReplaceAll(title, "\n", "")
  263. temp["title"] = title
  264. if util.ObjToString(temp["area"]) == "A" {
  265. temp["area"] = "全国"
  266. }
  267. temp["attachment_count"] = GetAttachmentCount(temp)
  268. delete(temp, "projectinfo")
  269. res = append(res, temp)
  270. if redisCache {
  271. //信息缓存3天
  272. info := map[string]interface{}{}
  273. for _, v := range SaveBiddingField {
  274. if v == "_id" || temp[v] == nil {
  275. continue
  276. }
  277. info[v] = temp[v]
  278. }
  279. redis.Put(Pushcache_1, "info_"+_id, info, 259200)
  280. }
  281. temp = make(map[string]interface{})
  282. index++
  283. if index%500 == 0 {
  284. logger.Info("加载", coll, "数据:", index)
  285. }
  286. }
  287. logger.Info(coll, "数据已经加载结束。。。", index)
  288. return &res, endTime
  289. }
  290. //
  291. func IsVipUser(vipStatus int) bool {
  292. if vipStatus == 1 || vipStatus == 2 {
  293. return true
  294. }
  295. return false
  296. }
  297. //
  298. func ToSortList(list interface{}) *SortList {
  299. sl := make(SortList, 0)
  300. if list == nil {
  301. return &sl
  302. }
  303. b, err := json.Marshal(list)
  304. if err != nil {
  305. return &sl
  306. }
  307. err = json.Unmarshal(b, &sl)
  308. if err != nil {
  309. return &sl
  310. }
  311. sort.Sort(sl)
  312. return &sl
  313. }
  314. //第一个参数是老数据,第二个参数是新进数据
  315. func MergeSortList(o, n interface{}, maxPushSize int) *SortList {
  316. of, oo := o.(*SortList)
  317. if !oo {
  318. of = ToSortList(o)
  319. }
  320. nf, no := n.(*SortList)
  321. if !no {
  322. nf = ToSortList(n)
  323. }
  324. idMap := map[string]bool{}
  325. for _, v := range *nf {
  326. idMap[util.ObjToString((*v.Info)["_id"])] = true
  327. }
  328. for _, v := range *of {
  329. if idMap[util.ObjToString((*v.Info)["_id"])] {
  330. continue
  331. }
  332. *nf = append(*nf, v)
  333. }
  334. sort.Sort(nf)
  335. if len(*nf) > maxPushSize {
  336. *nf = (*nf)[:maxPushSize]
  337. }
  338. return nf
  339. }
  340. //获取招标信息附件数量
  341. func GetAttachmentCount(temp map[string]interface{}) int {
  342. isValidFile, _ := temp["isValidFile"].(bool)
  343. if isValidFile {
  344. return 1
  345. }
  346. return 0
  347. }
  348. //获取招标信息附件数量
  349. func GetAttachmentCountById(mgo *MongodbSim, dbName, coll, _id string) int {
  350. sess := mgo.GetMgoConn()
  351. defer mgo.DestoryMongoConn(sess)
  352. temp := map[string]interface{}{}
  353. sess.DB(dbName).C(coll).Find(map[string]interface{}{
  354. "_id": StringTOBsonId(_id),
  355. }).Select(map[string]interface{}{
  356. "isValidFile": 1,
  357. }).One(&temp)
  358. if temp != nil {
  359. return GetAttachmentCount(temp)
  360. }
  361. return -1
  362. }
  363. //
  364. func NewBiddingInfo(info *map[string]interface{}, keys []string) *BiddingInfo {
  365. bi := &BiddingInfo{}
  366. bi.Title, _ = (*info)["title"].(string)
  367. bi.ClearTitle = TitleClearRe.ReplaceAllString(strings.Replace(bi.Title, "\n", "", -1), "$1")
  368. bi.Area, _ = (*info)["area"].(string)
  369. bi.AreaTitle = fmt.Sprintf("[%s]%s", bi.Area, bi.ClearTitle)
  370. bi.Publishtime = util.Int64All((*info)["publishtime"])
  371. bi.PublishtimeYMD = FormatDateByInt64(&bi.Publishtime, Date_Short_Layout)
  372. bi.PublishtimeDiff = util.TimeDiff(time.Unix(bi.Publishtime, 0))
  373. bi.Buyerclass, _ = (*info)["buyerclass"].(string)
  374. bi.Subscopeclass = GetSubScopeClass((*info)["s_subscopeclass"])
  375. bi.Bidamount = (*info)["bidamount"]
  376. bi.Budget = (*info)["budget"]
  377. if bi.Bidamount != nil {
  378. bi.Acount = ConversionMoney(bi.Bidamount)
  379. } else if bi.Budget != nil {
  380. bi.Acount = ConversionMoney(bi.Budget)
  381. }
  382. bi.Id, _ = (*info)["_id"].(string)
  383. bi.Subtype, _ = (*info)["subtype"].(string)
  384. bi.Toptype, _ = (*info)["toptype"].(string)
  385. bi.Infotype = bi.Subtype
  386. if bi.Infotype == "" {
  387. bi.Infotype = bi.Toptype
  388. }
  389. bi.HighlightTitle = bi.ClearTitle
  390. for _, kw := range keys {
  391. kws := strings.Split(kw, "+")
  392. n := 0
  393. otitle := bi.HighlightTitle
  394. for _, kwn := range kws {
  395. ot := strings.Replace(otitle, kwn, "<span class='keys'>"+kwn+"</span>", 1)
  396. if ot != bi.HighlightTitle {
  397. n++
  398. otitle = ot
  399. } else {
  400. break
  401. }
  402. }
  403. if n == len(kws) {
  404. bi.HighlightTitle = otitle
  405. break
  406. }
  407. }
  408. return bi
  409. }
  410. //
  411. func SortListSplit(list *SortList, f func(v interface{})) {
  412. l := len(*list)
  413. if l == 0 {
  414. return
  415. }
  416. i := Mgo_ListSize
  417. for {
  418. if l > i {
  419. arr := (*list)[i-Mgo_ListSize : i]
  420. f(&arr)
  421. } else if l > i-Mgo_ListSize {
  422. arr := (*list)[i-Mgo_ListSize:]
  423. f(&arr)
  424. break
  425. }
  426. i += Mgo_ListSize
  427. }
  428. }
  429. //获取企业授权超级订阅/大会员的用户
  430. func LoadEntProductUsers(m *Mysql, testUserIds []int) (map[string]*UserInfo, map[int]*UserInfo, map[int]*UserInfo, []*UserInfo) {
  431. logger.Info("开始加载企业授权用户。。。")
  432. phoneMap := map[string]*UserInfo{}
  433. userMap := map[int]*UserInfo{}
  434. entMap := map[int]*UserInfo{}
  435. all := []*UserInfo{}
  436. query := `SELECT DISTINCT a.ent_id,IF(instr(a.product_type,'` + Ent_EmpowerMember + `')>0,'` + Ent_EmpowerMember + `','` + Ent_EmpowerVip + `') as product_type,c.phone,b.ent_user_id,d.name as ent_name,d.power_source,d.isNew from entniche_wait_empower a
  437. inner join entniche_power b on (a.end_time>? and b.status=1 and (a.product_type like '%` + Ent_EmpowerVip + `%' or a.product_type like '%` + Ent_EmpowerMember + `%') and a.id=b.wait_empower_id)
  438. inner join entniche_user c on (`
  439. if len(testUserIds) > 0 {
  440. array := []string{}
  441. for _, v := range testUserIds {
  442. array = append(array, fmt.Sprint(v))
  443. }
  444. query += `c.id in (` + strings.Join(array, ",") + `) and `
  445. }
  446. query += `b.ent_user_id=c.id)
  447. inner join entniche_info d on (d.id=a.ent_id)`
  448. m.SelectByBath(200, func(l *[]map[string]interface{}) bool {
  449. for _, v := range *l {
  450. phone, _ := v["phone"].(string)
  451. if phone == "" {
  452. continue
  453. }
  454. u := &UserInfo{
  455. Entniche: &Entniche{
  456. EntId: util.IntAll(v["ent_id"]),
  457. EntName: util.ObjToString(v["ent_name"]),
  458. UserId: util.IntAll(v["ent_user_id"]),
  459. ProductType: util.ObjToString(v["product_type"]),
  460. PowerSource: util.IntAll(v["power_source"]),
  461. IsNew: util.IntAll(v["isNew"]),
  462. },
  463. Phone: phone,
  464. }
  465. if strings.Contains(u.Entniche.ProductType, Ent_EmpowerMember) {
  466. u.MemberStatus = 1
  467. } else if strings.Contains(u.Entniche.ProductType, Ent_EmpowerVip) {
  468. u.VipStatus = 1
  469. } else {
  470. continue
  471. }
  472. phoneMap[phone] = u
  473. userMap[u.Entniche.UserId] = u
  474. all = append(all, u)
  475. entMap[u.Entniche.EntId] = u
  476. logger.Info("加载企业授权用户", u.Entniche.EntName, u.Entniche.EntId, u.Entniche.UserId, u.Entniche.ProductType, u.Phone)
  477. }
  478. return true
  479. }, query, NowFormat(Date_Full_Layout))
  480. logger.Info("企业授权用户加载结束。。。", len(phoneMap), len(userMap), len(entMap), len(all))
  481. return phoneMap, userMap, entMap, all
  482. }
  483. //加载商机管理用户
  484. func LoadEntnicheUsers(m *Mysql) map[string]bool {
  485. logger.Info("开始加载新版商机管理用户。。。")
  486. r := map[string]bool{}
  487. m.SelectByBath(200, func(l *[]map[string]interface{}) bool {
  488. for _, v := range *l {
  489. phone := util.ObjToString(v["phone"])
  490. if phone != "" {
  491. r[phone] = true
  492. logger.Info("加载商机管理用户", phone)
  493. }
  494. }
  495. return true
  496. }, `SELECT b.phone from entniche_info a INNER JOIN entniche_user b on (a.status=1 and a.power_source is null and b.power=1 and a.id=b.ent_id)`)
  497. logger.Info("商机管理用户加载结束。。。", len(r))
  498. return r
  499. }
  500. //
  501. func GetWxTplMsg(subSet *SubSet) (string, string) {
  502. keyword := strings.Join(subSet.Keys, " ")
  503. if len([]rune(keyword)) > 10 {
  504. keyword = string([]rune(keyword)[:10]) + "..."
  505. }
  506. area := strings.Join(subSet.Areas, " ")
  507. if len([]rune(area)) > 10 {
  508. area = string([]rune(area)[:10]) + "..."
  509. }
  510. return keyword, area
  511. }
  512. //
  513. func GetPhone(u map[string]interface{}) string {
  514. phone := util.ObjToString(u["s_phone"])
  515. if phone == "" {
  516. phone = util.ObjToString(u["s_m_phone"])
  517. }
  518. return phone
  519. }
  520. //
  521. func GetAllByEntUserId(mgo *MongodbSim, msl *Mysql, entUserId int) *map[string]interface{} {
  522. entUsers := msl.SelectBySql(`select phone from entniche_user where id=?`, entUserId)
  523. if entUsers == nil || len(*entUsers) == 0 {
  524. logger.Info("entniche_user表中没有找到该企业用户", entUserId)
  525. return nil
  526. }
  527. phone, _ := (*entUsers)[0]["phone"].(string)
  528. if phone == "" {
  529. return nil
  530. }
  531. return getEntPushSet(mgo, msl, entUserId, phone)
  532. }
  533. //
  534. func GetAllByEntPositionId(mgo *MongodbSim, tidb, msl *Mysql, positionId int) *map[string]interface{} {
  535. position := tidb.SelectBySql(`select a.ent_id,b.phone from base_position a inner join base_user b on (a.id=? and a.user_id=b.id)`, positionId)
  536. if position == nil || len(*position) == 0 {
  537. logger.Info("无效的职位id", position)
  538. return nil
  539. }
  540. entId := util.Int64All((*position)[0]["ent_id"])
  541. if entId == 0 {
  542. logger.Info("该职位id没有找到对应的企业id", position)
  543. return nil
  544. }
  545. phone, _ := (*position)[0]["phone"].(string)
  546. if phone == "" {
  547. logger.Info("该职位id没有找到对应的手机号", position)
  548. return nil
  549. }
  550. entUsers := msl.SelectBySql(`select id from entniche_user where phone=? and ent_id=?`, phone, entId)
  551. if entUsers == nil || len(*entUsers) == 0 {
  552. logger.Info("entniche_user表中没有找到该企业用户", phone, entId)
  553. return nil
  554. }
  555. return getEntPushSet(mgo, msl, util.IntAll((*entUsers)[0]["id"]), phone)
  556. }
  557. //
  558. func getEntPushSet(mgo *MongodbSim, msl *Mysql, entUserId int, phone string) *map[string]interface{} {
  559. users, ok := mgo.Find(Mgo_User, map[string]interface{}{
  560. "$or": []map[string]interface{}{
  561. map[string]interface{}{
  562. "s_phone": phone,
  563. },
  564. map[string]interface{}{
  565. "s_m_phone": phone,
  566. },
  567. },
  568. }, `{"s_phone":-1}`, map[string]interface{}{
  569. "_id": 0,
  570. "s_m_openid": 1,
  571. "i_ispush": 1,
  572. "s_jpushid": 1,
  573. "s_opushid": 1,
  574. "s_appponetype": 1,
  575. "i_applystatus": 1,
  576. }, false, -1, -1)
  577. if !ok || users == nil || len(*users) == 0 {
  578. logger.Info("user表中没有找到该企业用户", entUserId, phone)
  579. return nil
  580. }
  581. user := map[string]interface{}{}
  582. for _, v := range *users {
  583. s_m_openid := util.ObjToString(v["s_m_openid"])
  584. i_ispush := util.IntAll(v["i_ispush"])
  585. s_jpushid := util.ObjToString(v["s_jpushid"])
  586. s_opushid := util.ObjToString(v["s_opushid"])
  587. s_appponetype := util.ObjToString(v["s_appponetype"])
  588. if user["s_m_openid"] == nil && user["i_ispush"] == nil && s_m_openid != "" && i_ispush == 1 {
  589. user["s_m_openid"] = s_m_openid
  590. user["i_ispush"] = i_ispush
  591. user["i_applystatus"] = v["i_applystatus"]
  592. }
  593. if user["s_jpushid"] == nil && user["s_opushid"] == nil && user["s_appponetype"] == nil && s_appponetype != "" && (s_jpushid != "" || s_opushid != "") {
  594. user["s_jpushid"] = s_jpushid
  595. user["s_opushid"] = s_opushid
  596. user["s_appponetype"] = s_appponetype
  597. }
  598. }
  599. entniche_user, ok := mgo.FindOneByField(Mgo_Ent_User, map[string]interface{}{
  600. "i_userid": entUserId,
  601. }, `{"_id":0,"i_member_status":1,"i_vip_status":1,"o_follow_project":1,"o_follow_ent":1}`)
  602. if ok && entniche_user != nil && len(*entniche_user) > 0 {
  603. for k, v := range *entniche_user {
  604. user[k] = v
  605. }
  606. }
  607. entniche_rule, ok := mgo.Find("entniche_rule", map[string]interface{}{
  608. "i_userid": entUserId,
  609. }, nil, `{"_id":0,"o_entniche":1,"i_type":1}`, false, -1, -1)
  610. if ok && entniche_rule != nil {
  611. for _, v := range *entniche_rule {
  612. i_type := util.IntAll(v["i_type"])
  613. if i_type == 0 {
  614. user["o_entniche"] = v["o_entniche"]
  615. } else if i_type == 1 {
  616. user["o_vipjy"] = v["o_entniche"]
  617. user["o_member_jy"] = v["o_entniche"]
  618. } else if i_type == 2 {
  619. user["o_jy"] = v["o_entniche"]
  620. }
  621. }
  622. }
  623. return &user
  624. }
  625. //
  626. func GetEntUserSubset(mgo *MongodbSim, entUserId, tp int) map[string]interface{} {
  627. temp, ok := mgo.FindOneByField("entniche_rule", map[string]interface{}{
  628. "i_userid": entUserId,
  629. "i_type": tp,
  630. }, `{"o_entniche":1}`)
  631. if ok && temp != nil && len(*temp) > 0 {
  632. o_msgset, _ := (*temp)["o_entniche"].(map[string]interface{})
  633. return o_msgset
  634. }
  635. return nil
  636. }
  637. //根据企业员工id获取身份信息
  638. func IdentityByEntUserId(base, main *Mysql, entUserId int64) *IdentityInfo {
  639. ents := main.SelectBySql(`SELECT a.id,a.name,a.phone,a.ent_id,b.name as ent_name from entniche_user a inner join entniche_info b on (a.id=? and a.ent_id=b.id) limit 1`, entUserId)
  640. if ents == nil || len(*ents) == 0 {
  641. return nil
  642. }
  643. if entId := Int64All((*ents)[0]["ent_id"]); entId > 0 {
  644. list := base.SelectBySql(`SELECT a.id as position_id,c.person_id,a.person_name,a.account_id,a.type as position_type,d.id as user_id,b.id as ent_account_id from base_user d
  645. inner join base_position a on (d.phone=? and a.ent_id=? and a.type=1 and d.id=a.user_id)
  646. inner join base_account c on (c.ent_id=? and c.type=1 and a.account_id=c.id)
  647. inner join base_account b on (b.type=1 and b.person_id=0 and b.ent_id=?) limit 1`, ObjToString((*ents)[0]["phone"]), entId, entId, entId)
  648. if list != nil && len(*list) == 1 {
  649. identity := &IdentityInfo{
  650. PersonId: Int64All((*list)[0]["person_id"]),
  651. UserName: ObjToString((*list)[0]["person_name"]),
  652. AccountId: Int64All((*list)[0]["account_id"]),
  653. EntAccountId: Int64All((*list)[0]["ent_account_id"]),
  654. PositionId: Int64All((*list)[0]["position_id"]),
  655. PositionType: Int64All((*list)[0]["position_type"]),
  656. UserId: Int64All((*list)[0]["user_id"]),
  657. EntId: entId,
  658. EntUserId: Int64All((*ents)[0]["id"]),
  659. EntUserName: ObjToString((*ents)[0]["name"]),
  660. Name: ObjToString((*ents)[0]["ent_name"]),
  661. }
  662. return identity
  663. }
  664. }
  665. return nil
  666. }