setName('resource_auto_recovery') ->setDescription('resource_auto_recovery to resource pool'); } protected function execute(Input $input, Output $output) { Log::close(NULL); $recovery_list = Setting::where([['name','=','auto_recovery'],['state','=',1],['content','<>',0]])->select()->toArray(); if (empty($recovery_list)) return $output->writeln("没有要执行的任务"); foreach($recovery_list as $key=>$val){ $orgids = orgSubIds($val['root_id']); $endtime = date('Y-m-d H:i:s',(time() - (int)$val['content'] * 86400)); $where[] = ['org_id','in',$orgids]; $where[] = ['crm_res_id','>',0]; $where[] = ['employee_id','>',0]; $where[] = ['employee_time','<=',$endtime]; $where[] = ['state','in',Customer::changeState('待确认','chaos')]; $cuslist = Customer::where($where)->field('id,name,crm_res_id,state')->select()->toArray(); if(!empty($cuslist)) $this->recovery_cus($cuslist); } $output->writeln("回收至资源库完成"); } /** * 处理员工需要回收的资源 */ public function recovery_cus($cuslist) { foreach($cuslist as $key=>$val){ $crm_log = CrmImportLog::where('id', $val['crm_res_id'])->find(); $left_num = $crm_log->left_num + 1; $crm_log->left_num = $left_num ? $left_num : 0; $crm_log->save(); $is_distribution = $crm_log->pid ? 1 : 0; Customer::where([['id', '=', $val['id']]])->update(['employee_id' => null, 'is_resource' => 1, 'fresh' => 1, 'employee_time'=> null ,'is_distribution' => $is_distribution,'state'=> 0]); } } }