From: Alexander Smirnov Date: Mon, 25 Mar 2024 10:06:32 +0000 (+0300) Subject: modify code after moving to pgsql starting X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=67ec148411b1eda88e880562752c84fe355a238e;p=yii-erp24%2F.git modify code after moving to pgsql starting --- diff --git a/erp24/config/db.php b/erp24/config/db.php index 1dde726..92a4430 100644 --- a/erp24/config/db.php +++ b/erp24/config/db.php @@ -1,6 +1,6 @@ yii\db\Connection::class, 'dsn' => strtr('pgsql:host={host};port={port};dbname={dbname}', [ '{host}' => getenv('POSTGRES_HOSTNAME') ?: '127.0.0.1', diff --git a/erp24/helpers/SalaryHelper.php b/erp24/helpers/SalaryHelper.php index d717223..13160b2 100755 --- a/erp24/helpers/SalaryHelper.php +++ b/erp24/helpers/SalaryHelper.php @@ -166,7 +166,7 @@ class SalaryHelper AND p.type_id = 1 AND - (p.component_parent_id = '' OR p.component_parent_id = 0 OR p.component_parent_id IS NULL) + (p.component_parent_id = '' OR p.component_parent_id = '0' OR p.component_parent_id IS NULL) AND (sales.order_id='' OR sales.order_id='0') @@ -460,7 +460,7 @@ class SalaryHelper AND sales.id = p.check_id AND - (p.component_parent_id = '' OR p.component_parent_id = 0 OR p.component_parent_id IS NULL) + (p.component_parent_id = '' OR p.component_parent_id = '0' OR p.component_parent_id IS NULL) AND (sales.order_id='' OR sales.order_id='0') @@ -560,7 +560,7 @@ class SalaryHelper AND products_class.tip = 'matrix' WHERE - 1 + 1 = 1 ", [] ); diff --git a/erp24/records/Products1c.php b/erp24/records/Products1c.php index 6816a71..72889c2 100644 --- a/erp24/records/Products1c.php +++ b/erp24/records/Products1c.php @@ -245,10 +245,7 @@ class Products1c extends \yii\db\ActiveRecord WHERE products_1c.name != '' - ", - [ - ':search_in' => $searchIn, - ] + " ); $data = $command->queryAll(); diff --git a/erp24/services/CabinetService.php b/erp24/services/CabinetService.php index d386291..c3dcfde 100755 --- a/erp24/services/CabinetService.php +++ b/erp24/services/CabinetService.php @@ -3797,7 +3797,7 @@ Group BY `admin_id` /** @var Timetable[] $timetable */ $query = Timetable::find() - ->select(['admin_id', 'MAX(`date`) AS `last_shift`']) + ->select(['admin_id', 'MAX(date) AS last_shift']) ->andWhere(['admin_group_id' => $adminGroupId]) ->andWhere(['slot_type_id' => [ Timetable::TIMESLOT_WORK, // "работа" @@ -3853,7 +3853,7 @@ Group BY `admin_id` /** @var Timetable[] $timetable */ $queryOtherAdminDay = Timetable::find() - ->select(['date' => new \yii\db\Expression("DISTINCT(`date`)"), 'id']) + ->select(['date' => new \yii\db\Expression("DISTINCT(date)"), 'id']) ->andWhere(['>=', 'date', $dateFrom]) ->andWhere(['<=', 'date', $dateTo]) ->andWhere(['not in', 'date', $adminTableDays]) @@ -3897,7 +3897,7 @@ Group BY `admin_id` /** @var Timetable[] $timetable */ $queryOtherAdminNight = Timetable::find() - ->select(['date' => new \yii\db\Expression("DISTINCT(`date`)"), 'id']) + ->select(['date' => new \yii\db\Expression("DISTINCT(date)"), 'id']) ->andWhere(['>=', 'date', $dateFrom]) ->andWhere(['<=', 'date', $dateTo]) ->andWhere(['not in', 'date', $adminTableDaysLast]) @@ -4001,7 +4001,7 @@ Group BY `admin_id` ->andWhere(['date' => $date]) ->andWhere(['<>','admin.group_id', -1]) ->andWhere(['shift_id' => $shiftIdForDict]) - ->andWhere(['`timetable`.`store_id`' => $storeId]) + ->andWhere(['timetable.store_id' => $storeId]) ->andWhere(['slot_type_id' => $slotTypeId]) ->andWhere(['tabel' => 0]) ->asArray() @@ -4017,7 +4017,7 @@ Group BY `admin_id` * @param $adminFloristPrepared * @return Timetable[] */ - public function getTimetableAdminByData($date, $adminFloristPrepared): array + public function getTimetableAdminByData($date, $adminFloristPrepared) { $timetable = []; @@ -4034,14 +4034,14 @@ Group BY `admin_id` ]; } - /** @var Timetable[] $timetable */ + /** @var Timetable $timetable */ $timetable = Timetable::find() ->with('admin') ->andWhere(['date' => $date]) ->andWhere(['admin_id' => $adminIds]) ->andWhere(['slot_type_id' => $slotTypeId]) ->andWhere(['tabel' => 0]) - ->orderBy(new Expression('rand()')) + ->orderBy(new Expression('random()')) ->asArray() ->one() ; @@ -5395,8 +5395,8 @@ Group BY `admin_id` { return round(DashboardSales::find() ->select(['summ']) - ->andWhere(['`store_id`'=> $employeeSelectStoreId]) - ->andWhere(['`field_name`'=> $fieldName]) + ->andWhere(['store_id'=> $employeeSelectStoreId]) + ->andWhere(['field_name'=> $fieldName]) ->andWhere(['>=', 'date', $dateFrom]) ->andWhere(['<=', 'date', $dateTo]) ->average('summ'), 2); @@ -5407,8 +5407,8 @@ Group BY `admin_id` { $query = DashboardSales::find() ->select(['summ' => new \yii\db\Expression("SUM(summ)")]) - ->andWhere(['`store_id`'=> $employeeSelectStoreId]) - ->andWhere(['`field_name`'=> $fieldName]) + ->andWhere(['store_id'=> $employeeSelectStoreId]) + ->andWhere(['field_name'=> $fieldName]) ->andWhere(['>=', 'date', $dateFrom]) ->andWhere(['<=', 'date', $dateTo]); @@ -5425,8 +5425,8 @@ Group BY `admin_id` public function getSumListField($fieldName, $employeeSelectStoreId, $dateFrom, $dateTo) : array { return DashboardSales::find() - ->andWhere(['`store_id`'=> $employeeSelectStoreId]) - ->andWhere(['`field_name`'=> $fieldName]) + ->andWhere(['store_id'=> $employeeSelectStoreId]) + ->andWhere(['field_name'=> $fieldName]) ->andWhere(['>=', 'date', $dateFrom]) ->andWhere(['<=', 'date', $dateTo]) ->indexBy('date') @@ -5514,7 +5514,7 @@ Group BY `admin_id` } $dashboardSales = DashboardSales::find() - ->andWhere(['`field_name`'=> 'sales_summ']) + ->andWhere(['field_name'=> 'sales_summ']) ->andWhere(['>=', 'date', $dateFrom]) ->andWhere(['<=', 'date', $dateTo]) ->asArray() @@ -5523,7 +5523,7 @@ Group BY `admin_id` $avgCheckSummTrigger = 1200; $dashboardSalesAvgCheck = DashboardSales::find() - ->andWhere(['`field_name`'=> 'sales_avg_check']) + ->andWhere(['field_name'=> 'sales_avg_check']) ->andWhere(['>=', 'date', $dateFrom]) ->andWhere(['<=', 'date', $dateTo]) ->andWhere(['>', 'summ', $avgCheckSummTrigger]) @@ -5620,7 +5620,7 @@ Group BY `admin_id` } $dashboardSales = DashboardSales::find() - ->andWhere(['`field_name`'=> 'sales_summ']) + ->andWhere(['field_name'=> 'sales_summ']) ->andWhere(['>=', 'date', $dateFrom]) ->andWhere(['<=', 'date', $dateTo]) ->asArray() @@ -5629,7 +5629,7 @@ Group BY `admin_id` $avgCheckSummTrigger = 1200; $dashboardSalesAvgCheck = DashboardSales::find() - ->andWhere(['`field_name`'=> 'sales_avg_check']) + ->andWhere(['field_name'=> 'sales_avg_check']) ->andWhere(['>=', 'date', $dateFrom]) ->andWhere(['<=', 'date', $dateTo]) ->andWhere(['>', 'summ', $avgCheckSummTrigger]) @@ -6500,8 +6500,8 @@ Group BY `admin_id` $adminPayrollIdsCurrentMonth = AdminPayroll::find() ->select(['id']) ->indexBy('id') - ->andWhere(['`admin_payroll`.`date`' => $yearSelect . '-' . $monthWithZeroSelect]) - ->andWhere(['`admin_payroll`.`store_id`' => $storeId]) + ->andWhere(['admin_payroll.date' => $yearSelect . '-' . $monthWithZeroSelect]) + ->andWhere(['admin_payroll.store_id' => $storeId]) ->asArray()->column(); @@ -6509,8 +6509,8 @@ Group BY `admin_id` $adminPayrollIdsBeforeMonth = AdminPayroll::find() ->select(['id']) ->indexBy('id') - ->andWhere(['`admin_payroll`.`date`' => $yearBeforeSelect . '-' . $monthWithZeroBeforeSelect]) - ->andWhere(['`admin_payroll`.`store_id`' => $storeId]) + ->andWhere(['admin_payroll.date' => $yearBeforeSelect . '-' . $monthWithZeroBeforeSelect]) + ->andWhere(['admin_payroll.store_id' => $storeId]) ->asArray()->column(); diff --git a/erp24/services/DashboardService.php b/erp24/services/DashboardService.php index a64816a..628f4cb 100755 --- a/erp24/services/DashboardService.php +++ b/erp24/services/DashboardService.php @@ -118,7 +118,7 @@ class DashboardService // массив с полями дашборда $fields_arr = DashboardFields::find() ->select(['id', 'name']) - ->andWhere(['`active`' => 1]) + ->andWhere(['active' => 1]) ->andWhere(['<>', 'name', 'sales_summ']) ->indexBy('id') ->asArray() diff --git a/erp24/services/InfoTableService.php b/erp24/services/InfoTableService.php index 7f4b2bb..79ad50c 100644 --- a/erp24/services/InfoTableService.php +++ b/erp24/services/InfoTableService.php @@ -557,7 +557,7 @@ class InfoTableService } $ids = array_unique($ids); - //$query->andWhere(['`products_1c`.`parent_id`' => $ids]);// ['`products_1c`.`parent_id`' => $products] + //$query->andWhere(['products_1c.parent_id' => $ids]);// ['products_1c.parent_id' => $products] } @@ -580,18 +580,18 @@ class InfoTableService { $query = Sales::find() ->select([ - '`sales`.`id`', - '`sales`.`date`', - '`sales`.`operation`', - '`sales`.`store_id`', - '`sales_products`.`price`', - '`sales_products`.`discount`', - '`sales_products`.`quantity`', - '`sales_products`.`summ`', - '`sales_products`.`product_id`', - '`products_1c`.`id`', - '`products_1c`.`parent_id`', - '`products_1c`.`name`', + 'sales.id', + 'sales.date', + 'sales.operation', + 'sales.store_id', + 'sales_products.price', + 'sales_products.discount', + 'sales_products.quantity', + 'sales_products.summ', + 'sales_products.product_id', + 'products_1c.id', + 'products_1c.parent_id', + 'products_1c.`name`', ]) ->joinWith('products1c') diff --git a/erp24/services/SalesService.php b/erp24/services/SalesService.php index 33c39f1..e7812eb 100755 --- a/erp24/services/SalesService.php +++ b/erp24/services/SalesService.php @@ -246,17 +246,17 @@ class SalesService if ($isAdministrator) { $query->select([ 'summ' => new \yii\db\Expression("SUM(summ - skidka)"), - 'date' => new \yii\db\Expression("DATE_FORMAT(date,'%Y-%m-%d')"), + 'date' => new \yii\db\Expression("TO_CHAR(date,'%Y-%m-%d')"), 'operation' ]); } else { $query->select([ 'summ' => new \yii\db\Expression("SUM(summ - skidka)"), - 'date' => new \yii\db\Expression("(case when (HOUR(date) >= 0 and HOUR(date) <= $dateTimeEndDayPreparedHour) + 'date' => new \yii\db\Expression("(case when (extract (HOUR from date) >= 0 and extract(HOUR from date) <= $dateTimeEndDayPreparedHour) THEN - DATE_FORMAT(DATE_ADD(date, INTERVAL -1 DAY),'%Y-%m-%d') + TO_CHAR(date - INTERVAL '1 DAY','%Y-%m-%d') ELSE - DATE_FORMAT(date,'%Y-%m-%d') + TO_CHAR(date,'%Y-%m-%d') END) "), 'operation' @@ -315,7 +315,7 @@ class SalesService if ($isAdministrator) { $query->select([ 'summ' => new \yii\db\Expression("SUM(summ - skidka)"), - 'date' => new \yii\db\Expression("DATE_FORMAT(date,'%Y-%m-%d')"), + 'date' => new \yii\db\Expression("TO_CHAR(date,'%Y-%m-%d')"), 'operation' ]); } else { @@ -323,9 +323,9 @@ class SalesService 'summ' => new \yii\db\Expression("SUM(summ - skidka)"), 'date' => new \yii\db\Expression("(case when (HOUR(date) >= 0 and HOUR(date) < $dateTimeEndDayPreparedHour) THEN - DATE_FORMAT(DATE_ADD(date, INTERVAL -1 DAY),'%Y-%m-%d') + TO_CHAR(date - INTERVAL '1 DAY','%Y-%m-%d') ELSE - DATE_FORMAT(date,'%Y-%m-%d') + TO_CHAR(date,'%Y-%m-%d') END) "), 'operation' @@ -365,9 +365,9 @@ class SalesService $orderCondition = " AND ( - `order_id` = '' + \"order_id\" = '' OR - `order_id` = '0' + \"order_id\" = '0' ) "; @@ -376,10 +376,10 @@ class SalesService $queryRow = " SELECT count(*) as cnt, - sum(if(phone!='NULL',1,0)) as bonus_clients_cnt, + sum(case when phone is distinct from NULL THEN 1 ELSE 0 END) as bonus_clients_cnt, sum(summ-skidka) as summ, store_id, - DATE_FORMAT(date,'%Y-%m-%d') as date_t + to_char(date,'%Y-%m-%d') as date_t FROM sales WHERE @@ -404,7 +404,7 @@ class SalesService $payArrCondition = " AND - `pay_arr` IN (" . $payType . ") + \"pay_arr\" IN (" . $payType . ") "; } @@ -453,7 +453,7 @@ class SalesService $payArrCondition = " AND - `pay_arr` IN (" . $payType . ") + \"pay_arr\" IN (" . $payType . ") "; } @@ -465,7 +465,7 @@ class SalesService SELECT count(*) as cnt, store_id, - DATE_FORMAT(date,'%Y-%m-%d') as date_t + TO_CHAR(date,'%Y-%m-%d') as date_t FROM sales WHERE @@ -636,18 +636,18 @@ class SalesService if ($shiftTypeDay) { $hourCondition = " AND - HOUR(date) >= 8 #дневная смена + extract(HOUR from date) >= 8 /* дневная смена */ AND - HOUR(date) < 20 #дневная смена + extract(HOUR from date) < 20 /* дневная смена */ "; } else { $hourCondition = " AND ( - HOUR(date) >= 20 #ночная смена + extract(HOUR from date) >= 20 /* ночная смена */ OR - HOUR(date) < 8 #ночная смена + extract(HOUR from date) < 8 /* ночная смена */ ) "; @@ -656,9 +656,9 @@ class SalesService $orderCondition = " AND ( - `order_id` = '' + order_id = '' OR - `order_id` = '0' + order_id = '0' ) "; @@ -668,11 +668,11 @@ class SalesService SELECT count(*) as cnt, store_id, - (case when (HOUR(date) >= 0 and HOUR(date) < 8) + (case when (extract(HOUR from date) >= 0 and extract(HOUR from date) < 8) THEN - DATE_FORMAT(DATE_ADD(date, INTERVAL -1 DAY),'%Y-%m-%d') + TO_CHAR(date - INTERVAL '1 DAY','%Y-%m-%d') ELSE - DATE_FORMAT(date,'%Y-%m-%d') + TO_CHAR(date,'%Y-%m-%d') END) AS date_t FROM @@ -713,18 +713,18 @@ class SalesService if ($shiftTypeDay) { $hourCondition = " AND - HOUR(date) >= 8 #дневная смена + extract(hour from date) >= 8 /* дневная смена */ AND - HOUR(date) < 20 #дневная смена + extract(hour from date) < 20 /* дневная смена */ "; } else { $hourCondition = " AND ( - HOUR(date) >= 20 #ночная смена + extract(hour from date) >= 20 /* ночная смена */ OR - HOUR(date) < 8 #ночная смена + extract(hour from date) < 8 /* ночная смена */ ) "; @@ -733,9 +733,9 @@ class SalesService $orderCondition = " AND ( - `order_id` = '' + order_id = '' OR - `order_id` = '0' + order_id = '0' ) "; @@ -744,13 +744,13 @@ class SalesService SELECT count(*) as cnt, store_id, - (DATE_FORMAT(date,'%Y-%m-%d')) + (TO_CHAR(date,'%Y-%m-%d')) AS date_t, - (DATE_FORMAT(date,'%Y-%m-%d_%k')) + (TO_CHAR(date,'%Y-%m-%d_%k')) AS date_k, - (DATE_FORMAT(date,'%k')) + (TO_CHAR(date,'%k')) AS date_t_h, - (DATE_FORMAT(date,'%Y-%m-%d')) + (TO_CHAR(date,'%Y-%m-%d')) AS date_t_d FROM sales @@ -1120,7 +1120,7 @@ class SalesService sales.date, sales.number, (p.summ) AS summ, - p.`product_id` AS product_guid, + p.product_id AS product_guid, sales.summ AS sales_summ, sales.skidka, 0 as bonus, @@ -1150,7 +1150,7 @@ class SalesService AND products_class.tip = 'matrix' WHERE - 1 + 1 = 1 ) AND sales.date >= :date_from @@ -1234,7 +1234,7 @@ class SalesService AND products_class.tip = 'matrix' WHERE - 1 + 1 = 1 ) AND sales.date >= :date_from @@ -1287,18 +1287,18 @@ class SalesService $connection = Yii::$app->getDb(); - $selectColumn = "(p.`summ` - p.`discount`) AS summ, `sales`.`operation`, `sales`.`store_id`, `sales`.`store_id_1c`"; + $selectColumn = "(p.summ - p.discount) AS summ, sales.operation, sales.store_id, sales.store_id_1c"; if ($isAdministrator) { - $selectColumn .= ", DATE_FORMAT(`sales`.`date`,'%Y-%m-%d') + $selectColumn .= ", TO_CHAR(sales.date,'%Y-%m-%d') AS date"; } else { - $selectColumn .= ", (case when (HOUR(`sales`.`date`) >= 0 and HOUR(`sales`.`date`) < $dateTimeEndDayPreparedHour) + $selectColumn .= ", (case when (extract (hour from sales.date) >= 0 and extract(hour from sales.date) < $dateTimeEndDayPreparedHour) THEN - DATE_FORMAT(DATE_ADD(`sales`.`date`, INTERVAL -1 DAY),'%Y-%m-%d') + TO_CHAR(sales.date - INTERVAL '1 DAY','%Y-%m-%d') ELSE - DATE_FORMAT(`sales`.`date`,'%Y-%m-%d') + TO_CHAR(sales.date,'%Y-%m-%d') END) AS date "; @@ -1308,35 +1308,35 @@ class SalesService SELECT " . $selectColumn . " FROM - `sales_products` as p, - `sales` + sales_products as p, + sales WHERE - `sales`.`store_id_1c` = :store_id_1c + sales.store_id_1c = :store_id_1c AND - `sales`.`id` = p.`check_id` + sales.id = p.check_id AND ( - `sales`.`order_id`='' + sales.order_id='' OR - `sales`.`order_id`='0' + sales.order_id='0' ) AND - p.`product_id` IN ( + p.product_id IN ( SELECT - `products_1c`.`id` + products_1c.id FROM - `products_1c` - RIGHT JOIN `products_class` + products_1c + RIGHT JOIN products_class ON - `products_1c`.`parent_id` = `products_class`.`category_id` + products_1c.parent_id = products_class.category_id AND - `products_class`.`tip` = 'matrix' + products_class.tip = 'matrix' WHERE - 1 + 1 = 1 ) AND - `sales`.`date` >= :date_from + sales.date >= :date_from AND - `sales`.`date` <= :date_to + sales.date <= :date_to ", [ ':store_id_1c' => $entityCityStoreEmployeeSelect, @@ -1395,7 +1395,7 @@ class SalesService sales.date, sales.number, (p.summ) AS summ, - p.`product_id` AS product_guid, + p.product_id AS product_guid, sales.summ AS sales_summ, sales.skidka, 0 as bonus, @@ -1425,7 +1425,7 @@ class SalesService AND products_class.tip = 'matrix' WHERE - 1 + 1 = 1 ) AND sales.date >= :date_from @@ -1507,7 +1507,7 @@ class SalesService AND products_class.tip = 'matrix' WHERE - 1 + 1 = 1 ) AND sales.date >= :date_from @@ -1597,8 +1597,8 @@ class SalesService $command = $connection->createCommand(" SELECT DISTINCT (sales.id), - DATE_FORMAT(sales.date, '%d.%m в %H:%i') as dt, - DATE_FORMAT(sales.date, '%Y-%m-%d') as sales_date_dt, + TO_CHAR(sales.date, '%d.%m в %H:%i') as dt, + TO_CHAR(sales.date, '%Y-%m-%d') as sales_date_dt, sales.date, sales.matrix, sales.skidka, diff --git a/erp24/services/ShipmentService.php b/erp24/services/ShipmentService.php index ae76542..68bfe13 100755 --- a/erp24/services/ShipmentService.php +++ b/erp24/services/ShipmentService.php @@ -256,10 +256,10 @@ class ShipmentService 'id' => 'id', 'providers_arr' => 'providers_arr', 'status' => 'status', - 'date_start' => "DATE_FORMAT(`date_start`, '%Y-%m-%d')", - 'date_add' => "DATE_FORMAT(`date_add`, '%Y-%m-%d')", - 'division_date' => "DATE_FORMAT(`division_date`, '%Y-%m-%d')", - 'date_update' => "UNIX_TIMESTAMP(`date_update`)", + 'date_start' => "DATE_FORMAT(date_start, '%Y-%m-%d')", + 'date_add' => "DATE_FORMAT(date_add, '%Y-%m-%d')", + 'division_date' => "DATE_FORMAT(division_date, '%Y-%m-%d')", + 'date_update' => "UNIX_TIMESTAMP(date_update)", 'parent_id' ] ) @@ -281,7 +281,7 @@ class ShipmentService } else { // иначе идем к родителю и узнаем дату матери к которой будем привязываться $date_start = StoreOrders::find() - ->select(['date_start' => "DATE_FORMAT(`date_start`, '%Y-%m-%d')"]) + ->select(['date_start' => "DATE_FORMAT(date_start, '%Y-%m-%d')"]) ->andWhere(['id' => $OrderData["parent_id"]]) ->asArray() ->scalar(); @@ -393,7 +393,7 @@ class ShipmentService ->select([ 'field_name', 'product_id', - 'sum' => "SUM(`value`)", + 'sum' => "SUM(value)", ]) ->andWhere(['order_id'=>$this->orderId]) ->andWhere(['store_id' => '']) @@ -432,7 +432,7 @@ class ShipmentService 'field_name', 'product_id', 'color', - 'sum' => "SUM(`value`)", + 'sum' => "SUM(value)", ]) ->andWhere(['order_id'=>$this->orderId]) ->andWhere(['<>', 'store_id', '']) @@ -1212,13 +1212,13 @@ setTimeout(function(){ // ); $vnesli = StoreOrderStatus::find() - ->select(['`order_id`']) + ->select(['order_id']) ->andWhere(['order_id' => $orderId]) ->andWhere(['status_id' => $status_order_id]) ->andWhere(['status' => 1]) ->groupBy(['order_id']) ->asArray() - ->count('`order_id`'); + ->count('order_id'); $store_order_status=array(); diff --git a/erp24/services/StoreVisitorsService.php b/erp24/services/StoreVisitorsService.php index a501b9d..6cd6f12 100755 --- a/erp24/services/StoreVisitorsService.php +++ b/erp24/services/StoreVisitorsService.php @@ -30,18 +30,18 @@ class StoreVisitorsService if ($shiftTypeDay) { $hourCondition = " AND - `date_hour` >= 8 #дневная смена + date_hour >= 8 /* дневная смена */ AND - `date_hour` < 20 #дневная смена + date_hour < 20 /* дневная смена */ "; } else { $hourCondition = " AND ( - `date_hour` >= 20 #ночная смена + date_hour >= 20 /* ночная смена */ OR - `date_hour` < 8 #ночная смена + date_hour < 8 /* ночная смена */ ) "; @@ -50,17 +50,17 @@ class StoreVisitorsService $command = $connection->createCommand( " SELECT - SUM(`counter`) as cnt, - `date_hour`, + SUM(counter) as cnt, + date_hour, store_id, - (case when (`date_hour` >= 0 and `date_hour` < 8) + (case when (date_hour >= 0 and date_hour < 8) THEN - DATE_FORMAT(DATE_ADD(date, INTERVAL -1 DAY),'%Y-%m-%d') + TO_CHAR(date - INTERVAL '1 DAY','%Y-%m-%d') ELSE - DATE_FORMAT(date,'%Y-%m-%d') + TO_CHAR(date,'%Y-%m-%d') END) AS date_t, - CONCAT ((DATE_FORMAT(date,'%Y-%m-%d_')),`date_hour`) + CONCAT ((TO_CHAR(date,'%Y-%m-%d_')),date_hour) AS date_k FROM @@ -74,10 +74,10 @@ class StoreVisitorsService AND date<=:date_to GROUP BY - `date_hour`, - `date_t`, - `date_k`, - `store_id` + date_hour, + date_t, + date_k, + store_id ", [ ':date_from' => $dateFrom, diff --git a/erp24/web/index.php b/erp24/web/index.php index f94e130..7c88b09 100644 --- a/erp24/web/index.php +++ b/erp24/web/index.php @@ -30,9 +30,10 @@ if ( $postJson = Yii::$app->request->post(); unset($postJson["_csrf"]); $post = \yii\helpers\Json::encode($postJson); + $post = str_replace('"', '\'', $post); $app->db->createCommand( - 'INSERT INTO page_statistics (admin_id, url, post, created_at) VALUES ("' . $_SESSION['admin_id'] . '", "' - . $url . '", :post, NOW())' + 'INSERT INTO page_statistics (admin_id, url, post, created_at) VALUES (\'' . $_SESSION['admin_id'] . '\', \'' + . $url . '\', :post, NOW())' )->bindParam(':post', $post, PDO::PARAM_STR)->execute(); }