Commit a8c24760 authored by zw's avatar zw

周pk

parent 86589da3
<?php
namespace app\index\controller;
use app\extra\RedisExt;
use app\index\extend\Basic;
use app\index\service\RankingListService;
use app\index\untils\ExportExcelUntil;
......@@ -31,12 +32,15 @@ class RankingList extends Basic{
*/
public function getRandKingList(){
$params = $this->params;
/*$params["position"] = 1;//职称 1店长 2经理 3主任 4顾问 0新人
$this->siteId = 10002;*/
/* $params = array(
"position" => 1,//职称 1店长 2经理 3主任 4顾问 0新人
"pk_type" => 2//pk类型 1月pk 2周pk
);*/
if(!isset($params["position"]) || $params["position"] < 0 || $params["position"] > 5){
return $this->response("101","请求参数错误");
}
$result = $this->service_->RankingList( $params["position"],$this->siteId);
$pk_type = empty($params["pk_type"]) ? 0 : $params["pk_type"];
$result = $this->service_->RankingList( $params["position"],$this->siteId,$pk_type);
if(count($result) > 0){
return $this->response("200","success",$result);
}
......@@ -51,8 +55,12 @@ class RankingList extends Basic{
* @throws \think\exception\DbException
*/
public function getStoreRandKingList(){
//$this->siteId = 10001;
$result = $this->service_->StoreRankingList( $this->siteId);
$params = $this->params;
/* $params = array(
"pk_type" => 1//pk类型 1月pk 2周pk
);*/
$pk_type = empty($params["pk_type"]) ? 0 : $params["pk_type"];
$result = $this->service_->StoreRankingList( $this->siteId,$pk_type);
if(count($result) > 0){
return $this->response("200","success",$result);
}
......@@ -68,10 +76,13 @@ class RankingList extends Basic{
*/
public function exportReport(){
$params = $this->params;
/* $params["position"] = 1;
$this->siteId = 10001;*/
/* $params = array(
"position" => 1,//职称 1店长 2经理 3主任 4顾问 0新人
"pk_type" => 1//pk类型 1月pk 2周pk
);*/
$pk_type = empty($params["pk_type"]) ? 0 : $params["pk_type"];
$export = new ExportExcelUntil();
$result = $this->service_->RankingList( $params["position"],$this->siteId);
$result = $this->service_->RankingList( $params["position"],$this->siteId,$pk_type);
$title = [ '经纪人ID', '门店名称', '经纪人姓名', '经纪人电话', '业绩'];
$export->exportTables('PK明细表', $result, 5, 'PK明细表', $title);
......@@ -86,10 +97,13 @@ class RankingList extends Basic{
* @throws \think\exception\DbException
*/
public function exportReportStore(){
/* $params["position"] = 1;
$this->siteId = 10001;*/
$params = $this->params;
/* $params = array(
"pk_type" => 1//pk类型 1月pk 2周pk
);*/
$pk_type = empty($params["pk_type"]) ? 0 : $params["pk_type"];
$export = new ExportExcelUntil();
$result = $this->service_->StoreRankingList( $this->siteId);
$result = $this->service_->StoreRankingList( $this->siteId,$pk_type);
$title = [ '部门ID', '门店名称', '业绩'];
$export->exportTables('门店PK明细表', $result, 3, '门店PK明细表', $title);
......@@ -208,4 +222,19 @@ class RankingList extends Basic{
}
return $this->response("200","null");
}
public function setWeekPk(){
$params = $this->params;
$params = array(
"site_id" => "10001",
"min_num" => 5,
"max_num" => 7,
"total_date_start" => "2018-10-01",
"total_date_end" => "2018-10-08",
"sort_date_start" => "2018-11-01",
"sort_date_end" => "2018-11-08",
);
$redisExt = RedisExt::getRedis();
$redisExt->set();
}
}
\ No newline at end of file
......@@ -21,19 +21,29 @@ class RankingListService
private $agentTotalModel;
private $crewNum;
private $crewNumMax;
private $weekNum;
private $weekNumMax;
public function __construct()
{
$this->agentModel = new AAgents();
$this->agentTotalModel = new TAgentTotalModel();
$this->crewNum = array(
"10001"=>20,
"10002"=>8
"10001" => 20,
"10002" => 8
);
$this->crewNumMax = array(
"10001" => 25,
"10002" => 13
);
$this->weekNum = array(
"10001" => 5,
"10002" => 5
);
$this->weekNumMax = array(
"10001" => 7,
"10002" => 7
);
}
......@@ -46,10 +56,15 @@ class RankingListService
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function RankingList($position, $siteId)
public function RankingList($position, $siteId,$pk_type)
{
$begin_time = date('Y-m-01 00:00:00', strtotime('-3 month'));
$end_time = date("Y-m-d 23:59:59", strtotime(-date('d') . 'day'));
//周pk
if($pk_type == 2){
$begin_time = "2018-10-01";
$end_time = "2018-10-08";
}
$params["a.site_id"] = $siteId;
$params["a.position"] = $position;
$params["a.status"] = array("in", "0,3");
......@@ -60,17 +75,21 @@ class RankingListService
}
//分组
$result = $this->group($resultArr,$siteId);
$result = $this->group($resultArr,$siteId,$pk_type);
//循环分组后的数组,查询出各组本月业绩排行
//本月
$begin_time = date('Y-m-01', time());
$end_time = date("Y-m-01", strtotime('+1 month'));
$sort_begin_time = date('Y-m-01', time());
$sort_end_time = date("Y-m-01", strtotime('+1 month'));
//周pk
if($pk_type == 2){
$sort_begin_time = "2018-11-01";
$sort_end_time = "2018-11-08";
}
$param_now["a.site_id"] = $siteId;
$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));
$param_now['b.total_time'] = array('between', array($sort_begin_time, $sort_end_time));
foreach ($result as $index => $item) {
$ids = "";
foreach ($item as $key => $value) {
......@@ -86,60 +105,24 @@ class RankingListService
}
/**
* @param $resultArr
* @param $siteId
* @return array
*/
private function group($resultArr,$siteId){
//分组
$total = count($resultArr);
$total_page = floor($total / $this->crewNum[$siteId]);
$residue = $total % $this->crewNum[$siteId];
$full = $total_page * ($this->crewNumMax[$siteId] - $this->crewNum[$siteId]);
$x = $this->crewNum[$siteId];
$y = $total_page;
if ($full < $residue) {
$y = $y + 1;
} else {
$x = ceil($residue / $total_page) + $this->crewNum[$siteId];
}
$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;
}
}
}
return $result;
}
/**
* 门店业绩排行
* @param $siteId
* @param $pk_type
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function StoreRankingList($siteId){
public function StoreRankingList($siteId,$pk_type){
$begin_time = date('Y-m-01 00:00:00', strtotime('-3 month'));
$end_time = date("Y-m-d 23:59:59", strtotime(-date('d') . 'day'));
//周pk
if($pk_type == 2){
$begin_time = "2018-10-01";
$end_time = "2018-10-08";
}
$params["a.site_id"] = $siteId;
$params["a.status"] = 0;
$params["a.id"] = array("not in","5288,3742,5292");
......@@ -151,16 +134,21 @@ class RankingListService
}
//分组
$result = $this->group($resultArr,$siteId);
$result = $this->group($resultArr,$siteId,$pk_type);
//循环分组后的数组,查询出各组本月业绩排行
//本月
$begin_time = date('Y-m-01', time());
$end_time = date("Y-m-01", strtotime('+1 month'));
$sort_begin_time = date('Y-m-01', time());
$sort_end_time = date("Y-m-01", strtotime('+1 month'));
if($pk_type == 2){
$sort_begin_time = "2018-11-01";
$sort_end_time = "2018-11-08";
}
$param_now["a.site_id"] = $siteId;
$param_now["a.status"] = 0;
$param_now['b.total_time'] = array('between', array($begin_time, $end_time));
$param_now['b.total_time'] = array('between', array($sort_begin_time, $sort_end_time));
foreach ($result as $index => $item) {
$ids = "";
foreach ($item as $key => $value) {
......@@ -174,6 +162,57 @@ class RankingListService
return $result;
}
/**
* @param $resultArr
* @param $siteId
* @param $pk_type
* @return array
*/
private function group($resultArr,$siteId,$pk_type){
$crewNum_ = $this->crewNum[$siteId];
$crewNumMax_ = $this->crewNumMax[$siteId];
if($pk_type == 2){
$crewNum_ = $this->weekNum[$siteId];
$crewNumMax_ = $this->weekNumMax[$siteId];
}
//分组
$total = count($resultArr);
$total_page = floor($total / $crewNum_);
$residue = $total % $crewNum_;
$full = $total_page * ($crewNumMax_ - $crewNum_);
$x = $crewNum_;
$y = $total_page;
if ($full < $residue) {
$y = $y + 1;
} else {
$x = ceil($residue / $total_page) + $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;
}
}
}
return $result;
}
/**
* 门店排名
* @param $params
......
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