$type, 'bip_code' => $code])->find(); } /** * 根据类型和本地ID获取数据 * @param string $type 数据类型 * @param int $localId 本地ID * @return array|null */ public static function getByTypeAndLocalId($type, $localId) { return self::where(['data_type' => $type, 'local_id' => $localId])->find(); } /** * 获取指定类型的所有数据 * @param string $type 数据类型 * @return array */ public static function getListByType($type) { return self::where(['data_type' => $type])->select(); } /** * 保存或更新基础数据 * @param string $type 数据类型 * @param string $bipCode 用友BIP编码 * @param string $bipName 用友BIP名称 * @param int|null $localId 本地ID(可选) * @param array $extraData 额外数据 * @return bool */ public static function saveOrUpdate($type, $bipCode, $bipName, $localId = null, $extraData = []) { $data = self::where(['data_type' => $type, 'bip_code' => $bipCode])->find(); $saveData = [ 'data_type' => $type, 'bip_code' => $bipCode, 'bip_name' => $bipName, 'local_id' => $localId, 'extra_data' => json_encode($extraData, JSON_UNESCAPED_UNICODE), 'updatetime' => time(), ]; if ($data) { // 更新 return $data->save($saveData); } else { // 新增 $saveData['createtime'] = time(); return self::create($saveData); } } /** * 清除指定类型的数据 * @param string $type 数据类型 * @return bool */ public static function clearByType($type) { return self::where(['data_type' => $type])->delete(); } }