编辑代码




<?php 
$arr = [
           // ['product_id','warehouse_id','store_id','batch','product_count'],
         ['374','36','15','20190101','-50'],
['367','36','15','20190101','-100'],
['350','36','15','20190101','-100'],
['374','39','15','20190101','50'],
['367','39','15','20190101','100'],
['350','39','15','20190101','100'],
['374','36','15','20190101','-50'],
['367','36','15','20190101','-100'],
['350','36','15','20190101','-100'],
['374','39','15','20190101','50'],
['367','39','15','20190101','100'],
['350','39','15','20190101','100'],
        
        ];
        foreach ($arr as $item) {
            if ($item[4]> 0) {
 $sql[] = "UPDATE `kkpos_stock` set `product_count` = `product_count` - {$item[4]} where `product_id` = {$item[0]} and `warehouse_id` = {$item[1]} and `store_id` = {$item[2]} and `batch` = '{$item[3]}'  limit 1;";
            } else {
                $item[4] = abs($item[4]);
                 $sql[] = "UPDATE `kkpos_stock` set `product_count` = `product_count` + {$item[4]} where `product_id` = {$item[0]} and `warehouse_id` = {$item[1]} and `store_id` = {$item[2]} and `batch` = '{$item[3]}'  limit 1;";
            }
           
        }
        echo json_encode($sql, 256);