$relation_type, 'relation_id' => $relation_id])->with(['staff','admin'])->field('content,operation_id,createtime,operation_type')->order('id desc')->select(); } //员工 public function staff() { return $this->hasOne(Staff::class, 'id', 'operation_id')->removeOption('soft_delete')->field('id,name,img'); } //员工 public function admin() { return $this->hasOne(\app\admin\model\Admin::class, 'id', 'operation_id')->field('id,nickname'); } //创建日志 public static function createLog($relation_type, $relation_id, $content) { $staff = Staff::info(); if(empty($staff)){ $admin = Session::get('admin'); $data = [ 'content' => $content, 'operation_type' => 2, 'operation_id' => $admin['id']??0, 'relation_type' => $relation_type, 'relation_id' => $relation_id, ]; }else{ $data = [ 'content' => $content, 'operation_type' => 1, 'operation_id' => $staff->id, 'relation_type' => $relation_type, 'relation_id' => $relation_id, ]; } $Enent = new self; $result = $Enent->save($data); if (false === $result) { // 验证失败 输出错误信息 throw new Exception($Enent->getError()); } return true; } }