|
|
@@ -3,16 +3,12 @@
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
use App\Components\AsyncResponse;
|
|
|
-use App\Owner;
|
|
|
-use App\OwnerGroup;
|
|
|
use App\Role;
|
|
|
use App\Supplier;
|
|
|
use App\User;
|
|
|
use App\UserDetail;
|
|
|
use App\UserWorkgroup;
|
|
|
-use Doctrine\DBAL\Configuration;
|
|
|
use Exception;
|
|
|
-use Illuminate\Database\Eloquent\Builder;
|
|
|
use Illuminate\Http\Request;
|
|
|
use Illuminate\Http\Response;
|
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
@@ -81,7 +77,12 @@ class UserController extends Controller
|
|
|
$logistics=app('LogisticService')->getSelection(["id","name"],"物流");
|
|
|
$userWorkgroups=UserWorkgroup::query()->get();
|
|
|
$suppliers=Supplier::query()->get();
|
|
|
- return view('maintenance.user.create',['rolesAll'=>$roles,'logistics'=>$logistics,'userWorkgroups'=>$userWorkgroups,'suppliers'=>$suppliers]);
|
|
|
+
|
|
|
+ //工作组 项目组
|
|
|
+ /* @var $user User */
|
|
|
+ $workGroup = app('WarehouseService')->getTreeData();
|
|
|
+ $ownerGroup = app('UserOwnerGroupService')->getSelection();
|
|
|
+ return view('maintenance.user.create',['rolesAll'=>$roles,'logistics'=>$logistics,'userWorkgroups'=>$userWorkgroups,'suppliers'=>$suppliers, 'ownerGroup' => $ownerGroup, 'workGroup'=>$workGroup]);
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -117,7 +118,19 @@ class UserController extends Controller
|
|
|
$userWorkgroup=$user->userWorkgroups()->first();
|
|
|
$supplierUser=$user->suppliers()->get();
|
|
|
$suppliers=Supplier::query()->get();
|
|
|
- return view('maintenance.user.edit',compact('user','rolesAll','roles','logistics','logisticUser','userWorkgroups','userWorkgroup','suppliers','supplierUser'));
|
|
|
+ //工作组 项目组
|
|
|
+ /* @var $user User */
|
|
|
+ $workGroup = app('WarehouseService')->getTreeData();
|
|
|
+ $group = $user->workGroups()->get();
|
|
|
+ $groups = [];
|
|
|
+ foreach ($group as $v){
|
|
|
+ array_push($groups,'g'.$v->id);
|
|
|
+ array_push($groups,'w'.$v->warehouse_id);
|
|
|
+ }
|
|
|
+ $workGroups = $groups;
|
|
|
+ $ownerGroup = app('UserOwnerGroupService')->getSelection();
|
|
|
+ $ownerGroups = $user->ownerGroups->pluck('id');
|
|
|
+ return view('maintenance.user.edit',compact('user','rolesAll','roles','logistics','logisticUser','userWorkgroups','userWorkgroup','suppliers','supplierUser','workGroup','workGroups','ownerGroup','ownerGroups'));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -167,6 +180,18 @@ class UserController extends Controller
|
|
|
if (!$user->userDetail) UserDetail::query()->create(['user_id'=>$user->id,'mobile_phone'=>$phone]);
|
|
|
UserDetail::query()->where('user_id',$user->id) ->update(['mobile_phone'=>$phone]);
|
|
|
}
|
|
|
+
|
|
|
+ //工作组
|
|
|
+ $work_id = [];
|
|
|
+ $treeData = $request->input('treeData')??[];
|
|
|
+ foreach ($treeData as $v){
|
|
|
+ if (strrpos($v,'g') != 'FALSE') array_push($work_id, mb_substr($v,1));
|
|
|
+ }
|
|
|
+ if ($work_id)$user->workGroups()->sync($work_id);
|
|
|
+ //项目组
|
|
|
+ $owners = $request->input('ownerGroup')??'';
|
|
|
+ if ($owners)$user->ownerGroups()->sync($owners);
|
|
|
+
|
|
|
app('LogService')->log(__METHOD__,__FUNCTION__,json_encode($request->toArray()),Auth::user()['id']);
|
|
|
app("UserService")->clearUserCache($user);
|
|
|
return redirect('maintenance/user/')->with('successTip',"成功修改用户“{$user['name']}”!");
|
|
|
@@ -200,4 +225,30 @@ class UserController extends Controller
|
|
|
$user->update(["password" => Hash::make(request("pwd"))]);
|
|
|
$this->success();
|
|
|
}
|
|
|
+
|
|
|
+ //工作组
|
|
|
+ public function saveWorkGroups(Request $request)
|
|
|
+ {
|
|
|
+ if(!Gate::allows('用户-编辑')){ return redirect(url('/')); }
|
|
|
+ $params = $request->all();
|
|
|
+ $work_id = [];
|
|
|
+ foreach ($params['workGroups'] as $v){
|
|
|
+ if (strrpos($v,'g') != 'FALSE') array_push($work_id, mb_substr($v,1));
|
|
|
+ }
|
|
|
+ /* @var $user User */
|
|
|
+ $user = User::query()->find($params['id']);
|
|
|
+ $user->workGroups()->sync($work_id);
|
|
|
+ return ['success'=>true];
|
|
|
+ }
|
|
|
+
|
|
|
+ //工作组
|
|
|
+ public function saveOwnerGroups(Request $request)
|
|
|
+ {
|
|
|
+ if(!Gate::allows('用户-编辑')){ return redirect(url('/')); }
|
|
|
+ $params = $request->all();
|
|
|
+ /* @var $user User */
|
|
|
+ $user = User::query()->find($params['id']);
|
|
|
+ $user->ownerGroups()->sync($params['ownerGroups']);
|
|
|
+ return ['success'=>true];
|
|
|
+ }
|
|
|
}
|