hasMany(ServiceWorkAllocateWorkerLog::class,'work_id','work_id')->field('*'); } public function saleGroupInfo() { return $this->hasOne(SaleGroup::class, 'id', 'sale_group_id') ->field('*'); } public function saleInfo() { return $this->hasOne(Sale::class, 'id', 'sale_id') ->field('*'); } public function propertyHead() { return $this->hasOne(PropertyHead::class, 'id', 'property_head_id') ->field('*'); } public function propertyUser() { return $this->hasOne(PropertyUser::class, 'id', 'property_user_id') ->field('*'); } public function propertyWork() { return $this->hasOne(ServiceWork::class, 'id', 'work_id') ->field('id,real_name,mobile,address,create_time'); } public function propertyOrderCustomerLog() { return $this->hasMany(PropertyOrderCustomerLog::class,'order_id','id')->order(['id'=>'desc']); } public static function onBeforeInsert($model){ $propertyHeadInfo = PropertyHead::where('id',$model->property_head_id)->findOrEmpty(); if(!$propertyHeadInfo->isEmpty()){ $propertyHeadInfo = $propertyHeadInfo->toArray(); $model->sale_type = $propertyHeadInfo['sale_type']??0; $model->sale_id = $propertyHeadInfo['sale_id']??0; if($propertyHeadInfo['sale_id']){ $saleGroupId = Sale::where('id',$propertyHeadInfo['sale_id'])->value('sale_group_id'); $model->sale_group_id = $saleGroupId??0; } } Log::info('新增物业订单:'.json_encode([$model->property_head_id,$model->sale_type,$model->sale_id,$model->sale_group_id])); } }