Owner.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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\LogModelChanging;
  11. class Owner extends Model
  12. {
  13. use LogModelChanging;
  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. ];
  29. public static function filterAuthorities(){
  30. $user=Auth::user();
  31. $query = (new static)->newQuery();
  32. if(!$user){
  33. return $query->where('id','0');
  34. }
  35. $ownerIds=app('UserService')->getPermittingOwnerIds($user);
  36. if(empty($ownerIds))return $query;
  37. return $query->whereIn('id',$ownerIds);
  38. }
  39. /**
  40. * 退货管理里,客户审核的代码,是拼音+日期+计数,计数的后缀就是checking_count
  41. * @return int|mixed
  42. */
  43. public function getIncreasedCheckingCount(){
  44. $this['checking_count']=$this['checking_count']+1;
  45. $this->update();
  46. return $this['checking_count'];
  47. }
  48. public function paperBoxes()
  49. {
  50. return $this->belongsToMany('\App\PaperBox', 'owner_paper_box', 'owner_id', 'paper_box_id');
  51. }
  52. public function orderTrackingOwner(){
  53. return $this->belongsTo(OrderTrackingOwner::class,'id','owner_id');
  54. }
  55. public function contracts()
  56. { //合同
  57. return $this->hasMany(OwnerContract::class,"owner_id","id");
  58. }
  59. public function order(){
  60. return $this->hasOne(Order::class,'owner_id','id');
  61. }
  62. public function customer()
  63. { //客户
  64. return $this->hasOne(Customer::class,"id","customer_id");
  65. }
  66. public function userOwnerGroup()
  67. { //项目组
  68. return $this->hasOne(UserOwnerGroup::class,"id","user_owner_group_id");
  69. }
  70. public function ownerStoragePriceModels()
  71. { //仓储计费
  72. return $this->belongsToMany(OwnerStoragePriceModel::class,"owner_storage_price_model_owner","owner_id","owner_storage_price_model_id");
  73. }
  74. public function ownerAreaReport()
  75. { //面积报表
  76. return $this->hasOne(OwnerAreaReport::class,"owner_id","id");
  77. }
  78. public function ownerPriceOperations()
  79. { //作业计费
  80. return $this->belongsToMany(OwnerPriceOperation::class,"owner_price_operation_owner","owner_id","owner_price_operation_id");
  81. }
  82. public function ownerPriceExpresses()
  83. { //快递计费
  84. return $this->belongsToMany(OwnerPriceExpress::class,"owner_price_express_owner","owner_id","owner_price_express_id");
  85. }
  86. public function ownerPriceLogistics()
  87. { //物流计费
  88. return $this->belongsToMany(OwnerPriceLogistic::class,"owner_price_logistic_owner","owner_id","owner_price_logistic_id");
  89. }
  90. public function ownerPriceDirectLogistics()
  91. { //直发车计费
  92. return $this->belongsToMany(OwnerPriceDirectLogistic::class,"owner_price_direct_logistic_owner","owner_id","owner_price_direct_logistic_id");
  93. }
  94. public function warehouse()
  95. { //仓库
  96. return $this->belongsTo(Warehouse::class,"warehouse_id","id");
  97. }
  98. }