CheckDispatchStatisticsCommand.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. namespace App\Console\Commands\Xjc;
  3. use App\Repositories\Enums\Check\StatusEnum;
  4. use App\Repositories\Enums\Human\DispatchStatusEnum;
  5. use App\Repositories\Enums\ModelStatusEnum;
  6. use App\Repositories\Enums\Recruit\PositionStatusEnum;
  7. use App\Repositories\Models\Human\Dispatch;
  8. use App\Repositories\Models\Human\Staff;
  9. use App\Repositories\Models\Recruit\Position;
  10. use App\Repositories\Models\Xjc\Shop;
  11. use App\Repositories\Models\Xjc\ShopStatistics;
  12. use App\Services\Xjc\ShopStatisticsService;
  13. use Carbon\Carbon;
  14. use Illuminate\Console\Command;
  15. use Illuminate\Support\Arr;
  16. use Illuminate\Support\Facades\DB;
  17. use Illuminate\Support\Facades\Log;
  18. /**
  19. * 门店每日统计
  20. * @package Prettus\Repository\Generators\Commands
  21. * @author Anderson Andrade <contato@andersonandra.de>
  22. */
  23. class CheckDispatchStatisticsCommand extends Command
  24. {
  25. /**
  26. * The name of command.
  27. *
  28. * @var string
  29. */
  30. protected $signature = 'dispatch:statistics';
  31. /**
  32. * The description of command.
  33. *
  34. * @var string
  35. */
  36. protected $description = 'dispatch statistics';
  37. /**
  38. * The type of class being generated.
  39. *
  40. * @var string
  41. */
  42. protected $type = 'dispatch';
  43. /**
  44. * Execute the command.
  45. *
  46. * @return void
  47. * @see fire()
  48. */
  49. public function handle(ShopStatisticsService $shopStatisticsService)
  50. {
  51. $day = Carbon::yesterday()->toDateString();
  52. $shop_ids = Shop::query()->where('status', ModelStatusEnum::OK)->distinct()->pluck('id');
  53. foreach ($shop_ids as $shop_id) {
  54. $is_exists = ShopStatistics::query()->where('shop_id', $shop_id)->whereDate('day', $day)->where('is_check', 1)->exists();
  55. if (!$is_exists) {
  56. $shopStatisticsService->handleRefresh($shop_id, $day);
  57. }
  58. //删除
  59. 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();
  60. 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();
  61. }
  62. $this->line('操作成功');
  63. }
  64. }