Commit 82416f68 authored by zhuwei's avatar zhuwei

业绩修改

parent 2171ec8e
......@@ -37,38 +37,26 @@ class Performance extends Basic
{
header('Access-Control-Allow-Origin:*');
$params = $this->params;
/*$params = array(
"agent_id" => 80,
"type" => 3, //1表示个人业绩排行 2门店 3区域
"end_day" => "",
"start_day" =>"",
'request_source_type'=>"",
'second_select'=>"",
'second_id'=>"",
);*/
/*$params = array(
"agent_id" => 80,
"type" => 3, //1表示个人业绩排行 2门店 3区域
"end_day" => "",
"start_day" =>""
);*/
if (!isset($params["agent_id"]) || !isset($params["type"])) {
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改为本月
$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-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);
if (count($list) > 0) {
$result["list"] = $list['list'];
$result["total"] = $list['total'];
$result["list"] = $list;
$result["start_time"] = $start_day;
$result["end_time"] = $end_day;
return $this->response("200", "request success", $result);
......
......@@ -62,7 +62,7 @@ class PerformanceService
* @throws \think\db\exception\ModelNotFoundException
* @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);
......@@ -70,14 +70,6 @@ class PerformanceService
$where_ = [];
$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
$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";
if($request_source_type == 0){
$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);
$result = $this->totalModel->getTotalByAgentId($field, $where_, $type, $order);
//dump($result);
$arr = [];
$total = $this->totalModel->getTotalByAgentIdCount($field, $where_, $type, $order,$having);
$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) {
switch ($type) {
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["is_my"] = $agent_info["id"];
$info = $this->agentModel->getAgentsInfoByAgentId($field, [ "agent_id" => $value["agent_id"] ]);
......@@ -121,11 +103,15 @@ class PerformanceService
$value["store_name"] = $info[0]["store_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);
}
break;
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["is_my"] = $agent_info["store_id"];
$info = $this->agentModel->getAgentsInfoByAgentId($field, [ "agent_id" => $value["agent_id"], "" ]);
......@@ -154,16 +140,12 @@ class PerformanceService
$value["store_name"] = $info[0]["store_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);
break;
}
}
return ['list'=>$arr,'total'=>$total];
return $arr;
}
......
......@@ -66,7 +66,7 @@ class TAgentTotalModel extends Model
* @param string $order
* @return false|\PDOStatement|string|\think\Collection
*/
public function getTotalByAgentId($field ,$params, $type ,$order = "",$having)
public function getTotalByAgentId($field ,$params, $type ,$order = "")
{
$group_ = "";
switch ($type) {
......@@ -86,7 +86,6 @@ class TAgentTotalModel extends Model
->where($params)
->group($group_)
->order($order)
->having($having)
->select();
// echo $this->db_->getLastSql();
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