Batch.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace App;
  3. use Illuminate\Database\Eloquent\Model;
  4. use App\Traits\LogModelChanging;
  5. class Batch extends Model
  6. {
  7. use LogModelChanging;
  8. protected $fillable = [
  9. 'id','code','type', 'wms_type', 'status', 'wms_status', 'wms_created_at',"remark","owner_id",
  10. ];
  11. public function orders(){
  12. return $this->hasMany('App\Order','batch_id','id');
  13. }
  14. public function setProcessed(){
  15. $this['status'] = '已处理';
  16. $this->orders()->each(function (Order $order){
  17. $order->setProcessed();
  18. });
  19. $this->update();
  20. }
  21. public function assignBins(){
  22. $this->orders()->each(function (Order $order,$i){
  23. $bin=new OrderBin(['order_id'=>$order['id'],'number'=>($i+1)]);
  24. $bin->save();
  25. });
  26. return $this->orders()->count();
  27. }
  28. public function delete()
  29. {
  30. $this->orders()->each(function(Order $order){
  31. $order->delete();
  32. });
  33. return parent::delete();
  34. }
  35. public function owner()
  36. {
  37. return $this->hasOne(Owner::class,"id","owner_id");
  38. }
  39. }