Commit 9bd8fd70 authored by zw's avatar zw

优化下分区代码

parent 4a1d1177
...@@ -25,6 +25,9 @@ class RankingList extends Basic{ ...@@ -25,6 +25,9 @@ class RankingList extends Basic{
/** /**
* 查询分区业绩pk * 查询分区业绩pk
* @return \think\Response * @return \think\Response
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/ */
public function getRandKingList(){ public function getRandKingList(){
$params = $this->params; $params = $this->params;
...@@ -40,9 +43,12 @@ class RankingList extends Basic{ ...@@ -40,9 +43,12 @@ class RankingList extends Basic{
return $this->response("200", "request null"); return $this->response("200", "request null");
} }
/**
* 门店业绩pk /**门店业绩pk
* @return \think\Response * @return \think\Response
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/ */
public function getStoreRandKingList(){ public function getStoreRandKingList(){
$params = $this->params; $params = $this->params;
...@@ -57,6 +63,9 @@ class RankingList extends Basic{ ...@@ -57,6 +63,9 @@ class RankingList extends Basic{
/** /**
* 导出分区pk榜 * 导出分区pk榜
* @return string * @return string
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/ */
public function exportReport(){ public function exportReport(){
$params = $this->params; $params = $this->params;
...@@ -73,6 +82,9 @@ class RankingList extends Basic{ ...@@ -73,6 +82,9 @@ class RankingList extends Basic{
/** /**
* 导出门店pk榜 * 导出门店pk榜
* @return string * @return string
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/ */
public function exportReportStore(){ public function exportReportStore(){
$params = $this->params; $params = $this->params;
...@@ -89,6 +101,9 @@ class RankingList extends Basic{ ...@@ -89,6 +101,9 @@ class RankingList extends Basic{
/** /**
* pk榜门店业绩和个人业绩排序显示前五 * pk榜门店业绩和个人业绩排序显示前五
* @return \think\Response * @return \think\Response
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/ */
public function selectPkSortByTime() public function selectPkSortByTime()
{ {
......
...@@ -58,38 +58,7 @@ class RankingListService ...@@ -58,38 +58,7 @@ class RankingListService
} }
//分组 //分组
$total = count($resultArr); $result = $this->group($resultArr);
$total_page = floor($total / $this->crewNum);
$residue = $total % $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;
}
$result = [];
$i = 0;
$k = 0;
foreach ($resultArr as $key => $item) {
$result[$i][$k++] = $item;
if ($y == $total_page) {
if (($k == $x - 1) && ($residue % $total_page) > 0 && ($i + 1) <= ($total_page - ($residue % $total_page))) {
$k = 0;
++$i;
} elseif ($k == $x) {
$k = 0;
++$i;
}
} else {
if ($k == $x) {
$k = 0;
++$i;
}
}
}
//循环分组后的数组,查询出各组本月业绩排行 //循环分组后的数组,查询出各组本月业绩排行
//本月 //本月
...@@ -116,25 +85,10 @@ class RankingListService ...@@ -116,25 +85,10 @@ class RankingListService
} }
/** /**
* 门店业绩排行 * @param $resultArr
* @param $siteId
* @return array * @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/ */
public function StoreRankingList($siteId){ private function group($resultArr){
$begin_time = date('Y-m-01 00:00:00', strtotime('-1 month'));
$end_time = date("Y-m-d 23:59:59", strtotime(-date('d') . 'day'));
$params["a.site_id"] = $siteId;
$params["a.status"] = 0;
$params['b.total_time'] = array('between', array($begin_time, $end_time));
$resultArr = $this->getStoreSort($params, $begin_time, $end_time, "");
if (count($resultArr) <= 0) {
return false;
}
//分组 //分组
$total = count($resultArr); $total = count($resultArr);
$total_page = floor($total / $this->crewNum); $total_page = floor($total / $this->crewNum);
...@@ -147,7 +101,6 @@ class RankingListService ...@@ -147,7 +101,6 @@ class RankingListService
} 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;
...@@ -169,6 +122,31 @@ class RankingListService ...@@ -169,6 +122,31 @@ class RankingListService
} }
} }
} }
return $result;
}
/**
* 门店业绩排行
* @param $siteId
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function StoreRankingList($siteId){
$begin_time = date('Y-m-01 00:00:00', strtotime('-1 month'));
$end_time = date("Y-m-d 23:59:59", strtotime(-date('d') . 'day'));
$params["a.site_id"] = $siteId;
$params["a.status"] = 0;
$params['b.total_time'] = array('between', array($begin_time, $end_time));
$resultArr = $this->getStoreSort($params, $begin_time, $end_time, "");
if (count($resultArr) <= 0) {
return false;
}
//分组
$result = $this->group($resultArr);
//循环分组后的数组,查询出各组本月业绩排行 //循环分组后的数组,查询出各组本月业绩排行
//本月 //本月
...@@ -202,7 +180,7 @@ class RankingListService ...@@ -202,7 +180,7 @@ class RankingListService
* @throws \think\db\exception\ModelNotFoundException * @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException * @throws \think\exception\DbException
*/ */
public function getStoreSort($params, $begin_time, $end_time, $ids) private function getStoreSort($params, $begin_time, $end_time, $ids)
{ {
$storeModel = new AStore(); $storeModel = new AStore();
$fields = "a.id,a.store_name,SUM(b.performance) as performance"; $fields = "a.id,a.store_name,SUM(b.performance) as performance";
...@@ -225,7 +203,7 @@ class RankingListService ...@@ -225,7 +203,7 @@ 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) private 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";
//查询出有业绩的经纪人 //查询出有业绩的经纪人
...@@ -265,7 +243,6 @@ class RankingListService ...@@ -265,7 +243,6 @@ class RankingListService
foreach ($store_sort as $key => $value) { foreach ($store_sort as $key => $value) {
$store_arr = $this->agentModel->getStoreOrDistrict(["store_id" => $value["store_id"], "level" => ["in", "20"]]); $store_arr = $this->agentModel->getStoreOrDistrict(["store_id" => $value["store_id"], "level" => ["in", "20"]]);
if (count($store_arr) > 0) { if (count($store_arr) > 0) {
//$value["name"] = count($store_arr) > 0 ? $store_arr[0]["name"] : "---";
$store_sort[$key]["img"] = $store_arr[0]["img"]; $store_sort[$key]["img"] = $store_arr[0]["img"];
} }
} }
......
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