Commit bd7b8ede authored by clone's avatar clone

办公楼统计

parent 91e0ac56
......@@ -9,7 +9,7 @@ use think\Db;
class OfficeGRoom extends BaseModel
{
protected $table = 'office_g_room';
private $db_;
private $db_;
public function __construct($data = [])
{
......@@ -29,7 +29,7 @@ class OfficeGRoom extends BaseModel
if (empty($room_id)) {
return false;
}
return $this->editData(['is_rent'=>$is_rent], $room_id);
return $this->editData(['is_rent' => $is_rent], $room_id);
}
/**
......@@ -210,8 +210,8 @@ class OfficeGRoom extends BaseModel
if (empty($data['id'])) {
$save_data['operation_id'] = $agent_id; //上传人
$save_data['create_time'] = date('Y-m-d H:i:s');
$room_id = $this->db_->insertGetId($save_data);
$save_data['create_time'] = date('Y-m-d H:i:s');
$room_id = $this->db_->insertGetId($save_data);
} else {
try {
$save_data['update_time'] = date('Y-m-d H:i:s');
......@@ -256,8 +256,8 @@ class OfficeGRoom extends BaseModel
{
$result = $this->field($field)
->alias("a")
->join('office_g_building b', 'a.building_id=b.id','left')
->join('g_business_district c', 'b.business_district_id=c.id','left')
->join('office_g_building b', 'a.building_id=b.id', 'left')
->join('g_business_district c', 'b.business_district_id=c.id', 'left')
->where($params)
->find();
// dump($this->getLastSql());
......@@ -285,7 +285,7 @@ class OfficeGRoom extends BaseModel
* @param string $order_
* @return false|\PDOStatement|string|\think\Collection
*/
public function getMyBuildingRoom($field, $params,$pageSize,$pageNo,$order_='a.id desc')
public function getMyBuildingRoom($field, $params, $pageSize, $pageNo, $order_ = 'a.id desc')
{
$result = Db::table($this->table)
->field($field)
......@@ -293,7 +293,6 @@ class OfficeGRoom extends BaseModel
->join('office_g_building b', 'a.building_id = b.id', 'left')
->join('office_g_room_to_agent c', 'a.id = c.house_id', 'left')
->join('g_business_district d', 'b.business_district_id = d.id', 'left')
->where($params)
->order($order_)
->limit($pageSize)
......@@ -423,7 +422,8 @@ class OfficeGRoom extends BaseModel
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getRoomBuilding($pageNo = 1, $pageSize = 15, $order_ = 'a.id desc', $field = '', $params = '') {
public function getRoomBuilding($pageNo = 1, $pageSize = 15, $order_ = 'a.id desc', $field = '', $params = '')
{
$params['b.is_del'] = 0;
return $this->field($field)
->alias('a')
......@@ -449,7 +449,7 @@ class OfficeGRoom extends BaseModel
return $data = $this
->field($field)
->alias("a")
->join("office_g_building b","a.building_id=b.id","left")
->join("office_g_building b", "a.building_id=b.id", "left")
->where($params)
->find();
}
......@@ -469,7 +469,7 @@ class OfficeGRoom extends BaseModel
{
return $data = $this->field($field)
->alias("a")
->join("office_g_building b","a.building_id=b.id","left")
->join("office_g_building b", "a.building_id=b.id", "left")
->where($params)
->order($order)
->limit($pageSize)
......@@ -490,10 +490,10 @@ class OfficeGRoom extends BaseModel
$result = Db::table($this->table)
->field($field)
->alias("a")
->join("office_g_building b","a.building_id=b.id","left")
->join("office_g_building b", "a.building_id=b.id", "left")
->where($params)
->select();
// echo $this->getLastSql();
// echo $this->getLastSql();
return $result;
}
......@@ -504,7 +504,8 @@ class OfficeGRoom extends BaseModel
* @throws \think\Exception
* @throws \think\exception\PDOException
*/
public function updateData($data, $where) {
public function updateData($data, $where)
{
return $this->db_->where($where)->update($data);
}
......@@ -516,9 +517,37 @@ class OfficeGRoom extends BaseModel
public function getHouseColumn($field, $params)
{
return $this->db_->alias("a")
->join("office_g_building b","a.building_id=b.id","left")
->join("office_g_building b", "a.building_id=b.id", "left")
->where($params)
->column($field);
}
/**
* 获取添加的办公楼的每天数量
* @param $params
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getAddHouseNumGroupTimeNew($params)
{
$field = "count(1) as num";
$where_ = [];
$where_["status"] = array('neq', 3);
if (isset($params["agent_id"])) {
$where_["operation_id"] = $params["agent_id"];
}
if (isset($params["create_time"])) {
$where_["create_time"] = $params["create_time"];
}
$result = $this->db_
->field($field)
->where($where_)
->select();
//echo $this->getLastSql();
return $result;
}
}
......@@ -584,8 +584,8 @@ class OfficeOBargainModel extends Model
return Db::table($this->table)
->field($field)
->alias("a")
->join("o_partial_commission b", "a.id=b.bargain_id", "right")
->join('o_real_income c', 'b.real_income_id = c.id', 'left')
->join("office_o_partial_commission b", "a.id=b.bargain_id", "right")
->join('office_o_real_income c', 'b.real_income_id = c.id', 'left')
->where($where_)
->select();
}
......
......@@ -240,10 +240,6 @@ class ResultsSummaryNewTask
}
}
private function save(){
}
/* public function test()
......
<?php
namespace app\task\controller;
use app\extra\RedisExt;
use app\model\AAgents;
use app\model\ASuperviseModel;
use app\model\GHouses;
use app\model\OBargainModel;
use app\model\OfficeGRoom;
use app\model\OfficeOBargainModel;
use app\model\OfficeOMarchInModel;
use app\model\OfficeOPayLogModel;
use app\model\OfficeOReportModel;
use app\model\OfficeTAgentTotalModel;
use app\model\OfficeUPhoneFollowUp;
use app\model\OMarchInModel;
use app\model\OPayLogModel;
use app\model\OReportModel;
use app\model\TAgentTotalModel;
use app\model\UPhoneFollowUp;
use app\model\UPhoneFollowUpTemporary;
use app\model\Users;
use Think\Log;
use think\Request;
/**
* Created by PhpStorm.
* User : zw
* Date : 2019/06/24
* Time : 上午10:07
* Intro:
*/
class ResultsSummaryOfficeTask
{
private $agentsModel;
private $tAgentTotalModel;
private $houseModel;
private $userModel;
private $bargainModel;
private $reportModel;
private $marchInModel;
private $payLogModel;
private $superviseModel;
private $redis_;
function __construct()
{
$this->agentsModel = new AAgents();
$this->tAgentTotalModel = new OfficeTAgentTotalModel();
$this->houseModel = new OfficeGRoom();
$this->userModel = new Users();
$this->bargainModel = new OfficeOBargainModel();
$this->reportModel = new OfficeOReportModel();
$this->marchInModel = new OfficeOMarchInModel();
$this->payLogModel = new OfficeOPayLogModel();
$this->redis_ = RedisExt::getRedis();
$this->superviseModel = new ASuperviseModel();
}
public function totalAgentResults()
{
set_time_limit(0); // 取消脚本运行时间的超时上限
$day = date("Y-m-d", time());
Log::record("-------run_total_office----".$this->redis_->get("run_total_office" . $day),"info");
if ($this->redis_ && $this->redis_->get("run_total_office" . $day)) {
return;
}
$this->redis_->set("run_total_office" . $day, 1, 3600);
//todo 按小时统计
//todo 1.分页查询经纪人, 2遍历执行,判断一个经纪人在统计表最后一条统计数据的日期
//TODO 3.日期加一天并判断是否大于等于当前时间大于return 4.执行此日期的统计,5.当次日期小于当前日期,递归日期加一。继续统计
$total = $this->agentsModel->getAgentsCountByTask();
$pageSize = 20;
$pageTotal = ceil($total / $pageSize);
for ($pageNo = 1; $pageNo <= $pageTotal; $pageNo++) {
$resultArr = $this->agentsModel->getAgentsListByTask($pageNo, $pageSize, "id,store_id,district_id,site_id");
$this->executeTotal($resultArr, null);
unset($resultArr);
}
unset($this->agentsModel);
unset($this->tAgentTotalModel);
unset($this->houseModel);
unset($this->userModel);
unset($this->bargainModel);
unset($this->reportModel);
unset($this->marchInModel);
unset($this->payLogModel);
return;
}
public function totalAgentResultsByTime()
{
set_time_limit(0); // 取消脚本运行时间的超时上限
$total_time = $_GET["total_time"];
$total = $this->agentsModel->getAgentsCountByTask();
$pageSize = 20;
$pageTotal = ceil($total / $pageSize);
for ($pageNo = 1; $pageNo <= $pageTotal; $pageNo++) {
$resultArr = $this->agentsModel->getAgentsListByTask($pageNo, $pageSize, "id,store_id,district_id,site_id");
$this->executeTotal($resultArr, $total_time);
unset($resultArr);
}
unset($this->agentsModel);
unset($this->tAgentTotalModel);
unset($this->houseModel);
unset($this->userModel);
unset($this->bargainModel);
unset($this->reportModel);
unset($this->marchInModel);
unset($this->payLogModel);
}
public function totalAgentResultsByYesterday()
{
set_time_limit(0); // 取消脚本运行时间的超时上限
$total_time = date("Y-m-d",strtotime("-1 day"));
$total = $this->agentsModel->getAgentsCountByTask();
$pageSize = 20;
$pageTotal = ceil($total / $pageSize);
for ($pageNo = 1; $pageNo <= $pageTotal; $pageNo++) {
$resultArr = $this->agentsModel->getAgentsListByTask($pageNo, $pageSize, "id,store_id,district_id,site_id");
$this->executeTotal($resultArr, $total_time);
unset($resultArr);
}
unset($this->agentsModel);
unset($this->tAgentTotalModel);
unset($this->houseModel);
unset($this->userModel);
unset($this->bargainModel);
unset($this->reportModel);
unset($this->marchInModel);
unset($this->payLogModel);
}
/**
*同城调门店转业绩
* @param $agent_id
* @param $store_id
* @param $district_id
* @param $start_time
* @param $end_time
* @return bool
*/
public function updateStoreByAgentId($agent_id,$store_id,$district_id,$start_time,$end_time){
$date = floor((strtotime($end_time)-strtotime($start_time))/86400);
if($date > 31) {
return false;
}
$params["district_id"] = $district_id;
$params["store_id"] = $store_id;
$where["agent_id"] = $agent_id;
$where["total_time"] = array("between",array($start_time, $end_time));
$is_ok = $this->tAgentTotalModel->updateTotal($params,$where);
if($is_ok > 0 ){
return true;
}
return false;
}
/**
* @param $agent_id
* @param $store_id
* @param $district_id
* @param $total_time string 比如修改了数据如成交报告,成交报告提交时间是昨天那么这里的时间就是昨天
* @param $site_id
*/
public function updateTotalByAgentId($agent_id, $store_id, $district_id, $total_time,$site_id)
{
$params[0]["id"] = $agent_id;
$params[0]["store_id"] = $store_id;
$params[0]["district_id"] = $district_id;
$params[0]["site_id"] = $site_id;
/* $params[0]["id"] = 5439;
$params[0]["store_id"] = 92;
$params[0]["district_id"] = 2;
$total_time = '2018-08-15';*/
$this->executeTotal($params, $total_time);
}
private function executeTotal($resultArr, $total_time)
{
$start_total_time = date("Y-m-d 00:00:00", time());
$end_total_time = date("Y-m-d H:i:s", time());
if (!empty($total_time)) {
$start_total_time = $total_time . " 00:00:00";
$end_total_time = $total_time . " 23:59:59";
} else {
$total_time = date("Y-m-d", time());
}
$insertArr = $updateArr = [];
foreach ($resultArr as $key => $value) {
$param["agent_id"] = $value["id"];
$param["is_del"] = 0;
$param["total_time"] = $total_time;
$total_time_arr = $this->tAgentTotalModel->getTotalEndTimeByAgentId("id,total_time", $param);
$id = 0;
if (count($total_time_arr) > 0) {
$id = $total_time_arr[0]["id"];
}
if (empty($value["id"]) || empty($value["district_id"]) || empty($value["store_id"])) {
continue;
}
$agent_id = $value["id"];
$district_id = $value["district_id"];
$store_id = $value["store_id"];
$site_id = $value["site_id"];
//todo 查询时间段的数据
$result = $this->selectTotal($agent_id, $district_id, $store_id, $start_total_time, $end_total_time,$site_id);
if (empty($result)) continue;
if ($id > 0) {
$result["id"] = $id;
unset($result["create_time"]);
//调配门店经纪人id不变,门店或区域id变动,所以修改数据不做修改门店和部门id
unset($result["district_id"]);
unset($result["store_id"]);
array_push($updateArr, $result);
} else {
array_push($insertArr, $result);
}
unset($result);
}
if (count($insertArr) > 0) {
$this->tAgentTotalModel->addTotal($insertArr);
}
if (count($updateArr) > 0) {
$this->tAgentTotalModel->saveTotal($updateArr);
}
}
private function save(){
}
/* public function test()
{
$params = $this->selectTotal(1, 1, 1, "2018-02-02", "2018-03-15");
$this->tAgentTotalModel->addTotal($params);
// dump($params);
}*/
private function selectTotal($agent_id, $district_id, $store_id, $start_total_time, $end_total_time,$site_id)
{
//todo 如果查询出这个时间段都为0 则给此经纪人插入条最后一个日期的为空的数据
$result_arr = [];
//房源
$params["agent_id"] = $agent_id;
$params['create_time'] = array( 'between', array( $start_total_time, $end_total_time ) );
$addHouseNum = $this->houseModel->getAddHouseNumGroupTimeNew($params);
$result_arr["house_num"] = $addHouseNum[0]["num"];
//dump($addHouseNum);
//客源
$addUserNum = $this->userModel->getAddUserNumGroupTimeNew($params);
$result_arr["user_num"] = $addUserNum[0]["num"];
//dump($addUserNum);
//业绩
$performanceSum = $this->bargainModel->getAddBargainNumGroupTimeNew($params, 1);//1表示业绩 2表示实收
// dump($performanceSum);
$result_arr["performance_sum"] = $performanceSum[0]["num"];
//实收
$receivedSum = $this->bargainModel->getReceivedGroupTimeNew($params);
$result_arr["received_sum"] = empty($receivedSum[0]["num"]) ? "" : $receivedSum[0]["num"];
//dump($receivedSum);
//约带看
$reportNum = $this->reportModel->getAddReportNumGroupTimeNew($params);
$result_arr["report_num"] = $reportNum[0]["num"];
//dump($reportNum);
//进场
$addMarchInNum = $this->marchInModel->getAddMarchInNumGroupTimeNew($params);
$result_arr["addMarch_in_num"] = $addMarchInNum[0]["num"];
//dump($addMarchInNum);
//收款
$payLogNum = $this->payLogModel->getAddPayLogNumGroupTimeNew($params);
$result_arr["pay_log_num"] = $payLogNum[0]["num"];
//dump($payLogNum);
// 监督
$supervision_num = $this->superviseModel->getAddPayLogNumGroupTimeNew($params);
$result_arr["supervision_num"] = $supervision_num[0]["num"];
//成交报告
$bargainSum = $this->bargainModel->getAddBargainNumGroupTimeNew($params, 3);//表示统计
$result_arr["bargain_sum"] = $bargainSum[0]["num"];
//电话跟进数
$uFollowModel = new OfficeUPhoneFollowUp($site_id);
$followUp = $uFollowModel->getFollowTotal($params);
$result_arr["followUp_sum"] = $followUp;
return $this->binAgentModel($agent_id, $district_id, $store_id, $result_arr, $start_total_time);
}
private function binAgentModel($agent_id, $district_id, $store_id, $result_arr, $start_total_time)
{
$params = [];
if (!empty($result_arr["house_num"]) || !empty($result_arr["user_num"]) || !empty($result_arr["performance_sum"]) ||
!empty($result_arr["received_sum"]) || !empty($result_arr["report_num"]) || !empty($result_arr["addMarch_in_num"]) ||
!empty($result_arr["pay_log_num"]) || !empty($result_arr["supervision_num"]) || !empty($result_arr["bargain_sum"])
|| !empty($result_arr["followUp_sum"])) {
$params["district_id"] = $district_id;
$params["store_id"] = $store_id;
$params["agent_id"] = $agent_id;
$params["total_time"] = $start_total_time;
$params["create_time"] = date("Y-m-d H:i:s", time());
$params["update_time"] = date("Y-m-d H:i:s", time());
$params["add_house_num"] = !empty($result_arr["house_num"]) ? $result_arr["house_num"] : 0;
$params["add_user_num"] = !empty($result_arr["user_num"]) ? $result_arr["user_num"] : 0;
$params["performance"] = !empty($result_arr["performance_sum"]) ? $result_arr["performance_sum"] : 0;
$params["official_receipts"] = !empty($result_arr["received_sum"]) ? $result_arr["received_sum"] : 0;
$params["look_at_num"] = !empty($result_arr["report_num"]) ? $result_arr["report_num"] : 0;
$params["march_in_num"] = !empty($result_arr["addMarch_in_num"]) ? $result_arr["addMarch_in_num"] : 0;
$params["paylog"] = !empty($result_arr["pay_log_num"]) ? $result_arr["pay_log_num"] : 0;
$params["supervision_num"] = !empty($result_arr["supervision_num"]) ? $result_arr["supervision_num"] : 0;
$params["bargain_sum"] = !empty($result_arr["bargain_sum"]) ? $result_arr["bargain_sum"] : 0;
$params["followUp_sum"] = !empty($result_arr["followUp_sum"]) ? $result_arr["followUp_sum"] : 0;
}
unset($result_arr);
return $params;
}
/**
* 根据bargain_id统计
*
* @param Request $request
* @return false|string
*/
public function updateBargainPerformance(Request $request) {
try {
$bargain_id = $request->get('bargain_id');
if (empty($bargain_id)) {
return json_encode([ 'code' => 101, 'msg' => 'params is error' ]);
}
$data['msg'] = '';
$where = $update_data = [];
if ($bargain_id) {
$where['b.id'] = $bargain_id;
}
if (!empty($where)) {
//获取被修改人信息
$agent_data = $this->agentsModel->agentBargainAll('a.id,a.store_id,a.district_id,b.create_time', $where);
foreach ($agent_data as $k=>$v) {
$create_time = date('Y-m-d', strtotime($v['create_time']));
$this->totalOfficialReceipts($v['id'], $v['district_id'], $v['store_id'], $create_time);
}
}
$data['code'] = 200;
} catch (\Exception $e) {
$data['code'] = 101;
$data['msg'] = '内部错误:'.$e->getMessage();
}
return json_encode([ 'code' => $data['code'], 'msg' => $data['msg']]);
}
/**
* (临时处理)业绩统计-实收统计
*
* @param $agent_id
* @param $district_id
* @param $store_id
* @param $date
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function totalOfficialReceipts($agent_id, $district_id, $store_id, $date) {
//获取被修改人信息
$date = date('Y-m-d', strtotime($date));
$update_data = [];
$where_bargain['agent_id'] = $agent_id;
$where_bargain['create_time'] = ['BETWEEN', [$date.' 00:00:00', $date.' 23:59:59']];
//实收
$receivedSum = $this->bargainModel->getAddBargainNumGroupTimeNew($where_bargain, 2); //1表示业绩 2表示实收
$received_sum = empty($receivedSum[0]["num"]) ? 0 : $receivedSum[0]["num"];
//业绩
$performanceSum = $this->bargainModel->getAddBargainNumGroupTimeNew($where_bargain, 1);//1表示业绩 2表示实收
$performance_sum = empty($performanceSum[0]["num"])? 0:$performanceSum[0]["num"];
$id = $this->tAgentTotalModel->getTotalEndTimeByAgentId('id', ['total_time'=>$date, 'agent_id'=>$where_bargain['agent_id']]);
if (empty($id[0]['id'])) {
$insert_data[] = [
'store_id' => $store_id,
'district_id' => $district_id,
'agent_id' => $agent_id,
'official_receipts' => $received_sum,
'performance' => $performance_sum,
'total_time' => $date,
'create_time' => date('Y-m-d H:i:s')
];
$this->tAgentTotalModel->addTotal($insert_data);
} else {
$update_data[] = [
'official_receipts' => $received_sum,
'performance' => $performance_sum,
'id' => $id[0]['id'],
'update_time' => date('Y-m-d H:i:s')
];
$this->tAgentTotalModel->saveTotal($update_data);
}
return ;
}
}
\ No newline at end of file
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