diff --git a/Application/Admin/Controller/FinancialSummarySetController.class.php b/Application/Admin/Controller/FinancialSummarySetController.class.php index a71d04f64..b00f4a819 100644 --- a/Application/Admin/Controller/FinancialSummarySetController.class.php +++ b/Application/Admin/Controller/FinancialSummarySetController.class.php @@ -15,10 +15,7 @@ class FinancialSummarySetController extends \Think\Controller public $year;//年份 public $adddata;//要添加的数据 //数据库 - public $model; public $FinancialSummaryModel; - - public $continue=false;//单元测试,开启后可访问独立函数测试 public function _initialize(){ //初始化 $this->beginThismonth = mktime(0,0,0,date('m')-1,1,date('Y')); @@ -29,7 +26,6 @@ class FinancialSummarySetController extends \Think\Controller $this->date = $this->year."-".$this->month; $this->nowdata =time(); - $this->model =M(); $this->FinancialSummaryModel =M("FinancialSummary",'tab_'); $this->DepositModel =M("Deposit",'tab_'); $this->SpendModel = M("Spend",'tab_'); @@ -49,8 +45,9 @@ class FinancialSummarySetController extends \Think\Controller $this->date = $month; $tarry = explode('-',$month); $this->year= $tarry[0]; - $this->month= $tarry[1]; + if(strlen($tarry[1]) < 2) $tarry[1]="0".$tarry[1]; + $this->month= $tarry[1]; $this->beginThismonth=mktime(0,0,0,$tarry[1],1,$tarry[0]); $this->endThismonth=mktime(0,0,0,$tarry[1]-0+1,1,$tarry[0])-1; $this->reCount(); @@ -66,12 +63,10 @@ class FinancialSummarySetController extends \Think\Controller # code... //清理之前的聚合 $temp =array( - "count_date"=>$this->date + "count_year"=>$this->year, + "count_month"=>$this->month ); - - $this->gamemodel->where($temp)->delete(); - $this->usermodel->where($temp)->delete(); - $this->monthmodel->where($temp)->delete(); + $this->FinancialSummaryModel->where($temp)->delete(); echo "重置成功执行重新生成:"; } @@ -84,13 +79,10 @@ class FinancialSummarySetController extends \Think\Controller set_time_limit(0); $t1 = microtime(true); //判断是否已经聚合 - // $countRes = M("spend_count","tab_")->field("count(*) date_count")->where("count_date = '{$this->date}'")->find()['date_count']; - // $countUserRes = M("spend_user_count","tab_")->field("count(*) date_count")->where("count_date = '{$this->date}'")->find()['date_count']; - // if($countRes > 0 || $countUserRes >0){ - // die("error:Repeated statistics,msg:{$this->date}已经聚合过"); - // } - $this->model->startTrans(); - $this->continue =true; + $countRes = $this->FinancialSummaryModel->field("IFNULL(COUNT(*),0) count")->where("count_year = '{$this->year}' and count_month= '{$this->month}'")->find()['count']; + if($countRes > 0){ + die("error:Repeated statistics,msg:{$this->date}已经聚合过"); + } //按收入类型 $this->setIncomeMoney(); @@ -98,9 +90,9 @@ class FinancialSummarySetController extends \Think\Controller $this->setPromoteMoney(); //支付渠道/支付类型 $this->setPayWayMoney(); - //执行 - dump($this->adddata); - $this->model->commit(); + //存入数据 + $this->addDb(); + $t2 = microtime(true); die("success runtime:".round($t2-$t1,3).'s'); } @@ -113,19 +105,11 @@ class FinancialSummarySetController extends \Think\Controller $this->getBalanceCoinIncome(); $this->getGameSupersignIncome(); $this->getTestUserIncome(); - - # code... + $this->getRewardRecordIncome(); } //现金充值及平台币消耗 protected function getCashAndBalanCoinSpend() { - $temparr = array( - "type"=>1, - "count_month"=>$this->month, - "count_year"=>$this->year, - "create_time"=>$this->nowdata - ); - $map = array( "pay_time"=> array('BETWEEN',array($this->beginThismonth, $this->endThismonth)), @@ -135,14 +119,15 @@ class FinancialSummarySetController extends \Think\Controller ->field("IFNULL(SUM(CASE WHEN pay_way > 0 THEN pay_amount ELSE 0 END),0) as cash_count,IFNULL(SUM(CASE WHEN pay_way = 0 THEN pay_amount ELSE 0 END),0) as balance_coin_count") ->where($map) ->find(); - $cash_spend = $temparr; $cash_spend["key_name"] = "cash_spend"; + $cash_spend["type"] = 1; + $cash_spend["sort"] = 1; $cash_spend["sum_money"] = $res['cash_count']; $this->adddata[]=$cash_spend; - $balance_coin_spend = $temparr; $balance_coin_spend["key_name"] = "balance_coin_spend"; + $balance_coin_spend["type"] = 1; $balance_coin_spend["sort"] = 2; $balance_coin_spend["sum_money"] = $res['balance_coin_count']; $this->adddata[]=$balance_coin_spend; @@ -154,9 +139,6 @@ class FinancialSummarySetController extends \Think\Controller "key_name"=>'balance_coin_income', "type"=>1, "sort"=>3, - "count_month"=>$this->month, - "count_year"=>$this->year, - "create_time"=>$this->nowdata ); $map = array( "create_time"=> array('BETWEEN',array($this->beginThismonth, $this->endThismonth)), @@ -179,9 +161,6 @@ class FinancialSummarySetController extends \Think\Controller "key_name"=>'game_supersign_income', "type"=>1, "sort"=>4, - "count_month"=>$this->month, - "count_year"=>$this->year, - "create_time"=>$this->nowdata ); $map = array( "pay_time"=> array('BETWEEN',array($this->beginThismonth, $this->endThismonth)), @@ -196,10 +175,7 @@ class FinancialSummarySetController extends \Think\Controller $temparr = array( "key_name"=>'test_user_income', "type"=>1, - "sort"=>5, - "count_month"=>$this->month, - "count_year"=>$this->year, - "create_time"=>$this->nowdata + "sort"=>5 ); //获取测试白名单 $testlist = M("TestWhiteList",'tab_')->field("user_id")->select(); @@ -229,6 +205,33 @@ class FinancialSummarySetController extends \Think\Controller $temparr['sum_money'] = number_format(($cash_spend*100+$deposit*100)/100, 2, '.', ''); $this->adddata[]=$temparr; } + //奖罚收入 + protected function getRewardRecordIncome() + { + $map = array( + "reward_time"=> array('BETWEEN',array($this->beginThismonth, $this->endThismonth)), + ); + $rrres = M("RewardRecord","tab_") + ->field(" + IFNULL(SUM(CASE WHEN reward_type = 1 THEN money ELSE 0 END),0) as reward_count, + IFNULL(SUM(CASE WHEN reward_type = 2 THEN money ELSE 0 END),0) as fine_count + ") + ->where($map) + ->find(); + //奖励负,惩罚正 + $this->adddata[] = array( + "key_name"=>'reward_count', + "type"=>1, + "sort"=>6, + 'sum_money'=>$rrres['reward_count'] + ); + $this->adddata[] = array( + "key_name"=>'fine_count', + "type"=>1, + "sort"=>7, + 'sum_money'=>$rrres['fine_count'] + ); + } /** * 获取类型为2,3的数据/按合作方类型 */ @@ -265,22 +268,22 @@ class FinancialSummarySetController extends \Think\Controller //处理数据 $this->adddata[] = array( "key_name"=>'inside_count', - "type"=>2,"sort"=>1,"count_month"=>$this->month,"count_year"=>$this->year,"create_time"=>$this->nowdata, + "type"=>2,"sort"=>1, "sum_money"=>number_format($inside_count/100, 2, '.', '') ); $this->adddata[] = array( "key_name"=>'outer_count', - "type"=>2,"sort"=>2,"count_month"=>$this->month,"count_year"=>$this->year,"create_time"=>$this->nowdata, + "type"=>2,"sort"=>2, "sum_money"=>number_format($outer_count/100, 2, '.', '') ); $this->adddata[] = array( "key_name"=>'inside_count', - "type"=>3,"sort"=>1,"count_month"=>$this->month,"count_year"=>$this->year,"create_time"=>$this->nowdata, + "type"=>3,"sort"=>1, "sum_money"=>number_format($inside_nobind_count/100, 2, '.', '') ); $this->adddata[] = array( "key_name"=>'outer_count', - "type"=>3,"sort"=>2,"count_month"=>$this->month,"count_year"=>$this->year,"create_time"=>$this->nowdata, + "type"=>3,"sort"=>2, "sum_money"=>number_format($outer_nobind_count/100, 2, '.', '') ); } @@ -304,37 +307,37 @@ class FinancialSummarySetController extends \Think\Controller $moneyarry['zfb'] = ($moneyarry['gfzfb']-0+$moneyarry['sqzfb']); $this->adddata[] = array( "key_name"=>'gfwx_count', - "type"=>4,"sort"=>1,"count_month"=>$this->month,"count_year"=>$this->year,"create_time"=>$this->nowdata, + "type"=>4,"sort"=>1, "sum_money"=>number_format($moneyarry['wx']/100, 2, '.', '') ); $this->adddata[] = array( "key_name"=>'gfzfb_count', - "type"=>4,"sort"=>2,"count_month"=>$this->month,"count_year"=>$this->year,"create_time"=>$this->nowdata, + "type"=>4,"sort"=>2, "sum_money"=>number_format($moneyarry['gfzfb']/100, 2, '.', '') ); $this->adddata[] = array( "key_name"=>'sqzfb_count', - "type"=>4,"sort"=>3,"count_month"=>$this->month,"count_year"=>$this->year,"create_time"=>$this->nowdata, + "type"=>4,"sort"=>3, "sum_money"=>number_format($moneyarry['sqzfb']/100, 2, '.', '') ); $this->adddata[] = array( "key_name"=>'sqkj_count', - "type"=>4,"sort"=>4,"count_month"=>$this->month,"count_year"=>$this->year,"create_time"=>$this->nowdata, + "type"=>4,"sort"=>4, "sum_money"=>number_format($moneyarry['sqkj']/100, 2, '.', '') ); $this->adddata[] = array( "key_name"=>'wx_count', - "type"=>5,"sort"=>1,"count_month"=>$this->month,"count_year"=>$this->year,"create_time"=>$this->nowdata, + "type"=>5,"sort"=>1, "sum_money"=>number_format($moneyarry['wx']/100, 2, '.', '') ); $this->adddata[] = array( "key_name"=>'zfb_count', - "type"=>5,"sort"=>2,"count_month"=>$this->month,"count_year"=>$this->year,"create_time"=>$this->nowdata, + "type"=>5,"sort"=>2, "sum_money"=>number_format($moneyarry['zfb']/100, 2, '.', '') ); $this->adddata[] = array( "key_name"=>'kj_count', - "type"=>5,"sort"=>3,"count_month"=>$this->month,"count_year"=>$this->year,"create_time"=>$this->nowdata, + "type"=>5,"sort"=>3, "sum_money"=>number_format($moneyarry['sqkj']/100, 2, '.', '') ); } @@ -417,5 +420,17 @@ class FinancialSummarySetController extends \Think\Controller $moneyarry['wx'] += $dbres['wx_count']; $moneyarry['gfzfb'] += $dbres['zfb_count']; } + public function addDb() + { + foreach ($this->adddata as $k=> &$v) { + $v["count_month"] = $this->month; + $v["count_year"] = $this->year; + $v["create_time"] = $this->nowdata; + } + $res = $this->FinancialSummaryModel->addAll($this->adddata); + if(!$res){ + echo "DB save error"; + } + } }