Commit d9fea626 by lincyawer

重构个人主页页面api

parent 1fa6a45e
......@@ -8,7 +8,6 @@
use App\Http\Service\LoginService;
use App\Http\Service\UserService;
use App\Http\Service\UserTokenService;
use App\Models\user\UserInfoModel;
use App\Models\user\LoginModel;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Config;
......@@ -221,7 +220,6 @@ private function checkLoginFailedLimit($info)
// 只做邮件提醒
$maxTimes = Config::get('website.maxPasswdIncorrectTimes', 3); // 3 30 90
// if ($wrongTimes == $maxTimes || $wrongTimes == 10 * $maxTimes || $wrongTimes == 30 * $maxTimes) {
if ($wrongTimes == $maxTimes) {
$body = "您的账号24小时内已错误登录{$wrongTimes}次, 为了您的账号安全,请尽快更改密码。";
Mail::raw($body, function ($message) use ($email, $name) {
......
......@@ -113,7 +113,7 @@ public static function Autograph()
function Crumbs($menus, $uri)
{
$actives = [];
CheckActive($menus, $actives, $uri);
Functions::CheckActive($menus, $actives, $uri);
$ret = '';
foreach ($actives as $k => $v) {
if ($k == count($actives) - 1) {
......@@ -141,7 +141,7 @@ static function CheckActive($menus, &$arr, $url)
if (isset($menu->href) && ($menu->href == $url || ($menu->href == '/' && $url == '//')))
return true;
if (isset($menu->childs) && count($menu->childs) > 0) { // 多级菜单递归查找
$ret = CheckActive($menu->childs, $arr, $url);
$ret = Functions::CheckActive($menu->childs, $arr, $url);
if ($ret)
return $ret;
}
......
......@@ -43,6 +43,7 @@ class Kernel extends HttpKernel
'api' => [
// \Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class,
'throttle:api',
\App\Http\Middleware\CheckLogin::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],
'noauth' => [],
......
......@@ -36,7 +36,7 @@ public function handle($request, Closure $next)
$user = (object)$ret['data'];
$user->header = $request->cookie('oa_header');
// $request->user= $user;
$request->user= $user;
$request->setUserResolver(function () use ($user) {
return $user;
});
......
......@@ -2,14 +2,21 @@
namespace App\Http\Service;
use App\Models\CommonModel;
use App\Models\user\DepartmentModel;
class DepartmentService
class DepartmentService extends CommonModel
{
protected $table = 'user_department';
protected $primaryKey = 'department_id';
protected $guarded = ['department_id'];
// protected $fillable = ['department_name', 'author', 'last_author'];
const CREATED_AT = 'ctime';
const UPDATED_AT = 'mtime';
// 获取菜单
public static function getDepartmentHtml()
{
$department_id_name_parentId_list = DepartmentModel::getDepartmentIdNameParentIdList();
$department_id_name_parentId_list = DepartmentModel::getDepList();
$department_tree = self::generateTree($department_id_name_parentId_list);
return self::makeDepartmentHtml($department_tree);
}
......@@ -73,18 +80,22 @@ public static function getSubDepartmentId($department_id, &$department_ids)
return $department_ids;
}
// 获取最顶层部门id
public static function getRootDepartmentId($department_id)
{
if (empty($department_id)) {
return $department_id;
}
$department_info = DepartmentModel::getDepartmentById($department_id);
$department_info = self::getDepartmentById($department_id);
if ($department_info['parent_id']) {
return self::getRootDepartmentId($department_info['parent_id']);
}
return ($department_info) ? $department_info['department_id'] : 0;
}
// 根据部门id,获取部门信息
public static function getDepartmentById($department_id)
{
$res = self::where('department_id', $department_id)->first();
return ($res) ? $res->toArray() : [];
}
}
<?php
namespace App\Http\Service;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Log;
class LdapManagerService
{
// LDAP variables
private $ldaphost;
private $ldaprdn;
private $ldappass;
private $ldapport;
private static $fields = [
'email' => 'mail',
'name' => 'displayName',
'workNumber' => 'employeeNumber',
'mobile' => 'mobile',
'introduction' => 'description',
'address' => 'street',
'province' => 'st',
'header' => 'jpegPhoto',
];
public function __construct()
{
$config = Config::get('website.ldap');
$this->ldaphost = $config['host'];
$this->ldaprdn = $config['dn'];
$this->ldappass = $config['passwd'];
$this->ldapport = $config['port'];
$dn_arr = explode(",", $this->ldaprdn);
array_shift($dn_arr);
$this->ldapUserOu = "ou=Group," . implode(",", $dn_arr);
}
public function ldapCreateUser($info)
{
if (!function_exists('ldap_connect')) {
Log::error("ldap not installed");
return false;
}
if (empty($info['engName']) || empty($info['userId'])) {
Log::error("ldapCreateUser : empty engName or userId");
throw new \Exception("ldapCreateUser : empty engName or userId");
}
Log::info("execute ldapCreateUser" . $info['userId']);
// Connecting to LDAP
$ldapconn = ldap_connect($this->ldaphost, $this->ldapport);
if (!$ldapconn) {
Log::error("Could not connect to {$this->ldaphost}");
throw new \Exception("Could not connect to {$this->ldaphost}");
}
ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3);
// binding to ldap server
$ldapbind = ldap_bind($ldapconn, $this->ldaprdn, $this->ldappass);
if (!$ldapbind) {
Log::error("Could not bind to {$this->ldaprdn}");
throw new \Exception("Could not bind to {$this->ldaprdn}");
}
$dn = "cn=" . $info['email'] . ",cn={$info['businessCategory']}," . $this->ldapUserOu;
$temp['cn'] = $info['email'];
$temp['sn'] = $info['engName'];
$temp['uid'] = $info['userId'];
$temp['gidNumber'] = $info['gidNumber'];
$temp['businessCategory'] = $info['businessCategory'];
$temp['uidNumber'] = $info['userId'];
$temp['givenName'] = $info['engName'];
$temp['objectclass'] = ["top", "posixAccount", "inetOrgPerson"];
$temp['homeDirectory'] = "/home/users/{$info['engName']}";
$temp['userPassword'] = '{MD5}' . base64_encode(pack('H*', md5("123456")));
foreach (self::$fields as $from => $to) {
if (!empty($info[$from])) {
$temp[$to] = $info[$from];
}
}
$ret = ldap_add($ldapconn, $dn, $temp);
if (!$ret) {
Log::error("ldap_add failed");
}
ldap_close($ldapconn);
return $ret ? true : false;
}
public function ldapUpdate($email, $info)
{
if (!function_exists('ldap_connect')) {
Log::error("ldap not installed");
return false;
}
assert(!empty($info));
Log::info("execute ldapUpdate " . $email);
// Connecting to LDAP
$ldapconn = ldap_connect($this->ldaphost, $this->ldapport);
if (!$ldapconn) {
Log::error("Could not connect to {$this->ldaphost}");
throw new \Exception("Could not connect to {$this->ldaphost}");
}
ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3);
// binding to ldap server
$ldapbind = ldap_bind($ldapconn, $this->ldaprdn, $this->ldappass);
if (!$ldapbind) {
Log::error("Could not bind to {$this->ldaprdn}");
throw new \Exception("Could not bind to {$this->ldaprdn}");
}
$dn = "cn=" . $email . ",cn={$info['businessCategory']}," . $this->ldapUserOu;
foreach (self::$fields as $from => $to) {
if (!empty($info[$from])) {
$update[$to] = $info[$from];
} else {
$update[$to] = Array();
}
}
$update['gidNumber'] = $info['gidNumber'];
$update['businessCategory'] = $info['businessCategory'];
$ret = ldap_modify($ldapconn, $dn, $update);
if (!$ret) {
Log::error("ldap_modify failed : update failed");
}
ldap_close($ldapconn);
return $ret ? true : false;
}
public function ldapResetPasswd($email, $passwd, $ldap_group_name)
{
if (!function_exists('ldap_connect')) {
Log::error("ldap not installed");
return false;
}
Asset(!empty($passwd));
Log::info("ldapResetPasswd " . $email);
// Connecting to LDAP
$ldapconn = ldap_connect($this->ldaphost, $this->ldapport);
if (!$ldapconn) {
Log::error("Could not connect to {$this->ldaphost}");
throw new \Exception("Could not connect to {$this->ldaphost}");
}
ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3);
// binding to ldap server
$ldapbind = ldap_bind($ldapconn, $this->ldaprdn, $this->ldappass);
if (!$ldapbind) {
Log::error("Could not bind to {$this->ldaprdn}");
throw new \Exception("Could not bind to {$this->ldaprdn}");
}
$passwd = '{MD5}' . base64_encode(pack('H*', md5($passwd)));
$dn = "cn=" . $email . ",cn={$ldap_group_name}," . $this->ldapUserOu;
$reset['userPassword'] = $passwd;
$ret = ldap_modify($ldapconn, $dn, $reset);
if (!$ret) {
Log::error("ldap_modify failed: reset password failed");
}
ldap_close($ldapconn);
return $ret ? true : false;
}
public function ldapSearchCn($email, $ldap_group_name)
{
if (!function_exists('ldap_connect')) {
Log::error("ldap not installed");
return false;
}
Assert(!empty($email));
Log::info("execute ldapSearchCn " . $email);
// Connecting to LDAP
$ldapconn = ldap_connect($this->ldaphost, $this->ldapport);
if (!$ldapconn) {
Log::error("Could not connect to {$this->ldaphost}");
throw new \Exception("Could not connect to {$this->ldaphost}");
}
ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3);
// binding to ldap server
$ldapbind = ldap_bind($ldapconn, $this->ldaprdn, $this->ldappass);
if (!$ldapbind) {
Log::error("Could not bind to {$this->ldaprdn}");
throw new \Exception("Could not bind to {$this->ldaprdn}");
}
$ret = ldap_search($ldapconn, "cn={$ldap_group_name}," . $this->ldapUserOu, "(cn={$email})");
if (!$ret) {
Log::error("ldap_search error");
return false;
}
$entry = ldap_first_entry($ldapconn, $ret);
ldap_close($ldapconn);
return $entry ? true : false;
}
public function ldapDelete($email, $ldap_department_name)
{
if (!function_exists('ldap_connect')) {
Log::error("ldap not installed");
return false;
}
Log::info("execute ldapDelete " . $email);
// Connecting to LDAP
$ldapconn = ldap_connect($this->ldaphost, $this->ldapport);
if (!$ldapconn) {
Log::error("Could not connect to {$this->ldaphost}");
throw new \Exception("Could not connect to {$this->ldaphost}");
}
ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3);
// binding to ldap server
$ldapbind = ldap_bind($ldapconn, $this->ldaprdn, $this->ldappass);
if (!$ldapbind) {
Log::error("Could not bind to {$this->ldaprdn}");
throw new \Exception("Could not bind to {$this->ldaprdn}");
}
$dn = "cn=" . $email . ",cn={$ldap_department_name}," . $this->ldapUserOu;
if (!$this->ldapSearchCn($email, $ldap_department_name)) {
return true;
}
$ret = ldap_delete($ldapconn, $dn);
if (!$ret) {
Log::error("ldap_delete failed : delete failed");
}
ldap_close($ldapconn);
return $ret ? true : false;
}
}
<?php
namespace App\Http\Service;
use App\Http\Error;
use App\Http\Output;
use App\Models\user\DepartmentModel;
use App\Models\user\TBusinessConfigModel;
use App\Models\user\TRolePermModel;
use App\Models\user\TUserPermModel;
use App\Models\user\UserInfoModel;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
class PermService
{
......@@ -18,10 +25,11 @@ class PermService
'采购' => 8,
'行政' => 9,
];
// 检查用户是否具有系统访问权限
public static function checkAccess($request): bool
public static function checkAccess(Request $request): bool
{
$user_id = $request->user->userId;
$user_id = $request->getUserResolver()()->userId;
$role = self::getUserRole($request);
if ($role == 1) {
......@@ -40,6 +48,7 @@ public static function checkAccess($request): bool
return false;
}
// 获取用户角色:1-管理员,0-用户
public static function getUserRole(Request $request): int
{
......@@ -173,6 +182,7 @@ public static function handleMenus($menus, $perms)
return array_values($menus);
}
// 获取权限菜单
public static function getMenuPerm($menus, $user_id)
{
......@@ -183,4 +193,94 @@ public static function getMenuPerm($menus, $user_id)
return false;
}
public static function getParentDepartment($id)
{
$parentId = DepartmentModel::getParentId($id);
$parentDep = DepartmentModel::getInfoById($parentId);
if(isset($parentDep[0])){
return $parentDep[0]['department_name'];
}
return '';
}
// 设置用户角色权限
public static function setUserRolePerm($info, $bid, $roleId)
{
$data = [];
$data['bid'] = $bid;
$data['userId'] = $info['userId'];
$data['roles'] = json_encode(array("{$roleId}"));
$data['perms'] = json_encode(array());
$data['username'] = $info['email'];
$data['begDate'] = date('Y-m-d');
$data['endDate'] = date('Y-m-d', time() + 15552000); // 半年
$data['ctime'] = date('Y-m-d H:i:s');
$data['mtime'] = date('Y-m-d H:i:s');
$id = TUserPermModel::setUserRoot($data);
if ($id === false) {
return false;
}
return true;
}
// 清除用户所有权限
public static function delUserPerms($userId)
{
$map = [];
if (is_array($userId)) {
$str_userid = implode(',', $userId);
$map[] = [DB::raw("userId in ({$str_userid})"), '1'];
} else {
$map['userId'] = $userId;
}
return TUserPermModel::deleteUserRoot($map);
}
// 设置用户权限
public static function setupUserPerm($info, $rolename = '运营')
{
$business_info = TBusinessConfigModel::getBusinessInfoByTitle($info['title']);
$data['bid'] = $business_info->bid;
$data['userId'] = $info['userId'];
// 检查是否存在
$ret = TUserPermModel::getBidUserId($data);
if ($ret) {
$data['roles'] = json_encode(["{self::roles[$rolename]}"]);
$data['mtime'] = date('Y-m-d H:i:s');
$update = TUserPermModel::updateRoleNameMtime($data);
if ($update === false) {
return false;
}
return true;
}
// 不存在则创建
$role = TRolePermModel::getBidUsername($business_info->bid, $rolename);
$data['roles'] = json_encode(array("{$role->roleId}"));
$data['perms'] = json_encode(array());
$data['username'] = $info['email'];
$data['begDate'] = date('Y-m-d');
$data['endDate'] = date('Y-m-d', time() + 15552000); // 半年
$data['ctime'] = date('Y-m-d H:i:s');
$data['mtime'] = date('Y-m-d H:i:s');
$id = TUserPermModel::setUserRoot($data);
if ($id === false) {
return false;
}
return true;
}
}
......@@ -45,18 +45,4 @@ public static function createToken($userId, $expire = null)
}
return $data;
}
public static function setTokenStatus($userId, $token, $status)
{
return DB::table(self::TABLE_NAME)->where('userId', $userId)
->where('token', $token)->update(['status' => $status, 'mtime' => date('Y-m-d H:i:s')]);
}
public static function checkToken($userId, $token)
{
$count = DB::table(self::TABLE_NAME)->where('userId', $userId)
->where('status', 0)->where('token', $token)
->where('expireTime', '>=', date('Y-m-d H:i:s'))->count();
return $count == 1;
}
}
<?php
namespace App\Models\crm;
use Illuminate\Database\Eloquent\Model;
class EmployeeCardModel extends Model
{
protected $connection = 'crm';
protected $table = 'employee_card';
protected $primaryKey = 'id';
protected $guarded = ['id'];
public $timestamps = true;
const CREATED_AT = 'create_time';
const UPDATED_AT = 'update_time';
/** * @param \DateTime|int $value * @return false|int * @author dividez */
public function fromDateTime($value)
{
return strtotime(parent::fromDateTime($value));
}
public static function delById($userId)
{
return self::where('sale_id', $userId)->delete();
}
public static function create($userId,$employee)
{
return self::updateOrCreate(['sale_id' => $userId], $employee);
}
}
<?php
namespace App\Models\queue;
use Illuminate\Database\Eloquent\Model;
use PhpAmqpLib\Connection\AMQPStreamConnection;
use PhpAmqpLib\Message\AMQPMessage;
class QueuedModel extends Model
{
public function pushAmq($content = '')
{
$config = Config('database.connections.rabbitmq');
$connection = new AMQPStreamConnection($config['host'], $config['port'], $config['login'], $config['password'],
$config['vhost']); // 创建连接
$channel = $connection->channel();
$channel->queue_declare($config['queue'], false, true, false, false);
$message = new AMQPMessage($content);
$channel->basic_publish($message, '', $config['queue']); // 推送消息
$channel->close();
$connection->close();
}
public function pullAmq($queue_name = '')
{
// $queue_name = 'test';
$config = Config('database.connections.rabbitmq');
$connection = new AMQPStreamConnection($config['host'], $config['port'], $config['login'], $config['password'],
$config['vhost']); // 创建连接
$channel = $connection->channel();
$message = $channel->basic_get($queue_name); // 取出消息
echo '<pre>';
print_r($message);
$channel->basic_ack($message->delivery_info['delivery_tag']); // 确认取出消息后会发送一个ack来确认取出来了,然后会从rabbitmq中将这个消息移除,如果删掉这段代码,会发现rabbitmq中的消息还是没有减少
$channel->close();
$connection->close();
}
// 自定义队列推送
public function pushQueue($queue_name, $content)
{
$config = Config('database.connections.rabbitmq');
$connection = new AMQPStreamConnection($config['host'], $config['port'], $config['login'], $config['password'],
$config['vhost']); // 创建连接
$channel = $connection->channel();
$channel->queue_declare($queue_name, false, true, false, false);
$message = new AMQPMessage($content);
$channel->basic_publish($message, '', $queue_name); // 推送消息
$channel->close();
$connection->close();
}
}
<?php
namespace App\Models\user;
use App\Models\CommonModel;
......@@ -12,103 +14,28 @@ class DepartmentModel extends CommonModel
const CREATED_AT = 'ctime';
const UPDATED_AT = 'mtime';
public static function getDepartmentListByIds($ids)
{
$res = self::whereIn('department_id', $ids)->get();
return ($res) ? $res->toArray() : [];
}
public static function countDepartmentId($departmentId)
{
return self::where('parent', $departmentId)->count();
}
public static function deleteDepartmentId($departmentId)
{
self::where('department_id', $departmentId)->delete();
}
public static function getDepartmentIdWithNameList($department_id)
{
return self::where('parent_id', $department_id)->select('department_id', 'department_name')->get();
}
public static function getDepartmentIdWithNameMap()
{
return self::pluck('department_name', 'department_id');
}
public static function getDepartmentIdList($department_id)
{
return self::where('department_id', $department_id)->first();
}
// 根据部门id,获取部门信息
public static function getDepartmentById($department_id)
{
$res = self::where('department_id', $department_id)->first();
return ($res) ? $res->toArray() : [];
}
public static function getDepartmentNameWithIdList($map = '')
public static function getDepList()
{
if ($map) {
return self::where($map)->pluck('department_name', 'department_id')->toArray();
}
return self::pluck('department_name', 'department_id')->toArray();
}
public static function getExistDepartmentIdsByIds($depart_ids)
{
return self::whereIn('department_id', $depart_ids)
->select(['department_name', 'department_id'])
->get()
->pluck(['department_id'])->toArray();
}
public static function getDepartmentNameList($department_name)
{
return self::where('department_name', $department_name)->first();
}
public static function updateDataByDepartmentId($departmentId, $data)
{
return self::where('department_id', $departmentId)->update($data);
}
public static function createData($data)
{
return self::create($data);
}
public function fromDateTime($value)
{
return strtotime(parent::fromDateTime($value));
return self::select('department_id', 'department_name', 'parent_id')->get()->toArray();
}
//根据插入时间获取id
public static function getIdFormCtime($data)
public static function getParentId($id)
{
return self::insertGetId($data);
return self::select('department_id', 'department_name', 'parent_id')->where('department_id', $id)->get()->toArray();
}
public static function getDepartmentInfoList($field)
public static function getInfoById($id)
{
return self::select($field)
->get()
->toArray();
return self::where('department_id', $id)->get()->toArray();
}
public static function getDepartmentIdNameParentIdList()
public static function getDepartmentNameWithIdArray()
{
return self::select('department_id', 'department_name', 'parent_id')->get()->toArray();
return self::select('department_name', 'department_id')->get();
}
public static function getDepartmentNameWithIdArray()
public static function getDepartmentIdWithNameList($department_id)
{
return self::lists('department_name', 'department_id');
return self::where('parent_id', $department_id)->select('department_id', 'department_name')->get();
}
}
......@@ -14,22 +14,4 @@ public static function insertData($data)
{
return self::insert($data);
}
public static function getLoginListByUserIdAndTime($userId, $expire)
{
$res = self::where('userId', $userId)
->where('expireTime', '>', $expire)->get();
return ($res) ? $res->toArray() : [];
}
// 根据条件获取列表
public static function getListByWhere($where, $page, $limit, $field = "*")
{
$query = self::select($field);
if ($where) {
$query->where($where);
}
return $query->orderBy('loginTime', 'desc')->paginate($limit, ['*'], 'page', $page)->toArray();
}
}
......@@ -13,16 +13,6 @@ class PositionModel extends CommonModel
const CREATED_AT = 'ctime';
const UPDATED_AT = 'mtime';
public static function getPositionFieldList($where, $field, $limit, $page)
{
$query = self::select($field);
if ($where) {
$query->where($where);
}
return $query->orderBy('ctime', 'desc')
->orderBy('position_id', 'desc')
->paginate($limit, ['*'], 'page', $page)->toArray();
}
public function fromDateTime($value)
{
......@@ -42,25 +32,7 @@ public static function getPositionNameMap()
return $data;
}
public static function getPositionNameList($position_name)
{
return self::where('position_name', $position_name)->first();
}
public static function createData($data)
{
return self::create($data);
public static function getPositionNameWithIdArray(){
return self::select('position_name', 'position_id')->get();
}
public static function updatedData($position_id, $data)
{
return self::where('position_id', $position_id)->update($data);
}
public static function deleteData($position_id)
{
return self::where('position_id', $position_id)->delete();
}
}
<?php
namespace App\Models\user;
use Illuminate\Database\Eloquent\Model;
class PositionPermModel extends Model
{
protected $table = 'user_position_perm';
protected $primaryKey = 'position_perm_id';
protected $guarded = ['position_perm_id'];
// protected $fillable = ['user_role_id', 'user_role_name', 'bid', 'business_name', 'role_id', 'role_name', 'author', 'last_author'];
const CREATED_AT = 'ctime';
const UPDATED_AT = 'mtime';
// 获取用户角色权限
public static function getUserRolePermList($position_id)
{
if (!$position_id) return false;
return self::where('position_id', $position_id)->select('position_perm_id', 'position_id', 'bid', 'role_id')->get()->toArray();
}
}
......@@ -10,23 +10,6 @@ class TBusinessConfigModel extends CommonModel
protected $primaryKey = 'bid';
public $timestamps = false;
// 获取所有业务系统名称
public static function getBusinessNameList()
{
return self::pluck('title', 'bid')->toArray();
}
//获取系统信息
public static function getBusinessInfo()
{
$domain = $_SERVER['SERVER_ADDR'] == '127.0.0.1' ? 'http://' . substr($_SERVER['HTTP_HOST'], 1) : 'http://' . $_SERVER['HTTP_HOST'];
// 根据域名查询系统业务ID
$business = self::where('url', $domain)->first();
return !empty($business) ? $business : false;
}
//根据title获取系统信息
public static function getBusinessInfoByTitle($title)
{
......
......@@ -4,16 +4,16 @@
use Illuminate\Database\Eloquent\Model;
Class TRolePermModel extends Model
class TRolePermModel extends Model
{
protected $table = 't_role_perm';
protected $primaryKey = 'roleId';
public $timestamps = false;
// 获取所有业务系统角色
public static function getRoles($bid)
//获取业务id和角色名
public static function getRoleInfoByRoleIdAndBid($role_id, $bid)
{
return self::where('bid', $bid)->pluck('name', 'roleId')->toArray();
return self::where(['roleId' => $role_id, 'bid' => $bid])->first();
}
//获取业务id和角色名
......@@ -22,9 +22,8 @@ public static function getBidUsername($bid, $roleName)
return self::where(['bid' => $bid, 'name' => $roleName])->first();
}
//获取业务id和角色名
public static function getRoleInfoByRoleIdAndBid($role_id, $bid)
public static function QueryWhere(array $whereCond)
{
return self::where(['roleId' => $role_id, 'bid' => $bid])->first();
return self::where($whereCond)->get();
}
}
......@@ -16,39 +16,26 @@ public static function getUserIdBid($uid, $bid)
{
return self::where(['userId' => $uid, 'bid' => $bid])->first();
}
//清除用户权限
public static function deleteUserRoot($map)
{
return self::where($map)->delete();
}
//设置角色权限
public static function setUserRoot($data)
{
return self::insertGetId($data);
}
//修改角色名称和时间
public static function updateRoleNameMtime($data)
//清除用户权限
public static function deleteUserRoot($map)
{
return self::update($data);
return self::where($map)->delete();
}
//获取业务id和用户id
public static function getBidUserId($data)
public static function getBidUserId($whereList)
{
return self::where($data)->first();
return self::where($whereList)->first();
}
//
public static function selectBidRoles($bid,$roleId)
//修改角色名称和时间
public static function updateRoleNameMtime($data)
{
return self::where(['bid','=', $bid],['roles', 'REGEXP',$roleId])->select();
}
public static function insertData($user_perm){
return self::insert($user_perm);
return self::update($data);
}
}
......@@ -12,92 +12,8 @@ class UserInfoModel extends commonModel
public $timestamps = false;
const STATUS_WORKING = 0;
const STATUS_NOT_WORKING = 4;
public static function getUserDepartmentList()
{
return self::where([
'status' => self::STATUS_WORKING,
])->select([
'userId',
'name',
'department_id',
'department_name'
])->get();
}
// 根据用户ids,获取用户列表
public static function getUsersByIds($user_ids)
{
$res = self::whereIn('userId', $user_ids)->get();
return ($res) ? $res->toArray() : [];
}
// 根据用户email, 获取用户信息
public static function getUserByEmail($email)
{
$res = self::where('email', $email)->first();
return ($res) ? $res->toArray() : [];
}
public static function getDepartmentIdWithNameMap()
{
return self::where('department_id', '>', 0)->pluck('department_name', 'department_id');
}
public static function getUserIdWithEmail($data)
{
return self::where('position_id', $data)->select('userId', 'email')->get()->toArray();
}
public static function getUserIdNameEmailStatusMap()
{
return self::select('userId', 'name', 'email', 'status')->get();
}
public static function updateByDepartmentId($department_id, $data)
{
self::where('department_id', $department_id)->update($data);
}
public static function updateByPositionId($position_id, $data)
{
self::where('position_id', $position_id)->update($data);
}
public static function getUserIdNameStatus($id)
{
return self::where('userId', $id)->select('userId', 'name', 'status')->first();
}
public static function getUserNameEmailStatus($id)
{
$res = self::where('userId', $id)->select('name', 'email', 'status')->first();
return ($res) ? $res->toArray() : [];
}
public static function countIdByStatus($users, $status)
{
return self::whereIn('userId', $users)->where('status', '<>', $status)->count();
}
public static function getUserIdStatus($ids, $status)
{
return self::whereIn('userId', $ids)->select('userId', '<>', $status)->first();
}
public static function getIdByStatus($userId, $status)
{
return self::where('userId', $userId)->where('status', '<>', $status)->first();
}
public static function getIdByName($val)
{
return self::where('name', $val)->select('userId')->first();
}
public static function getNameWithEngNameMap($userId)
{
return self::leftJoin('user_info as t', 'user_info.superior', '=', 't.userId')
......@@ -106,9 +22,25 @@ public static function getNameWithEngNameMap($userId)
->first();
}
public static function QueryWhere( array $whereCond)
public static function getInfoById($id)
{
return self::where('userId', $id)->get();
}
public static function QueryWhere(array $whereCond)
{
return self::where($whereCond)->get();
}
public static function queryLimitOffset($whereList, $limit, $offset)
{
$query = self::where($whereList);
$count = $query->count();
$list = $query->skip($offset)->take($limit)->orderBy("userId", "desc")->get();
return [
'data'=>$list,
'total'=>$count,
];
}
}
......@@ -9,13 +9,14 @@
"license": "MIT",
"require": {
"php": "^7.4|^8.0",
"ext-json": "*",
"ext-openssl": "*",
"fruitcake/laravel-cors": "^2.0",
"guzzlehttp/guzzle": "^7.0.1",
"laravel/framework": "^8.75",
"laravel/sanctum": "^2.11",
"laravel/tinker": "^2.5",
"ext-json": "*",
"ext-openssl": "*"
"php-amqplib/php-amqplib": "^3.4"
},
"require-dev": {
"facade/ignition": "^2.5",
......
<?php
use App\Http\Controllers\UserController;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
......@@ -19,3 +20,5 @@
});
Route::post('/login',[\App\Http\Controllers\LoginController::class, 'checkLogin']);
Route::post('/update',[\App\Http\Controllers\UserController::class, 'update']);
Route::get('/user/userlist', [\App\Http\Service\UserService::class, 'getList']);
......@@ -2,6 +2,7 @@
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\UserController;
/*
|--------------------------------------------------------------------------
| Web Routes
......@@ -16,7 +17,9 @@
//Route::get('/', function () {
// return view('welcome');
//});
Route::get('/', function (){
Route::get('/', function () {
return "func";
});
Route::get('/my', [UserController::class, 'my']);//目前路由为 /my
Route::get('/userlist', [UserController::class, 'userlist']);
Route::get('/user/{id?}', [UserController::class, 'info']);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment