114 lines
3.2 KiB
PHP
114 lines
3.2 KiB
PHP
<?php
|
|
|
|
namespace KupShop\OrderingBundle\Controller;
|
|
|
|
use KupShop\KupShopBundle\Util\Compat\ServiceContainer;
|
|
use Monolog\Logger;
|
|
use Picqer\Barcode\BarcodeGeneratorPNG;
|
|
use Query\Operator;
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
use Symfony\Component\Routing\Annotation\Route;
|
|
|
|
class WpjController extends AbstractController
|
|
{
|
|
/**
|
|
* @Route("/_wpj/bounce/")
|
|
*
|
|
* @return Response
|
|
*/
|
|
public function bounceAction(Request $request)
|
|
{
|
|
$email = null;
|
|
preg_match_all('/(\s*\n)To: (.*)/', $request->getContent(), $matches);
|
|
if (!empty($matches)) {
|
|
$email = array_filter(end($matches), function ($x) { return $x != 'mail@kupshop.cz'; });
|
|
$email = reset($email);
|
|
}
|
|
|
|
if (!empty($email)) {
|
|
$this->log($email);
|
|
foreach ($this->getOrdersByEmail($email) as $order) {
|
|
sqlQueryBuilder()->update('orders')
|
|
->set('flags', 'ADD_TO_SET("NE", flags)')
|
|
->where(Operator::equals(['id' => $order['id']]))
|
|
->execute();
|
|
}
|
|
}
|
|
|
|
return new Response($request->getContent());
|
|
}
|
|
|
|
private function log($email)
|
|
{
|
|
/** @var Logger $logger */
|
|
$logger = ServiceContainer::getService('logger');
|
|
$logger->warning(
|
|
'Not able to deliver e-mail',
|
|
[
|
|
'email' => $email,
|
|
]
|
|
);
|
|
}
|
|
|
|
private function getOrdersByEmail(string $email)
|
|
{
|
|
return sqlQueryBuilder()
|
|
->select('id')
|
|
->from('orders')
|
|
->andWhere(Operator::equals(['invoice_email' => $email]))
|
|
->andWhere('DATEDIFF(NOW(), date_created) < 3')
|
|
->execute();
|
|
}
|
|
|
|
/**
|
|
* @Route("/_wpj/barcode/")
|
|
*
|
|
* @throws \Picqer\Barcode\Exceptions\BarcodeException
|
|
*/
|
|
public function barcodeAction(Request $request): Response
|
|
{
|
|
$type = 'int25';
|
|
if (!empty($_GET['type'])) {
|
|
$type = $_GET['type'];
|
|
}
|
|
|
|
if ($type == 'ean13') {
|
|
$_GET['oID'] = sprintf('%013d', intval($_GET['oID']));
|
|
}
|
|
|
|
$height = 60;
|
|
if (!empty($_GET['height'])) {
|
|
$height = $_GET['height'];
|
|
}
|
|
$size = $_GET['size'] ?? 1;
|
|
$show_value = ($_GET['showValue'] ?? '') !== 'false';
|
|
|
|
// Convert to BarcodeGenerator
|
|
$generator = new BarcodeGeneratorPNG();
|
|
|
|
switch ($type) {
|
|
case 'int25':
|
|
$type = $generator::TYPE_INTERLEAVED_2_5;
|
|
break;
|
|
case 'ean13':
|
|
$type = $generator::TYPE_EAN_13;
|
|
break;
|
|
case 'code39':
|
|
$type = $generator::TYPE_CODE_39;
|
|
break;
|
|
case 'code128':
|
|
$type = $generator::TYPE_CODE_128;
|
|
break;
|
|
}
|
|
|
|
$result = $generator->getBarcode($_GET['oID'], $type, $size + 1, $height);
|
|
|
|
$response = new Response($result);
|
|
$response->headers->set('Content-type', 'image/png');
|
|
|
|
return $response;
|
|
}
|
|
}
|