CacheShelfController.php 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Components\AsyncResponse;
  4. use App\Exceptions\ErrorException;
  5. use App\MaterialBox;
  6. use App\Services\CacheShelfService;
  7. use App\Services\StationCacheShelfGridService;
  8. use App\Station;
  9. use App\StationCacheShelfGrid;
  10. use Illuminate\Contracts\Foundation\Application;
  11. use Illuminate\Contracts\View\Factory;
  12. use Illuminate\Database\Eloquent\Builder;
  13. use Illuminate\Http\Request;
  14. use Illuminate\View\View;
  15. class CacheShelfController extends Controller
  16. {
  17. use AsyncResponse;
  18. /**
  19. * 缓存货架
  20. * @return Application|Factory|View
  21. */
  22. public function index()
  23. {
  24. $stations = Station::query()->with('stationType:name', 'parent:name')->whereHas('stationType', function ($query) {
  25. /** @var Builder $query */
  26. $query->where('name', '缓存架');
  27. })->paginate(100);
  28. return view('station.cachingShelf.list.index', compact('stations'));
  29. }
  30. /**
  31. * 获取缓存货架上的任务列表
  32. * @param Request $request
  33. * @param string $id
  34. * @param CacheShelfService $service
  35. */
  36. public function getTasksApi(Request $request,string $id,CacheShelfService $service)
  37. {
  38. /** @var Station $station */
  39. $station = Station::query()->where('id',$id)->first();
  40. $service->getTasks($station);
  41. $this->success($station['grids']);
  42. }
  43. /**
  44. * 缓存架亮灯
  45. * @param Request $request
  46. * @param StationCacheShelfGridService $gridService
  47. */
  48. public function lightOnApi(Request $request,StationCacheShelfGridService $gridService)
  49. {
  50. $grid_id = $request['index'];
  51. /** @var Station $station */
  52. $station = Station::query()->where('id',$request['id'])->first();
  53. $grid = StationCacheShelfGrid::query()->firstOrCreate(['station_id'=>$station['id'],'grid_id'=>$grid_id]);
  54. $materialBox = MaterialBox::query()->firstOrCreate(['code'=>$request['code']]);
  55. $grid->update(['material_box_id' => $materialBox['id'],'status' => 1]);
  56. return $gridService->lightOn($station,$request['x'],$request['y']);
  57. }
  58. // /**
  59. // * 拍灯推送任务
  60. // * @param Request $request
  61. // * @param CacheShelfService $service
  62. // */
  63. // public function pushTaskApi(Request $request,CacheShelfService $service)
  64. // {
  65. // /**
  66. // * @var Station $station
  67. // * @var MaterialBox $materialBox
  68. // * @var StationCacheShelfGrid $grid
  69. // */
  70. // $station = Station::query()->where('id',$request['id'])->first();
  71. // $materialBox = MaterialBox::query()->where('code',$request['code'])->first();
  72. // $grid = StationCacheShelfGrid::query()->where(['station_id'=>$station['id'],'grid_id'=>$request['index']])->first();
  73. //
  74. // try {
  75. // $bool = $service->putBinToStore($station, $materialBox, $grid);
  76. // if($bool)$this->success();
  77. // else $this->error('推送任务异常');
  78. // } catch (ErrorException $e) {
  79. // $this->error($e->getMessage());
  80. // }
  81. // }
  82. }