Commit 3471ac49 authored by clone's avatar clone

业绩

parent ba20d46e
......@@ -146,4 +146,24 @@ class Performance extends Basic
}
}
public function storeOrAgentSort(){
$params = $this->params;
$params = array(
"agent_id" => 1,
"start_time" => "2018-03-10",
"end_time" => "2018-03-23",
);
if (!isset($params["agent_id"]) || !isset($params["start_time"]) || !isset($params["end_time"])) {
return $this->response("101", "请求参数错误");
}
try {
$result = $this->service_->storeSortByDistrictId($params["agent_id"], $params["start_time"], $params["end_time"]);
return $this->response("200", "request success", $result);
} catch (Exception $exception) {
return $this->response("101", "request error,msg:" . $exception);
}
}
}
......@@ -65,7 +65,9 @@ class PerformanceService
$where_['total_time'] = array( 'between', array( $end_day, $yesterday ) );
$result = $this->totalModel->getTotalByAgentId($where_, $type);
$field = "agent_id,store_id,district_id,sum(performance) as performance_total";
$order = "performance_total desc";
$result = $this->totalModel->getTotalByAgentId($field, $where_, $type, $order);
//dump($result);
$arr = [];
$field = "a.name,a.img,b.store_name,c.district_name";
......@@ -147,11 +149,7 @@ class PerformanceService
*/
public function personagePerformance($agent_id, $start_time, $end_time, $is_case, $house_id)
{
$field = "agent_id,sum(look_at_num) as look_at_num,sum(march_in_num) as march_in_num , sum(paylog) as paylog ,
sum(bargain_sum) as bargain_sum";
$result = [];
switch ($is_case) {
case 1:
$now_date = date("Y-m-d", time());
......@@ -160,6 +158,9 @@ class PerformanceService
$params['create_time'] = array( 'between', array( $start_time . " 00:00:00", $end_time . " 23:59:59" ) );
$result = $this->nowTimeSum($params);
} else {
$field = "agent_id,sum(look_at_num) as look_at_num,sum(march_in_num) as march_in_num , sum(paylog) as paylog ,
sum(bargain_sum) as bargain_sum";
$where_["agent_id"] = $agent_id;
$where_['total_time'] = array( 'between', array( $start_time, $end_time ) );
......@@ -235,7 +236,7 @@ class PerformanceService
break;
}
$result = $this->getOrderList($params,$type);
$result = $this->getOrderList($params, $type);
if (count($result) > 0) {
return $result;
} else {
......@@ -255,16 +256,16 @@ class PerformanceService
break;
case 2:
$field = "DATE(a.create_time) as create_time ,b.house_id,b.house_title,c.user_phone,c.user_name,c.user_id,d.internal_title,d.internal_address";
$result = $this->marchInModel->getAddMarchInOrderList($field,$params);
$result = $this->marchInModel->getAddMarchInOrderList($field, $params);
break;
case 3:
$field = "DATE(a.create_time) as create_time ,b.house_id,b.house_title,c.user_phone,c.user_name,c.user_id,d.internal_title,d.internal_address";
$result = $this->payLogModel->getAddPayLogOrderList($field,$params);
$result = $this->payLogModel->getAddPayLogOrderList($field, $params);
break;
case 4:
$field = "DATE(a.create_time) as create_time ,b.house_id,b.house_title,c.user_phone,c.user_name,c.user_id,d.internal_title,d.internal_address";
$result = $this->bargainModel->getAddBargainOrderList($field,$params);
$result = $this->bargainModel->getAddBargainOrderList($field, $params);
break;
default:
......@@ -274,6 +275,7 @@ class PerformanceService
}
/**
* 个人业绩当天业绩统计
* @param $params
* @return array
*/
......@@ -281,27 +283,133 @@ class PerformanceService
{
$result = [];
$reportNum = $this->reportModel->getAddReportNum($params);
if (count($reportNum) > 0) {
$result["look_at_num"] = $reportNum[0]["num"];
}
$result["look_at_num"] = isset($reportNum[0]["num"]) ? $reportNum[0]["num"] : 0;
$addMarchInNum = $this->marchInModel->getAddMarchInNum($params);
if (count($addMarchInNum) > 0) {
$result["march_in_num"] = $addMarchInNum[0]["num"];
}
$result["march_in_num"] = isset($addMarchInNum[0]["num"]) ? $addMarchInNum[0]["num"] : 0;
$payLogNum = $this->payLogModel->getAddPayLogNum($params);
if (count($payLogNum) > 0) {
$result["paylog"] = $payLogNum[0]["num"];
$result["paylog"] = isset($payLogNum[0]["num"]) ? $payLogNum[0]["num"] : 0;
$bargainSum = $this->bargainModel->getAddBargainNum($params, 3);//表示统计
$result["bargain_sum"] = isset($bargainSum[0]["num"]) ? $bargainSum[0]["num"] : 0;
return $result;
}
$bargainSum = $this->bargainModel->getAddBargainNum($params);//表示统计
if (count($bargainSum) > 0) {
$result["bargain_sum"] = $bargainSum[0]["num"];
public function storePerformance($agent_id, $start_time, $end_time)
{
$result = $this->agentModel->searchAgentsByKeyword("id,store_id,district_id,level", [ "id" => $agent_id ]);
if (count($result) <= 0) {
return null;
}
return $result;
$type = 0;
if ($result[0]["level"] == 20) {
$type = 2;
$params["store_id"] = $result[0]["store_id"];
} elseif ($result[0]["level"] == 30 || $result[0]["level"] == 40) {
$type = 3;
$params["district_id"] = $result[0]["district_id"];
}
public function storePerformance($agent_id,$start_time,$end_time){
$list = [];
$now_date = date("Y-m-d", time());
if ($start_time == $now_date && $end_time == $now_date) {
$params['create_time'] = array( 'between', array( $start_time . " 00:00:00", $end_time . " 23:59:59" ) );
$list = $this->sumDistrictPerformance($params);
} else {
$field = "sum(add_house_num) as add_house_num,sum(add_user_num) as add_user_num,
sum(performance) as performance,sum(official_receipts) as official_receipts,sum(look_at_num) as look_at_num,
sum(march_in_num) as march_in_num,sum(paylog) as paylog,sum(supervision_num) as supervision_num";
$params['total_time'] = array( 'between', array( $start_time, $end_time ) );
$list = $this->totalModel->getTotalByAgentId($field, $params, $type, "");
}
if (count($list) > 0) {
return $list;
} else {
return null;
}
}
public function storeSortByDistrictId($agent_id, $start_time, $end_time)
{
$result = $this->agentModel->searchAgentsByKeyword("id,store_id,district_id,level", [ "id" => $agent_id ]);
dump($result);
if (count($result) <= 0) {
return null;
}
$field = "store_id,agent_id,sum(add_house_num) as add_house_num,sum(add_user_num) as add_user_num,sum(march_in_num) as march_in_num,
sum(performance) as performance,sum(official_receipts) as official_receipts";
/* $where_["agent_id"] = $agent_id;
$where_['total_time'] = array( 'between', array( $start_time, $end_time ) );
$list = $this->totalModel->personagePerformance($field, $where_);*/
$type = 0;
if ($result[0]["level"] == 20) {
$type = 1;
$params["store_id"] = $result[0]["store_id"];
} elseif ($result[0]["level"] == 30 || $result[0]["level"] == 40) {
$type = 2;
$params["district_id"] = $result[0]["district_id"];
}
$params['total_time'] = array( 'between', array( $start_time, $end_time ) );
$field = "agent_id,store_id,district_id,sum(performance) as performance_total";
$order = "total_time desc";
$result = $this->totalModel->getTotalByAgentId($field, $params, $type, $order);
dump($result);
}
private function sumDistrictPerformance($params)
{
$result = [];
//房源
$addHouseNum = $this->houseModel->getAddHouseNum($params);
$result["add_house_num"] = isset($addHouseNum[0]["num"]) ? $addHouseNum[0]["num"] : 0;
//dump($addHouseNum);
//客源
$addUserNum = $this->userModel->getAddUserNum($params);
$result["add_user_num"] = isset($addUserNum[0]["num"]) ? $addUserNum[0]["num"] : 0;
//dump($addUserNum);
//业绩
$performanceSum = $this->bargainModel->getAddBargainNum($params, 1);//1表示业绩 2表示实收
$result["performance"] = isset($performanceSum[0]["num"]) ? $performanceSum[0]["num"] : 0;
//实收
$receivedSum = $this->bargainModel->getAddBargainNum($params, 2);//1表示业绩 2表示实收
$result["official_receipts"] = isset($receivedSum[0]["num"]) ? $receivedSum[0]["num"] : 0;
//dump($receivedSum);
//约带看
$reportNum = $this->reportModel->getAddReportNum($params);
$result["look_at_num"] = isset($reportNum[0]["num"]) ? $reportNum[0]["num"] : 0;
//dump($reportNum);
//进场
$addMarchInNum = $this->marchInModel->getAddMarchInNum($params);
$result["march_in_num"] = isset($addMarchInNum[0]["num"]) ? $addMarchInNum[0]["num"] : 0;
//dump($addMarchInNum);
//收款
$payLogNum = $this->payLogModel->getAddPayLogNum($params);
$result["paylog"] = isset($payLogNum[0]["num"]) ? $payLogNum[0]["num"] : 0;
//dump($payLogNum);
//todo 监督
$result["supervision_num"] = 0;
return $result;
}
}
\ No newline at end of file
......@@ -22,7 +22,7 @@ class VerifyService
}
/**
* 经纪人身份验证
* 经纪人身份验证 获取经纪人
* @param $agent_id
* @return null|string
*/
......
......@@ -518,6 +518,23 @@ class GHouses extends BaseModel
->select();
}
public function getAddHouseNum($params){
$field = "count(1) as num";
$where_ = [];
if(isset($params["agent_id"])){
$where_["upload_id"] = $params["agent_id"];
}
if(isset($params["create_time"])){
$where_["create_time"] = $params["create_time"];
}
$result = Db::table($this->table)
->field($field)
->where($where_)
->select();
//echo Db::table($this->table)->getLastSql();
return $result;
}
/******zw end ************/
......
......@@ -324,9 +324,18 @@ class OBargainModel extends Model
->select();
}
public function getAddBargainNum($params){
public function getAddBargainNum($params,$type){
$where_ = [];
if($type == 1){
$field = "sum(scale_fee) as num";
}elseif($type == 2){
$field = "sum(practical_fee) as num";
}elseif ($type == 3){
$field = "count(1) as num";
}
if(isset($params["agent_id"])){
$where_["a.agent_id"] = $params["agent_id"];
......
......@@ -57,15 +57,18 @@ class TAgentTotalModel extends Model
->select();
}
/**
* 获取分组统计数据
* @param $field
* @param $params
* @param $type
* @param string $order
* @return false|\PDOStatement|string|\think\Collection
*/
public function getTotalByAgentId($params, $type)
public function getTotalByAgentId($field ,$params, $type ,$order = "")
{
$group_ = "agent_id";
$group_ = "";
switch ($type) {
case 1:
$group_ = "agent_id";
......@@ -76,12 +79,13 @@ class TAgentTotalModel extends Model
case 3:
$group_ = "district_id";
break;
}
$result = $this->db_
->field("agent_id,store_id,district_id,sum(performance) as performance_total")
->field($field)
->where($params)
->group($group_)
->order("performance_total desc")
->order($order)
->select();
//echo $this->db_->getLastSql();
return $result;
......
......@@ -325,6 +325,21 @@ class Users extends Model
->select();
}
public function getAddUserNum($params){
$field = "count(1) as num";
$where_ = [];
if(isset($params["agent_id"])){
$where_["referrer_id"] = $params["agent_id"];
}
if(isset($params["create_time"])){
$where_["create_time"] = $params["create_time"];
}
return Db::table($this->table)
->field($field)
->where($where_)
->select();
}
public function all_user_count($params='')
{
......
......@@ -363,6 +363,7 @@ Route::group('broker', [
'selectPerformanceByTime' => ['api_broker/Performance/selectPerformanceByTime', ['method' => 'get']],
'agentPerformanceBySearch' => ['api_broker/Performance/agentPerformanceBySearch', ['method' => 'get']],
'orderNoList' => ['api_broker/Performance/orderNoList', ['method' => 'get']],
'storeOrAgentSort' => ['api_broker/Performance/storeOrAgentSort', ['method' => 'get']],
'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