|
@@ -41,7 +41,7 @@ use App\Model\Article;
|
|
|
use App\Model\WebsiteCategory;
|
|
|
use App\Model\AdPlace;
|
|
|
use App\Model\WebsiteImg;
|
|
|
-
|
|
|
+use App\Model\SectorComponent;
|
|
|
#[RpcService(name: "PublicRpcService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
|
|
|
class PublicRpcService implements PublicRpcServiceInterface
|
|
|
{
|
|
@@ -1172,17 +1172,28 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
if(empty($sector_place)){
|
|
|
return Result::error('位置不存在!');
|
|
|
}
|
|
|
- $sector = [
|
|
|
- 'template_id' => $data['template_id'],
|
|
|
- 'sector_type' => $data['sector_type'],
|
|
|
- 'sector_name' => $data['sector_name'],
|
|
|
- 'sector_id' => $data['sector_id'],
|
|
|
- 'place_type' => $data['place_type'],
|
|
|
- 'sector_width' => $data['sector_width'],
|
|
|
- 'sector_height' => $data['sector_height'],
|
|
|
- 'component_num' => $data['component_num'],
|
|
|
- 'page_type' => $data['page_type'],
|
|
|
- ];
|
|
|
+ $sort = json_decode($data['component_code'],true);
|
|
|
+ $kw = 0;
|
|
|
+ $flattened = [];
|
|
|
+ $component = [];
|
|
|
+ $sector_component = [];
|
|
|
+ foreach ($sort as $key => $subArray) {
|
|
|
+ foreach ($subArray as $k => $item) {
|
|
|
+ $component[] = $item;
|
|
|
+ $sector_component[] = [
|
|
|
+ 'sector_id' => $data['sector_id'],
|
|
|
+ 'component_id' => $item,
|
|
|
+ 'sort_id' => $key + 1,
|
|
|
+ 'place_id' => $data['place_type'],
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $component_num = count($component);
|
|
|
+ $count = count(array_unique($component));
|
|
|
+ // return Result::success($sector_component);
|
|
|
+ if(count($sort) != $data['component_num'] || $component_num != $count){
|
|
|
+ return Result::error('组件关联错误!');
|
|
|
+ }
|
|
|
// 通栏分类:1:资讯类:2:通栏广告类;3:混合类;4:头条类;5:轮播图类;
|
|
|
$sector_code = [
|
|
|
'sectorName' => $data['sector_name'],
|
|
@@ -1191,12 +1202,30 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
'sectorPlace' => $data['place_type'],
|
|
|
];
|
|
|
// return Result::success($sector_code);
|
|
|
- $data['sector_code'] = json_encode($sector_code);
|
|
|
- $result = Sector::insertGetId($data);
|
|
|
- if (empty($result)) {
|
|
|
- return Result::error('添加失败');
|
|
|
+ $data['sector_code'] = json_encode($sector_code);
|
|
|
+ Db::beginTransaction();
|
|
|
+ try {
|
|
|
+ $com_sector = SectorComponent::insert($sector_component);
|
|
|
+ if(empty($com_sector)){
|
|
|
+ Db::rollBack();
|
|
|
+ return Result::error('通栏关联组件失败!');
|
|
|
+ }
|
|
|
+ // $up_component = Component::whereIn('component_type',$sector_component['component_id'])->update(['status' => 2]);
|
|
|
+ // if(empty($up_component)){
|
|
|
+ // Db::rollBack();
|
|
|
+ // return Result::error('通栏关联组件失败!');
|
|
|
+ // }
|
|
|
+ $result = Sector::insertGetId($data);
|
|
|
+ if (empty($result)) {
|
|
|
+ Db::rollBack();
|
|
|
+ return Result::error('添加失败');
|
|
|
+ }
|
|
|
+ Db::commit();
|
|
|
+ return Result::success($result);
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ Db::rollBack();
|
|
|
+ return Result::error($e->getMessage());
|
|
|
}
|
|
|
- return Result::success($result);
|
|
|
}
|
|
|
/**
|
|
|
* 删除通栏
|
|
@@ -1205,15 +1234,27 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
*/
|
|
|
public function delSector(array $data): array
|
|
|
{
|
|
|
- $component_id = Component::where('sector_id', $data['id'])->pluck('id')->toArray();
|
|
|
- if (!empty($component_id)) {
|
|
|
- return Result::error('请先删除相关组件!');
|
|
|
+ $sector = Sector::where('id', $data['id'])->first();
|
|
|
+ if (empty($sector)) {
|
|
|
+ return Result::error('通栏不存在!');
|
|
|
}
|
|
|
- $result = Sector::where('id', $data['id'])->delete();
|
|
|
- if ($result == 1) {
|
|
|
- return Result::success('删除成功');
|
|
|
- } else {
|
|
|
- return Result::error('删除失败');
|
|
|
+ Db::beginTransaction();
|
|
|
+ try {
|
|
|
+ $component_id = SectorComponent::where('sector_id', $sector['sector_id'])->delete();
|
|
|
+ if (empty($component_id)) {
|
|
|
+ Db::rollBack();
|
|
|
+ return Result::error('解除相关组件关联关系失败!');
|
|
|
+ }
|
|
|
+ $result = Sector::where('id', $data['id'])->delete();
|
|
|
+ if (empty($result)) {
|
|
|
+ Db::rollBack();
|
|
|
+ return Result::error('通栏删除失败!');
|
|
|
+ }
|
|
|
+ Db::commit();
|
|
|
+ return Result::success('通栏删除成功!');
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ Db::rollBack();
|
|
|
+ return Result::error($e->getMessage());
|
|
|
}
|
|
|
}
|
|
|
/**
|
|
@@ -1251,11 +1292,69 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
if (empty($template)) {
|
|
|
return Result::error('皮肤不存在!');
|
|
|
}
|
|
|
- $result = Sector::where('id', $data['id'])->update($data);
|
|
|
- if ($result == 1) {
|
|
|
- return Result::success('修改成功');
|
|
|
- } else {
|
|
|
- return Result::error('修改失败');
|
|
|
+ $sort = json_decode($data['component_code'],true);
|
|
|
+ $kw = 0;
|
|
|
+ $flattened = [];
|
|
|
+ $component = [];
|
|
|
+ $sector_component = [];
|
|
|
+ foreach ($sort as $key => $subArray) {
|
|
|
+ foreach ($subArray as $k => $item) {
|
|
|
+ $component[] = $item;
|
|
|
+ $sector_component[] = [
|
|
|
+ 'sector_id' => $data['sector_id'],
|
|
|
+ 'component_id' => $item,
|
|
|
+ 'sort_id' => $key + 1,
|
|
|
+ 'place_id' => $data['place_type'],
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // // 批量插入数据到 ComponentSector 表
|
|
|
+ // \App\Model\ComponentSector::insert($sector_component);
|
|
|
+ $component_num = count($component);
|
|
|
+ $count = count(array_unique($component));
|
|
|
+ // return Result::success($sector_component);
|
|
|
+ if(count($sort) != $data['component_num'] || $component_num != $count){
|
|
|
+ return Result::error('组件关联错误!');
|
|
|
+ }
|
|
|
+ $data['sector_code'] = json_encode($sector_code);
|
|
|
+ Db::beginTransaction();
|
|
|
+ try {
|
|
|
+ $com_sector = SectorComponent::where('sector_id', $data['sector_id'])->pluck('component_id');
|
|
|
+ if(empty($com_sector)){
|
|
|
+ Db::rollBack();
|
|
|
+ return Result::error('通栏解除组件关联失败!');
|
|
|
+ }
|
|
|
+ // $up_component = Component::whereIn('component_type',$com_sector)->update(['status' => 1]);
|
|
|
+ // if(empty($up_component)){
|
|
|
+ // Db::rollBack();
|
|
|
+ // return Result::error('通栏解除组件关联失败!');
|
|
|
+ // }
|
|
|
+ $del_SectorComponent = SectorComponent::where('sector_id', $data['sector_id'])->delete();
|
|
|
+ if(empty($del_SectorComponent)){
|
|
|
+ Db::rollBack();
|
|
|
+ return Result::error('通栏解除组件关联失败!');
|
|
|
+ }
|
|
|
+ $com_sector = SectorComponent::insert($sector_component);
|
|
|
+ if(empty($com_sector)){
|
|
|
+ Db::rollBack();
|
|
|
+ return Result::error('通栏关联组件失败!');
|
|
|
+ }
|
|
|
+ // $up_component = Component::whereIn('component_id',$sector_component['component_type'])
|
|
|
+ // ->update(['status' => 2,]);
|
|
|
+ // if(empty($up_component)){
|
|
|
+ // Db::rollBack();
|
|
|
+ // return Result::error('通栏关联组件失败!');
|
|
|
+ // }
|
|
|
+ $result = Sector::where('id', $data['id'])->update($data);
|
|
|
+ if (empty($result)) {
|
|
|
+ Db::rollBack();
|
|
|
+ return Result::error('修改失败');
|
|
|
+ }
|
|
|
+ Db::commit();
|
|
|
+ return Result::success($result);
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ Db::rollBack();
|
|
|
+ return Result::error($e->getMessage());
|
|
|
}
|
|
|
}
|
|
|
public function getComponentList(array $data): array
|
|
@@ -1426,7 +1525,9 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
];
|
|
|
$add_arr['ad'] = json_encode($ad,true);
|
|
|
$add_arr['component_column'] = $component_type['com_code'] ?? '';
|
|
|
+ $add_arr['adimg_info'] = $data['img_info'];
|
|
|
$ad_imginfo = json_decode($data['img_info'],true);
|
|
|
+
|
|
|
break;
|
|
|
case 13: //13:底部导航类;
|
|
|
$component_data['componentData'] = [
|
|
@@ -1471,12 +1572,13 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
$add_arr['ad'] = json_encode($ad,true);
|
|
|
$add_arr['component_data'] = json_encode($component_data,true);
|
|
|
$add_arr['component_column'] = $component_type['com_code'] ?? '';
|
|
|
+ $add_arr['adimg_info'] = $data['img_info'];
|
|
|
+ $ad_imginfo = json_decode($data['img_info'],true);
|
|
|
break;
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
- var_dump($ad_imginfo);
|
|
|
- if($data['type_id'] == 11){
|
|
|
+ if($data['type_id'] == 11 || $data['type_id'] == 14){
|
|
|
Db::beginTransaction();
|
|
|
try{
|
|
|
$website_img = WebsiteImg::insertGetId($ad_imginfo);
|
|
@@ -1511,11 +1613,34 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
if(empty($component)){
|
|
|
return Result::error('组件不存在!');
|
|
|
}
|
|
|
- $result = Component::where('id',$data['id'])->delete();
|
|
|
- if(empty($result)){
|
|
|
+ $component_id = SectorComponent::where('component_id', $component['component_type'])->first();
|
|
|
+ if (!empty($component_id)) {
|
|
|
+ return Result::error('请先解除相关组件关联关系!');
|
|
|
+ }
|
|
|
+ Db::beginTransaction();
|
|
|
+ try{
|
|
|
+ if($component['type_id'] == 11 || $component['type_id'] == 14){
|
|
|
+ $ad_img = WebsiteImg::where('id',$component['ad_imgid'])->first();
|
|
|
+ if(!empty($ad_img)){
|
|
|
+ $ad_img = WebsiteImg::where('id',$component['ad_imgid'])->delete();
|
|
|
+ if(empty($ad_img)){
|
|
|
+ Db::rollBack();
|
|
|
+ return Result::error('删除广告默认图失败!');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $result = Component::where('id',$data['id'])->delete();
|
|
|
+ if(empty($result)){
|
|
|
+ Db::rollBack();
|
|
|
+ return Result::error('删除失败!');
|
|
|
+ }
|
|
|
+ Db::commit();
|
|
|
+ return Result::success($result);
|
|
|
+ }catch(\Exception $e){
|
|
|
+ Db::rollback();
|
|
|
return Result::error('删除失败!');
|
|
|
}
|
|
|
- return Result::success($result);
|
|
|
+
|
|
|
}
|
|
|
public function updateComponent(array $data): array
|
|
|
{
|
|
@@ -1530,6 +1655,10 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
if(empty($component_type)){
|
|
|
return Result::error('组件分类不存在!');
|
|
|
}
|
|
|
+ $component = Component::where('id',$id)->first();
|
|
|
+ if(empty($component)){
|
|
|
+ return Result::error('组件不存在!');
|
|
|
+ }
|
|
|
// 组件分类:1:资讯-头条组件;2:资讯-轮播组件;3:资讯-推荐图类组件;4:资讯-最新类组件;5:资讯-推荐类;6:资讯-热点类组件;
|
|
|
// 7:资讯-栏目类组件;8:列表类组件;9:详情类组件;10:二级导航栏类组件;11:广告类;12:静态资源类;13:底部导航类;
|
|
|
$data['type_id'] = intval($data['type_id']);
|
|
@@ -1642,6 +1771,7 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
];
|
|
|
$add_arr['ad'] = json_encode($ad,true);
|
|
|
$add_arr['component_column'] = $component_type['com_code'] ?? '';
|
|
|
+ $add_arr['adimg_info'] = $data['img_info'];
|
|
|
$ad_imginfo = json_decode($data['img_info'],true);
|
|
|
break;
|
|
|
case 13: //13:底部导航类;
|
|
@@ -1687,10 +1817,14 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
$add_arr['ad'] = json_encode($ad,true);
|
|
|
$add_arr['component_data'] = json_encode($component_data,true);
|
|
|
$add_arr['component_column'] = $component_type['com_code'] ?? '';
|
|
|
+ $add_arr['adimg_info'] = $data['img_info'];
|
|
|
+ $ad_imginfo = json_decode($data['img_info'],true);
|
|
|
break;
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
+
|
|
|
+ // var_dump("ad_imginfo:",$ad_imginfo);
|
|
|
$cll_column = [
|
|
|
'img_num' => null,
|
|
|
'text_num' => null,
|
|
@@ -1710,12 +1844,12 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
'ad' => '',
|
|
|
'ad_type' => null,
|
|
|
'ad_imgid' => null,
|
|
|
+ 'adimg_info' => '[]',
|
|
|
];
|
|
|
Db::beginTransaction();
|
|
|
try{
|
|
|
- $component = Component::where('id',$id)->first();
|
|
|
// return Result::success($add_arr);
|
|
|
- if($component['type_id'] == 11 && $component['type_id'] != $data['type_id']){
|
|
|
+ if(($component['type_id'] == 11 || $component['type_id'] == 14) && ($data['type_id'] != 11 && $data['type_id'] != 14)){
|
|
|
$website_img = WebsiteImg::where('id',$component['ad_imgid'])->delete();
|
|
|
|
|
|
if(empty($website_img)){
|
|
@@ -1725,7 +1859,7 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
var_dump("删除",$website_img);
|
|
|
|
|
|
}
|
|
|
- if($data['type_id'] == 11 && $component['type_id'] != $data['type_id']){
|
|
|
+ if(($data['type_id'] == 11 || $data['type_id'] == 14) && ($component['type_id'] != 11 && $component['type_id'] != 14)){
|
|
|
$website_img = WebsiteImg::insertGetId($ad_imginfo);
|
|
|
$add_arr['ad_imgid'] = $website_img;
|
|
|
if(empty($website_img)){
|
|
@@ -1735,24 +1869,27 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
var_dump("上传",$website_img);
|
|
|
|
|
|
}
|
|
|
- if($data['type_id'] == 11 && $component['type_id'] == $data['type_id']){
|
|
|
- $website_img = WebsiteImg::where('id',$component['ad_imgid'])->update($ad_imginfo);
|
|
|
+ if(($component['type_id'] == 11 || $component['type_id'] == 14) && ($data['type_id'] == 11 || $data['type_id'] == 14)){
|
|
|
+ $website_img = WebsiteImg::where('id',$component['ad_imgid'])->first();
|
|
|
+ if(empty($website_img)){
|
|
|
+ $website_img = WebsiteImg::insertGetId($ad_imginfo);
|
|
|
+ $add_arr['ad_imgid'] = $website_img;
|
|
|
+ }else{
|
|
|
+ $website_img = WebsiteImg::where('id',$component['ad_imgid'])->update($ad_imginfo);
|
|
|
+ $add_arr['ad_imgid'] = $component['ad_imgid'];
|
|
|
+ }
|
|
|
if(empty($website_img)){
|
|
|
Db::rollBack();
|
|
|
return Result::error('广告默认图修改失败!');
|
|
|
}
|
|
|
- var_dump("修改",$website_img);
|
|
|
|
|
|
}
|
|
|
$add_arr = array_merge($cll_column,$add_arr);
|
|
|
- // $result = Component::where('id',$id)->get();
|
|
|
- // return Result::success($result);
|
|
|
$result = Component::where('id',$id)->update($add_arr);
|
|
|
- // var_dump("修改zj",$add_arr);
|
|
|
- // if(empty($result)){
|
|
|
- // Db::rollBack();
|
|
|
- // return Result::error('修改失败!');
|
|
|
- // }
|
|
|
+ if(empty($result)){
|
|
|
+ Db::rollBack();
|
|
|
+ return Result::error('修改失败!');
|
|
|
+ }
|
|
|
Db::commit();
|
|
|
}catch(\Exception $e){
|
|
|
Db::rollBack();
|
|
@@ -2235,7 +2372,7 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
if (isset($sector['component_num']) && is_numeric($sector['component_num'])) {
|
|
|
$num = intval($sector['component_num']);
|
|
|
if ($num > 0 && $num <= 10) {
|
|
|
-// 使用 range 函数生成一个从 1 到 $num 的连续整数数组,存储到 $sector_arr 中
|
|
|
+ // 使用 range 函数生成一个从 1 到 $num 的连续整数数组,存储到 $sector_arr 中
|
|
|
$sector_arr = range(1, $num);
|
|
|
} else {
|
|
|
$sector_arr = [];
|
|
@@ -2262,9 +2399,9 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
public function getAllSectorPlace(array $data): array
|
|
|
{
|
|
|
$where['type_id'] = $data['type_id'];
|
|
|
- if($data['type_id'] == 1){
|
|
|
- $where['status'] = 1;
|
|
|
- }
|
|
|
+ // if($data['type_id'] == 1){
|
|
|
+ // $where['status'] = 1;
|
|
|
+ // }
|
|
|
if(isset($data['sector_type']) && !empty($data['sector_type'])){
|
|
|
$where['sector_type'] = $data['sector_type'];
|
|
|
}
|
|
@@ -2272,9 +2409,17 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
$where['component_num'] = $data['component_num'];
|
|
|
}
|
|
|
$sector_place = SectorPlace::where($where)
|
|
|
- ->leftJoin('size','sector_place.size_id','=','size.id')
|
|
|
- ->select('sector_place.*','size.width','size.height')
|
|
|
+ // ->select('sector_place.*','size.width','size.height')
|
|
|
->get()->all();
|
|
|
+ if($data['type_id'] == 2){
|
|
|
+ foreach($sector_place as $key => $value){
|
|
|
+ $sector_place[$key]['component'] = Component::where('type_id',$value['type'])
|
|
|
+ ->where('component_width',$value['width'])
|
|
|
+ ->where('component_height',$value['height'])
|
|
|
+ ->get()->all();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
if(empty($sector_place)){
|
|
|
return Result::error('通栏版式不存在!');
|
|
|
}
|
|
@@ -2312,15 +2457,27 @@ class PublicRpcService implements PublicRpcServiceInterface
|
|
|
public function getAllComponent(array $data): array
|
|
|
{
|
|
|
$where = [];
|
|
|
- if(isset($data['sector_id']) && !empty($data['sector_id'])){
|
|
|
- $where['component.sector_id'] = $data['sector_id'];
|
|
|
- }
|
|
|
- if(isset($data['sort_id']) && !empty($data['sort_id'])){
|
|
|
- $where['component.sort_id'] = $data['sort_id'];
|
|
|
+ if((isset($data['sector_id']) && !empty($data['sector_id'])) || (isset($data['sort_id']) && !empty($data['sort_id']))){
|
|
|
+ $sector['sector_component.sector_id'] = $data['sector_id'];
|
|
|
+ $sector['sector_component.sort_id'] = $data['sort_id'];
|
|
|
+ $where = SectorComponent::where($sector)->pluck('component_id')->toArray();
|
|
|
+ $component = Component::whereIn('id',$where)->get()->all();
|
|
|
+ }else{
|
|
|
+ if(isset($data['type_id']) && !empty($data['type_id'])){
|
|
|
+ $where['component.type_id'] = $data['type_id'];
|
|
|
+ }
|
|
|
+ if(isset($data['width']) && !empty($data['width'])){
|
|
|
+ $where['component.component_width'] = $data['width'];
|
|
|
+ }
|
|
|
+ if(isset($data['height']) && !empty($data['height'])){
|
|
|
+ $where['component.component_height'] = $data['height'];
|
|
|
+ }
|
|
|
+ $component = Component::where($where)
|
|
|
+ // ->leftJoin('size','component.size_id','=','size.id')
|
|
|
+ // ->select('component.*','size.width','size.height')
|
|
|
+ ->get()->all();
|
|
|
}
|
|
|
- $component = Component::where($where)->leftJoin('size','component.size_id','=','size.id')
|
|
|
- ->select('component.*','size.width','size.height')
|
|
|
- ->get()->all();
|
|
|
+
|
|
|
if(empty($component)){
|
|
|
return Result::error('组件不存在!');
|
|
|
}
|