<?php
/**
 * Created by PhpStorm.
 * User: stanley-king
 * Date: 2017/11/9
 * Time: 下午5:19
 */

define('BASE_ROOT_PATH',str_replace('/test','',dirname(__FILE__)));

require_once(BASE_ROOT_PATH . '/fooder.php');
require_once(BASE_ROOT_PATH . '/helper/search/tcp_client.php');
require_once(BASE_ROOT_PATH . '/helper/message/publisher.php');

class TestCommand extends PHPUnit_Framework_TestCase
{
    public static function setUpBeforeClass()
    {
        Base::run_util();
    }

    public function testInit_reward()
    {
        $mod_member = Model('member');
        $i = 0;
        while (true)
        {
            $start = $i * 1000;
            $items = $mod_member->field('member_id')->order('member_id asc')->limit("{$start},1000")->select();
            if(empty($items)) {
                return;
            }
            $i++;

            foreach ($items as $item)
            {
                $user = intval($item['member_id']);
                if($user <= 0) continue;

                $val = $mod_member->field('count(*) inviter_count' )->where(['inviter_id' => $user])->select();
                $invitees = intval($val[0]['inviter_count']);
                if($invitees <= 0) continue;

                $ret = $mod_member->editMember(['member_id' => $user],['invitees' => $invitees,'reward_amount' => $invitees * 30]);
                if($ret == false) {
                    Log::record("update member_id = {$user} invitees and reward",Log::ERR);
                }
            }
        }
    }
}
