Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Created by PhpStorm.
- * User: vrtc
- * Date: 08.12.15
- * Time: 11:40
- */
- require_once("config.php");
- $mysqli = new mysqli(DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_DATABASE);
- if (mysqli_connect_errno()) {
- printf("Подключение к серверу MySQL невозможно. Код ошибки: %s\n", mysqli_connect_error());
- exit;
- }
- $mysqli->set_charset("utf8");
- $query = $mysqli->query("SELECT * FROM `" . DB_PREFIX . "order` WHERE kkm = 0 AND payment_code= 'payanyway_pcard'");
- if ($query->num_rows == 0) {
- return null;
- } else {
- $i = 0;
- while ($row = $query->fetch_array(MYSQLI_ASSOC)) {
- $orders[$i] = $row;
- $i++;
- }
- $getInfo = getInfo();
- //если смена закрыта
- if (isset($getInfo['Info']['SessionState']) && $getInfo['Info']['SessionState'] == 3) {
- $Zreport = [
- 'Command' => "ZReport",
- 'NumDevice' => 2,
- 'CashierName' => ''
- ];
- $zResult = connect($Zreport);
- OpenShift();
- $getInfo = getInfo();
- }
- //если смена открыта , но давно
- if (isset($getInfo['Info']['SessionState']) && $getInfo['Info']['SessionState'] == 1) {
- OpenShift();
- $getInfo = getInfo();
- }
- if (isset($getInfo['Info']['SessionState']) && $getInfo['Info']['SessionState'] == 2) {
- foreach ($orders as $order) {
- $queryP = $mysqli->query("SELECT * FROM `" . DB_PREFIX . "order_product` WHERE order_id = " . (int)$order['order_id'] . " ");
- while ($row = $queryP->fetch_array(MYSQLI_ASSOC)) {
- $products[$i] = $row;
- $i++;
- }
- $kkmProducts = [];
- foreach ($products as $product) {
- $kkmProducts[] = [
- 'Register' => [
- 'Name' => $product['name'],
- 'Quantity' => (int)$product['quantity'],
- 'Price' => (int)$product['price'],
- 'Amount' => (int)$product['total'],
- ]
- ];
- }
- $RegisterCheck = [
- 'Command' => "RegisterCheck",
- 'NumDevice' => 2,
- 'IsFiscalCheck' => true,
- 'NotPrint' => false,
- 'ClientAddress' => $order['email'],
- 'CheckStrings' => $kkmProducts,
- 'Cash' => 0,
- 'CashLessType1' => (int)$order['total']
- ];
- // var_dump($RegisterCheck); exit;
- $RegisterCheck = connect($RegisterCheck);
- //если чек напечатан
- if (isset($RegisterCheck['Status']) && ($RegisterCheck['Status'] == 1 || $RegisterCheck['Status'] == 0)) {
- $mysqli->query("UPDATE `" . DB_PREFIX . "order` SET kkm = 1 WHERE order_id = " . (int)$order['order_id'] . " ");
- }
- //var_dump($RegisterCheck);
- }
- }
- }
- function OpenShift()
- {
- $OpenShift = [
- 'Command' => "OpenShift",
- 'NumDevice' => 2,
- 'CashierName' => ''
- ];
- return connect($OpenShift);
- }
- function getInfo()
- {
- $GetDataKKT = [
- 'Command' => "GetDataKKT",
- 'NumDevice' => 2,
- 'CashierName' => ''
- ];
- return connect($GetDataKKT);
- }
- function connect($data)
- {
- $user = "";
- $password = "";
- $url = "";
- $dataCommand = json_encode($data);
- $ch = curl_init();
- //коннектим к кассе
- curl_setopt($ch, CURLOPT_URL, $url."/Execute");
- curl_setopt($ch, CURLOPT_POSTFIELDS, $dataCommand);
- curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 20);
- curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
- curl_setopt($ch, CURLOPT_POST, true);
- //нельзя в урле передать порт, поэтому тут костыль подставляем
- curl_setopt($ch, CURLOPT_PORT, 1195);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_USERPWD, $user . ':' . $password);
- curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
- curl_setopt($ch, CURLOPT_HTTPHEADER, array(
- 'Accept: application/json',
- 'Content-Type: application/json')
- );
- if (curl_exec($ch) === false) {
- //в пизду
- echo 'Curl error: ' . curl_error($ch);
- }
- $errors = curl_error($ch);
- $result = curl_exec($ch);
- $returnCode = (int)curl_getinfo($ch, CURLINFO_HTTP_CODE);
- curl_close($ch);
- //код ответа
- echo $returnCode;
- //ошибки если есть
- var_dump($errors);
- //тело ответа
- return json_decode($result, true);
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement