Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CnChunfeng
/
crm_server
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
e3c1fe0b
authored
May 06, 2021
by
朱继来
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
添加跟进用户任务
parent
760fb1fe
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
129 additions
and
1 deletions
cmd/task/follow_user/main.go
internal/model/task_info.go
internal/model/users.go
internal/service/dingding.go
cmd/task/follow_user/main.go
0 → 100644
View file @
e3c1fe0b
package
main
/**
线下跟进用户任务
1. 任务未结束前,此任务唯一,不重复生成
2. 设置截止时间,截止时间前一天推送邮件提醒
*/
import
(
"crm-server/cmd/task/common"
"crm-server/internal/dao"
"crm-server/internal/model"
"crm-server/internal/service"
"flag"
"fmt"
"github.com/ichunt2019/logger"
"time"
)
// 日志目录
var
LogDir
string
// 解析命令行参数
func
initArgs
()
{
flag
.
StringVar
(
&
LogDir
,
"logDir"
,
""
,
"日志目录"
)
flag
.
Parse
()
}
func
main
()
{
initArgs
()
logConfig
:=
make
(
map
[
string
]
string
)
logConfig
[
"log_path"
]
=
LogDir
+
"/task/follow_user"
logConfig
[
"log_chan_size"
]
=
"100"
logger
.
InitLogger
(
"file"
,
logConfig
)
logger
.
Init
()
// 查看任务是否开启
task_setup
:=
common
.
GetTaskSetup
(
10
)
setTaskInfo
(
task_setup
.
Status
,
task_setup
.
Id
,
task_setup
.
TaskType
,
task_setup
.
TaskDisplayDegree
)
fmt
.
Println
(
"任务执行完成"
)
}
func
setTaskInfo
(
status
,
task_id
,
task_type
,
task_display_degree
int
)
{
if
status
==
0
||
status
==
-
1
{
// 数据不存在或未开启则直接中断
return
}
db
:=
dao
.
GetNewDb
()
// 查询有截止时间且待处理的任务记录
row
,
err
:=
db
.
Queryx
(
"select * from lie_task_info where task_type = 10 and status = 1 and is_send_msg = -1 limit 10"
)
defer
db
.
Close
()
if
err
!=
nil
{
logger
.
Info
(
"获取待处理的跟进用户任务记录失败: "
,
err
.
Error
())
return
}
for
row
.
Next
()
{
var
task_info
model
.
TaskInfo
row
.
StructScan
(
&
task_info
)
var
current_time
=
time
.
Now
()
.
Unix
()
// 若截止时间为0 或 截止时间减当前时间大于一天,则跳出本次循环,不处理
if
task_info
.
EndTime
==
0
||
(
task_info
.
EndTime
-
current_time
)
>
86400
{
continue
}
var
user
model
.
Users
db
.
Get
(
&
user
,
"select * from lie_user where user_id = ?"
,
task_info
.
UserId
)
var
account
string
if
user
.
Mobile
!=
""
{
account
=
user
.
Mobile
}
else
{
account
=
user
.
Email
}
// 推送邮件给客服
tm
:=
time
.
Unix
(
task_info
.
EndTime
,
0
)
limit_time_str
:=
tm
.
Format
(
"2006-01-02 03:04:05"
)
contents
:=
"CRM系统>任务信息管理>跟进用户任务:会员账号"
+
account
+
"跟进用户任务待处理,请前往CRM系统>任务信息管理>跟进用户处理,任务截止时间:"
+
limit_time_str
res
:=
service
.
SendMail
(
task_info
.
UserId
,
task_info
.
SaleId
,
task_type
,
contents
)
if
res
{
db
.
Exec
(
"update lie_task_info set is_send_msg = ? where id = ?"
,
1
,
task_info
.
Id
)
}
}
}
\ No newline at end of file
internal/model/task_info.go
View file @
e3c1fe0b
...
...
@@ -8,6 +8,7 @@ type TaskInfo struct {
TaskDisplayDegree
int
`json:"task_display_degree" db:"task_display_degree"`
SaleId
int
`json:"sale_id" db:"sale_id"`
Status
int
`json:"status" db:"status"`
IsSendMsg
int
`json:"is_send_msg" db:"is_send_msg"`
EndTime
int64
`json:"end_time" db:"end_time"`
CreateTime
int64
`json:"create_time" db:"create_time"`
UpdateTime
int64
`json:"update_time" db:"update_time"`
...
...
internal/model/users.go
View file @
e3c1fe0b
...
...
@@ -39,4 +39,6 @@ type Users struct {
Is_free
int64
`json:"is_free" db:"is_free"`
Free_time
int64
`json:"free_time" db:"free_time"`
Is_churn
int64
`json:"is_churn" db:"is_churn"`
Is_add_task
int64
`json:"is_add_task" db:"is_add_task"`
Channel_type
int64
`json:"channel_type" db:"channel_type"`
}
internal/service/dingding.go
View file @
e3c1fe0b
...
...
@@ -18,7 +18,7 @@ const APIMD5STR string = "fh6y5t4rr351d2c3bryi"
const
APIDOMAIN
string
=
configs
.
Api_url
+
"/msg/sendMessageByAuto"
const
ADMINTEL
int64
=
17600091664
const
DINGALERTURL
string
=
configs
.
Api_url
+
"/msg/dingalert"
var
TASK_TYPE_VAL
=
map
[
int
]
string
{
1
:
"领取分配"
,
2
:
"未成交释放(30)"
,
3
:
"已成交释放(180)"
,
4
:
"快速找料"
,
5
:
"老客户活跃"
,
6
:
"BOM询价"
,
7
:
"H5留言"
,
8
:
"发票提醒"
,
9
:
"开发板方案"
}
var
TASK_TYPE_VAL
=
map
[
int
]
string
{
1
:
"领取分配"
,
2
:
"未成交释放(30)"
,
3
:
"已成交释放(180)"
,
4
:
"快速找料"
,
5
:
"老客户活跃"
,
6
:
"BOM询价"
,
7
:
"H5留言"
,
8
:
"发票提醒"
,
9
:
"开发板方案"
,
10
:
"跟进用户"
}
func
AdminErr
(
err
error
)
{
if
err
!=
nil
{
...
...
@@ -141,4 +141,35 @@ func SendNewTaskMsg(crm_user_id int, sale_id int , task_type int, limit_time str
defer
resp
.
Body
.
Close
()
}
// CRM任务推送邮件
func
SendMail
(
crm_user_id
int
,
sale_id
int
,
task_type
int
,
contents
string
)
bool
{
if
sale_id
==
0
{
return
false
}
var
email
string
// 客服邮箱
dao
.
GetCmsDb
()
.
Get
(
&
email
,
"select email from user_info where userId = ?"
,
sale_id
)
timeNow
:=
time
.
Now
()
.
Unix
()
requestContent
,
_
:=
json
.
Marshal
(
map
[
string
]
string
{
"contents"
:
contents
})
requestTel
,
_
:=
json
.
Marshal
([]
string
{
email
})
resp
,
err
:=
http
.
PostForm
(
APIDOMAIN
,
url
.
Values
{
"data"
:
{
string
(
requestContent
)},
"touser"
:
{
string
(
requestTel
)},
"keyword"
:
{
"crm-task-send-mail"
},
"k1"
:
{
strconv
.
FormatInt
(
int64
(
timeNow
),
10
)},
"k2"
:
{
common
.
Md5
(
common
.
Md5
(
strconv
.
FormatInt
(
int64
(
timeNow
),
10
))
+
APIMD5STR
)},
"is_ignore"
:
{
"1"
},
})
defer
resp
.
Body
.
Close
()
if
err
!=
nil
{
DingAlert
(
configs
.
Ding_crm_task_token
,
"任务告警:"
+
TASK_TYPE_VAL
[
task_type
]
+
"任务记录邮件推送失败,CRM用户ID:"
+
strconv
.
Itoa
(
crm_user_id
),
""
)
return
false
}
return
true
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment