Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
孙龙
/
golang-queue-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
526a92a4
authored
Oct 11, 2021
by
mushishixian
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
活动相关脚本修改
parent
702be50f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
21 deletions
special/activity_statistics/main.go
special/activity_statistics/model/user_main.go
special/activity_statistics/main.go
View file @
526a92a4
...
@@ -103,8 +103,6 @@ func main() {
...
@@ -103,8 +103,6 @@ func main() {
updateTime
=
1
updateTime
=
1
}
}
updateTime
=
1
//先去取出所有的正在进行的活动列表
//先去取出所有的正在进行的活动列表
var
giftActivityList
[]
model
.
GiftActivity
var
giftActivityList
[]
model
.
GiftActivity
err
=
specialDb
.
Reset
()
.
Table
(
&
giftActivityList
)
.
Fields
(
"id,start_time,end_time"
)
.
err
=
specialDb
.
Reset
()
.
Table
(
&
giftActivityList
)
.
Fields
(
"id,start_time,end_time"
)
.
...
@@ -124,7 +122,7 @@ func main() {
...
@@ -124,7 +122,7 @@ func main() {
newUserNum
=
0
newUserNum
=
0
if
orderGiftUserIds
!=
nil
{
if
orderGiftUserIds
!=
nil
{
userIds
=
orderGiftUserIds
.
([]
interface
{})
userIds
=
orderGiftUserIds
.
([]
interface
{})
if
len
(
userIds
)
>
0
{
if
len
(
userIds
)
>
0
{
//然后根据得到的user_id去In查询所有的用户,并且是要新注册的用户
//然后根据得到的user_id去In查询所有的用户,并且是要新注册的用户
newUserNum
,
err
=
db
.
Reset
()
.
Table
(
"lie_user_main"
)
.
WhereIn
(
"user_id"
,
userIds
)
.
Where
(
"is_new"
,
1
)
.
Count
()
newUserNum
,
err
=
db
.
Reset
()
.
Table
(
"lie_user_main"
)
.
WhereIn
(
"user_id"
,
userIds
)
.
Where
(
"is_new"
,
1
)
.
Count
()
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -132,7 +130,6 @@ func main() {
...
@@ -132,7 +130,6 @@ func main() {
fmt
.
Println
(
err
.
Error
())
fmt
.
Println
(
err
.
Error
())
}
}
}
}
}
}
//先查询统计是否存在
//先查询统计是否存在
count
,
_
:=
specialDb
.
Reset
()
.
Table
(
"lie_activity_statistics"
)
.
Where
(
"activity_id"
,
activity
.
Id
)
.
count
,
_
:=
specialDb
.
Reset
()
.
Table
(
"lie_activity_statistics"
)
.
Where
(
"activity_id"
,
activity
.
Id
)
.
...
@@ -217,7 +214,9 @@ func main() {
...
@@ -217,7 +214,9 @@ func main() {
}
}
}
}
//价格促销活动*****************
updateTime
=
1
//价格促销活动统计***********************************************************************************************
var
priceActivityList
[]
model
.
PriceActivity
var
priceActivityList
[]
model
.
PriceActivity
err
=
specialDb
.
Reset
()
.
Table
(
&
priceActivityList
)
.
Fields
(
"id,start_time,end_time"
)
.
err
=
specialDb
.
Reset
()
.
Table
(
&
priceActivityList
)
.
Fields
(
"id,start_time,end_time"
)
.
Where
(
"end_time"
,
">"
,
updateTime
)
.
Select
()
Where
(
"end_time"
,
">"
,
updateTime
)
.
Select
()
...
@@ -227,11 +226,6 @@ func main() {
...
@@ -227,11 +226,6 @@ func main() {
}
}
for
_
,
activity
:=
range
priceActivityList
{
for
_
,
activity
:=
range
priceActivityList
{
orderNum
,
_
:=
db
.
Reset
()
.
Table
(
"lie_order_activity_count"
)
.
Where
(
"activity_id"
,
activity
.
Id
)
.
Count
(
"order_id"
)
orderNum
,
_
:=
db
.
Reset
()
.
Table
(
"lie_order_activity_count"
)
.
Where
(
"activity_id"
,
activity
.
Id
)
.
Count
(
"order_id"
)
//newUserNum, _ := db.Reset().Table("lie_order_activity_count").LeftJoin("lie_user_main on lie_order_activity_count.user_id = lie_user_main.user_id").
// Where("lie_order_activity_count.activity_id", activity.Id).Where("lie_user_main.is_new", 1).
// Count("lie_user_main.user_id")
//先找出这个活动对应的所有用户(根据user_id)去重
//先找出这个活动对应的所有用户(根据user_id)去重
orderActivityUserIds
,
_
:=
orderDb
.
Reset
()
.
Table
(
"lie_order_activity_count"
)
.
orderActivityUserIds
,
_
:=
orderDb
.
Reset
()
.
Table
(
"lie_order_activity_count"
)
.
Where
(
"lie_order_activity_count.activity_id"
,
activity
.
Id
)
.
Where
(
"lie_order_activity_count.activity_id"
,
activity
.
Id
)
.
...
@@ -241,7 +235,7 @@ func main() {
...
@@ -241,7 +235,7 @@ func main() {
newUserNum
=
0
newUserNum
=
0
if
orderActivityUserIds
!=
nil
{
if
orderActivityUserIds
!=
nil
{
userIds
=
orderActivityUserIds
.
([]
interface
{})
userIds
=
orderActivityUserIds
.
([]
interface
{})
if
len
(
userIds
)
>
0
{
if
len
(
userIds
)
>
0
{
//然后根据得到的user_id去In查询所有的用户,并且是要新注册的用户
//然后根据得到的user_id去In查询所有的用户,并且是要新注册的用户
newUserNum
,
err
=
db
.
Reset
()
.
Table
(
"lie_user_main"
)
.
WhereIn
(
"user_id"
,
userIds
)
.
Where
(
"is_new"
,
1
)
.
Count
()
newUserNum
,
err
=
db
.
Reset
()
.
Table
(
"lie_user_main"
)
.
WhereIn
(
"user_id"
,
userIds
)
.
Where
(
"is_new"
,
1
)
.
Count
()
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -249,7 +243,6 @@ func main() {
...
@@ -249,7 +243,6 @@ func main() {
fmt
.
Println
(
err
.
Error
())
fmt
.
Println
(
err
.
Error
())
}
}
}
}
}
}
//先查询统计是否存在
//先查询统计是否存在
...
@@ -278,15 +271,32 @@ func main() {
...
@@ -278,15 +271,32 @@ func main() {
}
}
}
}
items
,
err
:=
db
.
Reset
()
.
items
,
err
:=
db
.
Reset
()
.
Fields
(
"activity_id,
order_id,lie_user_main.user_id,mobile,create_device
,sum(lie_order_activity_count.amount) as total_amount"
)
.
Fields
(
"activity_id,
user_id,order_id
,sum(lie_order_activity_count.amount) as total_amount"
)
.
Table
(
"lie_order_activity_count"
)
.
Table
(
"lie_order_activity_count"
)
.
LeftJoin
(
"lie_user_main on lie_order_activity_count.user_id = lie_user_main.user_id"
)
.
Where
(
"lie_order_activity_count.activity_id"
,
activity
.
Id
)
.
Where
(
"lie_order_activity_count.activity_id"
,
activity
.
Id
)
.
GroupBy
(
"order_id"
)
.
Get
()
GroupBy
(
"order_id"
)
.
Get
()
if
err
!=
nil
{
if
err
!=
nil
{
logger
.
Error
(
err
.
Error
())
logger
.
Error
(
err
.
Error
())
fmt
.
Println
(
err
.
Error
())
fmt
.
Println
(
err
.
Error
())
}
}
//找出有用户id,然后去DB里面用IN查找用户数据
var
activityUserIds
[]
interface
{}
for
_
,
item
:=
range
items
{
resultByte
,
_
:=
json
.
Marshal
(
item
)
result
:=
string
(
resultByte
)
userId
:=
gjson
.
Get
(
result
,
"user_id"
)
.
Int
()
activityUserIds
=
append
(
activityUserIds
,
int
(
userId
))
}
userMap
:=
make
(
map
[
int
]
model
.
UserMain
)
if
len
(
activityUserIds
)
>
0
{
var
users
[]
model
.
UserMain
err
=
db
.
Reset
()
.
Table
(
&
users
)
.
Fields
(
"user_id,mobile,is_new,create_device"
)
.
WhereIn
(
"user_id"
,
activityUserIds
)
.
Select
()
for
_
,
user
:=
range
users
{
userMap
[
user
.
UserId
]
=
user
}
}
fmt
.
Println
(
"用户数据为 : "
,
userMap
)
for
_
,
item
:=
range
items
{
for
_
,
item
:=
range
items
{
resultByte
,
err
:=
json
.
Marshal
(
item
)
resultByte
,
err
:=
json
.
Marshal
(
item
)
result
:=
string
(
resultByte
)
result
:=
string
(
resultByte
)
...
@@ -297,7 +307,6 @@ func main() {
...
@@ -297,7 +307,6 @@ func main() {
Find
(
bson
.
M
{
"order_id"
:
gjson
.
Get
(
result
,
"order_id"
)
.
Int
(),
"activity_id"
:
gjson
.
Get
(
result
,
"activity_id"
)
.
Int
()})
.
Find
(
bson
.
M
{
"order_id"
:
gjson
.
Get
(
result
,
"order_id"
)
.
Int
(),
"activity_id"
:
gjson
.
Get
(
result
,
"activity_id"
)
.
Int
()})
.
One
(
&
priceActivityMongo
)
One
(
&
priceActivityMongo
)
if
err
!=
nil
&&
err
!=
mgo
.
ErrNotFound
{
if
err
!=
nil
&&
err
!=
mgo
.
ErrNotFound
{
logger
.
Error
(
err
.
Error
())
logger
.
Error
(
err
.
Error
())
fmt
.
Println
(
err
.
Error
())
fmt
.
Println
(
err
.
Error
())
}
}
...
@@ -306,9 +315,12 @@ func main() {
...
@@ -306,9 +315,12 @@ func main() {
priceActivityMongo
.
ActivityId
=
gjson
.
Get
(
result
,
"activity_id"
)
.
Int
()
priceActivityMongo
.
ActivityId
=
gjson
.
Get
(
result
,
"activity_id"
)
.
Int
()
priceActivityMongo
.
OrderId
=
gjson
.
Get
(
result
,
"order_id"
)
.
Int
()
priceActivityMongo
.
OrderId
=
gjson
.
Get
(
result
,
"order_id"
)
.
Int
()
priceActivityMongo
.
UserId
=
gjson
.
Get
(
result
,
"user_id"
)
.
Int
()
priceActivityMongo
.
UserId
=
gjson
.
Get
(
result
,
"user_id"
)
.
Int
()
priceActivityMongo
.
Mobile
=
gjson
.
Get
(
result
,
"mobile"
)
.
String
()
priceActivityMongo
.
OrderAmount
=
gjson
.
Get
(
result
,
"total_amount"
)
.
Float
()
priceActivityMongo
.
OrderAmount
=
gjson
.
Get
(
result
,
"total_amount"
)
.
Float
()
priceActivityMongo
.
Pf
=
gjson
.
Get
(
result
,
"create_device"
)
.
Int
()
//priceActivityMongo.Mobile = gjson.Get(result, "mobile").String()
//priceActivityMongo.Pf = gjson.Get(result, "create_device").Int()
priceActivityMongo
.
Mobile
=
userMap
[
int
(
priceActivityMongo
.
UserId
)]
.
Mobile
priceActivityMongo
.
Pf
=
userMap
[
int
(
priceActivityMongo
.
UserId
)]
.
CreateDevice
fmt
.
Println
(
"mongo数据为 : "
,
priceActivityMongo
)
err
=
mongoConn
.
DB
(
"ichunt"
)
.
C
(
"price_activity_statistics"
)
.
Insert
(
&
priceActivityMongo
)
err
=
mongoConn
.
DB
(
"ichunt"
)
.
C
(
"price_activity_statistics"
)
.
Insert
(
&
priceActivityMongo
)
if
err
!=
nil
{
if
err
!=
nil
{
logger
.
Error
(
err
.
Error
())
logger
.
Error
(
err
.
Error
())
...
...
special/activity_statistics/model/user_main.go
View file @
526a92a4
package
model
package
model
type
UserMain
struct
{
type
UserMain
struct
{
UserId
int
`gorose:"user_id"`
UserId
int
`gorose:"user_id"`
Mobile
string
`gorose:"mobile"`
Mobile
string
`gorose:"mobile"`
IsNew
int
`gorose:"is_new"`
IsNew
int
`gorose:"is_new"`
RegRemark
string
`gorose:"reg_remark"`
CreateDevice
int64
`gorose:"create_device"`
RegRemark
string
`gorose:"reg_remark"`
}
}
func
(
um
*
UserMain
)
TableName
()
string
{
func
(
um
*
UserMain
)
TableName
()
string
{
...
...
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