<?php

/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
namespace app\crm\command;
use think\console\Command;
use think\console\Input;
use think\console\Output;

class Runlogdata extends Command{

    protected function configure()
    {
        $this->setName('runlogdata')->setDescription('Suxuan system service: logdata statistics');
    }
    
    protected function execute(Input $input, Output $output)
    {
        $mc = new \app\common\lib\mcInterface();
        $data = $mc->cacheData('5ef1a04c80175');
        if($data){
            $mcproductId = $data['product_id'];
        }
        if(!$mcproductId){
            die('can\'t read mc product id.');
        }
        $max = db('action_log','db_logs')->order('id desc')->find();
        $maxId = $max['id'];
        while (1){
            $logs = db('action_log','db_logs')->where('id','>',$maxId)->order('id asc')->select();
            foreach ($logs as $k => $v) {
                $logs[$k]['mc_product_id'] = $mcproductId;
                $maxId = $v['id'];
            }
            $res = http_request('http://61crm.c.suxuantech.cn/index/logdata/receive', 'POST',json_encode($logs));
            // var_dump($res['response']);
            sleep(5);
        }
        
    }

}