update
This commit is contained in:
@@ -925,9 +925,10 @@ class Products
|
||||
$order_name = $_POST['order'][0]['name'] ? $_POST['order'][0]['name'] : 'clicks';
|
||||
$search = trim( (string) \S::get( 'search_text' ) );
|
||||
$filter_cl4 = trim( (string) \S::get( 'filter_cl4' ) );
|
||||
$filter_cl1 = trim( (string) \S::get( 'filter_cl1' ) );
|
||||
|
||||
// ➊ MIN/MAX ROAS dla kontekstu klienta (opcjonalnie z filtrem search)
|
||||
$bounds = \factory\Products::get_roas_bounds( (int) $client_id, $search, $campaign_id, $ad_group_id, $filter_cl4 );
|
||||
$bounds = \factory\Products::get_roas_bounds( (int) $client_id, $search, $campaign_id, $ad_group_id, $filter_cl4, $filter_cl1 );
|
||||
$roas_min = (float)$bounds['min'];
|
||||
$roas_max = (float)$bounds['max'];
|
||||
// zabezpieczenie przed dzieleniem przez 0
|
||||
@@ -962,8 +963,8 @@ class Products
|
||||
</div>';
|
||||
};
|
||||
|
||||
$db_results = \factory\Products::get_products( $client_id, $search, $limit, $start, $order_name, $order_dir, $campaign_id, $ad_group_id, $filter_cl4 );
|
||||
$recordsTotal = \factory\Products::get_records_total_products( $client_id, $search, $campaign_id, $ad_group_id, $filter_cl4 );
|
||||
$db_results = \factory\Products::get_products( $client_id, $search, $limit, $start, $order_name, $order_dir, $campaign_id, $ad_group_id, $filter_cl4, $filter_cl1 );
|
||||
$recordsTotal = \factory\Products::get_records_total_products( $client_id, $search, $campaign_id, $ad_group_id, $filter_cl4, $filter_cl1 );
|
||||
|
||||
// Sredni CR konta — do obliczenia progu klikniec
|
||||
$account_cr = \factory\Products::get_account_conversion_rate( (int) $client_id );
|
||||
@@ -978,6 +979,7 @@ class Products
|
||||
{
|
||||
$custom_class = '';
|
||||
$custom_label_4 = \factory\Products::get_product_data( $row['product_id'], 'custom_label_4' );
|
||||
$custom_label_1 = \factory\Products::get_product_data( $row['product_id'], 'custom_label_1' );
|
||||
$custom_name = \factory\Products::get_product_data( $row['product_id'], 'title' );
|
||||
$product_url = trim( (string) \factory\Products::get_product_data( $row['product_id'], 'product_url' ) );
|
||||
|
||||
@@ -1004,6 +1006,20 @@ class Products
|
||||
else if ( $custom_label_4 == 'paused' )
|
||||
$custom_label_4_color = 'background-color:rgb(143, 143, 143); color: #FFF;';
|
||||
|
||||
$custom_label_1_color = '';
|
||||
if ( $custom_label_1 == 'bestseller' )
|
||||
$custom_label_1_color = 'background-color:rgb(96, 119, 102); color: #FFF;';
|
||||
else if ( $custom_label_1 == 'deleted' )
|
||||
$custom_label_1_color = 'background-color:rgb(255, 0, 0); color: #FFF;';
|
||||
else if ( $custom_label_1 == 'zombie' )
|
||||
$custom_label_1_color = 'background-color:rgb(58, 58, 58); color: #FFF;';
|
||||
else if ( $custom_label_1 == 'pla_single' )
|
||||
$custom_label_1_color = 'background-color:rgb(49, 184, 9); color: #FFF;';
|
||||
else if ( $custom_label_1 == 'pla' )
|
||||
$custom_label_1_color = 'background-color:rgb(74, 63, 136); color: #FFF;';
|
||||
else if ( $custom_label_1 == 'paused' )
|
||||
$custom_label_1_color = 'background-color:rgb(143, 143, 143); color: #FFF;';
|
||||
|
||||
// ➌ ROAS – liczba + pasek performance
|
||||
$roasValue = (float)$row['roas'];
|
||||
$roasDisplay = (int) round( $roasValue, 0 );
|
||||
@@ -1096,7 +1112,7 @@ class Products
|
||||
\S::number_display( $row['conversions_value'] ),
|
||||
$roasCellHtml,
|
||||
'<input type="text" class="form-control min_roas" product_id="' . $row['product_id'] . '" value="' . $row['min_roas'] . '" style="width: 100px;">',
|
||||
htmlspecialchars( (string) ( $row['custom_label_3'] ?? '' ) ),
|
||||
'<input type="text" class="form-control custom_label_1" product_id="' . $row['product_id'] . '" value="' . $custom_label_1 . '" style="' . $custom_label_1_color . '">',
|
||||
'<input type="text" class="form-control custom_label_4" product_id="' . $row['product_id'] . '" value="' . $custom_label_4 . '" style="' . $custom_label_4_color . '">',
|
||||
'<div class="btn-group btn-group-sm products-row-actions" role="group">'
|
||||
. '<button type="button" class="btn btn-primary assign-product-scope" product_id="' . $row['product_id'] . '" title="Dodaj produkt do kampanii/grupy"><i class="fa-solid fa-diagram-project"></i></button>'
|
||||
@@ -1172,6 +1188,29 @@ class Products
|
||||
exit;
|
||||
}
|
||||
|
||||
static public function get_distinct_cl1()
|
||||
{
|
||||
$client_id = (int) \S::get( 'client_id' );
|
||||
$values = \factory\Products::get_distinct_custom_label_1( $client_id );
|
||||
echo json_encode( [ 'status' => 'ok', 'values' => $values ] );
|
||||
exit;
|
||||
}
|
||||
|
||||
static public function save_custom_label_1()
|
||||
{
|
||||
$product_id = \S::get( 'product_id' );
|
||||
$custom_label_1 = \S::get( 'custom_label_1' );
|
||||
|
||||
if ( \factory\Products::set_product_data( $product_id, 'custom_label_1', $custom_label_1 ) )
|
||||
{
|
||||
\factory\Products::add_product_comment( $product_id, 'Zmiana etykiety 1 na: ' . $custom_label_1 );
|
||||
echo json_encode( [ 'status' => 'ok' ] );
|
||||
}
|
||||
else
|
||||
echo json_encode( [ 'status' => 'error' ] );
|
||||
exit;
|
||||
}
|
||||
|
||||
static public function product_history()
|
||||
{
|
||||
$client_id = \S::get( 'client_id' );
|
||||
|
||||
@@ -7,6 +7,7 @@ class Products
|
||||
return in_array( (string) $field, [
|
||||
'custom_label_4',
|
||||
'custom_label_3',
|
||||
'custom_label_1',
|
||||
'title',
|
||||
'description',
|
||||
'google_product_category',
|
||||
@@ -486,7 +487,7 @@ class Products
|
||||
$sql .= ' AND ag.status = \'active\'';
|
||||
}
|
||||
|
||||
static public function get_products( $client_id, $search, $limit, $start, $order_name, $order_dir, $campaign_id = 0, $ad_group_id = 0, $custom_label_4 = '' )
|
||||
static public function get_products( $client_id, $search, $limit, $start, $order_name, $order_dir, $campaign_id = 0, $ad_group_id = 0, $custom_label_4 = '', $custom_label_1 = '' )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
@@ -499,7 +500,7 @@ class Products
|
||||
'campaign_name' => 'campaign_name',
|
||||
'ad_group_name' => 'ad_group_name',
|
||||
'name' => 'name',
|
||||
'custom_label_3' => 'custom_label_3',
|
||||
'custom_label_1' => 'custom_label_1',
|
||||
'impressions' => 'impressions',
|
||||
'impressions_30' => 'impressions_30',
|
||||
'clicks' => 'clicks',
|
||||
@@ -520,7 +521,7 @@ class Products
|
||||
p.id AS product_id,
|
||||
p.offer_id,
|
||||
p.min_roas,
|
||||
COALESCE( NULLIF( TRIM( p.custom_label_3 ), \'\' ), \'\' ) AS custom_label_3,
|
||||
COALESCE( NULLIF( TRIM( p.custom_label_1 ), \'\' ), \'\' ) AS custom_label_1,
|
||||
pa.campaign_id AS campaign_id,
|
||||
COALESCE( NULLIF( TRIM( c.campaign_name ), \'\' ), \'--- brak kampanii ---\' ) AS campaign_name,
|
||||
CASE
|
||||
@@ -565,6 +566,7 @@ class Products
|
||||
OR p.title LIKE :search
|
||||
OR p.offer_id LIKE :search
|
||||
OR p.custom_label_4 LIKE :search
|
||||
OR p.custom_label_1 LIKE :search
|
||||
OR c.campaign_name LIKE :search
|
||||
OR ag.ad_group_name LIKE :search
|
||||
)';
|
||||
@@ -577,13 +579,19 @@ class Products
|
||||
$params[':custom_label_4'] = '%' . $custom_label_4 . '%';
|
||||
}
|
||||
|
||||
$sql .= ' GROUP BY p.id, p.offer_id, p.min_roas, p.custom_label_3, p.name, p.title, pa.campaign_id, c.campaign_name, pa.ad_group_id, ag.ad_group_name';
|
||||
if ( $custom_label_1 !== '' )
|
||||
{
|
||||
$sql .= ' AND p.custom_label_1 LIKE :custom_label_1';
|
||||
$params[':custom_label_1'] = '%' . $custom_label_1 . '%';
|
||||
}
|
||||
|
||||
$sql .= ' GROUP BY p.id, p.offer_id, p.min_roas, p.custom_label_1, p.name, p.title, pa.campaign_id, c.campaign_name, pa.ad_group_id, ag.ad_group_name';
|
||||
$sql .= ' ORDER BY ' . $order_sql . ' ' . $order_dir . ', product_id DESC LIMIT ' . $start . ', ' . $limit;
|
||||
|
||||
return $mdb -> query( $sql, $params ) -> fetchAll( \PDO::FETCH_ASSOC );
|
||||
}
|
||||
|
||||
public static function get_roas_bounds( int $client_id, ?string $search = null, int $campaign_id = 0, int $ad_group_id = 0, string $custom_label_4 = '' ): array
|
||||
public static function get_roas_bounds( int $client_id, ?string $search = null, int $campaign_id = 0, int $ad_group_id = 0, string $custom_label_4 = '', string $custom_label_1 = '' ): array
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
@@ -612,6 +620,7 @@ class Products
|
||||
OR p.title LIKE :search
|
||||
OR p.offer_id LIKE :search
|
||||
OR p.custom_label_4 LIKE :search
|
||||
OR p.custom_label_1 LIKE :search
|
||||
OR c.campaign_name LIKE :search
|
||||
OR ag.ad_group_name LIKE :search
|
||||
)';
|
||||
@@ -624,6 +633,12 @@ class Products
|
||||
$params[':custom_label_4'] = '%' . $custom_label_4 . '%';
|
||||
}
|
||||
|
||||
if ( $custom_label_1 !== '' )
|
||||
{
|
||||
$sql .= ' AND p.custom_label_1 LIKE :custom_label_1';
|
||||
$params[':custom_label_1'] = '%' . $custom_label_1 . '%';
|
||||
}
|
||||
|
||||
$row = $mdb -> query( $sql, $params ) -> fetch( \PDO::FETCH_ASSOC );
|
||||
|
||||
return [
|
||||
@@ -656,7 +671,7 @@ class Products
|
||||
return $total_conversions / $total_clicks;
|
||||
}
|
||||
|
||||
static public function get_records_total_products( $client_id, $search, $campaign_id = 0, $ad_group_id = 0, $custom_label_4 = '' )
|
||||
static public function get_records_total_products( $client_id, $search, $campaign_id = 0, $ad_group_id = 0, $custom_label_4 = '', $custom_label_1 = '' )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
@@ -679,6 +694,7 @@ class Products
|
||||
OR p.title LIKE :search
|
||||
OR p.offer_id LIKE :search
|
||||
OR p.custom_label_4 LIKE :search
|
||||
OR p.custom_label_1 LIKE :search
|
||||
OR c.campaign_name LIKE :search
|
||||
OR ag.ad_group_name LIKE :search
|
||||
)';
|
||||
@@ -691,6 +707,12 @@ class Products
|
||||
$params[':custom_label_4'] = '%' . $custom_label_4 . '%';
|
||||
}
|
||||
|
||||
if ( $custom_label_1 !== '' )
|
||||
{
|
||||
$sql .= ' AND p.custom_label_1 LIKE :custom_label_1';
|
||||
$params[':custom_label_1'] = '%' . $custom_label_1 . '%';
|
||||
}
|
||||
|
||||
$sql .= ' GROUP BY p.id, pa.campaign_id, pa.ad_group_id
|
||||
) AS grouped_rows';
|
||||
|
||||
@@ -760,6 +782,30 @@ class Products
|
||||
return $rows ?: [];
|
||||
}
|
||||
|
||||
static public function get_distinct_custom_label_1( $client_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$client_id = (int) $client_id;
|
||||
|
||||
if ( $client_id <= 0 )
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
$rows = $mdb -> query(
|
||||
"SELECT DISTINCT p.custom_label_1
|
||||
FROM products p
|
||||
WHERE p.client_id = :client_id
|
||||
AND p.custom_label_1 IS NOT NULL
|
||||
AND p.custom_label_1 != ''
|
||||
ORDER BY p.custom_label_1 ASC",
|
||||
[ ':client_id' => $client_id ]
|
||||
) -> fetchAll( \PDO::FETCH_COLUMN );
|
||||
|
||||
return $rows ?: [];
|
||||
}
|
||||
|
||||
static public function get_product_data( $product_id, $field )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
Reference in New Issue
Block a user