123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- <?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;
- /**
- * 定时拉取群聊统计数据
- * 拉取时间为每天晚上12点之前
- * Class WeworksingleGetGroupStatistic
- * @package app\command
- */
- class WeworksingleGetGroupStatistic extends Command
- {
- protected function configure()
- {
- $this->setName('weworksingle_get_group_statistic')
- ->setDescription('weworksingle get group statistic');
- }
- protected function execute(Input $input, Output $output)
- {
- $list = WeworksingleCompanySetting::where('corp_id', '<>', '')->select();
- foreach ($list as $k => $v) {
- $save_data = [];
- $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');
- if (!empty($weworksingle_user)){
- $weworksingle_uid = WeworksingleUser::where('id', 'in', $weworksingle_user)->column('userid');
- foreach ($weworksingle_uid as $kk => $vv){
- $param = [
- 'day_begin_time'=> strtotime(date('Y-m-d', time())),
- 'day_end_time'=> strtotime(date('Y-m-d', time())),
- 'owner_filter'=> [
- 'userid_list'=> $vv
- ],
- 'offset'=> 0,
- 'limit'=> 1000
- ];
- $data = (new apiSingle($chat_config))->getGroupChatStatistic($param);
- $save_data[] = [
- 'owner'=> $vv,
- 'data'=> $data,
- 'root_id'=> $root_id
- ];
- }
- }
- }
- if (!empty($save_data)){
- (new WeworksingleExternalUserRecord())->saveAll($save_data);
- }
- }
- // 指令输出
- $output->writeln(date('Y-m-d H:i:s', time()) . '--weworksingle_get_group_statistic--ok');
- }
- }
|