| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- <?php
- namespace App;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Database\Eloquent\SoftDeletes;
- use Illuminate\Support\Facades\Auth;
- /**
- * @method static orderBy(string $string, string $string1)
- */
- use App\Traits\ModelTimeFormat;
- class Owner extends Model
- {
- use ModelTimeFormat;
- public $fillable = [
- 'name', //名称
- 'code', //代码
- 'checking_count', //审核数量
- 'deleted_at', //删除时间
- "customer_id", //客户ID
- "tax_rate", //税率
- "contract_number", //合同号
- "salesman", //销售名称
- "linkman", //联系人
- "phone_number", //联系电话
- "user_owner_group_id", //项目组ID
- "waring_line_on", //月单量预警
- "description" //描述
- ];
- public static function filterAuthorities(){
- $user=Auth::user();
- $query = (new static)->newQuery();
- if(!$user){
- return $query->where('id','0');
- }
- $ownerIds=app('UserService')->getPermittingOwnerIds($user);
- if(empty($ownerIds))return $query;
- return $query->whereIn('id',$ownerIds);
- }
- /**
- * 退货管理里,客户审核的代码,是拼音+日期+计数,计数的后缀就是checking_count
- * @return int|mixed
- */
- public function getIncreasedCheckingCount(){
- $this['checking_count']=$this['checking_count']+1;
- $this->update();
- return $this['checking_count'];
- }
- public function paperBoxes()
- {
- return $this->belongsToMany('\App\PaperBox', 'owner_paper_box', 'owner_id', 'paper_box_id');
- }
- public function orderTrackingOwner(){
- return $this->belongsTo(OrderTrackingOwner::class,'id','owner_id');
- }
- public function order(){
- return $this->hasOne(Order::class,'owner_id','id');
- }
- public function customer()
- { //客户
- return $this->hasOne(Customer::class,"id","customer_id");
- }
- public function userOwnerGroup()
- { //项目组
- return $this->hasOne(UserOwnerGroup::class,"id","user_owner_group_id");
- }
- public function ownerStoragePriceModels()
- { //仓储计费
- return $this->belongsToMany(OwnerStoragePriceModel::class,"owner_storage_price_model_owner","owner_id","owner_storage_price_model_id");
- }
- public function ownerAreaReport()
- { //面积报表
- return $this->hasOne(OwnerAreaReport::class,"owner_id","id");
- }
- public function ownerStoragePriceModelOwners()
- { //仓储计费-货主 中间表
- return $this->hasMany(OwnerStoragePriceModelOwner::class,"owner_id","id");
- }
- public function ownerPriceOperations()
- { //作业计费
- return $this->belongsToMany(OwnerPriceOperation::class,"owner_price_operation_owner","owner_id","owner_price_operation_id");
- }
- public function ownerPriceExpresses()
- { //快递计费
- return $this->belongsToMany(OwnerPriceExpress::class,"owner_price_express_owner","owner_id","owner_price_express_id");
- }
- public function ownerPriceLogistics()
- { //物流计费
- return $this->belongsToMany(OwnerPriceLogistic::class,"owner_price_logistic_owner","owner_id","owner_price_logistic_id");
- }
- public function ownerPriceDirectLogistics()
- { //直发车计费
- return $this->belongsToMany(OwnerPriceDirectLogistic::class,"owner_price_direct_logistic_owner","owner_id","owner_price_direct_logistic_id");
- }
- public function getOwnerStoragePriceModelIds($type = 'string')
- { //获取仓储计费的关联ID字符串或数组
- $this->load('ownerStoragePriceModelOwners');
- if ($type == 'string'){
- $ids = '';
- foreach ($this->ownerStoragePriceModelOwners as $os){
- $ids .= $os->owner_storage_price_model_id.",";
- }
- return $ids;
- }
- return array_column(($this->ownerStoragePriceModelOwners)->toArray(),"owner_storage_price_model_id");
- }
- }
|