| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- <?php
- namespace App\Http\Controllers\Manage;
- use App\Libs\ApiResponse;
- use App\Libs\Utils;
- use App\Services\Manage\ArtStyleService;
- use Illuminate\Http\Request;
- use Illuminate\Routing\Controller as BaseController;
- use Illuminate\Support\Facades\Validator;
- class ArtStyleController extends BaseController
- {
- use ApiResponse;
- protected $artStyleService;
- public function __construct(ArtStyleService $artStyleService)
- {
- $this->artStyleService = $artStyleService;
- }
- /**
- * 画风管理列表(分页)
- *
- * @param Request $request
- * @return mixed
- */
- public function adminList(Request $request)
- {
- $data = $request->all();
- $validator = Validator::make($data, [
- 'page' => 'nullable|integer|min:1',
- 'per_page' => 'nullable|integer|min:1|max:100',
- 'is_enabled' => 'nullable|integer|in:0,1',
- 'keyword' => 'nullable|string|max:100',
- ], [
- 'page.integer' => 'page必须为整数',
- 'page.min' => 'page不能小于1',
- 'per_page.integer' => 'per_page必须为整数',
- 'per_page.min' => 'per_page不能小于1',
- 'per_page.max' => 'per_page不能超过100',
- 'is_enabled.in' => 'is_enabled仅支持0或1',
- 'keyword.max' => 'keyword不能超过100个字符',
- ]);
- if ($validator->fails()) {
- Utils::throwError('1002:' . $validator->errors()->first());
- }
- $result = $this->artStyleService->getList($data);
- $list = collect($result->items())->map(function ($item) {
- // $item->aliases = is_string($item->aliases) ? json_decode($item->aliases, true) : [];
- return $item;
- });
- return $this->success([
- 'meta' => getMeta($result),
- 'list' => $list,
- ]);
- }
- /**
- * 新增画风
- *
- * @param Request $request
- * @return mixed
- */
- public function add(Request $request)
- {
- $data = $request->all();
- $validator = Validator::make($data, [
- 'art_style' => 'required|string|max:100',
- 'pic_url' => 'required|string|max:500',
- 'aliases' => 'nullable',
- 'prompt' => 'required|string',
- 'character_prefix' => 'nullable|string',
- 'scene_prefix' => 'nullable|string',
- 'is_enabled' => 'nullable|integer|in:0,1',
- ], [
- 'art_style.required' => '请传入画风名称',
- 'art_style.max' => '画风名称不能超过100个字符',
- 'pic_url.required' => '请传入画风图片URL',
- 'pic_url.max' => '画风图片URL不能超过500个字符',
- 'prompt.required' => '请传入画风提示词prompt',
- 'is_enabled.in' => 'is_enabled仅支持0或1',
- ]);
- if ($validator->fails()) {
- Utils::throwError('1002:' . $validator->errors()->first());
- }
- $result = $this->artStyleService->addArtStyle($data);
- return $this->success($result);
- }
- /**
- * 修改画风
- *
- * @param Request $request
- * @return mixed
- */
- public function edit(Request $request)
- {
- $data = $request->all();
- $validator = Validator::make($data, [
- 'id' => 'required|integer|min:1',
- 'pic_url' => 'required|string|max:500',
- 'art_style' => 'nullable|string|max:100',
- 'aliases' => 'nullable',
- 'prompt' => 'required|string',
- 'character_prefix' => 'nullable|string',
- 'scene_prefix' => 'nullable|string',
- 'is_enabled' => 'nullable|integer|in:0,1',
- ], [
- 'id.required' => '请传入画风ID',
- 'id.integer' => '画风ID必须为整数',
- 'id.min' => '画风ID不能小于1',
- 'pic_url.required' => '请传入画风图片URL',
- 'pic_url.max' => '画风图片URL不能超过500个字符',
- 'art_style.max' => '画风名称不能超过100个字符',
- 'prompt.required' => '请传入画风提示词prompt',
- 'is_enabled.in' => 'is_enabled仅支持0或1',
- ]);
- if ($validator->fails()) {
- Utils::throwError('1002:' . $validator->errors()->first());
- }
- $result = $this->artStyleService->editArtStyle($data);
- return $this->success($result);
- }
- /**
- * 删除画风(软删除)
- *
- * @param Request $request
- * @return mixed
- */
- public function delete(Request $request)
- {
- $data = $request->all();
- $validator = Validator::make($data, [
- 'id' => 'required|integer|min:1',
- ], [
- 'id.required' => '请传入画风ID',
- 'id.integer' => '画风ID必须为整数',
- 'id.min' => '画风ID不能小于1',
- ]);
- if ($validator->fails()) {
- Utils::throwError('1002:' . $validator->errors()->first());
- }
- $result = $this->artStyleService->deleteArtStyle($data);
- return $this->success(['success' => $result ? 1 : 0]);
- }
- }
|