Commit 2087079c authored by zw's avatar zw

pk

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