feat: 添加负库存检测与归零功能
This commit is contained in:
parent
5ab280a05f
commit
d3e58573ec
@ -316,10 +316,27 @@ class WorkbenchController extends BaseAdminController
|
||||
return $this->data($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 负库存检测
|
||||
*/
|
||||
public function negative_inventory()
|
||||
{
|
||||
$parmas = $this->request->get();
|
||||
$data = WarehouseLogic::negativeInventory($parmas);
|
||||
return $this->data($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 负库存归零
|
||||
*/
|
||||
public function update_negative_zero()
|
||||
{
|
||||
$parmas = $this->request->get();
|
||||
$res = WarehouseLogic::updateNegativeZero($parmas);
|
||||
if($res){
|
||||
return $this->data([], '操作成功');
|
||||
}else{
|
||||
return $this->data([], '操作失败', 400);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -217,5 +217,19 @@ class WarehouseLogic extends BaseLogic
|
||||
$count = WarehouseProductStorege::where('nums', '<', 0)->count();
|
||||
}
|
||||
return ['lists' => $list, 'count' => $count];
|
||||
}
|
||||
/**
|
||||
* 负库存更新归0
|
||||
*/
|
||||
public static function updateNegativeZero($parmas)
|
||||
{
|
||||
if ($parmas['type'] == 1) {
|
||||
$res = StoreProduct::where('id',$parmas['id'])->update(['stock'=>0]);
|
||||
} elseif ($parmas['type'] == 2) {
|
||||
$res=StoreBranchProduct::where('id',$parmas['id'])->update(['stock'=>0]);
|
||||
} elseif ($parmas['type'] == 3) {
|
||||
$res = WarehouseProductStorege::where('id',$parmas['id'])->update(['nums'=>0]);
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
}
|
||||
|
@ -51,45 +51,8 @@ class StoreOrderLogic extends BaseLogic
|
||||
$params['shipping_type']=2;
|
||||
$params['pay_type'] = 7;
|
||||
$order = OrderLogic::createOrder($cartId, null, $user, $params);
|
||||
if (OrderLogic::hasError()) {
|
||||
StoreOrderLogic::setError(OrderLogic::getError());
|
||||
return false;
|
||||
} else {
|
||||
$arr = [
|
||||
'warehouse_id' => $params['warehouse_id']??-1,
|
||||
'store_id' => $params['store_id'],
|
||||
'supplier_id' => 0,
|
||||
'code' => getNewOrderId('PS'),
|
||||
'admin_id' => $params['admin_id'],
|
||||
'financial_pm' => 0,
|
||||
'batch' => 0,
|
||||
'mark' => $mark ?? "",
|
||||
];
|
||||
$arr['delivery_time'] = time();
|
||||
$res = WarehouseOrder::create($arr);
|
||||
foreach ($params['product_arr'] as $k => $v) {
|
||||
$data = [
|
||||
'warehouse_id' => $params['warehouse_id']??-1,
|
||||
'product_id' => $v['product_id'],
|
||||
'store_id' => $params['store_id'],
|
||||
'financial_pm' => 0,
|
||||
'batch' => 1,
|
||||
'nums' => $v['stock'],
|
||||
'status' => 1,
|
||||
'admin_id' => $params['admin_id'],
|
||||
];
|
||||
$storeProduct = StoreBranchProduct::where('id', $v['id'])->findOrEmpty()->toArray();
|
||||
if ($v['stock']>0) {
|
||||
$data['total_price'] = bcmul($v['stock'], $storeProduct['purchase'], 2);
|
||||
$data['purchase'] = $storeProduct['purchase'];
|
||||
$data['oid'] = $res['id'];
|
||||
WarehouseProductLogic::add($data,0);
|
||||
$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']]);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user