StationTaskCommodityService.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace App\Services;
  3. use Illuminate\Support\Collection;
  4. class StationTaskCommodityService
  5. {
  6. /** @var StationService $stationService */
  7. private $stationService;
  8. /** @var StationTaskBatchTypeService $stationTaskBatchTypeService */
  9. private $stationTaskBatchTypeService;
  10. /** @var BatchService $batchService */
  11. private $batchService;
  12. /** @var StationTypeService $stationTypeService */
  13. private $stationTypeService;
  14. /** @var StationTaskService $stationTaskService */
  15. private $stationTaskService;
  16. /** @var StationTaskMaterialBoxService $stationTaskMaterialBoxService */
  17. private $stationTaskMaterialBoxService;
  18. public function __construct(){
  19. $this->stationService=null;
  20. $this->stationTypeService=null;
  21. $this->stationTaskBatchTypeService=null;
  22. $this->batchService=null;
  23. $this->stationTaskService=null;
  24. $this->stationTaskMaterialBoxService=null;
  25. }
  26. function get(array $whereParams){
  27. ksort($whereParams);
  28. return Cache::remember('stationTaskChild_'.md5(json_encode($whereParams)), config('cache.expirations.oftenChange'), function ()use($whereParams) {
  29. $query = StationTaskCommodity::query();
  30. foreach ($whereParams as $column => $value){
  31. if (is_array($value))$query->whereIn($column,$value);
  32. else $query->where($column,$value);
  33. }
  34. return $query->get();
  35. });
  36. }
  37. function createByBatches(array $batches): Collection
  38. {
  39. $stationTaskCommodity_toCreate=new Collection();
  40. $batches_handled=collect();
  41. foreach ($batches as $batch){
  42. $stationType=$this->stationTypeService->getByBatch($batch);
  43. $station=$this->stationService->getStation_byType($stationType['name']);
  44. // $materialBox=$this->stationTaskMaterialBoxService->get(['code'=>]);
  45. // $stationTaskCommodity_toCreate->push([
  46. // 'station_id'=>$station['id'],
  47. // 'station_id'=>$station['id'],
  48. // 'status'=>'待处理'
  49. // ]);
  50. $batches_handled->push($batch);
  51. }
  52. $this->batchService->updateWhereIn('id',data_get($batches_handled,'*.id'),['status'=>'处理中']);
  53. }
  54. }