|
@@ -59,31 +59,32 @@ class FooterService implements FooterServiceInterface
|
|
|
*/
|
|
|
public function addFooterCategory(array $data): array
|
|
|
{
|
|
|
-
|
|
|
- //从WebsiteCategory取出alis ,并转成拼音存放到alias_pinyin
|
|
|
- // $result = WebsiteCategory::where($where)->first();
|
|
|
- // $result = $result->toArray();
|
|
|
if(empty($data)){
|
|
|
$result = Website::select('website_name','id')->get();
|
|
|
}else{
|
|
|
- // $alias = $data['name'];
|
|
|
- // 引入 Pinyin 类
|
|
|
-
|
|
|
- // $alias_pinyin = $pinyin->permalink($alias, '');
|
|
|
// 底部导航类型 0:内容型;1:列表型;
|
|
|
$webid = Website::select('website_name','id')->where('id',$data['website_id'])->first();
|
|
|
if(empty($webid)){
|
|
|
return Result::error("该网站不存在!");
|
|
|
}
|
|
|
- // 同一网站下的底部导航名称不能重复
|
|
|
- $name = FooterCategory::where('website_id',$data['website_id'])->where('name',$data['name'])->first();
|
|
|
- if(!empty($name)){
|
|
|
- return Result::error("该底部导航名称已存在!");
|
|
|
+ Db::beginTransaction();
|
|
|
+ try{
|
|
|
+ // 同一网站下的底部导航名称不能重复
|
|
|
+ $name = FooterCategory::where('website_id',$data['website_id'])->where('name',$data['name'])->first();
|
|
|
+ if(!empty($name)){
|
|
|
+ return Result::error("该底部导航名称已存在!");
|
|
|
+ }
|
|
|
+ $pinyin = new Pinyin();
|
|
|
+ $result = FooterCategory::insertGetId($data);
|
|
|
+ $name_pinyin['name_pinyin'] = $pinyin->permalink($data['name'], '') ;
|
|
|
+ // return Result::success($name_pinyin);
|
|
|
+ $result = FooterCategory::where('id', $result)->update($name_pinyin);
|
|
|
+ Db::commit();
|
|
|
+ } catch(\Throwable $ex){
|
|
|
+ Db::rollBack();
|
|
|
+ $errorMessage = $ex->getMessage();
|
|
|
+ return Result::error("添加失败!",$errorMessage);
|
|
|
}
|
|
|
- $pinyin = new Pinyin();
|
|
|
- $result = FooterCategory::insertGetId($data);
|
|
|
- $name_pinyin['name_pinyin'] = $pinyin->permalink($data['name'], '') . $result;
|
|
|
- $result = FooterCategory::where('id', $result)->update($name_pinyin);
|
|
|
}
|
|
|
if(empty($result)){
|
|
|
return Result::error("添加失败!");
|
|
@@ -126,7 +127,8 @@ class FooterService implements FooterServiceInterface
|
|
|
return Result::error("该网站不存在!");
|
|
|
}
|
|
|
$pinyin = new Pinyin();
|
|
|
- $data['name_pinyin'] = $pinyin->permalink($data['name'], ''). $data['id'];
|
|
|
+ $data['name_pinyin'] = $pinyin->permalink($data['name'], '');
|
|
|
+
|
|
|
$result = FooterCategory::where('id', $data['id'])->update($data);
|
|
|
}
|
|
|
if (empty($result)) {
|
|
@@ -152,11 +154,12 @@ class FooterService implements FooterServiceInterface
|
|
|
}else{
|
|
|
$result['footer_category'] = FooterCategory::where('id', $data['id'])->delete();
|
|
|
$result['footer_content'] = FooterContent::where('fcat_id', $data['id'])->delete();
|
|
|
+ Db::commit();
|
|
|
// $result = FooterCategory::where('footer_category.id',$data['id'])
|
|
|
// ->leftJoin("footer_content","footer_content.fcat_id","footer_category.id")
|
|
|
// ->delete();
|
|
|
}
|
|
|
- Db::commit();
|
|
|
+
|
|
|
} catch(\Throwable $ex){
|
|
|
Db::rollBack();
|
|
|
var_dump($ex->getMessage());
|