Owner.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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_id", //税率
  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. "relevance", //关联模型的JSON数组
  30. 'subjection' //主体公司
  31. ];
  32. //relevance说明 0:仓储 1:作业 2:快递 3:物流 4:直发 存储示例:["0","1"]存在仓储与作业计费
  33. protected $casts = [
  34. "relevance" => "array"
  35. ];
  36. const subjection=[
  37. 0=>'',
  38. 1 => "宝时物流",
  39. 2 => "宝时供应链",
  40. ];
  41. public static function filterAuthorities(){
  42. $user=Auth::user();
  43. $query = (new static)->newQuery();
  44. if(!$user){
  45. return $query->where('id','0');
  46. }
  47. $ownerIds=app('UserService')->getPermittingOwnerIds($user);
  48. if(empty($ownerIds))return $query;
  49. return $query->whereIn('id',$ownerIds);
  50. }
  51. /**
  52. * 退货管理里,客户审核的代码,是拼音+日期+计数,计数的后缀就是checking_count
  53. * @return int|mixed
  54. */
  55. public function getIncreasedCheckingCount(){
  56. $this['checking_count']=$this['checking_count']+1;
  57. $this->update();
  58. return $this['checking_count'];
  59. }
  60. public function paperBoxes()
  61. {
  62. return $this->belongsToMany('\App\PaperBox', 'owner_paper_box', 'owner_id', 'paper_box_id');
  63. }
  64. public function orderTrackingOwner(){
  65. return $this->belongsTo(OrderTrackingOwner::class,'id','owner_id');
  66. }
  67. public function contracts()
  68. { //合同
  69. return $this->hasMany(OwnerContract::class,"owner_id","id");
  70. }
  71. public function order(){
  72. return $this->hasOne(Order::class,'owner_id','id');
  73. }
  74. public function customer()
  75. { //客户
  76. return $this->hasOne(Customer::class,"id","customer_id");
  77. }
  78. public function userOwnerGroup()
  79. { //项目组
  80. return $this->hasOne(UserOwnerGroup::class,"id","user_owner_group_id");
  81. }
  82. public function userWorkGroup()
  83. { //工作组
  84. return $this->belongsTo(UserWorkgroup::class,"user_workgroup_id","id");
  85. }
  86. public function ownerStoragePriceModels()
  87. { //仓储计费
  88. return $this->belongsToMany(OwnerStoragePriceModel::class,"owner_storage_price_model_owner","owner_id","owner_storage_price_model_id");
  89. }
  90. public function ownerAreaReport()
  91. { //面积报表
  92. return $this->hasOne(OwnerAreaReport::class,"owner_id","id");
  93. }
  94. public function ownerPriceOperations()
  95. { //作业计费
  96. return $this->belongsToMany(OwnerPriceOperation::class,"owner_price_operation_owner","owner_id","owner_price_operation_id");
  97. }
  98. public function ownerPriceExpresses()
  99. { //快递计费
  100. return $this->belongsToMany(OwnerPriceExpress::class,"owner_price_express_owner","owner_id","owner_price_express_id");
  101. }
  102. public function ownerPriceLogistics()
  103. { //物流计费
  104. return $this->belongsToMany(OwnerPriceLogistic::class,"owner_price_logistic_owner","owner_id","owner_price_logistic_id");
  105. }
  106. public function ownerPriceDirectLogistics()
  107. { //直发车计费
  108. return $this->belongsToMany(OwnerPriceDirectLogistic::class,"owner_price_direct_logistic_owner","owner_id","owner_price_direct_logistic_id");
  109. }
  110. public function warehouse()
  111. { //仓库
  112. return $this->belongsTo(Warehouse::class,"warehouse_id","id");
  113. }
  114. public function ownerMaterials()
  115. { //耗材
  116. return $this->hasMany(OwnerMaterial::class,"owner_id","id");
  117. }
  118. public function taxRate()
  119. { //税率
  120. return $this->belongsTo(TaxRate::class);
  121. }
  122. }