refactor(warehouse): 重构仓库出库逻辑
- 移除了单店和多店的区分逻辑 - 新增了订单类型的判断逻辑 - 优化了订单创建和商品添加的流程 - 删除了一些冗余代码 - 调整了部分变量命名
This commit is contained in:
parent
bdc290c6b1
commit
535bd7e47e
@ -71,65 +71,57 @@ class WarehouseOrderController extends BaseAdminController
|
||||
public function outbound()
|
||||
{
|
||||
$product_arr = $this->request->post('product_arr');
|
||||
$store_arr = $this->request->post('store_arr');
|
||||
$warehouse_id = $this->request->post('warehouse_id');
|
||||
$delivery_time = $this->request->post('delivery_time');
|
||||
$mark = $this->request->post('mark');
|
||||
$count = count($store_arr);
|
||||
// foreach ($product_arr as $key => $arr) {
|
||||
// $stock = bcmul($arr['stock'], $count);
|
||||
// $nums = WarehouseProductStorege::where('warehouse_id', $warehouse_id)->where('product_id', $arr['id'])->value('nums');
|
||||
// if ($nums < $stock) {
|
||||
// return $this->fail('商品库存不足');
|
||||
// }
|
||||
// }
|
||||
$order_type = $this->request->post('order_type', 1);
|
||||
Db::startTrans();
|
||||
try {
|
||||
if ($count == 1) {
|
||||
$store_id = $store_arr[0];
|
||||
$arr = [
|
||||
if($order_type==1){
|
||||
$code=getNewOrderId('TGY');
|
||||
}else{
|
||||
$code=getNewOrderId('BS');
|
||||
}
|
||||
$arr = [
|
||||
'warehouse_id' => $warehouse_id,
|
||||
'store_id' => 0,
|
||||
'supplier_id' => 0,
|
||||
'code' => $code,
|
||||
'admin_id' => $this->adminId,
|
||||
'financial_pm' => 0,
|
||||
'batch' => 0,
|
||||
'mark' => $mark ?? "",
|
||||
];
|
||||
$arr['delivery_time'] = strtotime($delivery_time);
|
||||
$res = WarehouseOrder::create($arr);
|
||||
foreach ($product_arr as $key => $arr) {
|
||||
$data = [
|
||||
'warehouse_id' => $warehouse_id,
|
||||
'store_id' => $store_id,
|
||||
'supplier_id' => 0,
|
||||
'code' => getNewOrderId('PS'),
|
||||
'admin_id' => $this->adminId,
|
||||
'product_id' => $arr['id'],
|
||||
'store_id' => 0,
|
||||
'financial_pm' => 0,
|
||||
'batch' => 0,
|
||||
'mark' => $mark ?? "",
|
||||
'batch' => 1,
|
||||
'nums' => $arr['stock'],
|
||||
'status' => 1,
|
||||
'admin_id' => $this->adminId,
|
||||
'order_type' => $order_type,
|
||||
];
|
||||
$arr['delivery_time'] = strtotime($delivery_time);
|
||||
$res = WarehouseOrder::create($arr);
|
||||
foreach ($product_arr as $key => $arr) {
|
||||
$data = [
|
||||
'warehouse_id' => $warehouse_id,
|
||||
'product_id' => $arr['id'],
|
||||
'store_id' => $store_id,
|
||||
'financial_pm' => 0,
|
||||
'batch' => 1,
|
||||
'nums' => $arr['stock'],
|
||||
'status' => 1,
|
||||
'admin_id' => $this->adminId,
|
||||
];
|
||||
$storeProduct = StoreProduct::where('id', $arr['id'])->findOrEmpty()->toArray();
|
||||
if ($arr['stock'] == 0) {
|
||||
StoreProductLogic::ordinary($arr, $store_id, $this->adminId, $storeProduct);
|
||||
} else {
|
||||
$data['total_price'] = bcmul($arr['stock'], $storeProduct['purchase'], 2);
|
||||
$data['purchase'] = $storeProduct['purchase'];
|
||||
$data['oid'] = $res['id'];
|
||||
$data['financial_pm'] = 0;
|
||||
WarehouseProductLogic::add($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']]);
|
||||
}
|
||||
}
|
||||
$storeProduct = StoreProduct::where('id', $arr['id'])->find();
|
||||
$data['total_price'] = bcmul($arr['stock'], $storeProduct['purchase'], 2);
|
||||
$data['purchase'] = $storeProduct['purchase'];
|
||||
$data['oid'] = $res['id'];
|
||||
$data['financial_pm'] = 0;
|
||||
$data['price'] = $storeProduct['price'];
|
||||
WarehouseProductLogic::add($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']]);
|
||||
}
|
||||
Db::commit();
|
||||
} catch (\Throwable $e) {
|
||||
Db::rollback();
|
||||
throw new BusinessException($e->getMessage());
|
||||
}
|
||||
return $this->success('已导入后台队列,请在门店入库记录中查看', [], 1, 1);
|
||||
return $this->success('出库成功', [], 1, 1);
|
||||
}
|
||||
|
||||
|
||||
@ -142,7 +134,7 @@ class WarehouseOrderController extends BaseAdminController
|
||||
public function edit()
|
||||
{
|
||||
$params = $this->request->post();
|
||||
$params['admin_id']=$this->adminId;
|
||||
$params['admin_id'] = $this->adminId;
|
||||
$result = WarehouseOrderLogic::edit($params);
|
||||
if (true === $result) {
|
||||
return $this->success('编辑成功', [], 1, 1);
|
||||
@ -155,7 +147,8 @@ class WarehouseOrderController extends BaseAdminController
|
||||
* @author admin
|
||||
* @date 2024/08/20 10:50
|
||||
*/
|
||||
public function update_edit(){
|
||||
public function update_edit()
|
||||
{
|
||||
$params = $this->request->post();
|
||||
$result = WarehouseOrderLogic::update_edit($params);
|
||||
if (true === $result) {
|
||||
@ -212,19 +205,19 @@ class WarehouseOrderController extends BaseAdminController
|
||||
$value->unit_name = '';
|
||||
}
|
||||
$order['total_num'] += $value->nums;
|
||||
$value->supplier_name= Supplier::where('id', $value->supplier_id)->value('mer_name');
|
||||
if($value->pay_type==1){
|
||||
$value->supplier_name = Supplier::where('id', $value->supplier_id)->value('mer_name');
|
||||
if ($value->pay_type == 1) {
|
||||
$credit_pay += $value->total_price;
|
||||
$value->pay_type_name='赊账';
|
||||
}elseif($value->pay_type==2){
|
||||
$value->pay_type_name = '赊账';
|
||||
} elseif ($value->pay_type == 2) {
|
||||
$cash_pay += $value->total_price;
|
||||
$value->pay_type_name='现款';
|
||||
}else{
|
||||
$value->pay_type_name='未设置';
|
||||
$value->pay_type_name = '现款';
|
||||
} else {
|
||||
$value->pay_type_name = '未设置';
|
||||
}
|
||||
}
|
||||
$order['credit_pay']=$credit_pay;
|
||||
$order['cash_pay']=$cash_pay;
|
||||
$order['credit_pay'] = $credit_pay;
|
||||
$order['cash_pay'] = $cash_pay;
|
||||
$file_path = $xlsx->export($data, $order);
|
||||
|
||||
return $this->success('导出成功', ['url' => $file_path]);
|
||||
@ -237,7 +230,7 @@ class WarehouseOrderController extends BaseAdminController
|
||||
{
|
||||
$id = $this->request->post('id');
|
||||
$type = $this->request->post('type');
|
||||
if(in_array($type, [2,3])){
|
||||
if (in_array($type, [2, 3])) {
|
||||
return $this->fail('暂不支持此操作');
|
||||
}
|
||||
$xlsx = new OrderDetail();
|
||||
@ -245,11 +238,11 @@ class WarehouseOrderController extends BaseAdminController
|
||||
$system_store = SystemStore::where('id', $order['store_id'])->value('name');
|
||||
$data = WarehouseProduct::where('oid', $id)->select();
|
||||
$order['total_num'] = 0;
|
||||
$total_price=0;
|
||||
$total_price = 0;
|
||||
foreach ($data as $key => &$value) {
|
||||
if(in_array($order['store_id'],[17,18])){
|
||||
$find = StoreBranchProduct::where('product_id', $value->product_id)->where('store_id',$order['store_id'])->withTrashed()->find();
|
||||
}else{
|
||||
if (in_array($order['store_id'], [17, 18])) {
|
||||
$find = StoreBranchProduct::where('product_id', $value->product_id)->where('store_id', $order['store_id'])->withTrashed()->find();
|
||||
} else {
|
||||
$find = StoreProduct::where('id', $value->product_id)->withTrashed()->find();
|
||||
}
|
||||
$value->store_name = $find['store_name'] ?? '';
|
||||
@ -267,10 +260,10 @@ class WarehouseOrderController extends BaseAdminController
|
||||
// $value->total_price=bcmul($find['price'],$value['nums'],2);
|
||||
// $total_price+=$value->total_price;
|
||||
// }else{
|
||||
if($type==1){
|
||||
if ($type == 1) {
|
||||
$value->price = $value['purchase'];
|
||||
$value->total_price=bcmul($value['purchase'],$value['nums'],2);
|
||||
$total_price+=$value->total_price;
|
||||
$value->total_price = bcmul($value['purchase'], $value['nums'], 2);
|
||||
$total_price += $value->total_price;
|
||||
}
|
||||
|
||||
|
||||
@ -283,25 +276,25 @@ class WarehouseOrderController extends BaseAdminController
|
||||
}
|
||||
$order['total_num'] += $value->nums;
|
||||
}
|
||||
if($type==2){
|
||||
$order['total_price']=$total_price;
|
||||
if ($type == 2) {
|
||||
$order['total_price'] = $total_price;
|
||||
}
|
||||
$order['delivery_time']=date('Y-m-d H:i:s',$order['delivery_time']);
|
||||
$order['pay_time']=$order['create_time'];
|
||||
$order['order_id']=$order['code'];
|
||||
$order['delivery_time'] = date('Y-m-d H:i:s', $order['delivery_time']);
|
||||
$order['pay_time'] = $order['create_time'];
|
||||
$order['order_id'] = $order['code'];
|
||||
|
||||
if($order['oid']>0){
|
||||
$orders=StoreOrder::where('id',$order['oid'])->findOrEmpty();
|
||||
$order['real_name']=$orders['real_name'];
|
||||
$order['user_phone']=$orders['user_phone'];
|
||||
$order['user_address']=$orders['user_address'];
|
||||
if ($order['oid'] > 0) {
|
||||
$orders = StoreOrder::where('id', $order['oid'])->findOrEmpty();
|
||||
$order['real_name'] = $orders['real_name'];
|
||||
$order['user_phone'] = $orders['user_phone'];
|
||||
$order['user_address'] = $orders['user_address'];
|
||||
}
|
||||
$file_path = $xlsx->export($data, $system_store, $order);
|
||||
|
||||
return $this->success('导出成功', ['url' => $file_path]);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* 导出标签
|
||||
*/
|
||||
public function export_tags()
|
||||
@ -309,26 +302,26 @@ class WarehouseOrderController extends BaseAdminController
|
||||
$id = $this->request->post('id');
|
||||
$warehouseOrder = WarehouseOrder::where('id', $id)->field('oid,store_id,delivery_time')->find();
|
||||
$system_store = SystemStore::where('id', $warehouseOrder['store_id'])->value('introduction');
|
||||
$data = WarehouseProduct::where('oid', $id)->where('financial_pm',0)->field('oid,product_id,nums')->select()
|
||||
->each(function ($item) use ($system_store,$warehouseOrder) {
|
||||
$data = WarehouseProduct::where('oid', $id)->where('financial_pm', 0)->field('oid,product_id,nums')->select()
|
||||
->each(function ($item) use ($system_store, $warehouseOrder) {
|
||||
$find = StoreProduct::where('id', $item['product_id'])->field('store_name,unit')->withTrashed()->find();
|
||||
$unit_name = StoreProductUnit::where('id', $find['unit'])->value('name');
|
||||
$item['system_store'] = $system_store;
|
||||
$item['subtitle'] = $item['oid'].' '.convertStringToNumber($item['nums']).'/'.$unit_name;
|
||||
$item['subtitle'] = $item['oid'] . ' ' . convertStringToNumber($item['nums']) . '/' . $unit_name;
|
||||
$item['store_name'] = $find['store_name'];
|
||||
if($warehouseOrder['oid']){
|
||||
$find=StoreOrder::where('id',$warehouseOrder['oid'])->field('real_name,user_address')->find();
|
||||
if($find){
|
||||
$item['address'] = $find['real_name'].' '.$find['user_address'];
|
||||
}else{
|
||||
if ($warehouseOrder['oid']) {
|
||||
$find = StoreOrder::where('id', $warehouseOrder['oid'])->field('real_name,user_address')->find();
|
||||
if ($find) {
|
||||
$item['address'] = $find['real_name'] . ' ' . $find['user_address'];
|
||||
} else {
|
||||
$item['address'] = '无地址';
|
||||
}
|
||||
}else{
|
||||
} else {
|
||||
$item['address'] = '无地址';
|
||||
}
|
||||
})
|
||||
->toArray();
|
||||
$file_path=(new Beforehand())->export($data, $system_store);
|
||||
$file_path = (new Beforehand())->export($data, $system_store);
|
||||
return $this->success('导出成功', ['url' => $file_path]);
|
||||
}
|
||||
}
|
||||
|
@ -91,7 +91,7 @@ class WarehouseProductLogic extends BaseLogic
|
||||
'nums' => $params['nums'],
|
||||
'before_nums' => $before_nums,
|
||||
'after_nums' => $after_nums,
|
||||
// 'price' => $params['price'] ?? '',
|
||||
'price' => $params['price'] ?? '',
|
||||
'purchase' => $params['purchase'] ?? '',
|
||||
// 'cost' => $params['cost'] ?? '',
|
||||
'total_price' => $params['total_price'] ?? '',
|
||||
|
Loading…
x
Reference in New Issue
Block a user