setName('droppoolremind')->setDescription('customer drop pool remind'); } protected function execute(Input $input, Output $output) { $setting_list = Setting::where('name', '=', 'pubpool')->select()->toArray(); foreach ($setting_list as $setting) { $content = !empty($setting['content']) ? json_decode($setting['content'], true) : []; if (!empty($content)) { $empty = false; //判断是否是正常数据,因为之前可能有垃圾数据 foreach ($content as $k => $v) { if (!isset($v['day']) || !isset($v['state'])) { $empty = true; } } if (!$empty) { $whereOr = []; foreach ($content as $k => $v) { if ($v['state'] == 1 && $v['day'] > 0) { $today_s = date('Y-m-d 23:59:59', strtotime('yesterday')); $today_e = date('Y-m-d 00:00:00', strtotime('tomorrow')); $whereOr[] = [ ['state', 'in', Customer::changeState($k, 'chaos')], ['protected_to', 'between', [$today_s, $today_e]], ]; } } if (!empty($whereOr)) { $root_id = $setting['root_id']; $org_ids = orgSubIds($root_id); $manager = Employee::where([['root_id', '=', $root_id], ['is_manager', '=', 1]])->column('id,org_id'); $customers = Customer::where([['org_id', 'in', $org_ids]])->where(function ($query) use ($whereOr) { $query->whereOr($whereOr); })->field('count(id) as count_id,org_id')->group('org_id')->select()->toArray(); $customers_arr = array_column($customers, 'count_id', 'org_id'); foreach ($manager as $k => $v) { $count = 0; if (isset($customers_arr[$v['org_id']])) { $count = $customers_arr[$v['org_id']]; } $msg = '今天待回收客户' . $count .'个'; if ($count) { event(new Msg($v['id'], $msg, 'willDropCustomer', json_encode(date('Y-m-d')))); } } } } } } $output->writeln("true"); } }