Commit 5330c2e1 authored by zhuwei's avatar zhuwei

1

parent a1420fd2
......@@ -16,6 +16,7 @@ use app\model\ChatRelation;
use app\model\GHouses;
use app\model\OBargainModel;
use app\model\OMarchInModel;
use app\model\TAgentTotalModel;
use app\model\Users;
class OperationData extends Basic
......@@ -355,43 +356,163 @@ class OperationData extends Basic
{
header('Access-Control-Allow-Origin:*');
$params = $this->params;
$time_start = $params['time_start'];
$time_end = $params['time_end'];
$performance_time_start = $params['performance_time_start'];
$performance_time_end = $params['performance_time_end'];
$real_performance_time_start = $params['real_performance_time_start'];
$real_performance_time_end = $params['real_performance_time_end'];
//要计算的所有月份
$month_num = $this->diffDate($time_start, $time_end);
$return = [
[ 'city' => '上海市', 'site_id' => '10001', 'value' => [] ],
[ 'city' => '杭州市', 'site_id' => '10002', 'value' => [] ],
[ 'city' => '深圳市', 'site_id' => '10003', 'value' => [] ],
[ 'city' => '广州市', 'site_id' => '10004', 'value' => [] ],
[ 'city' => '北京市', 'site_id' => '10005', 'value' => [] ],
[ 'city' => '汇总', 'site_id' => '', 'value' => [] ],
];
$m_total = new TAgentTotalModel();
$m_agent = new AAgents();
$params = $this->params;//time_start time_end
$return = ['上海'=>[
[ 'time' => '2019-10-10 - 2019-10-10', 'people_num' => 123,'performanceSum' => 123, 'real_performanceSum' => 123 ],
[ 'time' => '2019-10-10 - 2019-10-10', 'people_num' => 123,'performanceSum' => 123, 'real_performanceSum' => 123 ],
[ 'time' => '2019-10-10 - 2019-10-10', 'people_num' => 123,'performanceSum' => 123, 'real_performanceSum' => 123 ],
[ 'time' => '2019-10-10 - 2019-10-10', 'people_num' => 123,'performanceSum' => 123, 'real_performanceSum' => 123 ],
],'杭州'=>[
[ 'time' => '2019-10-10 - 2019-10-10', 'people_num' => 123,'performanceSum' => 123, 'real_performanceSum' => 123 ],
[ 'time' => '2019-10-10 - 2019-10-10', 'people_num' => 123,'performanceSum' => 123, 'real_performanceSum' => 123 ],
[ 'time' => '2019-10-10 - 2019-10-10', 'people_num' => 123,'performanceSum' => 123, 'real_performanceSum' => 123 ],
[ 'time' => '2019-10-10 - 2019-10-10', 'people_num' => 123,'performanceSum' => 123, 'real_performanceSum' => 123 ],
],'深圳'=>[
[ 'time' => '2019-10-10 - 2019-10-10', 'people_num' => 123,'performanceSum' => 123, 'real_performanceSum' => 123 ],
[ 'time' => '2019-10-10 - 2019-10-10', 'people_num' => 123,'performanceSum' => 123, 'real_performanceSum' => 123 ],
[ 'time' => '2019-10-10 - 2019-10-10', 'people_num' => 123,'performanceSum' => 123, 'real_performanceSum' => 123 ],
[ 'time' => '2019-10-10 - 2019-10-10', 'people_num' => 123,'performanceSum' => 123, 'real_performanceSum' => 123 ],
],'广州'=>[
[ 'time' => '2019-10-10 - 2019-10-10', 'people_num' => 123,'performanceSum' => 123, 'real_performanceSum' => 123 ],
[ 'time' => '2019-10-10 - 2019-10-10', 'people_num' => 123,'performanceSum' => 123, 'real_performanceSum' => 123 ],
[ 'time' => '2019-10-10 - 2019-10-10', 'people_num' => 123,'performanceSum' => 123, 'real_performanceSum' => 123 ],
[ 'time' => '2019-10-10 - 2019-10-10', 'people_num' => 123,'performanceSum' => 123, 'real_performanceSum' => 123 ],
],'北京'=>[
[ 'time' => '2019-10-10 - 2019-10-10', 'people_num' => 123,'performanceSum' => 123, 'real_performanceSum' => 123 ],
[ 'time' => '2019-10-10 - 2019-10-10', 'people_num' => 123,'performanceSum' => 123, 'real_performanceSum' => 123 ],
[ 'time' => '2019-10-10 - 2019-10-10', 'people_num' => 123,'performanceSum' => 123, 'real_performanceSum' => 123 ],
[ 'time' => '2019-10-10 - 2019-10-10', 'people_num' => 123,'performanceSum' => 123, 'real_performanceSum' => 123 ],
],'汇总'=>[
[ 'time' => '2019-10-10 - 2019-10-10', 'people_num' => 123,'performanceSum' => 123, 'real_performanceSum' => 123 ],
[ 'time' => '2019-10-10 - 2019-10-10', 'people_num' => 123,'performanceSum' => 123, 'real_performanceSum' => 123 ],
[ 'time' => '2019-10-10 - 2019-10-10', 'people_num' => 123,'performanceSum' => 123, 'real_performanceSum' => 123 ],
[ 'time' => '2019-10-10 - 2019-10-10', 'people_num' => 123,'performanceSum' => 123, 'real_performanceSum' => 123 ],
]];
foreach ($return as $key => $v) {
$value = [];
foreach ($month_num as $month_key => $month_v) {
$value_ = [];
//业绩计算时间
$p_start = $month_v . '-' . $performance_time_start;
$p_end = $month_v . '-' . $performance_time_end;
//实收计算时间
$r_p_start = $month_v . '-' . $real_performance_time_start;
$r_p__end = $month_v . '-' . $real_performance_time_end;
// 业绩
$value_['performance_time'] = $p_start . '至' . $p_end;
if ($v['city'] == '汇总') {
$conditions['site_id'] = array('in','10001,10002,10003,10004,10005');
} else {
$conditions['site_id'] = $v['site_id'];
}
$conditions['site_id'] = $v['site_id'];
$conditions['create_time'] = array( 'between', array( $p_start . " 00:00:00", $p_end . " 23:59:59" ) );
$performanceSum = $m_total->performanceStatistics($conditions, 1);
$value_['performance'] = isset($performanceSum[0]["num"]) ? $performanceSum[0]["num"] : 0;
// 实收
$value_['performance_time'] = $p_start . '至' . $p_end;
if ($v['city'] == '汇总') {
$conditions['site_id'] = array('in','10001,10002,10003,10004,10005');
} else {
$conditions['site_id'] = $v['site_id'];
}
$conditions['site_id'] = $v['site_id'];
$conditions['create_time'] = array( 'between', array( $r_p_start . " 00:00:00", $r_p__end . " 23:59:59" ) );
$real_performanceSum = $m_total->performanceStatistics($conditions, 2);
$value_['real_performance'] = isset($real_performanceSum[0]["num"]) ? $real_performanceSum[0]["num"] : 0;
//人数
$params = [];
if ($v['city'] == '汇总') {
$params['site_id'] = array('in','10001,10002,10003,10004,10005');
} else {
$params['site_id'] = $v['site_id'];
}
$params['create_time'] = array( 'between', array( $month_v . "-01 00:00:00", $month_v . "-31 23:59:59" ) );
$agentsCount = $m_agent->getAgentsCountByStoreId($params);
$value_['people_num'] = isset($agentsCount) ? $agentsCount : 0;
$value[] = $value_;
}
$return[$key]['value'] = $value;
}
// $return = $this->sum($return);
return $this->response(200, 'success', $return);
}
function sum($date)
{
// $performance_count = 0;
// $real_performance_count = [];
$people_num_count = [];
foreach ($date as $key => $v) {
foreach ($v['value'] as $month_key => $month_v) {
$people_num_count['people_num'][]= ['index'=>$month_key,'val'=>$month_v['people_num']];
}
}
dump($people_num_count);
return $date;
}
/**
* 找出两个日期之间的所有的月份
* @param $date1
* @param $date2
* @return array
*/
function diffDate($date1, $date2) {
//首次进入将分割开始与结束日期。
$startDate = explode('-', $date1);
$endDate = explode('-', $date2);
$startYear = $startDate[0];
$endYear = $endDate[0];
$startMonth = $startDate[1];
$endMonth = $endDate[1];
$YmArr = [];
//同一年和跨年分开处理。
if($startYear != $endYear){
//找出跨年所有的月份
for ($year=$startYear; $year < $endYear; $year++) {
for ($month=$startMonth; $month <= 12; $month++) {
$lenth = strlen($month);
if($lenth != 2){
$month = '0'.$month;
}
$Ym = $year.'-'.$month;//拼接日期,根据自己需要的格式拼接。
$YmArr[] = $Ym;
}
$startMonth = 1; //跨年的时候重置月份
}
//找出本年到现在的所有月份
for ($nowMonth=1; $nowMonth <= $endMonth; $nowMonth++) {
$lenth = strlen($nowMonth);
if($lenth != 2){
$nowMonth = '0'.$nowMonth;
}
$nowYm = $endYear.$nowMonth;
$YmArr[] = $nowYm;
}
}else{
for ($nowMonth=$startMonth; $nowMonth <= $endMonth; $nowMonth++) {
$lenth = strlen($nowMonth);
if($lenth != 2){
$nowMonth = '0'.$nowMonth;
}
$nowYm = $endYear.'-'.$nowMonth;
$YmArr[] = $nowYm;
}
}
return $YmArr;
}
}
\ No newline at end of file
......@@ -1771,4 +1771,9 @@ class OBargainModel extends Model
->order("a.id asc")
->find();
}
}
\ No newline at end of file
......@@ -353,4 +353,31 @@ class TAgentTotalModel extends Model
return $result;
}
public function performanceStatistics($params,$type)
{
if($type == 1){
$field = "sum(a.performance) as performance_total";
}else{
$field = "sum(a.official_receipts) as official_receipts_total";
}
if (isset($params["create_time"])) {
$where_["a.create_time"] = $params["create_time"];
}
if (isset($params["site_id"])) {
$where_["b.site_id"] = $params["site_id"];
}
$where_['a.is_del'] = 0;
$return = Db::table($this->table)
->field($field)
->alias("a")
->join("a_agents b", "a.agent_id = b.id", "left")
->where($where_)
->select();
return $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