调整录入人

dev
vine_liutk 2022-10-17 16:45:28 +08:00
parent 8f37920775
commit b694bb992a
8 changed files with 43 additions and 29 deletions

View File

@ -16,7 +16,7 @@ class CropFlowController extends Controller
$query = CropFlow::filter($request->input());
$totalNum = $query->sum('sale');//总产量
$list = $query->simplePaginate(Paginator::resolvePerPage('per_page', 20, 50));
$list->load(['user']);
$list->load(['createdBy']);
return $this->json([
'total' => $totalNum,
'list' => CropFlowResource::collection($list),
@ -30,7 +30,8 @@ class CropFlowController extends Controller
return array_merge($item, [
'time_year' => $request->input('time_year'),
'crop_id' => $request->input('crop_id'),
'user_id' => auth('api')->user()?->id ?? 0,
'created_by' => auth('api')->user()?->id ?? 0,
'updated_by' => auth('api')->user()?->id ?? 0,
'created_at' => now(),
'updated_at' => now(),
]);
@ -46,7 +47,9 @@ class CropFlowController extends Controller
public function update(CropFlow $cropFlow, CropFlowUpdateRequest $request)
{
$cropFlow->update($request->input());
$cropFlow->update(array_merge($request->input(),
['updated_by'=>auth('api')->user()?->id ?? 0,]
));
return $this->success('修改成功');
}

View File

@ -16,7 +16,7 @@ class CropYieldController extends Controller
$query = CropYield::filter($request->all());
$totalNum = $query->sum('yield');//总产量
$list = $query->simplePaginate(Paginator::resolvePerPage('per_page', 20, 50));
$list->load(['base', 'user']);
$list->load(['base', 'createdBy']);
return $this->json([
'total' => $totalNum,
'list' => CropYieldResource::collection($list)
@ -30,7 +30,8 @@ class CropYieldController extends Controller
return array_merge($item, [
'time_year' => $request->input('time_year'),
'crop_id' => $request->input('crop_id'),
'user_id' => auth('api')->user()?->id ?? 0,
'created_by' => auth('api')->user()?->id ?? 0,
'updated_by' => auth('api')->user()?->id ?? 0,
'created_at' => now(),
'updated_at' => now(),
]);
@ -40,13 +41,15 @@ class CropYieldController extends Controller
public function show(CropYield $cropYield)
{
$cropYield->load(['base', 'crop', 'user']);
$cropYield->load(['base', 'crop', 'createdBy']);
return $this->json(CropYieldResource::make($cropYield));
}
public function update(CropYield $cropYield, CropYieldUpdateRequest $request)
{
$cropYield->update($request->input());
$cropYield->update(array_merge($request->input(),
['updated_by'=>auth('api')->user()?->id ?? 0,]
));
return $this->success('修改成功');
}

View File

@ -23,8 +23,8 @@ class CropFlowResource extends JsonResource
'crop_id' => $this->crop_id,
'time_year' => $this->time_year,
'sale' => $this->sale,
'user' => $this->whenLoaded('user', function (){
return $this->user?->name;
'created_by' => $this->whenLoaded('createdBy', function (){
return $this->createdBy?->name;
}, ''),//录入人
'created_at' => strtotime($this->created_at) ?? 0,//录入时间
];

View File

@ -28,8 +28,8 @@ class CropYieldResource extends JsonResource
'yield' => $this->yield,
'output' => $this->output,
'cultivated' => $this->cultivated,
'user' => $this->whenLoaded('user', function (){
return $this->user?->name;
'created_by' => $this->whenLoaded('createdBy', function (){
return $this->createdBy?->name;
}, ''),//录入人
'created_at' => strtotime($this->created_at) ?? 0,//录入时间
];

View File

@ -11,7 +11,8 @@ class CropFlow extends Model
use Filterable;
protected $fillable = [
'crop_id', 'flow_name', 'time_year', 'sale', 'user_id'
'crop_id', 'flow_name', 'time_year', 'sale', 'user_id',
'created_by', 'updated_by'
];
/**
@ -23,12 +24,13 @@ class CropFlow extends Model
return $this->belongsTo(Keywords::class, 'crop_id');
}
/**
* 录入人
*
* @return void
*/
public function user(){
return $this->belongsTo(AdminUser::class, 'user_id');
public function createdBy()
{
return $this->belongsTo(AdminUser::class, 'created_by');
}
public function updatedBy()
{
return $this->belongsTo(AdminUser::class, 'updated_by');
}
}

View File

@ -10,7 +10,10 @@ class CropYield extends Model
{
use Filterable;
protected $fillable = ['base_id', 'crop_id', 'time_year', 'yield', 'cultivated', 'output', 'user_id'];
protected $fillable = [
'base_id', 'crop_id', 'time_year', 'yield', 'cultivated', 'output', 'user_id',
'created_by', 'updated_by'
];
/**
* 基地
@ -30,13 +33,14 @@ class CropYield extends Model
return $this->belongsTo(Keywords::class, 'crop_id');
}
/**
* 录入人
*
* @return void
*/
public function user(){
return $this->belongsTo(AdminUser::class, 'user_id');
public function createdBy()
{
return $this->belongsTo(AdminUser::class, 'created_by');
}
public function updatedBy()
{
return $this->belongsTo(AdminUser::class, 'updated_by');
}
}

View File

@ -21,7 +21,8 @@ return new class extends Migration
$table->unsignedDecimal('yield', 12, 2)->comment('产量(斤)');
$table->unsignedDecimal('cultivated', 12, 2)->comment('耕地面积(亩)');
$table->unsignedDecimal('output', 12, 2)->comment('产值(元)');
$table->unsignedBigInteger('user_id')->comment('录入人');
$table->unsignedBigInteger('created_by')->comment('创建人ID');
$table->unsignedBigInteger('updated_by')->comment('修改人ID');
$table->timestamps();
$table->comment('农产品产量');

View File

@ -19,7 +19,8 @@ return new class extends Migration
$table->string('flow_name')->comment('流向地');
$table->unsignedInteger('time_year')->comment('年份');
$table->unsignedDecimal('sale', 12, 2)->comment('销量(斤)');
$table->unsignedBigInteger('user_id')->comment('录入人');
$table->unsignedBigInteger('created_by')->comment('创建人ID');
$table->unsignedBigInteger('updated_by')->comment('修改人ID');
$table->timestamps();
});
}