CacheShelfController.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Components\AsyncResponse;
  4. use App\Services\CacheShelfService;
  5. use App\Station;
  6. use Illuminate\Contracts\Foundation\Application;
  7. use Illuminate\Contracts\View\Factory;
  8. use Illuminate\Database\Eloquent\Builder;
  9. use Illuminate\Http\Request;
  10. use Illuminate\View\View;
  11. class CacheShelfController extends Controller
  12. {
  13. use AsyncResponse;
  14. /**
  15. * 缓存货架
  16. * @return Application|Factory|View
  17. */
  18. public function index()
  19. {
  20. $stations = Station::query()->with('stationType:name', 'parent:name')->whereNull('parent_id')->whereIn('station_type_id', function ($query) {
  21. /** @var Builder $query */
  22. $query->from('station_types')->selectRaw('id')->where('name', '缓存架');
  23. })->paginate(10);
  24. return view('station.cachingShelf.list.index', compact('stations'));
  25. }
  26. /**
  27. * 获取缓存货架上的料箱
  28. * @param Request $request
  29. * @param string $id
  30. * @param CacheShelfService $service
  31. */
  32. public function getChildStationApi(Request $request,string $id,CacheShelfService $service)
  33. {
  34. $stations = $service->getChildStation($id);
  35. $this->success($stations);
  36. }
  37. /**
  38. * 缓存架亮灯
  39. * @param Request $request
  40. * @param CacheShelfService $service
  41. * @return mixed
  42. */
  43. public function lightOnApi(Request $request,CacheShelfService $service): array
  44. {
  45. if($request['stationCode'] && $request['materialBoxCode']){
  46. return $service->bindMaterialBox($request['stationCode'],$request['materialBoxCode']);
  47. }
  48. return ['success' => false,'message' => '参数错误'];
  49. }
  50. /**
  51. * @param Request $request
  52. * @param CacheShelfService $service
  53. * @return array|bool[]
  54. */
  55. public function clearTaskApi(Request $request,CacheShelfService $service): array
  56. {
  57. $code = $request['station'];
  58. return $service->clearTask($code);
  59. }
  60. }