Owner.php 4.1 KB

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