]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
modify code after moving to pgsql starting
authorAlexander Smirnov <fredeom@mail.ru>
Mon, 25 Mar 2024 10:06:32 +0000 (13:06 +0300)
committerAlexander Smirnov <fredeom@mail.ru>
Mon, 25 Mar 2024 10:06:32 +0000 (13:06 +0300)
erp24/config/db.php
erp24/helpers/SalaryHelper.php
erp24/records/Products1c.php
erp24/services/CabinetService.php
erp24/services/DashboardService.php
erp24/services/InfoTableService.php
erp24/services/SalesService.php
erp24/services/ShipmentService.php
erp24/services/StoreVisitorsService.php
erp24/web/index.php

index 1dde7260730e33c905bd005bd6c1a26eb8a77053..92a443056c18bb1f5315a967abd8dcb6912742bc 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 
-return 1 == 2 ? [
+return 1 == 1 ? [
     'class' => yii\db\Connection::class,
     'dsn' => strtr('pgsql:host={host};port={port};dbname={dbname}', [
         '{host}' => getenv('POSTGRES_HOSTNAME') ?: '127.0.0.1',
index d717223f81c818dde908530e8232cd9b50e7d048..13160b2c49dcd46097e4b7984f0603ea0b162c6f 100755 (executable)
@@ -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
             ",
             []
         );
index 6816a71594d0b9e96547ba9123b08496a0b66359..72889c211457bda731305219f2b2db319d42d366 100644 (file)
@@ -245,10 +245,7 @@ class Products1c extends \yii\db\ActiveRecord
             
             WHERE
                 products_1c.name != ''
-            ",
-            [
-                ':search_in' => $searchIn,
-            ]
+            "
         );
 
         $data = $command->queryAll();
index d38629178d3cfef5a1bf76ca35dd56b16b3fe563..c3dcfde3aad7ab8dae0e75fa45d1175e59486906 100755 (executable)
@@ -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();
 
 
index a64816a05d969b9d6e4c726eba466e16a01fc8c3..628f4cb520479153d81bf5eb578bb3d98a2458c9 100755 (executable)
@@ -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()
index 7f4b2bbf582bb72e440311ab9c48f1a31a3ec6ff..79ad50c035677c5127ce3d1c90a4341dc2765a2e 100644 (file)
@@ -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')
index 33c39f1f997b4ff4371bc8b7b140d97f721dbfbc..e7812eb9a74e2cdd7716166625c0e51d23937cf4 100755 (executable)
@@ -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,
index ae76542b4f2b2bfb43460ccc8b23db9958e9a2cc..68bfe139d2879e58c8f16eb7199226820b0c2922 100755 (executable)
@@ -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();
index a501b9d25b471e5643de8c1b8c0a7273e3cb669e..6cd6f12ca2991e5cba03ea16b02f5af2aa8c8c7f 100755 (executable)
@@ -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,
index f94e1302a2168eca4c256bab2f214109d0a4f912..7c88b0945982802ffffcc6f636e323d1df20450d 100644 (file)
@@ -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();
 }