<?php/**
* Created by victor ma.
* User: victor ma
* Date: 2021/7/14
* Time: 16:17
*/namespaceapp\admin\controller;useapp\common\controller\Backend;usefast\Date;usethink\Log;classPoundRecordChartextendsBackend{protected$model=null;publicfunction_initialize(){parent::_initialize();$this->model=model('AdminLog');}/**
* 查看
*/publicfunctionindex(){try{\think\Db::execute("SET @@sql_mode='';");}catch(\Exception$e){}$date_column=[];$starttime=Date::unixtime('day',-12);$endtime=Date::unixtime('day',0,'end');$starttime1=date('Y-m-d',strtotime('-12 days'));//获取指定月份的第一天$endtime1=date('Y-m-d',strtotime('+1 days'));//获取指定月份的最后一天$joinlist=Db("view_pound_record")->where('created_at','between time',[$starttime1,$endtime1])->field('sum(settlement_weight) as nums, DATE_FORMAT(created_at, "%Y-%m-%d") AS created_date')->group('created_date')->select();$providerlist=Db("view_pound_record")->where('created_at','between time',[$starttime1,$endtime1])->where('weight_type','=',1)->field('place_name')->group('place_name')->select();for($time=$starttime;$time<=$endtime;){$date_column[]=date("Y-m-d",$time);$time+=86400;}$dailyCountList=array_fill_keys($date_column,0);foreach($joinlistas$k=>$v){$dailyCountList[$v['created_date']]=$v['nums'];}$place_weight_name_list=[];$series_array=[];foreach($providerlistas$k=>$v){$place_weight_name_list[$k]=$v['place_name'];$each_provider_list=Db("view_pound_record")->where('created_at','between time',[$starttime1,$endtime1])->where('place_name','=',$v['place_name'])->where('weight_type','=',1)->field('sum(settlement_weight) as total_settle_weight,DATE_FORMAT(created_at, "%Y-%m-%d") AS created_date')->group('created_date')->select();$each_place_daily_list1=array_fill_keys($date_column,0);foreach($each_provider_listas$kkk=>$vvv){$each_place_daily_list1[$vvv['created_date']]=intval($vvv['total_settle_weight']);}$series=newSeries();$series->name=$v['place_name'];$series->type='line';$series->stack='总数';$series->data=array_values($each_place_daily_list1);$series_array[]=$series;}$receiverlist=array_fill_keys($date_column,0);foreach($receiverlistas$k=>$v){$receiverlist[$v['weight_date']]=$v['nums'];}$this->view->assign(['total_record'=>\app\admin\model\PoundRecord::whereTime('created_at','today')->count(),'total_settlement_weight'=>\app\admin\model\PoundRecord::whereTime('created_at','today')->sum('settlement_weight')/1000,'total_should_money'=>\app\admin\model\PoundRecord::whereTime('created_at','today')->sum('should_price'),'total_actual_money'=>\app\admin\model\PoundRecord::whereTime('created_at','today')->sum('actual_price'),]);$this->assignconfig('column',array_keys($dailyCountList));$this->assignconfig('userdata',array_values($dailyCountList));$this->assignconfig('place_weight_name_list',array_values($place_weight_name_list));$this->assignconfig('place_weight_date_list',array_values($date_column));$this->assignconfig('place_weight_json',$series_array);//Log::write(array_values($place_weight_name_list),"info");return$this->view->fetch();}/**
* 详情
*/publicfunctiondetail($ids){$row=$this->model->get(['id'=>$ids]);if(!$row){$this->error(__('No Results were found'));}$this->view->assign("row",$row->toArray());return$this->view->fetch();}}classSeries{public$name;public$type;public$stack;public$data;}