Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
tl_estate
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
hujun
tl_estate
Commits
5313ac6c
Commit
5313ac6c
authored
Jun 24, 2019
by
zhuwei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
业绩排行
parent
ab1f0f33
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
461 additions
and
4 deletions
+461
-4
OfficePerformance.php
application/index/controller/OfficePerformance.php
+2
-4
OfficePerformanceService.php
application/index/service/OfficePerformanceService.php
+459
-0
No files found.
application/index/controller/OfficePerformance.php
View file @
5313ac6c
...
...
@@ -7,10 +7,8 @@ namespace app\index\controller;
* Time: 上午10:18
*/
use
app\index\extend\Basic
;
use
app\index\service\PerformanceService
;
use
app\index\untils\ExportExcelUntil
;
use
app\index\service\OfficePerformanceService
;
use
think\Request
;
use
\think\Session
;
class
OfficePerformance
extends
Basic
{
...
...
@@ -21,7 +19,7 @@ class OfficePerformance extends Basic
function
__construct
(
Request
$request
=
null
)
{
parent
::
__construct
(
$request
);
$this
->
service_
=
new
PerformanceService
();
$this
->
service_
=
new
Office
PerformanceService
();
$this
->
pageSize
=
20
;
}
...
...
application/index/service/OfficePerformanceService.php
0 → 100644
View file @
5313ac6c
<?php
namespace
app\index\service
;
use
app\index\untils\ExportExcelUntil
;
use
app\model\AAgents
;
use
app\model\ADistrict
;
use
app\model\AStore
;
use
app\model\GHouses
;
use
app\model\OBargainModel
;
use
app\model\OMarchInModel
;
use
app\model\OReportModel
;
use
app\model\TAgentTotalModel
;
use
app\model\Users
;
use
\think\Session
;
/**
* Created by PhpStorm.
* User: zhuwei
* Date: 2018/7/31
* Time: 上午11:03
*/
class
OfficePerformanceService
{
private
$totalModel
;
private
$agentModel
;
private
$storeModel
;
private
$districtModel
;
private
$houseModel
;
private
$userModel
;
private
$bargainModel
;
private
$reportModel
;
private
$marchInModel
;
public
function
__construct
()
{
$this
->
totalModel
=
new
TAgentTotalModel
();
$this
->
agentModel
=
new
AAgents
();
$this
->
houseModel
=
new
GHouses
();
$this
->
userModel
=
new
Users
();
$this
->
bargainModel
=
new
OBargainModel
();
$this
->
reportModel
=
new
OReportModel
();
$this
->
marchInModel
=
new
OMarchInModel
();
$this
->
districtModel
=
new
ADistrict
();
$this
->
storeModel
=
new
AStore
();
}
/**
* @param $agent_id
* @param $type
* @param $yesterday
* @param $end_day
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public
function
totalAgent
(
$type
,
$yesterday
,
$end_day
,
$pageNo
,
$pageSize
,
$father_id
,
$params
)
{
$order_
=
$params
[
'order'
];
$where_
=
[];
if
(
$father_id
){
if
(
$type
==
1
){
$where_
[
'a.store_id'
]
=
$father_id
;
}
elseif
(
$type
==
2
){
$where_
[
'a.district_id'
]
=
$father_id
;
}
}
if
(
!
empty
(
$params
[
'site_id'
]))
{
$where_
[
'd.site_id'
]
=
$params
[
'site_id'
];
}
//区域搜索条件
if
(
!
empty
(
$params
[
'district_id'
]))
{
$where_
[
'a.district_id'
]
=
$params
[
'district_id'
];
}
//部门搜索条件
if
(
!
empty
(
$params
[
'store_id'
]))
{
$where_
[
'a.store_id'
]
=
$params
[
'store_id'
];
}
//经纪人搜索条件
if
(
!
empty
(
$params
[
'agent_id'
]))
{
$where_
[
'a.agent_id'
]
=
$params
[
'agent_id'
];
}
$where_
[
'a.total_time'
]
=
array
(
'between'
,
array
(
$end_day
,
$yesterday
)
);
/* 成交报告数 bargain_sum
收款数 paylog
进场数 march_in_num
报备数 look_at_num
新增商铺数 add_house_num
新增客户数 add_user_num
团队人数 team_num*/
$field
=
"a.agent_id,a.store_id,a.district_id,
sum(a.performance) as performance_total,
sum(a.bargain_sum) as bargain_sum_total,
sum(a.paylog) as paylog_total,
sum(a.march_in_num) as march_in_num_total,
sum(a.look_at_num) as look_at_num_total,
sum(a.add_house_num) as add_house_num_total,
sum(a.followUp_sum) as followUp_sum_total,
sum(a.add_user_num) as add_user_num_total
"
;
//排序规则
$order
=
"performance_total "
.
$params
[
'order'
];
$result
=
$this
->
totalModel
->
getTotalByAgentIdForPcPerformance
(
$field
,
$where_
,
$type
,
$order
,
$pageSize
,
$pageNo
);
$total_result
=
$this
->
totalModel
->
getTotalByAgentIdForPcPerformanceTotal
(
$field
,
$where_
,
$type
);
/*计算总业绩*/
$field
=
"sum(performance) as performance_total"
;
$sum_result
=
$this
->
totalModel
->
getTotalByAgentIdForPcPerformanceSum
(
$field
,
$where_
,
$type
);
$sum_result_num
=
0
;
foreach
(
$sum_result
as
$k1
=>
$v1
)
{
$sum_result_num
+=
$v1
[
'performance_total'
];
}
/*计算总业绩 end*/
$arr
=
[];
$num
=
(
$pageNo
-
1
)
*
$pageSize
;
foreach
(
$result
as
$key
=>
$value
)
{
if
(
$order_
==
'desc'
)
{
$result
[
$key
][
"index_"
]
=
$key
+
1
+
$num
;
}
else
{
$result
[
$key
][
"index_"
]
=
$total_result
-
$key
-
$num
;
}
if
(
$type
==
1
)
{
#个人
$field
=
"a.name,b.store_name,c.district_name"
;
$agent_result
=
$this
->
agentModel
->
getAgentsInfoByAgentIdForPerformanceService
(
$field
,
[
"agent_id"
=>
$value
[
"agent_id"
]
]);
$result
[
$key
][
"name"
]
=
$agent_result
[
0
][
"name"
]
?
$agent_result
[
0
][
"name"
]
:
'未知'
;
$result
[
$key
][
"store_name"
]
=
$agent_result
[
0
][
"store_name"
]
?
$agent_result
[
0
][
"store_name"
]
:
'未知'
;
$result
[
$key
][
"district_name"
]
=
$agent_result
[
0
][
"district_name"
]
?
$agent_result
[
0
][
"district_name"
]
:
'未知'
;
}
elseif
(
$type
==
2
)
{
#门店
$store_params
[
'id'
]
=
$value
[
"store_id"
];
$store_field
=
'id,store_name'
;
$store_result
=
$this
->
storeModel
->
getStore
(
$store_params
,
$store_field
);
$result
[
$key
][
"store_name"
]
=
$store_result
[
0
][
"store_name"
]
?
$store_result
[
0
][
"store_name"
]
:
'未知'
;
//计算门店人数
$params
=
[];
$params
[
'store_id'
]
=
$value
[
"store_id"
];
$params
[
"status"
]
=
0
;
//只查询正常状态的经纪人
$result
[
$key
][
"team_num"
]
=
$this
->
agentModel
->
getAgentsCountByStoreId
(
$params
);
}
elseif
(
$type
==
3
)
{
#部门
$district_params
[
'id'
]
=
$value
[
"district_id"
];
$district_params
[
'status'
]
=
0
;
$district_field
=
'id,district_name'
;
$district_result
=
$this
->
districtModel
->
getDistrict
(
$district_params
,
$district_field
);
$result
[
$key
][
"district_name"
]
=
$district_result
[
0
][
"district_name"
]
?
$district_result
[
0
][
"district_name"
]
:
'未知'
;
//计算区域人数
$params_
=
[];
$params_
[
'district_id'
]
=
$value
[
"district_id"
];
$params_
[
"status"
]
=
0
;
//只查询正常状态的经纪人
$result
[
$key
][
"team_num"
]
=
$this
->
agentModel
->
getAgentsCountByStoreId
(
$params_
);
}
}
if
(
count
(
$arr
)
==
1
)
{
$agent_id
=
$arr
[
0
][
'agent_id'
];
//只有一条数据说明是经纪人个人业绩查询,将完整排名查下,将个人排名查出来
$ranking_num
=
$this
->
getRanking
(
$type
,
$yesterday
,
$end_day
,
$pageNo
,
$pageSize
,
$params
,
$agent_id
);
$result
[
0
][
'index_'
]
=
$ranking_num
;
}
return
[
'list'
=>
$result
,
'total'
=>
$total_result
,
'performance_total'
=>
$sum_result_num
];
}
/**
* 查询完整排名
* @param $type
* @param $yesterday
* @param $end_day
* @param $pageNo
* @param $pageSize
* @param $params
* @param string $agent_id
* @return int]
*/
public
function
getRanking
(
$type
,
$yesterday
,
$end_day
,
$pageNo
,
$pageSize
,
$params
,
$agent_id
)
{
$where_
=
[];
//区域搜索条件
if
(
!
empty
(
$params
[
'district_id'
]))
{
$where_
[
'district_id'
]
=
$params
[
'district_id'
];
}
//部门搜索条件
if
(
!
empty
(
$params
[
'store_id'
]))
{
$where_
[
'store_id'
]
=
$params
[
'store_id'
];
}
$where_
[
'total_time'
]
=
array
(
'between'
,
array
(
$end_day
,
$yesterday
)
);
/* 成交报告数 bargain_sum
收款数 paylog
进场数 march_in_num
报备数 look_at_num
新增商铺数 add_house_num
新增客户数 add_user_num
团队人数 team_num*/
$field
=
"agent_id,store_id,district_id,
sum(performance) as performance_total,
sum(bargain_sum) as bargain_sum_total,
sum(paylog) as paylog_total,
sum(march_in_num) as march_in_num_total,
sum(look_at_num) as look_at_num_total,
sum(add_house_num) as add_house_num_total,
sum(add_user_num) as add_user_num_total
"
;
//排序规则
$order
=
"performance_total "
.
$params
[
'order'
];
$result
=
$this
->
totalModel
->
getTotalByAgentId
(
$field
,
$where_
,
$type
,
$order
);
$arr
=
[];
$field
=
"a.name,a.img,b.store_name,c.district_name"
;
foreach
(
$result
as
$key
=>
$value
)
{
switch
(
$type
)
{
case
1
:
$value
[
"index_"
]
=
$key
+
1
;
$info
=
$this
->
agentModel
->
getAgentsInfoByAgentId
(
$field
,
[
"agent_id"
=>
$value
[
"agent_id"
]
]);
if
(
count
(
$info
)
>
0
)
{
$value
[
"name"
]
=
$info
[
0
][
"name"
];
$value
[
"img"
]
=
AGENTHEADERIMGURL
.
$info
[
0
][
"img"
];
$value
[
"store_name"
]
=
$info
[
0
][
"store_name"
];
$value
[
"district_name"
]
=
$info
[
0
][
"district_name"
];
array_push
(
$arr
,
$value
);
}
break
;
case
2
:
$value
[
"index_"
]
=
$key
+
1
;
$info
=
$this
->
agentModel
->
getAgentsInfoByAgentId
(
$field
,
[
"agent_id"
=>
$value
[
"agent_id"
],
""
]);
$store_name
=
$this
->
agentModel
->
getStoreOrDistrict
([
"store_id"
=>
$value
[
"store_id"
],
"level"
=>
20
]);
if
(
count
(
$info
)
>
0
)
{
$value
[
"name"
]
=
count
(
$store_name
)
>
0
?
$store_name
[
0
][
"name"
]
:
"---"
;
$value
[
"img"
]
=
AGENTHEADERIMGURL
.
$store_name
[
0
][
"img"
];
$value
[
"store_name"
]
=
$info
[
0
][
"store_name"
];
$value
[
"district_name"
]
=
$info
[
0
][
"district_name"
];
}
//计算门店人数
$params
=
[];
$params
[
'store_id'
]
=
$value
[
"store_id"
];
$params
[
"status"
]
=
0
;
//只查询正常状态的经纪人
$value
[
"team_num"
]
=
$this
->
agentModel
->
getAgentsCountByStoreId
(
$params
);
array_push
(
$arr
,
$value
);
break
;
case
3
:
$value
[
"index_"
]
=
$key
+
1
;
$info
=
$this
->
agentModel
->
getAgentsInfoByAgentId
(
$field
,
[
"agent_id"
=>
$value
[
"agent_id"
]
]);
$district_name
=
$this
->
agentModel
->
getStoreOrDistrict
([
"district_id"
=>
$value
[
"district_id"
],
"level"
=>
[
"in"
,
"30,40"
]
]);
if
(
count
(
$info
)
>
0
)
{
$value
[
"name"
]
=
count
(
$district_name
)
>
0
?
$district_name
[
0
][
"name"
]
:
"---"
;
$value
[
"img"
]
=
AGENTHEADERIMGURL
.
$district_name
[
0
][
"img"
];
$value
[
"store_name"
]
=
$info
[
0
][
"store_name"
];
$value
[
"district_name"
]
=
$info
[
0
][
"district_name"
];
}
//计算区域人数
$params
=
[];
$params
[
'district_id'
]
=
$value
[
"district_id"
];
$params
[
"status"
]
=
0
;
//只查询正常状态的经纪人
$value
[
"team_num"
]
=
$this
->
agentModel
->
getAgentsCountByStoreId
(
$params
);
array_push
(
$arr
,
$value
);
break
;
}
}
foreach
(
$arr
as
$k
=>
$v
)
{
if
(
$v
[
'agent_id'
]
==
$agent_id
){
return
$v
[
'index_'
];
}
}
return
1
;
}
/**
* 导出业绩excel
* @param $type
* @param $yesterday
* @param $end_day
* @param $father_id
* @return array
*/
public
function
totalAgentExcel
(
$type
,
$yesterday
,
$end_day
,
$father_id
,
$params
)
{
$where_
=
[];
$e_data_new
=
[];
if
(
$father_id
){
if
(
$type
==
1
){
$where_
[
'a.store_id'
]
=
$father_id
;
}
elseif
(
$type
==
2
){
$where_
[
'a.district_id'
]
=
$father_id
;
}
}
if
(
!
empty
(
$params
[
'site_id'
]))
{
$where_
[
'd.site_id'
]
=
$params
[
'site_id'
];
}
//区域搜索条件
if
(
!
empty
(
$params
[
'district_id'
]))
{
$where_
[
'a.district_id'
]
=
$params
[
'district_id'
];
}
//部门搜索条件
if
(
!
empty
(
$params
[
'store_id'
]))
{
$where_
[
'a.store_id'
]
=
$params
[
'store_id'
];
}
//经纪人搜索条件
if
(
!
empty
(
$params
[
'agent_id'
]))
{
$where_
[
'a.agent_id'
]
=
$params
[
'agent_id'
];
}
$where_
[
'a.total_time'
]
=
array
(
'between'
,
array
(
$end_day
,
$yesterday
)
);
/* 成交报告数 bargain_sum
收款数 paylog
进场数 march_in_num
报备数 look_at_num
新增商铺数 add_house_num
新增客户数 add_user_num
团队人数 team_num*/
$field
=
"a.agent_id,a.store_id,a.district_id,
sum(a.performance) as performance_total,
sum(a.bargain_sum) as bargain_sum_total,
sum(a.paylog) as paylog_total,
sum(a.march_in_num) as march_in_num_total,
sum(a.look_at_num) as look_at_num_total,
sum(a.add_house_num) as add_house_num_total,
sum(a.followUp_sum) as followUp_sum_total,
sum(a.add_user_num) as add_user_num_total"
;
$order
=
"performance_total desc"
;
$result
=
$this
->
totalModel
->
getTotalByAgentIdSite
(
$field
,
$where_
,
$type
,
$order
);
foreach
(
$result
as
$key
=>
$value
)
{
$result
[
$key
][
"index_"
]
=
$key
+
1
;
if
(
$type
==
1
)
{
#个人
$field
=
"a.name,b.store_name,c.district_name"
;
$agent_result
=
$this
->
agentModel
->
getAgentsInfoByAgentIdForPerformanceService
(
$field
,
[
"agent_id"
=>
$value
[
"agent_id"
]
]);
$result
[
$key
][
"name"
]
=
$agent_result
[
0
][
"name"
]
?
$agent_result
[
0
][
"name"
]
:
'未知'
;
$result
[
$key
][
"store_name"
]
=
$agent_result
[
0
][
"store_name"
]
?
$agent_result
[
0
][
"store_name"
]
:
'未知'
;
$result
[
$key
][
"district_name"
]
=
$agent_result
[
0
][
"district_name"
]
?
$agent_result
[
0
][
"district_name"
]
:
'未知'
;
}
elseif
(
$type
==
2
)
{
#门店
$store_params
[
'id'
]
=
$value
[
"store_id"
];
$store_field
=
'id,store_name'
;
$store_result
=
$this
->
storeModel
->
getStore
(
$store_params
,
$store_field
);
$result
[
$key
][
"store_name"
]
=
$store_result
[
0
][
"store_name"
]
?
$store_result
[
0
][
"store_name"
]
:
'未知'
;
//计算门店人数
$params
=
[];
$params
[
'store_id'
]
=
$value
[
"store_id"
];
$params
[
"status"
]
=
0
;
//只查询正常状态的经纪人
$result
[
$key
][
"team_num"
]
=
$this
->
agentModel
->
getAgentsCountByStoreId
(
$params
);
}
elseif
(
$type
==
3
)
{
#部门
$district_params
[
'id'
]
=
$value
[
"district_id"
];
$district_params
[
'status'
]
=
0
;
$district_field
=
'id,district_name'
;
$district_result
=
$this
->
districtModel
->
getDistrict
(
$district_params
,
$district_field
);
$result
[
$key
][
"district_name"
]
=
$district_result
[
0
][
"district_name"
]
?
$district_result
[
0
][
"district_name"
]
:
'未知'
;
//计算区域人数
$params_
=
[];
$params_
[
'district_id'
]
=
$value
[
"district_id"
];
$params_
[
"status"
]
=
0
;
//只查询正常状态的经纪人
$result
[
$key
][
"team_num"
]
=
$this
->
agentModel
->
getAgentsCountByStoreId
(
$params_
);
}
}
//dump(json_encode($where_));exit;
//return ['list'=>$arr,'total'=>0];
if
(
!
$result
){
exit
(
'暂无数据'
);
}
$export
=
new
ExportExcelUntil
();
foreach
(
$result
as
$key
=>
$v
)
{
$e_data_old
[
'index'
]
=
$v
[
"index_"
];
//排名
if
(
$type
==
1
)
{
$e_data_old
[
'store_name'
]
=
$v
[
'store_name'
];
//门店名
$e_data_old
[
'district_name'
]
=
$v
[
'name'
];
//个人
}
elseif
(
$type
==
2
)
{
$e_data_old
[
'district_name'
]
=
$v
[
'store_name'
];
//门店
}
else
{
$e_data_old
[
'district_name'
]
=
$v
[
'district_name'
];
//部门
}
if
(
$type
!=
1
)
{
$e_data_old
[
'team_num'
]
=
$v
[
'team_num'
];
//团队人数
}
$e_data_old
[
'followUp_sum_total'
]
=
$v
[
'followUp_sum_total'
];
//新增客户
$e_data_old
[
'add_user_num_total'
]
=
$v
[
'add_user_num_total'
];
//新增客户
$e_data_old
[
'add_house_num_total'
]
=
$v
[
'add_house_num_total'
];
//新增商铺
$e_data_old
[
'look_at_num_total'
]
=
$v
[
'look_at_num_total'
];
//报备数
$e_data_old
[
'march_in_num_total'
]
=
$v
[
'march_in_num_total'
];
//进场数
$e_data_old
[
'paylog_total'
]
=
$v
[
'paylog_total'
];
//收款数
$e_data_old
[
'bargain_sum_total'
]
=
$v
[
'bargain_sum_total'
];
//成交单数
$e_data_old
[
'performance_total'
]
=
$v
[
'performance_total'
];
//业绩
$e_data_new
[]
=
$e_data_old
;
}
// dump($e_data_new);exit;
$field_num
=
11
;
if
(
$type
==
1
){
$title
=
[
'排名'
,
'门店'
,
'个人'
,
'客源跟进'
,
'新增客户'
,
'新增商铺'
,
'报备数'
,
'进场数'
,
'收款数'
,
'成交单数'
,
'业绩'
];
$title2
=
'个人业绩排行表('
.
$end_day
.
'至'
.
$yesterday
.
')'
;
}
elseif
(
$type
==
2
){
$title
=
[
'排名'
,
'门店'
,
'团队人数'
,
'客源跟进'
,
'新增客户'
,
'新增商铺'
,
'报备数'
,
'进场数'
,
'收款数'
,
'成交单数'
,
'业绩'
];
$title2
=
'门店业绩排行表('
.
$end_day
.
'至'
.
$yesterday
.
')'
;
}
else
{
$title
=
[
'排名'
,
'部门'
,
'团队人数'
,
'客源跟进'
,
'新增客户'
,
'新增商铺'
,
'报备数'
,
'进场数'
,
'收款数'
,
'成交单数'
,
'业绩'
];
$title2
=
'部门业绩排行表('
.
$end_day
.
'至'
.
$yesterday
.
')'
;
}
$export
->
exportTable
(
'业绩排行'
,
$e_data_new
,
$field_num
,
$title2
,
$title
);
return
''
;
}
}
\ No newline at end of file
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