Owner.php 4.1 KB

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