Commit 2087079c authored by zw's avatar zw

pk

parent 38458569
...@@ -61,7 +61,7 @@ class RankingList extends Basic{ ...@@ -61,7 +61,7 @@ class RankingList extends Basic{
public function selectPkSortByTime() public function selectPkSortByTime()
{ {
$params = $this->params; $params = $this->params;
/*$params = array( /* $params = array(
"site_id" => 10001 "site_id" => 10001
);*/ );*/
if (!isset($params["site_id"])) { if (!isset($params["site_id"])) {
......
...@@ -12,6 +12,8 @@ use app\model\TAgentTotalModel; ...@@ -12,6 +12,8 @@ use app\model\TAgentTotalModel;
* Time : 2:06 PM * Time : 2:06 PM
* Intro: * Intro:
*/ */
class RankingListService class RankingListService
{ {
private $agentModel; private $agentModel;
...@@ -24,7 +26,7 @@ class RankingListService ...@@ -24,7 +26,7 @@ class RankingListService
$this->agentModel = new AAgents(); $this->agentModel = new AAgents();
$this->agentTotalModel = new TAgentTotalModel(); $this->agentTotalModel = new TAgentTotalModel();
$this->crewNum = 20; $this->crewNum = 20;
$this->crewNumMax= 25; $this->crewNumMax = 25;
} }
/** /**
...@@ -45,7 +47,7 @@ class RankingListService ...@@ -45,7 +47,7 @@ class RankingListService
$params["a.position"] = $position; $params["a.position"] = $position;
$params["a.status"] = array("in", "0,3"); $params["a.status"] = array("in", "0,3");
$params['b.total_time'] = array('between', array($begin_time, $end_time)); $params['b.total_time'] = array('between', array($begin_time, $end_time));
$resultArr = $this->getSort($params,$begin_time, $end_time,""); $resultArr = $this->getSort($params, $begin_time, $end_time, "");
if (count($resultArr) <= 0) { if (count($resultArr) <= 0) {
return false; return false;
} }
...@@ -54,29 +56,29 @@ class RankingListService ...@@ -54,29 +56,29 @@ class RankingListService
$total = count($resultArr); $total = count($resultArr);
$total_page = floor($total / $this->crewNum); $total_page = floor($total / $this->crewNum);
$residue = $total % $this->crewNum; $residue = $total % $this->crewNum;
$full = $total_page * ($this->crewNumMax-$this->crewNum); $full = $total_page * ($this->crewNumMax - $this->crewNum);
$x = $this->crewNum; $x = $this->crewNum;
$y = $total_page; $y = $total_page;
if ($full < $residue) { if ($full < $residue) {
$y = $y + 1; $y = $y + 1;
}else{ } else {
$x = ceil($residue/$total_page) + $this->crewNum; $x = ceil($residue / $total_page) + $this->crewNum;
} }
$result = []; $result = [];
$i = 0; $i = 0;
$k = 0; $k = 0;
foreach ($resultArr as $key=>$item) { foreach ($resultArr as $key => $item) {
$result[$i][$k++] = $item; $result[$i][$k++] = $item;
if($y == $total_page){ if ($y == $total_page) {
if(($k == $x-1) && ($i+1) <= ($total_page - ($residue % $total_page)) ){ if (($k == $x - 1) && ($i + 1) <= ($total_page - ($residue % $total_page))) {
$k = 0; $k = 0;
++$i; ++$i;
}elseif($k == $x ){ } elseif ($k == $x) {
$k = 0; $k = 0;
++$i; ++$i;
} }
}else{ } else {
if($k == $x ){ if ($k == $x) {
$k = 0; $k = 0;
++$i; ++$i;
...@@ -93,15 +95,15 @@ class RankingListService ...@@ -93,15 +95,15 @@ class RankingListService
$param_now["a.position"] = $position; $param_now["a.position"] = $position;
$param_now["a.status"] = array("in", "0,3"); $param_now["a.status"] = array("in", "0,3");
$param_now['b.total_time'] = array('between', array($begin_time, $end_time)); $param_now['b.total_time'] = array('between', array($begin_time, $end_time));
foreach ($result as $index=>$item){ foreach ($result as $index => $item) {
$ids = ""; $ids = "";
foreach ($item as $key=>$value){ foreach ($item as $key => $value) {
$ids .= $value["id"] . ","; $ids .= $value["id"] . ",";
} }
$ids = rtrim($ids, ","); $ids = rtrim($ids, ",");
$param_now["a.id"] = array("in",$ids); $param_now["a.id"] = array("in", $ids);
$sort_arr = $this->getSort($param_now,$begin_time, $end_time,$ids); $sort_arr = $this->getSort($param_now, $begin_time, $end_time, $ids);
$result[$index]= $sort_arr; $result[$index] = $sort_arr;
} }
return $result; return $result;
...@@ -119,14 +121,15 @@ class RankingListService ...@@ -119,14 +121,15 @@ class RankingListService
* @throws \think\db\exception\ModelNotFoundException * @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException * @throws \think\exception\DbException
*/ */
public function getSort($params,$begin_time, $end_time,$ids){ public function getSort($params, $begin_time, $end_time, $ids)
{
$fields = "a.id,c.store_name,a.name,a.phone,SUM(b.performance) as performance"; $fields = "a.id,c.store_name,a.name,a.phone,SUM(b.performance) as performance";
//查询出有业绩的经纪人 //查询出有业绩的经纪人
$have_performance_arr = $this->agentModel->getAgentsListByPK($fields, $params); $have_performance_arr = $this->agentModel->getAgentsListByPK($fields, $params);
//查询出无业绩的经纪人 //查询出无业绩的经纪人
$arr = $this->agentModel->getAgentListByPk1($params["a.site_id"],$params["a.position"],$begin_time,$end_time, $arr = $this->agentModel->getAgentListByPk1($params["a.site_id"], $params["a.position"], $begin_time, $end_time,
$ids); $ids);
return array_merge($have_performance_arr,$arr); return array_merge($have_performance_arr, $arr);
} }
...@@ -138,23 +141,29 @@ class RankingListService ...@@ -138,23 +141,29 @@ class RankingListService
* @param $site_id * @param $site_id
* @return mixed * @return mixed
*/ */
public function totalAgent( $yesterday, $end_day,$site_id) public function totalAgent($yesterday, $end_day, $site_id)
{ {
$totalModel = new TAgentTotalModel(); $totalModel = new TAgentTotalModel();
$where_ = []; $where_ = [];
$where_['b.site_id'] = $site_id; $where_['b.site_id'] = $site_id;
$where_['a.total_time'] = array( 'between', array( $yesterday, $end_day ) ); $where_['a.total_time'] = array('between', array($yesterday, $end_day));
$field = "a.agent_id,b.name,c.store_name,sum(a.performance) as performance_total"; $field = "a.agent_id,b.name,a.store_id,b.img,c.store_name,sum(a.performance) as performance_total";
$order = "performance_total desc"; $order = "performance_total desc";
$data["agent_sort"] = $totalModel->getTotalByPk($field, $where_, 1, $order); $data["agent_sort"] = $totalModel->getTotalByPk($field, $where_, 1, $order);
$data["store_sort"] = $totalModel->getTotalByPk($field, $where_, 2, $order); $store_sort = $totalModel->getTotalByPk($field, $where_, 2, $order);
foreach ($store_sort as $key => $value) {
$store_arr = $this->agentModel->getStoreOrDistrict(["store_id" => $value["store_id"], "level" => ["in", "20"]]);
if (count($store_arr) > 0) {
$value["name"] = count($store_arr) > 0 ? $store_arr[0]["name"] : "---";
$value["img"] = $store_arr[0]["img"];
}
}
$data["store_sort"] = $store_sort;
$data["api_path"] = AGENTHEADERIMGURL;
return $data; return $data;
} }
} }
\ 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