feat(WarehouseProductLogic): 更新仓库产品逻辑,优化商品仓储信息处理,调整库存管理方法
This commit is contained in:
parent
748c3c7267
commit
c3a930a9e1
@ -45,7 +45,7 @@ class WarehouseProductLists extends BaseAdminDataLists implements ListsSearchInt
|
||||
public function lists(): array
|
||||
{
|
||||
return WarehouseProduct::where($this->searchWhere)
|
||||
->field(['id', 'admin_id','warehouse_id', 'product_id', 'financial_pm', 'batch', 'nums', 'price', 'total_price', 'manufacture','expiration_date','status','mark'])
|
||||
->field(['id', 'admin_id','warehouse_id', 'product_id', 'financial_pm', 'batch', 'nums', 'price','purchase','cost', 'total_price', 'manufacture','expiration_date','status','mark','create_time'])
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->order(['id' => 'desc'])
|
||||
->select()->each(function ($item){
|
||||
|
@ -5,6 +5,7 @@ namespace app\admin\logic\warehouse_product;
|
||||
|
||||
use app\common\model\warehouse_product\WarehouseProduct;
|
||||
use app\common\logic\BaseLogic;
|
||||
use app\common\model\store_branch_product\StoreBranchProduct;
|
||||
use app\common\model\store_product\StoreProduct;
|
||||
use app\common\model\warehouse_product_storege\WarehouseProductStorege;
|
||||
use support\Log;
|
||||
@ -31,27 +32,29 @@ class WarehouseProductLogic extends BaseLogic
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
$data=[
|
||||
$data = [
|
||||
'warehouse_id' => $params['warehouse_id'],
|
||||
'product_id' => $params['product_id'],
|
||||
'financial_pm' => $params['financial_pm'],
|
||||
'batch' => $params['batch'],
|
||||
'batch' => 0,
|
||||
'nums' => $params['nums'],
|
||||
'price' => $params['price']??'',
|
||||
'total_price' => $params['total_price']??'',
|
||||
'price' => $params['price'] ?? '',
|
||||
'purchase' => $params['purchase'] ?? '',
|
||||
'cost' => $params['cost'] ?? '',
|
||||
'total_price' => $params['total_price'] ?? '',
|
||||
'admin_id' => $params['admin_id'],
|
||||
'code' => $params['code']??'',
|
||||
'status' => $params['status']??0,
|
||||
'mark' => $params['mark']??'',
|
||||
'code' => $params['code'] ?? '',
|
||||
'status' => $params['status'] ?? 0,
|
||||
'mark' => $params['mark'] ?? '',
|
||||
];
|
||||
if(isset($params['manufacture']) &&$params['manufacture']!=''){
|
||||
$data['manufacture']=strtotime($params['manufacture']);
|
||||
if (isset($params['manufacture']) && $params['manufacture'] != '') {
|
||||
$data['manufacture'] = strtotime($params['manufacture']);
|
||||
}
|
||||
if(isset($params['expiration_date']) &&$params['expiration_date']!=''){
|
||||
$data['expiration_date']=strtotime($params['expiration_date']);
|
||||
if (isset($params['expiration_date']) && $params['expiration_date'] != '') {
|
||||
$data['expiration_date'] = strtotime($params['expiration_date']);
|
||||
}
|
||||
$res=WarehouseProduct::create($data);
|
||||
self::enter($res['id'],$params['financial_pm']);
|
||||
$res = WarehouseProduct::create($data);
|
||||
self::enter($res['id'], $params['financial_pm']);
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
@ -73,74 +76,73 @@ class WarehouseProductLogic extends BaseLogic
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
$data=[
|
||||
$data = [
|
||||
'warehouse_id' => $params['warehouse_id'],
|
||||
'product_id' => $params['product_id'],
|
||||
'financial_pm' => $params['financial_pm'],
|
||||
'batch' => $params['batch'],
|
||||
'batch' => WarehouseProduct::where(['product_id' => $params['product_id'], 'warehouse_id' => $params['warehouse_id'], 'financial_pm' => $params['financial_pm']])->count(),
|
||||
'nums' => $params['nums'],
|
||||
'price' => $params['price'],
|
||||
'admin_id' => $params['admin_id'],
|
||||
'total_price' => $params['total_price'],
|
||||
'code' => $params['code'],
|
||||
'purchase' => $params['purchase'] ?? '',
|
||||
'cost' => $params['cost'] ?? '',
|
||||
];
|
||||
if(isset($params['manufacture']) &&$params['manufacture']!=''){
|
||||
$data['manufacture']=strtotime($params['manufacture']);
|
||||
if (isset($params['manufacture']) && $params['manufacture'] != '') {
|
||||
$data['manufacture'] = strtotime($params['manufacture']);
|
||||
}
|
||||
if(isset($params['expiration_date']) &&$params['expiration_date']!=''){
|
||||
$data['expiration_date']=strtotime($params['expiration_date']);
|
||||
if (isset($params['expiration_date']) && $params['expiration_date'] != '') {
|
||||
$data['expiration_date'] = strtotime($params['expiration_date']);
|
||||
}
|
||||
$res=WarehouseProduct::where('id', $params['id'])->update($data);
|
||||
$res = WarehouseProduct::where('id', $params['id'])->update($data);
|
||||
|
||||
Db::commit();
|
||||
return $res;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
d($e);
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @notes 确认商品仓储信息
|
||||
* @param array $params
|
||||
* @author admin
|
||||
* @date 2024/07/31 16:55
|
||||
*/
|
||||
public static function enter($id,$financial_pm=0)
|
||||
public static function enter($id, $financial_pm = 0)
|
||||
{
|
||||
Db::startTrans();
|
||||
try {
|
||||
$find=WarehouseProduct::where('id',$id)->find();
|
||||
$find->status=1;
|
||||
$find->save();
|
||||
$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();
|
||||
}
|
||||
if($storege){
|
||||
if($financial_pm==0){
|
||||
$storege->nums=bcsub($storege->nums,$find['nums']);
|
||||
}else{
|
||||
$storege->nums=bcadd($storege->nums,$find['nums']);
|
||||
}
|
||||
$storege->save();
|
||||
|
||||
}else{
|
||||
WarehouseProductStorege::create([
|
||||
'warehouse_id' => $find['warehouse_id'],
|
||||
'product_id' => $find['product_id'],
|
||||
'nums' => $find['nums'],
|
||||
]);
|
||||
$find = WarehouseProduct::where('id', $id)->find();
|
||||
$find->status = 1;
|
||||
$find->batch = WarehouseProduct::where(['product_id' => $find['product_id'], 'warehouse_id' => $find['warehouse_id'], 'financial_pm' => $financial_pm])->count();
|
||||
$find->save();
|
||||
|
||||
$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 ($financial_pm == 0) {
|
||||
$storege->nums = bcsub($storege->nums, $find['nums']);
|
||||
} else {
|
||||
|
||||
$storege->nums = bcadd($storege->nums, $find['nums']);
|
||||
}
|
||||
Db::commit();
|
||||
return true;
|
||||
} catch (\Exception $e) {
|
||||
Db::rollback();
|
||||
self::setError($e->getMessage());
|
||||
return false;
|
||||
$storege->save();
|
||||
} else {
|
||||
WarehouseProductStorege::create([
|
||||
'warehouse_id' => $find['warehouse_id'],
|
||||
'product_id' => $find['product_id'],
|
||||
'nums' => $find['nums'],
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -167,12 +169,11 @@ class WarehouseProductLogic extends BaseLogic
|
||||
*/
|
||||
public static function detail($params): array
|
||||
{
|
||||
$data= WarehouseProduct::findOrEmpty($params['id'])->toArray();
|
||||
if($data){
|
||||
$data['manufacture']=date('Y-m-d',$data['manufacture']);
|
||||
$data['expiration_date']=date('Y-m-d',$data['expiration_date']);
|
||||
|
||||
$data = WarehouseProduct::findOrEmpty($params['id'])->toArray();
|
||||
if ($data) {
|
||||
$data['manufacture'] = date('Y-m-d', $data['manufacture']);
|
||||
$data['expiration_date'] = date('Y-m-d', $data['expiration_date']);
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ class WarehouseProductValidate extends BaseValidate
|
||||
*/
|
||||
public function sceneAdd()
|
||||
{
|
||||
return $this->only(['warehouse_id','product_id','financial_pm','batch','nums','price','total_price']);
|
||||
return $this->only(['warehouse_id','product_id','financial_pm','nums','price','total_price']);
|
||||
}
|
||||
|
||||
|
||||
@ -68,7 +68,7 @@ class WarehouseProductValidate extends BaseValidate
|
||||
*/
|
||||
public function sceneEdit()
|
||||
{
|
||||
return $this->only(['id','warehouse_id','product_id','financial_pm','batch','nums','price','total_price']);
|
||||
return $this->only(['id','warehouse_id','product_id','financial_pm','nums','price','total_price']);
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user