Ejemplo n.º 1
0
<?php

$stock_model = new shopStockModel();
$n = $stock_model->countAll();
if ($n > 0) {
    // repair invariant: all N stocks exists, but sku_cout IS NULL
    $sql = "\n    UPDATE shop_product_skus s JOIN (        \n        SELECT sk.id, SUM(st.count) cnt\n        FROM shop_product_skus sk\n        JOIN shop_product_stocks st ON sk.id = st.sku_id\n        WHERE sk.count IS NULL\n        GROUP BY sk.id\n        HAVING COUNT( * ) = {$n}\n    ) AS t ON s.id = t.id\n    SET s.count = t.cnt";
    $stock_model->exec($sql);
    $product_model = new shopProductModel();
    $product_model->correctCount();
}