Commit a61c63be authored by zhuwei's avatar zhuwei

业绩日报周报重写

parent 4948c360
...@@ -4,6 +4,7 @@ namespace app\api_broker\controller; ...@@ -4,6 +4,7 @@ namespace app\api_broker\controller;
use app\api_broker\extend\Basic; use app\api_broker\extend\Basic;
use app\api_broker\service\StatementService; use app\api_broker\service\StatementService;
use app\model\AAgents;
use app\model\RAgentNote; use app\model\RAgentNote;
use app\model\RAgentReport; use app\model\RAgentReport;
use think\Exception; use think\Exception;
...@@ -37,11 +38,17 @@ class Statement extends Basic ...@@ -37,11 +38,17 @@ class Statement extends Basic
header('Access-Control-Allow-Origin:*'); header('Access-Control-Allow-Origin:*');
$params = $this->params; $params = $this->params;
Log::write($params, 'zhuwei'); //记录日志
/*$params = array( /*$params = array(
"agent_id" => 3742,//5739 总监 5740店长 "agent_id" => 3742,//5739 总监 5740店长
"time_start" => date("Y-m-d", time()), "time_start" => date("Y-m-d", time()),
"time_end" => date("Y-m-d", time()), "time_end" => date("Y-m-d", time()),
);*/ );*/
$params = array (
'agent_id' => '5739',
'time_start' => '2018-11-23',
'time_end' => '2018-11-23',
);
if (!isset($params["agent_id"]) || !isset($params["time_start"]) || !isset($params["time_end"])) { if (!isset($params["agent_id"]) || !isset($params["time_start"]) || !isset($params["time_end"])) {
return $this->response("101", "请求参数错误"); return $this->response("101", "请求参数错误");
...@@ -208,20 +215,52 @@ class Statement extends Basic ...@@ -208,20 +215,52 @@ class Statement extends Basic
header('Access-Control-Allow-Origin:*'); header('Access-Control-Allow-Origin:*');
$params = $this->params; $params = $this->params;
/*$params = array( /*$params = array(
"agent_id" => 3742,//5739 总监 5740店长 "agent_id" => 5739,//5739 总监 5740店长
"time_start" => date("Y-m-d", time()), "day_or_week" => 0,//0 日报 1 周报
"time_end" => date("Y-m-d", time()),
);*/ );*/
if (!isset($params["agent_id"]) || !isset($params["time_start"]) || !isset($params["time_end"])) { if (!isset($params["agent_id"]) || !isset($params["time_start"]) || !isset($params["time_end"])) {
return $this->response("101", "请求参数错误"); return $this->response("101", "请求参数错误");
} }
$day_or_week = $params["time_start"] == $params["time_end"] ? 'day' : 'week'; #当前登录人角色 0经纪人 1店长 2总监
$time_end = $params["time_end"] . " 23:59:59"; $field = "id,store_id,district_id,level,name,phone,sex,status";
$result = $this->service_->selectStatementByAgentId($params["agent_id"], $params["time_start"], $time_end,$day_or_week); $agentModel = new AAgents();
$agent_result = $agentModel->getAgentById($field, [ "agent_id" => $params["agent_id"] ]);
if(!$agent_result){
return $this->response("200", "request is null");
}
$store_id = $agent_result[0]["store_id"];
$district_id = $agent_result[0]["district_id"];
if ($agent_result[0]["level"] == 10) {
//todo 业务员 Clerk
$agent_level = 0;
$result = $this->service_->selectStatementForClerk($params["agent_id"], $agent_level, $store_id,$district_id);
} elseif ($agent_result[0]["level"] == 20) {
//todo 1店长
$agent_level = 1;
if($params["day_or_week"] == 0 ){
//todo 日报
}else{
//todo 周报
}
} else {
//todo 2总监
$agent_level = 2;
if($params["day_or_week"] == 0 ){
//todo 日报
}else{
//todo 周报
}
}
if (count($result) > 0) { if ($result) {
return $this->response("200", "request success", $result); return $this->response("200", "request success", $result);
} else { } else {
return $this->response("200", "request is null"); return $this->response("200", "request is null");
......
...@@ -28,6 +28,7 @@ class StatementService ...@@ -28,6 +28,7 @@ class StatementService
private $followUpModel; private $followUpModel;
private $reportModel; private $reportModel;
private $marchInModel; private $marchInModel;
private $bargainModel;
const USER_LEVEL_FIST = 0; //经纪人 const USER_LEVEL_FIST = 0; //经纪人
const USER_LEVEL_SECOND = 1; //店长 const USER_LEVEL_SECOND = 1; //店长
...@@ -42,6 +43,8 @@ class StatementService ...@@ -42,6 +43,8 @@ class StatementService
$this->followUpModel = new FollowUpLogModel(); $this->followUpModel = new FollowUpLogModel();
$this->reportModel = new OReportModel(); $this->reportModel = new OReportModel();
$this->marchInModel = new OMarchInModel(); $this->marchInModel = new OMarchInModel();
$this->bargainModel = new OBargainModel();
} }
/** /**
...@@ -143,7 +146,7 @@ class StatementService ...@@ -143,7 +146,7 @@ class StatementService
$result["agent_total"] = $agent_total; $result["agent_total"] = $agent_total;
$result["house_num"] = $this->housesToAgents->getAddHouseNumByAgentId($conditions); $result["house_num"] = $this->housesToAgents->getAddHouseNumByAgentId($conditions);
//dump($conditions); dump($conditions);
$result["user_num"] = $this->userModel->getAddUserNumByAgentId($conditions); $result["user_num"] = $this->userModel->getAddUserNumByAgentId($conditions);
//dump($conditions); //dump($conditions);
//本周带看(报备) //本周带看(报备)
...@@ -163,15 +166,15 @@ class StatementService ...@@ -163,15 +166,15 @@ class StatementService
$where_['create_time'] = array( 'between', array( $start_time . " 00:00:00", $end_time . " 23:59:59" ) ); $where_['create_time'] = array( 'between', array( $start_time . " 00:00:00", $end_time . " 23:59:59" ) );
$where_['status'] =array( "in", '10, 11, 13, 20' ); $where_['status'] =array( "in", '10, 11, 13, 20' );
$obargain = new OBargainModel(); // $obargain = new OBargainModel();
$performanceSum = $obargain->getAddBargainNum($where_, 1);//1表示业绩 2表示实收 $performanceSum = $this->bargainModel->getAddBargainNum($where_, 1);//1表示业绩 2表示实收
$result["performance_month"] = isset($performanceSum[0]["num"]) ? $performanceSum[0]["num"] : 0; $result["performance_month"] = isset($performanceSum[0]["num"]) ? $performanceSum[0]["num"] : 0;
//本周业绩 //本周业绩
$start_time = date("Y-m-d", strtotime("-7 day")); $start_time = date("Y-m-d", strtotime("-7 day"));
$where_['create_time'] = $conditions['create_time']; $where_['create_time'] = $conditions['create_time'];
$performanceSum = $obargain->getAddBargainNum($where_, 1);//1表示业绩 2表示实收 $performanceSum = $this->bargainModel->getAddBargainNum($where_, 1);//1表示业绩 2表示实收
$result["performance_week"] = isset($performanceSum[0]["num"]) ? $performanceSum[0]["num"] : 0; $result["performance_week"] = isset($performanceSum[0]["num"]) ? $performanceSum[0]["num"] : 0;
//本周客源 //本周客源
...@@ -192,7 +195,7 @@ class StatementService ...@@ -192,7 +195,7 @@ class StatementService
} }
$where_['create_time'] = array( 'between', array( $start_time . " 00:00:00", $end_time . " 23:59:59" ) ); $where_['create_time'] = array( 'between', array( $start_time . " 00:00:00", $end_time . " 23:59:59" ) );
$performanceSum = $obargain->getAddBargainNumV2($where_, 3);//1表示业绩 2表示实收 $performanceSum = $this->bargainModel->getAddBargainNumV2($where_, 3);//1表示业绩 2表示实收
//dump($where_);exit; //dump($where_);exit;
$result["bargain_sum"] = isset($performanceSum[0]["num"]) ? $performanceSum[0]["num"] : 0; $result["bargain_sum"] = isset($performanceSum[0]["num"]) ? $performanceSum[0]["num"] : 0;
...@@ -211,7 +214,7 @@ class StatementService ...@@ -211,7 +214,7 @@ class StatementService
$where_["agent_id"] = array( "in", $agentIds ); $where_["agent_id"] = array( "in", $agentIds );
} }
$where_['create_time'] = array( 'between', array( $start_time . " 00:00:00", $end_time . " 23:59:59" ) ); $where_['create_time'] = array( 'between', array( $start_time . " 00:00:00", $end_time . " 23:59:59" ) );
$performanceSum = $obargain->getAddBargainNum($where_, 1);//1表示业绩 2表示实收 $performanceSum = $this->bargainModel->getAddBargainNum($where_, 1);//1表示业绩 2表示实收
$result["performance_day"] = isset($performanceSum[0]["num"]) ? $performanceSum[0]["num"] : 0; $result["performance_day"] = isset($performanceSum[0]["num"]) ? $performanceSum[0]["num"] : 0;
...@@ -229,7 +232,7 @@ class StatementService ...@@ -229,7 +232,7 @@ class StatementService
$where_["agent_id"] = $agent_id; $where_["agent_id"] = $agent_id;
$where_['create_time'] = array( 'between', array( $start_time . " 00:00:00", $end_time . " 23:59:59" ) ); $where_['create_time'] = array( 'between', array( $start_time . " 00:00:00", $end_time . " 23:59:59" ) );
// dump($where_); // dump($where_);
$performanceSum = $obargain->getAddBargainNum($where_, 3);//1表示业绩 2表示实收 $performanceSum = $this->bargainModel->getAddBargainNum($where_, 3);//1表示业绩 2表示实收
$result["bargain_sum_store"] = isset($performanceSum[0]["num"]) ? $performanceSum[0]["num"] : 0; $result["bargain_sum_store"] = isset($performanceSum[0]["num"]) ? $performanceSum[0]["num"] : 0;
...@@ -262,8 +265,8 @@ class StatementService ...@@ -262,8 +265,8 @@ class StatementService
//$where_["district_id"] = $district_id; //$where_["district_id"] = $district_id;
$where_["agent_id"] = $conditions["agent_id"]; $where_["agent_id"] = $conditions["agent_id"];
$where_['create_time'] = array( 'between', array( $start_time . " 00:00:00", $end_time . " 23:59:59" ) ); $where_['create_time'] = array( 'between', array( $start_time . " 00:00:00", $end_time . " 23:59:59" ) );
$obargain = new OBargainModel(); // $obargain = new OBargainModel();
$performanceSum = $obargain->getAddBargainNum($where_, 1);//1表示业绩 2表示实收 $performanceSum = $this->bargainModel->getAddBargainNum($where_, 1);//1表示业绩 2表示实收
$result["director_performance_month"] = isset($performanceSum[0]["num"]) ? $performanceSum[0]["num"] : 0; $result["director_performance_month"] = isset($performanceSum[0]["num"]) ? $performanceSum[0]["num"] : 0;
//todo 完成单数 //todo 完成单数
...@@ -275,7 +278,7 @@ class StatementService ...@@ -275,7 +278,7 @@ class StatementService
$where_['create_time'] = array( 'between', array( $start_time . " 00:00:00", $end_time . " 23:59:59" ) ); $where_['create_time'] = array( 'between', array( $start_time . " 00:00:00", $end_time . " 23:59:59" ) );
$performanceSum = $obargain->getAddBargainNumV2($where_, 3);//1表示业绩 2表示实收 $performanceSum = $this->bargainModel->getAddBargainNumV2($where_, 3);//1表示业绩 2表示实收
$result["director_bargain_sum_store"] = isset($performanceSum[0]["num"]) ? $performanceSum[0]["num"] : 0; $result["director_bargain_sum_store"] = isset($performanceSum[0]["num"]) ? $performanceSum[0]["num"] : 0;
} else {//周报 } else {//周报
...@@ -287,8 +290,8 @@ class StatementService ...@@ -287,8 +290,8 @@ class StatementService
$where_["agent_id"] = $conditions["agent_id"]; $where_["agent_id"] = $conditions["agent_id"];
$where_['create_time'] = array( 'between', array( $start_time . " 00:00:00", $end_time . " 23:59:59" ) ); $where_['create_time'] = array( 'between', array( $start_time . " 00:00:00", $end_time . " 23:59:59" ) );
$obargain = new OBargainModel(); // $obargain = new OBargainModel();
$performanceSum = $obargain->getAddBargainNum($where_, 1);//1表示业绩 2表示实收 $performanceSum = $this->bargainModel->getAddBargainNum($where_, 1);//1表示业绩 2表示实收
$result["director_performance_month"] = isset($performanceSum[0]["num"]) ? $performanceSum[0]["num"] : 0; $result["director_performance_month"] = isset($performanceSum[0]["num"]) ? $performanceSum[0]["num"] : 0;
//todo 上周业绩 //todo 上周业绩
...@@ -298,9 +301,9 @@ class StatementService ...@@ -298,9 +301,9 @@ class StatementService
// $where_["district_id"] = $district_id; // $where_["district_id"] = $district_id;
$where_["agent_id"] = $conditions["agent_id"]; $where_["agent_id"] = $conditions["agent_id"];
$where_['create_time'] = array( 'between', array( $start_time . " 00:00:00", $end_time . " 23:59:59" ) ); $where_['create_time'] = array( 'between', array( $start_time . " 00:00:00", $end_time . " 23:59:59" ) );
$obargain = new OBargainModel(); // $obargain = new OBargainModel();
$performanceSum = $obargain->getAddBargainNum($where_, 1);//1表示业绩 2表示实收 $performanceSum = $this->bargainModel->getAddBargainNum($where_, 1);//1表示业绩 2表示实收
$result["director_last_week_performance_num"] = isset($performanceSum[0]["num"]) ? $performanceSum[0]["num"] : 0; $result["director_last_week_performance_num"] = isset($performanceSum[0]["num"]) ? $performanceSum[0]["num"] : 0;
//todo 本周周业绩 //todo 本周周业绩
$where_ = []; $where_ = [];
...@@ -309,9 +312,9 @@ class StatementService ...@@ -309,9 +312,9 @@ class StatementService
// $where_["district_id"] = $district_id; // $where_["district_id"] = $district_id;
$where_["agent_id"] = $conditions["agent_id"]; $where_["agent_id"] = $conditions["agent_id"];
$where_['create_time'] = array( 'between', array( $start_time . " 00:00:00", $end_time . " 23:59:59" ) ); $where_['create_time'] = array( 'between', array( $start_time . " 00:00:00", $end_time . " 23:59:59" ) );
$obargain = new OBargainModel(); // $obargain = new OBargainModel();
$performanceSum = $obargain->getAddBargainNum($where_, 1);//1表示业绩 2表示实收 $performanceSum = $this->bargainModel->getAddBargainNum($where_, 1);//1表示业绩 2表示实收
$result["director_week_performance_num"] = isset($performanceSum[0]["num"]) ? $performanceSum[0]["num"] : 0; $result["director_week_performance_num"] = isset($performanceSum[0]["num"]) ? $performanceSum[0]["num"] : 0;
// 本月业绩 // 本月业绩
//todo 本月完成单数 //todo 本月完成单数
...@@ -323,7 +326,7 @@ class StatementService ...@@ -323,7 +326,7 @@ class StatementService
$where_['create_time'] = array( 'between', array( $start_time . " 00:00:00", $end_time . " 23:59:59" ) ); $where_['create_time'] = array( 'between', array( $start_time . " 00:00:00", $end_time . " 23:59:59" ) );
$performanceSum = $obargain->getAddBargainNumV2($where_, 3);//1表示业绩 2表示实收 $performanceSum = $this->bargainModel->getAddBargainNumV2($where_, 3);//1表示业绩 2表示实收
$result["director_bargain_sum_store"] = isset($performanceSum[0]["num"]) ? $performanceSum[0]["num"] : 0; $result["director_bargain_sum_store"] = isset($performanceSum[0]["num"]) ? $performanceSum[0]["num"] : 0;
//todo 上周人数 //todo 上周人数
$start_time = date("Y-m-d", strtotime("-14 day")); $start_time = date("Y-m-d", strtotime("-14 day"));
...@@ -540,4 +543,52 @@ class StatementService ...@@ -540,4 +543,52 @@ class StatementService
} }
/**
* 查询业务员日报数据
* @param $agent_id
* @param $agent_level
* @param $store_id
* @param $district_id
* user 朱伟
* time 2018-11-23 11:15:02
*/
public function selectStatementForClerk($agent_id, $agent_level, $store_id,$district_id)
{
$start_time = date("Y-m-01", time());
$end_time = date("Y-m-d", time());
$conditions['agent_id']=$agent_id;
$conditions['create_time'] = array( 'between', array( $start_time . " 00:00:00", $end_time . " 23:59:59" ) );
//todo 房源
$result["house_num"] = $this->housesToAgents->getAddHouseNumByAgentId($conditions);
//todo 客源
$result["user_num"] = $this->userModel->getAddUserNumByAgentId($conditions);
//todo 带看 (报备)
$addMarchInNum = $this->marchInModel->getAddMarchInNum($conditions);
$result["follow_up_num"] = isset($addMarchInNum[0]["num"]) ? $addMarchInNum[0]["num"] : 0;
//todo 业绩
$performanceSum = $this->bargainModel->getAddBargainNum($conditions, 1);//1表示业绩 2表示实收
$result["performance"] = isset($performanceSum[0]["num"]) ? $performanceSum[0]["num"] : 0;
//todo 本月-业绩
$start_time = date("Y-m-01", time());
$end_time = date("Y-m-d", time());
$conditions['create_time'] = array( 'between', array( $start_time . " 00:00:00", $end_time . " 23:59:59" ) );
$performanceSum = $this->bargainModel->getAddBargainNum($conditions, 1);//1表示业绩 2表示实收
$result["director_performance_month"] = isset($performanceSum[0]["num"]) ? $performanceSum[0]["num"] : 0;
//todo 本月-成交单数
$performanceSum = $this->bargainModel->getAddBargainNumV2($conditions, 3);//1表示业绩 2表示实收
//dump($where_);exit;
$result["bargain_sum"] = isset($performanceSum[0]["num"]) ? $performanceSum[0]["num"] : 0;
return $result;
}
} }
\ No newline at end of file
...@@ -706,6 +706,10 @@ Route::group('broker', [ ...@@ -706,6 +706,10 @@ Route::group('broker', [
'getVolume' => [ 'api_broker/SpreadUser/getVolume', [ 'method' => 'get' ] ], 'getVolume' => [ 'api_broker/SpreadUser/getVolume', [ 'method' => 'get' ] ],
'getHouseAddress' => [ 'api_broker/shop/getHouseAddress', [ 'method' => 'get' ] ] //搜索商铺地址 'getHouseAddress' => [ 'api_broker/shop/getHouseAddress', [ 'method' => 'get' ] ] //搜索商铺地址
//业绩日报周报重写
'dayStatement' => ['api_broker/Statement/dayStatement', ['method' => 'get|post']],
]); ]);
//Route::miss('api/index/miss');//处理错误的url //Route::miss('api/index/miss');//处理错误的url
\ No newline at end of file
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