Batch.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. namespace App;
  3. use Illuminate\Database\Eloquent\Model;
  4. use App\Traits\ModelLogChanging;
  5. use Illuminate\Database\Eloquent\Relations\HasOne;
  6. class Batch extends Model
  7. {
  8. use ModelLogChanging;
  9. protected $fillable = [
  10. 'id','code','type', 'wms_type', 'status', 'wms_status', 'wms_created_at',"remark","owner_id","split_size"
  11. ];
  12. const WMS_STATUS = [
  13. '00' => '创建',
  14. '40' => '部分收货',
  15. '90' => '取消',
  16. '99' => '完成',
  17. '62' => '部分装箱'
  18. ];
  19. public function orders(){
  20. return $this->hasMany('App\Order','batch_id','id');
  21. }
  22. public function setProcessed(){
  23. $this['status'] = '已处理';
  24. $this->orders()->each(function (Order $order){
  25. $order->setProcessed();
  26. });
  27. $this->update();
  28. }
  29. public function assignBins(){
  30. $this->orders()->each(function (Order $order,$i){
  31. $bin=new OrderBin(['order_id'=>$order['id'],'number'=>($i+1)]);
  32. $bin->save();
  33. });
  34. return $this->orders()->count();
  35. }
  36. public function delete()
  37. {
  38. $this->orders()->each(function(Order $order){
  39. $order->delete();
  40. });
  41. return parent::delete();
  42. }
  43. public function owner()
  44. {
  45. return $this->hasOne(Owner::class,"id","owner_id");
  46. }
  47. public function stationTaskBatch(): HasOne
  48. {
  49. return $this->hasOne(StationTaskBatch::class);
  50. }
  51. public function stationTask()
  52. {
  53. return $this->stationTaskBatch?
  54. $this->stationTaskBatch->belongsTo(StationTask::class):
  55. null;
  56. }
  57. }