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
|
public function lists(): array
|
||||||
{
|
{
|
||||||
return WarehouseProduct::where($this->searchWhere)
|
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)
|
->limit($this->limitOffset, $this->limitLength)
|
||||||
->order(['id' => 'desc'])
|
->order(['id' => 'desc'])
|
||||||
->select()->each(function ($item){
|
->select()->each(function ($item){
|
||||||
|
@ -5,6 +5,7 @@ namespace app\admin\logic\warehouse_product;
|
|||||||
|
|
||||||
use app\common\model\warehouse_product\WarehouseProduct;
|
use app\common\model\warehouse_product\WarehouseProduct;
|
||||||
use app\common\logic\BaseLogic;
|
use app\common\logic\BaseLogic;
|
||||||
|
use app\common\model\store_branch_product\StoreBranchProduct;
|
||||||
use app\common\model\store_product\StoreProduct;
|
use app\common\model\store_product\StoreProduct;
|
||||||
use app\common\model\warehouse_product_storege\WarehouseProductStorege;
|
use app\common\model\warehouse_product_storege\WarehouseProductStorege;
|
||||||
use support\Log;
|
use support\Log;
|
||||||
@ -35,9 +36,11 @@ class WarehouseProductLogic extends BaseLogic
|
|||||||
'warehouse_id' => $params['warehouse_id'],
|
'warehouse_id' => $params['warehouse_id'],
|
||||||
'product_id' => $params['product_id'],
|
'product_id' => $params['product_id'],
|
||||||
'financial_pm' => $params['financial_pm'],
|
'financial_pm' => $params['financial_pm'],
|
||||||
'batch' => $params['batch'],
|
'batch' => 0,
|
||||||
'nums' => $params['nums'],
|
'nums' => $params['nums'],
|
||||||
'price' => $params['price'] ?? '',
|
'price' => $params['price'] ?? '',
|
||||||
|
'purchase' => $params['purchase'] ?? '',
|
||||||
|
'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'] ?? '',
|
||||||
@ -77,12 +80,14 @@ class WarehouseProductLogic extends BaseLogic
|
|||||||
'warehouse_id' => $params['warehouse_id'],
|
'warehouse_id' => $params['warehouse_id'],
|
||||||
'product_id' => $params['product_id'],
|
'product_id' => $params['product_id'],
|
||||||
'financial_pm' => $params['financial_pm'],
|
'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'],
|
'nums' => $params['nums'],
|
||||||
'price' => $params['price'],
|
'price' => $params['price'],
|
||||||
'admin_id' => $params['admin_id'],
|
'admin_id' => $params['admin_id'],
|
||||||
'total_price' => $params['total_price'],
|
'total_price' => $params['total_price'],
|
||||||
'code' => $params['code'],
|
'code' => $params['code'],
|
||||||
|
'purchase' => $params['purchase'] ?? '',
|
||||||
|
'cost' => $params['cost'] ?? '',
|
||||||
];
|
];
|
||||||
if (isset($params['manufacture']) && $params['manufacture'] != '') {
|
if (isset($params['manufacture']) && $params['manufacture'] != '') {
|
||||||
$data['manufacture'] = strtotime($params['manufacture']);
|
$data['manufacture'] = strtotime($params['manufacture']);
|
||||||
@ -96,6 +101,7 @@ class WarehouseProductLogic extends BaseLogic
|
|||||||
return $res;
|
return $res;
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
Db::rollback();
|
Db::rollback();
|
||||||
|
d($e);
|
||||||
self::setError($e->getMessage());
|
self::setError($e->getMessage());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -109,25 +115,28 @@ class WarehouseProductLogic extends BaseLogic
|
|||||||
*/
|
*/
|
||||||
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 = 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])->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) {
|
if ($financial_pm == 0) {
|
||||||
StoreProduct::where('id', $find['product_id'])->dec('stock', $find['nums'])->update();
|
StoreProduct::where('id', $find['product_id'])->dec('stock', $find['nums'])->update();
|
||||||
} else {
|
} else {
|
||||||
StoreProduct::where('id',$find['product_id'])->inc('stock',$find['nums'])->update();
|
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']);
|
$storege->nums = bcsub($storege->nums, $find['nums']);
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
$storege->nums = bcadd($storege->nums, $find['nums']);
|
$storege->nums = bcadd($storege->nums, $find['nums']);
|
||||||
}
|
}
|
||||||
$storege->save();
|
$storege->save();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
WarehouseProductStorege::create([
|
WarehouseProductStorege::create([
|
||||||
'warehouse_id' => $find['warehouse_id'],
|
'warehouse_id' => $find['warehouse_id'],
|
||||||
@ -135,13 +144,6 @@ class WarehouseProductLogic extends BaseLogic
|
|||||||
'nums' => $find['nums'],
|
'nums' => $find['nums'],
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
Db::commit();
|
|
||||||
return true;
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
Db::rollback();
|
|
||||||
self::setError($e->getMessage());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -171,7 +173,6 @@ class WarehouseProductLogic extends BaseLogic
|
|||||||
if ($data) {
|
if ($data) {
|
||||||
$data['manufacture'] = date('Y-m-d', $data['manufacture']);
|
$data['manufacture'] = date('Y-m-d', $data['manufacture']);
|
||||||
$data['expiration_date'] = date('Y-m-d', $data['expiration_date']);
|
$data['expiration_date'] = date('Y-m-d', $data['expiration_date']);
|
||||||
|
|
||||||
}
|
}
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
@ -56,7 +56,7 @@ class WarehouseProductValidate extends BaseValidate
|
|||||||
*/
|
*/
|
||||||
public function sceneAdd()
|
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()
|
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