|
@@ -647,6 +647,119 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
return Result::error("修改失败" . $e->getMessage(), 0);
|
|
|
}
|
|
|
}
|
|
|
+ /**
|
|
|
+ * 获取风格
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function getTemplateClassList(array $data): array
|
|
|
+ {
|
|
|
+ $where = [];
|
|
|
+ if (isset($data['name']) && $data['name']) {
|
|
|
+ array_push($where, ['template_class.name', 'like', '%' . $data['name'] . '%']);
|
|
|
+ }
|
|
|
+ $template = TemplateClass::when($where, function ($query) use ($where) {
|
|
|
+ $query->where($where);
|
|
|
+ })
|
|
|
+ ->leftJoin('template', 'template_class.id', '=', 'template.template_class_id')
|
|
|
+ ->select('template_class.*', DB::raw('COUNT(template.id) as template_count'))
|
|
|
+ ->groupBy('template_class.id')
|
|
|
+ ->orderBy('template_class.updated_at', 'desc');
|
|
|
+ $countQuery = clone $template;
|
|
|
+ $count = $countQuery->count();
|
|
|
+ $row = $template
|
|
|
+ ->offset(($data['page'] - 1) * $data['pageSize'])
|
|
|
+ ->limit($data['pageSize'])
|
|
|
+ ->get();
|
|
|
+
|
|
|
+ $result = [
|
|
|
+ 'rows' => $row,
|
|
|
+ 'count' => $count,
|
|
|
+ ];
|
|
|
+
|
|
|
+ if ($row->isEmpty()) {
|
|
|
+ return Result::error("暂无风格", 0);
|
|
|
+ } else {
|
|
|
+ return Result::success($result);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 添加风格
|
|
|
+ * @param
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function addTemplateClass(array $data): array
|
|
|
+ {
|
|
|
+ $data['keyword'] = json_encode($data['keyword']);
|
|
|
+ $template = TemplateClass::where(['name' => $data['name']])->first();
|
|
|
+ if ($template) {
|
|
|
+ return Result::error("风格名称已存在", 0);
|
|
|
+ }
|
|
|
+ $result = TemplateClass::insertGetId($data);
|
|
|
+ if (empty($result)) {
|
|
|
+ return Result::error("创建风格失败", 0);
|
|
|
+ } else {
|
|
|
+ return Result::success(["id" => $result]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 更新风格
|
|
|
+ * @param array $data
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ public function upTemplateClass(array $data): array
|
|
|
+ {
|
|
|
+ $where = [
|
|
|
+ 'id' => $data['id'],
|
|
|
+ ];
|
|
|
+ $template = TemplateClass::where($where)->first();
|
|
|
+ if (empty($template)) {
|
|
|
+ return Result::error("未查询到风格", 0);
|
|
|
+ }
|
|
|
+ if($template->type == 1){
|
|
|
+ return Result::error("默认风格不能修改", 0);
|
|
|
+ }
|
|
|
+ $template = TemplateClass::where('id','!=',$data['id'])->where(['name' => $data['name']])->first();
|
|
|
+ if ($template) {
|
|
|
+ return Result::error("风格名称已存在", 0);
|
|
|
+ }
|
|
|
+ $updateData = [
|
|
|
+ 'name' => $data['name'],
|
|
|
+ 'keyword' => json_encode($data['keyword']),
|
|
|
+ ];
|
|
|
+ $result = TemplateClass::where($where)->update($updateData);
|
|
|
+ if (empty($result)) {
|
|
|
+ return Result::error("更新失败", 0);
|
|
|
+ } else {
|
|
|
+ return Result::success($result);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除风格
|
|
|
+ * @param array $data
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ public function delTemplateClass(array $data): array
|
|
|
+ {
|
|
|
+ $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($result);
|
|
|
+ }
|
|
|
+ }
|
|
|
/**
|
|
|
* 获取getTemplateClass
|
|
|
* @param array $data
|