diff --git a/app/admin/controller/inventory_transfer_order/InventoryTransferOrderController.php b/app/admin/controller/inventory_transfer_order/InventoryTransferOrderController.php new file mode 100644 index 000000000..26c3147b8 --- /dev/null +++ b/app/admin/controller/inventory_transfer_order/InventoryTransferOrderController.php @@ -0,0 +1,95 @@ +dataLists(new InventoryTransferOrderLists()); + } + + + /** + * @notes 添加商品调拨订单 + * @return \think\response\Json + * @author admin + * @date 2025/01/24 09:59 + */ + public function add() + { + $params = $this->request->post(); + $result = InventoryTransferOrderLogic::add($params,$this->adminId); + if (true === $result) { + return $this->success('添加成功', [], 1, 1); + } + return $this->fail(InventoryTransferOrderLogic::getError()); + } + + + /** + * @notes 编辑商品调拨订单 + * @return \think\response\Json + * @author admin + * @date 2025/01/24 09:59 + */ + public function edit() + { + $params = (new InventoryTransferOrderValidate())->post()->goCheck('edit'); + $result = InventoryTransferOrderLogic::edit($params); + if (true === $result) { + return $this->success('编辑成功', [], 1, 1); + } + return $this->fail(InventoryTransferOrderLogic::getError()); + } + + + /** + * @notes 删除商品调拨订单 + * @return \think\response\Json + * @author admin + * @date 2025/01/24 09:59 + */ + public function delete() + { + $params = (new InventoryTransferOrderValidate())->post()->goCheck('delete'); + InventoryTransferOrderLogic::delete($params); + return $this->success('删除成功', [], 1, 1); + } + + + /** + * @notes 获取商品调拨订单详情 + * @return \think\response\Json + * @author admin + * @date 2025/01/24 09:59 + */ + public function detail() + { + $params = (new InventoryTransferOrderValidate())->goCheck('detail'); + $result = InventoryTransferOrderLogic::detail($params); + return $this->data($result); + } + + +} \ No newline at end of file diff --git a/app/admin/lists/inventory_transfer_order/InventoryTransferOrderLists.php b/app/admin/lists/inventory_transfer_order/InventoryTransferOrderLists.php new file mode 100644 index 000000000..5d6230c84 --- /dev/null +++ b/app/admin/lists/inventory_transfer_order/InventoryTransferOrderLists.php @@ -0,0 +1,89 @@ + ['order_id', 'one_type', 'two_type', 'types'], + ]; + } + + + /** + * @notes 获取商品调拨订单列表 + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author admin + * @date 2025/01/24 09:59 + */ + public function lists(): array + { + return InventoryTransferOrder::where($this->searchWhere) + ->field(['id', 'order_id', 'one_id', 'one_type', 'two_id', 'two_type', 'types', 'total_nums', 'total_price']) + ->limit($this->limitOffset, $this->limitLength) + ->order(['id' => 'desc']) + ->select()->each(function ($item) { + $type_name=''; + if($item->one_type==1){ + $item->one_name=SystemStore::where('id',$item->one_id)->value('name'); + $type_name='门店转'; + }else{ + $item->one_name=Warehouse::where('id',$item->one_id)->value('name'); + $type_name='仓库转'; + } + if($item->two_type==1){ + $type_name.='门店'; + $item->two_name=SystemStore::where('id',$item->two_id)->value('name'); + }else{ + $type_name.='仓库'; + $item->two_name=Warehouse::where('id',$item->two_id)->value('name'); + } + $item->type_name=$type_name; + if($item->types==0){ + $item->types_name='正常减库'; + }else{ + $item->types_name='异常数据'; + } + }) + + ->toArray(); + } + + + /** + * @notes 获取商品调拨订单数量 + * @return int + * @author admin + * @date 2025/01/24 09:59 + */ + public function count(): int + { + return InventoryTransferOrder::where($this->searchWhere)->count(); + } +} diff --git a/app/admin/lists/purchase_product_offer/PurchaseProductOfferLists.php b/app/admin/lists/purchase_product_offer/PurchaseProductOfferLists.php index c04983240..5bed0f8d3 100644 --- a/app/admin/lists/purchase_product_offer/PurchaseProductOfferLists.php +++ b/app/admin/lists/purchase_product_offer/PurchaseProductOfferLists.php @@ -33,7 +33,7 @@ class PurchaseProductOfferLists extends BaseAdminDataLists implements ListsSearc public function setSearch(): array { return [ - '=' => ['order_id','buyer_confirm','buyer_id'], + '=' => ['order_id','buyer_confirm','buyer_id','is_storage'], ]; } diff --git a/app/admin/logic/inventory_transfer/InventoryTransferLogic.php b/app/admin/logic/inventory_transfer/InventoryTransferLogic.php index f8cc56ffb..9193f94c9 100644 --- a/app/admin/logic/inventory_transfer/InventoryTransferLogic.php +++ b/app/admin/logic/inventory_transfer/InventoryTransferLogic.php @@ -30,91 +30,7 @@ class InventoryTransferLogic extends BaseLogic */ public static function add(array $params,$admin_id=0): bool { - if (empty($params['product_arr'])) { - throw new BusinessException('请选择商品'); - } - $productIds = array_column($params['product_arr'], 'product_id'); - if ($params['one_type'] == 1) { - $outProducts = StoreBranchProduct::whereIn('product_id', $productIds)->where('store_id', $params['one_id'])->field('id,product_id,stock')->select()->toArray(); - } else { - $outProducts = WarehouseProductStorege::whereIn('product_id', $productIds)->where('warehouse_id', $params['one_id'])->field('id,product_id,nums stock')->select()->toArray(); - } - $outProducts = reset_index($outProducts, 'product_id'); - if ($params['two_type'] == 1) { - $inProducts = StoreBranchProduct::whereIn('product_id', $productIds)->where('store_id', $params['two_id'])->field('id,product_id,stock')->select()->toArray(); - } else { - $inProducts = WarehouseProductStorege::whereIn('product_id', $productIds)->where('warehouse_id', $params['two_id'])->field('id,product_id,nums stock')->select()->toArray(); - } - $inProducts = reset_index($inProducts, 'product_id'); - $insert = []; - foreach ($params['product_arr'] as $v) { - $outProduct = !empty($outProducts[$v['product_id']]) ? $outProducts[$v['product_id']] : ['stock' => 0, 'id' => 0, 'product_id' => $v['product_id']]; - $inProduct = !empty($inProducts[$v['product_id']]) ? $inProducts[$v['product_id']] : ['stock' => 0, 'id' => 0, 'product_id' => $v['product_id']]; - if ($outProduct['stock'] < $v['nums']) { - throw new BusinessException("出库商品 {$outProduct['product_id']} 调拨数量不能大于当前仓库库存"); - } - $insert[] = [ - 'product_id' => $v['product_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' => $params['one_type'], - 'two_type' => $params['two_type'], - 'one_id' => $params['one_id'], - 'two_id' => $params['two_id'], - 'create_time' => time(), - ]; - } - - Db::startTrans(); - try { - InventoryTransfer::insertAll($insert); - foreach ($insert as $v) { - if($params['one_type']==1){ - $find=StoreBranchProduct::where('product_id', $v['product_id'])->where('store_id', $params['one_id'])->find(); - $find->save(['stock' =>bcsub( $find['stock'],$v['nums'],2)]); - SqlChannelLog('StoreBranchProduct', $find['id'], $v['nums'], -1, Request()->url(),$admin_id); - } elseif ($params['one_type'] == 2) { - $find=WarehouseProductStorege::where('product_id', $v['product_id'])->where('warehouse_id', $params['one_id'])->find(); - $find->save(['nums' =>bcsub( $find['nums'],$v['nums'],2)]); - SqlChannelLog('WarehouseProductStorege', $find['id'], $v['nums'], -1, Request()->url(),$admin_id); - } - if($params['two_type']==1){ - $find=StoreBranchProduct::where('product_id', $v['product_id'])->where('store_id', $params['two_id'])->find(); - if (empty($find)) { - $storeProduct = StoreProduct::field('top_cate_id,two_cate_id,cate_id,store_name,image,price,vip_price,cost,purchase,keyword,bar_code,store_info,rose,product_type,unit,batch,store_batch,label_id,is_lack,manufacturer_information')->where('id', $v['product_id'])->find()->toArray(); - $find = new StoreBranchProduct(); - $find->product_id = $v['product_id']; - $find->store_id = $params['two_id']; - $find->stock = $v['nums']; - $find->setAttrs($storeProduct); - $find->save(); - } else { - $find->save(['stock' =>bcadd( $find['stock'],$v['nums'],2)]); - } - SqlChannelLog('StoreBranchProduct', $find['id'], $v['nums'], 1, Request()->url(),$admin_id); - } elseif ($params['two_type'] == 2) { - $find=WarehouseProductStorege::where('product_id', $v['product_id'])->where('warehouse_id', $params['two_id'])->find(); - if (empty($find)) { - $find = new WarehouseProductStorege(); - $find->warehouse_id = $params['two_id']; - $find->product_id = $v['product_id']; - $find->nums = $v['nums']; - $find->save(); - } else { - $find->save(['nums' =>bcadd( $find['nums'],$v['nums'],2)]); - } - SqlChannelLog('WarehouseProductStorege', $find['id'], $v['nums'], 1, Request()->url(),$admin_id); - } - } - Db::commit(); - return true; - } catch (\Throwable $e) { - Db::rollback(); - throw new BusinessException($e->getMessage()); - } + return true; } /** diff --git a/app/admin/logic/inventory_transfer_order/InventoryTransferOrderLogic.php b/app/admin/logic/inventory_transfer_order/InventoryTransferOrderLogic.php new file mode 100644 index 000000000..b4bd2a5e8 --- /dev/null +++ b/app/admin/logic/inventory_transfer_order/InventoryTransferOrderLogic.php @@ -0,0 +1,190 @@ +where('store_id', $params['one_id'])->field('id,product_id,stock')->select()->toArray(); + } else { + $outProducts = WarehouseProductStorege::whereIn('product_id', $productIds)->where('warehouse_id', $params['one_id'])->field('id,product_id,nums stock')->select()->toArray(); + } + $outProducts = reset_index($outProducts, 'product_id'); + if ($params['two_type'] == 1) { + $inProducts = StoreBranchProduct::whereIn('product_id', $productIds)->where('store_id', $params['two_id'])->field('id,product_id,stock')->select()->toArray(); + } else { + $inProducts = WarehouseProductStorege::whereIn('product_id', $productIds)->where('warehouse_id', $params['two_id'])->field('id,product_id,nums stock')->select()->toArray(); + } + $inProducts = reset_index($inProducts, 'product_id'); + $insert = []; + + + Db::startTrans(); + try { + foreach ($params['product_arr'] as $v) { + $outProduct = !empty($outProducts[$v['product_id']]) ? $outProducts[$v['product_id']] : ['stock' => 0, 'id' => 0, 'product_id' => $v['product_id']]; + $inProduct = !empty($inProducts[$v['product_id']]) ? $inProducts[$v['product_id']] : ['stock' => 0, 'id' => 0, 'product_id' => $v['product_id']]; + if ($outProduct['stock'] < $v['nums']) { + throw new BusinessException("出库商品 {$outProduct['product_id']} 调拨数量不能大于当前仓库库存"); + } + $insert[] = [ + 'product_id' => $v['product_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' => $params['one_type'], + 'two_type' => $params['two_type'], + 'one_id' => $params['one_id'], + 'two_id' => $params['two_id'], + 'create_time' => time(), + ]; + } + $order=InventoryTransferOrder::create([ + 'order_id' => getNewOrderId('DB'), + 'one_type' => $params['one_type'], + 'two_type' => $params['two_type'], + 'one_id' => $params['one_id'], + 'two_id' => $params['two_id'], + 'types' => $params['types']??0, + 'mark' => $params['mark']??'', + ]); + foreach ($insert as $k => $v) { + $insert[$k]['oid'] = $order['id']; + } + InventoryTransfer::insertAll($insert); + foreach ($insert as $v) { + if($params['one_type']==1){ + $find=StoreBranchProduct::where('product_id', $v['product_id'])->where('store_id', $params['one_id'])->find(); + $find->save(['stock' =>bcsub( $find['stock'],$v['nums'],2)]); + SqlChannelLog('StoreBranchProduct', $find['id'], $v['nums'], -1, Request()->url(),$admin_id); + } elseif ($params['one_type'] == 2) { + $find=WarehouseProductStorege::where('product_id', $v['product_id'])->where('warehouse_id', $params['one_id'])->find(); + $find->save(['nums' =>bcsub( $find['nums'],$v['nums'],2)]); + SqlChannelLog('WarehouseProductStorege', $find['id'], $v['nums'], -1, Request()->url(),$admin_id); + } + if($params['two_type']==1){ + $find=StoreBranchProduct::where('product_id', $v['product_id'])->where('store_id', $params['two_id'])->find(); + if (empty($find)) { + $storeProduct = StoreProduct::field('top_cate_id,two_cate_id,cate_id,store_name,image,price,vip_price,cost,purchase,keyword,bar_code,store_info,rose,product_type,unit,batch,store_batch,label_id,is_lack,manufacturer_information')->where('id', $v['product_id'])->find()->toArray(); + $find = new StoreBranchProduct(); + $find->product_id = $v['product_id']; + $find->store_id = $params['two_id']; + $find->stock = $v['nums']; + $find->setAttrs($storeProduct); + $find->save(); + } else { + $find->save(['stock' =>bcadd( $find['stock'],$v['nums'],2)]); + } + SqlChannelLog('StoreBranchProduct', $find['id'], $v['nums'], 1, Request()->url(),$admin_id); + } elseif ($params['two_type'] == 2) { + $find=WarehouseProductStorege::where('product_id', $v['product_id'])->where('warehouse_id', $params['two_id'])->find(); + if (empty($find)) { + $find = new WarehouseProductStorege(); + $find->warehouse_id = $params['two_id']; + $find->product_id = $v['product_id']; + $find->nums = $v['nums']; + $find->save(); + } else { + $find->save(['nums' =>bcadd( $find['nums'],$v['nums'],2)]); + } + SqlChannelLog('WarehouseProductStorege', $find['id'], $v['nums'], 1, Request()->url(),$admin_id); + } + } + Db::commit(); + return true; + } catch (\Throwable $e) { + Db::rollback(); + throw new BusinessException($e->getMessage()); + } + } + + + /** + * @notes 编辑商品调拨订单 + * @param array $params + * @return bool + * @author admin + * @date 2025/01/24 09:59 + */ + public static function edit(array $params): bool + { + Db::startTrans(); + try { + InventoryTransferOrder::where('id', $params['id'])->update([ + 'order_id' => $params['order_id'], + 'one_id' => $params['one_id'], + 'one_type' => $params['one_type'], + 'two_id' => $params['two_id'], + 'two_type' => $params['two_type'], + 'types' => $params['types'], + 'total_nums' => $params['total_nums'], + 'total_price' => $params['total_price'] + ]); + + Db::commit(); + return true; + } catch (\Throwable $e) { + Db::rollback(); + throw new BusinessException($e->getMessage()); + } + } + + + /** + * @notes 删除商品调拨订单 + * @param array $params + * @return bool + * @author admin + * @date 2025/01/24 09:59 + */ + public static function delete(array $params): bool + { + return InventoryTransferOrder::destroy($params['id']); + } + + + /** + * @notes 获取商品调拨订单详情 + * @param $params + * @return array + * @author admin + * @date 2025/01/24 09:59 + */ + public static function detail($params): array + { + return InventoryTransferOrder::findOrEmpty($params['id'])->toArray(); + } +} \ No newline at end of file diff --git a/app/admin/validate/inventory_transfer_order/InventoryTransferOrderValidate.php b/app/admin/validate/inventory_transfer_order/InventoryTransferOrderValidate.php new file mode 100644 index 000000000..34da6beea --- /dev/null +++ b/app/admin/validate/inventory_transfer_order/InventoryTransferOrderValidate.php @@ -0,0 +1,82 @@ + 'require', + ]; + + + /** + * 参数描述 + * @var string[] + */ + protected $field = [ + 'id' => 'id', + ]; + + + /** + * @notes 添加场景 + * @return InventoryTransferOrderValidate + * @author admin + * @date 2025/01/24 09:59 + */ + public function sceneAdd() + { + return $this->remove('id', true); + } + + + /** + * @notes 编辑场景 + * @return InventoryTransferOrderValidate + * @author admin + * @date 2025/01/24 09:59 + */ + public function sceneEdit() + { + return $this->only(['id']); + } + + + /** + * @notes 删除场景 + * @return InventoryTransferOrderValidate + * @author admin + * @date 2025/01/24 09:59 + */ + public function sceneDelete() + { + return $this->only(['id']); + } + + + /** + * @notes 详情场景 + * @return InventoryTransferOrderValidate + * @author admin + * @date 2025/01/24 09:59 + */ + public function sceneDetail() + { + return $this->only(['id']); + } + +} \ No newline at end of file diff --git a/app/common/model/inventory_transfer_order/InventoryTransferOrder.php b/app/common/model/inventory_transfer_order/InventoryTransferOrder.php new file mode 100644 index 000000000..630baa8f7 --- /dev/null +++ b/app/common/model/inventory_transfer_order/InventoryTransferOrder.php @@ -0,0 +1,22 @@ +