'array', 'raw_data' => 'array', 'seal_raw_data' => 'array', 'opt_raw_data' => 'array', ]; protected $hidden = [ 'create_time', 'update_time', 'drug_report_id', 'pkg_ratio_list', 'raw_data', 'seal_raw_data', 'opt_raw_data', ]; /** * @var array|string[] 定义可搜索字段(可选,可在调用时覆盖) */ public static $searchable = ['drug_id', 'drug_name', 'produce_ent_id', 'produce_ent_name']; /** * 获取「是否签收」文本 * @return string */ public function getIsSignTextAttribute(): string { $options = [ 0 => '', 1 => '未签收', 2 => '已签收', ]; return $options[$this->is_sign] ?? "未知「{$this->is_sign}」"; } /** * 获取「是否盖章」文本 * @return string */ public function getIsSealTextAttribute(): string { $options = [ 0 => '', 1 => '未盖章', 2 => '已盖章', ]; return $options[$this->is_sign] ?? "未知「{$this->is_sign}」"; } /** * 批量更新或插入 * @param array $data * @param array $uniqueKeys * @return int * @throws \Throwable */ public static function bulkUpsert(array $data, array $uniqueKeys = ['batch_no', 'drug_id']): int { if (empty($data)) { return 0; } return DB::transaction(function () use ($data, $uniqueKeys) { $count = 0; foreach (array_chunk($data, 100) as $chunk) { self::upsert( $chunk, $uniqueKeys, // 组合唯一键 array_keys($data[0]) // 要更新的字段 ); $count += count($chunk); } return $count; }); } }