Owner.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. "contract_number", //合同号
  21. "salesman", //销售名称
  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 order(){
  55. return $this->hasOne(Order::class,'owner_id','id');
  56. }
  57. public function customer()
  58. { //客户
  59. return $this->hasOne(Customer::class,"id","customer_id");
  60. }
  61. public function userOwnerGroup()
  62. { //项目组
  63. return $this->hasOne(UserOwnerGroup::class,"id","user_owner_group_id");
  64. }
  65. public function ownerStoragePriceModels()
  66. { //仓储计费
  67. return $this->belongsToMany(OwnerStoragePriceModel::class,"owner_storage_price_model_owner","owner_id","owner_storage_price_model_id");
  68. }
  69. public function ownerAreaReport()
  70. { //面积报表
  71. return $this->hasOne(OwnerAreaReport::class,"owner_id","id");
  72. }
  73. public function ownerStoragePriceModelOwners()
  74. { //仓储计费-货主 中间表
  75. return $this->hasMany(OwnerStoragePriceModelOwner::class,"owner_id","id");
  76. }
  77. public function ownerPriceOperations()
  78. { //作业计费
  79. return $this->belongsToMany(OwnerPriceOperation::class,"owner_price_operation_owner","owner_id","owner_price_operation_id");
  80. }
  81. public function ownerPriceExpresses()
  82. { //快递计费
  83. return $this->belongsToMany(OwnerPriceExpress::class,"owner_price_express_owner","owner_id","owner_price_express_id");
  84. }
  85. public function ownerPriceLogistics()
  86. { //物流计费
  87. return $this->belongsToMany(OwnerPriceLogistic::class,"owner_price_logistic_owner","owner_id","owner_price_logistic_id");
  88. }
  89. public function ownerPriceDirectLogistics()
  90. { //直发车计费
  91. return $this->belongsToMany(OwnerPriceDirectLogistic::class,"owner_price_direct_logistic_owner","owner_id","owner_price_direct_logistic_id");
  92. }
  93. public function getOwnerStoragePriceModelIds($type = 'string')
  94. { //获取仓储计费的关联ID字符串或数组
  95. $this->load('ownerStoragePriceModelOwners');
  96. if ($type == 'string'){
  97. $ids = '';
  98. foreach ($this->ownerStoragePriceModelOwners as $os){
  99. $ids .= $os->owner_storage_price_model_id.",";
  100. }
  101. return $ids;
  102. }
  103. return array_column(($this->ownerStoragePriceModelOwners)->toArray(),"owner_storage_price_model_id");
  104. }
  105. }