123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- <?php
- namespace app\command;
- use app\event\Msg;
- use think\console\Command;
- use think\console\input\Argument;
- use think\console\Input;
- use think\console\Output;
- use app\model\Customer;
- use app\model\Employee;
- use app\model\Setting;
- class DropPoolRemind extends Command
- {
- protected function configure()
- {
- $this->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");
- }
- }
|