Commit 24608f43 by Joneq

success user pond

parent bd9f7432
package main
import (
"flag"
"context"
"crm-server/internal/service"
"crm-server/internal/dao"
"crm-server/internal/model"
"fmt"
"github.com/bilibili/kratos/pkg/conf/paladin"
"github.com/bilibili/kratos/pkg/log"
)
func main() {
//获取输入参数
flag.Parse()
if err := paladin.Init(); err != nil {
panic(err)
}
//初始化日志目录
log.Init(&log.Config{Dir: "logs"})
defer log.Close()
log.Info("caipu-server start")
//测试数据库连接
var user_info model.UserInfo
var user_company model.UserCompany
//查找手机号
err := dao.GetCmsDb().QueryRowx("select mobile from user_info where userId = ?",1599).StructScan(&user_info)
if err != nil {
fmt.Println(err)
}
fmt.Println(user_info.Mobile)
//声明service层 测试数据库是否连接
svc := service.New()
ctx := context.Background()
//调用会员服务
fmt.Println(svc.GetUserInfoByUserId(ctx,1))
//查找公司名称
err = dao.GetDb().QueryRowx("select com_name from lie_user_company where user_id = ?",1).StructScan(&user_company)
if err != nil {
fmt.Println(err)
}
fmt.Println(user_company.Com_name)
}
package main
//用户池中已下单的释放
package logic
import (
"crm-server/internal/dao"
"crm-server/internal/model"
"crm-server/internal/service"
"time"
)
//用户池中已下单的释放
func HaveCreateHandle() {
db := dao.GetDb()
//需要等待释放的用户
var CreateOrderHandleUser = make(map[int]int)
var assign_active model.AssignActive
var month_time = (time.Now().Unix()- 86400 * 30 * 4)
//查找第一次出不再跟随的用户ID,然后释放
rows,err := db.Queryx("select aa.user_id,turn_in_id,no_create_order from lie_assign_active as aa left join lie_user_extend ue on aa.user_id = ue.user_id where is_success = ? and ue.no_create_order = 2 and change_time < ? and latest_order_time < ?",1,month_time,month_time)
service.AdminErr(err)
for rows.Next() {
err = rows.StructScan(&assign_active)
service.AdminErr(err)
CreateOrderHandleUser[assign_active.User_Id] = assign_active.Turn_In_id
dao.GetDb().Exec("delete from lie_salesman where user_id = ?",assign_active.User_Id)
}
//查找第二次出不再跟随的用户ID,释放并且屏蔽
rows,err = db.Queryx("select aa.user_id,turn_in_id,no_create_order from lie_assign_active as aa left join lie_user_extend ue on aa.user_id = ue.user_id where is_success = 2 and ue.no_create_order = 2 and change_time < ? and latest_order_time < ?",month_time,month_time)
service.AdminErr(err)
for rows.Next() {
err = rows.StructScan(&assign_active)
service.AdminErr(err)
CreateOrderHandleUser[assign_active.User_Id] = assign_active.Turn_In_id
SetFreeHandleUser[assign_active.User_Id] = CreateOrderHandleUser[assign_active.User_Id]
dao.GetDb().Exec("delete from lie_salesman where user_id = ?",assign_active.User_Id)
}
}
package logic
import (
"crm-server/internal/dao"
"crm-server/internal/model"
"crm-server/internal/service"
"time"
)
//用户池中未下单的待处理
func NoCreateHandle() {
db := dao.GetDb()
var assign_active model.AssignActive
var NoOrderHandleUser = make(map[int]int)
var month_time = (time.Now().Unix()- 86400 * 30 * 1)
//查找第一次出不再跟随的用户ID,然后释放
rows,err := db.Queryx("select aa.user_id,turn_in_id,no_create_order from lie_assign_active as aa left join lie_user_extend ue on aa.user_id = ue.user_id where is_success = ? and ue.no_create_order = 1 and change_time < ? and latest_order_time < ?",1,month_time,month_time)
service.AdminErr(err)
for rows.Next() {
err = rows.StructScan(&assign_active)
service.AdminErr(err)
NoOrderHandleUser[assign_active.User_Id] = assign_active.Turn_In_id
}
//查找第二次出不再跟随的用户ID,释放并且屏蔽
rows,err = db.Queryx("select aa.user_id,turn_in_id,no_create_order from lie_assign_active as aa left join lie_user_extend ue on aa.user_id = ue.user_id where is_success = ? and ue.no_create_order = 1 and change_time < ? and latest_order_time < ?",2,month_time,month_time)
service.AdminErr(err)
for rows.Next() {
err = rows.StructScan(&assign_active)
service.AdminErr(err)
NoOrderHandleUser[assign_active.User_Id] = assign_active.Turn_In_id
SetFreeHandleUser[assign_active.User_Id] = NoOrderHandleUser[assign_active.User_Id]
dao.GetDb().Exec("delete from lie_salesman where user_id = ?",assign_active.User_Id)
}
}
\ No newline at end of file
package logic
import (
"crm-server/internal/dao"
"crm-server/internal/model"
"crm-server/internal/service"
"fmt"
"time"
)
//提醒客服
func Notify() {
var assign_active model.AssignActive
//查找出需要发送通知的用户,发送通知
rows,err := dao.GetDb().Queryx("select turn_in_id,aa.user_id from lie_assign_active as aa left join lie_user_extend ue on aa.user_id = ue.user_id where (ue.no_create_order = 1 and change_time < ? and change_time > ? and latest_order_time < ? ) or (ue.no_create_order = 2 and change_time < ? and change_time > ? and latest_order_time < ? ) ",
(time.Now().Unix()- 86400 * 23),(time.Now().Unix()- 86400 * 24),(time.Now().Unix()- 86400 * 23),(time.Now().Unix()- 86400 * 103),(time.Now().Unix()- 86400 * 104),(time.Now().Unix()- 86400 * 103))
service.AdminErr(err)
var user_info model.UserInfo
var user_company model.UserCompany
for rows.Next() {
_ = rows.StructScan(&assign_active)
//查找手机号
err := dao.GetCmsDb().QueryRowx("select mobile from user_info where userId = ?",assign_active.Turn_In_id).StructScan(&user_info)
if err != nil {
fmt.Println(err)
}
//查找公司名称
err = dao.GetDb().QueryRowx("select com_name from lie_user_company where user_id = ?",assign_active.User_Id).StructScan(&user_company)
if err != nil {
fmt.Println(err)
}
service.SendMessage(user_info.Mobile,"您的客户:"+user_company.Com_name+"在跟进后23天任未下单,还有7天将被转出,请注意查看")
}
}
package logic
import (
"crm-server/internal/dao"
"fmt"
"time"
)
//需要等地屏蔽的用户
var SetFreeHandleUser = make(map[int]int)
//释放用户
func SetFree() {
//查找出即将释放的用户,然后释放
for k,v := range SetFreeHandleUser{
_,err := dao.GetDb() .Exec("INSERT INTO `lie_not_follow_user` (`user_id`, `sale_id`, `stop_time`)VALUES(?, ?,?)",k,v,time.Now().Unix())
if err != nil {
fmt.Println("添加记录失败",k)
}
dao.GetDb().Exec("delete from lie_assign_active where user_id = ? and turn_in_id = ?",k,v)
}
}
\ No newline at end of file
package main
import (
"crm-server/internal/dao"
"crm-server/internal/model"
"crm-server/internal/service"
"fmt"
"time"
)
import "crm-server/cmd/pond/logic"
//tpad https://www.tapd.cn/20225631/prong/stories/view/1120225631001003634
func main() {
db := dao.GetDb()
haveDandleUser := make(map[int]int)
var assign_active model.AssignActive
//查找出不再跟随的用户ID,然后不再允许跟进
rows,_ := db.Queryx("select user_id,turn_in_id from lie_assign_active where is_success = ? and change_time < ?",2,(time.Now().Unix()- 86400 * 30))
for rows.Next() {
_ = rows.StructScan(&assign_active)
haveDandleUser[assign_active.User_Id] = assign_active.Turn_In_id
}
//查找出即将释放的用户,然后释放
for k,v := range haveDandleUser{
_,err := db.Exec("INSERT INTO `lie_not_follow_user` (`user_id`, `sale_id`, `stop_time`)VALUES(?, ?,?)",k,v,time.Now().Unix())
if err != nil {
fmt.Println("添加记录失败",k)
}
db.Exec("delete from lie_assign_active where user_id = ? and turn_in_id = ?",k,v)
}
logic.HaveCreateHandle()
logic.NoCreateHandle()
logic.Notify()
logic.SetFree()
}
//查找出需要发送通知的用户,发送通知
rows,_ = db.Queryx("select turn_in_id,user_id from lie_assign_active where change_time < ? and change_time > ?",(time.Now().Unix()- 86400 * 23),(time.Now().Unix()- 86400 * 24))
db = dao.GetCmsDb()
var user_info model.UserInfo
var user_company model.UserCompany
for rows.Next() {
_ = rows.StructScan(&assign_active)
//查找手机号
err := db.QueryRowx("select mobile from user_info where userId = ?",assign_active.Turn_In_id).StructScan(&user_info)
if err != nil {
fmt.Println(err)
}
//查找公司名称
err = dao.GetDb().QueryRowx("select com_name from lie_user_company where user_id = ?",assign_active.User_Id).StructScan(&user_company)
if err != nil {
fmt.Println(err)
}
service.SendMessage(user_info.Mobile,"您的客户:"+user_company.Com_name+"在跟进后23天任未下单,还有7天将被转出,请注意查看")
}
}
package main
//用户池中未下单的释放
\ No newline at end of file
......@@ -7,6 +7,7 @@ type AssignActive struct {
Turn_In_id int `json:"turn_in_id"`
Assign_id int `json:"assign_id"`
Is_Success int `json:"is_success"`
No_Create_Order int `json:"no_create_order"`
Change_Time int `json:"change_time"`
Create_time int `json:"create_time"`
}
......
......@@ -12,6 +12,15 @@ import (
const APIMD5STR string = "fh6y5t4rr351d2c3bryi"
const APIDOMAIN string = "http://api.ichunt.com/msg/sendMessageByAuto"
const ADMINTEL int64 = 17600091664
func AdminErr(err error) {
if err != nil {
fmt.Println(err)
//SendMessage(ADMINTEL,err.Error())
}
}
func SendMessage(mobile int64 , content string){
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment