update
This commit is contained in:
64
inc/Hura8/Components/Staff/Model/StaffAuthModel.php
Normal file
64
inc/Hura8/Components/Staff/Model/StaffAuthModel.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
namespace Hura8\Components\Staff\Model;
|
||||
|
||||
use Hura8\System\Model\AuthModel;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class StaffAuthModel extends AuthModel
|
||||
{
|
||||
|
||||
private $tb_staff_login = "tb_staff_login";
|
||||
private $tb_staff_access_code = "tb_staff_access_code";
|
||||
|
||||
private $tb_staff_login_log = "tb_staff_login_log";
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct($this->tb_staff_login, $this->tb_staff_access_code);
|
||||
}
|
||||
|
||||
|
||||
public function getLoginListByIds(array $staff_ids) {
|
||||
if(!sizeof($staff_ids)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
list($parameterized_ids, $bind_types) = create_bind_sql_parameter_from_value_list($staff_ids, 'int');
|
||||
|
||||
$bind_values = $staff_ids;
|
||||
|
||||
$query = $this->db->runQuery(
|
||||
"SELECT `user_id`, `last_login_time`, `last_login_ip`, `last_login_device`, `last_login_browser`
|
||||
FROM ".$this->tb_staff_login."
|
||||
WHERE `user_id` IN (".$parameterized_ids.") ",
|
||||
$bind_types,
|
||||
$bind_values
|
||||
);
|
||||
|
||||
$item_list = [];
|
||||
foreach ($this->db->fetchAll($query) as $item) {
|
||||
$item_list[$item['user_id']] = $item;
|
||||
}
|
||||
|
||||
return $item_list;
|
||||
}
|
||||
|
||||
|
||||
public function getLoginLog(array $conditions = []) {
|
||||
$bind_types = [];
|
||||
$bind_values = [];
|
||||
|
||||
$query = $this->db->runQuery(
|
||||
"SELECT * FROM ".$this->tb_staff_login_log." WHERE 1 ORDER BY `id` DESC LIMIT 100 ",
|
||||
$bind_types,
|
||||
$bind_values
|
||||
);
|
||||
|
||||
return $this->db->fetchAll($query) ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
40
inc/Hura8/Components/Staff/Model/StaffDepartmentModel.php
Normal file
40
inc/Hura8/Components/Staff/Model/StaffDepartmentModel.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace Hura8\Components\Staff\Model;
|
||||
|
||||
use Hura8\Interfaces\AppResponse;
|
||||
use Hura8\System\Model\aEntityBaseModel;
|
||||
|
||||
|
||||
class StaffDepartmentModel extends aEntityBaseModel
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct('department');
|
||||
}
|
||||
|
||||
|
||||
protected function extendedFilterOptions() : array
|
||||
{
|
||||
return [
|
||||
// empty for now
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
protected function _buildQueryConditionExtend(array $filter_condition) : ?array
|
||||
{
|
||||
$where_clause = "";
|
||||
$bind_types = [];
|
||||
$bind_values = [];
|
||||
|
||||
return [
|
||||
$where_clause,
|
||||
$bind_types,
|
||||
$bind_values
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace Hura8\Components\Staff\Model;
|
||||
|
||||
class StaffDepartmentPermissionModel
|
||||
{
|
||||
protected $objStaffDepartmentModel;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->objStaffDepartmentModel = new StaffDepartmentModel();
|
||||
}
|
||||
|
||||
|
||||
public function getDepartmentMenuPermission($department_id) {
|
||||
$_info = $this->objStaffDepartmentModel->getInfo($department_id);
|
||||
|
||||
return ($_info['menu_permission']) ? \json_decode($_info['menu_permission'], true) : [];
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function getDepartmentEntityPermission($department_id) {
|
||||
$_info = $this->objStaffDepartmentModel->getInfo($department_id);
|
||||
|
||||
return ($_info['entity_permission']) ? \json_decode($_info['entity_permission'], true) : [];
|
||||
}
|
||||
|
||||
}
|
||||
38
inc/Hura8/Components/Staff/Model/StaffLogModel.php
Normal file
38
inc/Hura8/Components/Staff/Model/StaffLogModel.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace Hura8\Components\Staff\Model;
|
||||
|
||||
use Hura8\Interfaces\AppResponse;
|
||||
use Hura8\System\Model\aEntityBaseModel;
|
||||
|
||||
class StaffLogModel extends aEntityBaseModel
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct('staff_log');
|
||||
}
|
||||
|
||||
|
||||
protected function extendedFilterOptions() : array
|
||||
{
|
||||
return [
|
||||
// empty for now
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
protected function _buildQueryConditionExtend(array $condition) : ?array
|
||||
{
|
||||
$where_clause = "";
|
||||
$bind_types = [];
|
||||
$bind_values = [];
|
||||
|
||||
return [
|
||||
$where_clause,
|
||||
$bind_types,
|
||||
$bind_values
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
58
inc/Hura8/Components/Staff/Model/StaffModel.php
Normal file
58
inc/Hura8/Components/Staff/Model/StaffModel.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace Hura8\Components\Staff\Model;
|
||||
|
||||
use Hura8\Interfaces\AppResponse;
|
||||
use Hura8\System\Model\aEntityBaseModel;
|
||||
use Hura8\System\Security\DataValidator;
|
||||
|
||||
class StaffModel extends aEntityBaseModel
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct('staff');
|
||||
$this->tb_staff = $this->tb_entity;
|
||||
}
|
||||
|
||||
|
||||
protected function extendedFilterOptions() : array
|
||||
{
|
||||
return [
|
||||
// empty for now
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
public function getInfoByEmail($email) : ?array
|
||||
{
|
||||
$query = $this->db->runQuery("SELECT * FROM `".$this->tb_entity."` WHERE `email` = ? LIMIT 1 ", ['s'], [$email]) ;
|
||||
if( $item_info = $this->db->fetchAssoc($query)){
|
||||
return $this->formatItemInfo($item_info);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
protected function _buildQueryConditionExtend(array $condition) : ?array
|
||||
{
|
||||
/*$condition = array(
|
||||
"letter" => "",
|
||||
);*/
|
||||
|
||||
$catCondition = [];
|
||||
$bind_types = [];
|
||||
$bind_values = [];
|
||||
|
||||
|
||||
if(isset($filter_condition["letter"]) && strlen($filter_condition["letter"]) == 1){
|
||||
$catCondition[] = " AND `letter` = ? ";
|
||||
$bind_types[] = 's';
|
||||
$bind_values[] = $filter_condition["letter"];
|
||||
}
|
||||
|
||||
return array( join(" ", $catCondition), $bind_types, $bind_values);
|
||||
}
|
||||
|
||||
}
|
||||
67
inc/Hura8/Components/Staff/Model/StaffPermissionModel.php
Normal file
67
inc/Hura8/Components/Staff/Model/StaffPermissionModel.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
namespace Hura8\Components\Staff\Model;
|
||||
|
||||
|
||||
class StaffPermissionModel
|
||||
{
|
||||
|
||||
protected $objStaffModel;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->objStaffModel = new StaffModel();
|
||||
}
|
||||
|
||||
|
||||
public function getUserEntityPermission($admin_id) {
|
||||
|
||||
/*return [
|
||||
// entity group => entity
|
||||
'product' => [
|
||||
'item' => [
|
||||
'view' => true,
|
||||
'create' => false,
|
||||
'delete' => true,
|
||||
'update' => false,
|
||||
],
|
||||
],
|
||||
|
||||
'article' => [
|
||||
'item' => [
|
||||
'view' => true,
|
||||
'create' => false,
|
||||
'delete' => false,
|
||||
'update' => true,
|
||||
],
|
||||
]
|
||||
];*/
|
||||
|
||||
$admin_info = $this->objStaffModel->getInfo($admin_id);
|
||||
|
||||
if($admin_info['entity_permission']) {
|
||||
$entity_permission = \json_decode($admin_info['entity_permission'], true);
|
||||
|
||||
if(sizeof($entity_permission) > 0) {
|
||||
return $entity_permission;
|
||||
}
|
||||
}
|
||||
|
||||
// else use department
|
||||
if($admin_info['department']) {
|
||||
$objStaffDepartmentPermissionModel = new StaffDepartmentPermissionModel();
|
||||
$department_entity_permission = $objStaffDepartmentPermissionModel->getDepartmentEntityPermission($admin_info['department']);
|
||||
|
||||
return $department_entity_permission;
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
|
||||
public function getUserMenuPermission($admin_id) {
|
||||
$admin_info = $this->objStaffModel->getInfo($admin_id);
|
||||
return ($admin_info['menu_permission']) ? \json_decode($admin_info['menu_permission'], true) : [];
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user