cqp 1 месяц назад
Родитель
Сommit
5eeb4df502

+ 11 - 0
app/Http/Controllers/Api/LoginController.php

@@ -16,4 +16,15 @@ class LoginController extends BaseController
             return $this->json_return(201, $data);
         }
     }
+
+    public function cLogin(Request $request){
+        $service = new LoginService();
+        list($status,$data) = $service->cLogin($request->all());
+
+        if($status){
+            return $this->json_return(200,'',$data);
+        }else{
+            return $this->json_return(201, $data);
+        }
+    }
 }

+ 10 - 0
app/Providers/RouteServiceProvider.php

@@ -43,6 +43,8 @@ class RouteServiceProvider extends ServiceProvider
     public function map()
     {
         $this->mapApiRoutes();
+
+        $this->mapCApiRoutes();
     }
 
     /**
@@ -59,4 +61,12 @@ class RouteServiceProvider extends ServiceProvider
              ->namespace($this->namespace)
              ->group(base_path('routes/api.php'));
     }
+
+    protected function mapCApiRoutes()
+    {
+        Route::prefix('cApi')
+            ->middleware('api')
+            ->namespace($this->namespace)
+            ->group(base_path('routes/c_api.php'));
+    }
 }

+ 0 - 18
app/Service/EmployeeService.php

@@ -1064,22 +1064,4 @@ class EmployeeService extends Service
             ->pluck('title', 'id')
             ->toArray();
     }
-
-    public static function fillMenu2($menu_id, &$user){
-        // 直接查询匹配的菜单
-        $menuItem = SysMenu::where('del_time',0)
-            ->where('id', $menu_id)
-            ->first();
-
-        $func = $menuItem ? $menuItem->export_file_func : "";
-        $funcName = $menuItem ? $menuItem->title : "";
-
-        $header_default = config("excel." . $func) ?? [];
-//        $header_f = "extra_" . $menu_id;
-//        $service = new TableHeadService();
-//        if(method_exists($service,$header_f)) $service->$header_f($header_default);
-        $user['e_header_default'] = $header_default;
-
-        return [$func, $funcName];
-    }
 }

+ 26 - 0
app/Service/LoginService.php

@@ -39,6 +39,32 @@ class LoginService extends Service
         ]];
     }
 
+    public function clogin($data){
+        if(empty($data['account'])) return [false, '账号不能为空'];
+        if(empty($data['password'])) return [false, '密码不能为空'];
+
+        $account = $data['account'];
+        $password = $data['password'];
+        $employee = Employee::where('del_time',0)
+            ->where('account', $account)
+            ->first();
+        if(empty($employee)) return [false,'账号不存在或已被删除'];
+        $employee = $employee->toArray();
+
+        if(! Hash::check($password, $employee['password'])) return [false,'密码错误'];
+        if($employee['is_admin'] != Employee::IS_ADMIN_THREE) return [false, '账号限制登录'];
+
+        //生成token
+        list($status, $jwtToken) = TokenService::getToken($employee);
+        if(! $status) return [false, $jwtToken];
+
+        return [true, [
+            'token' => $jwtToken,
+            'employee_id' => $employee['id'],
+            'title' => $employee['title'],
+        ]];
+    }
+
     public static function checkUser($employee){
         if(empty($employee['employee_id'])) return [false, 'token错误'];
         if(! isset($employee['p_version'])) return [false, 'token错误'];

+ 1 - 1
config/cors.php

@@ -21,7 +21,7 @@ return [
      * You can enable CORS for 1 or multiple paths.
      * Example: ['api/*']
      */
-    'paths' => ['api/*','assetapi/*','maycur/*'],
+    'paths' => ['api/*','cApi/*'],
 
     /*
     * Matches the request method. `[*]` allows all methods.

+ 0 - 22
routes/api.php

@@ -239,25 +239,3 @@ Route::group(['middleware'=> ['checkLogin']],function ($route){
     $route->any('homePageData', 'Api\BIController@homePageData');
 });
 
-//中台路由
-Route::group(['middleware'=> ['checkCenterLogin']],function ($route){
-    $route->any('roleMiddleGroundAdd', 'Api\MiddleGroundController@roleAdd');
-    $route->any('roleMiddleGroundEdit', 'Api\MiddleGroundController@roleEdit');
-    $route->any('roleMiddleGroundDel', 'Api\MiddleGroundController@roleDel');
-    $route->any('roleMiddleGroundList', 'Api\MiddleGroundController@roleList');
-    $route->any('roleMiddleGroundDetail', 'Api\MiddleGroundController@roleDetail');
-    $route->any('roleMiddleGroundMenu', 'Api\MiddleGroundController@roleMenu');
-
-    //创建公司账号 工时设置 初始化
-    $route->any('initializationCompany', 'Api\MiddleGroundController@initializationCompany');
-    //公司列表
-    $route->any('initializationCompanyList', 'Api\MiddleGroundController@initializationCompanyList');
-
-    //菜单列表 为了设置角色权限用的
-    $route->any('menuMiddleGroundList', 'Api\MiddleGroundController@menuList');
-
-    //管理员
-    $route->any('employeeMiddleGroundList', 'Api\MiddleGroundController@employeeList');
-    $route->any('employeeMiddleGroundEdit', 'Api\MiddleGroundController@employeeEdit');
-});
-

+ 38 - 0
routes/c_api.php

@@ -0,0 +1,38 @@
+<?php
+
+use Illuminate\Http\Request;
+
+/*
+|--------------------------------------------------------------------------
+| API Routes
+|--------------------------------------------------------------------------
+|
+| Here is where you can register API routes for your application. These
+| routes are loaded by the RouteServiceProvider within a group which
+| is assigned the "api" middleware group. Enjoy building your API!
+|
+*/
+
+//伪中台路由
+Route::any('login', 'Api\LoginController@cLogin');
+Route::group(['middleware'=> ['checkCenterLogin']],function ($route){
+    $route->any('roleAdd', 'Api\MiddleGroundController@roleAdd');
+    $route->any('roleEdit', 'Api\MiddleGroundController@roleEdit');
+    $route->any('roleDel', 'Api\MiddleGroundController@roleDel');
+    $route->any('roleList', 'Api\MiddleGroundController@roleList');
+    $route->any('roleDetail', 'Api\MiddleGroundController@roleDetail');
+    $route->any('roleMenu', 'Api\MiddleGroundController@roleMenu');
+
+    //创建公司账号 工时设置 初始化
+    $route->any('initializationCompany', 'Api\MiddleGroundController@initializationCompany');
+    //公司列表
+    $route->any('initializationCompanyList', 'Api\MiddleGroundController@initializationCompanyList');
+
+    //菜单列表 为了设置角色权限用的
+    $route->any('menuList', 'Api\MiddleGroundController@menuList');
+
+    //管理员
+    $route->any('employeeList', 'Api\MiddleGroundController@employeeList');
+    $route->any('employeeEdit', 'Api\MiddleGroundController@employeeEdit');
+});
+