'array']; public array $searchable = [ 'title' => 'like', 'notice_type_id' => '=', 'type' => '=', ]; protected string $sortField = 'sort'; /** * 添加通知 * @param array $data * @return bool * @throws \ReflectionException */ public function storeBy(array $data): mixed { $result = ''; $this->beginTransaction(); try { $result = $this->create($this->filterData($data)); if (isset($data['user_ids']) && !empty($data['user_ids'])) { $this->addUserNotice($data['user_ids'], $result->id); } $this->commit(); } catch (\Exception $exception) { $this->rollback(); } return $result->id ?? 0; } private function addUserNotice(mixed $userIds, mixed $id) { $list = []; foreach ($userIds as $val) { $list[] = ['user_id' => $val, 'notice_id' => $id]; } if (!empty($list)) { UserNotice::insert($list); } return true; } }