Merge branch 'dev' into branch-dev
This commit is contained in:
872
app/Service/Admin/Depot/DepotService.php
Normal file
872
app/Service/Admin/Depot/DepotService.php
Normal file
@@ -0,0 +1,872 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Service\Admin\Depot;
|
||||
|
||||
use App\Constants\Admin\DepotCode;
|
||||
use App\Constants\Common\MaterialCode;
|
||||
use App\Constants\Common\RoleCode;
|
||||
use App\Exception\ErrException;
|
||||
use App\Extend\DateUtil;
|
||||
use App\Model\Depot;
|
||||
use App\Model\DepotPurchase;
|
||||
use App\Model\DepotRecycle;
|
||||
use App\Model\DepotSale;
|
||||
use App\Model\Material;
|
||||
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{
|
||||
|
||||
/**
|
||||
* @var Depot
|
||||
*/
|
||||
#[Inject]
|
||||
protected Depot $DepotModel;
|
||||
|
||||
#[Inject]
|
||||
protected Material $MaterialModel;
|
||||
|
||||
#[Inject]
|
||||
protected Supplier $SupplierModel;
|
||||
|
||||
#[Inject]
|
||||
protected MaterialStock $MaterialStockModel;
|
||||
|
||||
#[Inject]
|
||||
protected DepotPurchase $DepotPurchaseModel;
|
||||
|
||||
#[Inject]
|
||||
protected DepotSale $DepotSaleModel;
|
||||
|
||||
|
||||
#[Inject]
|
||||
protected DepotRecycle $DepotRecycleModel;
|
||||
|
||||
#[inject]
|
||||
protected MaterialApplication $MaterialApplicationModel;
|
||||
|
||||
public function handle()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function depotList():array
|
||||
{
|
||||
$limit = (int)$this->request->input('limit', 10);
|
||||
$id = (int)$this->request->input('query_id');
|
||||
$kitchenId = (int)$this->request->input('query_kitchen_id');
|
||||
|
||||
$list = $this->DepotModel
|
||||
->where('is_del',DepotCode::IS_NO_DEL)
|
||||
->when($id,function ($query) use ($id) {
|
||||
$query->where('id',$id);
|
||||
})
|
||||
->when($kitchenId,function ($query) use ($kitchenId) {
|
||||
$query->where('kitchen_id',$kitchenId);
|
||||
})
|
||||
->paginate($limit)->toArray();
|
||||
|
||||
return $this->return->success('success',$list);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function add():array
|
||||
{
|
||||
$name = $this->request->input('name');
|
||||
$kitchen_id = (int)$this->request->input('kitchen_id');
|
||||
$info = $this->DepotModel->getInfoByName($name,$kitchen_id);
|
||||
if (!empty($info)) throw new ErrException('仓库已存在');
|
||||
|
||||
$depot = new Depot();
|
||||
$depot->name = $name;
|
||||
$depot->city_id = $this->request->input('city_id');
|
||||
$depot->kitchen_id = $kitchen_id;
|
||||
|
||||
if (!$depot->save()) throw new ErrException('仓库添加失败');
|
||||
|
||||
return $this->return->success();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function edit(): array
|
||||
{
|
||||
$id = (int)$this->request->input('id');
|
||||
$depotName = $this->request->input('name');
|
||||
$kitchen_id = (int)$this->request->input('kitchen_id');
|
||||
|
||||
$info = $this->DepotModel->getInfoById($id);
|
||||
if (empty($info)) throw new ErrException('数据不存在');
|
||||
|
||||
$name = $this->DepotModel->getInfoByName($depotName,$kitchen_id);
|
||||
if (!empty($name)){
|
||||
if ($name->id != $info->id && $info->kitchen_id == $kitchen_id)
|
||||
throw new ErrException('仓库已存在');
|
||||
}
|
||||
|
||||
$info->name = $depotName;
|
||||
|
||||
if (!$info->save()) throw new ErrException('仓库修改失败');
|
||||
|
||||
return $this->return->success();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function delete(): array
|
||||
{
|
||||
$id = (int)$this->request->input('id');
|
||||
|
||||
$info = $this->DepotModel->getInfoById($id);
|
||||
if (empty($info)) throw new ErrException('仓库不存在');
|
||||
|
||||
$info->is_del = DepotCode::IS_DEL;
|
||||
|
||||
if (!$info->save()) throw new ErrException('删除失败');
|
||||
|
||||
return $this->return->success();
|
||||
}
|
||||
|
||||
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');
|
||||
|
||||
$purchase_price = $this->request->input('purchase_price');
|
||||
$number = $this->request->input('number');
|
||||
|
||||
if (!empty($purchase_price) && !empty($number)){
|
||||
$sum_price = bcmul($purchase_price,$number,2);
|
||||
}
|
||||
|
||||
$cityId = (int)$this->request->input('city_id');
|
||||
$kitchenId = (int)$this->request->input('kitchen_id');
|
||||
|
||||
$depotPurchase = new DepotPurchase();
|
||||
$depotPurchase->depot_id = $depotId;
|
||||
$depotPurchase->material_id = $materialId;
|
||||
$depotPurchase->supplier_id = $supplierId;
|
||||
$depotPurchase->type = 1;
|
||||
$depotPurchase->purchase_price = $purchase_price;
|
||||
$depotPurchase->number = $number;
|
||||
$depotPurchase->sum_price = $sum_price;
|
||||
$depotPurchase->status = DepotCode::INPUT;
|
||||
$depotPurchase->city_id = $cityId;
|
||||
$depotPurchase->kitchen_id = $kitchenId;
|
||||
$depotPurchase->operator_id = $this->adminId;
|
||||
|
||||
|
||||
$materialStock = $this->MaterialStockModel
|
||||
->where('depot_id',$depotId)
|
||||
->where('material_id',$materialId)
|
||||
->where('supplier_id',$supplierId)
|
||||
->first();
|
||||
if (empty($materialStock)){
|
||||
$materialStock = new MaterialStock();
|
||||
$materialStock->depot_id = $depotId;
|
||||
$materialStock->material_id = $materialId;
|
||||
$materialStock->supplier_id = $supplierId;
|
||||
$materialStock->current_stock = $number;
|
||||
$materialStock->unit_price = $purchase_price;
|
||||
}
|
||||
else{
|
||||
//库存增加
|
||||
// $totalValue = bcadd(bcmul($purchase_price,$number),bcmul($materialStock->unit_price,$materialStock->current_stock),2);
|
||||
$materialStock->current_stock = bcadd($materialStock->current_stock,$number,2);
|
||||
// $materialStock->unit_price = bcdiv($totalValue,$materialStock->current_stock,2);
|
||||
$materialStock->unit_price = $purchase_price;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
$number = $this->request->input('number');
|
||||
$sum_price = bcmul($info->purchase_price,$number,2);
|
||||
|
||||
$info->number = $number;
|
||||
$info->sum_price = $sum_price;
|
||||
|
||||
$materialStock = $this->MaterialStockModel
|
||||
->where('depot_id',$info->depot_id)
|
||||
->where('material_id',$info->material_id)
|
||||
->where('supplier_id',$info->supplier_id)
|
||||
->first();
|
||||
|
||||
$materialStock->current_stock = bcsub(bcadd($materialStock->current_stock,$number,2),$old_number,2);
|
||||
|
||||
if (!$info->save() || !$materialStock->save()) throw new ErrException('采购数量修改失败');
|
||||
|
||||
DB::commit();
|
||||
} catch (ErrException $error) {
|
||||
Db::rollBack();
|
||||
throw new ErrException($error->getMessage());
|
||||
}
|
||||
return $this->return->success();
|
||||
|
||||
}
|
||||
|
||||
public function purchaseBack():array
|
||||
{
|
||||
Db::beginTransaction();
|
||||
try {
|
||||
$id = (int)$this->request->input('id');
|
||||
// $number = (double)$this->request->input('number');
|
||||
$info = $this->DepotPurchaseModel->getDepotPurchase($id);
|
||||
$info->status = DepotCode::OUTPUT;
|
||||
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 = bcmul($depotPurchase->purchase_price,$depotPurchase->number,2);
|
||||
$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{
|
||||
if ($materialStock->current_stock < $depotPurchase->number)
|
||||
throw new ErrException('库存数量小于退货数量');
|
||||
//库存减少
|
||||
$materialStock->current_stock = bcsub($materialStock->current_stock,$depotPurchase->number,2);
|
||||
}
|
||||
|
||||
if (!$depotPurchase->save() || !$materialStock->save() || !$info->save()) throw new ErrException('采购退货异常');
|
||||
|
||||
DB::commit();
|
||||
} catch (ErrException $error) {
|
||||
Db::rollBack();
|
||||
throw new ErrException($error->getMessage());
|
||||
}
|
||||
|
||||
return $this->return->success();
|
||||
}
|
||||
|
||||
public function purchaseList():array
|
||||
{
|
||||
$limit = (int)$this->request->input('limit', 10);
|
||||
$id = (int)$this->request->input('query_id');
|
||||
$type = (int)$this->request->input('type');
|
||||
$kitchenId = (int)$this->request->input('query_kitchen_id');
|
||||
|
||||
$list = $this->DepotPurchaseModel
|
||||
->leftJoin('material','depot_purchase.material_id','=','material.id')
|
||||
->leftJoin('supplier','depot_purchase.supplier_id','=','supplier.id')
|
||||
->leftJoin('depot','depot_purchase.depot_id','=','depot.id')
|
||||
->where('depot_purchase.is_del',DepotCode::IS_NO_DEL)
|
||||
->when($id,function ($query) use ($id) {
|
||||
$query->where('depot_purchase.id',$id);
|
||||
})
|
||||
->when(!empty($type), function ($query) use ($type) {
|
||||
$query->where('type', $type);
|
||||
})
|
||||
->when($kitchenId,function ($query) use ($kitchenId) {
|
||||
$query->where('depot_purchase.kitchen_id',$kitchenId);
|
||||
})
|
||||
->orderBy('depot_purchase.create_time','desc')
|
||||
->paginate($limit,['depot_purchase.*','material.name as material_name','supplier.name as supplier_name','depot.name as depot_name'])
|
||||
->toArray();
|
||||
|
||||
return $this->return->success('success',$list);
|
||||
}
|
||||
|
||||
public function purchaseStatistics():array
|
||||
{
|
||||
$cityId = (int)$this->request->input('city_id');
|
||||
|
||||
//今日采购额
|
||||
$todayStartDate = DateUtil::getTodayStartDate();
|
||||
$todayEndDate = DateUtil::getTodayEndDate();
|
||||
$todayPurchase = $this->DepotPurchaseModel
|
||||
->where('is_del',DepotCode::IS_NO_DEL)
|
||||
->where('type',1)
|
||||
->where('status',DepotCode::INPUT)
|
||||
->where('city_id',$cityId)
|
||||
->whereBetween('create_time',[$todayStartDate,$todayEndDate])
|
||||
->sum('sum_price');
|
||||
|
||||
//昨天采购额
|
||||
$yesterdayStartDate = DateUtil::getStartDate();
|
||||
$yesterdayEndDate = DateUtil::getEndDate();
|
||||
$yesterdayPurchase = $this->DepotPurchaseModel
|
||||
->where('is_del',DepotCode::IS_NO_DEL)
|
||||
->where('type',1)
|
||||
->where('status',DepotCode::INPUT)
|
||||
->where('city_id',$cityId)
|
||||
->whereBetween('create_time',[$yesterdayStartDate,$yesterdayEndDate])
|
||||
->sum('sum_price');
|
||||
|
||||
//本月采购额
|
||||
$currentMonthStartDate = date("Y-m-01 00:00:00");
|
||||
$monthPurchase = $this->DepotPurchaseModel
|
||||
->where('is_del',DepotCode::IS_NO_DEL)
|
||||
->where('type',1)
|
||||
->where('status',DepotCode::INPUT)
|
||||
->where('city_id',$cityId)
|
||||
->whereBetween('create_time',[$currentMonthStartDate,$todayEndDate])
|
||||
->sum('sum_price');
|
||||
|
||||
//今年采购额
|
||||
$currentYearStartDate = date("Y-01-01 00:00:00");
|
||||
$yearPurchase = $this->DepotPurchaseModel
|
||||
->where('is_del',DepotCode::IS_NO_DEL)
|
||||
->where('type',1)
|
||||
->where('status',DepotCode::INPUT)
|
||||
->where('city_id',$cityId)
|
||||
->whereBetween('create_time',[$currentYearStartDate,$todayEndDate])
|
||||
->sum('sum_price');
|
||||
|
||||
return $this->return->success('success',["todayPurchase"=>$todayPurchase,"yesterdayPurchase"=>$yesterdayPurchase,
|
||||
"monthPurchase"=>$monthPurchase,"yearPurchase"=>$yearPurchase]);
|
||||
}
|
||||
|
||||
public function depotSale():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');
|
||||
$number = $this->request->input('number');
|
||||
$applicationId = (int)$this->request->input('application_id');
|
||||
$cityId = (int)$this->request->input('city_id');
|
||||
$kitchenId = (int)$this->request->input('kitchen_id');
|
||||
|
||||
if (RoleCode::WAREHOUSE != $this->roleId && RoleCode::SUPER_ADMIN != $this->roleId && RoleCode::ADMIN != $this->roleId)
|
||||
throw new ErrException('该角色没有权限');
|
||||
|
||||
$applicationInfo = $this->MaterialApplicationModel
|
||||
->where('id',$applicationId)
|
||||
->first();
|
||||
|
||||
$materialStock = $this->MaterialStockModel
|
||||
->where('depot_id',$depotId)
|
||||
->where('material_id',$materialId)
|
||||
->where('supplier_id',$supplierId)
|
||||
->first();
|
||||
|
||||
$depotSale = new DepotSale();
|
||||
$depotSale->depot_id = $depotId;
|
||||
$depotSale->dish_id = $applicationInfo->dish_id;
|
||||
$depotSale->material_id = $materialId;
|
||||
$depotSale->supplier_id = $supplierId;
|
||||
$depotSale->sale_price = $materialStock->unit_price;
|
||||
$depotSale->number = $number;
|
||||
$depotSale->sum_price = bcmul($depotSale->sale_price,$number,2);
|
||||
$depotSale->application_id = $applicationId;
|
||||
$depotSale->city_id = $cityId;
|
||||
$depotSale->kitchen_id = $kitchenId;
|
||||
$depotSale->operator_id = $this->adminId;
|
||||
|
||||
//库存减少
|
||||
$materialStock->current_stock = bcsub($materialStock->current_stock,$number,2);
|
||||
|
||||
$applicationInfo->al_number = bcadd($number,$applicationInfo->al_number,2);
|
||||
if ($applicationInfo->al_number < $applicationInfo->number)
|
||||
$applicationInfo->status = MaterialCode::PART_OUT;
|
||||
else
|
||||
$applicationInfo->status = MaterialCode::ALL_OUT;
|
||||
|
||||
if (!$depotSale->save() || !$materialStock->save() ||!$applicationInfo->save()) throw new ErrException('商品出库异常');
|
||||
|
||||
DB::commit();
|
||||
} catch (ErrException $error) {
|
||||
Db::rollBack();
|
||||
throw new ErrException($error->getMessage());
|
||||
}
|
||||
|
||||
return $this->return->success();
|
||||
|
||||
}
|
||||
|
||||
public function saleUpdate():array
|
||||
{
|
||||
Db::beginTransaction();
|
||||
try {
|
||||
$id = (int)$this->request->input('id');
|
||||
|
||||
if (RoleCode::WAREHOUSE != $this->roleId && RoleCode::SUPER_ADMIN != $this->roleId && RoleCode::ADMIN != $this->roleId)
|
||||
throw new ErrException('该角色没有权限');
|
||||
|
||||
$info = $this->DepotSaleModel
|
||||
->where('id',$id)
|
||||
->first();
|
||||
$applicationInfo = $this->MaterialApplicationModel
|
||||
->where('id',$info->application_id)
|
||||
->first();
|
||||
|
||||
$old_number = $info->number;
|
||||
|
||||
$number = $this->request->input('number');
|
||||
$sum_price = bcmul($info->sale_price,$number,2);
|
||||
|
||||
$info->number = $number;
|
||||
$info->sum_price = $sum_price;
|
||||
|
||||
$materialStock = $this->MaterialStockModel
|
||||
->where('depot_id',$info->depot_id)
|
||||
->where('material_id',$info->material_id)
|
||||
->where('supplier_id',$info->supplier_id)
|
||||
->first();
|
||||
|
||||
$materialStock->current_stock = bcadd($materialStock->current_stock,bcsub($old_number,$number,2),2);
|
||||
|
||||
$applicationInfo->al_number = bcadd($applicationInfo->al_number,bcsub($number,$old_number,2),2);
|
||||
if ($applicationInfo->al_number < $applicationInfo->number)
|
||||
$applicationInfo->status = MaterialCode::PART_OUT;
|
||||
else
|
||||
$applicationInfo->status = MaterialCode::ALL_OUT;
|
||||
|
||||
if (!$info->save() || !$materialStock->save() || !$applicationInfo->save()) throw new ErrException('商品出库数量修改失败');
|
||||
|
||||
DB::commit();
|
||||
} catch (ErrException $error) {
|
||||
Db::rollBack();
|
||||
throw new ErrException($error->getMessage());
|
||||
}
|
||||
|
||||
return $this->return->success();
|
||||
}
|
||||
|
||||
public function saleDelete():array
|
||||
{
|
||||
Db::beginTransaction();
|
||||
try {
|
||||
$id = (int)$this->request->input('id');
|
||||
|
||||
if (RoleCode::WAREHOUSE != $this->roleId && RoleCode::SUPER_ADMIN != $this->roleId && RoleCode::ADMIN != $this->roleId)
|
||||
throw new ErrException('该角色没有权限');
|
||||
|
||||
$info = $this->DepotSaleModel
|
||||
->where('is_del',MaterialCode::IS_NO_DEL)
|
||||
->where('id',$id)
|
||||
->first();
|
||||
|
||||
$applicationInfo = $this->MaterialApplicationModel
|
||||
->where('id',$info->application_id)
|
||||
->first();
|
||||
|
||||
$applicationInfo->al_number = bcsub($applicationInfo->al_number,$info->number,2);
|
||||
if (bccomp($applicationInfo->al_number,'0') <= 0)
|
||||
$applicationInfo->status = MaterialCode::AUDITED;
|
||||
else if ($applicationInfo->al_number < $applicationInfo->number)
|
||||
$applicationInfo->status = MaterialCode::PART_OUT;
|
||||
|
||||
$materialStock = $this->MaterialStockModel
|
||||
->where('depot_id',$info->depot_id)
|
||||
->where('material_id',$info->material_id)
|
||||
->where('supplier_id',$info->supplier_id)
|
||||
->first();
|
||||
|
||||
$materialStock->current_stock = bcadd($materialStock->current_stock,$info->number,2);
|
||||
|
||||
$info->is_del = MaterialCode::IS_DEL;
|
||||
|
||||
if (!$applicationInfo->save() || !$materialStock->save() || !$info->save()) throw new ErrException('商品出库数量删除失败');
|
||||
|
||||
DB::commit();
|
||||
} catch (ErrException $error) {
|
||||
Db::rollBack();
|
||||
throw new ErrException($error->getMessage());
|
||||
}
|
||||
|
||||
return $this->return->success();
|
||||
}
|
||||
|
||||
public function saleList():array
|
||||
{
|
||||
$limit = (int)$this->request->input('limit', 10);
|
||||
$id = (int)$this->request->input('query_id');
|
||||
$kitchenId = (int)$this->request->input('query_kitchen_id');
|
||||
|
||||
$list = $this->DepotSaleModel
|
||||
->leftJoin('material','depot_sale.material_id','=','material.id')
|
||||
->leftJoin('supplier','depot_sale.supplier_id','=','supplier.id')
|
||||
->leftJoin('dish','depot_sale.dish_id','=','dish.id')
|
||||
->leftJoin('depot','depot_sale.depot_id','=','depot.id')
|
||||
->leftJoin('admin_user','depot_sale.operator_id','=','admin_user.id')
|
||||
->where('depot_sale.is_del',MaterialCode::IS_NO_DEL)
|
||||
->when($id,function ($query) use ($id) {
|
||||
$query->where('depot_sale.id',$id);
|
||||
})
|
||||
->when($kitchenId,function ($query) use ($kitchenId) {
|
||||
$query->where('depot_sale.kitchen_id',$kitchenId);
|
||||
})
|
||||
->paginate($limit,['depot_sale.*','material.name as material_name','supplier.name as supplier_name','dish.dish as dish_name','admin_user.chinese_name as operator_name','depot.name as depot_name'])
|
||||
->toArray();
|
||||
|
||||
return $this->return->success('success',$list);
|
||||
}
|
||||
|
||||
public function saleStatistics():array
|
||||
{
|
||||
$cityId = (int)$this->request->input('city_id');
|
||||
|
||||
//今日销售额
|
||||
$todayStartDate = DateUtil::getTodayStartDate();
|
||||
$todayEndDate = DateUtil::getTodayEndDate();
|
||||
$todaySale = $this->DepotSaleModel
|
||||
->where('is_del',DepotCode::IS_NO_DEL)
|
||||
->where('city_id',$cityId)
|
||||
->whereBetween('create_time',[$todayStartDate,$todayEndDate])
|
||||
->sum('sum_price');
|
||||
|
||||
//昨天销售额
|
||||
$yesterdayStartDate = DateUtil::getStartDate();
|
||||
$yesterdayEndDate = DateUtil::getEndDate();
|
||||
$yesterdaySale = $this->DepotPurchaseModel
|
||||
->where('is_del',DepotCode::IS_NO_DEL)
|
||||
->where('city_id',$cityId)
|
||||
->whereBetween('create_time',[$yesterdayStartDate,$yesterdayEndDate])
|
||||
->sum('sum_price');
|
||||
|
||||
//本月销售额
|
||||
$currentMonthStartDate = date("Y-m-01 00:00:00");
|
||||
$monthSale = $this->DepotSaleModel
|
||||
->where('is_del',DepotCode::IS_NO_DEL)
|
||||
->where('city_id',$cityId)
|
||||
->whereBetween('create_time',[$currentMonthStartDate,$todayEndDate])
|
||||
->sum('sum_price');
|
||||
|
||||
//今年销售额
|
||||
$currentYearStartDate = date("Y-01-01 00:00:00");
|
||||
$yearSale = $this->DepotSaleModel
|
||||
->where('is_del',DepotCode::IS_NO_DEL)
|
||||
->where('city_id',$cityId)
|
||||
->whereBetween('create_time',[$currentYearStartDate,$todayEndDate])
|
||||
->sum('sum_price');
|
||||
|
||||
return $this->return->success('success',["todaySale"=>$todaySale,"yesterdaySale"=>$yesterdaySale,
|
||||
"monthSale"=>$monthSale,"yearSale"=>$yearSale]);
|
||||
}
|
||||
|
||||
public function recycle():array
|
||||
{
|
||||
Db::beginTransaction();
|
||||
try {
|
||||
$materialId = (int)$this->request->input('material_id');
|
||||
$supplierId = (int)$this->request->input('supplier_id');
|
||||
$number = (double)$this->request->input('number');
|
||||
$saleId = (int)$this->request->input('sale_id');
|
||||
$cityId = (int)$this->request->input('city_id');
|
||||
$kitchenId = (int)$this->request->input('kitchen_id');
|
||||
$depotInfo = $this->DepotModel
|
||||
->getInfoByName('回收仓库',$kitchenId);
|
||||
if (empty($depotInfo))
|
||||
throw new ErrException('未创建回收仓库');
|
||||
else
|
||||
$depotId = $depotInfo->id;
|
||||
|
||||
if (RoleCode::WAREHOUSE != $this->roleId && RoleCode::SUPER_ADMIN != $this->roleId && RoleCode::ADMIN != $this->roleId)
|
||||
throw new ErrException('该角色没有权限');
|
||||
|
||||
$saleInfo = $this->DepotSaleModel
|
||||
->where('is_del',MaterialCode::IS_NO_DEL)
|
||||
->where('id',$saleId)
|
||||
->first();
|
||||
|
||||
$saleInfo->back_number = $saleInfo->back_number + $number;
|
||||
$saleInfo->sum_price = $saleInfo->sale_price * ($saleInfo->number - $saleInfo->back_number);
|
||||
if ($saleInfo->back_number > $saleInfo->number)
|
||||
throw new ErrException('回收数量不能大于出库数量');
|
||||
|
||||
$materialStock = $this->MaterialStockModel
|
||||
->where('material_id',$materialId)
|
||||
->where('depot_id',$depotId)
|
||||
->where('supplier_id',$supplierId)
|
||||
->first();
|
||||
|
||||
$depotRecycle = new DepotRecycle();
|
||||
$depotRecycle->depot_id = $depotId;
|
||||
$depotRecycle->material_id = $materialId;
|
||||
$depotRecycle->supplier_id = $supplierId;
|
||||
$depotRecycle->recycle_price = $saleInfo->sale_price;
|
||||
$depotRecycle->number = $number;
|
||||
$depotRecycle->sum_price = $saleInfo->sale_price * $number;
|
||||
$depotRecycle->sale_id = $saleId;
|
||||
$depotRecycle->status = MaterialCode::AUDITED;
|
||||
$depotRecycle->city_id = $cityId;
|
||||
$depotRecycle->kitchen_id = $kitchenId;
|
||||
$depotRecycle->operator_id = $this->adminId;
|
||||
|
||||
if (empty($materialStock)){
|
||||
$materialStock = new MaterialStock();
|
||||
$materialStock->depot_id = $depotId;
|
||||
$materialStock->material_id = $materialId;
|
||||
$materialStock->supplier_id = $supplierId;
|
||||
$materialStock->current_stock = $number;
|
||||
$materialStock->unit_price = $depotRecycle->recycle_price;
|
||||
}
|
||||
else
|
||||
$materialStock->current_stock = $materialStock->current_stock + $number;
|
||||
|
||||
if (!$saleInfo->save() || !$depotRecycle->save() || !$materialStock->save()) throw new ErrException('回收发生异常');
|
||||
|
||||
DB::commit();
|
||||
} catch (ErrException $error) {
|
||||
Db::rollBack();
|
||||
throw new ErrException($error->getMessage());
|
||||
}
|
||||
|
||||
|
||||
return $this->return->success();
|
||||
|
||||
}
|
||||
|
||||
public function recycleUpdate():array
|
||||
{
|
||||
Db::beginTransaction();
|
||||
try {
|
||||
$id = (int)$this->request->input('id');
|
||||
$number = (double)$this->request->input('number');
|
||||
|
||||
if (RoleCode::WAREHOUSE != $this->roleId && RoleCode::SUPER_ADMIN != $this->roleId && RoleCode::ADMIN != $this->roleId)
|
||||
throw new ErrException('该角色没有权限');
|
||||
|
||||
$info = $this->DepotRecycleModel
|
||||
->where('id',$id)
|
||||
->first();
|
||||
|
||||
$old_number = $info->number;
|
||||
$sum_price = $info->recycle_price * $number;
|
||||
$info->number = $number;
|
||||
$info->sum_price = $sum_price;
|
||||
|
||||
$materialStock = $this->MaterialStockModel
|
||||
->where('material_id',$info->material_id)
|
||||
->where('depot_id',$info->depot_id)
|
||||
->where('supplier_id',$info->supplier_id)
|
||||
->first();
|
||||
|
||||
$materialStock->current_stock = $materialStock->current_stock + $number - $old_number;
|
||||
|
||||
$saleInfo = $this->DepotSaleModel
|
||||
->where('id',$info->sale_id)
|
||||
->first();
|
||||
|
||||
$saleInfo->back_number = $saleInfo->back_number + $number - $old_number;
|
||||
$saleInfo->sum_price = $saleInfo->sale_price * ($saleInfo->number - $saleInfo->back_number);
|
||||
if ($saleInfo->back_number > $saleInfo->number)
|
||||
throw new ErrException('回收数量不能大于出库数量');
|
||||
|
||||
if (!$info->save() || !$materialStock->save() || !$saleInfo->save()) throw new ErrException('商品回收数量修改失败');
|
||||
DB::commit();
|
||||
} catch (ErrException $error) {
|
||||
Db::rollBack();
|
||||
throw new ErrException($error->getMessage());
|
||||
}
|
||||
|
||||
return $this->return->success();
|
||||
|
||||
}
|
||||
|
||||
public function recycleDelete():array
|
||||
{
|
||||
Db::beginTransaction();
|
||||
try {
|
||||
$id = (int)$this->request->input('id');
|
||||
|
||||
if (RoleCode::WAREHOUSE != $this->roleId && RoleCode::SUPER_ADMIN != $this->roleId && RoleCode::ADMIN != $this->roleId)
|
||||
throw new ErrException('该角色没有权限');
|
||||
|
||||
$info = $this->DepotRecycleModel
|
||||
->where('id',$id)
|
||||
->first();
|
||||
|
||||
if ($info->status == MaterialCode::AUDITED){
|
||||
throw new ErrException('该回收已审核通过');
|
||||
}
|
||||
|
||||
$info->is_del = MaterialCode::IS_DEL;
|
||||
|
||||
$materialStock = $this->MaterialStockModel
|
||||
->where('material_id',$info->material_id)
|
||||
->where('depot_id',$info->depot_id)
|
||||
->where('supplier_id',$info->supplier_id)
|
||||
->first();
|
||||
|
||||
$materialStock->current_stock = $materialStock->current_stock - $info->number;
|
||||
|
||||
$saleInfo = $this->DepotSaleModel
|
||||
->where('id',$info->sale_id)
|
||||
->first();
|
||||
|
||||
$saleInfo->back_number = $saleInfo->back_number - $info->number;
|
||||
$saleInfo->sum_price = $saleInfo->sale_price * ($saleInfo->number - $saleInfo->back_number);
|
||||
|
||||
if (!$info->save() || !$materialStock->save() || !$saleInfo->save())
|
||||
throw new ErrException('商品回收删除失败');
|
||||
|
||||
DB::commit();
|
||||
} catch (ErrException $error) {
|
||||
Db::rollBack();
|
||||
throw new ErrException($error->getMessage());
|
||||
}
|
||||
|
||||
return $this->return->success();
|
||||
}
|
||||
|
||||
public function recycleList():array{
|
||||
|
||||
$limit = (int)$this->request->input('limit', 10);
|
||||
$id = (int)$this->request->input('query_id');
|
||||
$kitchenId = (int)$this->request->input('query_kitchen_id');
|
||||
|
||||
if (RoleCode::WAREHOUSE != $this->roleId && RoleCode::SUPER_ADMIN != $this->roleId && RoleCode::ADMIN != $this->roleId)
|
||||
throw new ErrException('该角色没有权限');
|
||||
|
||||
$list = $this->DepotRecycleModel
|
||||
->leftJoin('depot','depot_recycle.depot_id','=','depot.id')
|
||||
->leftJoin('material','depot_recycle.material_id','=','material.id')
|
||||
->leftJoin('supplier','depot_recycle.supplier_id','=','supplier.id')
|
||||
->leftJoin('admin_user','depot_recycle.operator_id','=','admin_user.id')
|
||||
->where('depot_recycle.is_del',MaterialCode::IS_NO_DEL)
|
||||
->when($id,function ($query) use ($id) {
|
||||
$query->where('depot_recycle.id',$id);
|
||||
})
|
||||
->when($kitchenId > 0,function($query) use($kitchenId){
|
||||
$query->where('depot_recycle.kitchen_id',$kitchenId);
|
||||
})
|
||||
->paginate($limit,['depot_recycle.*','material.name as material_name','supplier.name as supplier_name','admin_user.chinese_name as operator_name','depot.name as depot_name'])
|
||||
->toArray();
|
||||
|
||||
return $this->return->success('success',$list);
|
||||
}
|
||||
|
||||
public function recycleAudit():array
|
||||
{
|
||||
Db::beginTransaction();
|
||||
try {
|
||||
$id = (int)$this->request->input('id');
|
||||
$status = (int)$this->request->input('status');
|
||||
|
||||
if (RoleCode::WAREHOUSE != $this->roleId && RoleCode::SUPER_ADMIN != $this->roleId && RoleCode::ADMIN != $this->roleId)
|
||||
throw new ErrException('该角色没有权限');
|
||||
|
||||
$info = $this->DepotRecycleModel
|
||||
->where('id',$id)
|
||||
->first();
|
||||
|
||||
if ($info->status != MaterialCode::AUDITED){
|
||||
if ($status == MaterialCode::AUDITED){
|
||||
$saleInfo = $this->DepotSaleModel
|
||||
->where('is_del',MaterialCode::IS_NO_DEL)
|
||||
->where('id',$info->sale_id)
|
||||
->first();
|
||||
|
||||
if (empty($saleInfo)){
|
||||
throw new ErrException('无出库记录');
|
||||
}
|
||||
|
||||
$saleInfo->back_number = $saleInfo->back_number + $info->number;
|
||||
$saleInfo->sum_price = $saleInfo->sale_price * ($saleInfo->number - $saleInfo->back_number);
|
||||
|
||||
$materialStock = $this->MaterialStockModel
|
||||
->where('material_id',$info->material_id)
|
||||
->where('depot_id',$info->depot_id)
|
||||
->where('supplier_id',$info->supplier_id)
|
||||
->first();
|
||||
|
||||
if (empty($materialStock)){
|
||||
$materialStock = new MaterialStock();
|
||||
$materialStock->depot_id = $info->depotId;
|
||||
$materialStock->material_id = $info->materialId;
|
||||
$materialStock->supplier_id = $info->supplierId;
|
||||
$materialStock->current_stock = $info->number;
|
||||
$materialStock->unit_price = $info->recycle_price;
|
||||
}
|
||||
else
|
||||
$materialStock->current_stock = $materialStock->current_stock + $info->number;
|
||||
|
||||
if (!$materialStock->save() || !$saleInfo->save()) throw new ErrException('回收审核异常');
|
||||
|
||||
}
|
||||
}
|
||||
if ($info->status == MaterialCode::AUDITED){
|
||||
if ($status == MaterialCode::UN_AUDIT || $status == MaterialCode::AUDIT_REFUSE){
|
||||
$materialStock = $this->MaterialStockModel
|
||||
->where('is_del',MaterialCode::IS_NO_DEL)
|
||||
->where('material_id',$info->material_id)
|
||||
->where('depot_id',$info->depot_id)
|
||||
->where('supplier_id',$info->supplier_id)
|
||||
->first();
|
||||
|
||||
$materialStock->current_stock = $materialStock->current_stock - $info->number;
|
||||
|
||||
$saleInfo = $this->DepotSaleModel
|
||||
->where('id',$info->sale_id)
|
||||
->first();
|
||||
|
||||
$saleInfo->back_number = $saleInfo->back_number - $info->number;
|
||||
$saleInfo->sum_price = $saleInfo->sale_price * ($saleInfo->number - $saleInfo->back_number);
|
||||
|
||||
if (!$materialStock->save() || !$saleInfo->save()) throw new ErrException('回收审核异常');
|
||||
}
|
||||
}
|
||||
|
||||
$info->status = $status;
|
||||
|
||||
if (!$info->save()) throw new ErrException('回收审核异常');
|
||||
|
||||
DB::commit();
|
||||
} catch (ErrException $error) {
|
||||
Db::rollBack();
|
||||
throw new ErrException($error->getMessage());
|
||||
}
|
||||
|
||||
return $this->return->success();
|
||||
|
||||
}
|
||||
}
|
||||
65
app/Service/Admin/Material/DishService.php
Normal file
65
app/Service/Admin/Material/DishService.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Service\Admin\Material;
|
||||
|
||||
use App\Constants\Common\DishCode;
|
||||
use App\Model\Dish;
|
||||
use App\Service\Admin\BaseService;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
|
||||
class DishService extends BaseService
|
||||
{
|
||||
|
||||
/**
|
||||
* @var Dish
|
||||
*/
|
||||
#[Inject]
|
||||
protected Dish $DishModel;
|
||||
|
||||
public function handle()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function dishList(): array
|
||||
{
|
||||
$limit = (int)$this->request->input('limit', 10);
|
||||
$id = (int)$this->request->input('query_id');
|
||||
$cityId = (int)$this->request->input('query_city_id',0);
|
||||
$dishName = $this->request->input('query_dish_name');
|
||||
$date = $this->request->input('query_date');
|
||||
$status = (int)$this->request->input('query_status');
|
||||
$chefId = (int)$this->request->input('query_chef_id',0);
|
||||
|
||||
$list = $this->DishModel
|
||||
->where('is_del',DishCode::IS_NO_DEL)
|
||||
->when($id > 0, function ($query) use ($id) {
|
||||
$query->where('id', $id);
|
||||
})
|
||||
->when($cityId > 0, function ($query) use ($cityId) {
|
||||
$query->where('city_id', $cityId);
|
||||
})
|
||||
->when($dishName, function ($query) use ($dishName) {
|
||||
$query->where('dish', 'like', "$dishName%");
|
||||
})
|
||||
->when($date, function ($query) use ($date) {
|
||||
$query->where('date', $date);
|
||||
})
|
||||
->when($status, function ($query) use ($status) {
|
||||
$query->where('status', $status);
|
||||
})
|
||||
->when($chefId, function ($query) use ($chefId) {
|
||||
$query->where('chef_id', $chefId);
|
||||
})
|
||||
->orderBy('date','desc')
|
||||
->paginate($limit)->toArray();
|
||||
|
||||
return $this->return->success('success',$list);
|
||||
}
|
||||
|
||||
}
|
||||
130
app/Service/Admin/Material/MaterialCategoryService.php
Normal file
130
app/Service/Admin/Material/MaterialCategoryService.php
Normal file
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Service\Admin\Material;
|
||||
|
||||
use App\Constants\Common\MaterialCode;
|
||||
use App\Exception\ErrException;
|
||||
use App\Model\MaterialCategory;
|
||||
use App\Service\Admin\BaseService;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
|
||||
class MaterialCategoryService extends BaseService{
|
||||
|
||||
/**
|
||||
* @var MaterialCategory
|
||||
*/
|
||||
#[Inject]
|
||||
protected MaterialCategory $MaterialCategoryModel;
|
||||
|
||||
public function handle()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function add(): array
|
||||
{
|
||||
$model = new MaterialCategory();
|
||||
$pid = (int)$this->request->input('parent_id',0);
|
||||
if ($pid > 0){
|
||||
// $pidInfo = $this->MaterialCategoryModel->getInfoById($pid);
|
||||
$model->parent_id = $pid;
|
||||
}
|
||||
|
||||
$model->name = $this->request->input('name');
|
||||
$model->city_id = (int)$this->request->input('city_id',0);
|
||||
$model->kitchen_id = (int)$this->request->input('kitchen_id',0);
|
||||
|
||||
if (!$model->save()) throw new ErrException('添加失败');
|
||||
|
||||
return $this->return->success();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function edit(): array
|
||||
{
|
||||
$id = (int)$this->request->input('id');
|
||||
|
||||
$info = $this->MaterialCategoryModel->getInfoById($id);
|
||||
if (empty($info))
|
||||
throw new ErrException('数据不存在');
|
||||
|
||||
$info->name = $this->request->input('name');
|
||||
|
||||
$pid = (int)$this->request->input('parent_id',0);
|
||||
if ($pid == $id)
|
||||
throw new ErrException('上级数据不能为自身');
|
||||
|
||||
$pidInfo = $this->MaterialCategoryModel->getInfoById($pid);
|
||||
if (empty($pidInfo))
|
||||
throw new ErrException('该上级数据不存在');
|
||||
|
||||
$info->parent_id = $pid;
|
||||
|
||||
if (!$info->save()) throw new ErrException('修改失败');
|
||||
|
||||
return $this->return->success();
|
||||
}
|
||||
|
||||
public function delete(): array
|
||||
{
|
||||
$id = (int)$this->request->input('id');
|
||||
|
||||
$info = $this->MaterialCategoryModel->getInfoById($id);
|
||||
if (empty($info)) throw new ErrException('数据不存在');
|
||||
|
||||
$children = $this->MaterialCategoryModel->getInfoByPId($id);
|
||||
if (!empty($children)) throw new ErrException('请先删除下级数据');
|
||||
|
||||
$info->is_del = MaterialCode::IS_DEL;
|
||||
if (!$info->save()) throw new ErrException('删除失败');
|
||||
|
||||
return $this->return->success();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function findById():array
|
||||
{
|
||||
$id = (int)$this->request->input('query_id');
|
||||
$info = $this->MaterialCategoryModel->getInfoById($id)->toArray();
|
||||
if (empty($info)) throw new ErrException('数据不存在');
|
||||
return $this->return->success('success',$info);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function list(): array
|
||||
{
|
||||
$cityId = (int)$this->request->input('city_id');
|
||||
|
||||
$list = $this->MaterialCategoryModel
|
||||
->where('city_id',$cityId)
|
||||
->where('is_del',MaterialCode::IS_NO_DEL)->get()->toArray();
|
||||
|
||||
$tree = [];
|
||||
$map = [];
|
||||
|
||||
foreach ($list as &$category) {
|
||||
$category['children'] = [];
|
||||
$map[$category['id']] = &$category;
|
||||
|
||||
if ($category['parent_id'] && isset($map[$category['parent_id']])) {
|
||||
$map[$category['parent_id']]['children'][] = &$category;
|
||||
} else {
|
||||
$tree[] = &$category;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->return->success('success',$tree);
|
||||
}
|
||||
}
|
||||
199
app/Service/Admin/Material/MaterialService.php
Normal file
199
app/Service/Admin/Material/MaterialService.php
Normal file
@@ -0,0 +1,199 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Service\Admin\Material;
|
||||
|
||||
use App\Constants\Admin\DepotCode;
|
||||
use App\Constants\Common\MaterialCode;
|
||||
use App\Exception\ErrException;
|
||||
use App\Model\Material;
|
||||
use App\Model\MaterialApplication;
|
||||
use App\Model\MaterialStock;
|
||||
use App\Service\Admin\BaseService;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
|
||||
class MaterialService extends BaseService{
|
||||
|
||||
/**
|
||||
* @var Material
|
||||
*/
|
||||
#[Inject]
|
||||
protected Material $MaterialModel;
|
||||
|
||||
#[Inject]
|
||||
protected MaterialStock $MaterialStockModel;
|
||||
|
||||
#[Inject]
|
||||
protected MaterialApplication $MaterialApplicationModel;
|
||||
|
||||
public function handle()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function materialList(): array
|
||||
{
|
||||
$limit = (int)$this->request->input('limit', 10);
|
||||
$name = $this->request->input('query_name');
|
||||
$kitchenId = $this->request->input('query_kitchen_id');
|
||||
|
||||
$list = $this
|
||||
->MaterialModel
|
||||
->where('is_del',MaterialCode::IS_NO_DEL)
|
||||
// ->where('status',MaterialCode::ENABLE)
|
||||
->when(!empty($name), function ($query) use ($name) {
|
||||
$query->where('name', 'like', "$name%");
|
||||
})
|
||||
->when(!empty($kitchenId), function ($query) use ($kitchenId) {
|
||||
$query->where('kitchen_id', $kitchenId);
|
||||
})
|
||||
->paginate($limit)->toArray();
|
||||
|
||||
return $this->return->success('success',$list);
|
||||
}
|
||||
|
||||
public function add(): array
|
||||
{
|
||||
$material = new Material();
|
||||
$material->name = $this->request->input('name');
|
||||
$material->category_id = (int)$this->request->input('category_id');
|
||||
|
||||
$material->standard = $this->request->input('standard');
|
||||
$material->unit = $this->request->input('unit');
|
||||
$material->bar_code = $this->request->input('bar_code');
|
||||
$material->city_id = (int)$this->request->input('city_id',0);
|
||||
$material->kitchen_id = (int)$this->request->input('kitchen_id',0);
|
||||
|
||||
if (!$material->save()) throw new ErrException('添加失败');
|
||||
|
||||
return $this->return->success();
|
||||
}
|
||||
|
||||
public function delete(): array
|
||||
{
|
||||
$id = (int)$this->request->input('id');
|
||||
|
||||
$info = $this->MaterialModel->getInfoById($id);
|
||||
if (empty($info)) throw new ErrException('数据不存在');
|
||||
|
||||
$info->is_del = MaterialCode::IS_DEL;
|
||||
if (!$info->save()) throw new ErrException('删除失败');
|
||||
|
||||
return $this->return->success();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function edit(): array
|
||||
{
|
||||
$id = (int)$this->request->input('id');
|
||||
|
||||
$info = $this->MaterialModel->getInfoById($id);
|
||||
if (empty($info))
|
||||
throw new ErrException('数据不存在');
|
||||
|
||||
$category_id = (int)$this->request->input('category_id');
|
||||
$name = $this->request->input('name');
|
||||
$standard = $this->request->input('standard');
|
||||
$unit = $this->request->input('unit');
|
||||
$bar_code = $this->request->input('bar_code');
|
||||
$status = (int)$this->request->input('status');
|
||||
|
||||
if (!empty($category_id)) $info->category_id = $category_id;
|
||||
if (!empty($name)) $info->name = $name;
|
||||
if (!empty($standard)) $info->standard = $standard;
|
||||
if (!empty($unit)) $info->unit = $unit;
|
||||
if (!empty($bar_code)) $info->bar_code = $bar_code;
|
||||
if (!empty($status)) $info->status = $status;
|
||||
|
||||
if (!$info->save()) throw new ErrException('修改失败');
|
||||
|
||||
return $this->return->success();
|
||||
}
|
||||
|
||||
public function materialStockList(): array
|
||||
{
|
||||
$limit = (int)$this->request->input('limit', 10);
|
||||
$name = $this->request->input('query_name');
|
||||
$materialId = $this->request->input('query_materialId');
|
||||
$depotId = (int)$this->request->input('query_depotId');
|
||||
$supplierId = (int)$this->request->input('query_supplierId');
|
||||
$kitchenId = (int)$this->request->input('query_kitchenId');
|
||||
$list = $this->MaterialStockModel
|
||||
->leftJoin('material', 'material_stock.material_id', '=', 'material.id')
|
||||
->leftJoin('supplier', 'material_stock.supplier_id', '=', 'supplier.id')
|
||||
->leftJoin('depot', 'material_stock.depot_id', '=', 'depot.id')
|
||||
->where('material_stock.is_del',MaterialCode::IS_NO_DEL)
|
||||
->when(!empty($name), function ($query) use ($name) {
|
||||
$query->where('material.name', 'like', "$name%");
|
||||
})
|
||||
->when(!empty($materialId), function ($query) use ($materialId) {
|
||||
$query->where('material_stock.material_id', $materialId);
|
||||
})
|
||||
->when(!empty($depotId), function ($query) use ($depotId) {
|
||||
$query->where('material_stock.depot_id', $depotId);
|
||||
})
|
||||
->when(!empty($supplierId), function ($query) use ($supplierId) {
|
||||
$query->where('material_stock.supplier_id', $supplierId);
|
||||
})
|
||||
->when(!empty($kitchenId), function ($query) use ($kitchenId) {
|
||||
$query->where('material.kitchen_id', $kitchenId);
|
||||
})
|
||||
->paginate($limit,['material_stock.*','material.name as material_name','supplier.name as supplier_name','depot.name as depot_name'])
|
||||
->toArray();
|
||||
|
||||
return $this->return->success('success',$list);
|
||||
}
|
||||
|
||||
public function materialStockEdit(): array{
|
||||
$id = (int)$this->request->input('id');
|
||||
$currentStock = (double)$this->request->input('current_stock');
|
||||
$unitPrice = (double)$this->request->input('unit_price');
|
||||
|
||||
$info = $this->MaterialStockModel->where('id',$id)->first();
|
||||
|
||||
if (!empty($currentStock)){
|
||||
$info->current_stock = $currentStock;
|
||||
}
|
||||
if (!empty($unitPrice)){
|
||||
$info->unit_price = $unitPrice;
|
||||
}
|
||||
|
||||
if (!$info->save()) throw new ErrException('修改失败');
|
||||
|
||||
return $this->return->success();
|
||||
}
|
||||
|
||||
public function costListByChef():array
|
||||
{
|
||||
$limit = (int)$this->request->input('limit', 10);
|
||||
$chefName = $this->request->input('chef_name');
|
||||
$date = $this->request->input('date');
|
||||
$kitchenId = (int)$this->request->input('query_kitchen_id');
|
||||
|
||||
$list = $this->MaterialApplicationModel
|
||||
->leftJoin('material','material_application.material_id','=','material.id')
|
||||
->leftJoin('dish','material_application.dish_id','=','dish.id')
|
||||
->leftJoin('depot_sale','material_application.id','=','depot_sale.application_id')
|
||||
->leftJoin('admin_user','material_application.operator_id','=','admin_user.id')
|
||||
->where('material_application.is_del',MaterialCode::IS_NO_DEL)
|
||||
->where('depot_sale.is_del',DepotCode::IS_NO_DEL)
|
||||
->when(!empty($chefName), function ($query) use ($chefName) {
|
||||
$query->where('admin_user.chinese_name', $chefName);
|
||||
})
|
||||
->when(!empty($date), function ($query) use ($date) {
|
||||
$query->where('dish.date', $date);
|
||||
})
|
||||
->when(!empty($kitchenId), function ($query) use ($kitchenId) {
|
||||
$query->where('material_application.kitchen_id', $kitchenId);
|
||||
})
|
||||
->paginate($limit,['admin_user.chinese_name','dish.dish','material.name as material_name','material_application.id as application_id','material_application.number as application_number','depot_sale.number as sale_number','depot_sale.back_number'])
|
||||
->toArray();
|
||||
|
||||
// return $this->return->success('success',['list' => $list]);
|
||||
return $this->return->success('success',$list);
|
||||
}
|
||||
|
||||
}
|
||||
105
app/Service/Admin/Material/SupplierService.php
Normal file
105
app/Service/Admin/Material/SupplierService.php
Normal file
@@ -0,0 +1,105 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Service\Admin\Material;
|
||||
|
||||
use App\Exception\ErrException;
|
||||
use App\Model\Supplier;
|
||||
use App\Service\Admin\BaseService;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
|
||||
class SupplierService extends BaseService{
|
||||
|
||||
/**
|
||||
* @var Supplier
|
||||
*/
|
||||
#[Inject]
|
||||
protected Supplier $SupplierModel;
|
||||
|
||||
public function handle()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function list():array
|
||||
{
|
||||
$limit = (int)$this->request->input('limit', 10);
|
||||
$name = (int)$this->request->input('query_name');
|
||||
|
||||
$list = $this->SupplierModel
|
||||
->leftJoin('system_city','system_city.id','supplier.city_id')
|
||||
->leftJoin('kitchen','kitchen.id','supplier.kitchen_id')
|
||||
->where('supplier.is_del',1)
|
||||
->when(!empty($name), function ($query) use ($name) {
|
||||
$query->where('supplier.name', 'like', "$name%");
|
||||
})
|
||||
->paginate($limit,['supplier.*','system_city.title as city_name','kitchen.name as kitchen_name'])
|
||||
->toArray();
|
||||
|
||||
return $this->return->success('success',$list);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function add():array
|
||||
{
|
||||
$name = $this->request->input('name');
|
||||
$mobile = $this->request->input('mobile');
|
||||
$address = $this->request->input('address');
|
||||
$city_id = (int)$this->request->input('city_id');
|
||||
$kitchen_id = (int)$this->request->input('kitchen_id');
|
||||
|
||||
$supplier = new Supplier();
|
||||
$supplier->name = $name;
|
||||
$supplier->mobile = $mobile;
|
||||
$supplier->address = $address;
|
||||
$supplier->city_id = $city_id;
|
||||
$supplier->kitchen_id = $kitchen_id;
|
||||
|
||||
if (!$supplier->save()) throw new ErrException('供应商添加失败');
|
||||
|
||||
return $this->return->success();
|
||||
}
|
||||
|
||||
public function edit():array
|
||||
{
|
||||
$id = (int)$this->request->input('id');
|
||||
$name = $this->request->input('name');
|
||||
$mobile = $this->request->input('mobile');
|
||||
$address = $this->request->input('address');
|
||||
|
||||
$info = $this->SupplierModel->getInfoById($id);
|
||||
if (empty($info)) throw new ErrException('数据不存在');
|
||||
|
||||
if(!empty($name)) $info->name = $name;
|
||||
if(!empty($mobile)) $info->mobile = $mobile;
|
||||
if(!empty($address)) $info->address = $address;
|
||||
|
||||
if (!$info->save()) throw new ErrException('供应商修改失败');
|
||||
|
||||
return $this->return->success();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function delete(): array
|
||||
{
|
||||
$id = (int)$this->request->input('id');
|
||||
|
||||
$info = $this->SupplierModel->getInfoById($id);
|
||||
if (empty($info)) throw new ErrException('供应商不存在');
|
||||
|
||||
$info->is_del = 2;
|
||||
|
||||
if (!$info->save()) throw new ErrException('删除失败');
|
||||
|
||||
return $this->return->success();
|
||||
}
|
||||
}
|
||||
78
app/Service/Admin/System/WarehouseService.php
Normal file
78
app/Service/Admin/System/WarehouseService.php
Normal file
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Service\Admin\System;
|
||||
|
||||
use App\Constants\Admin\UserCode;
|
||||
use App\Constants\Common\RoleCode;
|
||||
use App\Exception\ErrException;
|
||||
use App\Model\AdminUser;
|
||||
use App\Model\WarehouseKeeper;
|
||||
use App\Service\Admin\BaseService;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
|
||||
class WarehouseService extends BaseService{
|
||||
|
||||
/**
|
||||
* @var AdminUser
|
||||
*/
|
||||
#[Inject]
|
||||
protected readonly AdminUser $adminUserModel;
|
||||
|
||||
/**
|
||||
* @var WarehouseKeeper
|
||||
*/
|
||||
#[Inject]
|
||||
protected readonly WarehouseKeeper $warehouseKeeperModel;
|
||||
|
||||
public function handle()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function warehouseList(): array
|
||||
{
|
||||
$limit = (int)$this->request->input('limit', 10);
|
||||
$cityId = (int)$this->request->input('query_city_id');
|
||||
$name = $this->request->input('query_name');
|
||||
|
||||
$list = $this
|
||||
->warehouseKeeperModel
|
||||
->leftJoin('admin_user', 'admin_user.id', '=', 'warehouse_keeper.user_id')
|
||||
->where('admin_user.is_del',UserCode::IS_NO_DEL)
|
||||
->where('admin_user.status',UserCode::ENABLE)
|
||||
->where('admin_user.role_id',RoleCode::WAREHOUSE)
|
||||
->when(!empty($cityId), function ($query) use ($cityId) {
|
||||
$query->where('admin_user.city_id', $cityId);
|
||||
})
|
||||
->when(!empty($name), function ($query) use ($name) {
|
||||
$query->where('admin_user.chinese_name', 'like', "$name%");
|
||||
})
|
||||
->paginate($limit,['warehouse_keeper.id','admin_user.avatar','admin_user.chinese_name','admin_user.city_id','warehouse_keeper.kitchen_id'])->toArray();
|
||||
|
||||
if (empty($list)) return $this->return->success('success',['list' => []]);
|
||||
|
||||
return $this->return->success('success',['list' => $list]);
|
||||
}
|
||||
|
||||
public function settingWarehouse(): array
|
||||
{
|
||||
$userId = (int)$this->request->input('user_id');
|
||||
$kitchenId = (int)$this->request->input('kitchen_id');
|
||||
$info = $this->warehouseKeeperModel->getInfoByUserId($userId);
|
||||
|
||||
if (RoleCode::SUPER_ADMIN != $this->roleId && RoleCode::ADMIN != $this->roleId)
|
||||
throw new ErrException('该角色没有权限');
|
||||
|
||||
if (!empty($info)) {
|
||||
if(!empty($kitchenId))
|
||||
$info->kitchen_id = $kitchenId;
|
||||
} else {
|
||||
throw new ErrException('设置仓管信息失败');
|
||||
}
|
||||
if (!$info->save()) throw new ErrException('设置仓管信息失败');
|
||||
|
||||
return $this->return->success();
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,7 @@ use App\Model\AdminRole;
|
||||
use App\Model\AdminUser;
|
||||
use App\Model\Chef;
|
||||
use App\Model\DriverSequence;
|
||||
use App\Model\WarehouseKeeper;
|
||||
use App\Service\Admin\BaseService;
|
||||
use Exception;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
@@ -112,6 +113,7 @@ class EmployeeService extends BaseService
|
||||
]),
|
||||
RoleCode::CHEF =>
|
||||
$this->addChef($model->id),
|
||||
RoleCode::WAREHOUSE => $this->addWarehouseKeeper($model->id),
|
||||
default => true,
|
||||
};
|
||||
|
||||
@@ -126,6 +128,12 @@ class EmployeeService extends BaseService
|
||||
$chef->user_id = $id;
|
||||
return $chef->save();
|
||||
}
|
||||
public function addWarehouseKeeper($id): bool
|
||||
{
|
||||
$warehouseKeeper = new WarehouseKeeper();
|
||||
$warehouseKeeper->user_id = $id;
|
||||
return $warehouseKeeper->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改
|
||||
@@ -152,6 +160,7 @@ class EmployeeService extends BaseService
|
||||
$del = match ($info->role_id) {
|
||||
RoleCode::DRIVER => (new DriverSequence)->where('driver_id', $info->id)->delete(),
|
||||
RoleCode::CHEF => (new Chef)->where('user_id', $info->id)->delete(),
|
||||
RoleCode::WAREHOUSE => (new WarehouseKeeper)->where('user_id', $info->id)->delete(),
|
||||
default => true,
|
||||
};
|
||||
|
||||
@@ -160,6 +169,7 @@ class EmployeeService extends BaseService
|
||||
'driver_id' => $info->id,
|
||||
]),
|
||||
RoleCode::CHEF => $this->addChef($info->id),
|
||||
RoleCode::WAREHOUSE => $this->addWarehouseKeeper($info->id),
|
||||
default => true,
|
||||
};
|
||||
|
||||
@@ -199,6 +209,7 @@ class EmployeeService extends BaseService
|
||||
$del = match ($info->role_id) {
|
||||
RoleCode::DRIVER => (new DriverSequence)->where('driver_id', $info->id)->update(['is_del' => UserCode::IS_DEL]),
|
||||
RoleCode::CHEF => (new Chef)->where('user_id', $info->id)->update(['is_del' => UserCode::IS_DEL]),
|
||||
RoleCode::WAREHOUSE => (new WarehouseKeeper)->where('user_id', $info->id)->update(['is_del' => UserCode::IS_DEL]),
|
||||
default => true,
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user