Owner.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. use App\Traits\ModelLogChanging;
  11. class Owner extends Model
  12. {
  13. use ModelLogChanging;
  14. use ModelTimeFormat;
  15. public $fillable = [
  16. 'name', //名称
  17. 'code', //代码
  18. 'checking_count', //审核数量
  19. 'deleted_at', //删除时间
  20. "customer_id", //客户ID
  21. "tax_rate", //税率
  22. "linkman", //联系人
  23. "phone_number", //联系电话
  24. "user_owner_group_id", //项目组ID
  25. "waring_line_on", //月单量预警
  26. "description", //描述
  27. "warehouse_id", //仓库ID
  28. "user_workgroup_id" //仓库小组(工作组)
  29. ];
  30. public static function filterAuthorities(){
  31. $user=Auth::user();
  32. $query = (new static)->newQuery();
  33. if(!$user){
  34. return $query->where('id','0');
  35. }
  36. $ownerIds=app('UserService')->getPermittingOwnerIds($user);
  37. if(empty($ownerIds))return $query;
  38. return $query->whereIn('id',$ownerIds);
  39. }
  40. /**
  41. * 退货管理里,客户审核的代码,是拼音+日期+计数,计数的后缀就是checking_count
  42. * @return int|mixed
  43. */
  44. public function getIncreasedCheckingCount(){
  45. $this['checking_count']=$this['checking_count']+1;
  46. $this->update();
  47. return $this['checking_count'];
  48. }
  49. public function paperBoxes()
  50. {
  51. return $this->belongsToMany('\App\PaperBox', 'owner_paper_box', 'owner_id', 'paper_box_id');
  52. }
  53. public function orderTrackingOwner(){
  54. return $this->belongsTo(OrderTrackingOwner::class,'id','owner_id');
  55. }
  56. public function contracts()
  57. { //合同
  58. return $this->hasMany(OwnerContract::class,"owner_id","id");
  59. }
  60. public function order(){
  61. return $this->hasOne(Order::class,'owner_id','id');
  62. }
  63. public function customer()
  64. { //客户
  65. return $this->hasOne(Customer::class,"id","customer_id");
  66. }
  67. public function userOwnerGroup()
  68. { //项目组
  69. return $this->hasOne(UserOwnerGroup::class,"id","user_owner_group_id");
  70. }
  71. public function userWorkGroup()
  72. { //工作组
  73. return $this->belongsTo(UserWorkgroup::class,"user_workgroup_id","id");
  74. }
  75. public function ownerStoragePriceModels()
  76. { //仓储计费
  77. return $this->belongsToMany(OwnerStoragePriceModel::class,"owner_storage_price_model_owner","owner_id","owner_storage_price_model_id");
  78. }
  79. public function ownerAreaReport()
  80. { //面积报表
  81. return $this->hasOne(OwnerAreaReport::class,"owner_id","id");
  82. }
  83. public function ownerPriceOperations()
  84. { //作业计费
  85. return $this->belongsToMany(OwnerPriceOperation::class,"owner_price_operation_owner","owner_id","owner_price_operation_id");
  86. }
  87. public function ownerPriceExpresses()
  88. { //快递计费
  89. return $this->belongsToMany(OwnerPriceExpress::class,"owner_price_express_owner","owner_id","owner_price_express_id");
  90. }
  91. public function ownerPriceLogistics()
  92. { //物流计费
  93. return $this->belongsToMany(OwnerPriceLogistic::class,"owner_price_logistic_owner","owner_id","owner_price_logistic_id");
  94. }
  95. public function ownerPriceDirectLogistics()
  96. { //直发车计费
  97. return $this->belongsToMany(OwnerPriceDirectLogistic::class,"owner_price_direct_logistic_owner","owner_id","owner_price_direct_logistic_id");
  98. }
  99. public function warehouse()
  100. { //仓库
  101. return $this->belongsTo(Warehouse::class,"warehouse_id","id");
  102. }
  103. public function ownerMaterials()
  104. { //耗材
  105. return $this->hasMany(OwnerMaterial::class,"owner_id","id");
  106. }
  107. }