Commit 7571e1b6 authored by zhuwei's avatar zhuwei

bug

parent 4970f9a5
......@@ -143,7 +143,7 @@ class Report extends Basic
$pageNo = empty($params['page_no']) ? 1 : $params['page_no'];
$pageSize = empty($params['page_size']) ? 15 : $params['page_size'];
$field = "a.id,a.user_id,a.report_agent_name,a.user_phone,a.user_name,a.predict_see_time,a.create_time,b.id as order_id,b.order_no,b.house_id,b.house_title";
$field = "a.id,a.user_id,a.report_agent_name,a.report_agent_phone,a.user_phone,a.user_name,a.predict_see_time,a.create_time,b.id as order_id,b.order_no,b.house_id,b.house_title";
$params["report_agent_id"] = $params["agent_id"];
......
......@@ -36,18 +36,21 @@ class Statement extends Basic
header('Access-Control-Allow-Origin:*');
$params = $this->params;
/*$params = array(
"agent_id" => 5740,
"agent_id" => 5739,//5739 总监 5740店长
"time_start" => date("Y-m-d", time()),
"time_end" => date("Y-m-d", time()) . " 23:59:59",
"time_end" => date("Y-m-d", time()),
);*/
if (!isset($params["agent_id"]) || !isset($params["time_start"]) || !isset($params["time_end"])) {
return $this->response("101", "请求参数错误");
}
$day_or_week = $params["time_start"] == $params["time_end"] ? 'day' : 'week';
$time_end = $params["time_end"] . " 23:59:59";
try {
$result = $this->service_->selectStatementByAgentId($params["agent_id"], $params["time_start"], $time_end);
$result = $this->service_->selectStatementByAgentId($params["agent_id"], $params["time_start"], $time_end,$day_or_week);
if (count($result) > 0) {
return $this->response("200", "request success", $result);
......
......@@ -48,7 +48,7 @@ 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,$day_or_week)
{
$field = "id,store_id,district_id,level,name,phone,sex,status";
......@@ -69,8 +69,8 @@ class StatementService
$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);
//dump($user_type);
return $this->selectStatement($conditions, $user_type, $store_id, $district_id,$day_or_week);
}
......@@ -82,7 +82,7 @@ class StatementService
* @param $district_id
* @return array
*/
private function selectStatement($conditions, $user_type, $store_id, $district_id)
private function selectStatement($conditions, $user_type, $store_id, $district_id,$day_or_week)
{
$result = $params = [];
......@@ -119,89 +119,161 @@ class StatementService
$conditions["agent_id"] = array( "in", $agentIds );
if ($user_type == 2) {
$district_lists = $this->getDistrictList($conditions, $district_id);
$district_lists = $this->getDistrictList($conditions, $district_id,$day_or_week);
$district_list = $district_lists["district_list"];
$result["last_week_total"] = $district_lists["last_week_total"];
}
}
}
$result["agent_total"] = $agent_total;
$result["house_num"] = $this->houseModel->getAddHouseNumByAgentId($conditions);
//dump($conditions);
$result["user_num"] = $this->userModel->getAddUserNumByAgentId($conditions);
//$result["follow_up_num"] = $this->followUpModel->getAddFollowUpNumByAgentId($conditions);
$result["follow_up_num"] = $this->reportModel->getAddFollowUpNumByAgentId($conditions);
//本月业绩
$start_time = date("Y-m-01", time());
$end_time = date("Y-m-d", strtotime("-1 day"));;
$where_["agent_id"] = array( "in", $agentIds );
$where_['create_time'] = array( 'between', array( $start_time . " 00:00:00", $end_time . " 23:59:59" ) );
$obargain = new OBargainModel();
$performanceSum = $obargain->getAddBargainNum($where_, 1);//1表示业绩 2表示实收
$result["performance_month"] = isset($performanceSum[0]["num"]) ? $performanceSum[0]["num"] : 0;
$result["agent_total"] = $agent_total;
$result["house_num"] = $this->houseModel->getAddHouseNumByAgentId($conditions);
//dump($conditions);
$result["user_num"] = $this->userModel->getAddUserNumByAgentId($conditions);
//$result["follow_up_num"] = $this->followUpModel->getAddFollowUpNumByAgentId($conditions);
$result["follow_up_num"] = $this->reportModel->getAddFollowUpNumByAgentId($conditions);
//本月业绩
$start_time = date("Y-m-01", time());
$end_time = date("Y-m-d", strtotime("-1 day"));;
$where_["agent_id"] = array( "in", $agentIds );
$where_['create_time'] = array( 'between', array( $start_time . " 00:00:00", $end_time . " 23:59:59" ) );
$obargain = new OBargainModel();
$performanceSum = $obargain->getAddBargainNum($where_, 1);//1表示业绩 2表示实收
$result["performance_month"] = isset($performanceSum[0]["num"]) ? $performanceSum[0]["num"] : 0;
//本周业绩
$start_time = date("Y-m-d", strtotime("-7 day"));
$where_['create_time'] = ['between', [$start_time . " 00:00:00", $end_time . " 23:59:59"]];
$performanceSum = $obargain->getAddBargainNum($where_, 1);//1表示业绩 2表示实收
$result["performance_week"] = isset($performanceSum[0]["num"]) ? $performanceSum[0]["num"] : 0;
//本月完成单数
$start_time = date("Y-m-01", time());
$end_time = date("Y-m-d", strtotime("-1 day"));
$where_["agent_id"] = array( "in", $agentIds );
$where_['create_time'] = array( 'between', array( $start_time . " 00:00:00", $end_time . " 23:59:59" ) );
$performanceSum = $obargain->getAddBargainNum($where_, 3);//1表示业绩 2表示实收
$result["bargain_sum"] = isset($performanceSum[0]["num"]) ? $performanceSum[0]["num"] : 0;
//客源
$addUserNum = $this->userModel->getAddUserNum($where_);
$result["add_user_num"] = isset($addUserNum[0]["num"]) ? $addUserNum[0]["num"] : 0;
//当日业绩
$start_time = date("Y-m-d", time());
$end_time = $start_time;
$where_["agent_id"] = array( "in", $agentIds );
$where_['create_time'] = array( 'between', array( $start_time . " 00:00:00", $end_time . " 23:59:59" ) );
$performanceSum = $obargain->getAddBargainNum($where_, 1);//1表示业绩 2表示实收
$result["performance_day"] = isset($performanceSum[0]["num"]) ? $performanceSum[0]["num"] : 0;
//当日客源
$addUserNum = $this->userModel->getAddUserNum($where_);
$result["add_user_num_day"] = isset($addUserNum[0]["num"]) ? $addUserNum[0]["num"] : 0;
//店长当日完成单数
$where_ = [];
$start_time = date("Y-m-d", time());
$end_time = $start_time;
$where_["agent_id"] = $store_id;
$where_['create_time'] = array( 'between', array( $start_time . " 00:00:00", $end_time . " 23:59:59" ) );
$performanceSum = $obargain->getAddBargainNum($where_, 3);//1表示业绩 2表示实收
$result["bargain_sum_store"] = isset($performanceSum[0]["num"]) ? $performanceSum[0]["num"] : 0;
//店长当日带看
$where_ = [];
$start_time = date("Y-m-d", time());
$end_time = $start_time;
$where_["agent_id"] = $store_id;
$where_['create_time'] = array( 'between', array( $start_time . " 00:00:00", $end_time . " 23:59:59" ) );
$reportNum = $this->reportModel->getAddReportNum($params);
$result["look_at_num_day_store"] = isset($reportNum[0]["num"]) ? $reportNum[0]["num"] : 0;
//todo
$result["store_list"] = $store_list;
$result["district_list"] = $district_list;
if($user_type == 2){//如果是总监
//todo 判断是日报还是周报
if($day_or_week == 'day'){//日报
}else{//周报
//todo 本月业绩
$where_ = [];
$start_time = date("Y-m-01", time());
$end_time = date("Y-m-d", strtotime("-1 day"));;
$where_["district_id"] = $district_id;
$where_['create_time'] = array( 'between', array( $start_time . " 00:00:00", $end_time . " 23:59:59" ) );
$obargain = new OBargainModel();
$performanceSum = $obargain->getAddBargainNum($where_, 1);//1表示业绩 2表示实收
$result["director_performance_month"] = isset($performanceSum[0]["num"]) ? $performanceSum[0]["num"] : 0;
//todo 上周业绩
$where_ = [];
$start_time = date("Y-m-d", strtotime("-14 day"));
$end_time = date("Y-m-d", strtotime("-7 day"));
$where_["district_id"] = $district_id;
$where_['create_time'] = array( 'between', array( $start_time . " 00:00:00", $end_time . " 23:59:59" ) );
$obargain = new OBargainModel();
$performanceSum = $obargain->getAddBargainNum($where_, 1);//1表示业绩 2表示实收
$result["director_last_week_performance_num"] = isset($performanceSum[0]["num"]) ? $performanceSum[0]["num"] : 0;
//todo 本周周业绩
$where_ = [];
$start_time = date("Y-m-d", strtotime("-7 day"));
$end_time = date("Y-m-d", time());
$where_["district_id"] = $district_id;
$where_['create_time'] = array( 'between', array( $start_time . " 00:00:00", $end_time . " 23:59:59" ) );
$obargain = new OBargainModel();
$performanceSum = $obargain->getAddBargainNum($where_, 1);//1表示业绩 2表示实收
$result["director_week_performance_num"] = isset($performanceSum[0]["num"]) ? $performanceSum[0]["num"] : 0;
// 本月业绩
//todo 本月完成单数
$where_ = [];
$start_time = date("Y-m-01", time());
$end_time = date("Y-m-d", time());
$where_["district_id"] = $district_id;
$where_['create_time'] = array( 'between', array( $start_time . " 00:00:00", $end_time . " 23:59:59" ) );
$performanceSum = $obargain->getAddBargainNum($where_, 3);//1表示业绩 2表示实收
$result["director_bargain_sum_store"] = isset($performanceSum[0]["num"]) ? $performanceSum[0]["num"] : 0;
//todo 上周人数
$start_time = date("Y-m-d", strtotime("-14 day"));
$end_time = date("Y-m-d", strtotime("-7 day"));
$params['create_time'] = array( 'between', array( $start_time . " 00:00:00", $end_time . " 23:59:59" ) );
$agentsCount = $this->agentModel->getAgentsCountByStoreId($params);
$result["director_last_week_employee_num"] = isset($agentsCount) ? $agentsCount : 0;
//todo 本周人数
$start_time = date("Y-m-d", strtotime("-7 day"));
$end_time = date("Y-m-d", time());
$params['create_time'] = array( 'between', array( $start_time . " 00:00:00", $end_time . " 23:59:59" ) );
$agentsCount = $this->agentModel->getAgentsCountByStoreId($params);
$result["director_week_employee_num"] = isset($agentsCount) ? $agentsCount : 0;
//本周业绩
$start_time = date("Y-m-d", strtotime("-7 day"));
$where_['create_time'] = ['between', [$start_time . " 00:00:00", $end_time . " 23:59:59"]];
$performanceSum = $obargain->getAddBargainNum($where_, 1);//1表示业绩 2表示实收
$result["performance_week"] = isset($performanceSum[0]["num"]) ? $performanceSum[0]["num"] : 0;
//本月完成单数
$start_time = date("Y-m-01", time());
$end_time = date("Y-m-d", strtotime("-1 day"));
$where_["agent_id"] = array( "in", $agentIds );
$where_['create_time'] = array( 'between', array( $start_time . " 00:00:00", $end_time . " 23:59:59" ) );
$performanceSum = $obargain->getAddBargainNum($where_, 3);//1表示业绩 2表示实收
$result["bargain_sum"] = isset($performanceSum[0]["num"]) ? $performanceSum[0]["num"] : 0;
//客源
$addUserNum = $this->userModel->getAddUserNum($where_);
$result["add_user_num"] = isset($addUserNum[0]["num"]) ? $addUserNum[0]["num"] : 0;
//当日业绩
$start_time = date("Y-m-d", time());
$end_time = $start_time;
$where_["agent_id"] = array( "in", $agentIds );
$where_['create_time'] = array( 'between', array( $start_time . " 00:00:00", $end_time . " 23:59:59" ) );
$performanceSum = $obargain->getAddBargainNum($where_, 1);//1表示业绩 2表示实收
$result["performance_day"] = isset($performanceSum[0]["num"]) ? $performanceSum[0]["num"] : 0;
//当日客源
$addUserNum = $this->userModel->getAddUserNum($where_);
$result["add_user_num_day"] = isset($addUserNum[0]["num"]) ? $addUserNum[0]["num"] : 0;
//店长当日完成单数
$where_ = [];
$start_time = date("Y-m-d", time());
$end_time = $start_time;
$where_["agent_id"] = $store_id;
$where_['create_time'] = array( 'between', array( $start_time . " 00:00:00", $end_time . " 23:59:59" ) );
$performanceSum = $obargain->getAddBargainNum($where_, 3);//1表示业绩 2表示实收
$result["bargain_sum_store"] = isset($performanceSum[0]["num"]) ? $performanceSum[0]["num"] : 0;
}
}
//店长当日带看
$where_ = [];
$start_time = date("Y-m-d", time());
$end_time = $start_time;
$where_["agent_id"] = $store_id;
$where_['create_time'] = array( 'between', array( $start_time . " 00:00:00", $end_time . " 23:59:59" ) );
$reportNum = $this->reportModel->getAddReportNum($params);
$result["look_at_num_day_store"] = isset($reportNum[0]["num"]) ? $reportNum[0]["num"] : 0;
//todo
$result["store_list"] = $store_list;
$result["district_list"] = $district_list;
return $result;
......@@ -249,7 +321,7 @@ class StatementService
* @param $district_id
* @return mixed
*/
private function getDistrictList($conditions, $district_id)
private function getDistrictList($conditions, $district_id,$day_or_week)
{
//根据门店统计本周人数和上周人数
$time_start = $conditions['time_start'];
......@@ -265,6 +337,7 @@ class StatementService
//dump($results);
$last_week_total = 0;
foreach ($results as $key => $value) {
// dump($value);
$last_week_total += $value["agent_num"];
$paramArr["store_id"] = $value["store_id"];
$paramArr["level"] = array( "in", [ 20, 40 ] );
......@@ -276,6 +349,63 @@ class StatementService
$results[$key]["last_week_num"] = $item["agent_num"];
}
}
if($day_or_week == 'week'){
//todo 本月业绩
$start_time = date("Y-m-01", time());
$end_time = date("Y-m-d", strtotime("-1 day"));;
$where_["store_id"] = $value["store_id"];
$where_['create_time'] = array( 'between', array( $start_time . " 00:00:00", $end_time . " 23:59:59" ) );
$obargain = new OBargainModel();
$performanceSum = $obargain->getAddBargainNum($where_, 1);//1表示业绩 2表示实收
$results[$key]["director_performance_month"] = isset($performanceSum[0]["num"]) ? $performanceSum[0]["num"] : 0;
//todo 上周业绩
$where_ = [];
$start_time = date("Y-m-d", strtotime("-14 day"));
$end_time = date("Y-m-d", strtotime("-7 day"));
$where_["store_id"] = $value["store_id"];
$where_['create_time'] = array( 'between', array( $start_time . " 00:00:00", $end_time . " 23:59:59" ) );
$obargain = new OBargainModel();
$performanceSum = $obargain->getAddBargainNum($where_, 1);//1表示业绩 2表示实收
$results[$key]["director_last_week_performance_num"] = isset($performanceSum[0]["num"]) ? $performanceSum[0]["num"] : 0;
//todo 本周周业绩
$where_ = [];
$start_time = date("Y-m-d", strtotime("-7 day"));
$end_time = date("Y-m-d", time());
$where_["store_id"] = $value["store_id"];
$where_['create_time'] = array( 'between', array( $start_time . " 00:00:00", $end_time . " 23:59:59" ) );
$obargain = new OBargainModel();
$performanceSum = $obargain->getAddBargainNum($where_, 1);//1表示业绩 2表示实收
$results[$key]["director_week_performance_num"] = isset($performanceSum[0]["num"]) ? $performanceSum[0]["num"] : 0;
// 本月业绩
//todo 本月完成单数
$where_ = [];
$start_time = date("Y-m-01", time());
$end_time = date("Y-m-d", time());
$where_["store_id"] = $value["store_id"];
$where_['create_time'] = array( 'between', array( $start_time . " 00:00:00", $end_time . " 23:59:59" ) );
$performanceSum = $obargain->getAddBargainNum($where_, 3);//1表示业绩 2表示实收
$results[$key]["director_bargain_sum_store"] = isset($performanceSum[0]["num"]) ? $performanceSum[0]["num"] : 0;
//todo 上周人数
$start_time = date("Y-m-d", strtotime("-14 day"));
$end_time = date("Y-m-d", strtotime("-7 day"));
$params["store_id"] = $value["store_id"];
$params['create_time'] = array( 'between', array( $start_time . " 00:00:00", $end_time . " 23:59:59" ) );
$agentsCount = $this->agentModel->getAgentsCountByStoreId($params);
$results[$key]["director_last_week_employee_num"] = isset($agentsCount) ? $agentsCount : 0;
//todo 本周人数
$start_time = date("Y-m-d", strtotime("-7 day"));
$end_time = date("Y-m-d", time());
$params['create_time'] = array( 'between', array( $start_time . " 00:00:00", $end_time . " 23:59:59" ) );
$agentsCount = $this->agentModel->getAgentsCountByStoreId($params);
$results[$key]["director_week_employee_num"] = isset($agentsCount) ? $agentsCount : 0;
}
}
$district_list["last_week_total"] = $last_week_total;
......
......@@ -384,6 +384,7 @@ class AAgents extends BaseModel
->where($params)
->select();
//echo Db::table($this->table)->getLastSql();
//dump($this->getLastSql());
return $result;
}
......@@ -940,4 +941,25 @@ class AAgents extends BaseModel
}
return $result;
}
/**
* 获取经纪人数量
*
* @param $params
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getAgentsCountByStoreId($params)
{
$result = Db::table($this->table)
->field("id,name")
->where($params)
->count();
//echo Db::table($this->table)->getLastSql();
//dump($this->getLastSql());
return $result;
}
}
\ No newline at end of file
......@@ -185,12 +185,12 @@ class OReportModel extends Model
//todo 约带看人姓名
if (!empty($params['report_agent_name'])) {
$conditions[] = "aaa.report_agent_name LIKE '%".$params['name']."%'";
$conditions[] = "aaa.report_agent_name LIKE '%".$params['report_agent_name']."%'";
}
//todo 约带看人手机号
if (!empty($params['phone'])) {
$conditions[] = "aaa.phone LIKE '%".$params['phone']."%'";
$conditions[] = "aaa.report_agent_phone LIKE '%".$params['report_agent_phone']."%'";
}
//todo 商铺名
if (!empty($params['house_title'])) {
......@@ -512,7 +512,7 @@ class OReportModel extends Model
AND `a`.`status` = 0
AND `b`.`is_del` = 0
) ) as aaa $where_params";
var_dump($sql);
$result = $this->db->query($sql);
//echo $this->getLastSql();
......
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