<?php
/**
 * CorrectMemCnt.php  UTF-8
 * 玩家风险数据
 *
 * @date    : 2018/10/24 10:37
 *
 * @license 这不是一个自由软件,未经授权不许任何使用和传播。
 * @author  : chenbingling <cbl@huosdk.com>
 * @version : HuoMap 1.0
 */

namespace console\index\controller;

use huo\controller\agent\AgentCache;
use huo\model\member\MemberModel;
use huo\model\user\UserModel;
use think\console\Command;
use think\console\Input;
use think\console\Output;

class CorrectMemCnt extends Command {
    protected function configure() {
        $this->setName('correct_mem_cnt')->setDescription('玩家邀请数量修正');
    }

    protected function execute(Input $input, Output $output) {
        set_time_limit(0);
        $_member_model = new MemberModel();
        $_user_model = new UserModel();
        $_agent_cache = AgentCache::ins();
        $_member_model->chunk(
            10, function ($members) use ($_member_model, $_user_model, $_agent_cache) {
            foreach ($members as $member) {
                /* 数据报表 */
                $_agent_id = $_user_model->getIdByMemId($member['id']);
                if (empty($_agent_id)) {
                    continue;
                }
                $_user_cnt = $_member_model->where(['parent_mem_id' => $member['id']])->count('id');
                if (false != $_user_cnt) {
                    $ae_data['reg_cnt'] = $_user_cnt;
                    $_agent_cache->updateAgentExt($_agent_id, $ae_data, true);
                }
            }
        }
        );
    }
}