|
@@ -788,8 +788,10 @@ class WebsiteService implements WebsiteServiceInterface
|
|
|
{
|
|
|
Db::beginTransaction();
|
|
|
try{
|
|
|
+ //合并栏目id
|
|
|
+ $reqIds = array_merge($data['old_category_arr_id'],$data['new_category_arr_id']);
|
|
|
//对比old 数组差异化,把差异化的删除
|
|
|
- $result = WebsiteCategory::where(['website_id'=>$data['website_id']])->get();
|
|
|
+ $result = WebsiteCategory::where(['website_id'=>$data['website_id'],'pid'=>0])->get();
|
|
|
$result = $result->toArray();
|
|
|
$categoryIds = [];
|
|
|
if($result){
|
|
@@ -797,15 +799,31 @@ class WebsiteService implements WebsiteServiceInterface
|
|
|
array_push($categoryIds,$val['category_id']);
|
|
|
}
|
|
|
}
|
|
|
- $differenceIDS = array_diff($data['old_category_arr_id'], $categoryIds);
|
|
|
- //有差异 删除
|
|
|
+ //和原始数据对比取交际
|
|
|
+ $reqidsIntersect = array_intersect($reqIds,$categoryIds);
|
|
|
+ //再取差集 进行对比
|
|
|
+ $differenceIDS = array_merge(array_diff($reqidsIntersect, $categoryIds),array_diff($categoryIds,$reqidsIntersect));
|
|
|
+ var_dump("差集:",$differenceIDS);
|
|
|
if(count($differenceIDS)>0){
|
|
|
- WebsiteCategory::where(['website_id'=>$data['website_id']])->whereIn("category_id",$differenceIDS)->delete();
|
|
|
+ $arr_ids = [];
|
|
|
+ foreach ($differenceIDS as $vv){
|
|
|
+ $idV = $this->getUnderlingUIds(intval($vv));
|
|
|
+ $ids_arrV = explode(",", $idV);
|
|
|
+ array_push($arr_ids,$ids_arrV);
|
|
|
+ }
|
|
|
}
|
|
|
+ $del_ids = array_reduce($arr_ids, 'array_merge', array());
|
|
|
+ //有差异 删除
|
|
|
+ if(count($del_ids)>0){
|
|
|
+ WebsiteCategory::where(['website_id'=>$data['website_id']])->whereIn("category_id",$del_ids)->delete();
|
|
|
+ }
|
|
|
+ //传过来的值 和 交际 对比,选出要添加的值 进行插入
|
|
|
+ $insertIDS = array_merge(array_diff($reqIds, $reqidsIntersect),array_diff($reqidsIntersect,$reqIds));
|
|
|
+ var_dump("要存储的:",$insertIDS);
|
|
|
//新的数组重新创建
|
|
|
- if(count($data['new_category_arr_id'])>0){
|
|
|
+ if(count($insertIDS)>0){
|
|
|
$arr = [];
|
|
|
- $categoryListIds = $data['new_category_arr_id'];
|
|
|
+ $categoryListIds = $insertIDS;
|
|
|
if($categoryListIds){
|
|
|
foreach ($categoryListIds as $v){
|
|
|
$ids = $this->getUnderlingUIds(intval($v));
|
|
@@ -817,6 +835,7 @@ class WebsiteService implements WebsiteServiceInterface
|
|
|
foreach ($arr as $subarray) {
|
|
|
$mergedArray = array_merge($mergedArray, $subarray);
|
|
|
}
|
|
|
+ var_dump("要插入的ID:",$mergedArray);
|
|
|
//查询出所有的分类进行分割插入 组装数据
|
|
|
$categoryListData = Category::whereIn('id',$mergedArray)->get();
|
|
|
$categoryListData = $categoryListData->toArray();
|
|
@@ -836,8 +855,9 @@ class WebsiteService implements WebsiteServiceInterface
|
|
|
}
|
|
|
}
|
|
|
WebsiteCategory::insert($insertData);
|
|
|
- Db::commit();
|
|
|
+
|
|
|
}
|
|
|
+ Db::commit();
|
|
|
} catch(\Throwable $ex){
|
|
|
Db::rollBack();
|
|
|
var_dump($ex->getMessage());
|