|
@@ -25,9 +25,7 @@ use App\Model\Sector;
|
|
|
use App\Model\Component;
|
|
|
use App\Model\Link;
|
|
|
use App\Model\FooterCategory;
|
|
|
-
|
|
|
-use function Hyperf\Support\retry;
|
|
|
-
|
|
|
+use App\Model\Size;
|
|
|
#[RpcService(name: "PublicRpcService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
|
|
|
class PublicRpcService implements PublicRpcServiceInterface
|
|
|
{
|
|
@@ -769,12 +767,19 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
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);
|
|
|
+
|
|
|
+ try{
|
|
|
+ // 默认风格 1
|
|
|
+ $template = Template::where('template_class_id',$data['id'])->update(['template_class_id'=>1]);
|
|
|
+ if(empty($template)){
|
|
|
+ Db::rollBack();
|
|
|
+ return Result::error("删除失败", 0);
|
|
|
+ }
|
|
|
+ $result = TemplateClass::where($where)->delete();
|
|
|
+ }catch (\Exception $e){
|
|
|
+ return Result::error("删除失败".$e->getMessage(), 0);
|
|
|
}
|
|
|
+ return Result::success($result);
|
|
|
}
|
|
|
/**
|
|
|
* 获取getTemplateClass
|
|
@@ -854,8 +859,12 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
* @param array $data
|
|
|
* @return array
|
|
|
*/
|
|
|
- public function delTemplate(array $data): array
|
|
|
+ public function delTemplate(array $data): array
|
|
|
{
|
|
|
+ $rector = Sector::where('template_id', $data['id'])->first();
|
|
|
+ if (!empty($rector)) {
|
|
|
+ return Result::error("此皮肤已被绑定,不可删除", 0);
|
|
|
+ }
|
|
|
$result = Template::where('id', $data['id'])->delete();
|
|
|
var_dump($result, '-------------------delete');
|
|
|
if ($result) {
|
|
@@ -897,42 +906,61 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
return Result::success('更新成功');
|
|
|
}
|
|
|
}
|
|
|
+ /**
|
|
|
+ * 获取通栏列表
|
|
|
+ * @param array $data
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
public function getSectorList(array $data): array
|
|
|
{
|
|
|
$where = [];
|
|
|
- if (!empty($data['template_class_id'])) {
|
|
|
- $where['template_class.id'] = $data['template_class_id'];
|
|
|
+ if (isset($data['template_class_id']) && !empty($data['template_class_id'])) {
|
|
|
+ $where['template_class_id'] = $data['template_class_id'];
|
|
|
}
|
|
|
- if (!empty($data['template_class_name'])) {
|
|
|
- $where[] = ['template_class.name', 'like', '%' . $data['template_class_name'] . '%'];
|
|
|
+ if (isset($data['template_id']) && !empty($data['template_id'])) {
|
|
|
+ array_push($where, ['template_id', $data['template_id']]);
|
|
|
}
|
|
|
-
|
|
|
- if (!empty($data['sector_name'])) {
|
|
|
- if (!empty($data['sector_name'])) {
|
|
|
- // $where['sector_name'] = $data['sector_name'];
|
|
|
- $where[] = ['sector.sector_name', 'like', '%' . $data['sector_name'] . '%'];
|
|
|
- }
|
|
|
+ if (isset($data['sector_name']) && !empty($data['sector_name'])) {
|
|
|
+ array_push($where, ['sector.sector_name', 'like', '%' . $data['sector_name'] . '%']);
|
|
|
}
|
|
|
-
|
|
|
+ if (isset($data['width']) && !empty($data['width']) && isset($data['height']) && !empty($data['height'])){
|
|
|
+ $size_id = Size::where('width','like','%' .$data['width'].'%')->where('height','like','%' .$data['height'].'%')->value('id')->all();
|
|
|
+ } else if( isset($data['width']) && !empty($data['width'])){
|
|
|
+ $size_id = Size::where('width','like','%' .$data['width'].'%')->value('id')->all();
|
|
|
+ }else if( isset($data['height']) && !empty($data['height'])){
|
|
|
+ $size_id = Size::where('height','like','%' .$data['height'].'%')->value('id')->all();
|
|
|
+ }else{
|
|
|
+ $size_id = [];
|
|
|
+ }
|
|
|
+ // $size_id = $size_id->toArray();
|
|
|
$result = Sector::where($where)
|
|
|
- ->leftJoin('template', 'template.id', '=', 'sector.template_id')
|
|
|
- ->leftJoin('template_class', 'template_class.id', '=', 'sector.template_id') // 添加这一行
|
|
|
- ->select('sector.*', 'sector.sector_name', 'template.template_name', 'template_class.name as template_class_name', 'template_class.id as template_class_id') // 修改这一行
|
|
|
+ ->when(!empty($size_id), function ($query) use ($size_id) {
|
|
|
+ $query->whereIn('size_id', $size_id);
|
|
|
+ })
|
|
|
+ ->leftJoin('size', 'size.id', '=', 'sector.size_id')
|
|
|
+ ->select('sector.*', 'size.width','size.height')
|
|
|
->orderBy('sector.id', 'desc')
|
|
|
- ->paginate($data['page_size'], ['*'], 'mypage_name', $data['page']);
|
|
|
-
|
|
|
+ ->paginate($data['page_size'], ['*'], 'page', $data['page']);
|
|
|
return Result::success($result);
|
|
|
}
|
|
|
+ /**
|
|
|
+ * 获取通栏详情
|
|
|
+ * @param array $data
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+
|
|
|
public function getSectorInfo(array $data): array
|
|
|
{
|
|
|
$where = [];
|
|
|
$where[] = ['sector.id', '=', $data['id']];
|
|
|
$result = Sector::where($where)
|
|
|
- ->leftJoin('template', 'template.id', '=', 'sector.template_id')
|
|
|
- ->leftJoin('template_class', 'template_class.id', '=', 'template.template_class_id') // 添加这一行
|
|
|
- ->select('sector.*', 'template.template_name', 'template_class.name as template_class_name', 'template_class.id as template_class_id') // 修改这一行
|
|
|
+ ->leftJoin('size', 'size.id', '=', 'sector.size_id')
|
|
|
+ ->select('sector.*', 'size.width','size.height')
|
|
|
->orderBy('sector.id', 'desc')
|
|
|
- ->get();
|
|
|
+ ->first();
|
|
|
+ if(empty($result)){
|
|
|
+ return Result::error('此通栏不存在!');
|
|
|
+ }
|
|
|
return Result::success($result);
|
|
|
}
|
|
|
|
|
@@ -1009,15 +1037,33 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
$result = $calendar->solar($data['year'], $data['month'], $data['day'], $data['hour']); // 阳历
|
|
|
return Result::success($result);
|
|
|
}
|
|
|
+ /**
|
|
|
+ * 添加通栏
|
|
|
+ * @param array $data
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
public function addSector(array $data): array
|
|
|
{
|
|
|
unset($data['user_id']);
|
|
|
- // $data['page_type'] = json_encode($data['page_type']);
|
|
|
+ $data['page_type'] = array_values(array_unique(array_map('intval', $data['page_type'])));
|
|
|
+ $data['page_type'] = json_encode($data['page_type']);
|
|
|
$result = Sector::insertGetId($data);
|
|
|
- return Result::success();
|
|
|
+ if(empty($result)){
|
|
|
+ return Result::error('添加失败');
|
|
|
+ }
|
|
|
+ return Result::success($result);
|
|
|
}
|
|
|
+ /**
|
|
|
+ * 删除通栏
|
|
|
+ * @param array $data
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
public function delSector(array $data): array
|
|
|
{
|
|
|
+ $component_id = Component::where('sector_id', $data['id'])->pluck('id')->toArray();
|
|
|
+ if(!empty($component_id)){
|
|
|
+ return Result::error('请先删除相关组件!');
|
|
|
+ }
|
|
|
$result = Sector::where('id', $data['id'])->delete();
|
|
|
if ($result == 1) {
|
|
|
return Result::success('删除成功');
|
|
@@ -1025,9 +1071,16 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
return Result::error('删除失败');
|
|
|
}
|
|
|
}
|
|
|
+ /**
|
|
|
+ * 修改通栏
|
|
|
+ * @param array $data
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
public function updateSector(array $data): array
|
|
|
{
|
|
|
unset($data['user_id']);
|
|
|
+ $data['page_type'] = array_values(array_unique(array_map('intval', $data['page_type'])));
|
|
|
+ $data['page_type'] = json_encode($data['page_type']);
|
|
|
$result = Sector::where('id', $data['id'])->update($data);
|
|
|
if ($result == 1) {
|
|
|
return Result::success('修改成功');
|