tp3.2 批量插入

$serverInfo = json_decode($_POST['serverinfo']);
$gameModel = D("Admin/Game");
$serverInfoModel = M('serverinfo', 'cy_');
$dataList = [];

$failGameId = [];//不存在的gameId
foreach ($serverInfo as $info) {
	$gameId = $info[0];
	$gameName = $gameModel->getGameName($gameId);
	if ($info[0] == 1) {
		continue;
	}
	if (empty($gameName)) { //过滤不存在的游戏
		$failGameId[]= $gameId;
		continue;
	}
	$data['gameid'] = $gameId;
	$data['sername'] = $info[1];
	$data['sertime'] = strtotime(gmdate('Y-m-d H:i', \PHPExcel_Shared_Date::ExcelToPHP($info[2])));
	$data['order'] = $info[3];
	$dataList[] = $data;
}

// 批量添加数据
$insertInfo = $serverInfoModel->addAll($dataList);

你可能感兴趣的:(tp3.2)