Browse Source

财务统计

master
lemon 4 years ago
parent
commit
fc5df9e1ae
  1. 4
      app/Admin/Controllers/OrderStatisticsController.php
  2. 6
      app/Admin/Controllers/ProductStatisticsController.php
  3. 36
      app/AdminAgent/Controllers/FinanceStatisticsController.php
  4. 4
      app/AdminAgent/Controllers/OrderStatisticsController.php
  5. 6
      app/AdminAgent/Controllers/ProductStatisticsController.php
  6. 45
      app/AdminSupplier/Controllers/FinanceStatisticsController.php
  7. 4
      app/AdminSupplier/Controllers/OrderStatisticsController.php
  8. 6
      app/AdminSupplier/Controllers/ProductStatisticsController.php

4
app/Admin/Controllers/OrderStatisticsController.php

@ -60,7 +60,7 @@ class OrderStatisticsController extends AdminController
$count = Order::query();
$dateTime = request('created_at', 0);
if ($dateTime) {
$count->whereBetween('created_at',$dateTime);
$count->whereBetween('created_at',[$dateTime['start'] . ' 00:00:00',$dateTime['end'].' 23:59:59']);
}
$count = $count->count();
$row->column(3, function (Column $column) use ($count) {
@ -78,7 +78,7 @@ HTML;
$orders = Order::query()->where('status',$v);
if ($dateTime) {
$orders->whereBetween('created_at',$dateTime);
$orders->whereBetween('created_at',[$dateTime['start'] . ' 00:00:00',$dateTime['end'].' 23:59:59']);
}
$orders = $orders->count();

6
app/Admin/Controllers/ProductStatisticsController.php

@ -73,7 +73,7 @@ class ProductStatisticsController extends AdminController
$dateTime = request()->get('created_at')??null;
$count = AgentProduct::query();
if (!empty($dateTime)) {
$count->whereBetween('created_at',$dateTime);
$count->whereBetween('created_at',[$dateTime['start'] . ' 00:00:00',$dateTime['end'].' 23:59:59']);
}
$count = $count->count();
return <<<HTML
@ -89,7 +89,7 @@ HTML;
$dateTime = request()->get('created_at')??null;
$profit = AgentProduct::query()->where('status',ProductStatus::ON_SALE);
if (!empty($dateTime)) {
$profit->whereBetween('created_at',$dateTime);
$profit->whereBetween('created_at',[$dateTime['start'] . ' 00:00:00',$dateTime['end'].' 23:59:59']);
}
$profit = $profit->count();
return <<<HTML
@ -107,7 +107,7 @@ HTML;
->where('status',ProductStatus::SOLD_OUT);
$dateTime = request()->get('created_at')??null;
if (!empty($dateTime)) {
$unSale->whereBetween('created_at',$dateTime);
$unSale->whereBetween('created_at',[$dateTime['start'] . ' 00:00:00',$dateTime['end'].' 23:59:59']);
}
$unSale = $unSale->count();
return <<<HTML

36
app/AdminAgent/Controllers/FinanceStatisticsController.php

@ -5,6 +5,7 @@ namespace App\AdminAgent\Controllers;
use App\AdminAgent\Metrics\Examples\FinanceStatistics;
use App\AdminAgent\Metrics\Examples\ProductStatistics;
use App\Common\OrderStatus;
use App\Common\PayType;
use App\Models\Order;
use App\Models\OrderProductItem;
use Dcat\Admin\Admin;
@ -33,7 +34,10 @@ class FinanceStatisticsController extends AdminController
//数据
//金额
$price = Order::query()->where('agent_id',Admin::user()->id)->complete();
//线下
$price = Order::query()->where('agent_id',Admin::user()->id)->where('pay_type','=',PayType::OFFLINE)->complete();
//线上
$onlinePrice = Order::query()->where('agent_id',Admin::user()->id)->where('pay_type','!=',PayType::OFFLINE)->complete();
//利润
$costPrice = OrderProductItem::query()->where('agent_id',Admin::user()->id)->whereHas('order',function ($query) {
$query->complete();
@ -44,14 +48,16 @@ class FinanceStatisticsController extends AdminController
$dateTime = request('created_at', 0);
if ($dateTime) {
$price->whereBetween('created_at',$dateTime);
$costPrice->whereBetween('created_at',$dateTime);
$count->whereBetween('created_at',$dateTime);
$price->whereBetween('created_at',[$dateTime['start'] . ' 00:00:00',$dateTime['end'].' 23:59:59']);
$costPrice->whereBetween('created_at',[$dateTime['start'] . ' 00:00:00',$dateTime['end'].' 23:59:59']);
$count->whereBetween('created_at',[$dateTime['start'] . ' 00:00:00',$dateTime['end'].' 23:59:59']);
$onlinePrice->whereBetween('created_at',[$dateTime['start'] . ' 00:00:00',$dateTime['end'].' 23:59:59']);
}
$price = $price->sum('price');
$onlinePrice = $onlinePrice->sum('price');
$costPrice = $costPrice->sum('price');
$profit = bcsub($price,$costPrice,2);
$profit = bcsub(bcadd($price,$onlinePrice,6),$costPrice,2);
$count = $count->count();
return $content
->body(
@ -75,10 +81,20 @@ class FinanceStatisticsController extends AdminController
});
})
->body(function (Row $row) use ($price, $profit, $count) {
->body(function (Row $row) use ($price, $profit, $count,$onlinePrice) {
$row->column(4, function (Column $column) use ($price) {
$column->row(Card::make('金额', function () use ($price) {
$row->column(3, function (Column $column) use ($onlinePrice) {
$column->row(Card::make('线上金额', function () use ($onlinePrice) {
return <<<HTML
<div class="d-flex justify-content-between align-items-center mt-1" style="margin-bottom: 2px">
<h2 class="ml-1 font-large-1 text-primary">$onlinePrice</h2>
</div>
HTML;
}));
});
$row->column(3, function (Column $column) use ($price) {
$column->row(Card::make('线下金额', function () use ($price) {
return <<<HTML
<div class="d-flex justify-content-between align-items-center mt-1" style="margin-bottom: 2px">
<h2 class="ml-1 font-large-1 text-primary">$price</h2>
@ -87,7 +103,7 @@ HTML;
}));
});
$row->column(4, function (Column $column) use ($profit) {
$row->column(3, function (Column $column) use ($profit) {
$column->row(Card::make('利润', function () use ($profit) {
return <<<HTML
<div class="d-flex justify-content-between align-items-center mt-1" style="margin-bottom: 2px">
@ -98,7 +114,7 @@ HTML;
});
$row->column(4, function (Column $column) use ($count) {
$row->column(3, function (Column $column) use ($count) {
$column->row(Card::make('已完成订单', function () use ($count) {
return <<<HTML
<div class="d-flex justify-content-between align-items-center mt-1" style="margin-bottom: 2px">

4
app/AdminAgent/Controllers/OrderStatisticsController.php

@ -61,7 +61,7 @@ class OrderStatisticsController extends AdminController
$count = Order::query()->where('agent_id',Admin::user()->id);
$dateTime = request('created_at', 0);
if ($dateTime) {
$count->whereBetween('created_at',$dateTime);
$count->whereBetween('created_at',[$dateTime['start'] . ' 00:00:00',$dateTime['end'].' 23:59:59']);
}
$count = $count->count();
$row->column(3, function (Column $column) use ($count) {
@ -79,7 +79,7 @@ HTML;
$orders = Order::query()->where('agent_id',Admin::user()->id)->where('status',$v);
if ($dateTime) {
$orders->whereBetween('created_at',$dateTime);
$orders->whereBetween('created_at',[$dateTime['start'] . ' 00:00:00',$dateTime['end'].' 23:59:59']);
}
$orders = $orders->count();

6
app/AdminAgent/Controllers/ProductStatisticsController.php

@ -73,7 +73,7 @@ class ProductStatisticsController extends AdminController
$dateTime = request()->get('created_at')??null;
$count = AgentProduct::query()->where('agent_id',Admin::user()->id);
if (!empty($dateTime)) {
$count->whereBetween('created_at',$dateTime);
$count->whereBetween('created_at',[$dateTime['start'] . ' 00:00:00',$dateTime['end'].' 23:59:59']);
}
$count = $count->count();
return <<<HTML
@ -89,7 +89,7 @@ HTML;
$dateTime = request()->get('created_at')??null;
$profit = AgentProduct::query()->where('agent_id',Admin::user()->id)->where('status',ProductStatus::ON_SALE);
if (!empty($dateTime)) {
$profit->whereBetween('created_at',$dateTime);
$profit->whereBetween('created_at',[$dateTime['start'] . ' 00:00:00',$dateTime['end'].' 23:59:59']);
}
$profit = $profit->count();
return <<<HTML
@ -108,7 +108,7 @@ HTML;
->where('status',ProductStatus::SOLD_OUT);
$dateTime = request()->get('created_at')??null;
if (!empty($dateTime)) {
$unSale->whereBetween('created_at',$dateTime);
$unSale->whereBetween('created_at',[$dateTime['start'] . ' 00:00:00',$dateTime['end'].' 23:59:59']);
}
$unSale = $unSale->count();
return <<<HTML

45
app/AdminSupplier/Controllers/FinanceStatisticsController.php

@ -5,6 +5,7 @@ namespace App\AdminSupplier\Controllers;
use App\AdminSupplier\Metrics\Examples\FinanceStatistics;
use App\AdminAgent\Metrics\Examples\ProductStatistics;
use App\Common\OrderStatus;
use App\Common\PayType;
use App\Models\Order;
use App\Models\OrderProductItem;
use Dcat\Admin\Admin;
@ -34,12 +35,16 @@ class FinanceStatisticsController extends AdminController
//金额
$price = OrderProductItem::query()->where('supplier_id',Admin::user()->id)->whereHas('order',function ($query) {
$query->complete();
$query->complete()->where('pay_type','=',PayType::OFFLINE);
});
//利润
$costPrice = OrderProductItem::query()->where('supplier_id',Admin::user()->id)->whereHas('order',function ($query) {
$query->complete();
$onlinePrice = OrderProductItem::query()->where('supplier_id',Admin::user()->id)->whereHas('order',function ($query) {
$query->complete()->where('pay_type','!=',PayType::OFFLINE);
});
////利润
//$costPrice = OrderProductItem::query()->where('supplier_id',Admin::user()->id)->whereHas('order',function ($query) {
// $query->complete();
//});
//已完成订单
$count = OrderProductItem::query()->where('supplier_id',Admin::user()->id)->whereHas('order',function ($query) {
@ -48,14 +53,15 @@ class FinanceStatisticsController extends AdminController
$dateTime = request('created_at', 0);
if ($dateTime) {
$price->whereBetween('created_at',$dateTime);
$costPrice->whereBetween('created_at',$dateTime);
$count->whereBetween('created_at',$dateTime);
$price->whereBetween('created_at',[$dateTime['start'] . ' 00:00:00',$dateTime['end'].' 23:59:59']);
//$costPrice->whereBetween('created_at',[$dateTime['start'] . ' 00:00:00',$dateTime['end'].' 23:59:59'])
$count->whereBetween('created_at',[$dateTime['start'] . ' 00:00:00',$dateTime['end'].' 23:59:59']);
$onlinePrice->whereBetween('created_at',[$dateTime['start'] . ' 00:00:00',$dateTime['end'].' 23:59:59']);
}
$price = $price->sum('price');
$costPrice = $costPrice->sum('price');
$profit = bcsub($price,$costPrice,2);
$onlinePrice = $onlinePrice->sum('price');
$profit = bcadd($price,$onlinePrice,2);
$count = $count->count();
return $content
->body(
@ -79,10 +85,21 @@ class FinanceStatisticsController extends AdminController
});
})
->body(function (Row $row) use ($price, $profit, $count) {
->body(function (Row $row) use ($price, $profit, $count,$onlinePrice) {
$row->column(3, function (Column $column) use ($onlinePrice) {
$column->row(Card::make('线上金额', function () use ($onlinePrice) {
return <<<HTML
<div class="d-flex justify-content-between align-items-center mt-1" style="margin-bottom: 2px">
<h2 class="ml-1 font-large-1 text-primary">$onlinePrice</h2>
</div>
HTML;
}));
});
$row->column(4, function (Column $column) use ($price) {
$column->row(Card::make('金额', function () use ($price) {
$row->column(3, function (Column $column) use ($price) {
$column->row(Card::make('线下金额', function () use ($price) {
return <<<HTML
<div class="d-flex justify-content-between align-items-center mt-1" style="margin-bottom: 2px">
<h2 class="ml-1 font-large-1 text-primary">$price</h2>
@ -91,7 +108,7 @@ HTML;
}));
});
$row->column(4, function (Column $column) use ($profit) {
$row->column(3, function (Column $column) use ($profit) {
$column->row(Card::make('利润', function () use ($profit) {
return <<<HTML
<div class="d-flex justify-content-between align-items-center mt-1" style="margin-bottom: 2px">
@ -102,7 +119,7 @@ HTML;
});
$row->column(4, function (Column $column) use ($count) {
$row->column(3, function (Column $column) use ($count) {
$column->row(Card::make('已完成订单', function () use ($count) {
return <<<HTML
<div class="d-flex justify-content-between align-items-center mt-1" style="margin-bottom: 2px">

4
app/AdminSupplier/Controllers/OrderStatisticsController.php

@ -61,7 +61,7 @@ class OrderStatisticsController extends AdminController
$count = OrderProductItem::query()->where('supplier_id',Admin::user()->id);
$dateTime = request('created_at', 0);
if ($dateTime) {
$count->whereBetween('created_at',$dateTime);
$count->whereBetween('created_at',[$dateTime['start'] . ' 00:00:00',$dateTime['end'].' 23:59:59']);
}
$count = $count->count();
$row->column(3, function (Column $column) use ($count) {
@ -82,7 +82,7 @@ HTML;
$query->where('status',$v);
});
if ($dateTime) {
$orders->whereBetween('created_at',$dateTime);
$orders->whereBetween('created_at',[$dateTime['start'] . ' 00:00:00',$dateTime['end'].' 23:59:59']);
}
$orders = $orders->count();

6
app/AdminSupplier/Controllers/ProductStatisticsController.php

@ -71,7 +71,7 @@ class ProductStatisticsController extends AdminController
$dateTime = request()->get('created_at')??null;
$count = Product::query()->where('supplier_id',Admin::user()->id);
if (!empty($dateTime)) {
$count->whereBetween('created_at',$dateTime);
$count->whereBetween('created_at',[$dateTime['start'] . ' 00:00:00',$dateTime['end'].' 23:59:59']);
}
$count = $count->count();
return <<<HTML
@ -87,7 +87,7 @@ HTML;
$dateTime = request()->get('created_at')??null;
$profit = Product::query()->where('supplier_id',Admin::user()->id)->where('status',ProductStatus::ON_SALE);
if (!empty($dateTime)) {
$profit->whereBetween('created_at',$dateTime);
$profit->whereBetween('created_at',[$dateTime['start'] . ' 00:00:00',$dateTime['end'].' 23:59:59']);
}
$profit = $profit->count();
return <<<HTML
@ -106,7 +106,7 @@ HTML;
->where('status',ProductStatus::UNAUDITED);
$dateTime = request()->get('created_at')??null;
if (!empty($dateTime)) {
$unSale->whereBetween('created_at',$dateTime);
$unSale->whereBetween('created_at',[$dateTime['start'] . ' 00:00:00',$dateTime['end'].' 23:59:59']);
}
$unSale = $unSale->count();
return <<<HTML

Loading…
Cancel
Save