Owner.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. namespace App;
  3. use Illuminate\Database\Eloquent\Model;
  4. use Illuminate\Database\Eloquent\SoftDeletes;
  5. use Illuminate\Support\Facades\Auth;
  6. /**
  7. * @method static orderBy(string $string, string $string1)
  8. */
  9. use App\Traits\ModelTimeFormat;
  10. class Owner extends Model
  11. {
  12. use ModelTimeFormat;
  13. public $fillable = ['name','code','checking_count','deleted_at'];
  14. public static function filterAuthorities(){
  15. $user=Auth::user();
  16. $query = (new static)->newQuery();
  17. if(!$user){
  18. return $query->where('id','0');
  19. }
  20. $ownerIds=$user->getPermittingOwnerIdsAttribute();
  21. return $query->whereIn('id',$ownerIds);
  22. }
  23. /**
  24. * 退货管理里,客户审核的代码,是拼音+日期+计数,计数的后缀就是checking_count
  25. * @return int|mixed
  26. */
  27. public function getIncreasedCheckingCount(){
  28. $this['checking_count']=$this['checking_count']+1;
  29. $this->update();
  30. return $this['checking_count'];
  31. }
  32. public function paperBoxes()
  33. {
  34. return $this->belongsToMany('\App\PaperBox', 'owner_paper_box', 'owner_id', 'paper_box_id');
  35. }
  36. public function orderTrackingOwner(){
  37. return $this->belongsTo(OrderTrackingOwner::class,'id','owner_id');
  38. }
  39. public function order(){
  40. return $this->hasOne(Order::class,'owner_id','id');
  41. }
  42. }