SortingStation.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. namespace App;
  3. use App\Http\Controllers\Controller;
  4. use Carbon\Carbon;
  5. use Illuminate\Database\Eloquent\Model;
  6. use mysql_xdevapi\Exception;
  7. use Zttp\Zttp;
  8. class SortingStation extends ModelExtended
  9. {
  10. protected $fillable = [
  11. 'name','type', 'bin_amount','is_occupied','is_online','processing_batch_id','login_at'
  12. ];
  13. static public function findOrCreate($name){
  14. $station=SortingStation::where('name',$name)->first();
  15. if(!$station){
  16. $station=new SortingStation(['name'=>$name]);
  17. $station->save();
  18. }
  19. return $station;
  20. }
  21. public function login(){
  22. $this['login_at'] = Carbon::now();
  23. $this['is_online'] = '是';
  24. $this->update();
  25. }
  26. public function setProcessingBatch(Batch $batch){
  27. $this['processing_batch_id'] = $batch['id'];
  28. $this['is_occupied'] = '是';
  29. $this->login();
  30. $this->update();
  31. }
  32. public function clearProcessingBatch(){
  33. $this['processing_batch_id'] = null;
  34. $this['is_occupied'] = '否';
  35. $this->login();
  36. $this->update();
  37. }
  38. }