|
|
@@ -47,6 +47,7 @@ final class MenuBadgeAdminService
|
|
|
'zh' => ['text' => ''], 'en' => ['text' => ''], 'vi' => ['text' => ''],
|
|
|
],
|
|
|
'sort' => (int) $row->sort,
|
|
|
+ 'status' => (int) ($row->status ?? 1),
|
|
|
'created_at' => (string) $row->created_at,
|
|
|
'updated_at' => (string) $row->updated_at,
|
|
|
];
|
|
|
@@ -68,6 +69,7 @@ final class MenuBadgeAdminService
|
|
|
'menu_text' => ['required', 'string', 'max:200'],
|
|
|
'badge_translations' => ['required', 'array:zh,en,vi'],
|
|
|
'sort' => ['nullable', 'integer', 'min:0', 'max:9999'],
|
|
|
+ 'status' => ['nullable', 'integer', 'in:0,1'],
|
|
|
])->validate();
|
|
|
$data['menu_text'] = trim($data['menu_text']);
|
|
|
if ($data['menu_text'] === '') {
|
|
|
@@ -75,8 +77,9 @@ final class MenuBadgeAdminService
|
|
|
}
|
|
|
$data['badge_translations'] = $this->badgeTexts($data['badge_translations']);
|
|
|
$sort = array_key_exists('sort', $data) && $data['sort'] !== null ? (int) $data['sort'] : null;
|
|
|
+ $status = array_key_exists('status', $data) && $data['status'] !== null ? (int) $data['status'] : null;
|
|
|
|
|
|
- return DB::transaction(function () use ($data, $sort) {
|
|
|
+ return DB::transaction(function () use ($data, $sort, $status) {
|
|
|
$now = now()->format('Y-m-d H:i:s');
|
|
|
$payload = [
|
|
|
'menu_text' => $data['menu_text'],
|
|
|
@@ -91,11 +94,15 @@ final class MenuBadgeAdminService
|
|
|
if ($sort !== null) {
|
|
|
$payload['sort'] = $sort;
|
|
|
}
|
|
|
+ if ($status !== null) {
|
|
|
+ $payload['status'] = $status;
|
|
|
+ }
|
|
|
DB::table('menu_badge_configs')->where('id', $data['id'])->update($payload);
|
|
|
OperationAuditService::record('menu_badge_config', (int) $data['id'], 'update', $this->row($before), $data);
|
|
|
$id = (int) $data['id'];
|
|
|
} else {
|
|
|
$payload['sort'] = $sort ?? (int) DB::table('menu_badge_configs')->max('sort') + 1;
|
|
|
+ $payload['status'] = $status ?? 1;
|
|
|
$payload['created_at'] = $now;
|
|
|
$id = (int) DB::table('menu_badge_configs')->insertGetId($payload);
|
|
|
OperationAuditService::record('menu_badge_config', $id, 'create', [], $data + ['id' => $id]);
|
|
|
@@ -122,4 +129,31 @@ final class MenuBadgeAdminService
|
|
|
return ['id' => (int) $data['id']];
|
|
|
});
|
|
|
}
|
|
|
+
|
|
|
+ public function status(array $input): array
|
|
|
+ {
|
|
|
+ $this->ready();
|
|
|
+ $data = Validator::make($input, [
|
|
|
+ 'id' => ['required', 'integer', 'min:1'],
|
|
|
+ 'status' => ['required', 'integer', 'in:0,1'],
|
|
|
+ ])->validate();
|
|
|
+
|
|
|
+ return DB::transaction(function () use ($data) {
|
|
|
+ $before = DB::table('menu_badge_configs')->where('id', $data['id'])->lockForUpdate()->first();
|
|
|
+ if (!$before) {
|
|
|
+ throw ValidationException::withMessages(['id' => '配置不存在']);
|
|
|
+ }
|
|
|
+ if ((int) $data['status'] === 1) {
|
|
|
+ $this->badgeTexts(json_decode((string) $before->badge_translations, true) ?: []);
|
|
|
+ }
|
|
|
+ DB::table('menu_badge_configs')->where('id', $data['id'])->update([
|
|
|
+ 'status' => (int) $data['status'],
|
|
|
+ 'updated_at' => now()->format('Y-m-d H:i:s'),
|
|
|
+ ]);
|
|
|
+ OperationAuditService::record('menu_badge_config', (int) $data['id'], 'status', $this->row($before), $data);
|
|
|
+ $saved = DB::table('menu_badge_configs')->where('id', $data['id'])->first();
|
|
|
+
|
|
|
+ return $this->row($saved);
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|