| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- <?php
- namespace App\Http\Controllers;
- use App\Components\AsyncResponse;
- use App\Exceptions\ErrorException;
- use App\MaterialBox;
- use App\Services\CacheShelfService;
- use App\Services\StationCacheShelfGridService;
- use App\Station;
- use App\StationCacheShelfGrid;
- use Illuminate\Contracts\Foundation\Application;
- use Illuminate\Contracts\View\Factory;
- use Illuminate\Database\Eloquent\Builder;
- use Illuminate\Http\Request;
- use Illuminate\View\View;
- class CacheShelfController extends Controller
- {
- use AsyncResponse;
- /**
- * 缓存货架
- * @return Application|Factory|View
- */
- public function index()
- {
- $stations = Station::query()->with('stationType:name', 'parent:name')->whereHas('stationType', function ($query) {
- /** @var Builder $query */
- $query->where('name', '缓存架');
- })->paginate(100);
- return view('station.cachingShelf.list.index', compact('stations'));
- }
- /**
- * 获取缓存货架上的任务列表
- * @param Request $request
- * @param string $id
- * @param CacheShelfService $service
- */
- public function getTasksApi(Request $request,string $id,CacheShelfService $service)
- {
- /** @var Station $station */
- $station = Station::query()->where('id',$id)->first();
- $service->getTasks($station);
- $this->success($station['grids']);
- }
- /**
- * 缓存架亮灯
- * @param Request $request
- * @param StationCacheShelfGridService $gridService
- */
- public function lightOnApi(Request $request,StationCacheShelfGridService $gridService)
- {
- $grid_id = $request['index'];
- /** @var Station $station */
- $station = Station::query()->where('id',$request['id'])->first();
- $grid = StationCacheShelfGrid::query()->firstOrCreate(['station_id'=>$station['id'],'grid_id'=>$grid_id]);
- $materialBox = MaterialBox::query()->firstOrCreate(['code'=>$request['code']]);
- $grid->update(['material_box_id' => $materialBox['id'],'status' => 1]);
- return $gridService->lightOn($station,$request['x'],$request['y']);
- }
- // /**
- // * 拍灯推送任务
- // * @param Request $request
- // * @param CacheShelfService $service
- // */
- // public function pushTaskApi(Request $request,CacheShelfService $service)
- // {
- // /**
- // * @var Station $station
- // * @var MaterialBox $materialBox
- // * @var StationCacheShelfGrid $grid
- // */
- // $station = Station::query()->where('id',$request['id'])->first();
- // $materialBox = MaterialBox::query()->where('code',$request['code'])->first();
- // $grid = StationCacheShelfGrid::query()->where(['station_id'=>$station['id'],'grid_id'=>$request['index']])->first();
- //
- // try {
- // $bool = $service->putBinToStore($station, $materialBox, $grid);
- // if($bool)$this->success();
- // else $this->error('推送任务异常');
- // } catch (ErrorException $e) {
- // $this->error($e->getMessage());
- // }
- // }
- }
|