فهرست منبع

Merge branch 'master' of http://git.bjzxtw.org.cn:3000/zxt/public_producer

LiuJ 2 هفته پیش
والد
کامیت
bce6b36d1c
2فایلهای تغییر یافته به همراه25 افزوده شده و 26 حذف شده
  1. 22 19
      app/JsonRpc/FooterService.php
  2. 3 7
      app/JsonRpc/WebsiteService.php

+ 22 - 19
app/JsonRpc/FooterService.php

@@ -59,36 +59,37 @@ 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("添加失败!");
         }else{
-            return Result::success($data);
+            return Result::success($result);
         }
     }
      /**
@@ -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());

+ 3 - 7
app/JsonRpc/WebsiteService.php

@@ -1526,17 +1526,13 @@ class WebsiteService implements WebsiteServiceInterface
             return Result::error("参数错误", 0);
         }
         if (isset($data['catid']) && !empty($data['catid'])) {
-            $fcatid = WebsiteCategory::where('website_id', $data['website_id'])->where('category_id', $data['catid'])->first();
-            if (empty($fcatid)) {
-                return Result::error("导航id错误", 0);
-            }
-            $result = Category::where('id', $data['catid'])->first();
-            $result['website_name'] = $website['website_name'] ?? '';
-            $result['suffix'] = $website['suffix'] ?? '';
+            $result = WebsiteCategory::where('website_id',$data['website_id'])->where('category_id',$data['catid'])->first();
         }
         if (empty($result)) {
             return Result::error("暂无导航", 0);
         }
+        $result['website_name'] = $website['website_name'] ?? '';
+        $result['suffix'] = $website['suffix'] ?? '';
         return Result::success($result);
     }
     /*