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
68ffbd0d
authored
Nov 01, 2021
by
朱继来
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
调整db
parent
b0188ed3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
1 deletions
cmd/task/user_order_count/main.go
internal/dao/sqlx.go
cmd/task/user_order_count/main.go
View file @
68ffbd0d
...
...
@@ -35,7 +35,7 @@ func main() {
tm
:=
time
.
Date
(
t
.
Year
(),
t
.
Month
(),
t
.
Day
(),
0
,
0
,
0
,
0
,
t
.
Location
())
yesterday_time
:=
tm
.
AddDate
(
0
,
0
,
-
1
)
.
Unix
()
db
:=
dao
.
GetLiexinDb
()
db
:=
dao
.
GetLiexin
Order
Db
()
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"
,
yesterday_time
)
defer
db
.
Close
()
...
...
internal/dao/sqlx.go
View file @
68ffbd0d
...
...
@@ -11,11 +11,13 @@ import (
var
instance
*
sqlx
.
DB
var
instanceCms
*
sqlx
.
DB
var
instanceLiexin
*
sqlx
.
DB
var
instanceLiexinOrder
*
sqlx
.
DB
var
instanceLiexinBom
*
sqlx
.
DB
var
once
sync
.
Once
var
onceCms
sync
.
Once
var
onceLiexin
sync
.
Once
var
onceLiexinOrder
sync
.
Once
var
onceLiexinBom
sync
.
Once
// 创建可释放的db连接
...
...
@@ -64,6 +66,15 @@ func GetLiexinDb()(*sqlx.DB) {
return
instanceLiexin
}
func
GetLiexinOrderDb
()(
*
sqlx
.
DB
)
{
dbConfig
:=
configs
.
GetDBLiexinOrder
()
db
,
err
:=
sqlx
.
Open
(
dbConfig
.
Engine
,
fmt
.
Sprintf
(
"%s:%s@tcp(%s:%s)/%s?charset=utf8"
,
dbConfig
.
User
,
dbConfig
.
Pass
,
dbConfig
.
Ip
,
dbConfig
.
Port
,
dbConfig
.
Table
))
if
err
!=
nil
{
log
.
Fatalln
(
err
)
}
return
db
}
func
GetLiexinBomDb
()(
*
sqlx
.
DB
)
{
onceLiexinBom
.
Do
(
func
()
{
dbConfig
:=
configs
.
GetDBLiexinBom
()
...
...
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