SortingStation.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. use App\Traits\ModelLogChanging;
  9. class SortingStation extends Model
  10. {
  11. use ModelLogChanging;
  12. protected $fillable = [
  13. 'name','type', 'bin_amount','is_occupied','is_online','processing_batch_id','login_at'
  14. ];
  15. static public function findOrCreate($name){
  16. $station=SortingStation::where('name',$name)->first();
  17. if(!$station){
  18. $station=new SortingStation(['name'=>$name]);
  19. $station->save();
  20. }
  21. return $station;
  22. }
  23. public function login(){
  24. $this['login_at'] = Carbon::now();
  25. $this['is_online'] = '是';
  26. $this->update();
  27. }
  28. public function setProcessingBatch(Batch $batch){
  29. $this['processing_batch_id'] = $batch['id'];
  30. $this['is_occupied'] = '是';
  31. $this->login();
  32. $this->update();
  33. }
  34. public function clearProcessingBatch(){
  35. $this['processing_batch_id'] = null;
  36. $this['is_occupied'] = '否';
  37. $this->login();
  38. $this->update();
  39. }
  40. }