Fix
parent
c164580e25
commit
3a0c372416
|
|
@ -18,6 +18,7 @@ use Dcat\Admin\Http\Controllers\AdminController;
|
|||
use Dcat\Admin\Layout\Row;
|
||||
use Dcat\Admin\Show;
|
||||
use Dcat\Admin\Widgets\Box;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class OfflineOrderController extends AdminController
|
||||
{
|
||||
|
|
@ -69,13 +70,11 @@ class OfflineOrderController extends AdminController
|
|||
<span class="label bg-success">{$phone}</span>
|
||||
HTML;
|
||||
});
|
||||
$grid->column('items', '品类')->display(function () {
|
||||
return $this->items->map(function ($item) {
|
||||
$grid->column('items')->display(function ($items) {
|
||||
return $items->map(function ($item) {
|
||||
$category = $item->productCategory?->name;
|
||||
|
||||
if ($item->discount_reduction_amount > 0) {
|
||||
$discount = round(bcdiv($item->discount_reduction_amount*10, $item->products_total_amount, 3), 2);
|
||||
|
||||
if ($discount = $item->getDiscount()) {
|
||||
$category .= " {$discount}折";
|
||||
}
|
||||
|
||||
|
|
@ -143,7 +142,12 @@ class OfflineOrderController extends AdminController
|
|||
|
||||
$grid->header(function ($collection) use ($grid) {
|
||||
return tap(new Row(), function ($row) use ($grid) {
|
||||
$query = OfflineOrder::query();
|
||||
$query = OfflineOrder::select([
|
||||
DB::raw('sum(products_total_amount) as products_total_amount'),
|
||||
DB::raw('sum(discount_reduction_amount) as discount_reduction_amount'),
|
||||
DB::raw('sum(points_deduction_amount) as points_deduction_amount'),
|
||||
DB::raw('sum(payment_amount) as payment_amount'),
|
||||
]);
|
||||
$grid->model()->getQueries()->unique()->each(function ($value) use (&$query) {
|
||||
if (in_array($value['method'], ['paginate', 'get', 'orderBy', 'orderByDesc'], true)) {
|
||||
return;
|
||||
|
|
@ -151,15 +155,13 @@ class OfflineOrderController extends AdminController
|
|||
|
||||
$query = call_user_func_array([$query, $value['method']], $value['arguments'] ?? []);
|
||||
});
|
||||
$productsTotalAmount = (clone $query)->sum('products_total_amount');
|
||||
$discountReductionAmount = (clone $query)->sum('discount_reduction_amount');
|
||||
$pointsDiscountAmount = (clone $query)->sum('points_deduction_amount');
|
||||
$paymentAmount = (clone $query)->sum('payment_amount');
|
||||
|
||||
$row->column(2, new InfoBox('订单总额', bcdiv($productsTotalAmount, 100, 2), 'fa fa-ticket'));
|
||||
$row->column(2, new InfoBox('折扣优惠', bcdiv($discountReductionAmount, 100, 2), 'fa fa-ticket'));
|
||||
$row->column(2, new InfoBox('积分抵扣', bcdiv($pointsDiscountAmount, 100, 2), 'fa fa-ticket'));
|
||||
$row->column(2, new InfoBox('实付金额', bcdiv($paymentAmount, 100, 2), 'fa fa-ticket'));
|
||||
$results = $query->first();
|
||||
|
||||
$row->column(2, new InfoBox('订单总额', bcdiv($results['products_total_amount'] ?? 0, 100, 2), 'fa fa-ticket'));
|
||||
$row->column(2, new InfoBox('折扣优惠', bcdiv($results['discount_reduction_amount'] ?? 0, 100, 2), 'fa fa-ticket'));
|
||||
$row->column(2, new InfoBox('积分抵扣', bcdiv($results['points_deduction_amount'] ?? 0, 100, 2), 'fa fa-ticket'));
|
||||
$row->column(2, new InfoBox('实付金额', bcdiv($results['payment_amount'] ?? 0, 100, 2), 'fa fa-ticket'));
|
||||
});
|
||||
});
|
||||
|
||||
|
|
@ -228,7 +230,7 @@ class OfflineOrderController extends AdminController
|
|||
$grid->disableRefreshButton();
|
||||
});
|
||||
|
||||
$column->row(Box::make('订单明细', $orderItemGrid));
|
||||
$column->row(Box::make('品类', $orderItemGrid));
|
||||
});
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,4 +33,18 @@ class OfflineOrderItem extends Model
|
|||
{
|
||||
return $this->belongsTo(OfflineProductCategory::class, 'product_category_id');
|
||||
}
|
||||
|
||||
public function getDiscount()
|
||||
{
|
||||
$discount = '';
|
||||
|
||||
if ($this->discount_reduction_amount > 0 && $this->products_total_amount > 0) {
|
||||
// 应付金额
|
||||
$total = $this->products_total_amount - $this->discount_reduction_amount;
|
||||
|
||||
$discount = round(bcdiv($total * 10, $this->products_total_amount, 3), 2);
|
||||
}
|
||||
|
||||
return $discount;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@
|
|||
|
||||
return [
|
||||
'labels' => [
|
||||
'OfflineOrderItemStatistic' => '订单明细统计',
|
||||
'offline-order-item-statistics' => '订单明细统计',
|
||||
'OfflineOrderItemStatistic' => '订单品类统计',
|
||||
'offline-order-item-statistics' => '订单品类统计',
|
||||
],
|
||||
'fields' => [
|
||||
'product_category_id' => '商品分类',
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ return [
|
|||
'out_trade_no' => '外部交易单号',
|
||||
'status' => '状态',
|
||||
'revoked_at' => '取消时间',
|
||||
'items' => '品类',
|
||||
],
|
||||
'options' => [
|
||||
],
|
||||
|
|
|
|||
Loading…
Reference in New Issue