调拨订单导出和插入修改1
This commit is contained in:
parent
83fe8c4539
commit
5e378a3372
@ -40,7 +40,6 @@ class InventoryTransferController extends BaseAdminController
|
||||
public function add()
|
||||
{
|
||||
$params = $this->request->post();
|
||||
// $params = (new InventoryTransferValidate())->post()->goCheck('add');
|
||||
$result = InventoryTransferLogic::add($params, $this->adminId);
|
||||
if (true === $result) {
|
||||
return $this->success('添加成功', [], 1, 1);
|
||||
@ -93,17 +92,4 @@ class InventoryTransferController extends BaseAdminController
|
||||
$result = InventoryTransferLogic::detail($params);
|
||||
return $this->data($result);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 导出调拨表格
|
||||
*/
|
||||
public function export()
|
||||
{
|
||||
$params = $this->request->post();
|
||||
$xlsx = new InventoryTransferXlsx();
|
||||
$order = InventoryTransferOrderLogic::detail($params);
|
||||
$file_path = $xlsx->export($order['product_list'], $order);
|
||||
return $this->success('导出成功', ['url' => $file_path]);
|
||||
}
|
||||
}
|
||||
|
@ -104,4 +104,16 @@ class InventoryTransferOrderController extends BaseAdminController
|
||||
InventoryTransferOrderLogic::audit($order);
|
||||
return $this->success('删除成功', [], 1, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出调拨表格
|
||||
*/
|
||||
public function export()
|
||||
{
|
||||
$params = $this->request->post();
|
||||
$xlsx = new InventoryTransferXlsx();
|
||||
$order = InventoryTransferOrderLogic::detail($params);
|
||||
$file_path = $xlsx->export($order['product_list'], $order);
|
||||
return $this->success('导出成功', ['url' => $file_path]);
|
||||
}
|
||||
}
|
||||
|
@ -30,10 +30,9 @@ class InventoryTransferLogic extends BaseLogic
|
||||
* @author admin
|
||||
* @date 2024/08/13 16:18
|
||||
*/
|
||||
public static function add(array $params, $admin_id = 0): bool
|
||||
public static function add(array $params, $admin_id = 0)
|
||||
{
|
||||
$find = InventoryTransferOrder::where('id', $params['oid'])->find()->toArray();
|
||||
$types = $find['types'] ?? 0;
|
||||
if (empty($params['product_arr'])) {
|
||||
throw new BusinessException('请选择商品');
|
||||
}
|
||||
@ -54,12 +53,12 @@ class InventoryTransferLogic extends BaseLogic
|
||||
Db::startTrans();
|
||||
try {
|
||||
$insert = [];
|
||||
|
||||
foreach ($params['product_arr'] as $v) {
|
||||
$outProduct = !empty($outProducts[$v['id']]) ? $outProducts[$v['id']] : ['stock' => 0, 'id' => 0, 'product_id' => $v['id']];
|
||||
$inProduct = !empty($inProducts[$v['id']]) ? $inProducts[$v['id']] : ['stock' => 0, 'id' => 0, 'product_id' => $v['id']];
|
||||
if ($outProduct['stock'] < $v['nums']) {
|
||||
throw new BusinessException("出库商品库存不足 {$outProduct['product_id']} 调拨数量不能大于当前仓库库存");
|
||||
continue;
|
||||
}
|
||||
$insert[] = [
|
||||
'oid' => $find['id'],
|
||||
@ -77,14 +76,14 @@ class InventoryTransferLogic extends BaseLogic
|
||||
];
|
||||
}
|
||||
InventoryTransfer::insertAll($insert);
|
||||
if ($types == 0 && $params['two_type'] == 1) {
|
||||
InventoryTransferOrderLogic::audit($params, $insert, $admin_id);
|
||||
if ($find['two_type'] == 1) {
|
||||
InventoryTransferOrderLogic::audit($find, $insert, $admin_id);
|
||||
}
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
} catch (\Throwable $e) {
|
||||
Db::rollback();
|
||||
return false;
|
||||
throw new BusinessException($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -300,7 +300,7 @@ class ProductSourceLinkInfoLogic extends BaseLogic
|
||||
'warehouse_id' => $this->info['warehouse_id'],
|
||||
'store_id' => $this->info['store_id'],
|
||||
'oid' => $item['oid'],
|
||||
'types' => empty($this->info['types']) ? ProductSourceLinkInfo::TypeOut: $this->info['types'],
|
||||
'types' => empty($this->info['types']) ? ProductSourceLinkInfo::TypeOut : $this->info['types'],
|
||||
'link_id' => $this->info['link_id'],
|
||||
'from_id' => $item['id'],
|
||||
'nums' => $needNum,
|
||||
@ -474,10 +474,10 @@ class ProductSourceLinkInfoLogic extends BaseLogic
|
||||
foreach ($list as $item) {
|
||||
$currentNum = max(bcsub($item['current_nums'], $needNum, 2), 0);
|
||||
if ($item['current_nums'] > $needNum) {
|
||||
[$update, $insert] = $this->getInsertAndUpdate2($update, $insert, $currentNum, $item, $needNum);
|
||||
[$update, $insert] = $this->getInsertAndUpdate($update, $insert, $currentNum, $item, $needNum);
|
||||
break;
|
||||
} else {
|
||||
[$update, $insert] = $this->getInsertAndUpdate2($update, $insert, 0, $item, $item['current_nums']);
|
||||
[$update, $insert] = $this->getInsertAndUpdate($update, $insert, 0, $item, $item['current_nums']);
|
||||
}
|
||||
$needNum = $needNum - $item['current_nums'];
|
||||
}
|
||||
@ -542,5 +542,4 @@ class ProductSourceLinkInfoLogic extends BaseLogic
|
||||
(new ProductSourceLinkInfo())->insertAll($insert);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user