<?php
namespace app\index\controller;
use think\Controller;
/**
 * 
 */
class Logdata  extends Controller
{
	
	function receive()
	{
		$data = file_get_contents('php://input');
		$listName = 'tmp_log_list';
		if($data){
			$data = json_decode($data,true);
			$i = 0;
			foreach ($data as $key => $value) {
				$i++;
				// $listName = $listNamePre.'_'.$value['mc_product_id'];
				\app\common\lib\redisQueue::init()->rPush($listName, $value);
				// var_dump($s);
			}
			echo 'Insert '.$i.' datas.';
		}else{
			echo 'No any data inserted.';
		}
	}
	function view(){
		if(request()->isAjax()){
			$msgId = input('msg_id');
			$productId = input('product_id');
			$listName = 'tmp_log_list';
			$count = \app\common\lib\redisQueue::init()->getInstance()->llen($listName);
			if(!$msgId && $count > 0){
				$i=0;
				while ($i < $count) {
					$i++;
					\app\common\lib\redisQueue::init()->blPop($listName);
				}
			}
			$msgId++;
			$res = \app\common\lib\redisQueue::init()->blPop($listName);
			if($res[1] && is_string($res[1])){
				$msg = json_decode($res[1],true);
			}
			if($msg['mc_product_id'] == $productId){
				$data = '操作时间：'.$msg['create_time'].'；操作模块：'.$msg['module'].'；操作方法：'.$msg['controller'].'；操作数据：'.$msg['old_data'];
			}else{
				$data = '';
			}
			return ['code'=>200,'msg_id'=>$msgId,'data'=>$data];
			
		}
		return $this->fetch();
	}
}