c1
This commit is contained in:
40
www/first.loc/api/Class/DataForms.php
Normal file
40
www/first.loc/api/Class/DataForms.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
class DataForms{
|
||||
|
||||
public function __construct($db)
|
||||
{
|
||||
$this->conn = $db;
|
||||
}
|
||||
|
||||
function to_UTF8($arr) {
|
||||
foreach($arr as $k=>$v){
|
||||
$v=iconv('Windows-1251','UTF-8',$v);
|
||||
$arr[$k]=$v;
|
||||
}
|
||||
return $arr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function Query()
|
||||
{
|
||||
|
||||
$result=[
|
||||
1,2,3
|
||||
];
|
||||
|
||||
|
||||
|
||||
return $result;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
36
www/first.loc/api/Class/Database.php
Normal file
36
www/first.loc/api/Class/Database.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
// Используем для подключения к базе данных MySQL
|
||||
class Database
|
||||
{
|
||||
// Учётные данные базы данных
|
||||
# private $host = "10.10.1.246";
|
||||
# public $db_name = "tsd_main";
|
||||
# private $username = "tsd";
|
||||
#private $password = "gcIL6UrWFtSdDTbz";
|
||||
|
||||
|
||||
private $host = "10.10.0.20";
|
||||
public $db_name = "tsd";
|
||||
private $username = "tsd_user";
|
||||
private $password = "stptoamh";
|
||||
|
||||
|
||||
|
||||
|
||||
public $conn;
|
||||
|
||||
// Получаем соединение с базой данных
|
||||
public function getConnection()
|
||||
{
|
||||
$this->conn = null;
|
||||
|
||||
try {
|
||||
$this->conn = new PDO("pgsql:host=".$this->host.";port=5432;dbname=".$this->db_name, $this->username, $this->password);
|
||||
//$this->conn = new PDO("mysql:host=" . $this->host . ";dbname=" . $this->db_name.";charset=UTF8", $this->username, $this->password);
|
||||
} catch (PDOException $exception) {
|
||||
echo "Ошибка соединения с БД: " . $exception->getMessage();
|
||||
}
|
||||
|
||||
return $this->conn;
|
||||
}
|
||||
}
|
||||
28
www/first.loc/api/Class/DatabaseMS.php
Normal file
28
www/first.loc/api/Class/DatabaseMS.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
|
||||
// Используем для подключения к базе данных MySQL
|
||||
class DatabaseMS
|
||||
{
|
||||
// Учётные данные базы данных
|
||||
private $host = "omega-server";
|
||||
public $db_name = "SKL_BLOKSQL";
|
||||
private $username = "sa";
|
||||
private $password = "haqdvega#";
|
||||
public $conn;
|
||||
|
||||
// Получаем соединение с базой данных
|
||||
public function getConnection()
|
||||
{
|
||||
$this->conn = null;
|
||||
|
||||
try {
|
||||
$this->conn = new PDO("dblib:host=" . $this->host . ";dbname=" . $this->db_name.";charset=CP1251", $this->username, $this->password);
|
||||
} catch (PDOException $exception) {
|
||||
echo "Ошибка соединения с БД: " . $exception->getMessage();
|
||||
}
|
||||
|
||||
return $this->conn;
|
||||
}
|
||||
}
|
||||
|
||||
31
www/first.loc/api/Class/DatabasePGSQL.php
Normal file
31
www/first.loc/api/Class/DatabasePGSQL.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
// Используем для подключения к базе данных MySQL
|
||||
class Database
|
||||
{
|
||||
// Учётные данные базы данных
|
||||
//private $host = "localhost:3308";
|
||||
private $host = "10.10.1.246";
|
||||
//public $db_name = "authentication_jwt";
|
||||
//private $username = "tsd_user";
|
||||
private $username = "tsd";
|
||||
//private $password = "Dfrgvm3@1";
|
||||
private $password = "gcIL6UrWFtSdDTbz";
|
||||
|
||||
|
||||
public $conn;
|
||||
|
||||
// Получаем соединение с базой данных
|
||||
public function getConnection()
|
||||
{
|
||||
$this->conn = null;
|
||||
|
||||
try {
|
||||
$this->conn = new PDO("pgsql:host=".$this->host.";port=5432;dbname=".$this->db_name, $this->username, $this->password);
|
||||
//$this->conn = new PDO("mysql:host=" . $this->host . ";dbname=" . $this->db_name.";charset=UTF8", $this->username, $this->password);
|
||||
} catch (PDOException $exception) {
|
||||
echo "Ошибка соединения с БД: " . $exception->getMessage();
|
||||
}
|
||||
|
||||
return $this->conn;
|
||||
}
|
||||
}
|
||||
340
www/first.loc/api/Class/MainClass.php
Normal file
340
www/first.loc/api/Class/MainClass.php
Normal file
@@ -0,0 +1,340 @@
|
||||
<?php
|
||||
#[AllowDynamicProperties]
|
||||
|
||||
Class MainClass {
|
||||
|
||||
private $headers = Array("Authorization: fi9tzpIHgp84E1Pf45rMzR/hy8lA2zE5", 'Content-Type: "application/json"');
|
||||
protected object $conn;
|
||||
|
||||
public function __construct($db)
|
||||
{
|
||||
$this->conn = $db;
|
||||
}
|
||||
|
||||
|
||||
function WrFile($param){
|
||||
//запись в файл. Не понятно зачем, но пока оставил
|
||||
|
||||
|
||||
$path='/var/www/tmp';
|
||||
$file_name=$param['date_query'].'.json';
|
||||
if(!file_exists($path)){
|
||||
mkdir($path);
|
||||
chmod ( $path, 0777 );
|
||||
}
|
||||
$path=$path.'/beru';
|
||||
|
||||
if(!file_exists($path)){
|
||||
mkdir($path);
|
||||
chmod ( $path, 0777 );
|
||||
}
|
||||
|
||||
if(file_exists($path.'/'.$file_name)){
|
||||
unlink($path.'/'.$file_name);
|
||||
}
|
||||
file_put_contents($path.'/'.$file_name, $param['data_json']);
|
||||
|
||||
|
||||
|
||||
}
|
||||
function getSSLPage($url,$post_data,$headers) {
|
||||
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_HEADER, false);
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER,$headers );
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
if(strlen(trim($post_data))>0){
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
|
||||
}
|
||||
curl_setopt ( $ch , CURLOPT_SSL_VERIFYPEER, 0 );
|
||||
curl_setopt ( $ch , CURLOPT_SSL_VERIFYHOST, 0 );
|
||||
//$http_code=curl_getinfo($ch,CURLINFO_RESPONSE_CODE);
|
||||
$output = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
||||
function wrDatabase($param){
|
||||
|
||||
/*
|
||||
$param=[
|
||||
`'date_query' => $date_query,
|
||||
'data_json' => $data_json,
|
||||
'db'=> $db,
|
||||
'user'= $user
|
||||
];`
|
||||
*/
|
||||
|
||||
$opers=json_decode($param['data_json'],true);
|
||||
|
||||
try{
|
||||
|
||||
//echo json_encode($opereturnrs);
|
||||
//die('stop');
|
||||
|
||||
$user=$param['user'];
|
||||
$date_query=$param['date_query'];
|
||||
$firma=$param['kag']['firma'];
|
||||
|
||||
for($i=0;$i<count($opers);$i++){
|
||||
|
||||
$item=$opers[$i];
|
||||
$vars=[
|
||||
'idoper'=>$item['id'],
|
||||
'data_json' => json_encode($item),
|
||||
'user'=>$user,
|
||||
'date_d'=>date('Y-m-d H:i:s'),
|
||||
'date_query'=>$date_query,
|
||||
'firma'=>$firma,
|
||||
|
||||
];
|
||||
|
||||
$this->conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
$this->conn->beginTransaction();
|
||||
|
||||
//удалить предыдущие загрузки по дате загрузки и номеру акта
|
||||
|
||||
$sth = $this->conn->prepare("delete from oper where idoper=:id and firma=:firma and date_query=:date_query");
|
||||
$sth->execute([
|
||||
'id'=>$item['id'],
|
||||
'firma'=>$firma,
|
||||
'date_query'=>$date_query,
|
||||
]);
|
||||
|
||||
$query="insert into oper
|
||||
(idoper,firma, data_json,date_d,\"user\",date_query)
|
||||
values
|
||||
(:idoper,:firma, :data_json,:date_d,:user,:date_query)";
|
||||
$stmt = $this->conn->prepare($query);
|
||||
|
||||
$stmt->execute($vars);
|
||||
|
||||
$error=$stmt->errorCode();
|
||||
$ids=$this->conn->lastInsertId();
|
||||
$this->conn->commit();
|
||||
|
||||
//idoper == >
|
||||
$ids_arr[$item['id']]=$ids;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
$result= ['result'=>1,'result'=>$ids_arr];
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}catch (Exception $e) {
|
||||
|
||||
$this->conn->rollBack();
|
||||
$error = "Ошибка: " . $e->getMessage();
|
||||
$result = ['result'=>0,'error'=>$error];
|
||||
}
|
||||
|
||||
return $result;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
function DataCollect($param){
|
||||
//результаты сканирования актов
|
||||
|
||||
$result=[];
|
||||
|
||||
$query = "select
|
||||
id,
|
||||
barcode,
|
||||
date_up
|
||||
from oper_collect
|
||||
where idoper=:id and firma=:firma ORDER BY date_up";
|
||||
$stmt = $this->conn->prepare($query);
|
||||
$vars['id'] = $param['idoper'];
|
||||
$vars['firma'] = $param['kag']['firma'];
|
||||
$stmt->execute($vars);
|
||||
$error = $stmt->errorCode();
|
||||
|
||||
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
|
||||
$result[] = $row;
|
||||
}
|
||||
|
||||
|
||||
return ['idoper'=>$param['idoper'] ,'collect'=>$result,'v'=>$vars];
|
||||
}
|
||||
|
||||
|
||||
function History($param){
|
||||
|
||||
$limit=$param['limit'];
|
||||
$kag=$param['kag'];
|
||||
|
||||
$vars=[
|
||||
'firma'=>$param['kag']['firma'],
|
||||
|
||||
];
|
||||
|
||||
$query = "select
|
||||
id,
|
||||
idoper,
|
||||
date_query,
|
||||
to_char(date_query,'DD.MM.YY') as date_q,
|
||||
data_json
|
||||
from oper
|
||||
where firma=:firma
|
||||
ORDER BY date_query DESC, id DESC
|
||||
limit 10
|
||||
";
|
||||
$stmt = $this->conn->prepare($query);
|
||||
$stmt->execute($vars);
|
||||
$error = $stmt->errorCode();
|
||||
|
||||
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
|
||||
$row['data_json']=json_decode($row['data_json'],true);
|
||||
$row['data_collect']=$this->DataCollect(['idoper'=>$row['idoper'],'kag'=>$param['kag']]);
|
||||
$row['param']=$param;
|
||||
$result[] = $row;
|
||||
}
|
||||
|
||||
|
||||
return ['data'=>$result];
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
function pushCollect($data){
|
||||
//записать данные по сборке
|
||||
|
||||
try{
|
||||
|
||||
|
||||
|
||||
|
||||
//--Повтор------------>
|
||||
$query = "select
|
||||
id
|
||||
from oper_collect
|
||||
where idoper=:id and firma=:firma and (barcode=:barcode OR barcode_json like '%".$data['barcode']."%') ORDER BY date_up";
|
||||
$stmt = $this->conn->prepare($query);
|
||||
$vars['id'] = $data['idoper'];
|
||||
$vars['firma'] = $data['kag']['firma'];
|
||||
$vars['barcode'] = $data['barcode'];
|
||||
|
||||
$stmt->execute($vars);
|
||||
$error = $stmt->errorCode();
|
||||
|
||||
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
|
||||
$result_b[] = $row;
|
||||
}
|
||||
// if(!$result_b){
|
||||
// $result = ['result'=>0,'error'=>$error,'rrr'=>$vars];
|
||||
// return $result;
|
||||
// }
|
||||
|
||||
|
||||
if($result_b and count($result_b)){
|
||||
$error = "Повтор ".$data['barcode'];
|
||||
$result = ['result'=>0,'error'=>$error];
|
||||
return $result;
|
||||
}
|
||||
|
||||
//<--Повтор------------
|
||||
|
||||
$vars=[
|
||||
'idoper'=>$data['idoper'],
|
||||
'date_query'=>$data['date_query'],
|
||||
'barcode' => $data['barcode'],
|
||||
'barcode_json'=> json_encode($data['barcode_json']),
|
||||
'date_up'=>date('Y-m-d H:i:s'),
|
||||
'iduser'=>$data['user']?$data['user']:0,
|
||||
'firma'=>$data['kag']['firma'],
|
||||
|
||||
];
|
||||
|
||||
$this->conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
$this->conn->beginTransaction();
|
||||
|
||||
|
||||
$query="insert into oper_collect
|
||||
(idoper, firma , date_query, barcode, barcode_json, date_up, \"user\")
|
||||
values
|
||||
(:idoper, :firma, :date_query,:barcode,:barcode_json,:date_up,:iduser)";
|
||||
$stmt = $this->conn->prepare($query);
|
||||
|
||||
$stmt->execute($vars);
|
||||
|
||||
$error=$stmt->errorCode();
|
||||
$id_new=$this->conn->lastInsertId();
|
||||
$this->conn->commit();
|
||||
|
||||
|
||||
$result= ['result'=>1];
|
||||
|
||||
}catch (Exception $e) {
|
||||
|
||||
$this->conn->rollBack();
|
||||
$error = "Ошибка: " . $e->getMessage();
|
||||
$result = ['result'=>0,'error'=>$error,'data'=>$data];
|
||||
}
|
||||
|
||||
return $result;
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
function PostingStatus($params)
|
||||
{
|
||||
|
||||
//$kag=$params['kag'];
|
||||
//$posting_number=$params['posting_number'];
|
||||
|
||||
$url='https://marketplace.book-online.ru/api/posting_status/';
|
||||
$json=json_encode($params);
|
||||
$result=$this->getSSLPage($url,$json,$this->headers);
|
||||
|
||||
return json_decode($result);
|
||||
|
||||
}
|
||||
|
||||
function DeleteCollect($params)
|
||||
{
|
||||
$oper=$params['oper'];
|
||||
$firma=$params['firma'];
|
||||
|
||||
if(strlen(trim($oper))>0 and strlen($firma)>0){
|
||||
$query="delete from oper_collect
|
||||
where idoper=:id and firma=:firma";
|
||||
|
||||
$vars=['id'=>$oper,'firma'=>$firma];
|
||||
$stmt = $this->conn->prepare($query);
|
||||
$stmt->execute($vars);
|
||||
$error=$stmt->errorCode();
|
||||
|
||||
return ['result'=>1,'error'=>$error,'vars'=>$vars];
|
||||
}
|
||||
|
||||
return ['result'=>0,'error'=>'неправильные входящие переменные!'];
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
154
www/first.loc/api/Class/function.php
Normal file
154
www/first.loc/api/Class/function.php
Normal file
@@ -0,0 +1,154 @@
|
||||
<?php
|
||||
function http_code($code = NULL) {
|
||||
|
||||
if ($code !== NULL) {
|
||||
|
||||
switch ($code) {
|
||||
case 100: $text = 'Continue'; break;
|
||||
case 101: $text = 'Switching Protocols'; break;
|
||||
case 200: $text = 'OK'; break;
|
||||
case 201: $text = 'Created'; break;
|
||||
case 202: $text = 'Accepted'; break;
|
||||
case 203: $text = 'Non-Authoritative Information'; break;
|
||||
case 204: $text = 'No Content'; break;
|
||||
case 205: $text = 'Reset Content'; break;
|
||||
case 206: $text = 'Partial Content'; break;
|
||||
case 300: $text = 'Multiple Choices'; break;
|
||||
case 301: $text = 'Moved Permanently'; break;
|
||||
case 302: $text = 'Moved Temporarily'; break;
|
||||
case 303: $text = 'See Other'; break;
|
||||
case 304: $text = 'Not Modified'; break;
|
||||
case 305: $text = 'Use Proxy'; break;
|
||||
case 400: $text = 'Bad Request'; break;
|
||||
case 401: $text = 'Unauthorized'; break;
|
||||
case 402: $text = 'Payment Required'; break;
|
||||
case 403: $text = 'Forbidden'; break;
|
||||
case 404: $text = 'Not Found'; break;
|
||||
case 405: $text = 'Method Not Allowed'; break;
|
||||
case 406: $text = 'Not Acceptable'; break;
|
||||
case 407: $text = 'Proxy Authentication Required'; break;
|
||||
case 408: $text = 'Request Time-out'; break;
|
||||
case 409: $text = 'Conflict'; break;
|
||||
case 410: $text = 'Gone'; break;
|
||||
case 411: $text = 'Length Required'; break;
|
||||
case 412: $text = 'Precondition Failed'; break;
|
||||
case 413: $text = 'Request Entity Too Large'; break;
|
||||
case 414: $text = 'Request-URI Too Large'; break;
|
||||
case 415: $text = 'Unsupported Media Type'; break;
|
||||
case 500: $text = 'Internal Server Error'; break;
|
||||
case 501: $text = 'Not Implemented'; break;
|
||||
case 502: $text = 'Bad Gateway'; break;
|
||||
case 503: $text = 'Service Unavailable'; break;
|
||||
case 504: $text = 'Gateway Time-out'; break;
|
||||
case 505: $text = 'HTTP Version not supported'; break;
|
||||
default:
|
||||
exit('Unknown http status code "' . htmlentities($code) . '"');
|
||||
break;
|
||||
}
|
||||
|
||||
$protocol = (isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0');
|
||||
|
||||
header($protocol . ' ' . $code . ' ' . $text);
|
||||
|
||||
$GLOBALS['http_response_code'] = $code;
|
||||
|
||||
} else {
|
||||
|
||||
$code = (isset($GLOBALS['http_response_code']) ? $GLOBALS['http_response_code'] : 200);
|
||||
|
||||
}
|
||||
|
||||
return $code;
|
||||
|
||||
}
|
||||
|
||||
function getQ_($url,$headers){
|
||||
$ch = curl_init($url);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
curl_setopt($ch, CURLOPT_HEADER, false);
|
||||
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER,$headers );
|
||||
$output = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
$ara=json_decode($output, true);
|
||||
return $ara;
|
||||
|
||||
}
|
||||
function getQ($url,$headers){
|
||||
//return [$url];
|
||||
// Инициализация сеанса cURL
|
||||
$ch = curl_init();
|
||||
// Установка URL
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
// Установка CURLOPT_RETURNTRANSFER (вернуть ответ в виде строки)
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
// Выполнение запроса cURL
|
||||
//$output содержит полученную строку
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER,$headers );
|
||||
|
||||
$output = curl_exec($ch);
|
||||
// return $output;
|
||||
$http_code=curl_getinfo($ch,CURLINFO_RESPONSE_CODE);
|
||||
|
||||
|
||||
if(stristr($output,'Something went wrong')){
|
||||
return [];//отправляем пустой массив
|
||||
}
|
||||
|
||||
if($http_code>=400 and $http_code<500){
|
||||
return [];//отправляем пустой массив
|
||||
}
|
||||
if($http_code>=500){
|
||||
return $http_code;
|
||||
}
|
||||
|
||||
|
||||
|
||||
$ara=json_decode($output, true);
|
||||
// закрытие сеанса curl для освобождения системных ресурсов
|
||||
curl_close($ch);
|
||||
return $ara;
|
||||
|
||||
}
|
||||
|
||||
function getSSLPage($url,$post_data,$headers) {
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_HEADER, false);
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
|
||||
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER,$headers );
|
||||
|
||||
|
||||
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
|
||||
if(strlen(trim($post_data))>0){
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
|
||||
}
|
||||
|
||||
curl_setopt ( $ch , CURLOPT_SSL_VERIFYPEER, 0 );
|
||||
curl_setopt ( $ch , CURLOPT_SSL_VERIFYHOST, 0 );
|
||||
|
||||
$http_code=curl_getinfo($ch,CURLINFO_RESPONSE_CODE);
|
||||
|
||||
|
||||
//$http_code=curl_getinfo($ch,CURLINFO_RESPONSE_CODE);
|
||||
$output = curl_exec($ch);
|
||||
|
||||
curl_close($ch);
|
||||
|
||||
|
||||
if($http_code>=400 or $http_code>=500){
|
||||
return $http_code;
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user