diff --git a/app/admin/service/VehColorService.php b/app/admin/service/VehColorService.php index a50a262..be83fcd 100644 --- a/app/admin/service/VehColorService.php +++ b/app/admin/service/VehColorService.php @@ -7,6 +7,7 @@ use app\common\traits\crud\CrudServiceTrait; use app\common\model\VehColor; use app\common\utils\translation\service\TranslationService; use app\queue\utils\Translat; +use support\Request; class VehColorService { @@ -46,4 +47,23 @@ class VehColorService $traitsourceFields ); } + + /** + * 添加前置处理 + */ + public function beforeServiceStore($data, Request $request) + { + $data['created_by'] = $request->user->uid; + $data['updated_by'] = $request->user->uid; + return $data; + } + + /** + * 添加前置处理 + */ + public function beforeServiceUpdate($data, Request $request) + { + $data['updated_by'] = $request->user->uid; + return $data; + } } \ No newline at end of file diff --git a/app/common/controller/VehColorController.php b/app/common/controller/VehColorController.php new file mode 100644 index 0000000..4473c44 --- /dev/null +++ b/app/common/controller/VehColorController.php @@ -0,0 +1,56 @@ +service = new VehColorService(); + } + + /** + * 列表页数据格式化 + * + * @param array $data + * @return array + */ + protected function indexFormat($data) + { + if (isset($data['created_at'])) + $data['created_at'] = date('Y-m-d H:i:s', $data['created_at']); + if (isset($data['updated_at'])) + $data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']); + if (isset($data['created_by']) && $data['created_by']) + $data['created_by_name'] = User::where('id', $data['created_by'])->value('name'); + if (isset($data['updated_by']) && $data['updated_by']) + $data['updated_by_name'] = User::where('id', $data['updated_by'])->value('name'); + return $data; + } + + /** + * 数据格式化 + * + * @param array $data + * @return array + */ + protected function showFormat($data) + { + if (isset($data['created_at'])) + $data['created_at'] = date('Y-m-d H:i:s', $data['created_at']); + if (isset($data['updated_at'])) + $data['updated_at'] = date('Y-m-d H:i:s', $data['updated_at']); + if (isset($data['created_by']) && $data['created_by']) + $data['created_by_name'] = User::where('id', $data['created_by'])->value('name'); + if (isset($data['updated_by']) && $data['updated_by']) + $data['updated_by_name'] = User::where('id', $data['updated_by'])->value('name'); + return $data; + } +} \ No newline at end of file diff --git a/app/common/model/VehColor.php b/app/common/model/VehColor.php index 9554aa5..ee7220a 100644 --- a/app/common/model/VehColor.php +++ b/app/common/model/VehColor.php @@ -40,7 +40,7 @@ class VehColor extends Model /** * 允许自动填充模型字段 */ - protected $fillable = ['id', 'color_code', 'color_text', 'type', 'hex_code', 'rgb_code', 'status', 'sort', 'created_at', 'updated_at']; + protected $fillable = ['id', 'color_code', 'color_text', 'type', 'hex_code', 'rgb_code', 'status', 'sort', 'created_at', 'updated_by', 'created_at', 'updated_at']; /** * 不允许自动填充模型字段 diff --git a/config/route.php b/config/route.php index 61f16eb..7f97d12 100644 --- a/config/route.php +++ b/config/route.php @@ -87,6 +87,15 @@ Route::group('/common', function () { Route::any('/unread', [app\common\controller\MessageUserStatusController::class, 'listUnRead']); }); + + // 汽车颜色 + Route::group('/color', function () { + Route::any('/list', [app\common\controller\VehColorController::class, 'index']); + Route::any('/show', [app\common\controller\VehColorController::class, 'show']); + Route::any('/store', [app\common\controller\VehColorController::class, 'store']); + Route::any('/update', [app\common\controller\VehColorController::class, 'update']); + Route::any('/destroy', [app\common\controller\VehColorController::class, 'destroy']); + }); }); // 后台管理