You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
117 lines
2.4 KiB
117 lines
2.4 KiB
<?php
|
|
|
|
namespace App\AdminSupplier\Metrics\Examples;
|
|
|
|
use App\Common\DataTime;
|
|
use App\Models\OrderProductItem;
|
|
use App\Models\User;
|
|
use Carbon\Carbon;
|
|
use Dcat\Admin\Admin;
|
|
use Dcat\Admin\Widgets\Metrics\Line;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Arr;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class NewUsers extends Line
|
|
{
|
|
/**
|
|
* 初始化卡片内容
|
|
*
|
|
* @return void
|
|
*/
|
|
protected function init()
|
|
{
|
|
parent::init();
|
|
|
|
$this->title('现金流水');
|
|
$this->dropdown([
|
|
//'day' => '本日',
|
|
'week' => '本周',
|
|
'month' => '本月',
|
|
//'year' => '今年',
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* 处理请求
|
|
*
|
|
* @param Request $request
|
|
*
|
|
* @return mixed|void
|
|
*/
|
|
public function handle(Request $request)
|
|
{
|
|
$order = OrderProductItem::query()
|
|
->where('supplier_id',Admin::user()->id);
|
|
|
|
switch ($request->get('option')) {
|
|
case 'day':
|
|
$order->whereDate('created_at', Carbon::today());
|
|
break;
|
|
case 'week':
|
|
$time = DataTime::beginAndEnd('week');
|
|
$order->whereBetween('created_at', $time);
|
|
break;
|
|
case 'month':
|
|
$order->whereMonth('created_at', Carbon::now()->month);
|
|
break;
|
|
case 'year':
|
|
$order->whereYear('created_at', Carbon::now()->year);
|
|
break;
|
|
default:
|
|
$time = DataTime::beginAndEnd('week');
|
|
$order->whereBetween('created_at', $time);
|
|
}
|
|
$countOrder = clone $order;
|
|
$count = $order->sum('price');
|
|
$this->withContent($count);
|
|
|
|
$countOrder = $countOrder->select('*')
|
|
->addSelect(DB::raw("sum(price) as sum_price,CONCAT(YEAR(created_at),'-',MONTH(created_at),'-',DAY(created_at)) AS statistics_time"))
|
|
->limit(30)
|
|
->groupBy('statistics_time')
|
|
->get()
|
|
->toArray();
|
|
// 图表数据
|
|
$this->chartLabels(Arr::pluck($countOrder, 'statistics_time'));
|
|
$this->withChart(Arr::pluck($countOrder, 'sum_price'));
|
|
}
|
|
|
|
/**
|
|
* 设置图表数据.
|
|
*
|
|
* @param array $data
|
|
*
|
|
* @return \App\AdminSupplier\Metrics\Examples\NewUsers
|
|
*/
|
|
public function withChart(array $data)
|
|
{
|
|
return $this->chart([
|
|
'series' => [
|
|
[
|
|
'name' => $this->title,
|
|
'data' => $data,
|
|
],
|
|
],
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* 设置卡片内容.
|
|
*
|
|
* @param string $content
|
|
*
|
|
* @return $this
|
|
*/
|
|
public function withContent($content)
|
|
{
|
|
return $this->content(
|
|
<<<HTML
|
|
<div class="d-flex justify-content-between align-items-center mt-1" style="margin-bottom: 2px">
|
|
<h2 class="ml-1 font-lg-1">{$content}</h2>
|
|
<span class="mb-0 mr-1 text-80">{$this->title}</span>
|
|
</div>
|
|
HTML
|
|
);
|
|
}
|
|
}
|