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
3eead39e
authored
Sep 24, 2021
by
朱继来
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
获取用户下单数
parent
7712c104
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
86 additions
and
0 deletions
cmd/task/user_order_count/main.go
internal/model/user_order_count.go
cmd/task/user_order_count/main.go
0 → 100644
View file @
3eead39e
package
main
/**
每天零点获取用户下单数
*/
import
(
"crm-server/internal/dao"
"crm-server/internal/model"
"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/user_order_count"
logConfig
[
"log_chan_size"
]
=
"100"
logger
.
InitLogger
(
"file"
,
logConfig
)
logger
.
Init
()
var
current_time
=
time
.
Now
()
.
Unix
()
db
:=
dao
.
GetLiexinDb
()
row
,
err
:=
db
.
Queryx
(
"SELECT user_id, FROM_UNIXTIME(create_time,
\"
%Y%m%d
\"
) AS date, COUNT(*) AS count FROM `lie_order` "
+
"WHERE user_id > 0 AND is_type = 0 AND create_time > ? GROUP BY user_id, date ORDER BY create_time"
,
current_time
)
defer
db
.
Close
()
if
err
!=
nil
{
fmt
.
Println
(
"获取用户下单数失败:"
+
err
.
Error
())
logger
.
Info
(
"获取用户下单数失败: "
,
err
.
Error
())
return
}
crm_db
:=
dao
.
GetDb
()
defer
crm_db
.
Close
()
if
!
row
.
Next
()
{
fmt
.
Println
(
"未获取到用户下单数"
)
return
}
for
row
.
Next
()
{
var
user_order_count
model
.
UserOrderCount
row
.
StructScan
(
&
user_order_count
)
var
user_order_id
int
crm_db
.
Get
(
&
user_order_id
,
"select id from lie_user_order_count where user_id = ? and date = ?"
,
user_order_count
.
User_Id
,
user_order_count
.
Date
)
if
user_order_id
!=
0
{
// 若存在,则跳过
continue
}
_
,
err
:=
crm_db
.
Exec
(
"insert into lie_user_order_count (user_id, date, count, create_time) values (?, ?, ?, ?)"
,
user_order_count
.
User_Id
,
user_order_count
.
Date
,
user_order_count
.
Count
,
current_time
)
if
err
!=
nil
{
fmt
.
Println
(
"添加用户下单数失败:"
+
err
.
Error
())
logger
.
Info
(
"添加用户下单数失败: "
,
err
.
Error
())
return
}
}
fmt
.
Println
(
"添加用户下单数成功"
)
}
\ No newline at end of file
internal/model/user_order_count.go
0 → 100644
View file @
3eead39e
package
model
type
UserOrderCount
struct
{
Id
int
`db:"id"`
User_Id
int
`db:"user_id"`
Date
string
`db:"date"`
Count
int
`db:"count"`
Create_Time
int64
`db:"create_time"`
}
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