修改定时更新出库商品供货价
This commit is contained in:
parent
c55533e764
commit
e2a3472a11
@ -138,22 +138,24 @@ class Task
|
|||||||
*/
|
*/
|
||||||
public function setPurchase()
|
public function setPurchase()
|
||||||
{
|
{
|
||||||
$list = WarehouseProduct::where('purchase', 0)->order('id desc')->limit(100)->select()->toArray();
|
new Crontab('0 0 * * * *', function () {
|
||||||
$productIds = array_unique(array_column($list, 'product_id'));
|
$list = WarehouseProduct::where('purchase', 0)->order('id desc')->limit(100)->select()->toArray();
|
||||||
$products = StoreProduct::whereIn('id', $productIds)->field('id,purchase')->select()->toArray();
|
$productIds = array_unique(array_column($list, 'product_id'));
|
||||||
$products = reset_index($products, 'id');
|
$products = StoreProduct::whereIn('id', $productIds)->field('id,purchase')->select()->toArray();
|
||||||
$update = [];
|
$products = reset_index($products, 'id');
|
||||||
foreach ($list as $item) {
|
$update = [];
|
||||||
$product = $products[$item['product_id']] ?? [];
|
foreach ($list as $item) {
|
||||||
if (empty($product) || empty($product['purchase'])) {
|
$product = $products[$item['product_id']] ?? [];
|
||||||
continue;
|
if (empty($product) || empty($product['purchase'])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$update[] = [
|
||||||
|
'id' => $item['id'],
|
||||||
|
'purchase' => min($product['purchase'], $item['price']),
|
||||||
|
];
|
||||||
}
|
}
|
||||||
$update[] = [
|
(new WarehouseProduct())->saveAll($update);
|
||||||
'id' => $item['id'],
|
});
|
||||||
'purchase' => min($product['purchase'], $item['price']),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
(new WarehouseProduct())->saveAll($update);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user