12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- <?php
- namespace App\Console\Commands\Xjc;
- use App\Repositories\Enums\Check\StatusEnum;
- use App\Repositories\Enums\Human\DispatchStatusEnum;
- use App\Repositories\Enums\ModelStatusEnum;
- use App\Repositories\Enums\Recruit\PositionStatusEnum;
- use App\Repositories\Models\Human\Dispatch;
- use App\Repositories\Models\Human\Staff;
- use App\Repositories\Models\Recruit\Position;
- use App\Repositories\Models\Xjc\Shop;
- use App\Repositories\Models\Xjc\ShopStatistics;
- use App\Services\Xjc\ShopStatisticsService;
- use Carbon\Carbon;
- use Illuminate\Console\Command;
- use Illuminate\Support\Arr;
- use Illuminate\Support\Facades\DB;
- use Illuminate\Support\Facades\Log;
- /**
- * 门店每日统计
- * @package Prettus\Repository\Generators\Commands
- * @author Anderson Andrade <contato@andersonandra.de>
- */
- class CheckDispatchStatisticsCommand extends Command
- {
- /**
- * The name of command.
- *
- * @var string
- */
- protected $signature = 'dispatch:statistics';
- /**
- * The description of command.
- *
- * @var string
- */
- protected $description = 'dispatch statistics';
- /**
- * The type of class being generated.
- *
- * @var string
- */
- protected $type = 'dispatch';
- /**
- * Execute the command.
- *
- * @return void
- * @see fire()
- */
- public function handle(ShopStatisticsService $shopStatisticsService)
- {
- $day = Carbon::yesterday()->toDateString();
- $shop_ids = Shop::query()->where('status', ModelStatusEnum::OK)->distinct()->pluck('id');
- foreach ($shop_ids as $shop_id) {
- $is_exists = ShopStatistics::query()->where('shop_id', $shop_id)->whereDate('day', $day)->where('is_check', 1)->exists();
- if (!$is_exists) {
- $shopStatisticsService->handleRefresh($shop_id, $day);
- }
- //删除
- Dispatch::query()->where('type', Dispatch::TYPE_SHOP)->whereDate('created_at', $day)->where('shop_id', $shop_id)->whereIn('dispatch_status', [DispatchStatusEnum::WAIT, DispatchStatusEnum::WAIT_SEND])->delete();
- Staff::query()->where('type', Dispatch::TYPE_SHOP)->whereDate('created_at', $day)->where('shop_id', $shop_id)->whereIn('dispatch_status', [DispatchStatusEnum::WAIT, DispatchStatusEnum::WAIT_SEND])->delete();
- }
- $this->line('操作成功');
- }
- }
|