Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yizhi_server
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
data_server
yizhi_server
Commits
b29eb37e
Commit
b29eb37e
authored
Apr 22, 2020
by
姜登
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
analyseInfo
parent
6d0b8de5
Pipeline
#22013
passed with stage
in 2 seconds
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
114 additions
and
10 deletions
+114
-10
account.js
app/controller/account.js
+26
-1
yzbillCostMonth.js
app/model/data/yzbillCostMonth.js
+4
-1
user.js
app/service/user.js
+7
-7
userDetail.js
app/service/userDetail.js
+75
-0
config.local.js
config/config.local.js
+2
-1
No files found.
app/controller/account.js
View file @
b29eb37e
...
...
@@ -15,7 +15,32 @@ class AccountController extends Controller {
}
async
analyse
()
{
const
{
ctx
,
service
}
=
this
;
const
input_params
=
ctx
.
request
.
query
;
const
rule
=
{
start_date
:
{
required
:
true
,
type
:
'string'
,
format
:
/^
[
1-9
]\d{3}
-
(
0
[
1-9
]
|1
[
0-2
])
-
(
0
[
1-9
]
|
[
1-2
][
0-9
]
|3
[
0-1
])
$|^
[
1-9
]\d{3}
-
(
0
[
1-9
]
|1
[
0-2
])
$/
,
message
:
'日期格式错误'
,
},
end_date
:
{
required
:
true
,
type
:
'string'
,
format
:
/^
[
1-9
]\d{3}
-
(
0
[
1-9
]
|1
[
0-2
])
-
(
0
[
1-9
]
|
[
1-2
][
0-9
]
|3
[
0-1
])
$|^
[
1-9
]\d{3}
-
(
0
[
1-9
]
|1
[
0-2
])
$/
,
message
:
'日期格式错误'
,
},
product
:
{
required
:
false
,
type
:
'string'
},
}
ctx
.
validate
(
rule
,
input_params
);
if
(
start_date
>
end_date
)
{
ctx
.
throw
(
400
,
'起始时间不能大于结束时间'
);
}
const
analyse_info
=
await
service
.
userDetail
.
analyseInfo
(
input_params
);
ctx
.
body
=
analyse_info
;
}
async
analyseDownload
()
{
...
...
app/model/data/yzbillCostMonth.js
View file @
b29eb37e
...
...
@@ -6,7 +6,10 @@ module.exports = app => {
const
billCostMonth
=
app
.
dataModel
.
define
(
'yzbillCostMonth'
,
{
appKey
:
{
type
:
INTEGER
,
primaryKey
:
true
},
service
:
STRING
,
day_month
:
STRING
,
day
:
{
type
:
STRING
,
field
:
'day_month'
},
query_volume
:
INTEGER
,
succ_volume
:
INTEGER
,
pull_volume
:
INTEGER
,
...
...
app/service/user.js
View file @
b29eb37e
...
...
@@ -111,15 +111,15 @@ class UserService extends Service {
],
where
:
{
user_id
,
day
:
last_day
},
})
lastday_info
.
use_amount
=
lastday_data
&&
lastday_data
.
amount
?
Number
((
lastday_data
.
amount
).
toFixed
(
2
))
:
0
;
lastday_info
.
use_money
=
lastday_data
&&
lastday_data
.
cost
?
Number
((
lastday_data
.
cost
).
toFixed
(
2
))
:
0
;
lastday_info
.
use_amount
=
lastday_data
&&
lastday_data
.
amount
?
Number
(
parseFloat
(
lastday_data
.
amount
).
toFixed
(
2
))
:
0
;
lastday_info
.
use_money
=
lastday_data
&&
lastday_data
.
cost
?
Number
(
parseFloat
(
lastday_data
.
cost
).
toFixed
(
2
))
:
0
;
const
left_money
=
await
ctx
.
dataModel
.
YzbillBalance
.
findOne
({
attributes
:
[
'balance_fn'
],
where
:
{
user_id
,
month
:
last_month
},
})
lastday_info
.
left_money
=
left_money
&&
left_money
.
balance_fn
?
Number
((
left_money
.
balance_fn
).
toFixed
(
2
))
:
0
;
lastday_info
.
left_money
=
left_money
&&
left_money
.
balance_fn
?
Number
(
parseFloat
(
left_money
.
balance_fn
).
toFixed
(
2
))
:
0
;
const
detail
=
[]
const
bill
=
await
ctx
.
dataModel
.
YzbillBalance
.
findAll
({
...
...
@@ -131,10 +131,10 @@ class UserService extends Service {
detail
.
push
({
name
:
bill
[
i
].
company
,
date
:
bill
[
i
].
month
,
start_left
:
Number
((
bill
[
i
].
balance_bg
).
toFixed
(
2
)),
middle_recharge
:
Number
((
bill
[
i
].
recharge_m
).
toFixed
(
2
)),
middlefee
:
Number
((
bill
[
i
].
cost_m
).
toFixed
(
2
)),
endfee
:
Number
((
bill
[
i
].
balance_fn
).
toFixed
(
2
)),
start_left
:
Number
(
parseFloat
(
bill
[
i
].
balance_bg
).
toFixed
(
2
)),
middle_recharge
:
Number
(
parseFloat
(
bill
[
i
].
recharge_m
).
toFixed
(
2
)),
middlefee
:
Number
(
parseFloat
(
bill
[
i
].
cost_m
).
toFixed
(
2
)),
endfee
:
Number
(
parseFloat
(
bill
[
i
].
balance_fn
).
toFixed
(
2
)),
})
}
...
...
app/service/userDetail.js
View file @
b29eb37e
...
...
@@ -40,6 +40,81 @@ class UserDetailService extends Service {
return
ret
.
get
(
'total'
);
}
async
analyseInfo
({
start_date
,
end_date
,
product
})
{
const
{
ctx
}
=
this
;
const
ret
=
{
product
:
'all'
,
overview
:
{
use_money
:
0
,
use_amount
:
0
,
},
list
:
[]
}
let
where
=
{
user_id
};
if
(
product
)
{
ret
.
product
=
product
;
where
.
service
=
product
;
}
const
appKeys
=
await
ctx
.
yizhiModel
.
UserService
.
findAll
({
attributes
:
[
'service'
,
'appkey'
],
where
});
if
(
appKeys
)
{
const
appList
=
[];
appKeys
.
forEach
((
value
,
index
)
=>
{
if
(
!
appList
.
includes
(
value
.
appkey
))
{
appList
.
push
(
value
.
appkey
);
}
});
let
type
=
'YzbillCost'
;
if
(
start_date
.
length
===
'7'
)
{
type
=
'YzbillCostMonth'
;
}
where
=
{
user_id
:
ctx
.
userId
,
appKey
:
appList
,
day
:
{
$lte
:
end_date
,
$gte
:
start_date
},
};
const
ret
=
await
ctx
.
dataModel
[
type
].
findAll
({
attributes
:
[
'day'
,
'pull_volume'
,
'cost'
],
where
,
order
:
[[
'day'
,
'desc'
]]
})
const
listMap
=
new
Map
();
for
(
let
i
=
0
;
i
<
ret
.
length
;
i
++
)
{
if
(
listMap
.
has
(
ret
[
i
].
day
))
{
let
obj
=
listMap
.
get
(
ret
[
i
].
day
);
obj
.
money
+=
parseFloat
(
ret
[
i
].
cost
);
obj
.
amount
+=
ret
[
i
].
pull_volume
;
listMap
.
set
(
ret
[
i
].
day
,
obj
);
}
else
{
listMap
.
set
(
ret
[
i
].
day
,
{
money
:
parseFloat
(
ret
[
i
].
cost
),
amount
:
ret
[
i
].
pull_volume
});
}
ret
.
overview
.
use_money
+=
parseFloat
(
ret
[
i
].
cost
);
ret
.
overview
.
use_amount
+=
ret
[
i
].
pull_volume
;
if
(
listMap
.
size
>
0
)
{
listMap
.
forEach
((
value
,
key
)
=>
{
ret
.
list
.
push
({
date
:
key
,
money
:
Number
((
value
.
money
).
toFixed
(
2
)),
amount
:
Number
((
value
.
amount
).
toFixed
(
0
))
})
})
}
}
return
ret
;
}
}
}
module
.
exports
=
UserDetailService
;
config/config.local.js
View file @
b29eb37e
...
...
@@ -21,7 +21,8 @@ module.exports = () => {
username
:
'hexin'
,
password
:
'gYUHszn9#q'
,
port
:
3306
,
}],
},
],
};
config
.
redis
=
{
...
...
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