Jelajahi Sumber

Merge branch 'zzd' of ssh://was.baoshi56.com:10022/var/git/bswas

LD 4 tahun lalu
induk
melakukan
f2a109d4ac

+ 1 - 1
app/Http/Controllers/Auth/LoginController.php

@@ -93,7 +93,7 @@ class LoginController extends Controller
 
         $this->incrementLoginAttempts($request);
         if(env('DB_USERNAME')!='developer')
-            app('LogService')->log(__METHOD__,__FUNCTION__,'',Auth::user()['id']);
+            app('LogService')->log(__METHOD__,__FUNCTION__,'',Auth::id());
         if($request['is_json']){
             return ['success'=>false,'errors'=>['name'=>['登录信息验证失败']]];
         }

+ 4 - 4
app/Http/Controllers/MenuController.php

@@ -93,13 +93,13 @@ class MenuController extends Controller
             "parent_id" => request("parent_id"),
             "level" => request("level"),
         ]);
-        //暂时禁止菜单新建时补充权限 留待权限路由绑定后可开启此步骤
-        /*Authority::query()->create([
+        //增加菜单权限
+        Authority::query()->create([
             'name' => $menu->name,
             'parent_id' => $mapping[$menu->parent_id] ?? null,
-            'alias_name' => $menu->name.$menu->id,
+            'alias_name' => app("MenuService")->getUniqueName($menu),
         ]);
-        app("AuthorityService")->removeAdminAuth();//刷掉超管权限缓存*/
+        app("AuthorityService")->removeAdminAuth();//刷掉超管权限缓存
         app("MenuService")->appendMenu($menu);//为菜单总缓存附加
         $this->success($menu);
     }

+ 21 - 16
app/Http/Controllers/TestController.php

@@ -10,6 +10,8 @@ use App\Console\Commands\CreateOwnerAreaReport;
 use App\Console\Commands\CreateOwnerBillReport;
 use App\Console\Commands\CreateOwnerReport;
 use App\Console\Commands\WasSyncWmsAsnInformation;
+use App\DeliveryAppointment;
+use App\DeliveryAppointmentDetail;
 use App\Events\BroadcastToStation;
 use App\Events\SendEmailEvent;
 use App\Exceptions\Exception;
@@ -134,6 +136,25 @@ class TestController extends Controller
         return call_user_func([$this, $method], $request);
     }
 
+    public function test1()
+    {
+        ini_set('max_execution_time',-1);
+        DeliveryAppointment::query()->with("details")->whereNotNull("asn_number")->get()->each(function ($d){
+            $asn = preg_split('/[,, ]+/is', $d->asn_number);
+            if ($asn && strlen($d->asn_number)>=13){
+                Store::query()->whereIn("asn_code",$asn)->where("owner_id",$d->owner_id)
+                ->with("storeItems")->get()->each(function ($store)use($d){
+                    $store->storeItems->each(function ($item)use($d){
+                        $de = DeliveryAppointmentDetail::query()->where("delivery_appointment_id",$d->id)
+                            ->where("commodity_id",$item->commodity_id)->first();
+                        if ($de && $item->expected_amount && $de->amount!=$item->expected_amount)$de->update(["amount"=>$item->expected_amount]);
+                    });
+                });
+            }
+        });
+        dd("OK");
+    }
+
     public function test()
     {
         dd(app("MenuService")->getVisibleFunctionList());
@@ -200,22 +221,6 @@ class TestController extends Controller
         app("MenuService")->setMenu();//重建菜单缓存
         app("AuthorityService")->removeAllAuth();//移除所有用户权限缓存,这将在用户下次访问时重新建立
     }
-    public function test1(){
-        DB::beginTransaction();
-        try{
-            DB::beginTransaction();
-            try{
-                $unit = Unit::query()->first();
-                $unit->update(["name"=>"xxx"]);
-                DB::commit();
-            }catch (\Exception $e){
-                DB::rollBack();
-            }
-            DB::commit();
-        }catch (\Exception $e){
-            DB::rollBack();
-        }
-    }
     public function orderCreateBill()
     {
         $order = Order::query()->find(\request("id"));

+ 1 - 28
app/Services/AuthorityService.php

@@ -5,8 +5,6 @@ namespace App\Services;
 
 
 use App\Authority;
-use App\Role;
-use Exception;
 use Illuminate\Database\Eloquent\Builder;
 use Illuminate\Database\Eloquent\Collection;
 use Illuminate\Support\Facades\Auth;
@@ -19,35 +17,10 @@ class AuthorityService
 {
     use ServiceAppAop;
     protected $modelClass=Authority::class;
-//    /**
-//     * @return Authority[]
-//     */
-//    function getAll(){
-//        $authorities = Cache::get('authorities');
-//        if(!$authorities){
-//            $authorities = Authority::with('roles')->get();
-//            Cache::put('authorities', $authorities, config('cache.expirations.authorities'));
-//        }
-//        return $authorities;
-//    }
-//
-//    /**
-//     * @param Authority $authority
-//     * @return Role[]
-//     * @throws Exception
-//     */
-//    function getRoles(Authority $authority){
-//        if(!$authority['id']??'') throw new Exception('User对象或id不能为空');
-//        $roles = Cache::get('authorityGetRoles'.$authority['id']);
-//        if(!$roles){
-//            $roles = Authority::with('roles')->get();
-//            Cache::put('authorities', $roles, config('cache.expirations.authorities'));
-//        }
-//        return $roles;
-//    }
 
     public function getUserAuthority()
     {
+        if (!Auth::user())return new Collection();
         $key = "authorities:user_".Auth::id();
         $isAdmin = array_search(Auth::user()["name"],config("users.superAdmin"))!==false;
         $tag = $isAdmin ? "authorities:admin" : "authorities:user";

+ 23 - 0
app/Services/MenuService.php

@@ -124,4 +124,27 @@ class MenuService
         $this->getVisibleFunctionList(Authority::query()->get(),$mapping);
         return $mapping;
     }
+
+    /**
+     * 获取唯一名称
+     */
+    public function getUniqueName(Menu $menu)
+    {
+        if (!$menu->parent_id)return $menu->name;
+        $menus = $this->getMenu();
+        $menuMap = [];
+        foreach ($menus as $menu)$menuMap[$menu->id] = $menu;
+        $names = [];
+        while ($menu){
+            $names[] = $menu->name;
+            if ($menu->parent_id)$menu = $menuMap[$menu->parent_id] ?? null;
+            else $menu = null;
+        }
+        $name = "";
+        for ($i=count($names)-1;$i>=0;$i--){
+            $name .= $names[$i];
+            if ($i!=0)$name .= "-";
+        }
+        return $name;
+    }
 }

+ 6 - 6
database/migrations/2021_03_23_140544_add_configurations_data.php

@@ -16,9 +16,9 @@ class AddConfigurationsData extends Migration
     {
         $time=\Illuminate\Support\Carbon::now()->toDateTimeString();
         $configurations = [];
-        $conf_one=['name'=>'price_coefficient','value'=>1.3,'description'=>'采购管理价格系数','operator'=>Auth::user()['id'],'created_at'=>$time,'updated_at'=>$time];
-        $conf_two=['name'=>'enquiry_time','value'=>4,'description'=>'报价需在询价发起延时时间之内有效','operator'=>Auth::user()['id'],'created_at'=>$time,'updated_at'=>$time];
-        $conf_three=['name'=>'receive_time','value'=>24,'description'=>'接单需在询价发起延时时间之内有效','operator'=>Auth::user()['id'],'created_at'=>$time,'updated_at'=>$time];
+        $conf_one=['name'=>'price_coefficient','value'=>1.3,'description'=>'采购管理价格系数','operator'=>Auth::id(),'created_at'=>$time,'updated_at'=>$time];
+        $conf_two=['name'=>'enquiry_time','value'=>4,'description'=>'报价需在询价发起延时时间之内有效','operator'=>Auth::id(),'created_at'=>$time,'updated_at'=>$time];
+        $conf_three=['name'=>'receive_time','value'=>24,'description'=>'接单需在询价发起延时时间之内有效','operator'=>Auth::id(),'created_at'=>$time,'updated_at'=>$time];
         $configurations[]=$conf_one;
         $configurations[]=$conf_two;
         $configurations[]=$conf_three;
@@ -32,8 +32,8 @@ class AddConfigurationsData extends Migration
      */
     public function down()
     {
-        Configuration::query()->where('name','价格系数')->delete();
-        Configuration::query()->where('name','询价延时时间')->delete();
-        Configuration::query()->where('name','接单延时时间')->delete();
+        Configuration::query()->where('name','price_coefficient')->delete();
+        Configuration::query()->where('name','enquiry_time')->delete();
+        Configuration::query()->where('name','receive_time')->delete();
     }
 }

+ 2 - 2
resources/views/auth/login.blade.php

@@ -122,8 +122,8 @@
                 tempTip.setDuration(6000);
                 tempTip.waitingTip('错误');
                 console.log(response)
-                alert('页面过期或网络异常,请在刷新后重新登录');
-                window.location.reload();
+                //alert('页面过期或网络异常,请在刷新后重新登录');
+                //window.location.reload();
             })
         }
     </script>

+ 2 - 2
resources/views/layouts/app.blade.php

@@ -39,8 +39,8 @@
 {{-- 必须在app.js前边--}}
 <script type="text/javascript">
     let menus = localStorage.getItem("menus");
-    if (menus===null)menus = getMenu();
-    let menuList = JSON.parse(menus);
+    if (menus===null && "{{\Illuminate\Support\Facades\Auth::id()}}")menus = getMenu();
+    let menuList = menus ? JSON.parse(menus) : {};
     let baseUrl = "{{url('')}}";
     let currentUri = window.location.href.slice(baseUrl.length+1);
     let relativeUrl = currentUri.split(/[/?]/);

+ 2 - 0
resources/views/layouts/menu.blade.php

@@ -32,6 +32,7 @@
             </li>
         @endguest
     </ul>
+    @if(\Illuminate\Support\Facades\Auth::id())
     <div class="modal fade" id="resetPwd">
         <div class="modal-dialog modal-dialog-centered">
             <div class="modal-content">
@@ -68,4 +69,5 @@
             </div>
         </div>
     </div>
+    @endif
 </div>

+ 1 - 1
resources/views/maintenance/authority/index.blade.php

@@ -64,7 +64,7 @@
                             this.parentList = this._mergeArray(this.list);//异步重构元素,先行返回
                         });
                         this.authority = {parent_id:"",name:"",alias_name:"",permission:"允许"};//重置列表
-                        $("#addModal").modal('hide');
+                        //$("#addModal").modal('hide');
                         return "录入成功";
                     },true);
                 },

+ 4 - 3
resources/views/maintenance/menu/_modal.blade.php

@@ -9,9 +9,10 @@
                 <div class="row">
                     <label class="col-2 offset-1" for="parent_id">父级</label>
                     <select :disabled="!!menu.id" class="col-5 form-control" id="parent_id" type="text" v-model="menu.parent_id">
-                        <option selected value="">顶级</option>
-                        <option v-for="m in menuList" :value="m.id" v-html="m.name"></option>
+                        <option selected value="" class="bg-success">顶级</option>
+                        <option v-for="m in menuList" :value="m.id" v-if="!m.hide" v-html="m.name" :class="m.level==1 ? 'bg-success' : ''"></option>
                     </select>
+                    <label class="col-3"><input type="text" class="form-control form-control-sm rounded-pill" placeholder="检索" @keydown.enter="seekMenu($event)"/></label>
                 </div>
                 <div class="row mt-2">
                     <label class="col-2 offset-1" for="name"><b class="text-danger">*&nbsp;</b>菜单名称</label>
@@ -56,4 +57,4 @@
             </div>
         </div>
     </div>
-</div>
+</div>

+ 25 - 4
resources/views/maintenance/menu/index.blade.php

@@ -167,7 +167,7 @@
                         }
                         if (obj[key]['level']!==1)name += "└─&nbsp;";
                         name += obj[key]["name"];
-                        arr.push({name:name,id:obj[key]["id"],level:obj[key]["level"]});
+                        arr.push({name:name,id:obj[key]["id"],level:obj[key]["level"],parent_id:obj[key]["parent_id"]});
                         if (obj[key].child)arr = this._mergeArray(obj[key].child,arr);
                     }
                     return arr;
@@ -220,7 +220,7 @@
                             menu.font = params.font;
                             menu.font_style = params.font_style;
                         }else this.insert(res);
-                        $("#modal").modal("hide");
+                        //$("#modal").modal("hide");
                         return msg;
                     },true);
                 },
@@ -287,6 +287,7 @@
                     let arr = [];
                     for (let i=0;i<nodes.length;i++){
                         let id = nodes[i].getAttribute("data-id");
+                        let parent_id = nodes[i].getAttribute("data-parent");
                         if (!id)continue;
                         let oldOrder = nodes[i].getAttribute("data-order");
                         if (oldOrder != index){
@@ -307,7 +308,7 @@
                                 break;
                             }
                         }
-                        arr.push({name:name,id:id,level:level});
+                        arr.push({name:name,id:id,level:level,parent_id:parent_id});
                     }
                     this.menuList = arr;
                     if (update.length > 1){
@@ -383,7 +384,27 @@
                         }
                     });
                     return menus;
-                }
+                },
+                seekMenu(e){
+                    let val = e.target.value;
+                    let menuMap = {};
+                    for (let i=0;i<this.menuList.length;i++){
+                        menuMap['_'+this.menuList[i].id] = i;
+                    }
+                    this.menuList.forEach((menu,index)=>{
+                        if (menu.name.indexOf(val)===-1)this.$set(this.menuList[index],"hide",true);
+                        else {
+                            this.$set(this.menuList[index],"hide",false);
+                            if (menu.parent_id){
+                                let tar = menuMap['_'+menu.parent_id];
+                                while (tar!==undefined){
+                                    this.$set(this.menuList[tar],"hide",false);
+                                    tar = menuMap['_'+this.menuList[tar].parent_id];
+                                }
+                            }
+                        }
+                    });
+                },
             }
         });
     </script>