|
@@ -835,43 +835,59 @@ class WebsiteService implements WebsiteServiceInterface
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 获取模板类型
|
|
|
+ * 获取风格
|
|
|
* @return void
|
|
|
*/
|
|
|
public function getTemplateClass(array $data): array
|
|
|
{
|
|
|
+ // return Result::success($data);
|
|
|
$where = [];
|
|
|
if (isset($data['name']) && $data['name']) {
|
|
|
array_push($where, ['name', 'like', '%' . $data['name'] . '%']);
|
|
|
}
|
|
|
- $result = TemplateClass::where($where)->orderBy('sort', 'asc')->get();
|
|
|
+ $template = TemplateClass::when($where, function ($query) use ($where) {
|
|
|
+ $query->where($where);
|
|
|
+ })
|
|
|
+ ->orderBy('updated_at', 'desc');
|
|
|
+ $count = $template->count();
|
|
|
+ $row = $template
|
|
|
+ ->offset(($data['page'] - 1) * $data['pageSize'])
|
|
|
+ ->limit($data['pageSize'])
|
|
|
+ ->get();
|
|
|
+ $result = [
|
|
|
+ 'rows' => $row,
|
|
|
+ 'count' => $count,
|
|
|
+ ];
|
|
|
if (empty($result)) {
|
|
|
- return Result::error("没有模板类型", 0);
|
|
|
+ return Result::error("暂无风格", 0);
|
|
|
} else {
|
|
|
return Result::success($result);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 添加模板类型
|
|
|
+ * 添加风格
|
|
|
* @param
|
|
|
* @return void
|
|
|
*/
|
|
|
public function addTemplateClass(array $data): array
|
|
|
{
|
|
|
- $insertData = [
|
|
|
- 'name' => $data['name'],
|
|
|
- ];
|
|
|
- $result = TemplateClass::insertGetId($insertData);
|
|
|
+ $data['keyword'] = json_encode($data['keyword']);
|
|
|
+ $template = TemplateClass::where(['name' => $data['name']])->first();
|
|
|
+ if ($template) {
|
|
|
+ return Result::error("风格名称已存在", 0);
|
|
|
+ }
|
|
|
+ // return Result::success($data);
|
|
|
+ $result = TemplateClass::insertGetId($data);
|
|
|
if (empty($result)) {
|
|
|
- return Result::error("创建失败", 0);
|
|
|
+ return Result::error("创建风格失败", 0);
|
|
|
} else {
|
|
|
return Result::success(["id" => $result]);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 更新模板
|
|
|
+ * 更新风格
|
|
|
* @param array $data
|
|
|
* @return array
|
|
|
*/
|
|
@@ -880,19 +896,31 @@ class WebsiteService implements WebsiteServiceInterface
|
|
|
$where = [
|
|
|
'id' => $data['id'],
|
|
|
];
|
|
|
- $insertData = [
|
|
|
+ $template = TemplateClass::where($where)->first();
|
|
|
+ if (empty($template)) {
|
|
|
+ return Result::error("未查询到风格", 0);
|
|
|
+ }
|
|
|
+ if($template->type == 1){
|
|
|
+ return Result::error("默认风格不能修改", 0);
|
|
|
+ }
|
|
|
+ $template = TemplateClass::where(['name' => $data['name']])->where('id','!=','id')->first();
|
|
|
+ if ($template) {
|
|
|
+ return Result::error("风格名称已存在", 0);
|
|
|
+ }
|
|
|
+ $updateData = [
|
|
|
'name' => $data['name'],
|
|
|
+ 'keyword' => json_encode($data['keyword']),
|
|
|
];
|
|
|
- $result = TemplateClass::where($where)->update($insertData);
|
|
|
+ $result = TemplateClass::where($where)->update($updateData);
|
|
|
if (empty($result)) {
|
|
|
return Result::error("更新失败", 0);
|
|
|
} else {
|
|
|
- return Result::success();
|
|
|
+ return Result::success($result);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 删除模板
|
|
|
+ * 删除风格
|
|
|
* @param array $data
|
|
|
* @return array
|
|
|
*/
|
|
@@ -901,12 +929,18 @@ class WebsiteService implements WebsiteServiceInterface
|
|
|
$where = [
|
|
|
'id' => $data['id'],
|
|
|
];
|
|
|
-
|
|
|
+ $template = TemplateClass::where($where)->first();
|
|
|
+ if (empty($template)) {
|
|
|
+ return Result::error("未查询到风格", 0);
|
|
|
+ }
|
|
|
+ if($template->type == 1){
|
|
|
+ return Result::error("默认风格不能删除", 0);
|
|
|
+ }
|
|
|
$result = TemplateClass::where($where)->delete();
|
|
|
if (empty($result)) {
|
|
|
return Result::error("删除失败", 0);
|
|
|
} else {
|
|
|
- return Result::success();
|
|
|
+ return Result::success($result);
|
|
|
}
|
|
|
}
|
|
|
|