123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- <?php
- namespace app\command;
- use app\event\Msg;
- use app\model\Employee;
- use app\model\EmployeeDisableRemind;
- use app\model\EmployeeMsg;
- use app\model\Miniprogram;
- use app\model\Setting;
- use think\console\Command;
- use think\console\Input;
- use think\console\Output;
- class DisableRemind extends Command
- {
- protected function configure()
- {
- $this->setName('disable_remind')
- ->setDescription('员工禁入小程序提醒');
- }
- protected function execute(Input $input, Output $output)
- {
- $list = Setting::where('name', '=', 'disable_day')->select()->toArray();
- foreach ($list as $k => $v) {
- if (empty($v['content']) || (int)$v['content'] !== 1) {
- continue;
- }
- $unlimited_where = [];
- $unlimited_where[] = ['name', '=', 'disable_day_unlimited'];
- $unlimited_where[] = ['root_id', '=', $v['root_id']];
- $unlimited_find = Setting::where($unlimited_where)->findOrEmpty();
- $employee_where = [];
- if (!$unlimited_find->isEmpty()) {
- $unlimited = explode(',', $unlimited_find['content']);
- $employee_where[] = ['id', 'not in', $unlimited];
- }
- // 离封号不足一天
- $left_time = time() - 4*3600*24;
- $left_time_str = date('Y-m-d H:i:s', $left_time);
- $left_time_str_start = date('Y-m-d H:i:s', $left_time - 24*3600);
- $employee_where[] = ['root_id', '=', $v['root_id']];
- $employee_where[] = ['uid', '>', 0];
- $employee_where[] = ['state', '=', '在职'];
- $employee_where[] = ['last_login_time', 'between', [$left_time_str_start, $left_time_str]];
- $employee_list = Employee::where($employee_where)->column('id,official_openid,last_login_time');
- $need = []; //需要提醒的员工
- if (!empty($employee_list)) {
- // 不受限制的人员
- $unlimited_setting = Setting::where([['root_id', '=', $v['root_id']], ['name', '=', 'disable_day_unlimited']])->value('content');
- $unlimited_ids = !empty($unlimited_setting) ? explode(',', $unlimited_setting) : [];
- // 查出来的需要提醒的人员
- $search_remind_ids = array_column($employee_list, 'id');
- // 实际需要提醒的人员
- $remind_ids = array_diff($search_remind_ids, $unlimited_ids);
- $r_where = [];
- $r_where[] = ['last_login_time', 'between', [$left_time_str_start, $left_time_str]];
- $r_where[] = ['root_id', '=', $v['root_id']];
- $r_where[] = ['employee_id', 'in', $remind_ids];
- $have_remind = EmployeeDisableRemind::where($r_where)->column('employee_id');
- foreach ($employee_list as $e) {
- if (!in_array($e['id'], $have_remind)) {
- $need[] = $e;
- }
- }
- }
- if (empty($need)) {
- continue;
- }
- $remind_record = [];
- foreach ($need as $n) {
- $unlimited_day = date('Y-m-d H:i:s', strtotime($n['last_login_time']) + 24*3600*5);
- $msg = '您的账号将于' . $unlimited_day . '封禁,请尽快登录小程序';
- event(new Msg($n['id'], $msg, 'employeeDisableRemind'));
- $remind_record[] = [
- 'employee_id'=> $n['id'],
- 'last_login_time'=> $n['last_login_time'],
- 'root_id'=> $v['root_id']
- ];
- }
- if (!empty($remind_record)) {
- (new EmployeeDisableRemind())->saveAll($remind_record);
- }
- }
- $output->writeln("员工禁入小程序提醒完毕: " . date('Y-m-d H:i:s'));
- }
- }
|