building-sign/app/model/Account.php

93 lines
2.7 KiB
PHP
Raw Normal View History

2023-01-09 08:41:41 +00:00
<?php
namespace app\model;
use think\model\relation\BelongsToMany;
use think\model\relation\HasMany;
class Account extends Base
{
public const ROLE_NORMAL = '0';//普通用户
public const ROLE_WORKER = '1';//工人
public const ROLE_MANAGER = '2';//负责人
public const STATUS_NORMAL = 'normal'; //正常
public const STATUS_DISABLE = 'disable';//禁用
public const GENDER_UNDEFINED = 0; // 未知
public const GENDER_MALE = 1; // 男性
public const GENDER_FEMALE = 2; // 女性
// 生成个人补充信息:邀请码、用户编号
public static function onAfterInsert($item)
{
$item->invite_code = md5($item->id, false);
$item->coding = date('y').str_pad((string) $item->id, 10, '0', STR_PAD_LEFT);
$item->save();
}
public static function roleText(): array
{
return [
self::ROLE_NORMAL => '普通用户',
self::ROLE_WORKER => '工人',
self::ROLE_MANAGER => '工地负责人',
];
}
public static function checkingText(): array
{
return [
0 => '正常',
1 => '资料审核中',
];
}
public static function genderText(): array
{
return [
self::GENDER_UNDEFINED => '保密',
self::GENDER_MALE => '男',
self::GENDER_FEMALE => '女',
];
}
// 获取用户信息 (包含待审核信息)
public static function getUser(int $accountId): array
{
$user = self::alias('a')
->leftJoin('position p', 'a.position = p.id')
->where('a.id', $accountId)
->field('a.*,p.name as position_name')
->find();
if (empty($user)) {
return [];
}
$user->headimgurl = resourceJoin($user->headimgurl, request()->domain());
$user['check_info'] = [];//待审核对比信息
if ($user->checking == self::COMMON_ON || $user->role == self::ROLE_WORKER) {
$user['check_info'] = CheckLog::getCheckInfo($accountId);
}
$user = $user->toArray();
unset($user['sex']);
unset($user['unionid']);
unset($user['last_login']);
unset($user['login_ip']);
unset($user['remarks']);
unset($user['remarks']);
return arrayNullToString($user);
}
// 工人-需要审核的字段
public static function needCheckFields(): array
{
return [
'real_name', 'mobile', 'position', 'pay', 'emergency_contact', 'emergency_phone', 'bank_card_name', 'bank_card_number',
'bank_name', 'card_number', 'bank_card_img', 'id_front', 'id_back', 'certificate'
2023-01-09 08:41:41 +00:00
];
}
}