Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Z
zhichan
Overview
Overview
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
蒋勇
zhichan
Commits
8d0d2d5b
Commit
8d0d2d5b
authored
Jul 17, 2020
by
linboxuan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ucommune-back operate api
parent
72212885
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
109 additions
and
17 deletions
+109
-17
center-order/app/base/service/impl/dbcorder/ucommuneOrderSve.js
+109
-17
No files found.
center-order/app/base/service/impl/dbcorder/ucommuneOrderSve.js
View file @
8d0d2d5b
const
system
=
require
(
"../../../system"
);
const
system
=
require
(
"../../../system"
);
const
ServiceBase
=
require
(
"../../sve.base"
);
const
ServiceBase
=
require
(
"../../sve.base"
);
var
moment
=
require
(
'moment'
)
class
OrderInfoService
extends
ServiceBase
{
class
OrderInfoService
extends
ServiceBase
{
constructor
()
{
constructor
()
{
super
(
"dbcorder"
,
ServiceBase
.
getDaoName
(
OrderInfoService
));
super
(
"dbcorder"
,
ServiceBase
.
getDaoName
(
OrderInfoService
));
...
@@ -53,35 +54,126 @@ class OrderInfoService extends ServiceBase {
...
@@ -53,35 +54,126 @@ class OrderInfoService extends ServiceBase {
}
}
async
getStatistics
(
pobj
,
actionBody
)
{
// uk运营后台 业务统计
// ----------------------------------------------uk运营后台 开始
var
needsCount
=
await
this
.
needInfoDao
.
findCount
({
where
:{
uapp_id
:
actionBody
.
uappId
}});
// 需求量
// uk运营后台 业务统计
async
getStatistics
(
pobj
,
actionBody
)
{
var
sql
=
"SELECT DISTINCT need.needNo,count(1) as count "
// 需求量sql 查询关于渠道的需求订单
var
needsCountSql
=
"select count(1) as count from n_need_info where uapp_id= "
+
actionBody
.
uappId
// 转换率sql 查询需求表并且有需求方案
var
conversionRateListSql
=
"SELECT DISTINCT need.needNo,count(1) as count "
+
" FROM n_need_info AS need LEFT JOIN n_need_solution AS solution ON need.needNo = solution.needNo "
+
" FROM n_need_info AS need LEFT JOIN n_need_solution AS solution ON need.needNo = solution.needNo "
+
" where solution.orderNo is not null and need.uapp_id = "
+
actionBody
.
uappId
;
+
" where solution.orderNo is not null and need.uapp_id = "
+
actionBody
.
uappId
;
var
conversionRateList
=
await
this
.
needInfoDao
.
customQuery
(
sql
);
if
(
conversionRateList
.
length
!=
1
)
{
conversionRate
=
0
;
}
var
conversionRate
=
(
conversionRateList
[
0
][
"count"
]
/
needsCount
).
toFixed
(
2
);
// 需求订单转化为订单的数量 保留两位
// 订单相关sql 查询订单量/订单交易额/公司宝结算额/渠道毛利
var
payObjSql
=
"select sum(totalSum) as totalSum,sum(pfProfitSum) as parentProfit,sum(channelProfitSum) as grossProfit, count(1) as count "
+
" from c_order_info where uapp_id="
+
actionBody
.
uappId
+
" and orderStatus!=1"
;
var
sql
=
"select sum(totalSum) as totalSum,sum(pfProfitSum) as parentProfit,sum(channelProfitSum) as grossProfit, count(1) as count "
// 整合起始时间/截止时间
+
" from c_order_info where uapp_id="
+
actionBody
.
uappId
+
" and orderStatus=2"
;
var
paramWhere
=
{}
var
payObj
=
await
this
.
customQuery
(
sql
);
// 订单量/交易总额/公司宝结算额/对方毛利
if
(
actionBody
.
startTime
&&
actionBody
.
entTime
)
{
if
(
payObj
.
length
!=
1
)
{
var
startTime
=
actionBody
.
startTime
.
trim
()
+
" 00:00:00"
;
var
entTime
=
actionBody
.
entTime
+
" 23:59:59"
;
needsCountSql
+=
" and updated_at >=:startTime and updated_at<=:entTime"
;
// 关于需求用了uupdate_at,订单用的created_at
conversionRateListSql
+=
" and need.updated_at >=:startTime and need.updated_at<=:entTime"
;
payObjSql
+=
" and created_at >=:startTime and created_at<=:entTime"
;
paramWhere
.
startTime
=
startTime
;
paramWhere
.
entTime
=
entTime
;
}
// 需求量
var
needsCountList
=
await
this
.
needInfoDao
.
customQuery
(
needsCountSql
,
paramWhere
);
var
needsCount
=
needsCountList
[
0
][
"count"
];
if
(
needsCountList
.
length
!=
0
)
{
needsCount
=
0
;
}
// 需求订单转化为订单的数量 保留两位 成为订单的需求 / 需求数量
var
conversionRateList
=
await
this
.
needInfoDao
.
customQuery
(
conversionRateListSql
,
paramWhere
);
var
conversionRate
=
(
conversionRateList
[
0
][
"count"
]
/
needsCount
).
toFixed
(
2
);
if
(
conversionRateList
.
length
!=
1
||
conversionRateList
[
0
][
"count"
]
==
0
)
{
conversionRate
=
0
;
}
}
// 订单量/交易总额/公司宝结算额/对方毛利
var
payObj
=
await
this
.
customQuery
(
payObjSql
,
paramWhere
);
payObj
=
payObj
[
0
];
let
resultObj
=
{
let
resultObj
=
{
needsCount
:
needsCount
,
needsCount
:
needsCount
,
payCount
:
payObj
[
0
].
count
,
payCount
:
payObj
.
count
?
payObj
.
count
:
0
,
conversionRate
:
conversionRate
,
conversionRate
:
conversionRate
,
paySumCount
:
payObj
[
0
].
totalSum
,
paySumCount
:
payObj
.
totalSum
?
payObj
.
totalSum
:
0
,
parentProfit
:
payObj
[
0
].
parentProfit
,
parentProfit
:
payObj
.
parentProfit
?
payObj
.
parentProfit
:
0
,
grossProfit
:
payObj
[
0
].
grossProfit
grossProfit
:
payObj
.
grossProfit
?
payObj
.
grossProfit
:
0
}
var
result
=
system
.
getResultSuccess
(
resultObj
);
return
result
;
}
// 趋势分析
async
getTrend
(
pobj
,
actionBody
)
{
var
startTime
=
moment
().
subtract
(
1
,
"years"
).
format
(
"YYYY-MM-DD HH:mm:ss"
);
var
entTime
=
moment
().
format
(
"YYYY-MM-DD HH:mm:ss"
);
// date
var
monthList
=
[];
for
(
var
i
=
11
;
i
>=
0
;
i
--
)
{
monthList
.
push
(
moment
().
subtract
(
i
,
"month"
).
format
(
"YYYY-MM"
))
}
var
paramWhere
=
{
uappId
:
actionBody
.
uappId
,
startTime
:
startTime
,
entTime
:
entTime
}
// 根据月份分组需求订单
var
needListSql
=
"SELECT DATE_FORMAT(created_at, '%Y-%m') AS month,count(*) as count "
+
" FROM n_need_info where uapp_id=:uappId and created_at >=:startTime and created_at<=:entTime GROUP BY month"
var
needList
=
await
this
.
needInfoDao
.
customQuery
(
needListSql
,
paramWhere
);
// 根据月份分组支付订单
var
orderListSql
=
"SELECT DATE_FORMAT(created_at, '%Y-%m') AS month,count(*) as count "
+
" FROM c_order_info where orderStatus=2 and uapp_id=:uappId and created_at >=:startTime and created_at<=:entTime GROUP BY month"
var
orderList
=
await
this
.
customQuery
(
orderListSql
,
paramWhere
);
// 处理数据
for
(
var
i
=
0
;
i
<
monthList
.
length
;
i
++
)
{
var
needMonthList
=
[]
for
(
var
j
=
0
;
j
<
needList
.
length
;
j
++
)
{
needMonthList
.
push
(
needList
[
j
][
"month"
])
}
if
(
needMonthList
.
indexOf
(
monthList
[
i
])
<
0
)
{
var
obj
=
{
month
:
monthList
[
i
],
count
:
0
}
needList
.
push
(
obj
)
}
var
orderMonthList
=
[]
for
(
var
j
=
0
;
j
<
orderList
.
length
;
j
++
)
{
orderMonthList
.
push
(
orderList
[
j
][
"month"
])
}
if
(
orderMonthList
.
indexOf
(
monthList
[
i
])
<
0
)
{
var
obj
=
{
month
:
monthList
[
i
],
count
:
0
}
orderList
.
push
(
obj
)
}
}
function
sortByKey
(
array
,
key
)
{
return
array
.
sort
(
function
(
a
,
b
)
{
var
x
=
a
[
key
];
var
y
=
b
[
key
];
return
((
x
<
y
)
?
-
1
:
((
x
>
y
)
?
1
:
0
));
});
}
orderList
=
sortByKey
(
orderList
,
'month'
)
needList
=
sortByKey
(
needList
,
'month'
)
let
resultObj
=
{
date
:
monthList
,
pay
:
orderList
,
need
:
needList
}
}
var
result
=
system
.
getResultSuccess
(
resultObj
);
var
result
=
system
.
getResultSuccess
(
resultObj
);
return
result
;
return
result
;
}
}
// ----------------------------------------------uk运营后台 结束
}
}
module
.
exports
=
OrderInfoService
;
module
.
exports
=
OrderInfoService
;
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