新增旧月份统计方法

master
chenzhi 5 years ago
parent 3703d7040b
commit aaf67b85cc

@ -17,6 +17,7 @@ class FinancialSummarySetController extends \Think\Controller
//数据库 //数据库
public $FinancialSummaryModel; public $FinancialSummaryModel;
public function _initialize(){ public function _initialize(){
//初始化 //初始化
$this->beginThismonth = mktime(0,0,0,date('m')-1,1,date('Y')); $this->beginThismonth = mktime(0,0,0,date('m')-1,1,date('Y'));
$this->endThismonth = mktime(0,0,0,date('m'),1,date('Y'))-1; $this->endThismonth = mktime(0,0,0,date('m'),1,date('Y'))-1;
@ -25,7 +26,7 @@ class FinancialSummarySetController extends \Think\Controller
$this->month= date('m',$temp); $this->month= date('m',$temp);
$this->date = $this->year."-".$this->month; $this->date = $this->year."-".$this->month;
$this->nowdata =time(); $this->nowdata =time();
$this->FinancialSummaryModel =M("FinancialSummary",'tab_'); $this->FinancialSummaryModel =M("FinancialSummary",'tab_');
$this->DepositModel =M("Deposit",'tab_'); $this->DepositModel =M("Deposit",'tab_');
$this->SpendModel = M("Spend",'tab_'); $this->SpendModel = M("Spend",'tab_');
@ -37,11 +38,12 @@ class FinancialSummarySetController extends \Think\Controller
/** /**
* 更新某月数据 * 更新某月数据
*/ */
public function setMonthFinancialSummary() public function setMonthFinancialSummary($count_date)
{ {
$month = I("count_date"); $month = $count_date;
if(empty($month)) die("参数错误"); if(empty($month)) die("参数错误");
$this->adddata = [];//置空否者会脚本进来会重复计算
$this->date = $month; $this->date = $month;
$tarry = explode('-',$month); $tarry = explode('-',$month);
$this->year= $tarry[0]; $this->year= $tarry[0];
@ -94,7 +96,7 @@ class FinancialSummarySetController extends \Think\Controller
$this->addDb(); $this->addDb();
$t2 = microtime(true); $t2 = microtime(true);
die("success runtime:".round($t2-$t1,3).'s'); echo ("success {$this->date}:ok runtime:".round($t2-$t1,3).'s'.PHP_EOL);
} }
/** /**
* 获取类型为1的数据,按收入类型 * 获取类型为1的数据,按收入类型
@ -430,6 +432,8 @@ class FinancialSummarySetController extends \Think\Controller
$res = $this->FinancialSummaryModel->addAll($this->adddata); $res = $this->FinancialSummaryModel->addAll($this->adddata);
if(!$res){ if(!$res){
echo "DB save error"; echo "DB save error";
}else{
} }
} }

@ -1,4 +1,5 @@
<?php <?php
use Admin\FinancialSummarySetController;
namespace Admin\Controller; namespace Admin\Controller;
/** /**
@ -7,6 +8,20 @@ namespace Admin\Controller;
*/ */
class OldCountController extends \Think\Controller class OldCountController extends \Think\Controller
{ {
//财务分类汇总统计旧数据聚合
public function FinancialSummaryInit()
{
//清空数据库
$sql = "truncate table tab_financial_summary";
$res = M()->execute($sql);
echo "tab_financial_summary 清空成功".PHP_EOL;
//获取19年9月到上个月的所有月份
$monthList = $this->getMonthsList();
$Financial = new FinancialSummarySetController();
foreach ($monthList as $k => $v) {
$Financial->setMonthFinancialSummary($v);
}
}
//超级签订单新增识别微信或者支付宝2019-12-11 //超级签订单新增识别微信或者支付宝2019-12-11
public function gameSupersignPaywayInit() public function gameSupersignPaywayInit()
{ {
@ -87,5 +102,25 @@ class OldCountController extends \Think\Controller
} }
die("init ok"); die("init ok");
} }
//获取公司月结所需要的所有月份截止至上个月
public function getMonthsList()
{
$start_month = "2019-09";
$temp = strtotime(date('Y-m-01 00:00:00',strtotime('-1 month')));
$end_month = date('Y',$temp)."-".date('m',$temp);
$time_arr = [];
$begin = new \DateTime($start_month);
$end = new \DateTime($end_month);
$end = $end->modify('+1 month');
$interval = new \DateInterval('P1M');
$daterange = new \DatePeriod($begin, $interval ,$end);
foreach($daterange as $date){
$time_arr[] = $date->format("Y-m");
}
return $time_arr;
}
} }

Loading…
Cancel
Save