<?php
namespace app\admin\controller;
use app\common\controller\Backend;
use fast\Date;
use think\Log;
class PoundRecordChart extends Backend
{
protected $model = null;
public function _initialize()
{
parent::_initialize();
$this->model = model('AdminLog');
}
public function index()
{
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 ($joinlist as $k => $v) {
$dailyCountList[$v['created_date']] = $v['nums'];
}
$place_weight_name_list = [];
$series_array = [];
foreach ($providerlist as $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_list as $kkk => $vvv) {
$each_place_daily_list1[$vvv['created_date']] = intval($vvv['total_settle_weight']);
}
$series = new Series();
$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 ($receiverlist as $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);
return $this->view->fetch();
}
public function detail($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();
}
}
class Series{
public $name;
public $type;
public $stack;
public $data;
}
|