Commit d9506d69 authored by zhuwei's avatar zhuwei

pc后台业绩修改

parent acae14ae
......@@ -77,10 +77,8 @@ class Performance extends Basic
$end_day = !empty($params["end_day"]) ? $params["end_day"] : date("Y-m-d", time());
$father_id = !empty($params["father_id"]) ? $params["father_id"] : '' ;
//todo 业绩查询目前分三种情况
$search_time_type = $this->getSearchTimeType($start_day,$end_day);
$list = $this->service_->totalAgent($params["type"], $end_day, $start_day,$pageNo,$pageSize,$father_id,$search_time_type);
$list = $this->service_->totalAgent($params["type"], $end_day, $start_day,$pageNo,$pageSize,$father_id);
//dump($list);
if (count($list) > 0) {
$result["list"] = $list['list'];
......@@ -105,9 +103,8 @@ class Performance extends Basic
header('Access-Control-Allow-Origin:*');
$params = $this->params;
// $params = array(
// "type" => 2, //1表示个人业绩排行 2门店 3区域
// "father_id" => 4,
// // "start_day" =>"",
// "start_day" => '2018-08-08',
// "end_day" => '2018-08-08',
// );
$params["type"] = 2;
......@@ -118,11 +115,8 @@ class Performance extends Basic
$start_day = !empty($params["start_day"]) ? $params["start_day"] : date("Y-m-01", time());
$father_id = !empty($params["father_id"]) ? $params["father_id"] : '' ;
//todo 业绩查询目前分三种情况
$search_time_type = $this->getSearchTimeType($start_day,$end_day);
$list = $this->service_->totalAgent($params["type"], $end_day, $start_day,$pageNo,$pageSize,$father_id,$search_time_type);
//dump($list);
$list = $this->service_->totalAgent($params["type"], $end_day, $start_day,$pageNo,$pageSize,$father_id);
if (count($list) > 0) {
$result["list"] = $list['list'];
$result["total"] = $list['total'];
......@@ -161,10 +155,7 @@ class Performance extends Basic
$start_day = !empty($params["start_day"]) ? $params["start_day"] : date("Y-m-01", time());
$father_id = !empty($params["father_id"]) ? $params["father_id"] : '' ;
//todo 业绩查询目前分三种情况
$search_time_type = $this->getSearchTimeType($start_day,$end_day);
$list = $this->service_->totalAgent($params["type"], $end_day, $start_day,$pageNo,$pageSize,$father_id,$search_time_type);
$list = $this->service_->totalAgent($params["type"], $end_day, $start_day,$pageNo,$pageSize,$father_id);
//dump($list);
if (count($list) > 0) {
$result["list"] = $list['list'];
......
......@@ -51,7 +51,7 @@ class PerformanceService
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function totalAgent($type, $yesterday, $end_day,$pageNo,$pageSize,$father_id,$search_time_type)
public function totalAgent($type, $yesterday, $end_day,$father_id)
{
$where_ = [];
$where_['total_time'] = array( 'between', array( $end_day, $yesterday ) );
......@@ -63,37 +63,19 @@ class PerformanceService
}
}
//todo 成交报告数 bargain_sum
//todo 成交报告数其他 bargain_sum
//todo 收款数 paylog
//todo 进场数 march_in_num
//todo 报备数 look_at_num
//todo 新增商铺数 add_house_num
//todo 新增客户数 add_user_num
//todo 团队人数 team_num
$field = "
agent_id,
store_id,
district_id,sum(performance) as performance_total,
sum(bargain_sum) as bargain_sum_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
";
$where_ = [];
$where_['a.create_time'] = array( 'between', array( $end_day . " 00:00:00", $yesterday . " 23:59:59" ) );
$field = "b.id as agent_id,b.store_id,b.district_id,sum(a.scale_fee) as performance_total";
$order = "performance_total desc";
//dump($where_);
//dump($type);
$result = $this->totalModel->getTotalByAgentIdPage($pageNo,$pageSize,$field, $where_, $type, $order);
$result = $this->bargainModel->getTotalByAgentId($field, $where_, $type, $order);
$arr = [];
$total = $this->totalModel->getTotalByAgentIdCount($field, $where_, $type, $order);
// $total = $this->totalModel->getTotalByAgentIdCount($field, $where_, $type, $order);
// $field = "a.name,a.img,b.store_name,c.district_name";
$field = "a.name,a.img,b.store_name,c.district_name";
//dump($result);
foreach ($result as $key => $value) {
switch ($type) {
......@@ -106,93 +88,42 @@ class PerformanceService
$value["store_name"] = $info[0]["store_name"];
$value["district_name"] = $info[0]["district_name"];
//todo 1.今天之前,不包括今天
//todo 2.今天之前,包括今天
//todo 3.就只查询今天
if($search_time_type != 1){//如果不等于1,说明需要计算当天的数据,用不用再说
//todo 计算当日业绩 performance_total
$where_ = [];
$time = date("Y-m-d", time());
$where_ = [];
//$where_["district_id"] = $district_id;
$where_["agent_id"] = $value["agent_id"];
$where_['total_time'] = array( 'between', array( $time . " 00:00:00", $time . " 23:59:59" ) );
$obargain = new OBargainModel();
$performanceSum = $obargain->getAddBargainNum($where_, 1);//1表示业绩 2表示实收
if($search_time_type == 2){//如果等于2,说明需要把今天之前的数据跟今天的数据合并起来
//dump($search_time_type);
//dump('如果等于2,说明需要把今天之前的数据跟今天的数据合并起来');
$performance_total = isset($performanceSum[0]["num"]) ? $performanceSum[0]["num"] : 0;
$value["performance_total"] = $value["performance_total"] + $performance_total;
}else{
//dump($search_time_type);
//dump('只查询今天的数据');
$value["performance_total"] = isset($performanceSum[0]["num"]) ? $performanceSum[0]["num"] : 0;
}
$where_['create_time'] = array( 'between', array( $end_day . " 00:00:00", $yesterday . " 23:59:59" ) );
$obargain = new OBargainModel();
//dump($where_);
//todo 计算当日成交单数 bargain_sum
$performanceSum = $obargain->getAddBargainNum($where_, 3);//1表示业绩 2表示实收
$performanceSum = $obargain->getAddBargainNum($where_, 3);//1表示业绩 2表示实收
$value["bargain_sum_total"] = isset($performanceSum[0]["num"]) ? $performanceSum[0]["num"] : 0;
if($search_time_type == 2){
$bargain_sum_total = isset($performanceSum[0]["num"]) ? $performanceSum[0]["num"] : 0;
$value["bargain_sum_total"] = $value["bargain_sum_total"] + $bargain_sum_total;
}else{
$value["bargain_sum_total"] = isset($performanceSum[0]["num"]) ? $performanceSum[0]["num"] : 0;
}
//todo 计算当日收款数 paylog
$receivedSum = $this->bargainModel->getAddBargainNum($where_, 2);//1表示业绩 2表示实收
$receivedSum = $this->bargainModel->getAddBargainNum($where_, 2);//1表示业绩 2表示实收
$value["paylog_total"] = isset($receivedSum[0]["num"]) ? $receivedSum[0]["num"] : 0;
if($search_time_type == 2){
$paylog_total = isset($receivedSum[0]["num"]) ? $receivedSum[0]["num"] : 0;
$value["paylog_total"] = $value["paylog_total"] + $paylog_total;
}else{
$value["paylog_total"] = isset($receivedSum[0]["num"]) ? $receivedSum[0]["num"] : 0;
}
//todo 计算当日进场数 march_in_num
$addMarchInNum = $this->marchInModel->getAddMarchInNum($where_);
$addMarchInNum = $this->marchInModel->getAddMarchInNum($where_);
$value["march_in_num_total"] = isset($addMarchInNum[0]["num"]) ? $addMarchInNum[0]["num"] : 0;
if($search_time_type == 2){
$march_in_num_total = isset($addMarchInNum[0]["num"]) ? $addMarchInNum[0]["num"] : 0;
$value["march_in_num_total"] = $value["march_in_num_total"] + $march_in_num_total;
}else{
$value["march_in_num_total"] = isset($addMarchInNum[0]["num"]) ? $addMarchInNum[0]["num"] : 0;
}
//todo 计算当日报备数 look_at_num
$reportNum = $this->reportModel->getAddReportNum($where_);
$reportNum = $this->reportModel->getAddReportNum($where_);
$value["look_at_num_total"] = isset($reportNum[0]["num"]) ? $reportNum[0]["num"] : 0;
if($search_time_type == 2){
$look_at_num_total = isset($reportNum[0]["num"]) ? $reportNum[0]["num"] : 0;
$value["look_at_num_total"] = $value["look_at_num_total"] + $look_at_num_total;
}else{
$value["look_at_num_total"] = isset($reportNum[0]["num"]) ? $reportNum[0]["num"] : 0;
}
//todo 计算当日新增商铺数 add_house_num
$addHouseNum = $this->houseModel->getAddHouseNum($where_);
$addHouseNum = $this->houseModel->getAddHouseNum($where_);
$value["add_house_num_total"] = isset($addHouseNum[0]["num"]) ? $addHouseNum[0]["num"] : 0;
if($search_time_type == 2){
$add_house_num_total = isset($addHouseNum[0]["num"]) ? $addHouseNum[0]["num"] : 0;
$value["add_house_num_total"] = $value["add_house_num_total"] + $add_house_num_total;
}else{
$value["add_house_num_total"] = isset($addHouseNum[0]["num"]) ? $addHouseNum[0]["num"] : 0;
}
//todo 计算当日新增客户数 add_user_num
$addUserNum = $this->userModel->getAddUserNum($where_);
if($search_time_type == 2){
$add_user_num_total = isset($addUserNum[0]["num"]) ? $addUserNum[0]["num"] : 0;
$value["add_user_num_total"] = $value["add_user_num_total"] + $add_user_num_total;
}else{
$result["add_user_num_total"] = isset($addUserNum[0]["num"]) ? $addUserNum[0]["num"] : 0;
}
}
$addUserNum = $this->userModel->getAddUserNum($where_);
$result["add_user_num_total"] = isset($addUserNum[0]["num"]) ? $addUserNum[0]["num"] : 0;
array_push($arr, $value);
}
......@@ -207,17 +138,16 @@ class PerformanceService
$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);
if($search_time_type != 1) {//如果不等于1,说明需要计算当天的数据,用不用再说
//查询总监下面门店的所有经纪人
$params = [];
$params["store_id"] = $value["store_id"];
$params['store_id'] = $value["store_id"];
$params["status"] = 0; //只查询正常状态的经纪人
$agentsArr = $this->agentModel->getAgentsByStoreId($params);
$agent_total = count($agentsArr);
......@@ -231,99 +161,60 @@ class PerformanceService
//todo 计算当日业绩 performance_total
$where_ = [];
$time = date("Y-m-d", time());
//$where_["district_id"] = $district_id;
$where_["agent_id"] = array( "in", $agentIds );
$where_['create_time'] = array( 'between', array( $time . " 04:00:00", $time . " 23:59:59" ) );
$where_['create_time'] = array( 'between', array( $end_day . " 00:00:00", $yesterday . " 23:59:59" ) );
$obargain = new OBargainModel();
$performanceSum = $obargain->getAddBargainNum($where_, 1);//1表示业绩 2表示实收
if($search_time_type == 2){//如果等于2,说明需要把今天之前的数据跟今天的数据合并起来
//dump($search_time_type);
//dump('如果等于2,说明需要把今天之前的数据跟今天的数据合并起来');
$performance_total = isset($performanceSum[0]["num"]) ? $performanceSum[0]["num"] : 0;
$value["performance_total"] = $value["performance_total"] + $performance_total;
}else{
//dump($search_time_type);
//dump('只查询今天的数据');
$value["performance_total"] = isset($performanceSum[0]["num"]) ? $performanceSum[0]["num"] : 0;
}
//dump($where_);
//todo 计算当日成交单数 bargain_sum
$performanceSum = $obargain->getAddBargainNum($where_, 3);//1表示业绩 2表示实收
if($search_time_type == 2){
$bargain_sum_total = isset($performanceSum[0]["num"]) ? $performanceSum[0]["num"] : 0;
$value["bargain_sum_total"] = $value["bargain_sum_total"] + $bargain_sum_total;
}else{
$value["bargain_sum_total"] = isset($performanceSum[0]["num"]) ? $performanceSum[0]["num"] : 0;
}
$value["bargain_sum_total"] = isset($performanceSum[0]["num"]) ? $performanceSum[0]["num"] : 0;
//todo 计算当日收款数 paylog
$receivedSum = $this->bargainModel->getAddBargainNum($where_, 2);//1表示业绩 2表示实收
if($search_time_type == 2){
$paylog_total = isset($receivedSum[0]["num"]) ? $receivedSum[0]["num"] : 0;
$value["paylog_total"] = $value["paylog_total"] + $paylog_total;
}else{
$value["paylog_total"] = isset($receivedSum[0]["num"]) ? $receivedSum[0]["num"] : 0;
}
$value["paylog_total"] = isset($receivedSum[0]["num"]) ? $receivedSum[0]["num"] : 0;
//todo 计算当日进场数 march_in_num
$addMarchInNum = $this->marchInModel->getAddMarchInNum($where_);
if($search_time_type == 2){
$march_in_num_total = isset($addMarchInNum[0]["num"]) ? $addMarchInNum[0]["num"] : 0;
$value["march_in_num_total"] = $value["march_in_num_total"] + $march_in_num_total;
}else{
$value["march_in_num_total"] = isset($addMarchInNum[0]["num"]) ? $addMarchInNum[0]["num"] : 0;
$value["march_in_num_total"] = isset($addMarchInNum[0]["num"]) ? $addMarchInNum[0]["num"] : 0;
}
//todo 计算当日报备数 look_at_num
$reportNum = $this->reportModel->getAddReportNum($where_);
if($search_time_type == 2){
$look_at_num_total = isset($reportNum[0]["num"]) ? $reportNum[0]["num"] : 0;
$value["look_at_num_total"] = $value["look_at_num_total"] + $look_at_num_total;
}else{
$value["look_at_num_total"] = isset($reportNum[0]["num"]) ? $reportNum[0]["num"] : 0;
}
$value["look_at_num_total"] = isset($reportNum[0]["num"]) ? $reportNum[0]["num"] : 0;
//todo 计算当日新增商铺数 add_house_num
$addHouseNum = $this->houseModel->getAddHouseNum($where_);
if($search_time_type == 2){
$add_house_num_total = isset($addHouseNum[0]["num"]) ? $addHouseNum[0]["num"] : 0;
$value["add_house_num_total"] = $value["add_house_num_total"] + $add_house_num_total;
}else{
$value["add_house_num_total"] = isset($addHouseNum[0]["num"]) ? $addHouseNum[0]["num"] : 0;
}
$value["add_house_num_total"] = isset($addHouseNum[0]["num"]) ? $addHouseNum[0]["num"] : 0;
//todo 计算当日新增客户数 add_user_num
$addUserNum = $this->userModel->getAddUserNum($where_);
if($search_time_type == 2){
$add_user_num_total = isset($addUserNum[0]["num"]) ? $addUserNum[0]["num"] : 0;
$value["add_user_num_total"] = $value["add_user_num_total"] + $add_user_num_total;
}else{
$result["add_user_num_total"] = isset($addUserNum[0]["num"]) ? $addUserNum[0]["num"] : 0;
}
$value["add_user_num_total"] = isset($addUserNum[0]["num"]) ? $addUserNum[0]["num"] : 0;
}
//dump($value);
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);
//dump($search_time_type);
if($search_time_type != 1) {//如果不等于1,说明需要计算当天的数据,用不用再说
$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);
//查询总监下面门店的所有经纪人
$params = [];
......@@ -339,87 +230,48 @@ class PerformanceService
$agentIds = rtrim($agentIds, ",");//经纪人ID集合
}//查询总监下面门店的所有经纪人 end
//todo 计算当日业绩 performance_total
$where_ = [];
$time = date("Y-m-d", time());
//$where_["district_id"] = $district_id;
$where_["agent_id"] = array( "in", $agentIds );
$where_['create_time'] = array( 'between', array( $time . " 04:00:00", $time . " 23:59:59" ) );
$where_['create_time'] = array( 'between', array( $end_day . " 00:00:00", $yesterday . " 23:59:59" ) );
$obargain = new OBargainModel();
$performanceSum = $obargain->getAddBargainNum($where_, 1);//1表示业绩 2表示实收
if($search_time_type == 2){//如果等于2,说明需要把今天之前的数据跟今天的数据合并起来
//dump($search_time_type);
//dump('如果等于2,说明需要把今天之前的数据跟今天的数据合并起来');
$performance_total = isset($performanceSum[0]["num"]) ? $performanceSum[0]["num"] : 0;
$value["performance_total"] = $value["performance_total"] + $performance_total;
}else{
//dump($search_time_type);
//dump('只查询今天的数据');
$value["performance_total"] = isset($performanceSum[0]["num"]) ? $performanceSum[0]["num"] : 0;
}
//todo 计算当日成交单数 bargain_sum
$performanceSum = $obargain->getAddBargainNum($where_, 3);//1表示业绩 2表示实收
if($search_time_type == 2){
$bargain_sum_total = isset($performanceSum[0]["num"]) ? $performanceSum[0]["num"] : 0;
$value["bargain_sum_total"] = $value["bargain_sum_total"] + $bargain_sum_total;
}else{
$value["bargain_sum_total"] = isset($performanceSum[0]["num"]) ? $performanceSum[0]["num"] : 0;
}
$value["bargain_sum_total"] = isset($performanceSum[0]["num"]) ? $performanceSum[0]["num"] : 0;
//todo 计算当日收款数 paylog
$receivedSum = $this->bargainModel->getAddBargainNum($where_, 2);//1表示业绩 2表示实收
if($search_time_type == 2){
$paylog_total = isset($receivedSum[0]["num"]) ? $receivedSum[0]["num"] : 0;
$value["paylog_total"] = $value["paylog_total"] + $paylog_total;
}else{
$value["paylog_total"] = isset($receivedSum[0]["num"]) ? $receivedSum[0]["num"] : 0;
}
$value["paylog_total"] = isset($receivedSum[0]["num"]) ? $receivedSum[0]["num"] : 0;
//todo 计算当日进场数 march_in_num
$addMarchInNum = $this->marchInModel->getAddMarchInNum($where_);
if($search_time_type == 2){
$march_in_num_total = isset($addMarchInNum[0]["num"]) ? $addMarchInNum[0]["num"] : 0;
$value["march_in_num_total"] = $value["march_in_num_total"] + $march_in_num_total;
}else{
$value["march_in_num_total"] = isset($addMarchInNum[0]["num"]) ? $addMarchInNum[0]["num"] : 0;
$value["march_in_num_total"] = isset($addMarchInNum[0]["num"]) ? $addMarchInNum[0]["num"] : 0;
}
//todo 计算当日报备数 look_at_num
$reportNum = $this->reportModel->getAddReportNum($where_);
if($search_time_type == 2){
$look_at_num_total = isset($reportNum[0]["num"]) ? $reportNum[0]["num"] : 0;
$value["look_at_num_total"] = $value["look_at_num_total"] + $look_at_num_total;
}else{
$value["look_at_num_total"] = isset($reportNum[0]["num"]) ? $reportNum[0]["num"] : 0;
}
$value["look_at_num_total"] = isset($reportNum[0]["num"]) ? $reportNum[0]["num"] : 0;
//todo 计算当日新增商铺数 add_house_num
$addHouseNum = $this->houseModel->getAddHouseNum($where_);
if($search_time_type == 2){
$add_house_num_total = isset($addHouseNum[0]["num"]) ? $addHouseNum[0]["num"] : 0;
$value["add_house_num_total"] = $value["add_house_num_total"] + $add_house_num_total;
}else{
$value["add_house_num_total"] = isset($addHouseNum[0]["num"]) ? $addHouseNum[0]["num"] : 0;
}
$value["add_house_num_total"] = isset($addHouseNum[0]["num"]) ? $addHouseNum[0]["num"] : 0;
//todo 计算当日新增客户数 add_user_num
$addUserNum = $this->userModel->getAddUserNum($where_);
if($search_time_type == 2){
$add_user_num_total = isset($addUserNum[0]["num"]) ? $addUserNum[0]["num"] : 0;
$value["add_user_num_total"] = $value["add_user_num_total"] + $add_user_num_total;
}else{
$result["add_user_num_total"] = isset($addUserNum[0]["num"]) ? $addUserNum[0]["num"] : 0;
}
}
array_push($arr, $value);
$result["add_user_num_total"] = isset($addUserNum[0]["num"]) ? $addUserNum[0]["num"] : 0;
array_push($arr, $value);
break;
}
}
return ['list'=>$arr,'total'=>$total];
//dump($arr);exit;
return ['list'=>$arr,'total'=>0];
}
......
......@@ -491,7 +491,7 @@ Route::group('broker', [
'agentPerformanceBySearch' => [ 'api_broker/Performance/agentPerformanceBySearch', [ 'method' => 'get' ] ],
'orderNoList' => [ 'api_broker/Performance/orderNoList', [ 'method' => 'get' ] ],
'storePerformanceBySearch' => [ 'api_broker/Performance/storePerformanceBySearch', [ 'method' => 'get' ] ],
'storeOrAgentSort' => [ 'api_broker/Performance/storeOrAgentSort', [ 'method' => 'get' ] ],
'storeOrAgentSort' => [ 'api_broker/Performance/storeOrAgentSort', [ 'method' => 'get|post' ] ],
'weekWorkImg' => [ 'api_broker/Statement/weekWorkImg', [ 'method' => 'post' ] ], //生成周报和日报图片
'setReportContent' => [ 'api_broker/Statement/setReportContent', [ 'method' => 'get|post' ] ], //保存日报周报四个字段
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment