Commit 13f52839 authored by clone's avatar clone

bug

parent fb8a933e
......@@ -70,9 +70,9 @@ class Performance extends Basic
header('Access-Control-Allow-Origin:*');
$params = $this->params;
/* $params = array(
"agent_id" => 10013,
"start_time" => "2018-04-11",
"end_time" => "2018-04-11",
"agent_id" => 4,
"start_time" => "2018-04-12",
"end_time" => "2018-04-12",
"is_case" => 2,//1经纪人 2案场
"house_id" => 0
);*/
......@@ -101,11 +101,11 @@ class Performance extends Basic
{
header('Access-Control-Allow-Origin:*');
$params = $this->params;
/* $params = array(
"agent_id" => 10014,
"start_time" => "2018-04-11",
"end_time" => "2018-04-11",
);*/
$params = array(
"agent_id" => 4,
"start_time" => "2018-04-12",
"end_time" => "2018-04-12",
);
try {
$result = $this->service_->storePerformance($params["agent_id"], $params["start_time"], $params["end_time"]);
......@@ -124,7 +124,7 @@ class Performance extends Basic
header('Access-Control-Allow-Origin:*');
$params = $this->params;
/* $params = array(
"agent_id" => 10013,
"agent_id" => 4,
"start_time" => "2018-03-13",
"end_time" => "2018-04-10",
"is_case" => 2,//1经纪人 2案场
......@@ -156,17 +156,18 @@ class Performance extends Basic
public function storeOrAgentSort(){
header('Access-Control-Allow-Origin:*');
$params = $this->params;
/* $params = array(
"agent_id" => 1,
"start_time" => "2018-03-10",
"end_time" => "2018-03-23",
/* $params = array(
"agent_id" => 6,
"is_store" => 2,//1经纪人排行 2门店
"start_time" => "2018-04-12",
"end_time" => "2018-04-12",
);*/
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"]);
$result = $this->service_->storeSortByDistrictId($params["agent_id"],$params["is_store"] , $params["start_time"], $params["end_time"]);
return $this->response("200", "request success", $result);
} catch (Exception $exception) {
......
......@@ -182,8 +182,8 @@ class PerformanceService
foreach ($house_id_arr as $item) {
$ids .= $item["houses_id"] . ",";
}
$ids = rtrim($ids, ",");
if(!$ids){ //代表没有案场
$ids = rtrim($ids, ",");
if (!$ids) { //代表没有案场
return null;
}
$condition["house_ids"] = $ids;
......@@ -232,8 +232,8 @@ class PerformanceService
foreach ($house_id_arr as $item) {
$ids .= $item["houses_id"] . ",";
}
$ids = rtrim($ids, ",");
if(!$ids){ //代表没有案场
$ids = rtrim($ids, ",");
if (!$ids) { //代表没有案场
return null;
}
$params["house_ids"] = $ids;
......@@ -306,7 +306,7 @@ class PerformanceService
public function storePerformance($agent_id, $start_time, $end_time)
{
$result = $this->agentModel->searchAgentsByKeyword("id,store_id,district_id,level", [ "id" => $agent_id ]);
// dump($result);
// dump($result);
if (count($result) <= 0) {
return null;
}
......@@ -326,13 +326,13 @@ class PerformanceService
if ($start_time == $now_date && $end_time == $now_date) {
$verify = new VerifyService();
$agent_ids = $verify->getAgentsByAgentId($agent_id);
$params["agent_id"] = array("in",$agent_ids);
$verify = new VerifyService();
$agent_ids = $verify->getAgentsByAgentId($agent_id);
$params["agent_id"] = array( "in", $agent_ids );
$params['create_time'] = array( 'between', array( $start_time . " 00:00:00", $end_time . " 23:59:59" ) );
$list = $this->sumDistrictPerformance($params);
// dump($list);exit;
// dump($list);exit;
} 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,
......@@ -354,30 +354,74 @@ class PerformanceService
}
public function storeSortByDistrictId($agent_id, $start_time, $end_time)
/**
* @param $agent_id
* @param $is_store
* @param $start_time
* @param $end_time
* @return array|false|null|\PDOStatement|string|\think\Collection
*/
public function storeSortByDistrictId($agent_id, $is_store, $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";
$list = [];
$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"];
}
$now_date = date("Y-m-d", time());
$params['total_time'] = array( 'between', array( $start_time, $end_time ) );
if ($start_time == $now_date && $end_time == $now_date) {
$verify = new VerifyService();
$agent_ids = $verify->getAgentsByAgentId($agent_id);
$params["id"] = array( "in", $agent_ids );
//todo 1.获取所有经纪人
$field = "id as agent_id,store_id";
$group = "";
if ($is_store == 2) {
$group = "store_id";
}
$list = $this->agentModel->getAgentsList($field, $params, $group);
foreach ($list as $key => $item) {
$totalParams['create_time'] = array( 'between', array( $start_time . " 00:00:00", $end_time . " 23:59:59" ) );
$totalParams['agent_id'] = $item["agent_id"];
if ($is_store == 2) {
$agent_ids = $verify->getAgentsByAgentId($item["agent_id"]);
$totalParams['agent_id'] = array( "in", $agent_ids );
}
//房源
$addHouseNum = $this->houseModel->getAddHouseNum($totalParams);
$list[$key]["add_house_num"] = isset($addHouseNum[0]["num"]) ? $addHouseNum[0]["num"] : 0;
//客源
$addUserNum = $this->userModel->getAddUserNum($totalParams);
$list[$key]["add_user_num"] = isset($addUserNum[0]["num"]) ? $addUserNum[0]["num"] : 0;
//进场
$addMarchInNum = $this->marchInModel->getAddMarchInNum($totalParams);
$list[$key]["march_in_num"] = isset($addMarchInNum[0]["num"]) ? $addMarchInNum[0]["num"] : 0;
//业绩
$performanceSum = $this->bargainModel->getAddBargainNum($totalParams, 1);//1表示业绩 2表示实收
$list[$key]["performance"] = isset($performanceSum[0]["num"]) ? $performanceSum[0]["num"] : 0;
//实收
$receivedSum = $this->bargainModel->getAddBargainNum($totalParams, 2);//1表示业绩 2表示实收
$list[$key]["official_receipts"] = isset($receivedSum[0]["num"]) ? $receivedSum[0]["num"] : 0;
}
} else {
$params['total_time'] = array( 'between', array( $start_time . " 00:00:00", $end_time . " 23:59:59" ) );
$order = "total_time desc";
$list = $this->totalModel->getTotalByAgentId($field, $params, $is_store, $order);
}
$order = "total_time desc";
$list = $this->totalModel->getTotalByAgentId($field, $params, $type, $order);
if (count($list) > 0) {
foreach ($list as $key => $item) {
$fields = "a.name,b.store_name";
......
......@@ -765,4 +765,20 @@ class AAgents extends BaseModel
->page($pageNo)
->select();
}
public function getAgentsList($field,$params,$group){
$where_ = [];
if($group == "store_id"){
$where_['level'] = array("in",[20,40]);
}
$result = Db::name($this->table)
->field($field)
->where($params)
->where($where_)
->group($group)
->select();
return $result;
}
}
\ 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