free_viewer.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. type FreeViewerDetails struct {
  7. UserId int
  8. RealName string
  9. Mobile string
  10. CompanyName string
  11. LastTime string
  12. Email string
  13. ApplyRecordId int
  14. }
  15. func GetFreeViewerDetails(startTime, endTime string) (items []*FreeViewerDetails, err error) {
  16. sql := `SELECT
  17. a.user_id,
  18. a.real_name,
  19. a.mobile,
  20. a.email,
  21. y.apply_record_id,
  22. IF(a.company_id > 1,b.company_name,a.note) AS company_name,
  23. IF(y.apply_record_id > 0,y.create_time, a.created_time) as last_time
  24. FROM
  25. wx_user AS a
  26. LEFT JOIN company AS b ON a.company_id = b.company_id
  27. LEFT JOIN (SELECT * from company_product where product_id = 1) AS bp ON a.company_id = bp.company_id
  28. LEFT JOIN (SELECT user_record_id, create_platform, user_id from user_record) AS c ON a.user_id = c.user_id
  29. LEFT JOIN (SELECT * from yb_apply_record where apply_record_id in (SELECT max(apply_record_id) from yb_apply_record GROUP BY user_id)) as y on a.user_id = y.user_id
  30. WHERE
  31. b.enabled = 1
  32. AND ( y.apply_record_id > 0 or a.company_id=1 or bp.company_product_id is null)
  33. AND ( a.mobile IS NOT NULL )
  34. AND ( a.mobile <> '' )
  35. AND ( c.create_platform <> 4 OR c.create_platform IS NULL )
  36. AND (y.status = "潜在用户" or y.status is null or y.status = "权益用户" or y.status = "流失" )
  37. AND ((y.apply_record_id > 0 and y.create_time > ? and y.create_time <= ?) OR (y.apply_record_id is null AND a.created_time > ? and a.created_time <= ?) )
  38. GROUP BY a.user_id ORDER BY last_time asc
  39. `
  40. _, err = orm.NewOrm().Raw(sql, startTime, endTime, startTime, endTime).QueryRows(&items)
  41. return
  42. }
  43. // DealWxUser 处理用户标记状态
  44. func DealWxUsers(userIds string) (err error) {
  45. sql := `update wx_user set is_deal = 1 where user_id in (`+userIds+`) and is_deal=0`
  46. _, err = orm.NewOrm().Raw(sql).Exec()
  47. return
  48. }
  49. // DealFiccApply 处理用户申请标记状态
  50. func DealFiccApply(applyRecordIds string, dealTime time.Time) (err error) {
  51. sql := `update yb_apply_record set op_status = 1, deal_time=? where apply_record_id in (`+applyRecordIds+`) and op_status=0`
  52. _, err = orm.NewOrm().Raw(sql, dealTime).Exec()
  53. return
  54. }