function ($params) { // $keyword = $params['keyword'] ?? ''; // return [ // 'filters' => [ // ['field' => '***', 'operator' => '=', 'value' => '***'] // ], // 'fields' => ['id'], // 'relations' => [], // 'custom' => function(Builder $q) use ($keyword) { // // 示例 // if ($keyword) { // $q->where(function($q2) use($keyword) { // $q2->whereHas('***', function($q3) use($keyword) { // $q3->where('***', 'like', "%{$keyword}%"); // })->orWhereHas('***', function($q4) use($keyword) { // $q4->where('***', 'like', "%{$keyword}%"); // }); // }); // } // }, // 'sorts' => [ // ['field' => 'created_at', 'direction' => 'desc'] // ], // 'pagination' => [ // 'page' => $params['page'] ?? 1, // 'per_page' => $params['per_page'] ?? 10, // ] // ]; // } ]; } public function login(array $params) { $sourceLocale = locale(); try { if (empty($params['username'])) { throw new BusinessException('用户名不能为空'); } if (empty($params['password'])) { throw new BusinessException('密码不能为空'); } $admin = AdminsModel::where(['username'=>$params['username']])->first(); if (!$admin) { throw new BusinessException('用户不存在'); } $userId = $admin['id']; $adminPassword = $admin['password']; // $hashedPassword = password_hash($params['password'], PASSWORD_DEFAULT); //注册时的加密方法 if (!password_verify($params['password'], $adminPassword)) { throw new BusinessException('密码错误'); } //密码验证成功后加密生成 Token $token = JwtUtil::generateToken($userId); $result = $admin; unset($result['password']); $result['token'] = $token; return $admin; } catch (\Throwable $th) { throw $th; } } }