Uchart 后端PHP调用代码

<?php
/**
 * Created by victor ma.
 * User: victor ma
 * Date: 2021/7/14
 * Time: 16:17
 */

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);
        //Log::write(array_values($place_weight_name_list),"info");
        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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值