Commit 6abdb601 authored by zhuwei's avatar zhuwei

service

parent 3d3c8170
......@@ -9,6 +9,7 @@ namespace app\index\controller;
* Time: 15:40:20
*/
use app\index\extend\Basic;
use app\index\service\OperationDataService;
use app\model\AAgents;
use app\model\ADistrict;
use app\model\AUserCallAgent;
......@@ -369,6 +370,15 @@ class OperationData extends Basic
return $this->response("101", $checkResult);
}
//验证时间是否合法
if(!checkTimeData($params['time_start'])){
return $this->response("101", '开始日期异常!');
}
//验证时间是否合法
if(!checkTimeData($params['time_end'])){
return $this->response("101", '结束日期异常!');
}
$time_start = $params['time_start'];
$time_end = $params['time_end'];
......@@ -379,8 +389,8 @@ class OperationData extends Basic
$real_performance_time_end = $params['real_performance_time_end'];
//要计算的所有月份
$month_num = $this->diffDate($time_start, $time_end);
$s_operation_data = new OperationDataService();
$month_num = $s_operation_data->diffDate($time_start, $time_end);
$return = [
[ 'city' => '上海市', 'site_id' => '10001', 'value' => [] ],
......@@ -454,61 +464,7 @@ class OperationData extends Basic
}
/**
* 找出两个日期之间的所有的月份
* @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;
}
......
<?php
/**
* Created by PhpStorm.
* User: zhuwei
* Date: 2019-10-14
* Time: 15:04:42
*/
namespace app\index\service;
class OperationDataService
{
protected $m_user;
protected $m_user_agent;
public function __construct()
{
}
/**
* 找出两个日期之间的所有的月份
* @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
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