Merge pull request 'feat(admin): 添加预订单修改数量和仓库重置数量功能' (#374) from dev into main

Reviewed-on: #374
This commit is contained in:
mkm 2024-12-07 11:56:01 +08:00
commit 619ec3b394
5 changed files with 105 additions and 3 deletions

View File

@ -132,6 +132,14 @@ class BeforehandOrderCartInfoController extends BaseAdminController
$result = BeforehandOrderCartInfoLogic::detail($params);
return $this->data($result);
}
/**
* 修改数量
*/
public function edit_nums()
{
$params = $this->request->post();
$result = BeforehandOrderCartInfoLogic::editNums($params);
return $this->data($result);
}
}

View File

@ -133,4 +133,14 @@ class WarehouseProductController extends BaseAdminController
// return $this->fail(WarehouseProductLogic::getError());
return $this->success('');
}
/**
* 仓库重置出入库数量
*/
public function set_nums()
{
$params=$this->request->post();
$result = WarehouseProductLogic::settNums($params);
return $this->success('');
}
}

View File

@ -136,11 +136,35 @@ class BeforehandOrderCartInfoLogic extends BaseLogic
return true;
} catch (\Throwable $e) {
Db::rollback();
d($e);
throw new BusinessException($e->getMessage());
}
}
/**
* @notes 编辑预订单购物详情表
* @param array $params
* @return bool
* @author admin
* @date 2024/09/30 11:32
*/
public static function editNums(array $params): bool
{
Db::startTrans();
try {
$find=BeforehandOrderCartInfo::where('id', $params['id'])->find();
if($find){
$data=['accept_num'=>$params['nums'],'pay_price'=>bcmul($find['price'],$params['nums'],2)];
$find->save($data);
$info = BeforehandOrderCartInfo::where('bhoid', $find['bhoid'])->field('sum(accept_num) as accept_num,sum(pay_price) as pay_price')->find();
BeforehandOrder::where('id', $find['bhoid'])->save(['pay_price'=>$info['pay_price'], 'total_num' => $info['accept_num']]);
}
Db::commit();
return true;
} catch (\Throwable $e) {
Db::rollback();
throw new BusinessException($e->getMessage());
}
}
/**
* 一键入库
*/

View File

@ -254,7 +254,7 @@ class WarehouseLogic extends BaseLogic
}
$list = WarehouseProductStorege::where($where)->page($parmas['page_no'], 15)->select()
->each(function ($item) {
$find = StoreProduct::where('id', $item['product_id'])->find();
$find = StoreProduct::where('id', $item['product_id'])->withTrashed()->find();
$item->store_name = $find['store_name'];
$item->image = $find['image'];
$item->stock = $item['nums'];

View File

@ -310,6 +310,66 @@ class WarehouseProductLogic extends BaseLogic
throw new BusinessException($th->getMessage());
}
}
/**
* * @notes 仓库重置出入库数量
* @param $id
* @return void
*/
public static function settNums($params)
{
Db::startTrans();
try {
$res = WarehouseProduct::where('id',$params['id'])->find();
if ($res) {
if ($res['financial_pm'] == 1) {
WarehouseProductStorege::where('warehouse_id', $res['warehouse_id'])->where('product_id', $res['product_id'])->dec('nums', $res['nums'])->update();
StoreBranchProduct::where('store_id', $res['store_id'])->where('product_id', $res['product_id'])->dec('stock', $res['nums'])->update();
$warehouseProductStorege = WarehouseProductStorege::where('warehouse_id', $res['warehouse_id'])->where('product_id', $res['product_id'])->find();
WarehouseProductStorege::where('warehouse_id', $res['warehouse_id'])->where('product_id', $res['product_id'])->inc('nums', $params['nums'])->update();
StoreBranchProduct::where('store_id', $res['store_id'])->where('product_id', $res['product_id'])->inc('stock', $params['nums'])->update();
$before_nums = $warehouseProductStorege['nums'];
$after_nums = $warehouseProductStorege['nums'] + $params['nums'];
} else {
WarehouseProductStorege::where('warehouse_id', $res['warehouse_id'])->where('product_id', $res['product_id'])->inc('nums', $res['nums'])->update();
StoreBranchProduct::where('store_id', $res['store_id'])->where('product_id', $res['product_id'])->dec('stock', $res['nums'])->update();
$warehouseProductStorege = WarehouseProductStorege::where('warehouse_id', $res['warehouse_id'])->where('product_id', $res['product_id'])->find();
WarehouseProductStorege::where('warehouse_id', $res['warehouse_id'])->where('product_id', $res['product_id'])->dec('nums', $params['nums'])->update();
StoreBranchProduct::where('store_id', $res['store_id'])->where('product_id', $res['product_id'])->inc('stock', $params['nums'])->update();
$before_nums = $warehouseProductStorege['nums'];
$after_nums = bcsub($warehouseProductStorege['nums'], $params['nums'], 2);
}
if($res['financial_pm']==1){
$datas=[
'nums' => $params['nums'],
'before_nums' => $before_nums,
'after_nums' => $after_nums,
'total_price' => bcmul($params['nums'], $res['purchase'], 2),
];
}else{
$datas=[
'nums' => $params['nums'],
'before_nums' => $before_nums,
'after_nums' => $after_nums,
'total_price' => bcmul($params['nums'], $res['price'], 2),
];
}
WarehouseProduct::where('id', $params['id'])->update($datas);
$finds = WarehouseProduct::where('oid', $res['oid'])->field('sum(nums) as nums')->find();
if ($finds) {
WarehouseOrder::where('id', $res['oid'])->update([
'nums' => $finds['nums'],
]);
}
}
Db::commit();
} catch (\Throwable $th) {
Db::rollback();
throw new BusinessException($th->getMessage());
}
}
/**
* @notes 获取商品仓储信息详情
* @param $params