Commit 71a8c772 authored by zw's avatar zw

日报周报

parent f2a7055c
......@@ -31,11 +31,11 @@ class Statement extends Basic
{
header('Access-Control-Allow-Origin:*');
$params = $this->params;
/* $params = array(
"agent_id" => 1,
"time_start" => date("Y-m-d", time()),
"time_end" => date("Y-m-d", time()) . " 23:59:59",
);*/
/*$params = array(
"agent_id" => 3,
"time_start" => date("Y-m-d", time()),
"time_end" => date("Y-m-d", time()) . " 23:59:59",
);*/
if (!isset($params["agent_id"]) || !isset($params["time_start"]) || !isset($params["time_end"])) {
return $this->response("101", "请求参数错误");
}
......
<?php
namespace app\api_broker\service;
use app\model\AAgents;
use app\model\FollowUpLogModel;
use app\model\GHouses;
......@@ -12,7 +14,8 @@ use app\model\Users;
* Time : 上午11:33
* Intro:
*/
class StatementService {
class StatementService
{
private $agentModel;
private $houseModel;
......@@ -25,9 +28,9 @@ class StatementService {
function __construct()
{
$this->agentModel = new AAgents();
$this->houseModel = new GHouses();
$this->userModel = new Users();
$this->agentModel = new AAgents();
$this->houseModel = new GHouses();
$this->userModel = new Users();
$this->followUpModel = new FollowUpLogModel();
}
......@@ -40,36 +43,37 @@ class StatementService {
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function selectStatementByAgentId($agent_id,$time_start,$time_end){
public function selectStatementByAgentId($agent_id, $time_start, $time_end)
{
$field = "id,store_id,district_id,level,name,phone,sex,status";
$agent_result = $this->agentModel->getAgentById($field,$agent_id);
$agent_result = $this->agentModel->getAgentById($field, [ "agent_id" => $agent_id ]);
if(count($agent_result) <= 0){
if (count($agent_result) <= 0) {
return null;
}
$user_type = self::USER_LEVEL_FIST; //经纪人权限,0经纪人 1店长 2总监
if($agent_result[0]["level"] == 20){
if ($agent_result[0]["level"] == 20) {
$user_type = self::USER_LEVEL_SECOND;
}elseif ($agent_result[0]["level"] == 30 || $agent_result[0]["level"] == 40 ){
} elseif ($agent_result[0]["level"] == 30 || $agent_result[0]["level"] == 40) {
$user_type = self::USER_LEVEL_THIRD;
}
$store_id = $agent_result[0]["store_id"];
$district_id = $agent_result[0]["district_id"];
$conditions["agent_id"] = $agent_id;
$conditions["agent_id"] = $agent_id;
$conditions['create_time'] = array( 'between', array( $time_start, $time_end ) );
return $this->selectStatement($conditions,$user_type,$store_id,$district_id);
return $this->selectStatement($conditions, $user_type, $store_id, $district_id);
}
private function selectStatement($conditions,$user_type,$store_id,$district_id){
private function selectStatement($conditions, $user_type, $store_id, $district_id)
{
$result = $params = [];
switch ($user_type){
switch ($user_type) {
case 0:
//todo
break;
......@@ -80,34 +84,81 @@ class StatementService {
break;
case 2:
$params["district_id"] = $district_id;
$params["status"] = 0; //只查询正常状态的经纪人
$params["status"] = 0; //只查询正常状态的经纪人
break;
}
$agent_total = 1; //进到这里的经纪人肯定都存在所以默认此经纪人数量为1
if(!empty($params)){
$agentsArr = $this->agentModel->getAgentsByStoreId($params);
$store_list = $district_list = [];
if (!empty($params)) {
$agentsArr = $this->agentModel->getAgentsByStoreId($params);
$agent_total = count($agentsArr);
if($agent_total > 0){
//dump($agentsArr);
if ($agent_total > 0) {
$agentIds = "";
foreach ($agentsArr as $key => $value){
$agentIds .= $value["id"] . ",";
foreach ($agentsArr as $key => $value) {
$agentIds .= $value["id"] . ",";
if ($user_type == 1) {
$store_list = $this->getStoreList($conditions, $value["id"],$value["name"],$key);
}
}
$agentIds = rtrim($agentIds, ",");
$conditions["agent_id"] = array( "in", $agentIds );
if($user_type == 2){
$district_lists = $this->getDistrictList($conditions,$district_id);
$district_list = $district_lists["district_list"];
$result["last_week_total"] = $district_lists["last_week_total"];
}
$agentIds = rtrim($agentIds, ",");
$conditions["agent_id"] = array("in",$agentIds);
}
}
$result["agent_total"] = $agent_total;
$result["house_num"] = $this->houseModel->getAddHouseNumByAgentId($conditions);
$result["user_num"] = $this->userModel->getAddUserNumByAgentId($conditions);
$result["agent_total"] = $agent_total;
$result["house_num"] = $this->houseModel->getAddHouseNumByAgentId($conditions);
$result["user_num"] = $this->userModel->getAddUserNumByAgentId($conditions);
$result["follow_up_num"] = $this->followUpModel->getAddFollowUpNumByAgentId($conditions);
//todo
$result["store_list"] = $store_list;
$result["district_list"] = $district_list;
return $result;
}
private function getStoreList($conditions,$agent_id,$agent_name,$key){
$conditions_ = $conditions;
$conditions_["agent_id"] = $agent_id;
//是门店 统计个人业绩
$store_list[$key]["agent_id"] = $agent_id;
$store_list[$key]["agent_name"] = $agent_name;
$store_list[$key]["house_num"] = $this->houseModel->getAddHouseNumByAgentId($conditions_);
$store_list[$key]["user_num"] = $this->userModel->getAddUserNumByAgentId($conditions_);
$store_list[$key]["follow_up_num"] = $this->followUpModel->getAddFollowUpNumByAgentId($conditions_);
return $store_list;
}
private function getDistrictList($conditions,$district_id){
//根据门店统计本周人数和上周人数
$time_start = $conditions['time_start'];
$last_week_start_time = date("Y-m-d" . " 00:00:00", strtotime("$time_start -1 week"));
$last_week_end_time = date("Y-m-d" . " 23:59:59", strtotime("$time_start -1 day"));
$where_["quit_time"] = array( 'between', array( $last_week_start_time, $last_week_end_time ) );
$where_["district_id"] = $district_id;
$result = $this->agentModel->countAgentNum($where_);
$last_week_total = 0;
foreach ($result as $key =>$value){
$last_week_total += $value["agent_num"];
$paramArr["store_id"] = $value["store_id"];
$paramArr["level"] = array("in",[20,40]);
$agentsResult = $this->agentModel->getAgentsByStoreId($paramArr);
$result[$key]["name"] = count($agentsResult) > 0 ? $agentsResult[0]["name"]: null;
}
$district_list["last_week_total"] = $last_week_total;
$district_list["district_list"] = $result;
return $district_list;
}
}
\ No newline at end of file
......@@ -286,9 +286,11 @@ class AAgents extends BaseModel
$where_["id"] = $params["agent_id"];
}
return $this->field($field)
$result = $this->field($field)
->where($where_)
->select();
// echo $this->getLastSql();
return $result;
}
/**
......@@ -385,13 +387,40 @@ class AAgents extends BaseModel
public function getAgentsByStoreId($params)
{
$result = Db::table($this->table)
->field("id")
->field("id,name")
->where($params)
->select();
//echo Db::table($this->table)->getLastSql();
return $result;
}
public function countAgentNum($params){
$where_ = $whereOr_ = [];
if(isset($params["quit_time"])){
$whereOr_["a.quit_time"] = $params["quit_time"];
$whereOr_["a.status"] = 3;
}
if(isset($params["district_id"])){
$where_["a.district_id"] = $params["district_id"];
$where_["a.status"] = 0;
}
$result = Db::table($this->table)
->field("a.id,a.store_id ,b.store_name,count(a.id) as agent_num")
->alias("a")
->join("a_store b","a.store_id = b.id","left")
->where($where_)
->whereOr(function ($query) use ($whereOr_) {
$query->where($whereOr_);
})
->group("a.store_id")
->select();
// echo Db::table($this->table)->getLastSql();
return $result;
}
public function getAgentsInfoByAgentId($field, $params)
{
$where_ = [];
......
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