feat : statement
This commit is contained in:
19
app/Amqp/Consumer/Statement/ChefConsumer.php
Normal file
19
app/Amqp/Consumer/Statement/ChefConsumer.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Amqp\Consumer\Statement;
|
||||
|
||||
use Hyperf\Amqp\Result;
|
||||
use Hyperf\Amqp\Annotation\Consumer;
|
||||
use Hyperf\Amqp\Message\ConsumerMessage;
|
||||
use PhpAmqpLib\Message\AMQPMessage;
|
||||
|
||||
#[Consumer(exchange: 'hyperf', routingKey: 'hyperf', queue: 'hyperf', name: "ChefConsumer", nums: 1)]
|
||||
class ChefConsumer extends ConsumerMessage
|
||||
{
|
||||
public function consumeMessage($data, AMQPMessage $message): Result
|
||||
{
|
||||
return Result::ACK;
|
||||
}
|
||||
}
|
||||
19
app/Amqp/Consumer/Statement/DriverConsumer.php
Normal file
19
app/Amqp/Consumer/Statement/DriverConsumer.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Amqp\Consumer\Statement;
|
||||
|
||||
use Hyperf\Amqp\Result;
|
||||
use Hyperf\Amqp\Annotation\Consumer;
|
||||
use Hyperf\Amqp\Message\ConsumerMessage;
|
||||
use PhpAmqpLib\Message\AMQPMessage;
|
||||
|
||||
#[Consumer(exchange: 'hyperf', routingKey: 'hyperf', queue: 'hyperf', name: "DriverConsumer", nums: 1)]
|
||||
class DriverConsumer extends ConsumerMessage
|
||||
{
|
||||
public function consumeMessage($data, AMQPMessage $message): Result
|
||||
{
|
||||
return Result::ACK;
|
||||
}
|
||||
}
|
||||
113
app/Amqp/Consumer/Statement/FinancesConsumer.php
Normal file
113
app/Amqp/Consumer/Statement/FinancesConsumer.php
Normal file
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Amqp\Consumer\Statement;
|
||||
|
||||
use App\Constants\Common\OrderCode;
|
||||
use App\Lib\Log;
|
||||
use App\Model\Cycle;
|
||||
use App\Model\FinancesStatement;
|
||||
use App\Model\Kitchen;
|
||||
use App\Model\Order;
|
||||
use Hyperf\Amqp\Message\Type;
|
||||
use Hyperf\Amqp\Result;
|
||||
use Hyperf\Amqp\Annotation\Consumer;
|
||||
use Hyperf\Amqp\Message\ConsumerMessage;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
use PhpAmqpLib\Message\AMQPMessage;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
|
||||
#[Consumer(exchange: 'Finances', routingKey: 'Finances', queue: 'Finances.statement', name: "FinancesConsumer", nums: 1)]
|
||||
class FinancesConsumer extends ConsumerMessage
|
||||
{
|
||||
|
||||
/**
|
||||
* @var Type|string 消息类型
|
||||
*/
|
||||
protected Type|string $type = Type::DIRECT;
|
||||
|
||||
/**
|
||||
* @var FinancesStatement
|
||||
*/
|
||||
#[Inject]
|
||||
protected FinancesStatement $financesStatementModel;
|
||||
|
||||
/**
|
||||
* @var Cycle
|
||||
*/
|
||||
#[Inject]
|
||||
protected Cycle $cycleModel;
|
||||
|
||||
/**
|
||||
* @var Kitchen
|
||||
*/
|
||||
#[Inject]
|
||||
protected Kitchen $kitchenModel;
|
||||
|
||||
/**
|
||||
* @var Order
|
||||
*/
|
||||
#[Inject]
|
||||
protected Order $orderModel;
|
||||
|
||||
/**
|
||||
* @var Log
|
||||
*/
|
||||
#[Inject]
|
||||
protected Log $log;
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
* @param AMQPMessage $message
|
||||
* @return Result
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function consumeMessage($data, AMQPMessage $message): Result
|
||||
{
|
||||
if (!$data['kitchen_id'] || !$data['cycle_id']) {
|
||||
$this->log->error('FinancesConsumer:error:NoData:'.json_encode($data));
|
||||
return Result::ACK;
|
||||
}
|
||||
|
||||
$kitchen = $this->kitchenModel->where('id',$data['kitchen_id'])->first();
|
||||
$cycle = $this->cycleModel->where('id',$data['cycle_id'])->first();
|
||||
if (empty($kitchen) || empty($cycle)) {
|
||||
$this->log->error('FinancesConsumer:error:kitchenOrCycleError:'.json_encode([
|
||||
'kitchen_id' => $data['kitchen_id'],
|
||||
'cycle_id' => $data['cycle_id'],
|
||||
'cycle' => $cycle,
|
||||
'kitchen' => $kitchen,
|
||||
'data' => $data,
|
||||
]));
|
||||
return Result::ACK;
|
||||
}
|
||||
|
||||
$statement = $this->financesStatementModel->getStatementByCycleIdAndKitchenId($data['cycle_id'],$data['kitchen_id']);
|
||||
if (!empty($statement)) $statement->delete();
|
||||
|
||||
$statement = new FinancesStatement();
|
||||
|
||||
$statement->date = $cycle->dates;
|
||||
$statement->cycle_id = $cycle->id;
|
||||
$statement->kitchen_id = $kitchen->id;
|
||||
$statement->discounts = $this->orderModel->getDiscountsByCycleIdAndKitchenId($cycle->id, $kitchen->id);
|
||||
$statement->net_sales = $this->orderModel->getNetSalesByCycleIdAndKitchenId($cycle->id, $kitchen->id);
|
||||
$statement->gross_sales = $statement->net_sales + $statement->discounts;
|
||||
$statement->option_order_number = $this->orderModel->getOrderNumberByCycleIdAndKitchenId($cycle->id, $kitchen->id, OrderCode::ORDER_TYPE_OPTIONAL);
|
||||
$statement->option_copies = $this->orderModel->getCopiesByCycleIdAndKitchenId($cycle->id, $kitchen->id, OrderCode::ORDER_TYPE_OPTIONAL);
|
||||
$statement->meal_order_number = $this->orderModel->getOrderNumberByCycleIdAndKitchenId($cycle->id, $kitchen->id, OrderCode::ORDER_TYPE_MEAL);
|
||||
$statement->meal_copies = $this->orderModel->getCopiesByCycleIdAndKitchenId($cycle->id, $kitchen->id, OrderCode::ORDER_TYPE_MEAL);
|
||||
|
||||
if (!$statement->save()) {
|
||||
$this->log->error('FinancesConsumer:error:FinancesStatement:'.json_encode([
|
||||
'statement' => $statement,
|
||||
'data' => $data,
|
||||
]));
|
||||
}
|
||||
|
||||
return Result::ACK;
|
||||
}
|
||||
}
|
||||
19
app/Amqp/Consumer/Statement/SiteConsumer.php
Normal file
19
app/Amqp/Consumer/Statement/SiteConsumer.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Amqp\Consumer\Statement;
|
||||
|
||||
use Hyperf\Amqp\Result;
|
||||
use Hyperf\Amqp\Annotation\Consumer;
|
||||
use Hyperf\Amqp\Message\ConsumerMessage;
|
||||
use PhpAmqpLib\Message\AMQPMessage;
|
||||
|
||||
#[Consumer(exchange: 'hyperf', routingKey: 'hyperf', queue: 'hyperf', name: "SiteConsumer", nums: 1)]
|
||||
class SiteConsumer extends ConsumerMessage
|
||||
{
|
||||
public function consumeMessage($data, AMQPMessage $message): Result
|
||||
{
|
||||
return Result::ACK;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user