1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- <?php
- namespace app\command;
- use app\model\Company;
- use app\model\Employee;
- use app\model\WeworksingleCompanySetting;
- use app\model\WeworksingleExternalUserRecord;
- use app\model\WeworksingleUser;
- use think\console\Command;
- use think\console\Input;
- use think\console\Output;
- use weworkapi\api\apiSingle;
- class WeworksingleGetExternalUser extends Command
- {
- protected function configure()
- {
- $this->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');
- }
- }
|