|
@@ -36,6 +36,9 @@ use App\Constants\ErrorCode;
|
|
|
use GuzzleHttp\Client;
|
|
|
use GuzzleHttp\Exception\GuzzleException;
|
|
|
use App\Model\SectorPlace;
|
|
|
+use App\Model\ComponentType;
|
|
|
+use App\Model\Article;
|
|
|
+use App\Model\WebsiteCategory;
|
|
|
#[RpcService(name: "PublicRpcService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
|
|
|
class PublicRpcService implements PublicRpcServiceInterface
|
|
|
{
|
|
@@ -1286,13 +1289,21 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
}
|
|
|
public function getComponentInfo(array $data): array
|
|
|
{
|
|
|
- $where = [];
|
|
|
+ $where = ['component.id'=>$data['id']];
|
|
|
+
|
|
|
$result = Component::where($where)
|
|
|
- ->leftJoin('template', 'template.id', '=', 'component.template_id')
|
|
|
- ->leftJoin('template_class', 'template_class.id', '=', 'template.template_class_id') // 添加这一行
|
|
|
+ // ->leftJoin('template_class', 'template_class.id', '=', 'template.template_class_id') // 去掉这一行
|
|
|
->leftJoin('sector', 'sector.id', '=', 'component.sector_id')
|
|
|
- ->select('template_class.name as template_class_name', 'template.template_name as template_name', 'sector.sector_name as sector_name', 'component.*')
|
|
|
+ ->leftJoin('template', 'template.template_id', '=', 'sector.template_id')
|
|
|
+ ->leftJoin('size','size.id','=','component.size_id')
|
|
|
+ ->leftJoin('component_type','component_type.id','=','component.type_id')
|
|
|
+ ->select( 'template.template_name as template_name', 'sector.sector_name as sector_name', 'component.*',
|
|
|
+ 'size.width','size.height','component_type.com_typename')
|
|
|
->get();
|
|
|
+ if(empty($result)){
|
|
|
+ return Result::error('暂无数据');
|
|
|
+ }
|
|
|
+
|
|
|
return Result::success($result);
|
|
|
}
|
|
|
/*
|
|
@@ -1419,34 +1430,29 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
$add_arr['component_data'] = json_encode($component_data,true);
|
|
|
}
|
|
|
|
|
|
- return Result::success($add_arr);
|
|
|
+ // return Result::success($add_arr);
|
|
|
Db::beginTransaction();
|
|
|
try{
|
|
|
$result = Component::insertGetId($add_arr);
|
|
|
- if(empty($result)){
|
|
|
+ if(empty($result)){
|
|
|
Db::rollBack();
|
|
|
return Result::error('添加失败!');
|
|
|
}
|
|
|
- // $sector_num = Sector::where('sector_id',$add_arr['sector_id'])->first();
|
|
|
- $component = Component::where('sector_id',$sector['sector_id'])->where('sort_id',$add_arr['sort_id'])->count();
|
|
|
- if($component == 0){
|
|
|
- $sector = Sector::where('sector_id',$sector['sector_id'])->update(['status',0]);
|
|
|
- if(empty($sector)){
|
|
|
+ $component = Component::where('sector_id',$sector['sector_id'])->distinct('sort_id')->count('sort_id');
|
|
|
+ // return Result::success($component == $sector['component_num']);
|
|
|
+ if($component == $sector['component_num'] && $sector['status'] == 0){
|
|
|
+ $sector_status = Sector::where('sector_id',$sector['sector_id'])->update(['status'=>1]);
|
|
|
+ if(empty($sector_status)){
|
|
|
Db::rollBack();
|
|
|
- return Result::error('通栏不存在!');
|
|
|
+ return Result::error('通栏状态不存在!');
|
|
|
}
|
|
|
}
|
|
|
Db::commit();
|
|
|
+ return Result::success($result);
|
|
|
}catch(\Exception $e){
|
|
|
Db::rollBack();
|
|
|
return Result::error($e->getMessage());
|
|
|
}
|
|
|
- // $result = Component::insertGetId($add_arr);
|
|
|
- if ($result) {
|
|
|
- return Result::success($result);
|
|
|
- } else {
|
|
|
- return Result::error('添加失败');
|
|
|
- }
|
|
|
}
|
|
|
public function delComponent(array $data): array
|
|
|
{
|
|
@@ -1456,8 +1462,6 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
return Result::error('组件不存在!');
|
|
|
}
|
|
|
// $sector_num = Sector::where('sector_id',$component['sector_id'])->first();
|
|
|
- $component_num = Component::where('id','!=',$data['id'])->where('sector_id',$component['sector_id'])
|
|
|
- ->where('sort_id',$component['sort_id'])->count();
|
|
|
Db::beginTransaction();
|
|
|
try{
|
|
|
$result = Component::where('id',$data['id'])->delete();
|
|
@@ -1465,7 +1469,10 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
Db::rollBack();
|
|
|
return Result::error('删除失败!');
|
|
|
}
|
|
|
- if($component_num == 0){
|
|
|
+ $component_num = Component::where('id','!=',$data['id'])->where('sector_id',$component['sector_id'])
|
|
|
+ ->where('sort_id',$component['sort_id'])->count();
|
|
|
+ $sector_status = Sector::where('sector_id',$component['sector_id'])->first();
|
|
|
+ if($component_num == 0 && $sector_status['status'] == 1){
|
|
|
$sector = Sector::where('sector_id',$component['sector_id'])->update(['status',0]);
|
|
|
if(empty($sector)){
|
|
|
Db::rollBack();
|
|
@@ -1482,15 +1489,17 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
public function updateComponent(array $data): array
|
|
|
{
|
|
|
unset($data['user_id']);
|
|
|
+ $id = $data['id'];
|
|
|
+ unset($data['id']);
|
|
|
$sector = Sector::where('sector_id',$data['sector_id'])->first();
|
|
|
if(empty($sector)){
|
|
|
return Result::error('通栏不存在!');
|
|
|
}
|
|
|
- $component_id = Component::function()->first();
|
|
|
+ $component_id = Component::where('id','!=',$id)->where('component_type',$data['component_type'])->first();
|
|
|
if(!empty($component_id) || $component_id != null){
|
|
|
return Result::error('组件编号已存在!');
|
|
|
}
|
|
|
- return Result::success($component_id);
|
|
|
+ // return Result::success($component_id);
|
|
|
$component_place = SectorPlace::where('sector_type',$sector['place_type'])
|
|
|
->where('type_id',2)->where('sort_id',$data['sort_id'])->first();
|
|
|
// return Result::success($component_place);
|
|
@@ -1586,7 +1595,6 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
break;
|
|
|
default:
|
|
|
break;
|
|
|
-
|
|
|
}
|
|
|
$component_head_code = [
|
|
|
'component_type' => $add_arr['component_type'],
|
|
@@ -1605,8 +1613,8 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
$add_arr['component_data'] = json_encode($component_data,true);
|
|
|
}
|
|
|
|
|
|
- return Result::success($add_arr);
|
|
|
- // $result = Component::where('id',$data['id'])->update($add_arr);
|
|
|
+ // return Result::success($add_arr);
|
|
|
+ $result = Component::where('id',$id)->update($add_arr);
|
|
|
if ($result) {
|
|
|
return Result::success($result);
|
|
|
} else {
|
|
@@ -2132,4 +2140,39 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
}
|
|
|
return Result::success($sector_place);
|
|
|
}
|
|
|
+ /**
|
|
|
+ * 组件管理-获取组件类型
|
|
|
+ */
|
|
|
+ public function getComponentType(array $data): array
|
|
|
+ {
|
|
|
+ $component_type = ComponentType::get()->all();
|
|
|
+ $article = Article::first()->toArray();
|
|
|
+ $category = WebsiteCategory::first()->toArray();
|
|
|
+ $footer_category = FooterCategory::first()->toArray();
|
|
|
+ $type_arr = [1,2,3,4,5,7,8,10];
|
|
|
+ // return Result::success(in_array(intval($value['id']),$type_arr));
|
|
|
+ foreach($component_type as $key => $value){
|
|
|
+ // 组件分类:1:资讯-头条组件;2:资讯-轮播组件;3:资讯-推荐类组件;4:资讯-热点类组件;5:栏目资讯类;
|
|
|
+ // 6:广告类组件;7:列表类组件;8:详情类组件;9:底部导航类组件;10:最新资讯类组件;11:导航栏类;
|
|
|
+ if(in_array(intval($value['id']),$type_arr)){
|
|
|
+ $component_type[$key]['all_code'] = array_keys($article);
|
|
|
+ }
|
|
|
+ if($value['id'] == 9){
|
|
|
+ $component_type[$key]['all_code'] = array_keys($footer_category);
|
|
|
+
|
|
|
+ }
|
|
|
+ if($value['id'] == 11){
|
|
|
+ $component_type[$key]['all_code'] = array_keys($category);
|
|
|
+
|
|
|
+ }
|
|
|
+ if($value['com_code']){
|
|
|
+ $component_type[$key]['com_code'] = json_decode($value['com_code'],true);
|
|
|
+ }
|
|
|
+ // $component_type[$key]['com_code'] = json_decode($value['com_code'],true);
|
|
|
+ }
|
|
|
+ if(empty($category)){
|
|
|
+ return Result::error('组件类型不存在!');
|
|
|
+ }
|
|
|
+ return Result::success($component_type);
|
|
|
+ }
|
|
|
}
|