|
@@ -1,39 +1,59 @@
|
|
|
package models
|
|
|
|
|
|
-import "github.com/rdlucklib/rdluck_tools/orm"
|
|
|
+import (
|
|
|
+ "github.com/rdlucklib/rdluck_tools/orm"
|
|
|
+ "time"
|
|
|
+)
|
|
|
|
|
|
type FreeViewerDetails struct {
|
|
|
UserId int
|
|
|
RealName string
|
|
|
Mobile string
|
|
|
- Note string
|
|
|
- CreatedTime string
|
|
|
- MaxCreatedTime string
|
|
|
+ CompanyName string
|
|
|
+ LastTime string
|
|
|
Email string
|
|
|
+ ApplyRecordId int
|
|
|
}
|
|
|
|
|
|
func GetFreeViewerDetails(startTime, endTime string) (items []*FreeViewerDetails, err error) {
|
|
|
- sql := `select u.user_id,u.real_name,u.mobile,u.note,u.created_time,max(uvh.created_time) as max_created_time,u.email
|
|
|
- from wx_user u
|
|
|
- LEFT JOIN user_view_history uvh on u.user_id = uvh.user_id
|
|
|
- INNER JOIN user_record AS c ON u.user_id=c.user_id
|
|
|
- where u.company_id = 1
|
|
|
- and u.is_deal=0
|
|
|
- and u.apply_method<>2
|
|
|
- and u.mobile is not null
|
|
|
- AND u.mobile<>''
|
|
|
- and u.created_time > ?
|
|
|
- and u.created_time <= ?
|
|
|
- AND c.create_platform<>4
|
|
|
- AND u.is_deal = 0
|
|
|
- group by u.user_id`
|
|
|
- _, err = orm.NewOrm().Raw(sql, startTime, endTime).QueryRows(&items)
|
|
|
+ sql := `SELECT
|
|
|
+ a.user_id,
|
|
|
+ a.real_name,
|
|
|
+ a.mobile,
|
|
|
+ a.email,
|
|
|
+ y.apply_record_id,
|
|
|
+ IF(a.company_id > 1,b.company_name,a.note) AS company_name,
|
|
|
+ IF(y.apply_record_id > 0,y.create_time, a.created_time) as last_time
|
|
|
+FROM
|
|
|
+ wx_user AS a
|
|
|
+ LEFT JOIN company AS b ON a.company_id = b.company_id
|
|
|
+ LEFT JOIN (SELECT * from company_product where product_id = 1) AS bp ON a.company_id = bp.company_id
|
|
|
+ LEFT JOIN (SELECT user_record_id, create_platform, user_id from user_record) AS c ON a.user_id = c.user_id
|
|
|
+ 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
|
|
|
+WHERE
|
|
|
+ b.enabled = 1
|
|
|
+ AND ( y.apply_record_id > 0 or a.company_id=1 or bp.company_product_id is null)
|
|
|
+ AND ( a.mobile IS NOT NULL )
|
|
|
+ AND ( a.mobile <> '' )
|
|
|
+ AND ( c.create_platform <> 4 OR c.create_platform IS NULL )
|
|
|
+ AND (y.status = "潜在用户" or y.status is null or y.status = "权益用户" or y.status = "流失" )
|
|
|
+ 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 <= ?) )
|
|
|
+ GROUP BY a.user_id ORDER BY last_time asc
|
|
|
+ `
|
|
|
+ _, err = orm.NewOrm().Raw(sql, startTime, endTime, startTime, endTime).QueryRows(&items)
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// DealWxUser 处理用户标记状态
|
|
|
-func DealWxUser(userId int) (err error) {
|
|
|
- sql := `update wx_user set is_deal = 1 where user_id=?`
|
|
|
- _, err = orm.NewOrm().Raw(sql, userId).Exec()
|
|
|
+func DealWxUsers(userIds string) (err error) {
|
|
|
+ sql := `update wx_user set is_deal = 1 where user_id in (`+userIds+`) and is_deal=0`
|
|
|
+ _, err = orm.NewOrm().Raw(sql).Exec()
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+// DealFiccApply 处理用户申请标记状态
|
|
|
+func DealFiccApply(applyRecordIds string, dealTime time.Time) (err error) {
|
|
|
+ sql := `update yb_apply_record set op_status = 1, deal_time=? where apply_record_id in (`+applyRecordIds+`) and op_status=0`
|
|
|
+ _, err = orm.NewOrm().Raw(sql, dealTime).Exec()
|
|
|
return
|
|
|
}
|