稻虾每周价格
parent
587995c699
commit
3ee1dec8ea
|
|
@ -0,0 +1,115 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Enums\OperationType;
|
||||||
|
use App\Http\Requestes\RiceShrimpWeeklyPriceStoreRequest;
|
||||||
|
use App\Http\Requestes\RiceShrimpWeeklyPriceUpdateRequest;
|
||||||
|
use App\Http\Resources\RiceShrimpWeeklyPriceResource;
|
||||||
|
use App\Models\RiceShrimpWeeklyPrice;
|
||||||
|
use App\Services\OperationLogService;
|
||||||
|
use Illuminate\Http\JsonResponse;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Http\Resources\Json\ResourceCollection;
|
||||||
|
|
||||||
|
class RiceShrimpWeeklyPriceController extends Controller
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 稻虾每周价格列表
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Http\Request $request
|
||||||
|
* @return \Illuminate\Http\Resources\Json\ResourceCollection
|
||||||
|
*/
|
||||||
|
public function index(Request $request): ResourceCollection
|
||||||
|
{
|
||||||
|
$riceShrimpWeeklyPrices = RiceShrimpWeeklyPrice::with(['createdBy', 'updatedBy'])
|
||||||
|
->filter($request->all())
|
||||||
|
->latest('id')
|
||||||
|
->paginate(20);
|
||||||
|
|
||||||
|
return RiceShrimpWeeklyPriceResource::collection($riceShrimpWeeklyPrices);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建稻虾每周价格
|
||||||
|
*
|
||||||
|
* @param \App\Http\Requestes\RiceShrimpWeeklyPriceStoreRequest $request
|
||||||
|
* @return \App\Http\Resources\RiceShrimpWeeklyPriceResource
|
||||||
|
*
|
||||||
|
* @throws \App\Exceptions\BizException
|
||||||
|
*/
|
||||||
|
public function store(RiceShrimpWeeklyPriceStoreRequest $request): RiceShrimpWeeklyPriceResource
|
||||||
|
{
|
||||||
|
$user = $request->user();
|
||||||
|
|
||||||
|
$riceShrimpWeeklyPrice = RiceShrimpWeeklyPrice::create(
|
||||||
|
array_merge(
|
||||||
|
$request->only(['year', 'quarter', 'price']),
|
||||||
|
[
|
||||||
|
'created_by' => $user->id,
|
||||||
|
'updated_by' => $user->id,
|
||||||
|
]
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
$riceShrimpWeeklyPrice->setRelations([
|
||||||
|
'createdBy' => $user,
|
||||||
|
'updatedBy' => $user,
|
||||||
|
]);
|
||||||
|
|
||||||
|
(new OperationLogService())->inLog(OperationType::Create, '', $riceShrimpWeeklyPrice, $request->input());
|
||||||
|
|
||||||
|
return RiceShrimpWeeklyPriceResource::make($riceShrimpWeeklyPrice);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改稻虾每周价格
|
||||||
|
*
|
||||||
|
* @param int $id
|
||||||
|
* @param \App\Http\Requestes\RiceShrimpWeeklyPriceUpdateRequest $request
|
||||||
|
* @return \App\Http\Resources\RiceShrimpWeeklyPriceResource
|
||||||
|
*/
|
||||||
|
public function update($id, RiceShrimpWeeklyPriceUpdateRequest $request): RiceShrimpWeeklyPriceResource
|
||||||
|
{
|
||||||
|
$riceShrimpWeeklyPrice = RiceShrimpWeeklyPrice::findOrFail($id);
|
||||||
|
|
||||||
|
foreach ([
|
||||||
|
'year',
|
||||||
|
'week',
|
||||||
|
'price',
|
||||||
|
] as $key) {
|
||||||
|
if ($request->filled($key)) {
|
||||||
|
$riceShrimpWeeklyPrice->{$key} = $request->input($key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($riceShrimpWeeklyPrice->isDirty()) {
|
||||||
|
$riceShrimpWeeklyPrice->updated_by = $request->user()->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
$riceShrimpWeeklyPrice->save();
|
||||||
|
|
||||||
|
(new OperationLogService())->inLog(OperationType::Update, '', $riceShrimpWeeklyPrice, $request->input());
|
||||||
|
|
||||||
|
return RiceShrimpWeeklyPriceResource::make(
|
||||||
|
$riceShrimpWeeklyPrice->loadMissing(['createdBy', 'updatedBy'])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除稻虾每周价格
|
||||||
|
*
|
||||||
|
* @param int $id
|
||||||
|
* @return \Illuminate\Http\JsonResponse
|
||||||
|
*/
|
||||||
|
public function destroy($id): JsonResponse
|
||||||
|
{
|
||||||
|
$riceShrimpWeeklyPrice = RiceShrimpWeeklyPrice::findOrFail($id);
|
||||||
|
|
||||||
|
$riceShrimpWeeklyPrice->delete();
|
||||||
|
|
||||||
|
(new OperationLogService())->inLog(OperationType::Delete, '', $riceShrimpWeeklyPrice);
|
||||||
|
|
||||||
|
return response()->json(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,32 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requestes;
|
||||||
|
|
||||||
|
use App\Rules\Quarter;
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
class RiceShrimpWeeklyPriceStoreRequest extends FormRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function rules()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'year' => ['required', 'int'],
|
||||||
|
'week' => ['required', 'int'],
|
||||||
|
'price' => ['required', 'int'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function attributes()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'year' => '年份',
|
||||||
|
'week' => '周',
|
||||||
|
'price' => '价格',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,31 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Requestes;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
||||||
|
class RiceShrimpWeeklyPriceUpdateRequest extends FormRequest
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Get the validation rules that apply to the request.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function rules()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'year' => ['filled', 'int'],
|
||||||
|
'week' => ['filled', 'int'],
|
||||||
|
'price' => ['filled', 'int'],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function attributes()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'year' => '年份',
|
||||||
|
'week' => '周',
|
||||||
|
'price' => '价格',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,28 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Resources;
|
||||||
|
|
||||||
|
use Illuminate\Http\Resources\Json\JsonResource;
|
||||||
|
|
||||||
|
class RiceShrimpWeeklyPriceResource extends JsonResource
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Transform the resource into an array.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Http\Request $request
|
||||||
|
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
|
||||||
|
*/
|
||||||
|
public function toArray($request)
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'id' => $this->id,
|
||||||
|
'year' => $this->year,
|
||||||
|
'week' => $this->week,
|
||||||
|
'price' => $this->price,
|
||||||
|
'created_by' => AdminUserResource::make($this->whenLoaded('createdBy')),
|
||||||
|
'updated_by' => AdminUserResource::make($this->whenLoaded('updatedBy')),
|
||||||
|
'created_at' => $this->created_at->unix(),
|
||||||
|
'updated_at' => $this->updated_at->unix(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,26 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use EloquentFilter\Filterable;
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class RiceShrimpWeeklyPrice extends Model
|
||||||
|
{
|
||||||
|
use Filterable, HasFactory;
|
||||||
|
|
||||||
|
protected $fillable = [
|
||||||
|
'year', 'week', 'price', 'created_by', 'updated_by',
|
||||||
|
];
|
||||||
|
|
||||||
|
public function createdBy()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(AdminUser::class, 'created_by');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updatedBy()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(AdminUser::class, 'updated_by');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,36 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::create('rice_shrimp_weekly_prices', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->integer('year')->comment('年');
|
||||||
|
$table->tinyInteger('week')->comment('第x周');
|
||||||
|
$table->unsignedBigInteger('price')->comment('价格');
|
||||||
|
$table->unsignedBigInteger('created_by')->comment('创建人ID');
|
||||||
|
$table->unsignedBigInteger('updated_by')->comment('修改人ID');
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('rice_shrimp_weekly_prices');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
@ -38,6 +38,7 @@ class EndpointPermissionSeeder extends Seeder
|
||||||
]],
|
]],
|
||||||
'industry_data' => ['name' => '重点产业', 'curd' => false, 'children' => [
|
'industry_data' => ['name' => '重点产业', 'curd' => false, 'children' => [
|
||||||
'rice_shrimp_prices' => ['name' => '稻虾价格', 'curd' => true],
|
'rice_shrimp_prices' => ['name' => '稻虾价格', 'curd' => true],
|
||||||
|
'rice_shrimp_weekly_prices' => ['name' => '稻虾每周价格', 'curd' => true],
|
||||||
'rice_shrimp_industries' => ['name' => '稻虾产业', 'curd' => true],
|
'rice_shrimp_industries' => ['name' => '稻虾产业', 'curd' => true],
|
||||||
'rice_shrimp_flows' => ['name' => '稻虾走向', 'curd' => true],
|
'rice_shrimp_flows' => ['name' => '稻虾走向', 'curd' => true],
|
||||||
'materiels' => ['name' => '大宗物资', 'curd' => true],
|
'materiels' => ['name' => '大宗物资', 'curd' => true],
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,16 @@ class KeywordsTableSeeder extends Seeder
|
||||||
]],
|
]],
|
||||||
];
|
];
|
||||||
|
|
||||||
|
$list[] = value(function () {
|
||||||
|
$list = [];
|
||||||
|
|
||||||
|
for ($i=1; $i <= 52; $i++) {
|
||||||
|
$list[] = ['key' => $i, 'name' => "第{$i}周", 'value' => ''];
|
||||||
|
}
|
||||||
|
|
||||||
|
return ['key' => 'weeks-per-year', 'name' => '每年周数', 'value' => '', 'list' => $list];
|
||||||
|
});
|
||||||
|
|
||||||
if ($list) {
|
if ($list) {
|
||||||
$this->createKeywords($list);
|
$this->createKeywords($list);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use App\Http\Controllers\RiceShrimpWeeklyPriceController;
|
||||||
use Illuminate\Support\Facades\Route;
|
use Illuminate\Support\Facades\Route;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -85,12 +86,14 @@ Route::group(['middleware' => 'auth:sanctum'], function () {
|
||||||
|
|
||||||
// 重点产业
|
// 重点产业
|
||||||
Route::apiResource('rice-shrimp-prices', RiceShrimpPriceController::class)->names('rice_shrimp_prices');
|
Route::apiResource('rice-shrimp-prices', RiceShrimpPriceController::class)->names('rice_shrimp_prices');
|
||||||
|
Route::apiResource('rice-shrimp-weekly-prices', RiceShrimpWeeklyPriceController::class)->names('rice_shrimp_weekly_prices');
|
||||||
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-price', [ChartController::class, 'riceShrimpPrice'])->name('charts.rice_shrimp_price');
|
||||||
|
Route::get('charts/rice-shrimp-weekly-price', [ChartController::class, 'riceShrimpWeeklyPrice'])->name('charts.rice_shrimp_weekly_price');
|
||||||
Route::get('charts/rice-shrimp-industry', [ChartController::class, 'riceShrimpIndustry'])->name('charts.rice_shrimp_industry');
|
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/rice-shrimp-flow', [ChartController::class, 'riceShrimpFlow'])->name('charts.rice_shrimp_flow');
|
||||||
Route::get('charts/materiel', [ChartController::class, 'materiel'])->name('charts.materiel');
|
Route::get('charts/materiel', [ChartController::class, 'materiel'])->name('charts.materiel');
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue