作者 Your Name

gx

... ... @@ -30,7 +30,6 @@ class BaseController extends Controller
{
$this->request = $request;
$this->param = $this->request->all();
$this->param['created_at'] = date("YmdHis");
$this->token = $this->request->header('token');
$this->get_param();
$this->auth_token();
... ... @@ -101,12 +100,12 @@ class BaseController extends Controller
case 'row':
$this->row = $v;
break;
case "create_at":
case "created_at":
$this->_btw[0] = $v;
$this->_btw[1] = date('Y-m-d H:i:s',time());
$this->map['create_at'] = ['between', $this->_btw];
break;
case "update_at":
case "updated_at":
$this->_btw[1] = $v;
$this->map['update_at'] = ['between', $this->_btw];
break;
... ...
... ... @@ -41,7 +41,7 @@ class ComController extends BaseController
$comLogic = new ComLogic();
$res = $comLogic->login($this->param);
if($res === false){
$this->response('请求失败',Code::USER_ERROR,[]);
$this->response('当前用户不存在或者被禁用,登录失败',Code::USER_ERROR,[]);
}
$this->response('请求成功',Code::SUCCESS,$res);
}
... ...
... ... @@ -23,6 +23,7 @@ class ProductClassifyController extends BaseController
$this->map['project_id'] = $this->user['project_id'];
$productClassifyModel = new ProductClassifyModel();
$lists = $productClassifyModel->lists($this->map,$this->p,$this->row,$this->order);
$this->allCount = $productClassifyModel->allCount;
$this->result($lists);
}
... ...
... ... @@ -23,6 +23,7 @@ class ProductController extends BaseController
$this->map['project_id'] = $this->user['project_id'];
$productModel = new ProductModel();
$lists = $productModel->lists($this->map,$this->p,$this->row,$this->order);
$this->allCount = $productModel->allCount;
$this->result($lists);
}
... ...
... ... @@ -19,6 +19,7 @@ class ProjectMenuController extends BaseController
//根据角色获取菜单列表
$projectMenuModel = new ProjectMenuModel();
$lists = $projectMenuModel->lists($this->param,$this->p,$this->row,$this->order);
$this->allCount = $projectMenuModel->allCount;
$this->result($lists);
}
... ...
... ... @@ -4,7 +4,7 @@ namespace App\Http\Controllers\Bside;
use App\Enums\Common\Code;
use App\Models\ProjectRole as ProjectRoleModel;
use Illuminate\Support\Facades\DB;
use App\Models\User as UserModel;
use Illuminate\Support\Facades\Validator;
class ProjectRoleController extends BaseController
... ... @@ -18,7 +18,9 @@ class ProjectRoleController extends BaseController
public function lists(){
//TODO::根据当前登录用户返回
$projectRoleModel = new ProjectRoleModel();
$lists = $projectRoleModel->lists($this->param,$this->p,$this->row,$this->order);
$this->map['status'] = 0;
$lists = $projectRoleModel->lists($this->map,$this->p,$this->row,$this->order);
$this->allCount = $projectRoleModel->allCount;
$this->result($lists);
}
... ... @@ -86,7 +88,7 @@ class ProjectRoleController extends BaseController
}
$projectRoleModel = new ProjectRoleModel();
//TODO::查询当前名称是否重复
$info = DB::table($projectRoleModel->getTable())->where('id','<>',$this->param['id'])
$info = $projectRoleModel->where('id','<>',$this->param['id'])
->where(['name'=>$this->param['name'],'project_id'=>$this->user['project_id']])->first();
if(!empty($info)){
$this->response('当前添加的角色已存在',Code::USER_PARAMS_ERROE);
... ... @@ -126,4 +128,37 @@ class ProjectRoleController extends BaseController
}
$this->response($this->param['status'] == 0 ? '启用成功' : '禁用成功',Code::SUCCESS);
}
/**
* @name :删除角色
* @return void
* @author :liyuhang
* @method
*/
public function del(){
//参数验证
$rules = [
'id'=>'required',
];
//验证的提示信息
$message = [
'id.required'=>'主键必须填写',
];
$validate = Validator::make($this->param, $rules, $message);
if($validate->fails()){
return $this->response($validate->errors()->first(),Code::USER_PARAMS_ERROE,$this->param);
}
$projectRoleModel = new ProjectRoleModel();
//查询当前角色下是否有用户
$userModel = new UserModel();
$user_info = $userModel->read(['role_id'=>$this->param['id']]);
if(!empty($user_info)){
$this->response('当前角色下有用户存在,不允许删除',Code::USER_ERROR);
}
$rs = $projectRoleModel->del(['id'=>$this->param['id']]);
if($rs === false){
$this->response('error',Code::USER_ERROR);
}
$this->response('success',Code::SUCCESS);
}
}
... ...
... ... @@ -19,12 +19,12 @@ class UserController extends BaseController
*/
public function lists(){
//TODO::搜索参数处理
$userLogic = new UserLogic();
$lists = $userLogic->lists($this->map,$this->p,$this->row,$this->order,['id','name','mobile']);
$userModel = new UserModel();
$lists = $userModel->lists($this->map,$this->p,$this->row,$this->order,['id','name','mobile']);
if(empty($lists)){
$this->response('请求失败',Code::USER_ERROR,[]);
}
return response()->json($lists);
$this->allCount = $userModel->allCount;
$this->result($lists);
}
... ...
... ... @@ -2,6 +2,7 @@
namespace App\Http\Logic\Bside;
use App\Models\ProjectRole as ProjectRoleModel;
use App\Models\User as UserModel;
use Illuminate\Support\Facades\Cache;
... ... @@ -14,12 +15,11 @@ class ComLogic extends BaseLogic
* @method
*/
public function login($param){
#TODO 查询mobile, 验证密码 true->return; false-> 查询sms发送记录 验证code
$userModel = new UserModel();
if(!isset($param['login_method'])){
//密码加密
$param['password'] = base64_encode(md5($param['password']));
$info = $userModel->read(['mobile'=>$param['mobile'],'password'=>$param['password']], ['*']);
$info = $userModel->read(['mobile'=>$param['mobile'],'password'=>$param['password'],'status'=>0], ['*']);
}else{
//TODO::验证验证码是否正确
$info = $userModel->read(['mobile'=>$param['mobile']],['*']);
... ... @@ -27,8 +27,13 @@ class ComLogic extends BaseLogic
if(empty($info)){
return false;
}
//当前用户角色是否被禁用
$projectRoleModel = new ProjectRoleModel();
$role_info = $projectRoleModel->read(['id'=>$info['role_id'],'status'=>0]);
if(empty($role_info)){
return false;
}
//验证码登录
if(isset($info['token']) && !empty($info['token'])){
//清除上一次用户缓存
Cache::pull($info['token']);
... ... @@ -38,7 +43,6 @@ class ComLogic extends BaseLogic
//存储缓存
Cache::add($token,$info);
//更新数据库
$data = [
'id'=>$info['id'],
'mobile'=>$info['mobile'],
... ...
... ... @@ -19,9 +19,10 @@ class Base extends Model
//TODO::where(['id'=>'','name'=>''])
$lists = $this->select($fields)->where($map)->forPage($p,$row)->orderBy($order)->get();
if ($lists->isEmpty() === false) {
return false;
}
$lists = $lists->toArray();
$this->allCount = $this->where($map)->count();
}
return $lists;
}
... ... @@ -38,8 +39,9 @@ class Base extends Model
public function list($map,$order = 'id',$fields = ['*']){
$lists = $this->select($fields)->where($map)->orderBy($order)->get();
if ($lists->isEmpty() === false) {
$lists = $lists->toArray();
return false;
}
$lists = $lists->toArray();
return $lists;
}
/**
... ...
... ... @@ -16,6 +16,10 @@ Route::group([], function () {
Route::any('/get_project', [\App\Http\Controllers\Bside\ComController::class, 'get_project'])->name('get_project');
Route::any('/user/lists', [\App\Http\Controllers\Bside\UserController::class, 'lists'])->name('user_lists');
Route::any('/project/page_lists', [\App\Http\Controllers\Bside\ProjectController::class, 'page_lists'])->name('page_lists');
//用户角色相关路由
Route::any('/project_role/lists', [\App\Http\Controllers\Bside\ProjectRoleController::class, 'lists'])->name('project_role_lists');
Route::any('/project_role/add', [\App\Http\Controllers\Bside\ProjectRoleController::class, 'add'])->name('project_role_add');
Route::any('/project_role/edit', [\App\Http\Controllers\Bside\ProjectRoleController::class, 'edit'])->name('project_role_edit');
Route::any('/project_role/status', [\App\Http\Controllers\Bside\ProjectRoleController::class, 'status'])->name('project_role_status');
Route::any('/project_role/del', [\App\Http\Controllers\Bside\ProjectRoleController::class, 'del'])->name('project_role_del');
});
... ...