setName('weworksingle_get_external_user') ->setDescription('weworksingle get external user'); } protected function execute(Input $input, Output $output) { $list = WeworksingleCompanySetting::where('corp_id', '<>', '')->select(); foreach ($list as $k => $v) { $chat_config['corp_id'] = $v['corp_id']; $chat_config['secret'] = $v['customer_secret']; $chat_config['token'] = $v['customer_token']; $chat_config['aes_key'] = $v['customer_aes_key']; $chat_config['company_id'] = $v['company_id']; if (!empty($v['customer_secret']) && !empty($v['customer_token']) && !empty($v['customer_aes_key']) && !empty($v['company_id'])) { $root_id = Company::where('id', '=', $v['company_id'])->value('root_id'); $weworksingle_user = Employee::where([['root_id', '=', $root_id], ['state', '=', '在职'], ['weworksingle_uid', '<>', 0]])->column('weworksingle_uid'); $uid = []; if (!empty($weworksingle_user)){ $weworksingle_uid = WeworksingleUser::where('id', 'in', $weworksingle_user)->column('userid'); foreach ($weworksingle_uid as $kk => $vv){ $start_time = strtotime(date('Y-m-d',strtotime('-1 day'))); $behavior = (new apiSingle($chat_config))->getUserBehaviorData([$vv], $partyid = [], $start_time, $start_time); $res = WeworksingleExternalUserRecord::where(['stat_time'=>$start_time,'userid'=>$vv,'root_id'=>$root_id])->count(); if(!$res){ $data = [ 'userid' => $vv, 'stat_time' => $behavior['stat_time'], 'new_apply_cnt' => $behavior['new_apply_cnt'], 'new_contact_cnt' => $behavior['new_contact_cnt'], 'chat_cnt' => $behavior['chat_cnt'], 'message_cnt' => $behavior['message_cnt'], 'reply_percentage' => isset($behavior['reply_percentage']) ? $behavior['reply_percentage'] : 0, 'avg_reply_time' => isset($behavior['avg_reply_time']) ? $behavior['avg_reply_time'] : 0, 'negative_feedback_cnt' => $behavior['negative_feedback_cnt'], 'root_id' => $root_id, ]; WeworksingleExternalUserRecord::create($data); } } } } } // 指令输出 $output->writeln(date('Y-m-d H:i:s', time()) . '--weworksingle_get_external_user--ok'); } }