Commit b2c65f46 authored by zhuwei's avatar zhuwei

业绩区分站点

parent 93fa4e17
...@@ -43,7 +43,7 @@ class Performance extends Basic ...@@ -43,7 +43,7 @@ class Performance extends Basic
"end_day" => "", "end_day" => "",
"start_day" =>"" "start_day" =>""
);*/ );*/
if (!isset($params["agent_id"]) || !isset($params["type"])) { if (!isset($params["agent_id"]) || !isset($params["type"]) || !isset($params["site_id"])) {
return $this->response("101", "请求参数错误"); return $this->response("101", "请求参数错误");
} }
//默认排序一周 2018-07-18改为本月 //默认排序一周 2018-07-18改为本月
...@@ -51,7 +51,7 @@ class Performance extends Basic ...@@ -51,7 +51,7 @@ class Performance extends Basic
$start_day = !empty($params["start_day"]) ? $params["start_day"] : date("Y-m-01", time()); $start_day = !empty($params["start_day"]) ? $params["start_day"] : date("Y-m-01", time());
$list = $this->service_->totalAgent($params["agent_id"], $params["type"], $start_day, $end_day); $list = $this->service_->totalAgent($params["agent_id"], $params["type"], $start_day, $end_day,$params["site_id"]);
if (count($list) > 0) { if (count($list) > 0) {
$result["list"] = $list; $result["list"] = $list;
$result["start_time"] = $start_day; $result["start_time"] = $start_day;
...@@ -107,8 +107,11 @@ class Performance extends Basic ...@@ -107,8 +107,11 @@ class Performance extends Basic
"start_time" => "2018-06-25", "start_time" => "2018-06-25",
"end_time" => "2018-06-25", "end_time" => "2018-06-25",
);*/ );*/
if (!isset($params["agent_id"]) || !isset($params["site_id"])) {
return $this->response("101", "请求参数错误");
}
try { try {
$result = $this->service_->storePerformance($params["agent_id"], $params["start_time"], $params["end_time"]." 23:59:59"); $result = $this->service_->storePerformance($params["agent_id"], $params["start_time"], $params["end_time"]." 23:59:59",$params["site_id"]);
return $this->response("200", "request success", $result); return $this->response("200", "request success", $result);
} catch (Exception $exception) { } catch (Exception $exception) {
return $this->response("101", "request error,msg:" . $exception); return $this->response("101", "request error,msg:" . $exception);
...@@ -164,11 +167,11 @@ class Performance extends Basic ...@@ -164,11 +167,11 @@ class Performance extends Basic
"end_time" => "2018-04-12", "end_time" => "2018-04-12",
);*/ );*/
if (!isset($params["agent_id"]) || !isset($params["start_time"]) || !isset($params["end_time"] )) { if (!isset($params["agent_id"]) || !isset($params["start_time"]) || !isset($params["end_time"] )|| !isset($params["site_id"])) {
return $this->response("101", "请求参数错误"); return $this->response("101", "请求参数错误");
} }
try { try {
$result = $this->service_->storeSortByDistrictId($params["agent_id"], $params["is_store"], $params["start_time"], $params["end_time"]." 23:59:59"); $result = $this->service_->storeSortByDistrictId($params["agent_id"], $params["is_store"], $params["start_time"], $params["end_time"]." 23:59:59",$params["site_id"]);
return $this->response("200", "request success", $result); return $this->response("200", "request success", $result);
} catch (Exception $exception) { } catch (Exception $exception) {
......
...@@ -59,7 +59,7 @@ class PerformanceService ...@@ -59,7 +59,7 @@ class PerformanceService
* @throws \think\db\exception\ModelNotFoundException * @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException * @throws \think\exception\DbException
*/ */
public function totalAgent($agent_id, $type, $yesterday, $end_day) public function totalAgent($agent_id, $type, $yesterday, $end_day,$site_id)
{ {
$params["agent_id"] = $agent_id; $params["agent_id"] = $agent_id;
$agent_info = $this->agentModel->getAgentById("id,store_id,district_id,level", $params); $agent_info = $this->agentModel->getAgentById("id,store_id,district_id,level", $params);
...@@ -68,11 +68,12 @@ class PerformanceService ...@@ -68,11 +68,12 @@ class PerformanceService
} }
$where_ = []; $where_ = [];
$where_['total_time'] = array( 'between', array( $yesterday, $end_day ) ); $where_['d.site_id'] = $site_id;
$where_['a.total_time'] = array( 'between', array( $yesterday, $end_day ) );
$field = "agent_id,store_id,district_id,sum(performance) as performance_total"; $field = "a.agent_id,a.store_id,a.district_id,sum(a.performance) as performance_total";
$order = "performance_total desc"; $order = "performance_total desc";
$result = $this->totalModel->getTotalByAgentId($field, $where_, $type, $order); $result = $this->totalModel->getTotalByAgentIdSite($field, $where_, $type, $order);
//dump($result); //dump($result);
$arr = []; $arr = [];
$field = "a.name,a.img,b.store_name,c.district_name"; $field = "a.name,a.img,b.store_name,c.district_name";
...@@ -312,7 +313,7 @@ class PerformanceService ...@@ -312,7 +313,7 @@ class PerformanceService
* @param $end_time * @param $end_time
* @return array|false|mixed|null|\PDOStatement|string|\think\Collection * @return array|false|mixed|null|\PDOStatement|string|\think\Collection
*/ */
public function storePerformance($agent_id, $start_time, $end_time) public function storePerformance($agent_id, $start_time, $end_time,$site_id)
{ {
//获取经纪人信息 //获取经纪人信息
$result = $this->agentModel->searchAgentsByKeyword("id,store_id,district_id,level", [ "id" => $agent_id ]); $result = $this->agentModel->searchAgentsByKeyword("id,store_id,district_id,level", [ "id" => $agent_id ]);
...@@ -324,19 +325,24 @@ class PerformanceService ...@@ -324,19 +325,24 @@ class PerformanceService
if ($result[0]["level"] == 20) { if ($result[0]["level"] == 20) {
$type = 2; $type = 2;
$params["store_id"] = $result[0]["store_id"]; $params["a.store_id"] = $result[0]["store_id"];
} elseif ($result[0]["level"] == 30 || $result[0]["level"] == 40) { } elseif ($result[0]["level"] == 30 || $result[0]["level"] == 40) {
$type = 3; $type = 3;
$params["district_id"] = $result[0]["district_id"]; $params["a.district_id"] = $result[0]["district_id"];
} }
$params['d.site_id'] = $site_id;
$field = " sum(a.add_house_num) as add_house_num,
sum(a.add_user_num) as add_user_num,
sum(a.performance) as performance,
sum(a.official_receipts) as official_receipts,
sum(a.look_at_num) as look_at_num,
sum(a.march_in_num) as march_in_num,
sum(a.paylog) as paylog,
sum(a.supervision_num) as supervision_num";
$field = "sum(add_house_num) as add_house_num,sum(add_user_num) as add_user_num, $params['a.total_time'] = array( 'between', array( $start_time, $end_time ) );
sum(performance) as performance,sum(official_receipts) as official_receipts,sum(look_at_num) as look_at_num,
sum(march_in_num) as march_in_num,sum(paylog) as paylog,sum(supervision_num) as supervision_num";
$params['total_time'] = array( 'between', array( $start_time, $end_time ) );
$list = $this->totalModel->getTotalByAgentId($field, $params, $type, ""); $list = $this->totalModel->getTotalByAgentIdSite($field, $params, $type, "");
// dump($list); // dump($list);
if (count($list) > 0) { if (count($list) > 0) {
$list = $list[0]; $list = $list[0];
...@@ -357,7 +363,7 @@ class PerformanceService ...@@ -357,7 +363,7 @@ class PerformanceService
* @param $end_time * @param $end_time
* @return array|false|null|\PDOStatement|string|\think\Collection * @return array|false|null|\PDOStatement|string|\think\Collection
*/ */
public function storeSortByDistrictId($agent_id, $is_store, $start_time, $end_time) public function storeSortByDistrictId($agent_id, $is_store, $start_time, $end_time,$site_id)
{ {
$result = $this->agentModel->searchAgentsByKeyword("id,store_id,district_id,level", [ "id" => $agent_id ]); $result = $this->agentModel->searchAgentsByKeyword("id,store_id,district_id,level", [ "id" => $agent_id ]);
...@@ -368,15 +374,21 @@ class PerformanceService ...@@ -368,15 +374,21 @@ class PerformanceService
$verify = new VerifyService(); $verify = new VerifyService();
$agent_ids = $verify->getAgentsByAgentId($agent_id); $agent_ids = $verify->getAgentsByAgentId($agent_id);
$params["agent_id"] = array( "in", $agent_ids ); $params["a.agent_id"] = array( "in", $agent_ids );
$params['d.site_id'] = $site_id;
$field = "store_id,agent_id,sum(add_house_num) as add_house_num,sum(add_user_num) as add_user_num,sum(march_in_num) as march_in_num, $field = "
sum(performance) as performance,sum(official_receipts) as official_receipts"; a.store_id,
a.agent_id,
$params['total_time'] = array( 'between', array( $start_time . " 00:00:00", $end_time . " 23:59:59" ) ); sum(a.add_house_num) as add_house_num,
sum(a.add_user_num) as add_user_num,
$order = "total_time desc"; sum(a.march_in_num) as march_in_num,
$list = $this->totalModel->getTotalByAgentId($field, $params, $is_store, $order); sum(a.performance) as performance,
sum(a.official_receipts) as official_receipts";
$params['a.total_time'] = array( 'between', array( $start_time . " 00:00:00", $end_time . " 23:59:59" ) );
$order = "a.total_time desc";
$list = $this->totalModel->getTotalByAgentIdSite($field, $params, $is_store, $order);
if (count($list) > 0) { if (count($list) > 0) {
......
...@@ -113,6 +113,34 @@ class TAgentTotalModel extends Model ...@@ -113,6 +113,34 @@ class TAgentTotalModel extends Model
} }
public function getTotalByAgentIdSite($field ,$params, $type ,$order = "")
{
$group_ = "";
switch ($type) {
case 1:
$group_ = "a.agent_id";
break;
case 2:
$group_ = "a.store_id";
break;
case 3:
$group_ = "a.district_id";
break;
}
$result = $this->db_
->field($field)
->alias('a')
->join('a_district d', 'a.district_id = d.id', 'left')
->where($params)
->group($group_)
->order($order)
->select();
echo $this->db_->getLastSql();
return $result;
}
public function getTotalByAgentIdPage($pageNo,$pageSize,$field ,$params, $type ,$order = "") public function getTotalByAgentIdPage($pageNo,$pageSize,$field ,$params, $type ,$order = "")
{ {
$group_ = ""; $group_ = "";
......
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