Commit 2a0af7e8 authored by zw's avatar zw

pk

parent 512474ce
......@@ -22,8 +22,8 @@ class RankingList extends Basic{
public function getRandKingList(){
$params = $this->params;
$params["position"] = 1;
$this->siteId = 10001;
/* $params["position"] = 1;
$this->siteId = 10001;*/
if(!isset($params["position"]) || $params["position"] < 0 || $params["position"] > 5){
return $this->response("101","请求参数错误");
}
......
......@@ -39,10 +39,11 @@ 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);
$resultArr = $this->getSort($params,$begin_time, $end_time,"");
if (count($resultArr) <= 0) {
return false;
}
//分组
$total = count($resultArr);
$total_page = floor($total / $this->crewNum);
......@@ -55,30 +56,28 @@ class RankingListService
}else{
$x = ceil($residue/$total_page) + $this->crewNum;
}
$result = [];
$i = 0;
$k = 0;
foreach ($resultArr as $key=>$item) {
echo "----";
echo $key;
dump($item);
echo "----";
/* if($y == $total_page){
if(($k == $x-1) && $i < (($residue % $total_page)-1) ){
$result[$i][$k++] = $item;
if($y == $total_page){
if(($k == $x-1) && ($i+1) <= ($total_page - ($residue % $total_page)) ){
$k = 0;
$i++;
++$i;
}elseif($k == $x ){
$k = 0;
$i++;
++$i;
}
}else{*/
}else{
if($k == $x ){
$k = 0;
$i++;
// }
++$i;
}
$result[$i][$k++] = $item;
}
}
//循环分组后的数组,查询出各组本月业绩排行
......@@ -97,18 +96,23 @@ class RankingListService
}
$ids = rtrim($ids, ",");
$param_now["a.id"] = array("in",$ids);
$sort_arr = $this->getSort($param_now);
$sort_arr = $this->getSort($param_now,$begin_time, $end_time,$ids);
$result[$index]= $sort_arr;
}
dump($result);
return $result;
}
public function getSort($params){
public function getSort($params,$begin_time, $end_time,$ids){
$fields = "a.id,a.store_id,a.district_id,a.name,a.phone,SUM(b.performance) as performance";
return $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,
$ids);
return array_merge($have_performance_arr,$arr);
}
......
......@@ -419,8 +419,7 @@ class AAgents extends BaseModel
*/
public function getAgentsListByPK( $field = "id",$params)
{
$params["a.district_id"] = array( 'not in', array( '13', '14', '15' ) );
return Db::table($this->table)
$data = Db::table($this->table)
->field($field)
->alias("a")
->join("t_agent_total b","a.id=b.agent_id","left")
......@@ -428,6 +427,28 @@ class AAgents extends BaseModel
->group("b.agent_id")
->order("performance desc")
->select();
//echo $this->getLastSql();
return $data;
}
public function getAgentListByPk1($siteId,$position,$startTime,$endTime,$ids){
$str_ids = " ";
$str_ids1 = " ";
if($ids){
$str_ids = " and id in ($ids)";
$str_ids1 = " and a.id in ($ids)";
}
$sql = "select aa.id,aa.store_id,aa.district_id,aa.name,aa.phone,aa.performance from
(select id,store_id,district_id,name,phone,0 as performance from a_agents
where position=$position and site_id=$siteId and status in (0,3) $str_ids )
as aa left join
(select a.id,a.store_id,a.district_id,a.name,a.phone,0 as performance from a_agents a
left join t_agent_total b on a.id=b.agent_id
where b.total_time BETWEEN '$startTime' and '$endTime'and a.status in (0,3) $str_ids1 GROUP BY b.agent_id )
as bb on aa.id = bb.id where bb.id is null" ;
$data = Db::table($this->table)->query($sql);
//echo $this->getLastSql();
return $data;
}
/**
......
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