feat: 增强抽奖管理功能,支持手动创建、更新和删除期号
- 新增 API 路由和控制器,允许管理员手动创建、更新和删除抽奖期号。 - 更新抽奖调度逻辑,确保在抽奖时间和封盘时间的管理上更加灵活。 - 添加多语言支持的错误信息,提升用户体验。 - 更新测试用例,确保新功能的正确性和稳定性。
This commit is contained in:
37
app/Services/Draw/DrawDestroyService.php
Normal file
37
app/Services/Draw/DrawDestroyService.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Draw;
|
||||
|
||||
use App\Models\Draw;
|
||||
use App\Models\TicketOrder;
|
||||
use App\Lottery\DrawStatus;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
/**
|
||||
* 物理删除误建的未开始期号(无注单、无开奖结果)。
|
||||
*/
|
||||
final class DrawDestroyService
|
||||
{
|
||||
public function destroy(Draw $draw): void
|
||||
{
|
||||
DB::transaction(function () use ($draw): void {
|
||||
/** @var Draw $locked */
|
||||
$locked = Draw::query()->whereKey($draw->id)->lockForUpdate()->firstOrFail();
|
||||
|
||||
if ($locked->status !== DrawStatus::Pending->value) {
|
||||
throw new \RuntimeException('draw_not_deletable');
|
||||
}
|
||||
|
||||
if ($locked->resultBatches()->exists()) {
|
||||
throw new \RuntimeException('draw_result_exists');
|
||||
}
|
||||
|
||||
$betTotal = (int) TicketOrder::query()->where('draw_id', $locked->id)->sum('total_actual_deduct');
|
||||
if ($betTotal > 0) {
|
||||
throw new \RuntimeException('draw_has_bets');
|
||||
}
|
||||
|
||||
$locked->delete();
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user