feat(admin): 添加导出退供应商功能并优化相关逻辑
- 新增导出退供应商功能,支持导出退供应商的结算单 - 优化退库和退供应商的逻辑,增加对不同退货类型的处理 - 修复仓库库存更新的相关问题 - 优化订单详情和导出功能,提高数据准确性
This commit is contained in:
parent
3166a06a56
commit
dcf7601285
@ -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]);
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
@ -394,6 +395,7 @@ class BeforehandOrderLogic extends BaseLogic
|
||||
'purchase' => $arr['purchase'],
|
||||
'oid' => $res['id'],
|
||||
'code' => $res['code'],
|
||||
'unit' => $arr['unit']??0,
|
||||
];
|
||||
WarehouseProductLogic::setOutbound($data);
|
||||
}
|
||||
@ -646,7 +648,7 @@ 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'];
|
||||
@ -656,7 +658,7 @@ class BeforehandOrderLogic extends BaseLogic
|
||||
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);
|
||||
@ -664,14 +666,14 @@ class BeforehandOrderLogic extends BaseLogic
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出退库
|
||||
* 导出退供应商
|
||||
*/
|
||||
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'];
|
||||
@ -681,7 +683,7 @@ class BeforehandOrderLogic extends BaseLogic
|
||||
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);
|
||||
|
@ -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'] ?? '',
|
||||
];
|
||||
|
@ -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;
|
||||
@ -37,12 +38,20 @@ class WarehouseProductReturnLogic extends BaseLogic
|
||||
}
|
||||
Db::startTrans();
|
||||
try {
|
||||
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('该商品没有退货记录');
|
||||
}
|
||||
}
|
||||
if ($find) {
|
||||
if ($params['return_type'] == 1) {
|
||||
if ($find['nums'] < $params['nums']) {
|
||||
throw new BusinessException('退货数量不能大于库存数量');
|
||||
}
|
||||
WarehouseProductReturn::create([
|
||||
$datas = [
|
||||
'source_id' => $params['id'],
|
||||
'bhoid' => $params['bhoid'] ?? 0,
|
||||
'warehouse_id' => $find['warehouse_id'],
|
||||
@ -57,7 +66,39 @@ class WarehouseProductReturnLogic extends BaseLogic
|
||||
'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']);
|
||||
}
|
||||
}
|
||||
$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;
|
||||
@ -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;
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user