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.
168 lines
4.1 KiB
168 lines
4.1 KiB
<?php
|
|
|
|
namespace App\AdminAgent\Metrics\Examples;
|
|
|
|
use App\Common\DataTime;
|
|
use App\Common\OrderStatus;
|
|
use App\Models\Order;
|
|
use Carbon\Carbon;
|
|
use Dcat\Admin\Admin;
|
|
use Dcat\Admin\Widgets\Metrics\Round;
|
|
use Illuminate\Http\Request;
|
|
|
|
class ProductOrders extends Round
|
|
{
|
|
/**
|
|
* 初始化卡片内容
|
|
*/
|
|
protected function init()
|
|
{
|
|
parent::init();
|
|
|
|
$this->title('订单状态统计');
|
|
$this->chartLabels(['Finished', 'Pending', 'Rejected']);
|
|
$this->dropdown([
|
|
//'day' => '本日',
|
|
'week' => '本周',
|
|
'month' => '本月',
|
|
'year' => '今年',
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* 处理请求
|
|
*
|
|
* @param Request $request
|
|
*
|
|
* @return mixed|void
|
|
*/
|
|
public function handle(Request $request)
|
|
{
|
|
$orders = Order::query()
|
|
->where('agent_id', Admin::user()->id)
|
|
->whereIn('status',[
|
|
OrderStatus::PAY_EARNEST,
|
|
OrderStatus::PAID,
|
|
OrderStatus::PAID_RETAINAGE,
|
|
OrderStatus::OFFLINE_PAID,
|
|
OrderStatus::SUCCESS
|
|
]);
|
|
|
|
switch ($request->get('option')) {
|
|
case 'day':
|
|
$orders->whereDate('created_at', Carbon::today());
|
|
break;
|
|
case 'week':
|
|
$time = DataTime::beginAndEnd('week');
|
|
$orders->whereBetween('created_at', $time);
|
|
|
|
break;
|
|
case 'month':
|
|
$orders->whereMonth('created_at', Carbon::now()->month);
|
|
|
|
break;
|
|
case 'year':
|
|
$orders->whereYear('created_at', Carbon::now()->year);
|
|
|
|
break;
|
|
default:
|
|
$time = DataTime::beginAndEnd('week');
|
|
$orders->whereBetween('created_at', $time);
|
|
}
|
|
$orders = $orders->pluck('status')->toArray();
|
|
$payEarnest = $pay = $success = 0;
|
|
|
|
$arr = [
|
|
OrderStatus::PAID,
|
|
OrderStatus::PAID_RETAINAGE,
|
|
OrderStatus::OFFLINE_PAID,
|
|
];
|
|
|
|
$count = count($orders);
|
|
if ($orders > 0) {
|
|
foreach ($orders as $status) {
|
|
if ($status == OrderStatus::PAY_EARNEST) {
|
|
$payEarnest++;
|
|
} elseif (in_array($status,$arr)) {
|
|
$pay++;
|
|
} elseif ($status == OrderStatus::SUCCESS) {
|
|
$success++;
|
|
}
|
|
}
|
|
}
|
|
|
|
// 卡片内容
|
|
$this->withContent($payEarnest, $pay, $success);
|
|
|
|
$payEarnestPer = $count > 0 ? bcdiv($payEarnest,$count,2) * 100 : 0;
|
|
$payPer = $count > 0 ? bcdiv($pay,$count,2) * 100 : 0;
|
|
$successPer = $count > 0 ? bcdiv($success,$count,2) * 100 : 0;
|
|
// 图表数据
|
|
$this->withChart([$payEarnestPer, $payPer, $successPer]);
|
|
|
|
// 总数
|
|
$this->chartTotal('总计', $count);
|
|
}
|
|
|
|
/**
|
|
* 设置图表数据.
|
|
*
|
|
* @param array $data
|
|
*
|
|
* @return $this
|
|
*/
|
|
public function withChart(array $data)
|
|
{
|
|
return $this->chart([
|
|
'series' => $data,
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* 卡片内容.
|
|
*
|
|
* @param int $finished
|
|
* @param int $pending
|
|
* @param int $rejected
|
|
*
|
|
* @return $this
|
|
*/
|
|
public function withContent($finished, $pending, $rejected)
|
|
{
|
|
return $this->content(
|
|
<<<HTML
|
|
<div class="col-12 d-flex flex-column flex-wrap text-center" style="max-width: 220px">
|
|
<div class="chart-info d-flex justify-content-between mb-1 mt-2" >
|
|
<div class="series-info d-flex align-items-center">
|
|
<i class="fa fa-circle-o text-bold-700 text-primary"></i>
|
|
<span class="text-bold-600 ml-50">已付定金</span>
|
|
</div>
|
|
<div class="product-result">
|
|
<span>{$finished}</span>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="chart-info d-flex justify-content-between mb-1">
|
|
<div class="series-info d-flex align-items-center">
|
|
<i class="fa fa-circle-o text-bold-700 text-warning"></i>
|
|
<span class="text-bold-600 ml-50">已付款</span>
|
|
</div>
|
|
<div class="product-result">
|
|
<span>{$pending}</span>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="chart-info d-flex justify-content-between mb-1">
|
|
<div class="series-info d-flex align-items-center">
|
|
<i class="fa fa-circle-o text-bold-700 text-danger"></i>
|
|
<span class="text-bold-600 ml-50">已完成</span>
|
|
</div>
|
|
<div class="product-result">
|
|
<span>{$rejected}</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
HTML
|
|
);
|
|
}
|
|
}
|