feat : statement

This commit is contained in:
2025-03-21 17:41:10 +08:00
parent 8176feb77b
commit 005fc4879a
12 changed files with 450 additions and 2 deletions

View File

@@ -0,0 +1,54 @@
<?php
declare(strict_types=1);
namespace App\Model;
use Hyperf\Database\Model\Builder;
use Hyperf\DbConnection\Model\Model;
/**
* @property int $id
* @property string $date
* @property int $cycle_id
* @property int $kitchen_id
* @property string $gross_sales
* @property string $discounts
* @property string $net_sales
* @property int $option_order_number
* @property int $option_copies
* @property int $meal_order_number
* @property int $meal_copies
* @property string $create_time
*/
class FinancesStatement extends Model
{
/**
* The table associated with the model.
*/
protected ?string $table = 'finances_statement';
/**
* The attributes that are mass assignable.
*/
protected array $fillable = [];
protected array $guarded = [];
/**
* The attributes that should be cast to native types.
*/
protected array $casts = ['id' => 'integer', 'cycle_id' => 'integer', 'kitchen_id' => 'integer', 'option_order_nnumber' => 'integer', 'option_copies' => 'integer', 'meal_order_number' => 'integer', 'meal_copies' => 'integer'];
const string CREATED_AT = 'create_time';
const null UPDATED_AT = null;
/**
* @param int $cycleId
* @param int $kitchenId
* @return Builder|\Hyperf\Database\Model\Model|FinancesStatement|null
*/
public function getStatementByCycleIdAndKitchenId(int $cycleId,int $kitchenId): \Hyperf\Database\Model\Model|FinancesStatement|Builder|null
{
return $this->where('cycle_id',$cycleId)->where('kitchen_id',$kitchenId)->first();
}
}

View File

@@ -87,4 +87,56 @@ class Order extends Model
'status' => OrderCode::PLAN
]);
}
/**
* @param int $cycleId
* @param int $kitchenId
* @return int|mixed|string
*/
public function getDiscountsByCycleIdAndKitchenId(int $cycleId, int $kitchenId): mixed
{
return $this->where('cycle_id',$cycleId)->where('kitchen_id',$kitchenId)->where('status',OrderCode::FINISH)->sum('discounts') ?? 0;
}
/**
* @param int $cycleId
* @param int $kitchenId
* @return int|mixed|string
*/
public function getNetSalesByCycleIdAndKitchenId(int $cycleId, int $kitchenId): mixed
{
return $this->where('cycle_id',$cycleId)->where('kitchen_id',$kitchenId)->where('status',OrderCode::FINISH)->sum('actual_price') ?? 0;
}
/**
* @param int $cycleId
* @param int $kitchenId
* @param int $type
* @return int
*/
public function getOrderNumberByCycleIdAndKitchenId(int $cycleId, int $kitchenId,int $type): int
{
return $this
->where('cycle_id',$cycleId)
->where('kitchen_id',$kitchenId)
->where('type',$type)
->where('status',OrderCode::FINISH)
->count() ?? 0;
}
/**
* @param int $cycleId
* @param int $kitchenId
* @param int $type
* @return int
*/
public function getCopiesByCycleIdAndKitchenId(int $cycleId, int $kitchenId,int $type): int
{
return $this
->where('cycle_id',$cycleId)
->where('kitchen_id',$kitchenId)
->where('type',$type)
->where('status',OrderCode::FINISH)
->sum('copies') ?? 0;
}
}