调拨订单导出和插入修改
This commit is contained in:
parent
d05a8c842d
commit
95514a0da6
@ -7,7 +7,8 @@ use app\admin\controller\BaseAdminController;
|
|||||||
use app\admin\lists\inventory_transfer\InventoryTransferLists;
|
use app\admin\lists\inventory_transfer\InventoryTransferLists;
|
||||||
use app\admin\logic\inventory_transfer\InventoryTransferLogic;
|
use app\admin\logic\inventory_transfer\InventoryTransferLogic;
|
||||||
use app\admin\validate\inventory_transfer\InventoryTransferValidate;
|
use app\admin\validate\inventory_transfer\InventoryTransferValidate;
|
||||||
|
use app\admin\logic\inventory_transfer_order\InventoryTransferOrderLogic;
|
||||||
|
use app\common\service\xlsx\InventoryTransferXlsx;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 商品调拨控制器
|
* 商品调拨控制器
|
||||||
@ -39,7 +40,7 @@ class InventoryTransferController extends BaseAdminController
|
|||||||
public function add()
|
public function add()
|
||||||
{
|
{
|
||||||
$params = (new InventoryTransferValidate())->post()->goCheck('add');
|
$params = (new InventoryTransferValidate())->post()->goCheck('add');
|
||||||
$result = InventoryTransferLogic::add($params,$this->adminId);
|
$result = InventoryTransferLogic::add($params, $this->adminId);
|
||||||
if (true === $result) {
|
if (true === $result) {
|
||||||
return $this->success('添加成功', [], 1, 1);
|
return $this->success('添加成功', [], 1, 1);
|
||||||
}
|
}
|
||||||
@ -93,4 +94,15 @@ class InventoryTransferController extends BaseAdminController
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
/**
|
||||||
|
* 导出调拨表格
|
||||||
|
*/
|
||||||
|
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,33 +104,4 @@ class InventoryTransferOrderController extends BaseAdminController
|
|||||||
InventoryTransferOrderLogic::audit($order);
|
InventoryTransferOrderLogic::audit($order);
|
||||||
return $this->success('删除成功', [], 1, 1);
|
return $this->success('删除成功', [], 1, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @notes 审核商品调拨订单
|
|
||||||
* @author admin
|
|
||||||
* @date 2025/01/24 09:59
|
|
||||||
*/
|
|
||||||
public function insert()
|
|
||||||
{
|
|
||||||
$params = $this->request->post();
|
|
||||||
$result = InventoryTransferOrderLogic::insert($params, $this->adminId);
|
|
||||||
if (true == $result) {
|
|
||||||
return $this->success('添加成功', [], 1, 1);
|
|
||||||
}
|
|
||||||
return $this->fail(InventoryTransferOrderLogic::getError());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 导出调拨表格
|
|
||||||
*/
|
|
||||||
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]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -4,10 +4,12 @@ namespace app\admin\logic\inventory_transfer;
|
|||||||
|
|
||||||
use app\admin\logic\warehouse_product\WarehouseProductLogic;
|
use app\admin\logic\warehouse_product\WarehouseProductLogic;
|
||||||
use app\common\model\inventory_transfer\InventoryTransfer;
|
use app\common\model\inventory_transfer\InventoryTransfer;
|
||||||
|
use app\admin\logic\inventory_transfer_order\InventoryTransferOrderLogic;
|
||||||
use app\common\logic\BaseLogic;
|
use app\common\logic\BaseLogic;
|
||||||
use app\common\model\store_branch_product\StoreBranchProduct;
|
use app\common\model\store_branch_product\StoreBranchProduct;
|
||||||
use app\common\model\store_product\StoreProduct;
|
use app\common\model\store_product\StoreProduct;
|
||||||
use app\common\model\warehouse_product_storege\WarehouseProductStorege;
|
use app\common\model\warehouse_product_storege\WarehouseProductStorege;
|
||||||
|
use app\common\model\inventory_transfer_order\InventoryTransferOrder;
|
||||||
use support\exception\BusinessException;
|
use support\exception\BusinessException;
|
||||||
use think\facade\Db;
|
use think\facade\Db;
|
||||||
|
|
||||||
@ -28,9 +30,62 @@ class InventoryTransferLogic extends BaseLogic
|
|||||||
* @author admin
|
* @author admin
|
||||||
* @date 2024/08/13 16:18
|
* @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): bool
|
||||||
{
|
{
|
||||||
return true;
|
$find = InventoryTransferOrder::where('id', $params['oid'])->find()->toArray();
|
||||||
|
$types = $find['types'] ?? 0;
|
||||||
|
if (empty($params['product_arr'])) {
|
||||||
|
throw new BusinessException('请选择商品');
|
||||||
|
}
|
||||||
|
$productIds = array_column($params['product_arr'], 'id');
|
||||||
|
if ($find['one_type'] == 1) {
|
||||||
|
$outProducts = StoreBranchProduct::whereIn('product_id', $productIds)->where('store_id', $find['one_id'])->field('id,product_id,stock')->select()->toArray();
|
||||||
|
} else {
|
||||||
|
$outProducts = WarehouseProductStorege::whereIn('product_id', $productIds)->where('warehouse_id', $find['one_id'])->field('id,product_id,nums stock')->select()->toArray();
|
||||||
|
}
|
||||||
|
$outProducts = reset_index($outProducts, 'product_id');
|
||||||
|
if ($find['two_type'] == 1) {
|
||||||
|
$inProducts = StoreBranchProduct::whereIn('product_id', $productIds)->where('store_id', $find['two_id'])->field('id,product_id,stock')->select()->toArray();
|
||||||
|
} else {
|
||||||
|
$inProducts = WarehouseProductStorege::whereIn('product_id', $productIds)->where('warehouse_id', $find['two_id'])->field('id,product_id,nums stock')->select()->toArray();
|
||||||
|
}
|
||||||
|
$inProducts = reset_index($inProducts, 'product_id');
|
||||||
|
$insert = [];
|
||||||
|
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("{$v['nums']}-{$outProduct['stock']}出库商品{$find['one_id']} 库存不足 {$outProduct['product_id']} 调拨数量不能大于当前仓库库存");
|
||||||
|
}
|
||||||
|
$insert[] = [
|
||||||
|
'oid' => $find['id'],
|
||||||
|
'product_id' => $v['id'],
|
||||||
|
'nums' => $v['nums'],
|
||||||
|
'one_before_nums' => $outProduct['stock'],
|
||||||
|
'one_after_nums' => bcsub($outProduct['stock'], $v['nums']),
|
||||||
|
'two_before_nums' => $inProduct['stock'],
|
||||||
|
'two_after_nums' => bcadd($inProduct['stock'], $v['nums']),
|
||||||
|
'one_type' => $find['one_type'],
|
||||||
|
'two_type' => $find['two_type'],
|
||||||
|
'one_id' => $find['one_id'],
|
||||||
|
'two_id' => $find['two_id'],
|
||||||
|
'create_time' => time(),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
InventoryTransfer::insertAll($insert);
|
||||||
|
if ($types == 0 && $params['two_type'] == 1) {
|
||||||
|
InventoryTransferOrderLogic::audit($params, $insert, $admin_id);
|
||||||
|
}
|
||||||
|
Db::commit();
|
||||||
|
return true;
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
Db::rollback();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -233,65 +233,4 @@ class InventoryTransferOrderLogic extends BaseLogic
|
|||||||
->toArray();
|
->toArray();
|
||||||
return $data->toArray();
|
return $data->toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 插入调拨订单
|
|
||||||
*/
|
|
||||||
public static function insert($params, $admin_id)
|
|
||||||
{
|
|
||||||
$find = InventoryTransferOrder::where('id', $params['oid'])->find()->toArray();
|
|
||||||
$types = $find['types'] ?? 0;
|
|
||||||
if (empty($params['product_arr'])) {
|
|
||||||
throw new BusinessException('请选择商品');
|
|
||||||
}
|
|
||||||
$productIds = array_column($params['product_arr'], 'id');
|
|
||||||
if ($find['one_type'] == 1) {
|
|
||||||
$outProducts = StoreBranchProduct::whereIn('product_id', $productIds)->where('store_id', $find['one_id'])->field('id,product_id,stock')->select()->toArray();
|
|
||||||
} else {
|
|
||||||
$outProducts = WarehouseProductStorege::whereIn('product_id', $productIds)->where('warehouse_id', $find['one_id'])->field('id,product_id,nums stock')->select()->toArray();
|
|
||||||
}
|
|
||||||
$outProducts = reset_index($outProducts, 'product_id');
|
|
||||||
if ($find['two_type'] == 1) {
|
|
||||||
$inProducts = StoreBranchProduct::whereIn('product_id', $productIds)->where('store_id', $find['two_id'])->field('id,product_id,stock')->select()->toArray();
|
|
||||||
} else {
|
|
||||||
$inProducts = WarehouseProductStorege::whereIn('product_id', $productIds)->where('warehouse_id', $find['two_id'])->field('id,product_id,nums stock')->select()->toArray();
|
|
||||||
}
|
|
||||||
$inProducts = reset_index($inProducts, 'product_id');
|
|
||||||
$insert = [];
|
|
||||||
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("{$v['nums']}-{$outProduct['stock']}出库商品{$find['one_id']} 库存不足 {$outProduct['product_id']} 调拨数量不能大于当前仓库库存");
|
|
||||||
}
|
|
||||||
$insert[] = [
|
|
||||||
'oid' => $find['id'],
|
|
||||||
'product_id' => $v['id'],
|
|
||||||
'nums' => $v['nums'],
|
|
||||||
'one_before_nums' => $outProduct['stock'],
|
|
||||||
'one_after_nums' => bcsub($outProduct['stock'], $v['nums']),
|
|
||||||
'two_before_nums' => $inProduct['stock'],
|
|
||||||
'two_after_nums' => bcadd($inProduct['stock'], $v['nums']),
|
|
||||||
'one_type' => $find['one_type'],
|
|
||||||
'two_type' => $find['two_type'],
|
|
||||||
'one_id' => $find['one_id'],
|
|
||||||
'two_id' => $find['two_id'],
|
|
||||||
'create_time' => time(),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
InventoryTransfer::insertAll($insert);
|
|
||||||
if ($types == 0 && $params['two_type'] == 1) {
|
|
||||||
self::audit($params, $insert, $admin_id);
|
|
||||||
}
|
|
||||||
Db::commit();
|
|
||||||
return true;
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
Db::rollback();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user