Merge pull request 'feat: 修改仓库产品逻辑以优化代码结构' (#116) from dev into main
Reviewed-on: #116
This commit is contained in:
commit
c20dbe164a
@ -33,32 +33,32 @@ class WarehouseProductLogic extends BaseLogic
|
|||||||
{
|
{
|
||||||
// Db::startTrans();
|
// Db::startTrans();
|
||||||
// try {
|
// try {
|
||||||
$data = [
|
$data = [
|
||||||
'warehouse_id' => $params['warehouse_id'],
|
'warehouse_id' => $params['warehouse_id'],
|
||||||
'store_id' => $params['store_id']??0,
|
'store_id' => $params['store_id'] ?? 0,
|
||||||
'product_id' => $params['product_id'],
|
'product_id' => $params['product_id'],
|
||||||
'financial_pm' => $params['financial_pm'],
|
'financial_pm' => $params['financial_pm'],
|
||||||
'batch' => 0,
|
'batch' => 0,
|
||||||
'nums' => $params['nums'],
|
'nums' => $params['nums'],
|
||||||
'price' => $params['price'] ?? '',
|
'price' => $params['price'] ?? '',
|
||||||
'purchase' => $params['purchase'] ?? '',
|
'purchase' => $params['purchase'] ?? '',
|
||||||
'cost' => $params['cost'] ?? '',
|
'cost' => $params['cost'] ?? '',
|
||||||
'total_price' => $params['total_price'] ?? '',
|
'total_price' => $params['total_price'] ?? '',
|
||||||
'admin_id' => $params['admin_id'],
|
'admin_id' => $params['admin_id'],
|
||||||
'code' => $params['code'] ?? '',
|
'code' => $params['code'] ?? '',
|
||||||
'status' => $params['status'] ?? 0,
|
'status' => $params['status'] ?? 0,
|
||||||
'mark' => $params['mark'] ?? '',
|
'mark' => $params['mark'] ?? '',
|
||||||
];
|
];
|
||||||
if (isset($params['manufacture']) && $params['manufacture'] != '') {
|
if (isset($params['manufacture']) && $params['manufacture'] != '') {
|
||||||
$data['manufacture'] = strtotime($params['manufacture']);
|
$data['manufacture'] = strtotime($params['manufacture']);
|
||||||
}
|
}
|
||||||
if (isset($params['expiration_date']) && $params['expiration_date'] != '') {
|
if (isset($params['expiration_date']) && $params['expiration_date'] != '') {
|
||||||
$data['expiration_date'] = strtotime($params['expiration_date']);
|
$data['expiration_date'] = strtotime($params['expiration_date']);
|
||||||
}
|
}
|
||||||
$res = WarehouseProduct::create($data);
|
$res = WarehouseProduct::create($data);
|
||||||
self::enter($res['id'], $params['financial_pm']);
|
self::enter($res['id'], $params['financial_pm']);
|
||||||
// Db::commit();
|
// Db::commit();
|
||||||
return $res;
|
return $res;
|
||||||
// } catch (\Exception $e) {
|
// } catch (\Exception $e) {
|
||||||
// Db::rollback();
|
// Db::rollback();
|
||||||
// Log::error($e->getMessage().',file:'.$e->getFile().',line:'.$e->getLine());
|
// Log::error($e->getMessage().',file:'.$e->getFile().',line:'.$e->getLine());
|
||||||
@ -119,25 +119,17 @@ class WarehouseProductLogic extends BaseLogic
|
|||||||
|
|
||||||
$find = WarehouseProduct::where('id', $id)->find();
|
$find = WarehouseProduct::where('id', $id)->find();
|
||||||
$find->status = 1;
|
$find->status = 1;
|
||||||
$find->batch = WarehouseProduct::where(['product_id' => $find['product_id'], 'warehouse_id' => $find['warehouse_id'], 'financial_pm' => $financial_pm,'store_id'=>$find['store_id']])->count();
|
$find->batch = WarehouseProduct::where(['product_id' => $find['product_id'], 'warehouse_id' => $find['warehouse_id'], 'financial_pm' => $financial_pm, 'store_id' => $find['store_id']])->count();
|
||||||
$find->save();
|
$find->save();
|
||||||
|
|
||||||
$storege = WarehouseProductStorege::where('warehouse_id', $find['warehouse_id'])->where('product_id', $find['product_id'])->find();
|
$storege = WarehouseProductStorege::where('warehouse_id', $find['warehouse_id'])->where('product_id', $find['product_id'])->find();
|
||||||
// if ($financial_pm == 0) {
|
|
||||||
// StoreProduct::where('id', $find['product_id'])->dec('stock', $find['nums'])->update();
|
|
||||||
// } else {
|
|
||||||
// StoreProduct::where('id', $find['product_id'])->inc('stock', $find['nums'])->update(['purchase' => $find['purchase'], 'cost' => $find['cost'], 'price' => $find['price']]);
|
|
||||||
// StoreBranchProduct::where('product_id', $find['product_id'])->update(['purchase' => $find['purchase'], 'cost' => $find['cost'], 'price' => $find['price']]);
|
|
||||||
// }
|
|
||||||
|
|
||||||
if ($storege) {
|
if ($storege) {
|
||||||
if ($financial_pm == 0) {
|
if ($financial_pm == 0) {
|
||||||
$storege->nums = bcsub($storege->nums, $find['nums']);
|
WarehouseProductStorege::where('id',$storege['id'])->dec('nums', $find['nums'])->update();
|
||||||
} else {
|
} else {
|
||||||
|
WarehouseProductStorege::where('id',$storege['id'])->inc('nums', $find['nums'])->update();
|
||||||
$storege->nums = bcadd($storege->nums, $find['nums']);
|
|
||||||
}
|
}
|
||||||
$storege->save();
|
|
||||||
} else {
|
} else {
|
||||||
WarehouseProductStorege::create([
|
WarehouseProductStorege::create([
|
||||||
'warehouse_id' => $find['warehouse_id'],
|
'warehouse_id' => $find['warehouse_id'],
|
||||||
@ -157,27 +149,26 @@ class WarehouseProductLogic extends BaseLogic
|
|||||||
*/
|
*/
|
||||||
public static function delete(array $params): bool
|
public static function delete(array $params): bool
|
||||||
{
|
{
|
||||||
$res=WarehouseProduct::where('id',$params['id'])->find();
|
$res = WarehouseProduct::where('id', $params['id'])->find();
|
||||||
if($res){
|
if ($res) {
|
||||||
$res->delete();
|
$res->delete();
|
||||||
if($res['financial_pm']==1){
|
if ($res['financial_pm'] == 1) {
|
||||||
WarehouseProductStorege::where('warehouse_id',$res['warehouse_id'])->dec('nums',$res['nums'])->update();
|
WarehouseProductStorege::where('warehouse_id', $res['warehouse_id'])->dec('nums', $res['nums'])->update();
|
||||||
}elseif($res['financial_pm']==0){
|
} elseif ($res['financial_pm'] == 0) {
|
||||||
$find=SystemStoreStorage::where(['outbound_id'=>$res['id']])->find();
|
$find = SystemStoreStorage::where(['outbound_id' => $res['id']])->find();
|
||||||
if($find){
|
if ($find) {
|
||||||
$stock=StoreBranchProduct::where(['store_id'=>$res['store_id'],'product_id'=>$res['product_id']])->value('stock');
|
$stock = StoreBranchProduct::where(['store_id' => $res['store_id'], 'product_id' => $res['product_id']])->value('stock');
|
||||||
if($stock<$res['nums']){
|
if ($stock < $res['nums']) {
|
||||||
self::setError('商品库存不足,无法退回');
|
self::setError('商品库存不足,无法退回');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$find->delete();
|
$find->delete();
|
||||||
StoreBranchProduct::where(['store_id'=>$res['store_id'],'product_id'=>$res['product_id']])->dec('stock',$res['nums'])->update();
|
StoreBranchProduct::where(['store_id' => $res['store_id'], 'product_id' => $res['product_id']])->dec('stock', $res['nums'])->update();
|
||||||
}
|
}
|
||||||
WarehouseProductStorege::where('warehouse_id',$res['warehouse_id'])->inc('nums',$res['nums'])->update();
|
WarehouseProductStorege::where('warehouse_id', $res['warehouse_id'])->inc('nums', $res['nums'])->update();
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user