一键报损

This commit is contained in:
mkm 2024-12-14 17:29:27 +08:00
parent c64b1df075
commit f81575085f
3 changed files with 96 additions and 10 deletions

View File

@ -98,7 +98,17 @@ class BeforehandOrderController extends BaseAdminController
return $this->success('出库成功', [], 1, 1);
}
/**
* 一键报损出库
*/
public function createOutboundDamageOrder()
{
$params = $this->request->post();
$params['admin_id'] = $this->adminId;
$result = BeforehandOrderLogic::createOutboundOrder($params);
return $this->success('出库成功', [], 1, 1);
}
/**
* @notes 订单转预定单
* @return \think\response\Json

View File

@ -414,6 +414,80 @@ class BeforehandOrderLogic extends BaseLogic
throw new BusinessException($e->getMessage());
}
}
/**
* @notes 一键报损出库
* @param array $params
* @return bool
* @author admin
* @date 2024/09/30 11:26
*/
public static function createOutboundDamageOrder(array $params): bool
{
$warehouse_id = $params['warehouse_id'];
$admin_id = $params['admin_id'];
$mark = $params['remark'] ?? '';
$order = BeforehandOrder::where('id', $params['id'])->find();
if (!$order) {
throw new BusinessException('该订单不存在');
}
if ($order['order_type'] != 7) {
throw new BusinessException('不是报损单,无法出库');
}
if ($order['outbound_id'] > 0) {
throw new BusinessException('该订单已创建出库单');
}
$info = BeforehandOrderCartInfo::where('bhoid', $params['id'])->select();
$count = BeforehandOrderCartInfo::where('bhoid', $params['bhoid'])->where('cart_num', 0)->count('id');
if ($count > 0) {
throw new BusinessException('订单中有数量为0的商品请先处理');
}
Db::startTrans();
try {
$arr = [
'oid' => 0,
'warehouse_id' => $warehouse_id,
'store_id' => 0,
'supplier_id' => 0,
'code' => getNewOrderId('BS'),
'admin_id' => $admin_id,
'financial_pm' => 0,
'batch' => 0,
'mark' => $mark,
];
$arr['delivery_time'] = time();
$res = WarehouseOrder::create($arr);
foreach ($info as $key => $arr) {
$data = [
'warehouse_id' => $warehouse_id,
'product_id' => $arr['product_id'],
'store_id' => 0,
'financial_pm' => 0,
'batch' => 1,
'order_type' => $order['order_type'],
'nums' => $arr['cart_num'],
'status' => 1,
'admin_id' => $admin_id,
'total_price' => $arr['total_price'],
'price' => $arr['price'],
'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']]);
Db::commit();
return true;
} catch (\Throwable $e) {
Db::rollback();
throw new BusinessException($e->getMessage());
}
}
/**
* @notes 订单转预定单
* @param array $params

View File

@ -125,16 +125,18 @@ class WarehouseProductLogic extends BaseLogic
if ($params['order_type'] != 6) {
$storege = WarehouseProductStorege::where('warehouse_id', $params['warehouse_id'])->where('product_id', $params['product_id'])->find();
if ($storege) {
SystemStoreStorage::create([
'store_id' => $params['store_id'],
'admin_id' => $params['admin_id'],
'order_type' => $params['order_type'],
'staff_id' => 0,
'type' => 1,
'product_id' => $params['product_id'],
'nums' => $params['nums'],
'status' => 0
]);
if($params['order_type']!=7){
SystemStoreStorage::create([
'store_id' => $params['store_id'],
'admin_id' => $params['admin_id'],
'order_type' => $params['order_type'],
'staff_id' => 0,
'type' => 1,
'product_id' => $params['product_id'],
'nums' => $params['nums'],
'status' => 0
]);
}
$after_nums = bcsub($storege['nums'], $params['nums']);
$total_price = bcmul($after_nums, $params['purchase'], 2);
WarehouseProductStorege::update(['nums' => bcsub($storege['nums'], $params['nums']), 'total_price' => $total_price], ['id' => $storege['id']]);