feat:depot_purchase
This commit is contained in:
@@ -18,6 +18,7 @@ use App\Model\MaterialApplication;
|
||||
use App\Model\MaterialStock;
|
||||
use App\Model\Supplier;
|
||||
use App\Service\Admin\BaseService;
|
||||
use Hyperf\DbConnection\Db;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
|
||||
class DepotService extends BaseService{
|
||||
@@ -142,6 +143,8 @@ class DepotService extends BaseService{
|
||||
|
||||
public function purchase():array
|
||||
{
|
||||
Db::beginTransaction();
|
||||
try {
|
||||
$depotId = (int)$this->request->input('depot_id');
|
||||
$materialId = (int)$this->request->input('material_id');
|
||||
$supplierId = (int)$this->request->input('supplier_id');
|
||||
@@ -185,18 +188,26 @@ class DepotService extends BaseService{
|
||||
}
|
||||
else{
|
||||
//库存增加
|
||||
$totalValue = $purchase_price * $number + $materialStock->unit_price * $materialStock->current_stock;
|
||||
$materialStock->current_stock = $materialStock->current_stock + $number;
|
||||
$materialStock->unit_price = $purchase_price;
|
||||
$materialStock->unit_price = $totalValue/$materialStock->current_stock;
|
||||
}
|
||||
|
||||
if (!$depotPurchase->save() || !$materialStock->save()) throw new ErrException('采购添加失败');
|
||||
|
||||
DB::commit();
|
||||
} catch (ErrException $error) {
|
||||
Db::rollBack();
|
||||
throw new ErrException($error->getMessage());
|
||||
}
|
||||
return $this->return->success();
|
||||
|
||||
}
|
||||
|
||||
public function purchaseUpdate():array
|
||||
{
|
||||
Db::beginTransaction();
|
||||
try {
|
||||
$id = (int)$this->request->input('id');
|
||||
$info = $this->DepotPurchaseModel->getDepotPurchase($id);
|
||||
$old_number = $info->number;
|
||||
@@ -217,6 +228,11 @@ class DepotService extends BaseService{
|
||||
|
||||
if (!$info->save() || !$materialStock->save()) throw new ErrException('采购数量修改失败');
|
||||
|
||||
DB::commit();
|
||||
} catch (ErrException $error) {
|
||||
Db::rollBack();
|
||||
throw new ErrException($error->getMessage());
|
||||
}
|
||||
return $this->return->success();
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user