diff --git a/app/admin/controller/beforehand_order/BeforehandOrderController.php b/app/admin/controller/beforehand_order/BeforehandOrderController.php index bca801f33..70822a825 100644 --- a/app/admin/controller/beforehand_order/BeforehandOrderController.php +++ b/app/admin/controller/beforehand_order/BeforehandOrderController.php @@ -251,4 +251,13 @@ class BeforehandOrderController extends BaseAdminController $file_path = BeforehandOrderLogic::StockReturn($params); return $this->success('导出成功', ['url' => $file_path]); } + /** + * 导出退供应商 + */ + public function return_supplier() + { + $params = $this->request->post(); + $file_path = BeforehandOrderLogic::ReturnSupplier($params); + return $this->success('导出成功', ['url' => $file_path]); + } } diff --git a/app/admin/lists/beforehand_order_cart_info/BeforehandOrderCartInfoLists.php b/app/admin/lists/beforehand_order_cart_info/BeforehandOrderCartInfoLists.php index c962dbe26..efeb9c9ba 100644 --- a/app/admin/lists/beforehand_order_cart_info/BeforehandOrderCartInfoLists.php +++ b/app/admin/lists/beforehand_order_cart_info/BeforehandOrderCartInfoLists.php @@ -78,7 +78,7 @@ class BeforehandOrderCartInfoLists extends BaseAdminDataLists implements ListsSe ->select()->each(function ($item) use ($system_store, $order_mark) { $find = StoreProduct::where('id', $item['product_id'])->field('top_cate_id,store_name,image,unit')->withTrashed()->find(); $item->unit_name = StoreProductUnit::where('id', $find->unit)->value('name'); - $item['warehouse_stock'] = WarehouseProductStorege::where('product_id', $item['product_id'])->value('nums') ?? 0; + $item['warehouse_stock'] = WarehouseProductStorege::where('product_id', $item['product_id'])->where('warehouse_id',1)->value('nums') ?? 0; $item['store_name'] = $find['store_name']; $item['system_store'] = $system_store; $item['order_mark'] = $order_mark; diff --git a/app/admin/logic/beforehand_order/BeforehandOrderLogic.php b/app/admin/logic/beforehand_order/BeforehandOrderLogic.php index c75f82e9f..964d00490 100644 --- a/app/admin/logic/beforehand_order/BeforehandOrderLogic.php +++ b/app/admin/logic/beforehand_order/BeforehandOrderLogic.php @@ -28,6 +28,7 @@ use app\common\service\xlsx\OrderAllocation; use app\common\service\xlsx\OrderInfo; use app\common\service\xlsx\OrderList; use app\common\service\xlsx\OrderOutbound; +use app\common\service\xlsx\ReturnSupplier; use app\common\service\xlsx\StockReturn; use DateTime; use support\exception\BusinessException; @@ -68,7 +69,7 @@ class BeforehandOrderLogic extends BaseLogic unset($params['product_arr'][$k]); continue; } - $total_prices=bcmul($v['price'],$v['nums'],2); + $total_prices = bcmul($v['price'], $v['nums'], 2); $datas[$k]['purchase'] = $v['purchase']; $datas[$k]['mark'] = $v['mark'] ?? ''; $datas[$k]['product_id'] = $v['product_id']; @@ -84,7 +85,7 @@ class BeforehandOrderLogic extends BaseLogic $datas[$k]['accept_num'] = $v['nums']; $datas[$k]['price'] = $v['price']; $datas[$k]['package'] = $v['package'] ?? ''; - $datas[$k]['total_price'] =$total_prices; + $datas[$k]['total_price'] = $total_prices; $datas[$k]['pay_price'] = $total_prices; $datas[$k]['create_time'] = time(); $datas[$k]['update_time'] = time(); @@ -311,13 +312,13 @@ class BeforehandOrderLogic extends BaseLogic { Db::startTrans(); try { - $find=BeforehandOrder::where('id', $params['id'])->find(); - $other_data=$find['other_data']; - if(!empty($params['other_data']['arrival_time'])){ - $other_data->arrival_time=$params['other_data']['arrival_time']; + $find = BeforehandOrder::where('id', $params['id'])->find(); + $other_data = $find['other_data']; + if (!empty($params['other_data']['arrival_time'])) { + $other_data->arrival_time = $params['other_data']['arrival_time']; } $find->save([ - 'other_data'=>json_encode($other_data, true), + 'other_data' => json_encode($other_data, true), 'file' => $params['file'], 'mark' => $params['mark'] ]); @@ -347,7 +348,7 @@ class BeforehandOrderLogic extends BaseLogic if (!$order) { throw new BusinessException('该订单不存在'); } - if($order['order_type']==5){ + if ($order['order_type'] == 5) { throw new BusinessException('仓库补货,不用出库'); } if ($order['outbound_id'] > 0) { @@ -355,8 +356,8 @@ class BeforehandOrderLogic extends BaseLogic } $info = BeforehandOrderCartInfo::where('bhoid', $params['bhoid'])->select(); foreach ($info as $k => $v) { - if($v['pay_price']<=0){ - throw new BusinessException('商品价格未空 不能生成出库订单,对应id:'.$v['id']); + if ($v['pay_price'] <= 0) { + throw new BusinessException('商品价格未空 不能生成出库订单,对应id:' . $v['id']); } } $count = BeforehandOrderCartInfo::where('bhoid', $params['bhoid'])->where('cart_num', 0)->count('id'); @@ -394,12 +395,13 @@ class BeforehandOrderLogic extends BaseLogic 'purchase' => $arr['purchase'], 'oid' => $res['id'], 'code' => $res['code'], + 'unit' => $arr['unit']??0, ]; WarehouseProductLogic::setOutbound($data); } $finds = WarehouseProduct::where('oid', $res['id'])->field('sum(nums) as nums,sum(total_price) as total_price')->find(); WarehouseOrder::where('id', $res['id'])->update(['total_price' => $finds['total_price'], 'nums' => $finds['nums']]); - $order->save(['outbound_id' => $res['id'], 'is_outbound' => 1,'pay_price'=>$finds['total_price']]); + $order->save(['outbound_id' => $res['id'], 'is_outbound' => 1, 'pay_price' => $finds['total_price']]); Db::commit(); return true; } catch (\Throwable $e) { @@ -513,7 +515,7 @@ class BeforehandOrderLogic extends BaseLogic */ public static function detail($params): array { - $res = BeforehandOrder::where('id',$params['id'])->find()->toArray(); + $res = BeforehandOrder::where('id', $params['id'])->find()->toArray(); $ids = BeforehandOrderCartInfo::where('bhoid', $params['id'])->column('product_id'); $top_cate_ids = StoreProduct::where('id', 'in', $ids)->column('top_cate_id'); if ($top_cate_ids) { @@ -618,11 +620,11 @@ class BeforehandOrderLogic extends BaseLogic { $order_info = new OrderOutbound(); $order = BeforehandOrder::where('id', $params['id'])->find(); - if($order['outbound_id']<=0){ + if ($order['outbound_id'] <= 0) { throw new BusinessException('订单未出库,不能导出出库单'); } $order['admin_name'] = Admin::where('id', $order['admin_id'])->value('name'); - $data= WarehouseProduct::where('oid',$order['outbound_id'])->where('nums','>',0)->select()->each(function ($item) { + $data = WarehouseProduct::where('oid', $order['outbound_id'])->where('nums', '>', 0)->select()->each(function ($item) { $find = StoreProduct::where('id', $item['product_id'])->field('top_cate_id,store_name,unit')->find(); $item['unit_name'] = StoreProductUnit::where('id', $find['unit'])->value('name'); $item['store_name'] = $find['store_name']; @@ -631,9 +633,9 @@ class BeforehandOrderLogic extends BaseLogic $order['system_store_name'] = SystemStore::where('id', $order['store_id'])->value('name'); $other_data = $order['other_data']; unset($order['other_data']); - $find=WarehouseOrder::where('id', $order['outbound_id'])->find(); - $order['order_id']=$find['code']; - $order['pay_price']=$find['total_price']; + $find = WarehouseOrder::where('id', $order['outbound_id'])->find(); + $order['order_id'] = $find['code']; + $order['pay_price'] = $find['total_price']; $file_path = $order_info->export($data, $order, $other_data); return $file_path; } @@ -646,42 +648,42 @@ class BeforehandOrderLogic extends BaseLogic $order_info = new StockReturn(); $order = BeforehandOrder::where('id', $params['id'])->find(); - $data= WarehouseProductReturn::where('bhoid',$order['id'])->select()->each(function ($item) { + $data = WarehouseProductReturn::where('bhoid', $order['id'])->where('return_type',1)->select()->each(function ($item) { $find = StoreProduct::where('id', $item['product_id'])->field('top_cate_id,store_name,unit')->find(); $item['unit_name'] = StoreProductUnit::where('id', $find['unit'])->value('name'); $item['store_name'] = $find['store_name']; return $item; }); - if(empty($data)){ + if (empty($data)) { throw new BusinessException('退库商品为空,不能导出退库单'); } $order['system_store_name'] = SystemStore::where('id', $order['store_id'])->value('name'); - $order['total_price'] =WarehouseProductReturn::where('bhoid',$order['id'])->sum('total_price'); + $order['total_price'] = WarehouseProductReturn::where('bhoid', $order['id'])->where('return_type',1)->sum('total_price'); $other_data = $order['other_data']; unset($order['other_data']); $file_path = $order_info->export($data, $order, $other_data); return $file_path; } - /** - * 导出退库 + /** + * 导出退供应商 */ - public static function return_supplier($params) + public static function ReturnSupplier($params) { $order_info = new ReturnSupplier(); $order = BeforehandOrder::where('id', $params['id'])->find(); - $data= WarehouseProductReturn::where('bhoid',$order['id'])->select()->each(function ($item) { + $data = WarehouseProductReturn::where('bhoid', $order['id'])->where('return_type',2)->select()->each(function ($item) { $find = StoreProduct::where('id', $item['product_id'])->field('top_cate_id,store_name,unit')->find(); $item['unit_name'] = StoreProductUnit::where('id', $find['unit'])->value('name'); $item['store_name'] = $find['store_name']; return $item; }); - if(empty($data)){ + if (empty($data)) { throw new BusinessException('退库商品为空,不能导出退库单'); } $order['system_store_name'] = SystemStore::where('id', $order['store_id'])->value('name'); - $order['total_price'] =WarehouseProductReturn::where('bhoid',$order['id'])->sum('total_price'); + $order['total_price'] = WarehouseProductReturn::where('bhoid', $order['id'])->where('return_type',2)->sum('total_price'); $other_data = $order['other_data']; unset($order['other_data']); $file_path = $order_info->export($data, $order, $other_data); diff --git a/app/admin/logic/warehouse_product/WarehouseProductLogic.php b/app/admin/logic/warehouse_product/WarehouseProductLogic.php index 99376e77e..f1aca754f 100644 --- a/app/admin/logic/warehouse_product/WarehouseProductLogic.php +++ b/app/admin/logic/warehouse_product/WarehouseProductLogic.php @@ -159,6 +159,7 @@ class WarehouseProductLogic extends BaseLogic 'total_price' => $params['total_price'] ?? 0, 'admin_id' => $params['admin_id'], 'code' => $params['code'] ?? '', + 'unit' => $params['unit'] ?? 0, 'status' => 1, 'mark' => $params['mark'] ?? '', ]; diff --git a/app/admin/logic/warehouse_product_return/WarehouseProductReturnLogic.php b/app/admin/logic/warehouse_product_return/WarehouseProductReturnLogic.php index dbea9f7c3..a2594842a 100644 --- a/app/admin/logic/warehouse_product_return/WarehouseProductReturnLogic.php +++ b/app/admin/logic/warehouse_product_return/WarehouseProductReturnLogic.php @@ -7,6 +7,7 @@ use app\common\model\warehouse_product_return\WarehouseProductReturn; use app\common\logic\BaseLogic; use app\common\model\beforehand_order\BeforehandOrder; use app\common\model\beforehand_order_cart_info\BeforehandOrderCartInfo; +use app\common\model\purchase_product_offer\PurchaseProductOffer; use app\common\model\warehouse_order\WarehouseOrder; use app\common\model\warehouse_product\WarehouseProduct; use app\common\model\warehouse_product_storege\WarehouseProductStorege; @@ -32,50 +33,90 @@ class WarehouseProductReturnLogic extends BaseLogic */ public static function add(array $params): bool { - if(empty($params['bhoid'])||$params['bhoid']==0){ + if (empty($params['bhoid']) || $params['bhoid'] == 0) { throw new BusinessException('订单id不能为空'); } Db::startTrans(); try { - $find=WarehouseProduct::where('id',$params['id'])->find(); - if($find){ - if($find['nums']<$params['nums']){ - throw new BusinessException('退货数量不能大于库存数量'); + if ($params['return_type'] == 1) { + $find = WarehouseProduct::where('id', $params['id'])->find(); + } else { + $find = WarehouseProductReturn::where('id', $params['id'])->find(); + if (empty($find)) { + throw new BusinessException('该商品没有退货记录'); } - WarehouseProductReturn::create([ - 'source_id'=>$params['id'], - 'bhoid'=>$params['bhoid']??0, - 'warehouse_id'=>$find['warehouse_id'], - 'supplier_id'=>$find['supplier_id'], - 'store_id'=>$find['store_id'], - 'product_id'=>$find['product_id'], - 'unit'=>$find['unit'], - 'financial_pm'=>$params['financial_pm'], - 'admin_id'=>$params['admin_id'], - 'nums'=>$params['nums'], - 'return_type'=>$params['return_type'], - 'mark'=>$params['mark'], - 'price'=>$find['price'], - 'total_price'=>bcmul($params['nums'],$find['price'],2), - ]); - if($params['financial_pm']==1 &&$params['return_type']==1){ - $nums=bcsub($find['nums'],$params['nums'],2); - $total_price=0; - if($nums>0){ - $total_price=bcmul($nums,$find['price'],2); + } + if ($find) { + if ($params['return_type'] == 1) { + if ($find['nums'] < $params['nums']) { + throw new BusinessException('退货数量不能大于库存数量'); } - $find->save(['nums'=>$nums,'total_price'=>$total_price]); - $total_price=WarehouseProduct::where('oid',$find['oid'])->sum('total_price'); - if($nums>0){ - WarehouseOrder::where(['id'=>$find['oid']])->update(['total_price'=>$total_price]); - BeforehandOrder::update(['pay_price'=>$total_price],['id'=>$params['bhoid']]); - }elseif($nums==0){ - WarehouseOrder::where(['id'=>$find['oid']])->update(['total_price'=>$total_price]); - BeforehandOrder::update(['pay_price'=>$total_price],['id'=>$params['bhoid']]); + $datas = [ + 'source_id' => $params['id'], + 'bhoid' => $params['bhoid'] ?? 0, + 'warehouse_id' => $find['warehouse_id'], + 'supplier_id' => $find['supplier_id'], + 'store_id' => $find['store_id'], + 'product_id' => $find['product_id'], + 'unit' => $find['unit'], + 'financial_pm' => $params['financial_pm'], + 'admin_id' => $params['admin_id'], + 'nums' => $params['nums'], + 'return_type' => $params['return_type'], + 'mark' => $params['mark'], + 'price' => $find['price'], + 'total_price' => bcmul($params['nums'], $find['price'], 2), + ]; + } else { + $proudct = WarehouseProductStorege::where(['product_id' => $find['product_id'], 'warehouse_id' => $find['warehouse_id']])->find(); + if (!$proudct) { + throw new BusinessException('该商品没有库存'); + } else { + if ($proudct['nums'] < $params['nums']) { + throw new BusinessException('该商品库存:'.$params['nums'].'小于仓库库存'.$proudct['nums']); + } } - WarehouseProductStorege::where(['product_id'=>$find['product_id'],'warehouse_id'=>$find['warehouse_id']])->inc('nums',$params['nums'])->update(); - }elseif($params['financial_pm']==0 &&$params['return_type']==2){ - WarehouseProductStorege::where(['product_id'=>$find['product_id'],'warehouse_id'=>$find['warehouse_id']])->dec('nums',$params['nums'])->update(); + $offer = PurchaseProductOffer::where('order_id', $params['bhoid'])->where('product_id', $find['product_id'])->find(); + if (!$offer) { + throw new BusinessException('该商品没有采购信息'); + } + $datas = [ + 'source_id' => $params['id'], + 'bhoid' => $params['bhoid'] ?? 0, + 'warehouse_id' => $find['warehouse_id'], + 'supplier_id' => $offer['supplier_id'], + 'store_id' => $find['store_id'], + 'product_id' => $find['product_id'], + 'unit' => $find['unit'], + 'financial_pm' => $params['financial_pm'], + 'admin_id' => $params['admin_id'], + 'nums' => $params['nums'], + 'return_type' => $params['return_type'], + 'mark' => $params['mark'], + 'price' => $offer['price'], + 'total_price' => bcmul($params['nums'], $offer['price'], 2), + ]; + } + + WarehouseProductReturn::create($datas); + if ($params['financial_pm'] == 1 && $params['return_type'] == 1) { + $nums = bcsub($find['nums'], $params['nums'], 2); + $total_price = 0; + if ($nums > 0) { + $total_price = bcmul($nums, $find['price'], 2); + } + $find->save(['nums' => $nums, 'total_price' => $total_price]); + $total_price = WarehouseProduct::where('oid', $find['oid'])->sum('total_price'); + if ($nums > 0) { + WarehouseOrder::where(['id' => $find['oid']])->update(['total_price' => $total_price]); + BeforehandOrder::update(['pay_price' => $total_price], ['id' => $params['bhoid']]); + } elseif ($nums == 0) { + WarehouseOrder::where(['id' => $find['oid']])->update(['total_price' => $total_price]); + BeforehandOrder::update(['pay_price' => $total_price], ['id' => $params['bhoid']]); + } + WarehouseProductStorege::where(['product_id' => $find['product_id'], 'warehouse_id' => $find['warehouse_id']])->inc('nums', $params['nums'])->update(); + } elseif ($params['financial_pm'] == 0 && $params['return_type'] == 2) { + WarehouseProductStorege::where(['product_id' => $find['product_id'], 'warehouse_id' => $find['warehouse_id']])->dec('nums', $params['nums'])->update(); } } @@ -100,9 +141,7 @@ class WarehouseProductReturnLogic extends BaseLogic { Db::startTrans(); try { - WarehouseProductReturn::where('id', $params['id'])->update([ - - ]); + WarehouseProductReturn::where('id', $params['id'])->update([]); Db::commit(); return true; @@ -137,4 +176,4 @@ class WarehouseProductReturnLogic extends BaseLogic { return WarehouseProductReturn::findOrEmpty($params['id'])->toArray(); } -} \ No newline at end of file +} diff --git a/app/common/service/xlsx/ReturnSupplier.php b/app/common/service/xlsx/ReturnSupplier.php index cfd734750..076724d26 100644 --- a/app/common/service/xlsx/ReturnSupplier.php +++ b/app/common/service/xlsx/ReturnSupplier.php @@ -32,7 +32,7 @@ class ReturnSupplier $sheet->getColumnDimension('H')->setAutoSize(true); $sheet->setCellValue('C2', '电话:'); - $sheet->setCellValue('D2', 08302669767); + $sheet->setCellValue('D2', '08302669767'); $sheet->setCellValue('F2', '订单编号:'); $sheet->setCellValue('G2', $order['order_id']??''); @@ -85,9 +85,9 @@ class ReturnSupplier $sheet->mergeCells('B' . ($count + 9) . ':E' . $count + 9); $sheet->setCellValue('A' . $count + 9, '销售地址:',); - $sheet->setCellValue('B' . $count + 9, '泸州市海吉星农产品商贸物流园122栋',); + $sheet->setCellValue('B' . $count + 9, '',); $sheet->setCellValue('F' . $count + 9, '电话:',); - $sheet->setCellValue('G' . $count + 9, '08302669767',); + $sheet->setCellValue('G' . $count + 9, '',); $sheet->setCellValue('H' . $count + 9, '签收:',); // 设置单元格的样式 $styleArray = [ @@ -111,7 +111,7 @@ class ReturnSupplier // 保存文件到 public 下 $writer = new Xlsx($spreadsheet); - $url = '/export/' . date('Y-m') . '/' .'供投里海农特产品退库结算单-'.date('Y-m-d H:i') . '.xlsx'; + $url = '/export/' . date('Y-m') . '/' .'供投里海农特产品退供应商结算单-'.date('Y-m-d H:i') . '.xlsx'; $file_path = public_path() . $url; // 保存文件到 public 下 $writer->save($file_path);