feat:depotPurchase
This commit is contained in:
@@ -68,7 +68,7 @@ class DepotController
|
||||
}
|
||||
|
||||
/**
|
||||
* 采购
|
||||
* 采购入库
|
||||
* @param DepotRequest $request
|
||||
* @return array
|
||||
* @throws Exception
|
||||
@@ -80,6 +80,19 @@ class DepotController
|
||||
return (new DepotService)->purchase();
|
||||
}
|
||||
|
||||
/**
|
||||
* 采购退货
|
||||
* @param DepotRequest $request
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
#[RequestMapping(path: "depot_purchase_back", methods: "POST")]
|
||||
#[Scene(scene: "purchase_back")]
|
||||
public function purchaseBack(DepotRequest $request): array
|
||||
{
|
||||
return (new DepotService)->purchaseBack();
|
||||
}
|
||||
|
||||
/**
|
||||
* 采购列表
|
||||
* @param DepotRequest $request
|
||||
|
||||
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Model;
|
||||
|
||||
use Hyperf\Database\Model\Builder;
|
||||
use Hyperf\DbConnection\Model\Model;
|
||||
|
||||
/**
|
||||
@@ -14,8 +15,7 @@ use Hyperf\DbConnection\Model\Model;
|
||||
* @property int $type
|
||||
* @property string $purchase_price
|
||||
* @property string $number
|
||||
* @property string $sum_price
|
||||
* @property int $status
|
||||
* @property string $sum_price
|
||||
* @property int $city_id
|
||||
* @property int $kitchen_id
|
||||
* @property int $operator_id
|
||||
@@ -38,9 +38,14 @@ class DepotPurchase extends Model
|
||||
/**
|
||||
* The attributes that should be cast to native types.
|
||||
*/
|
||||
protected array $casts = ['id' => 'integer', 'depot_id' => 'integer', 'material_id' => 'integer', 'supplier_id' => 'integer', 'type' => 'integer', 'status' => 'integer', 'city_id' => 'integer', 'kitchen_id' => 'integer', 'operator_id' => 'integer', 'is_del' => 'integer'];
|
||||
protected array $casts = ['id' => 'integer', 'depot_id' => 'integer', 'material_id' => 'integer', 'supplier_id' => 'integer', 'type' => 'integer', 'city_id' => 'integer', 'kitchen_id' => 'integer', 'operator_id' => 'integer', 'is_del' => 'integer'];
|
||||
|
||||
const CREATED_AT = 'create_time';
|
||||
|
||||
const UPDATED_AT = 'update_time';
|
||||
|
||||
public function getDepotPurchase(int $id): \Hyperf\Database\Model\Model|Builder|null
|
||||
{
|
||||
return $this->where('id',$id)->first();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,13 +36,16 @@ class MaterialStock extends Model
|
||||
*/
|
||||
protected array $casts = ['id' => 'integer', 'material_id' => 'integer', 'depot_id' => 'integer', 'supplier_id' => 'integer', 'is_del' => 'integer'];
|
||||
|
||||
const CREATED_AT = 'create_time';
|
||||
|
||||
const UPDATED_AT = 'update_time';
|
||||
|
||||
public function getMaterial(int $material_id,int $depot_id,int $supplier_id): \Hyperf\Database\Model\Model|Builder|null
|
||||
{
|
||||
return $this->where('is_del',MaterialCode::IS_NO_DEL)
|
||||
->where('material_id',$material_id)
|
||||
->where('depot_id',$depot_id)
|
||||
->where('supplier_id',$supplier_id)
|
||||
->where('is_del',MaterialCode::IS_NO_DEL)
|
||||
->first();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,8 @@ class DepotRequest extends FormRequest
|
||||
'depot_add' => ['name','city_id','kitchen_id'],
|
||||
'depot_edit' => ['id','name'],
|
||||
'depot_delete' => ['id'],
|
||||
'purchase' => ['depot_id','material_id','supplier_id','type','purchase_price','number','city_id','kitchen_id'],
|
||||
'purchase' => ['depot_id','material_id','supplier_id','purchase_price','number','city_id','kitchen_id'],
|
||||
'purchase_back' => ['id','number'],
|
||||
'purchase_list' => ['limit','query_id','query_kitchen_id'],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -135,10 +135,11 @@ class DepotService extends BaseService{
|
||||
if (empty($materialInfo)) throw new ErrException("材料不存在");
|
||||
|
||||
$supplierId = (int)$this->request->input('supplier_id');
|
||||
$supplierInfo = $this->SupplierModel->getInfoById($supplierId);
|
||||
if (empty($supplierInfo)) throw new ErrException('供应商不存在');
|
||||
if (!empty($supplierId)){
|
||||
$supplierInfo = $this->SupplierModel->getInfoById($supplierId);
|
||||
if (empty($supplierInfo)) throw new ErrException('供应商不存在');
|
||||
}
|
||||
|
||||
$type = (int)$this->request->input('type');
|
||||
$purchase_price = (double)$this->request->input('purchase_price');
|
||||
$number = (double)$this->request->input('number');
|
||||
|
||||
@@ -153,7 +154,7 @@ class DepotService extends BaseService{
|
||||
$depotPurchase->depot_id = $depotId;
|
||||
$depotPurchase->material_id = $materialId;
|
||||
$depotPurchase->supplier_id = $supplierId;
|
||||
$depotPurchase->type = $type;
|
||||
$depotPurchase->type = 1;
|
||||
$depotPurchase->purchase_price = $purchase_price;
|
||||
$depotPurchase->number = $number;
|
||||
$depotPurchase->sum_price = $sum_price;
|
||||
@@ -176,14 +177,8 @@ class DepotService extends BaseService{
|
||||
$materialStock->unit_price = $purchase_price;
|
||||
}
|
||||
else{
|
||||
//采购入库
|
||||
if ($depotPurchase->type == 1){
|
||||
$materialStock->current_stock = $materialStock->current_stock + $number;
|
||||
}
|
||||
//采购退货
|
||||
else
|
||||
$materialStock->current_stock = $materialStock->current_stock - $number;
|
||||
|
||||
//库存增加
|
||||
$materialStock->current_stock = $materialStock->current_stock + $number;
|
||||
}
|
||||
|
||||
if (!$depotPurchase->save() || !$materialStock->save()) throw new ErrException('采购添加失败');
|
||||
@@ -192,6 +187,51 @@ class DepotService extends BaseService{
|
||||
|
||||
}
|
||||
|
||||
public function purchaseBack():array
|
||||
{
|
||||
$id = (int)$this->request->input('id');
|
||||
$number = (double)$this->request->input('number');
|
||||
$info = $this->DepotPurchaseModel->getDepotPurchase($id);
|
||||
if (!empty($info)){
|
||||
$depotPurchase = new DepotPurchase();
|
||||
$depotPurchase->depot_id = $info->depot_id;
|
||||
$depotPurchase->material_id = $info->material_id;
|
||||
$depotPurchase->supplier_id = $info->supplier_id;
|
||||
$depotPurchase->type = 2;
|
||||
$depotPurchase->purchase_price = $info->purchase_price;
|
||||
if (empty($number)){
|
||||
$depotPurchase->number = $info->number;
|
||||
}
|
||||
else{
|
||||
if ($info->number >= $number)
|
||||
$depotPurchase->number = $number;
|
||||
else
|
||||
throw new ErrException('采购退货数量不能大于进货数量');
|
||||
}
|
||||
|
||||
$depotPurchase->sum_price = $depotPurchase->purchase_price * $depotPurchase->number;
|
||||
$depotPurchase->city_id = $info->city_id;
|
||||
$depotPurchase->kitchen_id = $info->kitchen_id;
|
||||
$depotPurchase->operator_id = $this->adminId;
|
||||
}
|
||||
|
||||
$materialStock = $this->MaterialStockModel
|
||||
->where('depot_id',$depotPurchase->depot_id)
|
||||
->where('material_id',$depotPurchase->material_id)
|
||||
->where('supplier_id',$depotPurchase->supplier_id)
|
||||
->first();
|
||||
if (empty($materialStock))
|
||||
throw new ErrException('库存更改异常');
|
||||
else{
|
||||
//库存减少
|
||||
$materialStock->current_stock = $materialStock->current_stock - $depotPurchase->number;
|
||||
}
|
||||
|
||||
if (!$depotPurchase->save() || !$materialStock->save()) throw new ErrException('采购退货失败');
|
||||
|
||||
return $this->return->success();
|
||||
}
|
||||
|
||||
public function purchaseList():array
|
||||
{
|
||||
$limit = (int)$this->request->input('limit', 10);
|
||||
|
||||
@@ -382,3 +382,17 @@ GET {{host}}/admin/depot/purchase_list?limit=10
|
||||
content-type: application/json
|
||||
Authorization: Bearer {{admin_token}}
|
||||
|
||||
### 采购入库
|
||||
POST {{host}}/admin/depot/depot_purchase
|
||||
Content-Type: application/x-www-form-urlencoded
|
||||
Authorization: Bearer {{admin_token}}
|
||||
|
||||
depot_id=1&material_id=1&supplier_id=1&purchase_price=60&number=2&city_id=1&kitchen_id=1
|
||||
|
||||
### 采购退货
|
||||
POST {{host}}/admin/depot/depot_purchase_back
|
||||
Content-Type: application/x-www-form-urlencoded
|
||||
Authorization: Bearer {{admin_token}}
|
||||
|
||||
id=6&number=2
|
||||
|
||||
|
||||
Reference in New Issue
Block a user