Ver código fonte

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

LD 4 anos atrás
pai
commit
9f41d7ef6c

+ 1 - 1
app/Http/Controllers/AuthorityController.php

@@ -70,7 +70,7 @@ class AuthorityController extends Controller
     public function destroy()
     {
         $this->gate("权限-删除");
-        Authority::destroy(request("ids"));
+        Authority::query()->whereIn('id',request("ids"))->get()->each(function ($auth){$auth->delete();});
         app("AuthorityService")->removeAllAuth();//刷掉权限缓存
         $this->success();
     }

+ 10 - 7
app/Http/Controllers/MenuController.php

@@ -42,13 +42,16 @@ class MenuController extends Controller
         if (request()->has("font_style"))$update["font_style"] = request("font_style");
         if (request()->has("route"))$update["route"] = request("route");
         if (request()->has("diff")){
-            $diff = request("diff");
-            Menu::query()->whereIn("id",request("child"))->update(["level"=>DB::raw("level - {$diff}")]);
+            $diff = request("diff"); //TODO 此处需要查询出模型 ->get()->each()来进行update操作以确保观察者检测到 下面同理
+            Menu::query()->whereIn("id",request("child"))->get()->each(function ($menu)use($diff){
+               $menu->update(["level"=>DB::raw("level - {$diff}")]);
+            });
         }
-        if ($update && Menu::query()->where("id",request("id"))->update($update)){
+        if ($update){
+            Menu::query()->where("id",request("id"))->first()->update($update);
             app("MenuService")->setMenu();//重建菜单缓存
             if ($authorityUpdate && ($mapping[request("id")] ?? null)){
-                Authority::query()->where("id",$mapping[request("id")])->update($authorityUpdate);
+                Authority::query()->where("id",$mapping[request("id")])->first()->update($authorityUpdate);
                 app("AuthorityService")->removeAllAuth();//移除所有用户权限缓存,这将在用户下次访问时重新建立
             }
         }
@@ -70,7 +73,7 @@ class MenuController extends Controller
         $mapping = app("MenuService")->getMenuAndAuthorityMapping();
         if ($id){
             $this->gate("基础设置-菜单-编辑");
-            Menu::query()->where("id",$id)->update([
+            Menu::query()->where("id",$id)->first()->update([
                 "name" => request("name"),
                 "route" => request("route"),
                 "font" => request("font"),
@@ -111,11 +114,11 @@ class MenuController extends Controller
         $mapping = app("MenuService")->getMenuAndAuthorityMapping();
         foreach ($ids as $id)if (isset($mapping[$id]))$authIds[] = $mapping[$id];
 
-        Menu::destroy($ids);
+        Menu::query()->whereIn("id",$ids)->get()->each(function ($menu){$menu->delete();});
         app("MenuService")->setMenu();//重建菜单缓存
         if ($authIds){
             DB::table("authority_role")->whereIn("id_authority",$authIds)->delete();
-            Authority::destroy($ids);
+            Authority::query()->whereIn("id",$authIds)->get()->each(function ($auth){$auth->delete();});
             app("AuthorityService")->removeAllAuth();//移除所有用户权限缓存,这将在用户下次访问时重新建立
         }
         $this->success();

+ 36 - 2
app/Http/Controllers/TestController.php

@@ -155,10 +155,44 @@ class TestController extends Controller
         dd("OK");
     }
 
+    public function test2()
+    {
+        ini_set('max_execution_time',-1);
+        $myfile = fopen(base_path()."\\database\\data\\menus.data", "a+");
+        foreach (Menu::query()->get() as $menu){
+            $txt = "INSERT INTO menus";
+            $columns = "(";
+            $values = "(";
+            foreach ($menu->toArray() as $col=>$val){
+                $columns .= "{$col},";
+                $values .= "'{$val}',";
+            }
+            $columns = mb_substr($columns,0,-1);
+            $values = mb_substr($values,0,-1);
+            $txt .= "{$columns}) VALUES{$values});\r\n";
+            fwrite($myfile, $txt);
+        }
+        fclose($myfile);
+
+        $myfile = fopen(base_path()."\\database\\data\\authorities.data", "a+");
+        foreach (Authority::query()->get() as $authority){
+            $txt = "INSERT INTO authorities";
+            $columns = "(";
+            $values = "(";
+            foreach ($authority->toArray() as $col=>$val){
+                $columns .= "{$col},";
+                $values .= "'{$val}',";
+            }
+            $columns = mb_substr($columns,0,-1);
+            $values = mb_substr($values,0,-1);
+            $txt .= "{$columns}) VALUES{$values});\r\n";
+            fwrite($myfile, $txt);
+        }
+        fclose($myfile);
+        dd("OK");
+    }
     public function test()
     {
-        dd(app("MenuService")->getVisibleFunctionList());
-        ini_set('max_execution_time',9999);
         DB::beginTransaction();
         try{
             $mapping = [

+ 16 - 0
app/Http/Controllers/UserController.php

@@ -2,6 +2,7 @@
 
 namespace App\Http\Controllers;
 
+use App\Components\AsyncResponse;
 use App\Role;
 use App\Supplier;
 use App\User;
@@ -14,10 +15,12 @@ use Illuminate\Http\Request;
 use Illuminate\Http\Response;
 use Illuminate\Support\Facades\Auth;
 use Illuminate\Support\Facades\Gate;
+use Illuminate\Support\Facades\Hash;
 use Illuminate\Support\Facades\Validator;
 
 class UserController extends Controller
 {
+    use AsyncResponse;
     /**
      * Display a listing of the resource.
      *
@@ -180,4 +183,17 @@ class UserController extends Controller
         $re=$user->delete();
         return ['success'=>$re];
     }
+
+    /**
+     * 重置密码
+     */
+    public function resetPassword()
+    {
+        $this->gate("用户-编辑");
+        $user = User::query()->find(\request("id"));
+        if (!$user)$this->error("用户不存在");
+        if (array_search($user->name,config("users.superAdmin"))!==false)$this->error("无权操作超管账户");
+        $user->update(["password" => Hash::make(request("pwd"))]);
+        $this->success();
+    }
 }

+ 66 - 0
app/Observers/AuthorityObserver.php

@@ -0,0 +1,66 @@
+<?php
+
+namespace App\Observers;
+
+use App\Authority;
+
+class AuthorityObserver
+{
+    /**
+     * Handle the authority "created" event.
+     *
+     * @param  \App\Authority  $authority
+     * @return void
+     */
+    public function created(Authority $authority)
+    {
+        if (env('APP_ENV')!='production')return;
+        $txt = "INSERT INTO authorities";
+        $columns = "(";
+        $values = "(";
+        foreach ($authority->toArray() as $col=>$val){
+            $columns .= "{$col},";
+            $values .= "'{$val}',";
+        }
+        $columns = mb_substr($columns,0,-1);
+        $values = mb_substr($values,0,-1);
+        $txt .= "{$columns}) VALUES{$values});\r\n";
+        $this->write($txt);
+    }
+
+    /**
+     * Handle the authority "updated" event.
+     *
+     * @param  \App\Authority  $authority
+     * @return void
+     */
+    public function updated(Authority $authority)
+    {
+        if (env('APP_ENV')!='production')return;
+        $txt = "UPDATE authorities SET ";
+        foreach ($authority->toArray() as $col=>$val)$txt .= "{$col}='{$val}',";
+        $txt = mb_substr($txt,0,-1);
+        $txt .= " WHERE id = {$authority->id};\r\n";
+        $this->write($txt);
+    }
+
+    /**
+     * Handle the authority "deleted" event.
+     *
+     * @param  \App\Authority  $authority
+     * @return void
+     */
+    public function deleted(Authority $authority)
+    {
+        if (env('APP_ENV')!='production')return;
+        $txt = "DELETE FROM authorities WHERE id = {$authority->id};\r\n";
+        $this->write($txt);
+    }
+
+    private function write($txt)
+    {
+        $myfile = fopen(base_path()."\\database\\data\\authorities.data", "a+");
+        fwrite($myfile, $txt);
+        fclose($myfile);
+    }
+}

+ 66 - 0
app/Observers/MenuObserver.php

@@ -0,0 +1,66 @@
+<?php
+
+namespace App\Observers;
+
+use App\Menu;
+
+class MenuObserver
+{
+    /**
+     * Handle the menu "created" event.
+     *
+     * @param  \App\Menu  $menu
+     * @return void
+     */
+    public function created(Menu $menu)
+    {
+        if (env('APP_ENV')!='production')return;
+        $txt = "INSERT INTO menus";
+        $columns = "(";
+        $values = "(";
+        foreach ($menu->toArray() as $col=>$val){
+            $columns .= "{$col},";
+            $values .= "'{$val}',";
+        }
+        $columns = mb_substr($columns,0,-1);
+        $values = mb_substr($values,0,-1);
+        $txt .= "{$columns}) VALUES{$values});\r\n";
+        $this->write($txt);
+    }
+
+    /**
+     * Handle the menu "updated" event.
+     *
+     * @param  \App\Menu  $menu
+     * @return void
+     */
+    public function updated(Menu $menu)
+    {
+        if (env('APP_ENV')!='production')return;
+        $txt = "UPDATE menus SET ";
+        foreach ($menu->toArray() as $col=>$val)$txt .= "{$col}='{$val}',";
+        $txt = mb_substr($txt,0,-1);
+        $txt .= " WHERE id = {$menu->id};\r\n";
+        $this->write($txt);
+    }
+
+    /**
+     * Handle the menu "deleted" event.
+     *
+     * @param  \App\Menu  $menu
+     * @return void
+     */
+    public function deleted(Menu $menu)
+    {
+        if (env('APP_ENV')!='production')return;
+        $txt = "DELETE FROM menus WHERE id = {$menu->id};\r\n";
+        $this->write($txt);
+    }
+
+    private function write($txt)
+    {
+        $myfile = fopen(base_path()."\\database\\data\\menus.data", "a+");
+        fwrite($myfile, $txt);
+        fclose($myfile);
+    }
+}

+ 2 - 6
app/Observers/OwnerObserver.php

@@ -15,16 +15,12 @@ class OwnerObserver
     public function created(Owner $owner)
     {
         app("OwnerAreaReportService")->notExistToInsert([$owner]);
-        if(env('APP_ENV')=='production')
-            app("OwnerService")->syncPush($owner);
-            app("OwnerService")->createAuthority($owner);
+        if(env('APP_ENV')=='production')app("OwnerService")->syncPush($owner);
     }
 
     public function updated(Owner $owner)
     {
-        if(env('APP_ENV')=='production'){
-            app("OwnerService")->syncUpdate($owner);
-        }
+        if(env('APP_ENV')=='production')app("OwnerService")->syncUpdate($owner);
     }
 
     public function deleted(Owner $owner)

+ 6 - 0
app/Providers/AppServiceProvider.php

@@ -2,11 +2,15 @@
 
 namespace App\Providers;
 
+use App\Authority;
 use App\Http\Controllers\Controller;
 use App\Jobs\LogisticSFSync;
 use App\Jobs\LogisticYDSync;
 use App\Jobs\LogisticYTOSync;
 use App\Jobs\LogisticZopSync;
+use App\Menu;
+use App\Observers\AuthorityObserver;
+use App\Observers\MenuObserver;
 use App\Observers\OwnerObserver;
 use App\Observers\UserWorkGroupObserver;
 use App\Owner;
@@ -346,5 +350,7 @@ class AppServiceProvider extends ServiceProvider
     {
         Owner::observe(OwnerObserver::class);
         UserWorkgroup::observe(UserWorkGroupObserver::class);
+        Menu::observe(MenuObserver::class);
+        Authority::observe(AuthorityObserver::class);
     }
 }

+ 5 - 0
app/Services/common/BatchUpdateService.php

@@ -70,6 +70,11 @@ class BatchUpdateService
             // DB::update
             $bool = DB::connection($connection)->update($updateSql, $bindings);
             app('LogService')->log(__METHOD__, __FUNCTION__, '批量更新:' . $tableName . ' | '.json_encode($multipleData).' | 溯源:'.json_encode($debug));
+            if (($tableName == 'authorities' || $tableName == 'menus') && env('APP_ENV')=='production'){
+                $myfile = fopen(base_path()."\\database\\data\\{$tableName}.data", "a+");
+                fwrite($myfile, vsprintf(str_replace('?',"'%s'",$updateSql), $bindings).";\r\n");
+                fclose($myfile);
+            }
             return $bool;
         } catch (\Exception $e) {
             app('LogService')->log(__METHOD__, __FUNCTION__, '批量更新失败' . $tableName . ' | '.json_encode($multipleData).' | 溯源:'.json_encode($debug) . $e->getMessage() . $e->getTraceAsString());

Diferenças do arquivo suprimidas por serem muito extensas
+ 537 - 36
composer.lock


+ 27 - 0
resources/views/maintenance/user/_resetPwd.blade.php

@@ -0,0 +1,27 @@
+<div class="modal fade" id="modal" tabindex="-1" role="dialog" aria-hidden="true">
+    <div class="modal-dialog modal-dialog-centered" role="document">
+        <div class="modal-content">
+            <div class="modal-header">
+                <div class="text-center font-weight-bold">重置密码</div>
+                <button type="button" class="close" data-dismiss="modal">&times;</button>
+            </div>
+            <div class="modal-body">
+                <div class="form-group row">
+                    <label for="password" class="col-md-4 col-form-label text-md-right">输入新密码</label>
+                    <label class="col-md-6">
+                        <input type="text" style='text-security:disc; -webkit-text-security:disc;ime-mode:disabled' v-model="user.pwd" class="form-control"/>
+                    </label>
+                </div>
+                <div class="form-group row">
+                    <label for="password-confirm" class="col-md-4 col-form-label text-md-right">重输密码</label>
+                    <label class="col-md-6">
+                        <input type="text" style='text-security:disc; -webkit-text-security:disc;ime-mode:disabled' v-model="user.rePwd" class="form-control"/>
+                    </label>
+                </div>
+            </div>
+            <div class="modal-footer">
+                <button class="col-12 btn btn-success" @click="resetPwd()">确定</button>
+            </div>
+        </div>
+    </div>
+</div>

+ 24 - 1
resources/views/maintenance/user/index.blade.php

@@ -10,6 +10,7 @@
                     <div class="alert alert-success h1">{{Session::get('successTip')}}</div>
                 @endif
                 <div id="list">
+                    @include("maintenance.user._resetPwd")
                     <table class="table table-striped table-sm td-min-width-80" id="table">
                         <tr v-for="(user,i) in users"  @click="selectTr===i+1?selectTr=0:selectTr=i+1" :class="selectTr===i+1?'focusing' : ''">
                             <td class="text-muted"><span>@{{user.id}}</span></td>
@@ -35,6 +36,7 @@
                             <td class="text-muted"><span>@{{user.created_at}}</span></td>
                             <td>
                                 @can('用户-编辑')
+                                <button class="btn btn-sm btn-warning" @click="openResetPwdModal(user)">重置密码</button>
                                 <button class="btn btn-sm btn-outline-primary" @click="edit(user.id)">改</button> @endcan
                                 @can('用户-删除')
                                 <button class="btn btn-sm btn-outline-dark" @click="destroy(user)">删</button> @endcan
@@ -65,7 +67,8 @@
                     {name:'{{$owner->id}}',value:'{{$owner->name}}'},
                     @endforeach
                 ],
-                selectTr:0
+                selectTr:0,
+                user:{},
             },
             mounted:function(){
                 let data = [
@@ -130,6 +133,26 @@
                             tempTip.show('删除用户失败!'+'网络错误:' + err)
                         });
                 },
+                openResetPwdModal(user){
+                    this.user = user;
+                    $("#modal").modal("show");
+                },
+                resetPwd(){
+                    window.tempTip.setIndex(1099);
+                    window.tempTip.setDuration(3000);
+                    if (this.user.pwd.length<6){
+                        window.tempTip.show("密码最少为六位");
+                        return;
+                    }
+                    if (this.user.pwd!==this.user.rePwd){
+                        window.tempTip.show("两次密码输入不一致");
+                        return;
+                    }
+                    window.tempTip.postBasicRequest("{{url('maintenance/user/resetPassword')}}",this.user,()=>{
+                        $("#modal").modal("hide");
+                        return "已重置用户:“"+this.user.name+"”的密码";
+                    },true);
+                },
             }
         });
     </script>

+ 5 - 1
routes/web.php

@@ -244,7 +244,11 @@ Route::group(['prefix'=>'maintenance'],function(){
         Route::post("getProvinces",'RegionController@getProvinces');
     });
     /** 耗材 */
-    Route::get('material','MaterialController@index');;
+    Route::get('material','MaterialController@index');
+    /** 用户 */
+    Route::group(['prefix'=>"user"],function (){
+        Route::post("resetPassword",'UserController@resetPassword');
+    });
     /** 项目耗材 */
     Route::group(['prefix'=>"ownerMaterial"],function (){
         Route::get("/",'OwnerMaterialController@index');

Alguns arquivos não foram mostrados porque muitos arquivos mudaram nesse diff