Commit 82416f68 authored by zhuwei's avatar zhuwei

业绩修改

parent 2171ec8e
...@@ -41,34 +41,22 @@ class Performance extends Basic ...@@ -41,34 +41,22 @@ class Performance extends Basic
"agent_id" => 80, "agent_id" => 80,
"type" => 3, //1表示个人业绩排行 2门店 3区域 "type" => 3, //1表示个人业绩排行 2门店 3区域
"end_day" => "", "end_day" => "",
"start_day" =>"", "start_day" =>""
'request_source_type'=>"",
'second_select'=>"",
'second_id'=>"",
);*/ );*/
if (!isset($params["agent_id"]) || !isset($params["type"])) { if (!isset($params["agent_id"]) || !isset($params["type"])) {
return $this->response("101", "请求参数错误"); return $this->response("101", "请求参数错误");
} }
$pageNo = empty($this->params['pageNo']) ? 1 : $this->params['pageNo'];
$pageSize = empty($this->params['pageSize']) ? 15 : $this->params['pageSize'];
//默认排序一周 2018-07-18改为本月 //默认排序一周 2018-07-18改为本月
$end_day = !empty($params["end_day"]) ? $params["end_day"] : date("Y-m-d", strtotime("-1 day")); $end_day = !empty($params["end_day"]) ? $params["end_day"] : date("Y-m-d", strtotime("-1 day"));
//$start_day = !empty($params["start_day"]) ? $params["start_day"] : date("Y-m-d", strtotime("-7 day")); //$start_day = !empty($params["start_day"]) ? $params["start_day"] : date("Y-m-d", strtotime("-7 day"));
$start_day = !empty($params["start_day"]) ? $params["start_day"] : date("Y-m-01", time()); $start_day = !empty($params["start_day"]) ? $params["start_day"] : date("Y-m-01", time());
$request_source_type = !empty($params["request_source_type"]) ? $params["request_source_type"] : 0 ;//请求来源默认0:App 1:PC后台
$second_select = !empty($params["second_select"]) ? $params["second_select"] : 0 ;//是否二级查询 是1 否0
$second_id = !empty($params["second_id"]) ? $params["second_id"] : '' ;//是否二级查询 是1 否0
$list = $this->service_->totalAgent($params["agent_id"], $params["type"], $end_day, $start_day,$request_source_type,$second_select,$second_id,$pageNo,$pageSize); $list = $this->service_->totalAgent($params["agent_id"], $params["type"], $end_day, $start_day);
//dump($list); //dump($list);
if (count($list) > 0) { if (count($list) > 0) {
$result["list"] = $list['list']; $result["list"] = $list;
$result["total"] = $list['total'];
$result["start_time"] = $start_day; $result["start_time"] = $start_day;
$result["end_time"] = $end_day; $result["end_time"] = $end_day;
return $this->response("200", "request success", $result); return $this->response("200", "request success", $result);
......
...@@ -62,7 +62,7 @@ class PerformanceService ...@@ -62,7 +62,7 @@ class PerformanceService
* @throws \think\db\exception\ModelNotFoundException * @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException * @throws \think\exception\DbException
*/ */
public function totalAgent($agent_id, $type, $yesterday, $end_day,$request_source_type,$second_select,$second_id,$pageNo,$pageSize) public function totalAgent($agent_id, $type, $yesterday, $end_day)
{ {
$agent_info = $this->getStoreAndDistrict($agent_id); $agent_info = $this->getStoreAndDistrict($agent_id);
...@@ -70,14 +70,6 @@ class PerformanceService ...@@ -70,14 +70,6 @@ class PerformanceService
$where_ = []; $where_ = [];
$where_['total_time'] = array( 'between', array( $end_day, $yesterday ) ); $where_['total_time'] = array( 'between', array( $end_day, $yesterday ) );
$having = '';
if($second_select == 1){
if($type == 2){
$having = "district_id =".$second_id;
}elseif($type == 3){
$having = "store_id =".$second_id;
}
}
...@@ -94,24 +86,14 @@ class PerformanceService ...@@ -94,24 +86,14 @@ class PerformanceService
$field = "agent_id,store_id,district_id,sum(performance) as performance_total,bargain_sum,bargain_sum,paylog,march_in_num,look_at_num,add_house_num,add_user_num"; $field = "agent_id,store_id,district_id,sum(performance) as performance_total,bargain_sum,bargain_sum,paylog,march_in_num,look_at_num,add_house_num,add_user_num";
$order = "performance_total desc"; $order = "performance_total desc";
$result = $this->totalModel->getTotalByAgentId($field, $where_, $type, $order);
if($request_source_type == 0){ //dump($result);
$result = $this->totalModel->getTotalByAgentId($field, $where_, $type, $order,$having);
}else{
$result = $this->totalModel->getTotalByAgentIdPage($pageNo,$pageSize,$field, $where_, $type, $order,$having);
}
//dump($where_);
//dump($having);
$arr = []; $arr = [];
$total = $this->totalModel->getTotalByAgentIdCount($field, $where_, $type, $order,$having);
$field = "a.name,a.img,b.store_name,c.district_name"; $field = "a.name,a.img,b.store_name,c.district_name";
//dump($result);
$ranking_num = $request_source_type == 0 ? 5 : 100 ;//App显示前5 PC后台显示前100
foreach ($result as $key => $value) { foreach ($result as $key => $value) {
switch ($type) { switch ($type) {
case 1: case 1:
if ($value["agent_id"] == $agent_info["id"] || $key < $ranking_num) { if ($value["agent_id"] == $agent_info["id"] || $key < 5) {
$value["index_"] = $key + 1; $value["index_"] = $key + 1;
$value["is_my"] = $agent_info["id"]; $value["is_my"] = $agent_info["id"];
$info = $this->agentModel->getAgentsInfoByAgentId($field, [ "agent_id" => $value["agent_id"] ]); $info = $this->agentModel->getAgentsInfoByAgentId($field, [ "agent_id" => $value["agent_id"] ]);
...@@ -121,11 +103,15 @@ class PerformanceService ...@@ -121,11 +103,15 @@ class PerformanceService
$value["store_name"] = $info[0]["store_name"]; $value["store_name"] = $info[0]["store_name"];
$value["district_name"] = $info[0]["district_name"]; $value["district_name"] = $info[0]["district_name"];
} }
//计算区域人数
$params = [];
$params['district_id'] = $value["district_id"];
$value["team_num"] = $this->agentModel->getAgentsCountByStoreId($params);
array_push($arr, $value); array_push($arr, $value);
} }
break; break;
case 2: case 2:
if ($value["store_id"] == $agent_info["store_id"] || $key < $ranking_num) { if ($value["store_id"] == $agent_info["store_id"] || $key < 5) {
$value["index_"] = $key + 1; $value["index_"] = $key + 1;
$value["is_my"] = $agent_info["store_id"]; $value["is_my"] = $agent_info["store_id"];
$info = $this->agentModel->getAgentsInfoByAgentId($field, [ "agent_id" => $value["agent_id"], "" ]); $info = $this->agentModel->getAgentsInfoByAgentId($field, [ "agent_id" => $value["agent_id"], "" ]);
...@@ -154,16 +140,12 @@ class PerformanceService ...@@ -154,16 +140,12 @@ class PerformanceService
$value["store_name"] = $info[0]["store_name"]; $value["store_name"] = $info[0]["store_name"];
$value["district_name"] = $info[0]["district_name"]; $value["district_name"] = $info[0]["district_name"];
} }
//计算区域人数
$params = [];
$params['district_id'] = $value["district_id"];
$value["team_num"] = $this->agentModel->getAgentsCountByStoreId($params);
array_push($arr, $value); array_push($arr, $value);
break; break;
} }
} }
return ['list'=>$arr,'total'=>$total]; return $arr;
} }
......
...@@ -66,7 +66,7 @@ class TAgentTotalModel extends Model ...@@ -66,7 +66,7 @@ class TAgentTotalModel extends Model
* @param string $order * @param string $order
* @return false|\PDOStatement|string|\think\Collection * @return false|\PDOStatement|string|\think\Collection
*/ */
public function getTotalByAgentId($field ,$params, $type ,$order = "",$having) public function getTotalByAgentId($field ,$params, $type ,$order = "")
{ {
$group_ = ""; $group_ = "";
switch ($type) { switch ($type) {
...@@ -86,7 +86,6 @@ class TAgentTotalModel extends Model ...@@ -86,7 +86,6 @@ class TAgentTotalModel extends Model
->where($params) ->where($params)
->group($group_) ->group($group_)
->order($order) ->order($order)
->having($having)
->select(); ->select();
// echo $this->db_->getLastSql(); // echo $this->db_->getLastSql();
return $result; return $result;
......
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