1
0

DisableRemind.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. namespace app\command;
  3. use app\event\Msg;
  4. use app\model\Employee;
  5. use app\model\EmployeeDisableRemind;
  6. use app\model\EmployeeMsg;
  7. use app\model\Miniprogram;
  8. use app\model\Setting;
  9. use think\console\Command;
  10. use think\console\Input;
  11. use think\console\Output;
  12. class DisableRemind extends Command
  13. {
  14. protected function configure()
  15. {
  16. $this->setName('disable_remind')
  17. ->setDescription('员工禁入小程序提醒');
  18. }
  19. protected function execute(Input $input, Output $output)
  20. {
  21. $list = Setting::where('name', '=', 'disable_day')->select()->toArray();
  22. foreach ($list as $k => $v) {
  23. if (empty($v['content']) || (int)$v['content'] !== 1) {
  24. continue;
  25. }
  26. $unlimited_where = [];
  27. $unlimited_where[] = ['name', '=', 'disable_day_unlimited'];
  28. $unlimited_where[] = ['root_id', '=', $v['root_id']];
  29. $unlimited_find = Setting::where($unlimited_where)->findOrEmpty();
  30. $employee_where = [];
  31. if (!$unlimited_find->isEmpty()) {
  32. $unlimited = explode(',', $unlimited_find['content']);
  33. $employee_where[] = ['id', 'not in', $unlimited];
  34. }
  35. // 离封号不足一天
  36. $left_time = time() - 4*3600*24;
  37. $left_time_str = date('Y-m-d H:i:s', $left_time);
  38. $left_time_str_start = date('Y-m-d H:i:s', $left_time - 24*3600);
  39. $employee_where[] = ['root_id', '=', $v['root_id']];
  40. $employee_where[] = ['uid', '>', 0];
  41. $employee_where[] = ['state', '=', '在职'];
  42. $employee_where[] = ['last_login_time', 'between', [$left_time_str_start, $left_time_str]];
  43. $employee_list = Employee::where($employee_where)->column('id,official_openid,last_login_time');
  44. $need = []; //需要提醒的员工
  45. if (!empty($employee_list)) {
  46. // 不受限制的人员
  47. $unlimited_setting = Setting::where([['root_id', '=', $v['root_id']], ['name', '=', 'disable_day_unlimited']])->value('content');
  48. $unlimited_ids = !empty($unlimited_setting) ? explode(',', $unlimited_setting) : [];
  49. // 查出来的需要提醒的人员
  50. $search_remind_ids = array_column($employee_list, 'id');
  51. // 实际需要提醒的人员
  52. $remind_ids = array_diff($search_remind_ids, $unlimited_ids);
  53. $r_where = [];
  54. $r_where[] = ['last_login_time', 'between', [$left_time_str_start, $left_time_str]];
  55. $r_where[] = ['root_id', '=', $v['root_id']];
  56. $r_where[] = ['employee_id', 'in', $remind_ids];
  57. $have_remind = EmployeeDisableRemind::where($r_where)->column('employee_id');
  58. foreach ($employee_list as $e) {
  59. if (!in_array($e['id'], $have_remind)) {
  60. $need[] = $e;
  61. }
  62. }
  63. }
  64. if (empty($need)) {
  65. continue;
  66. }
  67. $remind_record = [];
  68. foreach ($need as $n) {
  69. $unlimited_day = date('Y-m-d H:i:s', strtotime($n['last_login_time']) + 24*3600*5);
  70. $msg = '您的账号将于' . $unlimited_day . '封禁,请尽快登录小程序';
  71. event(new Msg($n['id'], $msg, 'employeeDisableRemind'));
  72. $remind_record[] = [
  73. 'employee_id'=> $n['id'],
  74. 'last_login_time'=> $n['last_login_time'],
  75. 'root_id'=> $v['root_id']
  76. ];
  77. }
  78. if (!empty($remind_record)) {
  79. (new EmployeeDisableRemind())->saveAll($remind_record);
  80. }
  81. }
  82. $output->writeln("员工禁入小程序提醒完毕: " . date('Y-m-d H:i:s'));
  83. }
  84. }