feat : chef statement
This commit is contained in:
@@ -161,7 +161,6 @@ class DispenseAddService extends BaseService
|
||||
'coupon_dispense_id' => $this->dispenseId,
|
||||
'user_id' => $userId,
|
||||
]);
|
||||
// $producer = ApplicationContext::getContainer()->get(Producer::class);
|
||||
$this->producer->produce($message);
|
||||
}
|
||||
|
||||
|
||||
@@ -10,11 +10,13 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Service\Admin\Order;
|
||||
|
||||
use App\Amqp\Producer\Statement\FinancesProducer;
|
||||
use App\Constants\Common\OrderCode;
|
||||
use App\Exception\ErrException;
|
||||
use App\Model\Order;
|
||||
use App\Model\OrderGood;
|
||||
use App\Service\Admin\BaseService;
|
||||
use Hyperf\Amqp\Producer;
|
||||
use Hyperf\DbConnection\Db;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
|
||||
@@ -32,7 +34,16 @@ class FinishService extends BaseService
|
||||
#[Inject]
|
||||
protected OrderGood $orderGoodModel;
|
||||
|
||||
public function handle()
|
||||
/**
|
||||
* @var Producer
|
||||
*/
|
||||
#[Inject]
|
||||
protected Producer $producer;
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function handle(): array
|
||||
{
|
||||
$kitchenId = (int)$this->request->input('kitchenId');
|
||||
$cycleId = (int)$this->request->input('cycleId');
|
||||
@@ -58,7 +69,14 @@ class FinishService extends BaseService
|
||||
}
|
||||
});
|
||||
|
||||
// 财务结算节点 消息队列 - 生成财务结算数据 完成订单数据
|
||||
$financesMessage = new FinancesProducer([
|
||||
'cycle_id' => $cycleId,
|
||||
'kitchen_id' => $kitchenId,
|
||||
]);
|
||||
$this->producer->produce($financesMessage);
|
||||
|
||||
//
|
||||
|
||||
return $this->return->success();
|
||||
}
|
||||
|
||||
146
app/Service/Amqp/Statement/ChefService.php
Normal file
146
app/Service/Amqp/Statement/ChefService.php
Normal file
@@ -0,0 +1,146 @@
|
||||
<?php
|
||||
/**
|
||||
* This service file is part of item.
|
||||
*
|
||||
* @author ctexthuang
|
||||
* @contact ctexthuang@qq.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Service\Amqp\Statement;
|
||||
|
||||
use App\Constants\Common\OrderCode;
|
||||
use App\Model\ChefStatement;
|
||||
use App\Model\Cycle;
|
||||
use App\Model\Kitchen;
|
||||
use App\Model\OrderGood;
|
||||
use App\Model\Sku;
|
||||
use App\Model\Spu;
|
||||
use Exception;
|
||||
use Hyperf\DbConnection\Db;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
|
||||
class ChefService
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public int $kitchenId;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public int $cycleId;
|
||||
|
||||
/**
|
||||
* @var Cycle
|
||||
*/
|
||||
#[Inject]
|
||||
protected Cycle $cycleModel;
|
||||
|
||||
/**
|
||||
* @var Kitchen
|
||||
*/
|
||||
#[Inject]
|
||||
protected Kitchen $kitchenModel;
|
||||
|
||||
/**
|
||||
* @var OrderGood
|
||||
*/
|
||||
#[Inject]
|
||||
protected OrderGood $orderGoodModel;
|
||||
|
||||
/**
|
||||
* @var Sku
|
||||
*/
|
||||
#[Inject]
|
||||
protected Sku $skuModel;
|
||||
|
||||
/**
|
||||
* @var Spu
|
||||
*/
|
||||
#[Inject]
|
||||
protected Spu $spuModel;
|
||||
|
||||
/**
|
||||
* @var ChefStatement
|
||||
*/
|
||||
#[Inject]
|
||||
protected ChefStatement $chefStatementModel;
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
public function handle(): void
|
||||
{
|
||||
$kitchen = $this->kitchenModel->where('id',$this->kitchenId)->first();
|
||||
$cycle = $this->cycleModel->where('id',$this->cycleId)->first();
|
||||
if (empty($kitchen) || empty($cycle)) {
|
||||
throw new Exception('kitchenOrCycleError:'.json_encode([
|
||||
'kitchen_id' => $this->kitchenId,
|
||||
'cycle_id' => $this->cycleId,
|
||||
'cycle' => $cycle,
|
||||
'kitchen' => $kitchen,
|
||||
]));
|
||||
}
|
||||
|
||||
$orderGoods = $this->orderGoodModel
|
||||
->where('cycle_id',$cycle->id)
|
||||
->where('kitchen_id',$this->kitchenId)
|
||||
->whereIn('status',[
|
||||
OrderCode::FINISH,OrderCode::CANCEL,OrderCode::FINISH_REFUND
|
||||
])
|
||||
->get();
|
||||
if ($orderGoods->isEmpty()) throw new Exception('orderGoodError:dataNull');
|
||||
$orderGoods = $orderGoods->toArray();
|
||||
|
||||
$skuIds = array_unique(array_column($orderGoods, 'sku_id'));
|
||||
$skuInfo = $this->skuModel->whereIn('id',$skuIds)->pluck('spu_id','id')->toArray();
|
||||
if (empty($skuInfo)) throw new Exception('skuInfoError:dataNull');
|
||||
$spuInfo = $this->spuModel->whereIn('id',array_unique(array_values($skuInfo)))->pluck('chef_id','id')->toArray();
|
||||
|
||||
$currentDate = date('Y-m-d H:i:s');
|
||||
|
||||
$insertData = [];
|
||||
foreach ($orderGoods as $orderGood) {
|
||||
if (empty($insertData[$orderGood['sku_id']])) {
|
||||
$insertData[$orderGood['sku_id']] = [
|
||||
'date' => $cycle->dates,
|
||||
'chef_id' => $spuInfo[$skuInfo[$orderGood['sku_id']]]['chef_id'] ?? 0,
|
||||
'sku_id' => $orderGood['sku_id'],
|
||||
'cycle_id' => $this->cycleId,
|
||||
'kitchen_id' => $this->kitchenId,
|
||||
'sale' => 0,
|
||||
'refund' => 0,
|
||||
'cancel' => 0,
|
||||
'create_time' => $currentDate,
|
||||
'update_time' => $currentDate
|
||||
];
|
||||
}
|
||||
|
||||
match ($orderGoods['status']) {
|
||||
OrderCode::FINISH => $insertData[$orderGood['sku_id']]['sale'] += $orderGood['quantity'],
|
||||
OrderCode::FINISH_REFUND => $insertData[$orderGood['sku_id']]['refund'] += $orderGood['quantity'],
|
||||
OrderCode::CANCEL => $insertData[$orderGood['sku_id']]['cancel'] += $orderGood['quantity'],
|
||||
};
|
||||
}
|
||||
|
||||
if (empty($insertData)) throw new Exception('insertDataError:dataNull');
|
||||
|
||||
Db::transaction(function () use ($insertData) {
|
||||
$delFlag = $this->chefStatementModel->where('cycle_id',$this->cycleId)->where('kitchen_id',$this->kitchenId)->delete();
|
||||
|
||||
$insertFlag = (new ChefStatement)->insert($insertData);
|
||||
|
||||
if (!$delFlag || !$insertFlag) {
|
||||
throw new Exception('insertDataError:'.json_encode([
|
||||
'data' => $insertData,
|
||||
'cycle_id' => $this->cycleId,
|
||||
'kitchen_id' => $this->kitchenId,
|
||||
]));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -162,6 +162,7 @@ class PlaceOrderService extends BaseOrderService
|
||||
$orderGoodInsertArr[] = [
|
||||
'order_id' => $this->orderId,
|
||||
'cycle_id' => $this->cycleId,
|
||||
'kitchen_id' => $this->orderRes['site_info']['kitchen_id'],
|
||||
'sku_id' => $one['id'],
|
||||
'spu_id' => $one['spu_id'],
|
||||
'user_id' => $this->userId,
|
||||
|
||||
Reference in New Issue
Block a user