| xqd
@@ -1,250 +1,179 @@
|
|
|
<?php
|
|
|
/**
|
|
|
- *
|
|
|
- * @author Mike <m@9026.com>
|
|
|
+ * 用户管理
|
|
|
+ * @author system
|
|
|
* @version 1.0
|
|
|
- * @date 2015年10月12日
|
|
|
+ * @date 2018-05-14 13:25:12
|
|
|
*
|
|
|
*/
|
|
|
-namespace App\Http\Controllers\Admin\Base;
|
|
|
-
|
|
|
+namespace App\Http\Controllers\Admin\Album;
|
|
|
use App\Http\Controllers\Admin\Controller;
|
|
|
-use App\Models\AdminUserModel;
|
|
|
-use App\Models\AlbumManufacturerModel;
|
|
|
+use App\Models\AlbumAgentModel;
|
|
|
use App\Models\AlbumUserModel;
|
|
|
-use App\Services\Admin\Role;
|
|
|
-use App\Services\Admin\AdminUser;
|
|
|
-use Request;
|
|
|
+use App\Repositories\Album\Criteria\UserWhere;
|
|
|
+use Illuminate\Http\Request;
|
|
|
+use App\Repositories\Base\Criteria\OrderBy;
|
|
|
+use App\Repositories\Album\Criteria\MultiWhere;
|
|
|
+use App\Repositories\Album\UserRepository;
|
|
|
|
|
|
class UserController extends Controller
|
|
|
{
|
|
|
- private $_service;
|
|
|
- private $_role_service;
|
|
|
+ private $repository;
|
|
|
|
|
|
- /**
|
|
|
- * 初始化Service
|
|
|
- */
|
|
|
- public function __construct()
|
|
|
- {
|
|
|
- parent::__construct();
|
|
|
- if(!$this->_service) $this->_service = new AdminUser();
|
|
|
- if(!$this->_role_service) $this->_role_service = new Role();
|
|
|
+ public function __construct(UserRepository $repository) {
|
|
|
+ if(!$this->repository) $this->repository = $repository;
|
|
|
}
|
|
|
-
|
|
|
- /**
|
|
|
- * 列表
|
|
|
- */
|
|
|
- function index()
|
|
|
- {
|
|
|
- $request = Request::all();
|
|
|
- $search['keyword'] = Request::input('keyword');
|
|
|
|
|
|
- $orderby = array();
|
|
|
+ function index(Request $request) {
|
|
|
+ $search['keyword'] = $request->input('keyword');
|
|
|
+ $search['storeid'] = $this->getStoreId();
|
|
|
+
|
|
|
+ $order = array();
|
|
|
if(isset($request['sort_field']) && $request['sort_field'] && isset($request['sort_field_by'])) {
|
|
|
- $orderby[$request['sort_field']] = $request['sort_field_by'];
|
|
|
- }
|
|
|
- if ($this->_user->is_root == 1) {
|
|
|
- $store_id = 0;
|
|
|
- } else {
|
|
|
- $store_id = $this->getStoreId();
|
|
|
+ $order[$request['sort_field']] = $request['sort_field_by'];
|
|
|
+ }else{
|
|
|
+ $order['id']='DESC';
|
|
|
}
|
|
|
- $list = $this->_service->search($search, $orderby, $store_id);
|
|
|
+
|
|
|
+ $list = $this->repository->searchUser($search,$order);
|
|
|
//dd($list);
|
|
|
- foreach ($list as $item) {
|
|
|
- $item->store = '暂无';
|
|
|
- $store = AlbumManufacturerModel::where('store_id', $item->store_id)->first();
|
|
|
- if ($store) {
|
|
|
- $item->store = $store->name;
|
|
|
- }
|
|
|
- }
|
|
|
- $roles = pairList($this->_getRoles(), 'id', 'name');
|
|
|
- return view('admin.base.user.index', compact('list', 'roles'));
|
|
|
+// dump($list);die;
|
|
|
+ return view('admin.album.user.index',compact('list'));
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 列表
|
|
|
- */
|
|
|
- function resetPwd()
|
|
|
- {
|
|
|
-// $pwd = '$2y$10$jRQGg4qdfDhdt.4TZpDaL.2pbgBJZqvdR.AMrE5rA2D3dgMyit8vS';
|
|
|
-// var_dump(crypt('abcded', $pwd));exit;
|
|
|
- $request = Request::all();
|
|
|
- $search['keyword'] = Request::input('keyword');
|
|
|
- $search['resetPwd'] =true;
|
|
|
+
|
|
|
+ function check(Request $request) {
|
|
|
+ $request = $request->all();
|
|
|
+ $search['keyword'] = $request->input('keyword');
|
|
|
$orderby = array();
|
|
|
if(isset($request['sort_field']) && $request['sort_field'] && isset($request['sort_field_by'])) {
|
|
|
$orderby[$request['sort_field']] = $request['sort_field_by'];
|
|
|
}
|
|
|
- $list = $this->_service->search($search, $orderby);
|
|
|
- return view('admin.base.user.resetPwd', compact('list'));
|
|
|
+ $list = $this->repository->search($search,$orderby);
|
|
|
+ return view('admin.album.user.check',compact('list'));
|
|
|
}
|
|
|
|
|
|
- function resetPwdPass()
|
|
|
- {
|
|
|
- $ok = $this->_service->resetPwdPass(Request::get('id'));
|
|
|
- if($ok) {
|
|
|
- $this->showMessage('操作成功');
|
|
|
- }else{
|
|
|
- $this->showWarning('操作失败');
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
- function resetPwdReject()
|
|
|
+ /**
|
|
|
+ * 添加
|
|
|
+ *
|
|
|
+ */
|
|
|
+ public function create(Request $request)
|
|
|
{
|
|
|
- $ok = $this->_service->resetPwdReject(Request::get('id'));
|
|
|
- if($ok) {
|
|
|
- $this->showMessage('操作成功');
|
|
|
- }else{
|
|
|
- $this->showWarning('操作失败');
|
|
|
+ if($request->method() == 'POST') {
|
|
|
+ return $this->_createSave();
|
|
|
}
|
|
|
+ return view('admin.album.user.edit');
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
/**
|
|
|
- * 更新
|
|
|
+ * 保存修改
|
|
|
*/
|
|
|
- public function create()
|
|
|
- {
|
|
|
- if(Request::method() == 'POST'){
|
|
|
- $data = Request::input('info');
|
|
|
- // $data['store_id'] = $this->getStoreId();
|
|
|
- if(isset($data['admin_role_id']))$data['admin_role_id'] = implode(',', $data['admin_role_id']);
|
|
|
- if($this->_service->create($data)){
|
|
|
- $this->showMessage('操作成功', urldecode(Request::input('_referer')));
|
|
|
- }else{
|
|
|
- $this->showWarning('操作失败' . $this->_service->getMsg(), urldecode(Request::input('_referer')));
|
|
|
- }
|
|
|
- }
|
|
|
- $data = $this->_service->find(Request::input('id'));
|
|
|
-
|
|
|
- if($this->_user['is_root']){
|
|
|
- $roles = $this->_getRoles();
|
|
|
+ private function _createSave(){
|
|
|
+ $data = (array) request('data');
|
|
|
+ $id = $this->repository->create($data);
|
|
|
+ if($id) {
|
|
|
+ $url[] = array('url'=>U( 'Album/User/index'),'title'=>'返回列表');
|
|
|
+ $url[] = array('url'=>U( 'Album/User/create'),'title'=>'继续添加');
|
|
|
+ $this->showMessage('添加成功',$url);
|
|
|
}else{
|
|
|
- $roles = $this->_getCurrentRoles();
|
|
|
+ $url[] = array('url'=>U( 'Album/User/index'),'title'=>'返回列表');
|
|
|
+ return $this->showWarning('添加失败',$url);
|
|
|
}
|
|
|
- return view('admin.base.user.edit', compact('data', 'roles'));
|
|
|
}
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
- * 更新
|
|
|
+ *
|
|
|
+ * 修改
|
|
|
+ *
|
|
|
+ *
|
|
|
*/
|
|
|
- public function update()
|
|
|
- {
|
|
|
- if(Request::method() == 'POST')
|
|
|
- {
|
|
|
- $data = Request::input('info');
|
|
|
- if ($data['password'] == null) {
|
|
|
- unset($data['password']);
|
|
|
- }
|
|
|
- // dd($data);
|
|
|
- if(isset($data['admin_role_id']))$data['admin_role_id'] = implode(',', $data['admin_role_id']);
|
|
|
- if($this->_service->update(Request::input('id'), $data)){
|
|
|
- $this->showMessage('操作成功', urldecode(Request::input('_referer')));
|
|
|
+ public function update(Request $request) {
|
|
|
+ $data = $this->repository->find($request->get('id'));
|
|
|
+ if($data->is_dealer == 1){
|
|
|
+ return $this->showWarning('该用户已成为经销商');
|
|
|
+ }
|
|
|
+ $save['is_dealer'] = 1;
|
|
|
+ $ok = $this->repository->update(request('id'),$save);
|
|
|
+
|
|
|
+ if($ok){
|
|
|
+ $add['store_id'] = $this->getStoreId();
|
|
|
+ $add['user_id'] = $data->id;
|
|
|
+ $add['name'] = $data->username;
|
|
|
+ $add['status'] = 1;
|
|
|
+ $res = AlbumAgentModel::create($add);
|
|
|
+ if($res) {
|
|
|
+ return $this->showMessage('操作成功');
|
|
|
}else{
|
|
|
- $this->showWarning('操作失败' . $this->_service->getMsg(), urldecode(Request::input('_referer')));
|
|
|
+ return $this->showWarning('操作失败');
|
|
|
}
|
|
|
}
|
|
|
- $data = $this->_service->find(Request::input('id'));
|
|
|
-
|
|
|
- if($this->_user['is_root']){
|
|
|
- $roles = $this->_getRoles();
|
|
|
- }else{
|
|
|
- $roles = $this->_getCurrentRoles();
|
|
|
- }
|
|
|
- $store = AlbumManufacturerModel::where('store_id', $data['store_id'])->first(['store_id', 'name', 'phone'])->toArray();
|
|
|
- return view('admin.base.user.edit', compact('data', 'roles', 'store'));
|
|
|
- }
|
|
|
-
|
|
|
- public function auth() {
|
|
|
- if(Request::method() == 'POST'){
|
|
|
- $info = Request::input('info');
|
|
|
- if(!empty($info['admin_role_id'])){
|
|
|
- $info['admin_role_id'] = implode(',', $info['admin_role_id']);
|
|
|
- }
|
|
|
- if(!$info['id']) {
|
|
|
- $this->showWarning('数据不全', urldecode(Request::input('_referer')));
|
|
|
- }
|
|
|
- if($this->_service->auth($info)){
|
|
|
- $this->showMessage('操作成功', urldecode(Request::input('_referer')));
|
|
|
- }else{
|
|
|
- $this->showWarning('操作失败'. $this->_service->getMsg(), urldecode(Request::input('_referer')));
|
|
|
- }
|
|
|
- }
|
|
|
- if($this->_user['is_root']){
|
|
|
- $roles = $this->_getRoles();
|
|
|
- }else{
|
|
|
- $roles = $this->_getCurrentRoles();
|
|
|
- }
|
|
|
- return view('admin.base.user.auth', compact( 'roles'));
|
|
|
+ return view('admin.album.user.edit',compact('data'));
|
|
|
}
|
|
|
|
|
|
- public function status() {
|
|
|
- $ok = $this->_service->updateStatus(Request::get('id'),Request::get('status'));
|
|
|
+ /**
|
|
|
+ * 保存修改
|
|
|
+ */
|
|
|
+ private function _updateSave() {
|
|
|
+ $data = (array) request('data');
|
|
|
+ $ok = $this->repository->update(request('id'),$data);
|
|
|
if($ok) {
|
|
|
- $this->showMessage('操作成功');
|
|
|
+ $url[] = array('url'=>U( 'Album/User/index'),'title'=>'返回列表');
|
|
|
+ return $this->showMessage('操作成功',urldecode(request('_referer')));
|
|
|
}else{
|
|
|
- $this->showWarning('操作失败' . $this->_service->getMsg());
|
|
|
+ $url[] = array('url'=>U( 'Album/User/index'),'title'=>'返回列表');
|
|
|
+ return $this->showWarning('操作失败',$url);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- /**
|
|
|
- * 得到当前角色所拥有的角色
|
|
|
- */
|
|
|
- private function _getCurrentRoles()
|
|
|
- {
|
|
|
- $_node = $this->_getRoleNode();
|
|
|
- return $this->_role_service->getChildByLevel($_node['level'])->toArray();
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 获取角色权限节点(level越小权限越大)
|
|
|
- */
|
|
|
- private function _getRoleNode()
|
|
|
- {
|
|
|
- return $this->_role_service->getLevelNode($this->_user['admin_role_id'])->toArray();
|
|
|
+ public function view(Request $request) {
|
|
|
+ $data = $this->repository->find(request('id'));
|
|
|
+ return view('admin.album.user.view',compact('data'));
|
|
|
}
|
|
|
|
|
|
- public function searchStore()
|
|
|
- {
|
|
|
- $keyword = Request::post('keywords');
|
|
|
- $query = AlbumManufacturerModel::where('id','>',0);
|
|
|
- if(isset($keyword) && $keyword) {
|
|
|
- $query = $query->where('id','like','%'.$keyword.'%')
|
|
|
- ->orWhere('phone','like','%'.$keyword.'%')
|
|
|
- ->orWhere('name','like','%'.$keyword.'%');
|
|
|
- }
|
|
|
- $list = $query->get(['name','id','phone'])->toArray();
|
|
|
- if(empty($list)){
|
|
|
- $list[0]=[
|
|
|
- 'id'=>0,
|
|
|
- 'name'=>'暂无'
|
|
|
- ];
|
|
|
- }
|
|
|
- return response()->json(['code' => 0, 'message' => '', 'data' => $list]);
|
|
|
- }
|
|
|
|
|
|
/**
|
|
|
- * 得到所有角色
|
|
|
+ *
|
|
|
+ * 状态改变
|
|
|
+ *
|
|
|
*/
|
|
|
- private function _getRoles()
|
|
|
- {
|
|
|
- return $this->_role_service->get()->toArray();
|
|
|
+ public function status(Request $request) {
|
|
|
+ $ok = $this->repository->updateStatus(request('id'),request('status'));
|
|
|
+ if($ok) {
|
|
|
+ return $this->showMessage('操作成功');
|
|
|
+ }else{
|
|
|
+ return $this->showWarning('操作失败');
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 删除
|
|
|
*/
|
|
|
- public function destroy()
|
|
|
- {
|
|
|
- $user = AdminUserModel::find(Request::get('id'));
|
|
|
- $ok = $user->delete();
|
|
|
- if ($ok) {
|
|
|
+ public function destroy(Request $request) {
|
|
|
+ $bool = $this->repository->destroy($request->get('id'));
|
|
|
+ if($bool) {
|
|
|
return $this->showMessage('操作成功');
|
|
|
- } else {
|
|
|
+ }else{
|
|
|
return $this->showWarning("操作失败");
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ public function role(Request $request){
|
|
|
+ $id = request('id');
|
|
|
+ $role = request('role');
|
|
|
+ $user = AlbumUserModel::find($id);
|
|
|
+ if ($role == 4) {
|
|
|
+ $user->is_boss = 1;
|
|
|
+ } else if ($role == 5) {
|
|
|
+ $user->is_boss = 0;
|
|
|
+ } else {
|
|
|
+ $user->role = $role;
|
|
|
+ }
|
|
|
+ $ok = $user->save();
|
|
|
+ if($ok) {
|
|
|
+ return $this->showMessage('操作成功');
|
|
|
+ }else{
|
|
|
+ return $this->showWarning('操作失败');
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|