bourse stock
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
2.5 KiB

<?php
namespace app\model;
use think\Env;
class AdminModel extends BaseModel
{
protected $name = 'account';
const STATUS_ON = 1; // 用户启用状态
const STATUS_FORBID = 2; // 用户禁用状态
// 通过代理id 获取代理下面可以访问的所有用户id
public static function getUserIdsByAgentId($agentId)
{
// 查询直接被管理的用户
$firstUserIds = UserModel::where('agent_id', $agentId)->column('user_id');
if(empty($firstUserIds)){
return [];
}
// 查询父级下面的用户
$userIds = UserModel::where('origin_user_id','in',$firstUserIds)->column('user_id');
return array_merge($firstUserIds, $userIds);
// return UserModel::where('origin_user_id','in',$firstUserIds)->column('user_id');
}
// 判断操作用户是否是代理商
public static function checkUserIsAgent($adminId)
{
// 代理角色
$roleId = 10;
$admin = self::where('id', $adminId)->find();
if($admin && $admin['role_id'] == $roleId){
return true;
}
return false;
// $agentGroupId = env('AGENT.AGENT_GROUP_ID');
// $authGroupAccess = AuthGroupAccessModel::where('uid', $adminId)->find();
// if($authGroupAccess && $authGroupAccess['group_id'] == $agentGroupId){
// return true;
// }
// return false;
}
/**
* @desc 根据用户id 查询指定字段
* @param $fields
* @param $userId
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public static function getFieldsByUserId($fields, $userId): array
{
$self = self::where('id', $userId)->field($fields)->find();
if(empty($self)){
return [];
}
return $self->toArray();
}
/**
* @desc 获取邀请码用户
* @param $inviteCode
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public static function getIdByInviteCode($inviteCode): int
{
$self = self::where('invite_code', $inviteCode)->value('id');
if(empty($self)){
return 0;
}
return $self;
}
public static function getCustomerIdsByAgentId($agentId): array
{
return self::where('parent_id', $agentId)->column('id');
}
}