|
@@ -655,11 +655,12 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
if (isset($data['name']) && $data['name']) {
|
|
|
array_push($where, ['template_class.name', 'like', '%' . $data['name'] . '%']);
|
|
|
}
|
|
|
+ if(isset($data['keyword']) && $data['keyword']){
|
|
|
+ array_push($where, ['template_class.keyword', 'like', '%'. $data['keyword']. '%']);
|
|
|
+ }
|
|
|
$template = TemplateClass::when($where, function ($query) use ($where) {
|
|
|
$query->where($where);
|
|
|
});
|
|
|
-
|
|
|
-
|
|
|
$count = $template->count();
|
|
|
// $countQuery = clone $template;
|
|
|
$row = $template
|
|
@@ -691,9 +692,11 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
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);
|
|
|
+ $template_class = TemplateClass::where('name', $data['name'])
|
|
|
+ ->orWhere('class_id', $data['class_id'])
|
|
|
+ ->first();
|
|
|
+ if ($template_class) {
|
|
|
+ return Result::error("风格名称或者风格编号已存在,不可添加!", 0);
|
|
|
}
|
|
|
$result = TemplateClass::insertGetId($data);
|
|
|
if (empty($result)) {
|
|
@@ -713,16 +716,19 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
$where = [
|
|
|
'id' => $data['id'],
|
|
|
];
|
|
|
- $template = TemplateClass::where($where)->first();
|
|
|
- if (empty($template)) {
|
|
|
+ $template_class = TemplateClass::where('id', $data['id'])->first();
|
|
|
+ if (empty($template_class)) {
|
|
|
return Result::error("未查询到风格", 0);
|
|
|
}
|
|
|
- if($template->type == 1){
|
|
|
+ if($template_class->type == 1){
|
|
|
return Result::error("默认风格不能修改", 0);
|
|
|
}
|
|
|
- $template = TemplateClass::where('id','!=',$data['id'])->where(['name' => $data['name']])->first();
|
|
|
+ $template = TemplateClass::where('id','!=',$data['id'])
|
|
|
+ ->where(['name' => $data['name']])
|
|
|
+ ->orWhere(['class_id' => $data['class_id']])
|
|
|
+ ->first();
|
|
|
if ($template) {
|
|
|
- return Result::error("风格名称已存在", 0);
|
|
|
+ return Result::error("风格名称或者风格编号已存在,不可编辑!", 0);
|
|
|
}
|
|
|
$updateData = [
|
|
|
'name' => $data['name'],
|
|
@@ -770,6 +776,11 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
$result = TemplateClass::get();
|
|
|
return Result::success($result);
|
|
|
}
|
|
|
+ /**
|
|
|
+ * 获取皮肤列表
|
|
|
+ * @param array $data
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
public function getTemplateList(array $data): array
|
|
|
{
|
|
|
$where = [];
|
|
@@ -777,7 +788,10 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
$where['template_class_id'] = $data['template_class_id'];
|
|
|
}
|
|
|
if (!empty($data['template_name'])) {
|
|
|
- $where['template_name'] = $data['template_name'];
|
|
|
+ array_push($where, ['template_name', 'like', '%'. $data['template_name']. '%']);
|
|
|
+ }
|
|
|
+ if (!empty($data['template_keyword'])) {
|
|
|
+ array_push($where, ['template_keyword', 'like', '%'. $data['template_keyword']. '%']);
|
|
|
}
|
|
|
$result = Template::where($where)
|
|
|
->leftJoin('template_class', 'template.template_class_id', 'template_class.id')
|
|
@@ -799,18 +813,33 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
->first();
|
|
|
return Result::success($result);
|
|
|
}
|
|
|
+ /**
|
|
|
+ * 添加皮肤
|
|
|
+ * @param array $data
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
public function addTemplate(array $data): array
|
|
|
{
|
|
|
var_dump($data);
|
|
|
unset($data['user_id']);
|
|
|
+ $template = Template::where('template_name', $data['template_name'])
|
|
|
+ ->orWhere('template_id', $data['template_id'])
|
|
|
+ ->first();
|
|
|
+ if ($template) {
|
|
|
+ return Result::error("皮肤名称或者皮肤编号已存在,不可添加!", 0);
|
|
|
+ }
|
|
|
$result = Template::insertGetId($data);
|
|
|
- if ($result) {
|
|
|
- $returData = Template::where('id', $result)->first();
|
|
|
- return Result::success($returData);
|
|
|
- } else {
|
|
|
- return Result::error("添加失败", 0);
|
|
|
+ if(empty($result)){
|
|
|
+ return Result::error("创建失败", 0);
|
|
|
+ }else{
|
|
|
+ return Result::success($result);
|
|
|
}
|
|
|
}
|
|
|
+ /**
|
|
|
+ * 删除皮肤
|
|
|
+ * @param array $data
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
public function delTemplate(array $data): array
|
|
|
{
|
|
|
$result = Template::where('id', $data['id'])->delete();
|
|
@@ -821,9 +850,26 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
return Result::error("删除失败", 0);
|
|
|
}
|
|
|
}
|
|
|
+ /**
|
|
|
+ * 更新皮肤
|
|
|
+ * @param array $data
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
public function updateTemplate(array $data): array
|
|
|
{
|
|
|
unset($data['user_id']);
|
|
|
+ $template = Template::where('id', $data['id'])
|
|
|
+ ->first();
|
|
|
+ if (empty($template)) {
|
|
|
+ return Result::error("此皮肤不存在!", 0);
|
|
|
+ }
|
|
|
+ $template = Template::where('id','!=',$data['id'])
|
|
|
+ ->where(['template_name' => $data['template_name']])
|
|
|
+ ->orWhere(['template_id' => $data['template_id']])
|
|
|
+ ->first();
|
|
|
+ if ($template) {
|
|
|
+ return Result::error("皮肤名称或者皮肤编号已存在,不可编辑!", 0);
|
|
|
+ }
|
|
|
$result = Template::where('id', $data['id'])->update($data);
|
|
|
var_dump($result, '-------------------update');
|
|
|
if (!$result) {
|