Merge branch 'main' of https://gitea.peidikeji.cn/pdkj/lcly-data-admin
commit
8d7fa2ef1f
|
|
@ -0,0 +1,199 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Enums\MaterielType;
|
||||||
|
use App\Models\Materiel;
|
||||||
|
use App\Models\RiceShrimpFlow;
|
||||||
|
use App\Models\RiceShrimpIndustry;
|
||||||
|
use App\Models\RiceShrimpPrice;
|
||||||
|
use App\Services\RiceShrimpPriceService;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
|
class ChartController extends Controller
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 稻虾价格趋势
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Http\Request $request
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function riceShrimpPrice(Request $request)
|
||||||
|
{
|
||||||
|
$quarters = [
|
||||||
|
1 => '1季度',
|
||||||
|
2 => '2季度',
|
||||||
|
3 => '3季度',
|
||||||
|
4 => '4季度',
|
||||||
|
];
|
||||||
|
|
||||||
|
$years = RiceShrimpPrice::select('year')
|
||||||
|
->groupBy('year')
|
||||||
|
->orderBy('year', 'desc')
|
||||||
|
->limit(3)
|
||||||
|
->get()
|
||||||
|
->pluck('year');
|
||||||
|
|
||||||
|
$riceShrimpPrices = RiceShrimpPrice::query()
|
||||||
|
->whereIn('year', $years)
|
||||||
|
->get();
|
||||||
|
|
||||||
|
$series = $riceShrimpPrices->groupBy('year')->map(function ($riceShrimpPrices, $year) use ($quarters) {
|
||||||
|
$riceShrimpPrices = $riceShrimpPrices->mapWithKeys(fn ($item) => [$item['quarter'] => $item]);
|
||||||
|
|
||||||
|
$data = [];
|
||||||
|
|
||||||
|
foreach ($quarters as $key => $value) {
|
||||||
|
$riceShrimpPrice = $riceShrimpPrices[$key] ?? null;
|
||||||
|
$data[] = $riceShrimpPrice?->price;
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
'name' => $year,
|
||||||
|
'data' => $data,
|
||||||
|
];
|
||||||
|
});
|
||||||
|
|
||||||
|
return [
|
||||||
|
'x_axis' => array_values($quarters),
|
||||||
|
'series' => $series->values()->all(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 稻虾产业
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Http\Request $request
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function riceShrimpIndustry(Request $request)
|
||||||
|
{
|
||||||
|
$riceShrimpIndustries = RiceShrimpIndustry::query()
|
||||||
|
->where('year', $request->query('year', date('Y')))
|
||||||
|
->get()
|
||||||
|
->mapWithKeys(fn ($item) => [$item['quarter'] => $item]);
|
||||||
|
|
||||||
|
$quarters = [
|
||||||
|
1 => '1季度',
|
||||||
|
2 => '2季度',
|
||||||
|
3 => '3季度',
|
||||||
|
4 => '4季度',
|
||||||
|
];
|
||||||
|
|
||||||
|
$areas = [];
|
||||||
|
$productOutputs = [];
|
||||||
|
$productValues = [];
|
||||||
|
|
||||||
|
foreach ($quarters as $key => $value) {
|
||||||
|
$riceShrimpIndustry = $riceShrimpIndustries[$key] ?? null;
|
||||||
|
|
||||||
|
$areas[] = $riceShrimpIndustry?->area;
|
||||||
|
$productOutputs[] = $riceShrimpIndustry?->product_output;
|
||||||
|
$productValues[] = $riceShrimpIndustry?->product_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
'x_axis' => array_values($quarters),
|
||||||
|
'series' => [
|
||||||
|
[
|
||||||
|
'name' => '产值',
|
||||||
|
'data' => $productValues,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'name' => '面积',
|
||||||
|
'data' => $areas,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'name' => '产量',
|
||||||
|
'data' => $productOutputs,
|
||||||
|
],
|
||||||
|
],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 稻虾流向
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Http\Request $request
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function riceShrimpFlow(Request $request)
|
||||||
|
{
|
||||||
|
$quarters = [
|
||||||
|
1 => '1季度',
|
||||||
|
2 => '2季度',
|
||||||
|
3 => '3季度',
|
||||||
|
4 => '4季度',
|
||||||
|
];
|
||||||
|
|
||||||
|
$riceShrimpFlows = RiceShrimpFlow::query()
|
||||||
|
->where('year', $request->query('year', date('Y')))
|
||||||
|
->get();
|
||||||
|
|
||||||
|
$series = $riceShrimpFlows->groupBy('area')->map(function ($riceShrimpFlows, $area) use ($quarters) {
|
||||||
|
$riceShrimpFlows = $riceShrimpFlows->mapWithKeys(fn ($item) => [$item['quarter'] => $item]);
|
||||||
|
|
||||||
|
$data = [];
|
||||||
|
|
||||||
|
foreach ($quarters as $key => $value) {
|
||||||
|
$riceShrimpFlow = $riceShrimpFlows[$key] ?? null;
|
||||||
|
$data[] = $riceShrimpFlow?->sales;
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
'name' => $area,
|
||||||
|
'data' => $data,
|
||||||
|
];
|
||||||
|
});
|
||||||
|
|
||||||
|
return [
|
||||||
|
'x_axis' => array_values($quarters),
|
||||||
|
'series' => $series->values()->all(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 大宗物资
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Http\Request $request
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function materiel(Request $request)
|
||||||
|
{
|
||||||
|
$quarters = [
|
||||||
|
1 => '1季度',
|
||||||
|
2 => '2季度',
|
||||||
|
3 => '3季度',
|
||||||
|
4 => '4季度',
|
||||||
|
];
|
||||||
|
|
||||||
|
$materiels = Materiel::query()
|
||||||
|
->where('year', $request->query('year', date('Y')))
|
||||||
|
->where('type', $request->query('type', MaterielType::Fodder))
|
||||||
|
->get();
|
||||||
|
|
||||||
|
$series = $materiels->groupBy('name')->map(function ($materiels, $name) use ($quarters) {
|
||||||
|
$materiels = $materiels->mapWithKeys(fn ($item) => [$item['quarter'] => $item]);
|
||||||
|
|
||||||
|
$lowestPrices = [];
|
||||||
|
$highestPrices = [];
|
||||||
|
|
||||||
|
foreach ($quarters as $key => $value) {
|
||||||
|
$materiel = $materiels[$key] ?? null;
|
||||||
|
$lowestPrices[] = $materiel?->lowest_price;
|
||||||
|
$highestPrices[] = $materiel?->highest_price;
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
'name' => $name,
|
||||||
|
'lowest_prices' => $lowestPrices,
|
||||||
|
'highest_prices' => $highestPrices,
|
||||||
|
];
|
||||||
|
});
|
||||||
|
|
||||||
|
return [
|
||||||
|
'x_axis' => array_values($quarters),
|
||||||
|
'series' => $series->values()->all(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -69,6 +69,12 @@ Route::group(['middleware' => 'auth:sanctum'], function () {
|
||||||
Route::apiResource('rice-shrimp-industries', RiceShrimpIndustryController::class)->names('rice_shrimp_industries');
|
Route::apiResource('rice-shrimp-industries', RiceShrimpIndustryController::class)->names('rice_shrimp_industries');
|
||||||
Route::apiResource('rice-shrimp-flows', RiceShrimpFlowController::class)->names('rice_shrimp_flows');
|
Route::apiResource('rice-shrimp-flows', RiceShrimpFlowController::class)->names('rice_shrimp_flows');
|
||||||
Route::apiResource('materiels', MaterielController::class)->names('materiels');
|
Route::apiResource('materiels', MaterielController::class)->names('materiels');
|
||||||
|
|
||||||
|
// 重点产业报表
|
||||||
|
Route::get('charts/rice-shrimp-price', [ChartController::class, 'riceShrimpPrice'])->name('charts.rice_shrimp_price');
|
||||||
|
Route::get('charts/rice-shrimp-industry', [ChartController::class, 'riceShrimpIndustry'])->name('charts.rice_shrimp_industry');
|
||||||
|
Route::get('charts/rice-shrimp-flow', [ChartController::class, 'riceShrimpFlow'])->name('charts.rice_shrimp_flow');
|
||||||
|
Route::get('charts/materiel', [ChartController::class, 'materiel'])->name('charts.materiel');
|
||||||
});
|
});
|
||||||
|
|
||||||
Route::prefix('users')->group(function () {
|
Route::prefix('users')->group(function () {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue